diff options
Diffstat (limited to 'src/main/java/net/sf/antcontrib/cpptasks/compiler')
6 files changed, 142 insertions, 112 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractCompiler.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractCompiler.java index c75334d..aa40d0b 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractCompiler.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractCompiler.java @@ -41,12 +41,12 @@ public abstract class AbstractCompiler extends AbstractProcessor Compiler { private static final String[] emptyIncludeArray = new String[0]; private final String outputSuffix; - protected AbstractCompiler(String[] sourceExtensions, - String[] headerExtensions, String outputSuffix) { + protected AbstractCompiler(final String[] sourceExtensions, + final String[] headerExtensions, final String outputSuffix) { super(sourceExtensions, headerExtensions); this.outputSuffix = outputSuffix; } - protected AbstractCompiler(AbstractCompiler cc) { + protected AbstractCompiler(final AbstractCompiler cc) { super(cc); this.outputSuffix = cc.outputSuffix; } @@ -57,11 +57,11 @@ public abstract class AbstractCompiler extends AbstractProcessor * 'tlb', '.res' * */ - protected boolean canParse(File sourceFile) { - String sourceName = sourceFile.toString(); - int lastPeriod = sourceName.lastIndexOf('.'); + protected boolean canParse(final File sourceFile) { + final String sourceName = sourceFile.toString(); + final int lastPeriod = sourceName.lastIndexOf('.'); if (lastPeriod >= 0 && lastPeriod == sourceName.length() - 4) { - String ext = sourceName.substring(lastPeriod).toUpperCase(); + final String ext = sourceName.substring(lastPeriod).toUpperCase(); if (ext.equals(".DLL") || ext.equals(".TLB") || ext.equals(".RES")) { return false; } @@ -72,10 +72,11 @@ public abstract class AbstractCompiler extends AbstractProcessor LinkType linkType, ProcessorDef[] baseConfigs, CompilerDef specificConfig, TargetDef targetPlatform, VersionInfo versionInfo); - public ProcessorConfiguration createConfiguration(CCTask task, - LinkType linkType, ProcessorDef[] baseConfigs, - ProcessorDef specificConfig, TargetDef targetPlatform, - VersionInfo versionInfo) { + @Override + public ProcessorConfiguration createConfiguration(final CCTask task, + final LinkType linkType, final ProcessorDef[] baseConfigs, + final ProcessorDef specificConfig, final TargetDef targetPlatform, + final VersionInfo versionInfo) { if (specificConfig == null) { throw new NullPointerException("specificConfig"); } @@ -83,10 +84,10 @@ public abstract class AbstractCompiler extends AbstractProcessor (CompilerDef) specificConfig, targetPlatform, versionInfo); } abstract protected Parser createParser(File sourceFile); - protected String getBaseOutputName(String inputFile) { + protected String getBaseOutputName(final String inputFile) { int lastSlash = inputFile.lastIndexOf('/'); - int lastReverse = inputFile.lastIndexOf('\\'); - int lastSep = inputFile.lastIndexOf(File.separatorChar); + final int lastReverse = inputFile.lastIndexOf('\\'); + final int lastSep = inputFile.lastIndexOf(File.separatorChar); if (lastReverse > lastSlash) { lastSlash = lastReverse; } @@ -99,12 +100,13 @@ public abstract class AbstractCompiler extends AbstractProcessor } return inputFile.substring(lastSlash + 1, lastPeriod); } - public String[] getOutputFileNames(String inputFile, VersionInfo versionInfo) { + @Override + public String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) { // // if a recognized input file // if (bid(inputFile) > 1) { - String baseName = getBaseOutputName(inputFile); + final String baseName = getBaseOutputName(inputFile); return new String[] { baseName + outputSuffix }; } return new String[0]; @@ -134,40 +136,40 @@ public abstract class AbstractCompiler extends AbstractProcessor * path settings * */ - public final DependencyInfo parseIncludes(CCTask task, File source, - File[] includePath, File[] sysIncludePath, File[] envIncludePath, - File baseDir, String includePathIdentifier) { + public final DependencyInfo parseIncludes(final CCTask task, final File source, + final File[] includePath, final File[] sysIncludePath, final File[] envIncludePath, + final File baseDir, final String includePathIdentifier) { // // if any of the include files can not be identified // change the sourceLastModified to Long.MAX_VALUE to // force recompilation of anything that depends on it long sourceLastModified = source.lastModified(); - File[] sourcePath = new File[1]; + final File[] sourcePath = new File[1]; sourcePath[0] = new File(source.getParent()); - Vector onIncludePath = new Vector(); - Vector onSysIncludePath = new Vector(); + final Vector onIncludePath = new Vector(); + final Vector onSysIncludePath = new Vector(); String baseDirPath; try { baseDirPath = baseDir.getCanonicalPath(); - } catch (IOException ex) { + } catch (final IOException ex) { baseDirPath = baseDir.toString(); } - String relativeSource = CUtil.getRelativePath(baseDirPath, source); + final String relativeSource = CUtil.getRelativePath(baseDirPath, source); String[] includes = emptyIncludeArray; if (canParse(source)) { - Parser parser = createParser(source); + final Parser parser = createParser(source); try { - Reader reader = new BufferedReader(new FileReader(source)); + final Reader reader = new BufferedReader(new FileReader(source)); parser.parse(reader); includes = parser.getIncludes(); - } catch (IOException ex) { + } catch (final IOException ex) { task.log("Error parsing " + source.toString() + ":" + ex.toString()); includes = new String[0]; } } for (int i = 0; i < includes.length; i++) { - String includeName = includes[i]; + final String includeName = includes[i]; if (!resolveInclude(includeName, sourcePath, onIncludePath)) { if (!resolveInclude(includeName, includePath, onIncludePath)) { if (!resolveInclude(includeName, sysIncludePath, @@ -185,22 +187,22 @@ public abstract class AbstractCompiler extends AbstractProcessor } } for (int i = 0; i < onIncludePath.size(); i++) { - String relativeInclude = CUtil.getRelativePath(baseDirPath, + final String relativeInclude = CUtil.getRelativePath(baseDirPath, (File) onIncludePath.elementAt(i)); onIncludePath.setElementAt(relativeInclude, i); } for (int i = 0; i < onSysIncludePath.size(); i++) { - String relativeInclude = CUtil.getRelativePath(baseDirPath, + final String relativeInclude = CUtil.getRelativePath(baseDirPath, (File) onSysIncludePath.elementAt(i)); onSysIncludePath.setElementAt(relativeInclude, i); } return new DependencyInfo(includePathIdentifier, relativeSource, sourceLastModified, onIncludePath, onSysIncludePath); } - protected boolean resolveInclude(String includeName, File[] includePath, - Vector onThisPath) { + protected boolean resolveInclude(final String includeName, final File[] includePath, + final Vector onThisPath) { for (int i = 0; i < includePath.length; i++) { - File includeFile = new File(includePath[i], includeName); + final File includeFile = new File(includePath[i], includeName); if (includeFile.exists()) { onThisPath.addElement(includeFile); return true; diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractLinker.java index 4e81408..1ebd8cf 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/AbstractLinker.java @@ -34,10 +34,10 @@ import org.apache.tools.ant.types.Environment; public abstract class AbstractLinker extends AbstractProcessor implements Linker { - public AbstractLinker(String[] objExtensions, String[] ignoredExtensions) { + public AbstractLinker(final String[] objExtensions, final String[] ignoredExtensions) { super(objExtensions, ignoredExtensions); } - public AbstractLinker(AbstractLinker ld) { + public AbstractLinker(final AbstractLinker ld) { super(ld); } /** @@ -51,8 +51,9 @@ public abstract class AbstractLinker extends AbstractProcessor * processor recognizes the file but doesn't process it (header * files, for example), 100 indicates strong interest */ - public int bid(String inputFile) { - int bid = super.bid(inputFile); + @Override + public int bid(final String inputFile) { + final int bid = super.bid(inputFile); switch (bid) { // // unrecognized extension, take the file @@ -67,25 +68,28 @@ public abstract class AbstractLinker extends AbstractProcessor } return bid; } - public Processor changeEnvironment(boolean newEnvironment, Environment env) { + @Override + public Processor changeEnvironment(final boolean newEnvironment, final Environment env) { return this; } abstract protected LinkerConfiguration createConfiguration(CCTask task, LinkType linkType, ProcessorDef[] baseConfigs, LinkerDef specificConfig, TargetDef targetPlatform, VersionInfo versionInfo); - public ProcessorConfiguration createConfiguration(CCTask task, - LinkType linkType, ProcessorDef[] baseConfigs, - ProcessorDef specificConfig, - TargetDef targetPlatform, - VersionInfo versionInfo) { + @Override + public ProcessorConfiguration createConfiguration(final CCTask task, + final LinkType linkType, final ProcessorDef[] baseConfigs, + final ProcessorDef specificConfig, + final TargetDef targetPlatform, + final VersionInfo versionInfo) { if (specificConfig == null) { throw new NullPointerException("specificConfig"); } return createConfiguration(task, linkType, baseConfigs, (LinkerDef) specificConfig, targetPlatform, versionInfo); } - public String getLibraryKey(File libfile) { + @Override + public String getLibraryKey(final File libfile) { return libfile.getName(); } public abstract String[] getOutputFileNames(String fileName, VersionInfo versionInfo); @@ -102,7 +106,8 @@ public abstract class AbstractLinker extends AbstractProcessor * @param objDir directory for generated files * @param matcher bidded fileset */ - public void addVersionFiles(final VersionInfo versionInfo, + @Override + public void addVersionFiles(final VersionInfo versionInfo, final LinkType linkType, final File outputFile, final boolean isDebug, diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java index 38492ea..1cbfd27 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java @@ -1,5 +1,5 @@ /* - * + * * Copyright 2002-2004 The Ant-Contrib project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,31 +26,31 @@ import net.sf.antcontrib.cpptasks.VersionInfo; import org.apache.tools.ant.BuildException; /** * A configuration for a C++ compiler - * + * * @author Curt Arnold */ public final class CommandLineCompilerConfiguration implements CompilerConfiguration { private/* final */String[] args; - private/* final */CommandLineCompiler compiler; - private String[] endArgs; + private final /* final */CommandLineCompiler compiler; + private final String[] endArgs; // // include path from environment variable not // explicitly stated in Ant script private/* final */File[] envIncludePath; private String[] exceptFiles; - private/* final */String identifier; + private final /* final */String identifier; private/* final */File[] includePath; - private/* final */String includePathIdentifier; - private boolean isPrecompiledHeaderGeneration; + private final /* final */String includePathIdentifier; + private final boolean isPrecompiledHeaderGeneration; private/* final */ProcessorParam[] params; - private/* final */boolean rebuild; + private final /* final */boolean rebuild; private/* final */File[] sysIncludePath; - public CommandLineCompilerConfiguration(CommandLineCompiler compiler, - String identifier, File[] includePath, File[] sysIncludePath, - File[] envIncludePath, String includePathIdentifier, String[] args, - ProcessorParam[] params, boolean rebuild, String[] endArgs) { + public CommandLineCompilerConfiguration(final CommandLineCompiler compiler, + final String identifier, final File[] includePath, final File[] sysIncludePath, + final File[] envIncludePath, final String includePathIdentifier, final String[] args, + final ProcessorParam[] params, final boolean rebuild, final String[] endArgs) { if (compiler == null) { throw new NullPointerException("compiler"); } @@ -63,45 +63,45 @@ public final class CommandLineCompilerConfiguration if (args == null) { this.args = new String[0]; } else { - this.args = (String[]) args.clone(); + this.args = args.clone(); } if (includePath == null) { this.includePath = new File[0]; } else { - this.includePath = (File[]) includePath.clone(); + this.includePath = includePath.clone(); } if (sysIncludePath == null) { this.sysIncludePath = new File[0]; } else { - this.sysIncludePath = (File[]) sysIncludePath.clone(); + this.sysIncludePath = sysIncludePath.clone(); } if (envIncludePath == null) { this.envIncludePath = new File[0]; } else { - this.envIncludePath = (File[]) envIncludePath.clone(); + this.envIncludePath = envIncludePath.clone(); } this.compiler = compiler; - this.params = (ProcessorParam[]) params.clone(); + this.params = params.clone(); this.rebuild = rebuild; this.identifier = identifier; this.includePathIdentifier = includePathIdentifier; - this.endArgs = (String[]) endArgs.clone(); + this.endArgs = endArgs.clone(); exceptFiles = null; isPrecompiledHeaderGeneration = false; } public CommandLineCompilerConfiguration( - CommandLineCompilerConfiguration base, String[] additionalArgs, - String[] exceptFiles, boolean isPrecompileHeaderGeneration) { + final CommandLineCompilerConfiguration base, final String[] additionalArgs, + final String[] exceptFiles, final boolean isPrecompileHeaderGeneration) { compiler = base.compiler; identifier = base.identifier; rebuild = base.rebuild; - includePath = (File[]) base.includePath.clone(); - sysIncludePath = (File[]) base.sysIncludePath.clone(); - endArgs = (String[]) base.endArgs.clone(); - envIncludePath = (File[]) base.envIncludePath.clone(); + includePath = base.includePath.clone(); + sysIncludePath = base.sysIncludePath.clone(); + endArgs = base.endArgs.clone(); + envIncludePath = base.envIncludePath.clone(); includePathIdentifier = base.includePathIdentifier; if (exceptFiles != null) { - this.exceptFiles = (String[]) exceptFiles.clone(); + this.exceptFiles = exceptFiles.clone(); } this.isPrecompiledHeaderGeneration = isPrecompileHeaderGeneration; args = new String[base.args.length + additionalArgs.length]; @@ -113,8 +113,9 @@ public final class CommandLineCompilerConfiguration args[index++] = additionalArgs[i]; } } - public int bid(String inputFile) { - int compilerBid = compiler.bid(inputFile); + @Override + public int bid(final String inputFile) { + final int compilerBid = compiler.bid(inputFile); if (compilerBid > 0 && exceptFiles != null) { for (int i = 0; i < exceptFiles.length; i++) { if (inputFile.equals(exceptFiles[i])) { @@ -124,8 +125,9 @@ public final class CommandLineCompilerConfiguration } return compilerBid; } - public void compile(CCTask task, File outputDir, String[] sourceFiles, - boolean relentless, ProgressMonitor monitor) throws BuildException { + @Override + public void compile(final CCTask task, final File outputDir, final String[] sourceFiles, + final boolean relentless, final ProgressMonitor monitor) throws BuildException { if (monitor != null) { monitor.start(this); } @@ -135,7 +137,7 @@ public final class CommandLineCompilerConfiguration if (monitor != null) { monitor.finish(this, true); } - } catch (BuildException ex) { + } catch (final BuildException ex) { if (monitor != null) { monitor.finish(this, false); } @@ -143,26 +145,27 @@ public final class CommandLineCompilerConfiguration } } /** - * + * * This method may be used to get two distinct compiler configurations, one * for compiling the specified file and producing a precompiled header * file, and a second for compiling other files using the precompiled * header file. - * + * * The last (preferrably only) include directive in the prototype file will * be used to mark the boundary between pre-compiled and normally compiled * headers. - * + * * @param prototype * A source file (for example, stdafx.cpp) that is used to build * the precompiled header file. @returns null if precompiled * headers are not supported or a two element array containing * the precompiled header generation configuration and the * consuming configuration - * + * */ + @Override public CompilerConfiguration[] createPrecompileConfigurations( - File prototype, String[] nonPrecompiledFiles) { + final File prototype, final String[] nonPrecompiledFiles) { if (compiler instanceof PrecompilingCompiler) { return ((PrecompilingCompiler) compiler) .createPrecompileConfigurations(this, prototype, @@ -175,47 +178,56 @@ public final class CommandLineCompilerConfiguration * canonical so that equivalent configurations will have equivalent string * representations */ + @Override public String getIdentifier() { return identifier; } + @Override public String getIncludePathIdentifier() { return includePathIdentifier; } - public String[] getOutputFileNames(String inputFile, VersionInfo versionInfo) { + @Override + public final String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) { return compiler.getOutputFileNames(inputFile, versionInfo); } - public CompilerParam getParam(String name) { + @Override + public CompilerParam getParam(final String name) { for (int i = 0; i < params.length; i++) { if (name.equals(params[i].getName())) return (CompilerParam) params[i]; } return null; } + @Override public ProcessorParam[] getParams() { return params; } + @Override public boolean getRebuild() { return rebuild; } + @Override public boolean isPrecompileGeneration() { return isPrecompiledHeaderGeneration; } - public DependencyInfo parseIncludes(CCTask task, File baseDir, File source) { + @Override + public DependencyInfo parseIncludes(final CCTask task, final File baseDir, final File source) { return compiler.parseIncludes(task, source, includePath, sysIncludePath, envIncludePath, baseDir, getIncludePathIdentifier()); } + @Override public String toString() { return identifier; } public String[] getPreArguments() { - return (String[]) args.clone(); + return args.clone(); } public String[] getEndArguments() { - return (String[]) endArgs.clone(); + return endArgs.clone(); } public File[] getIncludePath() { - return (File[]) includePath.clone(); + return includePath.clone(); } public Compiler getCompiler() { return compiler; diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java index 321bd29..24aa0d4 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinker.java @@ -105,6 +105,7 @@ public abstract class CommandLineLinker extends AbstractLinker protected abstract void addStack(int stack, Vector args); protected abstract void addEntry(String entry, Vector args); + @Override protected LinkerConfiguration createConfiguration( final CCTask task, final LinkType linkType, @@ -215,7 +216,8 @@ public abstract class CommandLineLinker extends AbstractLinker protected abstract String getCommandFileSwitch(String commandFile); - public String getIdentifier() { + @Override + public String getIdentifier() { if(identifier == null) { if (identifierArg == null) { identifier = getIdentifier(new String[] { command }, command); diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinkerConfiguration.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinkerConfiguration.java index f0aad67..bc66648 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinkerConfiguration.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/CommandLineLinkerConfiguration.java @@ -1,5 +1,5 @@ /* - * + * * Copyright 2002-2004 The Ant-Contrib project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,35 +24,35 @@ import net.sf.antcontrib.cpptasks.VersionInfo; import org.apache.tools.ant.BuildException; /** * A configuration for a command line linker - * + * * @author Curt Arnold */ public final class CommandLineLinkerConfiguration implements LinkerConfiguration { private/* final */String[][] args; - private/* final */String identifier; + private final /* final */String identifier; private String[] libraryNames; - private/* final */CommandLineLinker linker; - private/* final */boolean map; - private/* final */ProcessorParam[] params; - private/* final */boolean rebuild; - private boolean debug; - private String startupObject; - public CommandLineLinkerConfiguration(CommandLineLinker linker, - String identifier, String[][] args, ProcessorParam[] params, - boolean rebuild, boolean map, boolean debug, String[] libraryNames, - String startupObject) { + private final /* final */CommandLineLinker linker; + private final /* final */boolean map; + private final /* final */ProcessorParam[] params; + private final /* final */boolean rebuild; + private final boolean debug; + private final String startupObject; + public CommandLineLinkerConfiguration(final CommandLineLinker linker, + final String identifier, final String[][] args, final ProcessorParam[] params, + final boolean rebuild, final boolean map, final boolean debug, final String[] libraryNames, + final String startupObject) { if (linker == null) { throw new NullPointerException("linker"); } if (args == null) { throw new NullPointerException("args"); } else { - this.args = (String[][]) args.clone(); + this.args = args.clone(); } this.linker = linker; - this.params = (ProcessorParam[]) params.clone(); + this.params = params.clone(); this.rebuild = rebuild; this.identifier = identifier; this.map = map; @@ -60,15 +60,16 @@ public final class CommandLineLinkerConfiguration if (libraryNames == null) { this.libraryNames = new String[0]; } else { - this.libraryNames = (String[]) libraryNames.clone(); + this.libraryNames = libraryNames.clone(); } this.startupObject = startupObject; } - public int bid(String filename) { + @Override + public int bid(final String filename) { return linker.bid(filename); } public String[] getEndArguments() { - String[] clone = (String[]) args[1].clone(); + final String[] clone = args[1].clone(); return clone; } /** @@ -76,17 +77,19 @@ public final class CommandLineLinkerConfiguration * canonical so that equivalent configurations will have equivalent string * representations */ + @Override public String getIdentifier() { return identifier; } public String[] getLibraryNames() { - String[] clone = (String[]) libraryNames.clone(); + final String[] clone = libraryNames.clone(); return clone; } public boolean getMap() { return map; } - public String[] getOutputFileNames(String inputFile, VersionInfo versionInfo) { + @Override + public final String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) { return linker.getOutputFileNames(inputFile, versionInfo); } public LinkerParam getParam(String name) { @@ -96,32 +99,38 @@ public final class CommandLineLinkerConfiguration } return null; } + @Override public ProcessorParam[] getParams() { return params; } public String[] getPreArguments() { - String[] clone = (String[]) args[0].clone(); + final String[] clone = args[0].clone(); return clone; } + @Override public boolean getRebuild() { return rebuild; } public String getStartupObject() { return startupObject; } - public void link(CCTask task, TargetInfo linkTarget) throws BuildException { + @Override + public void link(final CCTask task, final TargetInfo linkTarget) throws BuildException { // // AllSourcePath's include any syslibsets // - String[] sourcePaths = linkTarget.getAllSourcePaths(); + final String[] sourcePaths = linkTarget.getAllSourcePaths(); linker.link(task, linkTarget.getOutput(), sourcePaths, this); } + @Override public String toString() { return identifier; } + @Override public Linker getLinker() { return linker; } + @Override public boolean isDebug() { return debug; } diff --git a/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkerConfiguration.java b/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkerConfiguration.java index ff7ac5d..114b8f1 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkerConfiguration.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/compiler/LinkerConfiguration.java @@ -1,5 +1,5 @@ /* - * + * * Copyright 2002-2004 The Ant-Contrib project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ import net.sf.antcontrib.cpptasks.TargetInfo; import org.apache.tools.ant.BuildException; /** * A configuration for a linker - * + * * @author Curt Arnold */ public interface LinkerConfiguration extends ProcessorConfiguration { |