Skip to content

Commit

Permalink
Reformat using spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 28, 2023
1 parent ed05eae commit c255bca
Show file tree
Hide file tree
Showing 67 changed files with 3,851 additions and 5,066 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:jason@maven.org">Jason van Zyl </a>
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka </a>
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;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;

Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}
}
}
}
Loading

0 comments on commit c255bca

Please sign in to comment.