You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2025/11/26 15:21:39 UTC
(sling-org-apache-sling-commons-compiler) 02/02: SLING-13013 apply spotless formatting
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/SLING-13013-parent-62
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-compiler.git
commit 3328b4d1ba93e2044dc2fddc49b7a8dd9fc7de63
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Nov 26 16:21:25 2025 +0100
SLING-13013 apply spotless formatting
---
pom.xml | 55 ++++----
.../sling/commons/compiler/CompilationResult.java | 29 ++--
.../sling/commons/compiler/CompilationUnit.java | 29 ++--
.../compiler/CompilationUnitWithSource.java | 26 ++--
.../sling/commons/compiler/CompilerMessage.java | 31 ++---
.../sling/commons/compiler/JavaCompiler.java | 29 ++--
.../org/apache/sling/commons/compiler/Options.java | 36 ++---
.../compiler/impl/CompilationResultImpl.java | 40 +++---
.../commons/compiler/impl/EclipseJavaCompiler.java | 152 +++++++++++----------
.../commons/compiler/impl/IsolatedClassLoader.java | 56 ++++----
.../sling/commons/compiler/package-info.java | 1 -
.../commons/compiler/source/JavaEscapeHelper.java | 49 ++++---
.../commons/compiler/source/package-info.java | 34 ++---
.../commons/compiler/impl/CompilerJava5Test.java | 38 +++---
.../compiler/source/JavaEscapeHelperTest.java | 80 +++++++----
15 files changed, 353 insertions(+), 332 deletions(-)
diff --git a/pom.xml b/pom.xml
index 327960e..4a3ffc0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -31,39 +31,19 @@
<version>2.4.1-SNAPSHOT</version>
<name>Apache Sling Commons Compiler</name>
- <description>
- The Apache Sling Commons Compiler bundle provides platform independent Java Compilation
- support using the Eclipse Java Compiler (org.eclipse.jdt).
- </description>
-
- <properties>
- <sling.java.version>11</sling.java.version>
- </properties>
+ <description>The Apache Sling Commons Compiler bundle provides platform independent Java Compilation
+ support using the Eclipse Java Compiler (org.eclipse.jdt).</description>
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-compiler.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-compiler.git</developerConnection>
+ <tag>org.apache.sling.commons.compiler-2.4.0</tag>
<url>https://github.com/apache/sling-org-apache-sling-commons-compiler.git</url>
- <tag>org.apache.sling.commons.compiler-2.4.0</tag>
- </scm>
+ </scm>
- <build>
- <plugins>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <excludePackageNames>
- org.apache.sling.commons.compiler.impl
- </excludePackageNames>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <properties>
+ <sling.java.version>11</sling.java.version>
+ </properties>
<dependencies>
<dependency>
@@ -86,7 +66,8 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
- <version>3.16.0</version> <!-- this is the version shipped in 2018-12/4.10.0 -->
+ <version>3.16.0</version>
+ <!-- this is the version shipped in 2018-12/4.10.0 -->
<scope>provided</scope>
</dependency>
<dependency>
@@ -112,4 +93,20 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <excludePackageNames>org.apache.sling.commons.compiler.impl</excludePackageNames>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/src/main/java/org/apache/sling/commons/compiler/CompilationResult.java b/src/main/java/org/apache/sling/commons/compiler/CompilationResult.java
index 447d7c6..a270b6f 100644
--- a/src/main/java/org/apache/sling/commons/compiler/CompilationResult.java
+++ b/src/main/java/org/apache/sling/commons/compiler/CompilationResult.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler;
@@ -63,6 +65,5 @@ public interface CompilationResult {
* @throws ClassNotFoundException If the class could not be found
* or compilation failed.
*/
- Class<?> loadCompiledClass(final String className)
- throws ClassNotFoundException;
+ Class<?> loadCompiledClass(final String className) throws ClassNotFoundException;
}
diff --git a/src/main/java/org/apache/sling/commons/compiler/CompilationUnit.java b/src/main/java/org/apache/sling/commons/compiler/CompilationUnit.java
index 3b5ae2c..208b40a 100644
--- a/src/main/java/org/apache/sling/commons/compiler/CompilationUnit.java
+++ b/src/main/java/org/apache/sling/commons/compiler/CompilationUnit.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler;
@@ -34,8 +36,7 @@ public interface CompilationUnit {
* @return The reader.
* @throws IOException If the source can't be read.
*/
- Reader getSource()
- throws IOException;
+ Reader getSource() throws IOException;
/**
* Returns the name of the top level public type.
diff --git a/src/main/java/org/apache/sling/commons/compiler/CompilationUnitWithSource.java b/src/main/java/org/apache/sling/commons/compiler/CompilationUnitWithSource.java
index df9a6e0..d8b03e0 100644
--- a/src/main/java/org/apache/sling/commons/compiler/CompilationUnitWithSource.java
+++ b/src/main/java/org/apache/sling/commons/compiler/CompilationUnitWithSource.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler;
diff --git a/src/main/java/org/apache/sling/commons/compiler/CompilerMessage.java b/src/main/java/org/apache/sling/commons/compiler/CompilerMessage.java
index aa28642..43998ee 100644
--- a/src/main/java/org/apache/sling/commons/compiler/CompilerMessage.java
+++ b/src/main/java/org/apache/sling/commons/compiler/CompilerMessage.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler;
@@ -56,10 +58,7 @@ public class CompilerMessage {
* @param column The column number of the offending program text
* @param message The actual text
*/
- public CompilerMessage(final String file,
- final int line,
- final int column,
- final String message) {
+ public CompilerMessage(final String file, final int line, final int column, final String message) {
this.file = file;
this.line = line;
this.column = column;
diff --git a/src/main/java/org/apache/sling/commons/compiler/JavaCompiler.java b/src/main/java/org/apache/sling/commons/compiler/JavaCompiler.java
index 351da45..994ba2e 100644
--- a/src/main/java/org/apache/sling/commons/compiler/JavaCompiler.java
+++ b/src/main/java/org/apache/sling/commons/compiler/JavaCompiler.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler;
@@ -38,6 +40,5 @@ public interface JavaCompiler {
* @return The compilation result with more information.
* @since 2.0
*/
- CompilationResult compile(CompilationUnit[] units,
- Options options);
+ CompilationResult compile(CompilationUnit[] units, Options options);
}
diff --git a/src/main/java/org/apache/sling/commons/compiler/Options.java b/src/main/java/org/apache/sling/commons/compiler/Options.java
index ee6048a..2a28c5e 100644
--- a/src/main/java/org/apache/sling/commons/compiler/Options.java
+++ b/src/main/java/org/apache/sling/commons/compiler/Options.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler;
@@ -109,12 +111,12 @@ public class Options extends HashMap<String, Object> {
return (String) this.get(KEY_TARGET_VERSION);
}
- /**
- * Should debug info be generated?
- * @return {@code true} if debug info should be generated.
- */
+ /**
+ * Should debug info be generated?
+ * @return {@code true} if debug info should be generated.
+ */
public boolean isGenerateDebugInfo() {
- if ( this.get(KEY_GENERATE_DEBUG_INFO) != null ) {
+ if (this.get(KEY_GENERATE_DEBUG_INFO) != null) {
return (Boolean) this.get(KEY_GENERATE_DEBUG_INFO);
}
return false;
diff --git a/src/main/java/org/apache/sling/commons/compiler/impl/CompilationResultImpl.java b/src/main/java/org/apache/sling/commons/compiler/impl/CompilationResultImpl.java
index 5d878b2..92b930c 100644
--- a/src/main/java/org/apache/sling/commons/compiler/impl/CompilationResultImpl.java
+++ b/src/main/java/org/apache/sling/commons/compiler/impl/CompilationResultImpl.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler.impl;
@@ -51,8 +53,7 @@ public class CompilationResultImpl implements CompilationResult {
this.compilationRequired = false;
}
- public CompilationResultImpl(final boolean ignoreWarnings,
- final ClassLoaderWriter writer) {
+ public CompilationResultImpl(final boolean ignoreWarnings, final ClassLoaderWriter writer) {
this.ignoreWarnings = ignoreWarnings;
this.classLoaderWriter = writer;
this.compilationRequired = true;
@@ -75,9 +76,8 @@ public class CompilationResultImpl implements CompilationResult {
/**
* @see org.apache.sling.commons.compiler.CompilationResult#loadCompiledClass(java.lang.String)
*/
- public Class<?> loadCompiledClass(final String className)
- throws ClassNotFoundException {
- if ( errors != null ) {
+ public Class<?> loadCompiledClass(final String className) throws ClassNotFoundException {
+ if (errors != null) {
throw new ClassNotFoundException(className);
}
return this.classLoaderWriter.getClassLoader().loadClass(className);
@@ -94,7 +94,7 @@ public class CompilationResultImpl implements CompilationResult {
* Notification of an error
*/
public void onError(String msg, String sourceFile, int line, int position) {
- if ( errors == null ) {
+ if (errors == null) {
errors = new ArrayList<CompilerMessage>();
}
errors.add(new CompilerMessage(sourceFile, line, position, msg));
@@ -104,8 +104,8 @@ public class CompilationResultImpl implements CompilationResult {
* Notification of a warning
*/
public void onWarning(String msg, String sourceFile, int line, int position) {
- if ( !this.ignoreWarnings ) {
- if ( warnings == null ) {
+ if (!this.ignoreWarnings) {
+ if (warnings == null) {
warnings = new ArrayList<CompilerMessage>();
}
warnings.add(new CompilerMessage(sourceFile, line, position, msg));
diff --git a/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java b/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java
index 4a99c3d..17891c9 100644
--- a/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java
+++ b/src/main/java/org/apache/sling/commons/compiler/impl/EclipseJavaCompiler.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler.impl;
@@ -72,7 +74,7 @@ public class EclipseJavaCompiler implements JavaCompiler {
/** the static policy. */
private final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
-
+
private final Set<String> warningEmittedForUnsupportedJavaVersion = new CopyOnWriteArraySet<>();
/**
@@ -80,14 +82,13 @@ public class EclipseJavaCompiler implements JavaCompiler {
*/
private ClassLoader getClassLoader(final Options options, final ClassLoaderWriter classLoaderWriter) {
final ClassLoader loader;
- if ( options.get(Options.KEY_CLASS_LOADER) != null ) {
- loader = (ClassLoader)options.get(Options.KEY_CLASS_LOADER);
- } else if ( options.get(Options.KEY_ADDITIONAL_CLASS_LOADER) != null ) {
- final ClassLoader additionalClassLoader = (ClassLoader)options.get(Options.KEY_ADDITIONAL_CLASS_LOADER);
+ if (options.get(Options.KEY_CLASS_LOADER) != null) {
+ loader = (ClassLoader) options.get(Options.KEY_CLASS_LOADER);
+ } else if (options.get(Options.KEY_ADDITIONAL_CLASS_LOADER) != null) {
+ final ClassLoader additionalClassLoader = (ClassLoader) options.get(Options.KEY_ADDITIONAL_CLASS_LOADER);
loader = new ClassLoader(classLoaderWriter.getClassLoader()) {
@Override
- protected Class<?> findClass(String name)
- throws ClassNotFoundException {
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
return additionalClassLoader.loadClass(name);
}
@@ -98,7 +99,7 @@ public class EclipseJavaCompiler implements JavaCompiler {
};
} else {
final ClassLoader cl = classLoaderWriter.getClassLoader();
- if ( cl == null ) {
+ if (cl == null) {
loader = this.classLoaderWriter.getClassLoader();
} else {
loader = cl;
@@ -111,8 +112,8 @@ public class EclipseJavaCompiler implements JavaCompiler {
* Get the class loader writer for the compilation.
*/
private ClassLoaderWriter getClassLoaderWriter(final Options options) {
- if (options.get(Options.KEY_CLASS_LOADER_WRITER) != null ) {
- return (ClassLoaderWriter)options.get(Options.KEY_CLASS_LOADER_WRITER);
+ if (options.get(Options.KEY_CLASS_LOADER_WRITER) != null) {
+ return (ClassLoaderWriter) options.get(Options.KEY_CLASS_LOADER_WRITER);
}
return this.classLoaderWriter;
}
@@ -120,9 +121,9 @@ public class EclipseJavaCompiler implements JavaCompiler {
/**
* Check if the compiled class file is older than the source file
*/
- private boolean isOutDated(final CompilationUnit unit,
- final ClassLoaderWriter writer) {
- final long targetLastModified = writer.getLastModified('/' + unit.getMainClassName().replace('.', '/') + ".class");
+ private boolean isOutDated(final CompilationUnit unit, final ClassLoaderWriter writer) {
+ final long targetLastModified =
+ writer.getLastModified('/' + unit.getMainClassName().replace('.', '/') + ".class");
if (targetLastModified < 0) {
return true;
}
@@ -134,8 +135,8 @@ public class EclipseJavaCompiler implements JavaCompiler {
* Return the force compilation value
*/
private boolean isForceCompilation(final Options options) {
- final Boolean flag = (Boolean)options.get(Options.KEY_FORCE_COMPILATION);
- if ( flag != null ) {
+ final Boolean flag = (Boolean) options.get(Options.KEY_FORCE_COMPILATION);
+ if (flag != null) {
return flag;
}
return false;
@@ -145,8 +146,8 @@ public class EclipseJavaCompiler implements JavaCompiler {
* Return the ignore warnings value
*/
private boolean isIgnoreWarnings(final Options options) {
- final Boolean flag = (Boolean)options.get(Options.KEY_IGNORE_WARNINGS);
- if ( flag != null ) {
+ final Boolean flag = (Boolean) options.get(Options.KEY_IGNORE_WARNINGS);
+ if (flag != null) {
return flag;
}
return false;
@@ -158,38 +159,37 @@ public class EclipseJavaCompiler implements JavaCompiler {
* @see org.apache.sling.commons.compiler.JavaCompiler#compile(org.apache.sling.commons.compiler.CompilationUnit[], org.apache.sling.commons.compiler.Options)
*/
@Override
- public CompilationResult compile(final CompilationUnit[] units,
- final Options compileOptions) {
+ public CompilationResult compile(final CompilationUnit[] units, final Options compileOptions) {
// make sure we have an options object (to avoid null checks all over the place)
final Options options = (compileOptions != null ? compileOptions : EMPTY_OPTIONS);
// get classloader and classloader writer
final ClassLoaderWriter writer = this.getClassLoaderWriter(options);
- if ( writer == null ) {
+ if (writer == null) {
return new CompilationResultImpl("Class loader writer for compilation is not available.");
}
final ClassLoader loader = this.getClassLoader(options, writer);
- if ( loader == null ) {
+ if (loader == null) {
return new CompilationResultImpl("Class loader for compilation is not available.");
}
// check sources for compilation
boolean needsCompilation = isForceCompilation(options);
- if ( !needsCompilation ) {
- for(final CompilationUnit unit : units) {
- if ( this.isOutDated(unit, writer) ) {
+ if (!needsCompilation) {
+ for (final CompilationUnit unit : units) {
+ if (this.isOutDated(unit, writer)) {
needsCompilation = true;
break;
}
}
}
- if ( !needsCompilation ) {
+ if (!needsCompilation) {
logger.debug("All source files are recent - no compilation required.");
return new CompilationResultImpl(writer);
}
// delete old class files
- for(final CompilationUnit unit : units) {
+ for (final CompilationUnit unit : units) {
final String name = '/' + unit.getMainClassName().replace('.', '/') + ".class";
writer.delete(name);
}
@@ -220,15 +220,8 @@ public class EclipseJavaCompiler implements JavaCompiler {
final CompileContext context = new CompileContext(units, result, writer, loader);
// create the compiler
- final org.eclipse.jdt.internal.compiler.Compiler compiler =
- new org.eclipse.jdt.internal.compiler.Compiler(
- context,
- this.policy,
- settings,
- context,
- this.problemFactory,
- null,
- null);
+ final org.eclipse.jdt.internal.compiler.Compiler compiler = new org.eclipse.jdt.internal.compiler.Compiler(
+ context, this.policy, settings, context, this.problemFactory, null, null);
// compile
compiler.compile(context.getSourceUnits());
@@ -241,43 +234,48 @@ public class EclipseJavaCompiler implements JavaCompiler {
if (CompilerOptions.versionToJdkLevel(javaVersion) == 0) {
String latestSupportedVersion = CompilerOptions.VERSION_11;
// only log once per invalid javaVersion
- if (!warningEmittedForUnsupportedJavaVersion.contains(javaVersion) && warningEmittedForUnsupportedJavaVersion.add(javaVersion)) {
- logger.warn("Using unsupported java version '{}', assuming latest supported version '{}'", javaVersion, latestSupportedVersion);
+ if (!warningEmittedForUnsupportedJavaVersion.contains(javaVersion)
+ && warningEmittedForUnsupportedJavaVersion.add(javaVersion)) {
+ logger.warn(
+ "Using unsupported java version '{}', assuming latest supported version '{}'",
+ javaVersion,
+ latestSupportedVersion);
}
return latestSupportedVersion;
}
return javaVersion;
}
- //--------------------------------------------------------< inner classes >
+ // --------------------------------------------------------< inner classes >
private class CompileContext implements ICompilerRequestor, INameEnvironment {
- private final Map<String,ICompilationUnit> compUnits;
+ private final Map<String, ICompilationUnit> compUnits;
private final CompilationResultImpl errorHandler;
private final ClassLoaderWriter classLoaderWriter;
private final ClassLoader classLoader;
- public CompileContext(final CompilationUnit[] units,
- final CompilationResultImpl errorHandler,
- final ClassLoaderWriter classWriter,
- final ClassLoader classLoader) {
- this.compUnits = new HashMap<>();
+ public CompileContext(
+ final CompilationUnit[] units,
+ final CompilationResultImpl errorHandler,
+ final ClassLoaderWriter classWriter,
+ final ClassLoader classLoader) {
+ this.compUnits = new HashMap<>();
for (int i = 0; i < units.length; i++) {
CompilationUnitAdapter cua = new CompilationUnitAdapter(units[i], errorHandler);
char[][] compoundName = CharOperation.arrayConcat(cua.getPackageName(), cua.getMainTypeName());
- this.compUnits.put(CharOperation.toString(compoundName), new CompilationUnitAdapter(units[i], errorHandler));
+ this.compUnits.put(
+ CharOperation.toString(compoundName), new CompilationUnitAdapter(units[i], errorHandler));
}
- this.errorHandler = errorHandler;
+ this.errorHandler = errorHandler;
this.classLoaderWriter = classWriter;
this.classLoader = classLoader;
}
public ICompilationUnit[] getSourceUnits() {
- return compUnits.values().toArray(
- new ICompilationUnit[compUnits.size()]);
+ return compUnits.values().toArray(new ICompilationUnit[compUnits.size()]);
}
/**
@@ -335,8 +333,7 @@ public class EclipseJavaCompiler implements JavaCompiler {
if (bytes == null) {
return null;
}
- ClassFileReader classFileReader =
- new ClassFileReader(bytes, fqn.toCharArray(), true);
+ ClassFileReader classFileReader = new ClassFileReader(bytes, fqn.toCharArray(), true);
return new NameEnvironmentAnswer(classFileReader, null);
} catch (Exception e) {
return null;
@@ -356,8 +353,7 @@ public class EclipseJavaCompiler implements JavaCompiler {
*/
@Override
public boolean isPackage(char[][] parentPackageName, char[] packageName) {
- String fqn = CharOperation.toString(
- CharOperation.arrayConcat(parentPackageName, packageName));
+ String fqn = CharOperation.toString(CharOperation.arrayConcat(parentPackageName, packageName));
return compUnits.get(fqn) == null && this.isPackage(fqn);
}
@@ -380,14 +376,15 @@ public class EclipseJavaCompiler implements JavaCompiler {
private boolean isPackage(String result) {
String resourceName = result.replace('.', '/') + ".class";
- if ( resourceName.startsWith("/") ) {
+ if (resourceName.startsWith("/")) {
resourceName = resourceName.substring(1);
}
final InputStream is = this.classLoader.getResourceAsStream(resourceName);
- if ( is != null ) {
+ if (is != null) {
try {
is.close();
- } catch (IOException ignore) {}
+ } catch (IOException ignore) {
+ }
}
return is == null;
}
@@ -408,7 +405,8 @@ public class EclipseJavaCompiler implements JavaCompiler {
} finally {
try {
is.close();
- } catch (IOException ignore) {}
+ } catch (IOException ignore) {
+ }
}
}
return null;
@@ -426,7 +424,7 @@ public class EclipseJavaCompiler implements JavaCompiler {
this.compUnit = compUnit;
this.errorHandler = errorHandler;
final int pos = compUnit.getMainClassName().lastIndexOf('.');
- if ( pos == -1 ) {
+ if (pos == -1) {
this.packageName = "";
this.mainTypeName = compUnit.getMainClassName();
} else {
@@ -458,12 +456,18 @@ public class EclipseJavaCompiler implements JavaCompiler {
reader.close();
}
} catch (IOException e) {
- this.errorHandler.onError("Unable to read source file " + this.compUnit.getMainClassName() + " : " + e.getMessage(),
- this.compUnit.getMainClassName(), 0, 0);
+ this.errorHandler.onError(
+ "Unable to read source file " + this.compUnit.getMainClassName() + " : " + e.getMessage(),
+ this.compUnit.getMainClassName(),
+ 0,
+ 0);
return null;
} finally {
- if ( fr != null ) {
- try { fr.close(); } catch (IOException ignore) {}
+ if (fr != null) {
+ try {
+ fr.close();
+ } catch (IOException ignore) {
+ }
}
}
}
@@ -490,7 +494,7 @@ public class EclipseJavaCompiler implements JavaCompiler {
@Override
public char[] getFileName() {
if (compUnit instanceof CompilationUnitWithSource) {
- return ((CompilationUnitWithSource)compUnit).getFileName().toCharArray();
+ return ((CompilationUnitWithSource) compUnit).getFileName().toCharArray();
} else {
return (this.packageName.replace('.', '/') + '/' + this.mainTypeName + ".java").toCharArray();
}
diff --git a/src/main/java/org/apache/sling/commons/compiler/impl/IsolatedClassLoader.java b/src/main/java/org/apache/sling/commons/compiler/impl/IsolatedClassLoader.java
index ace970a..270f31d 100644
--- a/src/main/java/org/apache/sling/commons/compiler/impl/IsolatedClassLoader.java
+++ b/src/main/java/org/apache/sling/commons/compiler/impl/IsolatedClassLoader.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler.impl;
@@ -25,24 +27,20 @@ import java.security.SecureClassLoader;
import org.apache.sling.commons.classloader.ClassLoaderWriter;
-
/**
* The <code>IsolatedClassLoader</code> class loads classes through
* the class loader writer
*/
-public final class IsolatedClassLoader
- extends SecureClassLoader {
+public final class IsolatedClassLoader extends SecureClassLoader {
private final ClassLoaderWriter classLoaderWriter;
- public IsolatedClassLoader(final ClassLoader parent,
- final ClassLoaderWriter classLoaderWriter) {
+ public IsolatedClassLoader(final ClassLoader parent, final ClassLoaderWriter classLoaderWriter) {
super(parent);
this.classLoaderWriter = classLoaderWriter;
}
-
- //---------- Class loader overwrites -------------------------------------
+ // ---------- Class loader overwrites -------------------------------------
/**
* Loads the class from this <code>ClassLoader</class>. If the
@@ -94,13 +92,12 @@ public final class IsolatedClassLoader
*/
protected Class<?> findClass(final String name) throws ClassNotFoundException {
try {
- return AccessController.doPrivileged(
- new PrivilegedExceptionAction<Class<?>>() {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
- public Class<?> run() throws ClassNotFoundException {
- return findClassPrivileged(name);
- }
- });
+ public Class<?> run() throws ClassNotFoundException {
+ return findClassPrivileged(name);
+ }
+ });
} catch (final java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
@@ -130,12 +127,12 @@ public final class IsolatedClassLoader
throw new ClassNotFoundException(name);
}
return c;
- } catch ( final ClassNotFoundException cnfe) {
+ } catch (final ClassNotFoundException cnfe) {
throw cnfe;
} catch (final Throwable t) {
throw new ClassNotFoundException(name, t);
}
- }
+ }
/**
* Defines a class getting the bytes for the class from the resource
@@ -148,12 +145,11 @@ public final class IsolatedClassLoader
* @throws ClassFormatError If the class bytes read from the resource are
* not a valid class.
*/
- private Class<?> defineClass(final String name, final InputStream is)
- throws IOException {
+ private Class<?> defineClass(final String name, final InputStream is) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buffer = new byte[2048];
int l;
- while ( ( l = is.read(buffer)) >= 0 ) {
+ while ((l = is.read(buffer)) >= 0) {
baos.write(buffer, 0, l);
}
final byte[] data = baos.toByteArray();
diff --git a/src/main/java/org/apache/sling/commons/compiler/package-info.java b/src/main/java/org/apache/sling/commons/compiler/package-info.java
index 5045562..114d6d1 100644
--- a/src/main/java/org/apache/sling/commons/compiler/package-info.java
+++ b/src/main/java/org/apache/sling/commons/compiler/package-info.java
@@ -21,4 +21,3 @@
package org.apache.sling.commons.compiler;
import org.osgi.annotation.versioning.Version;
-
diff --git a/src/main/java/org/apache/sling/commons/compiler/source/JavaEscapeHelper.java b/src/main/java/org/apache/sling/commons/compiler/source/JavaEscapeHelper.java
index ba910b7..f780502 100644
--- a/src/main/java/org/apache/sling/commons/compiler/source/JavaEscapeHelper.java
+++ b/src/main/java/org/apache/sling/commons/compiler/source/JavaEscapeHelper.java
@@ -1,21 +1,21 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.sling.commons.compiler.source;
import java.util.HashSet;
@@ -36,8 +36,7 @@ public final class JavaEscapeHelper {
private static final Set<String> specialIdentifiers = new HashSet<>();
private static final Pattern ESCAPED_CHAR_PATTERN = Pattern.compile("(__[0-9a-f]{4}__)");
- private JavaEscapeHelper() {
- }
+ private JavaEscapeHelper() {}
static {
javaKeywords.add("abstract");
@@ -122,7 +121,9 @@ public final class JavaEscapeHelper {
}
}
String currentIdentifier = modifiedIdentifier.toString();
- if (isJavaKeyword(currentIdentifier) || isJavaLiteral(currentIdentifier) || isSpecialIdentifier(currentIdentifier)) {
+ if (isJavaKeyword(currentIdentifier)
+ || isJavaLiteral(currentIdentifier)
+ || isSpecialIdentifier(currentIdentifier)) {
return escapeChar(currentIdentifier.charAt(0)) + currentIdentifier.substring(1);
}
return currentIdentifier;
@@ -154,8 +155,8 @@ public final class JavaEscapeHelper {
String toProcess = escapeSequence.replace("__", "");
return (char) Integer.parseInt(toProcess, 16);
}
- throw new IllegalArgumentException(
- String.format("String '%s' does not match pattern %s.", escapeSequence, ESCAPED_CHAR_PATTERN.pattern()));
+ throw new IllegalArgumentException(String.format(
+ "String '%s' does not match pattern %s.", escapeSequence, ESCAPED_CHAR_PATTERN.pattern()));
}
/**
@@ -230,6 +231,4 @@ public final class JavaEscapeHelper {
public static boolean isSpecialIdentifier(@NotNull String key) {
return specialIdentifiers.contains(key);
}
-
-
}
diff --git a/src/main/java/org/apache/sling/commons/compiler/source/package-info.java b/src/main/java/org/apache/sling/commons/compiler/source/package-info.java
index d58b643..ede5c29 100644
--- a/src/main/java/org/apache/sling/commons/compiler/source/package-info.java
+++ b/src/main/java/org/apache/sling/commons/compiler/source/package-info.java
@@ -1,21 +1,21 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+~ Licensed to the Apache Software Foundation (ASF) under one
+~ or more contributor license agreements. See the NOTICE file
+~ distributed with this work for additional information
+~ regarding copyright ownership. The ASF licenses this file
+~ to you under the Apache License, Version 2.0 (the
+~ "License"); you may not use this file except in compliance
+~ with the License. You may obtain a copy of the License at
+~
+~ http://www.apache.org/licenses/LICENSE-2.0
+~
+~ Unless required by applicable law or agreed to in writing,
+~ software distributed under the License is distributed on an
+~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+~ KIND, either express or implied. See the License for the
+~ specific language governing permissions and limitations
+~ under the License.
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@Version("1.0.0")
package org.apache.sling.commons.compiler.source;
diff --git a/src/test/java/org/apache/sling/commons/compiler/impl/CompilerJava5Test.java b/src/test/java/org/apache/sling/commons/compiler/impl/CompilerJava5Test.java
index 5540ce9..f137bc2 100644
--- a/src/test/java/org/apache/sling/commons/compiler/impl/CompilerJava5Test.java
+++ b/src/test/java/org/apache/sling/commons/compiler/impl/CompilerJava5Test.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.sling.commons.compiler.impl;
@@ -25,18 +27,16 @@ import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
+import junit.framework.TestCase;
import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.commons.compiler.CompilationResult;
import org.apache.sling.commons.compiler.CompilationUnit;
import org.apache.sling.commons.compiler.Options;
-import junit.framework.TestCase;
-
/**
* Test case for java 5 support
*/
-public class CompilerJava5Test extends TestCase
- implements ClassLoaderWriter {
+public class CompilerJava5Test extends TestCase implements ClassLoaderWriter {
private final List<String> deletedPath = new ArrayList<>();
@@ -53,7 +53,7 @@ public class CompilerJava5Test extends TestCase
options.put(Options.KEY_CLASS_LOADER_WRITER, this);
options.put(Options.KEY_CLASS_LOADER, this.getClass().getClassLoader());
- final CompilationResult result = new EclipseJavaCompiler().compile(new CompilationUnit[]{unit}, options);
+ final CompilationResult result = new EclipseJavaCompiler().compile(new CompilationUnit[] {unit}, options);
assertNotNull(result);
assertNull(result.getErrors());
assertEquals(1, deletedPath.size());
@@ -74,7 +74,7 @@ public class CompilerJava5Test extends TestCase
options.put(Options.KEY_CLASS_LOADER_WRITER, this);
options.put(Options.KEY_CLASS_LOADER, this.getClass().getClassLoader());
- final CompilationResult result = new EclipseJavaCompiler().compile(new CompilationUnit[]{unit}, options);
+ final CompilationResult result = new EclipseJavaCompiler().compile(new CompilationUnit[] {unit}, options);
assertNotNull(result);
assertNotNull(result.getErrors());
assertEquals(1, deletedPath.size());
@@ -82,7 +82,7 @@ public class CompilerJava5Test extends TestCase
assertEquals(0, outputPath.size());
}
- //--------------------------------------------------------< misc. helpers >
+ // --------------------------------------------------------< misc. helpers >
private CompilationUnit createCompileUnit(final String sourceFile) throws Exception {
return new CompilationUnit() {
diff --git a/src/test/java/org/apache/sling/commons/compiler/source/JavaEscapeHelperTest.java b/src/test/java/org/apache/sling/commons/compiler/source/JavaEscapeHelperTest.java
index 6ce1679..e9ace47 100644
--- a/src/test/java/org/apache/sling/commons/compiler/source/JavaEscapeHelperTest.java
+++ b/src/test/java/org/apache/sling/commons/compiler/source/JavaEscapeHelperTest.java
@@ -1,21 +1,21 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.sling.commons.compiler.source;
import org.junit.Test;
@@ -26,16 +26,33 @@ public class JavaEscapeHelperTest {
@Test
public void testGetClassNameFromScriptPath() {
- assertEquals("apps.projects.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/projects/script.html"));
- assertEquals("apps.projects.script__002e__html", JavaEscapeHelper.makeJavaPackage("\\apps\\projects\\script.html"));
- assertEquals("apps.my__002d__project.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/my-project/script.html"));
- assertEquals("apps.my__002d__project.script__002e__html", JavaEscapeHelper.makeJavaPackage("\\apps\\my-project\\script.html"));
- assertEquals("apps.my_project.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/my_project/script.html"));
- assertEquals("apps.my_project.script__002e__html", JavaEscapeHelper.makeJavaPackage("\\apps\\my_project\\script.html"));
- assertEquals("apps.projects.__0031__.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/projects/1/script.html"));
- assertEquals("apps.projects.__0031__.script__002e__html", JavaEscapeHelper.makeJavaPackage("\\apps\\projects\\1\\script.html"));
- assertEquals("apps.projects.__0073__witch.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/projects/switch/script.html"));
- assertEquals("apps.projects.__0073__witch.script__002e__html", JavaEscapeHelper.makeJavaPackage("\\apps\\projects\\switch\\script.html"));
+ assertEquals(
+ "apps.projects.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/projects/script.html"));
+ assertEquals(
+ "apps.projects.script__002e__html", JavaEscapeHelper.makeJavaPackage("\\apps\\projects\\script.html"));
+ assertEquals(
+ "apps.my__002d__project.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("/apps/my-project/script.html"));
+ assertEquals(
+ "apps.my__002d__project.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("\\apps\\my-project\\script.html"));
+ assertEquals(
+ "apps.my_project.script__002e__html", JavaEscapeHelper.makeJavaPackage("/apps/my_project/script.html"));
+ assertEquals(
+ "apps.my_project.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("\\apps\\my_project\\script.html"));
+ assertEquals(
+ "apps.projects.__0031__.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("/apps/projects/1/script.html"));
+ assertEquals(
+ "apps.projects.__0031__.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("\\apps\\projects\\1\\script.html"));
+ assertEquals(
+ "apps.projects.__0073__witch.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("/apps/projects/switch/script.html"));
+ assertEquals(
+ "apps.projects.__0073__witch.script__002e__html",
+ JavaEscapeHelper.makeJavaPackage("\\apps\\projects\\switch\\script.html"));
}
@Test
@@ -58,7 +75,10 @@ public class JavaEscapeHelperTest {
@Test
public void testUnescapeAll() {
- assertEquals("apps.projects.switch.script.html", JavaEscapeHelper.unescapeAll("apps.projects.__0073__witch.script__002e__html"));
- assertEquals("apps.projects.switch.script.html", JavaEscapeHelper.unescapeAll("apps.projects.switch.script.html"));
+ assertEquals(
+ "apps.projects.switch.script.html",
+ JavaEscapeHelper.unescapeAll("apps.projects.__0073__witch.script__002e__html"));
+ assertEquals(
+ "apps.projects.switch.script.html", JavaEscapeHelper.unescapeAll("apps.projects.switch.script.html"));
}
}