-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade parent and reformat using spotless
- Loading branch information
Showing
67 changed files
with
3,869 additions
and
5,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,29 +23,26 @@ | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
import org.codehaus.plexus.util.DirectoryScanner; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.codehaus.plexus.util.DirectoryScanner; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Jason van Zyl </a> | ||
* @author <a href="mailto:[email protected]">Michal Maczka </a> | ||
* @author <a href="mailto:[email protected]">Trygve Laugstøl</a> | ||
*/ | ||
public abstract class AbstractCompiler | ||
implements Compiler | ||
{ | ||
protected Logger log = LoggerFactory.getLogger ( getClass() ); | ||
public abstract class AbstractCompiler implements Compiler { | ||
protected Logger log = LoggerFactory.getLogger(getClass()); | ||
protected static final String EOL = System.lineSeparator(); | ||
|
||
protected static final String PS = System.getProperty( "path.separator" ); | ||
protected static final String PS = System.getProperty("path.separator"); | ||
|
||
private final CompilerOutputStyle compilerOutputStyle; | ||
|
||
|
@@ -59,9 +56,11 @@ public abstract class AbstractCompiler | |
// | ||
// ---------------------------------------------------------------------- | ||
|
||
protected AbstractCompiler( CompilerOutputStyle compilerOutputStyle, String inputFileEnding, | ||
String outputFileEnding, String outputFile ) | ||
{ | ||
protected AbstractCompiler( | ||
CompilerOutputStyle compilerOutputStyle, | ||
String inputFileEnding, | ||
String outputFileEnding, | ||
String outputFile) { | ||
this.compilerOutputStyle = compilerOutputStyle; | ||
|
||
this.inputFileEnding = inputFileEnding; | ||
|
@@ -77,91 +76,71 @@ protected AbstractCompiler( CompilerOutputStyle compilerOutputStyle, String inpu | |
|
||
public abstract String getCompilerId(); | ||
|
||
public CompilerResult performCompile(CompilerConfiguration configuration) | ||
throws CompilerException | ||
{ | ||
public CompilerResult performCompile(CompilerConfiguration configuration) throws CompilerException { | ||
throw new CompilerNotImplementedException("The performCompile method has not been implemented."); | ||
} | ||
|
||
public CompilerOutputStyle getCompilerOutputStyle() | ||
{ | ||
public CompilerOutputStyle getCompilerOutputStyle() { | ||
return compilerOutputStyle; | ||
} | ||
|
||
public String getInputFileEnding( CompilerConfiguration configuration ) | ||
throws CompilerException | ||
{ | ||
public String getInputFileEnding(CompilerConfiguration configuration) throws CompilerException { | ||
return inputFileEnding; | ||
} | ||
|
||
public String getOutputFileEnding( CompilerConfiguration configuration ) | ||
throws CompilerException | ||
{ | ||
if ( compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE ) | ||
{ | ||
throw new RuntimeException( "This compiler implementation doesn't have one output file per input file." ); | ||
public String getOutputFileEnding(CompilerConfiguration configuration) throws CompilerException { | ||
if (compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE) { | ||
throw new RuntimeException("This compiler implementation doesn't have one output file per input file."); | ||
} | ||
|
||
return outputFileEnding; | ||
} | ||
|
||
public String getOutputFile( CompilerConfiguration configuration ) | ||
throws CompilerException | ||
{ | ||
if ( compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) | ||
{ | ||
throw new RuntimeException( "This compiler implementation doesn't have one output file for all files." ); | ||
public String getOutputFile(CompilerConfiguration configuration) throws CompilerException { | ||
if (compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES) { | ||
throw new RuntimeException("This compiler implementation doesn't have one output file for all files."); | ||
} | ||
|
||
return outputFile; | ||
} | ||
|
||
public boolean canUpdateTarget( CompilerConfiguration configuration ) | ||
throws CompilerException | ||
{ | ||
public boolean canUpdateTarget(CompilerConfiguration configuration) throws CompilerException { | ||
return true; | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Utility Methods | ||
// ---------------------------------------------------------------------- | ||
|
||
public static String getPathString( List<String> pathElements ) | ||
{ | ||
public static String getPathString(List<String> pathElements) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
for ( String pathElement : pathElements ) | ||
{ | ||
sb.append( pathElement ).append( File.pathSeparator ); | ||
for (String pathElement : pathElements) { | ||
sb.append(pathElement).append(File.pathSeparator); | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
protected static Set<String> getSourceFilesForSourceRoot( CompilerConfiguration config, String sourceLocation ) | ||
{ | ||
protected static Set<String> getSourceFilesForSourceRoot(CompilerConfiguration config, String sourceLocation) { | ||
DirectoryScanner scanner = new DirectoryScanner(); | ||
|
||
scanner.setBasedir( sourceLocation ); | ||
scanner.setBasedir(sourceLocation); | ||
|
||
Set<String> includes = config.getIncludes(); | ||
|
||
if ( includes != null && !includes.isEmpty() ) | ||
{ | ||
String[] inclStrs = includes.toArray( new String[0] ); | ||
scanner.setIncludes( inclStrs ); | ||
} | ||
else | ||
{ | ||
scanner.setIncludes( new String[]{ "**/*.java" } ); | ||
if (includes != null && !includes.isEmpty()) { | ||
String[] inclStrs = includes.toArray(new String[0]); | ||
scanner.setIncludes(inclStrs); | ||
} else { | ||
scanner.setIncludes(new String[] {"**/*.java"}); | ||
} | ||
|
||
Set<String> excludes = config.getExcludes(); | ||
|
||
if ( excludes != null && !excludes.isEmpty() ) | ||
{ | ||
String[] exclStrs = excludes.toArray( new String[0] ); | ||
scanner.setExcludes( exclStrs ); | ||
if (excludes != null && !excludes.isEmpty()) { | ||
String[] exclStrs = excludes.toArray(new String[0]); | ||
scanner.setExcludes(exclStrs); | ||
} | ||
|
||
scanner.scan(); | ||
|
@@ -170,125 +149,105 @@ protected static Set<String> getSourceFilesForSourceRoot( CompilerConfiguration | |
|
||
Set<String> sources = new HashSet<>(); | ||
|
||
for ( String sourceDirectorySource : sourceDirectorySources ) | ||
{ | ||
File f = new File( sourceLocation, sourceDirectorySource ); | ||
for (String sourceDirectorySource : sourceDirectorySources) { | ||
File f = new File(sourceLocation, sourceDirectorySource); | ||
|
||
sources.add( f.getPath() ); | ||
sources.add(f.getPath()); | ||
} | ||
|
||
return sources; | ||
} | ||
|
||
protected static String[] getSourceFiles( CompilerConfiguration config ) | ||
{ | ||
protected static String[] getSourceFiles(CompilerConfiguration config) { | ||
Set<String> sources = new HashSet<>(); | ||
|
||
Set<File> sourceFiles = config.getSourceFiles(); | ||
|
||
if ( sourceFiles != null && !sourceFiles.isEmpty() ) | ||
{ | ||
for ( File sourceFile : sourceFiles ) | ||
{ | ||
sources.add( sourceFile.getAbsolutePath() ); | ||
if (sourceFiles != null && !sourceFiles.isEmpty()) { | ||
for (File sourceFile : sourceFiles) { | ||
sources.add(sourceFile.getAbsolutePath()); | ||
} | ||
} | ||
else | ||
{ | ||
for ( String sourceLocation : config.getSourceLocations() ) | ||
{ | ||
sources.addAll( getSourceFilesForSourceRoot( config, sourceLocation ) ); | ||
} else { | ||
for (String sourceLocation : config.getSourceLocations()) { | ||
sources.addAll(getSourceFilesForSourceRoot(config, sourceLocation)); | ||
} | ||
} | ||
|
||
String[] result; | ||
|
||
if ( sources.isEmpty() ) | ||
{ | ||
if (sources.isEmpty()) { | ||
result = new String[0]; | ||
} | ||
else | ||
{ | ||
result = sources.toArray( new String[0] ); | ||
} else { | ||
result = sources.toArray(new String[0]); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected static String makeClassName( String fileName, String sourceDir ) | ||
throws CompilerException | ||
{ | ||
File origFile = new File( fileName ); | ||
protected static String makeClassName(String fileName, String sourceDir) throws CompilerException { | ||
File origFile = new File(fileName); | ||
|
||
String canonical = null; | ||
|
||
if ( origFile.exists() ) | ||
{ | ||
canonical = getCanonicalPath( origFile ).replace( '\\', '/' ); | ||
if (origFile.exists()) { | ||
canonical = getCanonicalPath(origFile).replace('\\', '/'); | ||
} | ||
|
||
if ( sourceDir != null ) | ||
{ | ||
String prefix = getCanonicalPath( new File( sourceDir ) ).replace( '\\', '/' ); | ||
if (sourceDir != null) { | ||
String prefix = getCanonicalPath(new File(sourceDir)).replace('\\', '/'); | ||
|
||
if ( canonical != null ) | ||
{ | ||
if ( canonical.startsWith( prefix ) ) | ||
{ | ||
String result = canonical.substring( prefix.length() + 1, canonical.length() - 5 ); | ||
if (canonical != null) { | ||
if (canonical.startsWith(prefix)) { | ||
String result = canonical.substring(prefix.length() + 1, canonical.length() - 5); | ||
|
||
result = result.replace( '/', '.' ); | ||
result = result.replace('/', '.'); | ||
|
||
return result; | ||
} | ||
} | ||
else | ||
{ | ||
File t = new File( sourceDir, fileName ); | ||
} else { | ||
File t = new File(sourceDir, fileName); | ||
|
||
if ( t.exists() ) | ||
{ | ||
String str = getCanonicalPath( t ).replace( '\\', '/' ); | ||
if (t.exists()) { | ||
String str = getCanonicalPath(t).replace('\\', '/'); | ||
|
||
return str.substring( prefix.length() + 1, str.length() - 5 ).replace( '/', '.' ); | ||
return str.substring(prefix.length() + 1, str.length() - 5).replace('/', '.'); | ||
} | ||
} | ||
} | ||
|
||
if ( fileName.endsWith( ".java" ) ) | ||
{ | ||
fileName = fileName.substring( 0, fileName.length() - 5 ); | ||
if (fileName.endsWith(".java")) { | ||
fileName = fileName.substring(0, fileName.length() - 5); | ||
} | ||
|
||
fileName = fileName.replace( '\\', '.' ); | ||
fileName = fileName.replace('\\', '.'); | ||
|
||
return fileName.replace( '/', '.' ); | ||
return fileName.replace('/', '.'); | ||
} | ||
|
||
private static String getCanonicalPath( File origFile ) | ||
throws CompilerException | ||
{ | ||
try | ||
{ | ||
private static String getCanonicalPath(File origFile) throws CompilerException { | ||
try { | ||
return origFile.getCanonicalPath(); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
} catch (IOException e) { | ||
throw new CompilerException( | ||
"Error while getting the canonical path of '" + origFile.getAbsolutePath() + "'.", e ); | ||
"Error while getting the canonical path of '" + origFile.getAbsolutePath() + "'.", e); | ||
} | ||
} | ||
|
||
protected void logCompiling( String[] sourceFiles, CompilerConfiguration config ) | ||
{ | ||
if ( log.isInfoEnabled() ) | ||
{ | ||
String to = ( config.getWorkingDirectory() == null ) ? config.getOutputLocation() : | ||
config.getWorkingDirectory().toPath().relativize( new File( config.getOutputLocation() ).toPath() ).toString(); | ||
log.info( "Compiling " + | ||
( sourceFiles == null ? "" : ( sourceFiles.length + " source file" + ( sourceFiles.length == 1 ? " " : "s " ) ) ) + | ||
"with " + getCompilerId() + " [" + config.describe() + "]" + | ||
" to " + to ); | ||
protected void logCompiling(String[] sourceFiles, CompilerConfiguration config) { | ||
if (log.isInfoEnabled()) { | ||
String to = (config.getWorkingDirectory() == null) | ||
? config.getOutputLocation() | ||
: config.getWorkingDirectory() | ||
.toPath() | ||
.relativize(new File(config.getOutputLocation()).toPath()) | ||
.toString(); | ||
log.info("Compiling " | ||
+ (sourceFiles == null | ||
? "" | ||
: (sourceFiles.length + " source file" + (sourceFiles.length == 1 ? " " : "s "))) | ||
+ "with " | ||
+ getCompilerId() + " [" + config.describe() + "]" + " to " | ||
+ to); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.