Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs.compilers

public abstract Class DefaultCompilerAdapter

extends Object
implements CompilerAdapter, CompilerAdapterExtension
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.compilers.CompilerAdapterExtension, org.apache.tools.ant.taskdefs.compilers.CompilerAdapter
Known Direct Subclasses
org.apache.tools.ant.taskdefs.compilers.Gcj, org.apache.tools.ant.taskdefs.compilers.Javac12, org.apache.tools.ant.taskdefs.compilers.Javac13, org.apache.tools.ant.taskdefs.compilers.JavacExternal, org.apache.tools.ant.taskdefs.compilers.Jikes, org.apache.tools.ant.taskdefs.compilers.Jvc, org.apache.tools.ant.taskdefs.compilers.Kjc, org.apache.tools.ant.taskdefs.compilers.Sj
Imports
java.io.BufferedWriter, .File, .FileWriter, .IOException, java.util.Optional, java.util.regex.Pattern, java.util.stream.Collectors, .Stream, org.apache.tools.ant.BuildException, .Location, .Project, org.apache.tools.ant.taskdefs.Execute, .Javac, .LogStreamHandler, org.apache.tools.ant.taskdefs.condition.Os, org.apache.tools.ant.types.Commandline, .Path, org.apache.tools.ant.util.FileUtils, .JavaEnvUtils, .StringUtils

This is the default implementation for the CompilerAdapter interface. Currently, this is a cut-and-paste of the original javac task.
Since
Ant 1.3

Field Summary

Modifier and TypeField and Description
protected Javac
protected Path
private static final int
protected Path
protected File[]
protected Path
protected boolean
protected boolean
protected boolean
protected File
protected String
protected Path
private static final FileUtils
protected boolean
protected boolean
private static final Pattern
protected Location
protected static final String
lSep

Deprecated
protected String
protected String
protected Path
protected Path
protected boolean
protected Project
protected String
protected Path
protected String
protected Path
protected boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
addCurrentCompilerArgs(final Commandline
the command line to use
cmd
)

Adds the command line arguments specific to the current implementation.

protected void
addExtdirsToClasspath(final Path
the classpath to use
classpath
)

Deprecated since 1.5.x. Use org.apache.tools.ant.types.Path#addExtdirs instead.
Add extdirs to classpath
private String
adjustSourceValue(final String source)

Turn the task's attribute for -source into something that is understood by all javac's after 1.4.

protected boolean

Returns:

true if JDK 10+
assumeJava10Plus
()

Shall we assume JDK 10+ command line switches?

protected boolean

Returns:

true if jdk 1.1
assumeJava11
()

Deprecated since Ant 1.10.7, use assumeJava1_1Plus, if necessary combined with !assumeJava1_2Plus
Shall we assume JDK 1.1 command line switches?
protected boolean

Returns:

true if jdk 1.2
assumeJava12
()

Deprecated since Ant 1.10.7, use assumeJava1_2Plus, if necessary combined with !assumeJava1_3Plus
Shall we assume JDK 1.2 command line switches?
protected boolean

Returns:

true if jdk 1.3
assumeJava13
()

Deprecated since Ant 1.10.7, use assumeJava1_3Plus, if necessary combined with !assumeJava1_4Plus
Shall we assume JDK 1.3 command line switches?
protected boolean

Returns:

true if jdk 1.4
assumeJava14
()

Deprecated since Ant 1.10.7, use assumeJava1_4Plus, if necessary combined with !assumeJava1_5Plus
Shall we assume JDK 1.4 command line switches?
protected boolean

Returns:

true if JDK 1.5
assumeJava15
()

Deprecated since Ant 1.10.7, use assumeJava1_5Plus, if necessary combined with !assumeJava1_6Plus
Shall we assume JDK 1.5 command line switches?
protected boolean

Returns:

true if JDK 1.6
assumeJava16
()

Deprecated since Ant 1.10.7, use assumeJava1_6Plus, if necessary combined with !assumeJava1_7Plus
Shall we assume JDK 1.6 command line switches?
protected boolean

Returns:

true if JDK 1.7
assumeJava17
()

Deprecated since Ant 1.10.7, use assumeJava1_7Plus, if necessary combined with !assumeJava1_8Plus
Shall we assume JDK 1.7 command line switches?
protected boolean

Returns:

true if JDK 1.8
assumeJava18
()

Deprecated since Ant 1.10.7, use assumeJava1_8Plus, if necessary combined with !assumeJava9Plus
Shall we assume JDK 1.8 command line switches?
protected boolean

Returns:

true if JDK 9
assumeJava19
()

Deprecated use #assumeJava9 instead
Shall we assume JDK 9 command line switches?
protected boolean

Returns:

true if jdk 1.1 and above
assumeJava1_1Plus
()

Shall we assume JDK 1.1+ command line switches?

protected boolean

Returns:

true if jdk 1.2 and above
assumeJava1_2Plus
()

Shall we assume JDK 1.2+ command line switches?

protected boolean

Returns:

true if jdk 1.3 and above
assumeJava1_3Plus
()

Shall we assume JDK 1.3+ command line switches?

protected boolean

Returns:

true if jdk 1.4 and above
assumeJava1_4Plus
()

Shall we assume JDK 1.4+ command line switches?

protected boolean

Returns:

true if jdk 1.5 and above
assumeJava1_5Plus
()

Shall we assume JDK 1.5+ command line switches?

protected boolean

Returns:

true if jdk 1.6 and above
assumeJava1_6Plus
()

Shall we assume JDK 1.6+ command line switches?

protected boolean

Returns:

true if jdk 1.7 and above
assumeJava1_7Plus
()

Shall we assume JDK 1.7+ command line switches?

protected boolean

Returns:

true if jdk 1.8 and above
assumeJava1_8Plus
()

Shall we assume JDK 1.8+ command line switches?

protected boolean

Returns:

true if JDK 9
assumeJava9
()

Deprecated since Ant 1.10.7, use assumeJava9Plus, in the future if necessary combined with !assumeJava10Plus
Shall we assume JDK 9 command line switches?
protected boolean

Returns:

true if JDK 9+
assumeJava9Plus
()

Shall we assume JDK 9+ command line switches?

private boolean
assumeJavaXY(final String javacXY, final String javaEnvVersionXY)

Shall we assume command line switches for the given version of Java?

protected int

Returns:

the exit code of the compilation
executeExternalCompile
(final String[]
- arguments to pass to process on command line
args
,
final int
- index of the first source file in args, if the index is negative, no temporary file will ever be created, but this may hit the command line length limit on your system.
firstFileName
)

Do the compile with the specified arguments.

protected int

Returns:

the exit code of the compilation
executeExternalCompile
(final String[]
- arguments to pass to process on command line
args
,
final int
- index of the first source file in args, if the index is negative, no temporary file will ever be created, but this may hit the command line length limit on your system.
firstFileName
,
final boolean
- if set to true, filenames containing spaces will be quoted when they appear in the external file. This is necessary when running JDK 1.4's javac and probably others.
quoteFiles
)

Do the compile with the specified arguments.

protected Path

Returns:

a non-null Path instance that combines the user specified and the system bootclasspath.
getBootClassPath
()

Combines a user specified bootclasspath with the system bootclasspath taking build.sysclasspath into account.

protected Path

Returns:

the compilation class path
getCompileClasspath
()

Builds the compilation classpath.

private String
getDefaultSource()

A string that describes the default value for -source of the selected JDK's javac.

public Javac

Returns:

the configured Javac task instance used by this adapter.
getJavac
()

Get the Javac task instance associated with this compiler adapter

protected Path

Returns:

the modulepath
getModulepath
()

Builds the modulepath.

protected Path

Returns:

the modulesourcepath
getModulesourcepath
()

Builds the modulesourcepath for multi module compilation.

protected String

Returns:

"-g:none" unless we expect to invoke a JDK 1.1 compiler.
getNoDebugArgument
()

The argument the compiler wants to see if the debug attribute has been set to false.

protected Project

Returns:

the owner project
getProject
()

Get the project this compiler adapter was created in.

public String[]
getSupportedFileExtensions()

Implements org.apache.tools.ant.taskdefs.compilers.CompilerAdapterExtension.getSupportedFileExtensions.

By default, only recognize files with a Java extension, but specialized compilers can recognize multiple kinds of files.
protected Path

Returns:

the upgrademodulepath
getUpgrademodulepath
()

Builds the upgrademodulepath.

protected void
logAndAddFilesToCompile(final Commandline
the command line
cmd
)

Logs the compilation parameters, adds the files to compile and logs the "niceSourceList"

private boolean
mustSetSourceForTarget(String
the -target value, must not be null
t
)

Whether the selected -target is known to be incompatible with the default -source value of the selected JDK's javac.

private void
setImplicitSourceSwitch(final Commandline cmd, final String target, final String source)

public void
setJavac(final Javac
a configured Javac task.
attributes
)

Implements org.apache.tools.ant.taskdefs.compilers.CompilerAdapter.setJavac.

Set the Javac instance which contains the configured compilation attributes.
protected Commandline

Returns:

the command line
setupJavacCommand
()

Set up the command line.

protected Commandline

Returns:

the command line
setupJavacCommand
(final boolean
if true set the debug level with the -g switch
debugLevelCheck
)

Does the command line argument processing for classic and adds the files to compile as well.

protected Commandline

Returns:

the command line
setupJavacCommandlineSwitches
(final Commandline
the command line
cmd
)

Get the command line arguments for the switches.

protected Commandline

Returns:

the command line
setupJavacCommandlineSwitches
(final Commandline
the command line
cmd
,
final boolean
if true set set the debug level with the -g switch
useDebugLevel
)

Does the command line argument processing common to classic and modern.

protected Commandline

Returns:

the command line
setupModernJavacCommand
()

Does the command line argument processing for modern and adds the files to compile as well.

protected Commandline

Returns:

the command line
setupModernJavacCommandlineSwitches
(final Commandline
the command line
cmd
)

Does the command line argument processing for modern.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
protected Javac attributes
bootclasspathback to summary
protected Path bootclasspath
COMMAND_LINE_LIMITback to summary
private static final int COMMAND_LINE_LIMIT
compileClasspathback to summary
protected Path compileClasspath
compileListback to summary
protected File[] compileList
compileSourcepathback to summary
protected Path compileSourcepath
debugback to summary
protected boolean debug
dependback to summary
protected boolean depend
deprecationback to summary
protected boolean deprecation
destDirback to summary
protected File destDir
encodingback to summary
protected String encoding
extdirsback to summary
protected Path extdirs
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
includeAntRuntimeback to summary
protected boolean includeAntRuntime
includeJavaRuntimeback to summary
protected boolean includeJavaRuntime
JAVAC_ARG_FILE_CHARS_TO_QUOTEback to summary
private static final Pattern JAVAC_ARG_FILE_CHARS_TO_QUOTE
locationback to summary
protected Location location
lSepback to summary
protected static final String lSep

Deprecated

Annotations
@Deprecated
memoryInitialSizeback to summary
protected String memoryInitialSize
memoryMaximumSizeback to summary
protected String memoryMaximumSize
modulepathback to summary
protected Path modulepath
moduleSourcepathback to summary
protected Path moduleSourcepath
optimizeback to summary
protected boolean optimize
projectback to summary
protected Project project
releaseback to summary
protected String release
srcback to summary
protected Path src
targetback to summary
protected String target
upgrademodulepathback to summary
protected Path upgrademodulepath
verboseback to summary
protected boolean verbose

Constructor Detail

DefaultCompilerAdapterback to summary
public DefaultCompilerAdapter()

Method Detail

addCurrentCompilerArgsback to summary
protected void addCurrentCompilerArgs(final Commandline cmd)

Adds the command line arguments specific to the current implementation.

Parameters
cmd:Commandline

the command line to use

addExtdirsToClasspathback to summary
protected void addExtdirsToClasspath(final Path classpath)

Deprecated

since 1.5.x. Use org.apache.tools.ant.types.Path#addExtdirs instead.

Add extdirs to classpath

Parameters
classpath:Path

the classpath to use

Annotations
@Deprecated
adjustSourceValueback to summary
private String adjustSourceValue(final String source)

Turn the task's attribute for -source into something that is understood by all javac's after 1.4.

support for -source 1.1 and -source 1.2 has been added with JDK 1.4.2 but isn't present in 1.5.0+

assumeJava10Plusback to summary
protected boolean assumeJava10Plus()

Shall we assume JDK 10+ command line switches?

Returns:boolean

true if JDK 10+

Since
Ant 1.10.7
assumeJava11back to summary
protected boolean assumeJava11()

Deprecated

since Ant 1.10.7, use assumeJava1_1Plus, if necessary combined with !assumeJava1_2Plus

Shall we assume JDK 1.1 command line switches?

Returns:boolean

true if jdk 1.1

Annotations
@Deprecated
Since
Ant 1.5
assumeJava12back to summary
protected boolean assumeJava12()

Deprecated

since Ant 1.10.7, use assumeJava1_2Plus, if necessary combined with !assumeJava1_3Plus

Shall we assume JDK 1.2 command line switches?

Returns:boolean

true if jdk 1.2

Annotations
@Deprecated
Since
Ant 1.5
assumeJava13back to summary
protected boolean assumeJava13()

Deprecated

since Ant 1.10.7, use assumeJava1_3Plus, if necessary combined with !assumeJava1_4Plus

Shall we assume JDK 1.3 command line switches?

Returns:boolean

true if jdk 1.3

Annotations
@Deprecated
Since
Ant 1.5
assumeJava14back to summary
protected boolean assumeJava14()

Deprecated

since Ant 1.10.7, use assumeJava1_4Plus, if necessary combined with !assumeJava1_5Plus

Shall we assume JDK 1.4 command line switches?

Returns:boolean

true if jdk 1.4

Annotations
@Deprecated
Since
Ant 1.6.3
assumeJava15back to summary
protected boolean assumeJava15()

Deprecated

since Ant 1.10.7, use assumeJava1_5Plus, if necessary combined with !assumeJava1_6Plus

Shall we assume JDK 1.5 command line switches?

Returns:boolean

true if JDK 1.5

Annotations
@Deprecated
Since
Ant 1.6.3
assumeJava16back to summary
protected boolean assumeJava16()

Deprecated

since Ant 1.10.7, use assumeJava1_6Plus, if necessary combined with !assumeJava1_7Plus

Shall we assume JDK 1.6 command line switches?

Returns:boolean

true if JDK 1.6

Annotations
@Deprecated
Since
Ant 1.7
assumeJava17back to summary
protected boolean assumeJava17()

Deprecated

since Ant 1.10.7, use assumeJava1_7Plus, if necessary combined with !assumeJava1_8Plus

Shall we assume JDK 1.7 command line switches?

Returns:boolean

true if JDK 1.7

Annotations
@Deprecated
Since
Ant 1.8.2
assumeJava18back to summary
protected boolean assumeJava18()

Deprecated

since Ant 1.10.7, use assumeJava1_8Plus, if necessary combined with !assumeJava9Plus

Shall we assume JDK 1.8 command line switches?

Returns:boolean

true if JDK 1.8

Annotations
@Deprecated
Since
Ant 1.8.3
assumeJava19back to summary
protected boolean assumeJava19()

Deprecated

use #assumeJava9 instead

Shall we assume JDK 9 command line switches?

Returns:boolean

true if JDK 9

Annotations
@Deprecated
Since
Ant 1.9.4
assumeJava1_1Plusback to summary
protected boolean assumeJava1_1Plus()

Shall we assume JDK 1.1+ command line switches?

Returns:boolean

true if jdk 1.1 and above

Since
Ant 1.10.7
assumeJava1_2Plusback to summary
protected boolean assumeJava1_2Plus()

Shall we assume JDK 1.2+ command line switches?

Returns:boolean

true if jdk 1.2 and above

Since
Ant 1.10.7
assumeJava1_3Plusback to summary
protected boolean assumeJava1_3Plus()

Shall we assume JDK 1.3+ command line switches?

Returns:boolean

true if jdk 1.3 and above

Since
Ant 1.10.7
assumeJava1_4Plusback to summary
protected boolean assumeJava1_4Plus()

Shall we assume JDK 1.4+ command line switches?

Returns:boolean

true if jdk 1.4 and above

Since
Ant 1.10.7
assumeJava1_5Plusback to summary
protected boolean assumeJava1_5Plus()

Shall we assume JDK 1.5+ command line switches?

Returns:boolean

true if jdk 1.5 and above

Since
Ant 1.10.7
assumeJava1_6Plusback to summary
protected boolean assumeJava1_6Plus()

Shall we assume JDK 1.6+ command line switches?

Returns:boolean

true if jdk 1.6 and above

Since
Ant 1.10.7
assumeJava1_7Plusback to summary
protected boolean assumeJava1_7Plus()

Shall we assume JDK 1.7+ command line switches?

Returns:boolean

true if jdk 1.7 and above

Since
Ant 1.10.7
assumeJava1_8Plusback to summary
protected boolean assumeJava1_8Plus()

Shall we assume JDK 1.8+ command line switches?

Returns:boolean

true if jdk 1.8 and above

Since
Ant 1.10.7
assumeJava9back to summary
protected boolean assumeJava9()

Deprecated

since Ant 1.10.7, use assumeJava9Plus, in the future if necessary combined with !assumeJava10Plus

Shall we assume JDK 9 command line switches?

Returns:boolean

true if JDK 9

Annotations
@Deprecated
Since
Ant 1.9.8
assumeJava9Plusback to summary
protected boolean assumeJava9Plus()

Shall we assume JDK 9+ command line switches?

Returns:boolean

true if JDK 9+

Since
Ant 1.10.2
assumeJavaXYback to summary
private boolean assumeJavaXY(final String javacXY, final String javaEnvVersionXY)

Shall we assume command line switches for the given version of Java?

Since
Ant 1.8.3
executeExternalCompileback to summary
protected int executeExternalCompile(final String[] args, final int firstFileName)

Do the compile with the specified arguments.

Parameters
args:String[]

- arguments to pass to process on command line

firstFileName:int

- index of the first source file in args, if the index is negative, no temporary file will ever be created, but this may hit the command line length limit on your system.

Returns:int

the exit code of the compilation

executeExternalCompileback to summary
protected int executeExternalCompile(final String[] args, final int firstFileName, final boolean quoteFiles)

Do the compile with the specified arguments.

The working directory if the executed process will be the project's base directory.

Parameters
args:String[]

- arguments to pass to process on command line

firstFileName:int

- index of the first source file in args, if the index is negative, no temporary file will ever be created, but this may hit the command line length limit on your system.

quoteFiles:boolean

- if set to true, filenames containing spaces will be quoted when they appear in the external file. This is necessary when running JDK 1.4's javac and probably others.

Returns:int

the exit code of the compilation

Since
Ant 1.6
getBootClassPathback to summary
protected Path getBootClassPath()

Combines a user specified bootclasspath with the system bootclasspath taking build.sysclasspath into account.

Returns:Path

a non-null Path instance that combines the user specified and the system bootclasspath.

getCompileClasspathback to summary
protected Path getCompileClasspath()

Builds the compilation classpath.

Returns:Path

the compilation class path

getDefaultSourceback to summary
private String getDefaultSource()

A string that describes the default value for -source of the selected JDK's javac.

getJavacback to summary
public Javac getJavac()

Get the Javac task instance associated with this compiler adapter

Returns:Javac

the configured Javac task instance used by this adapter.

getModulepathback to summary
protected Path getModulepath()

Builds the modulepath.

Returns:Path

the modulepath

Since
1.9.7
getModulesourcepathback to summary
protected Path getModulesourcepath()

Builds the modulesourcepath for multi module compilation.

Returns:Path

the modulesourcepath

Since
1.9.7
getNoDebugArgumentback to summary
protected String getNoDebugArgument()

The argument the compiler wants to see if the debug attribute has been set to false.

A return value of null means no argument at all.

Returns:String

"-g:none" unless we expect to invoke a JDK 1.1 compiler.

Since
Ant 1.6.3
getProjectback to summary
protected Project getProject()

Get the project this compiler adapter was created in.

Returns:Project

the owner project

Since
Ant 1.6
getSupportedFileExtensionsback to summary
public String[] getSupportedFileExtensions()

Implements org.apache.tools.ant.taskdefs.compilers.CompilerAdapterExtension.getSupportedFileExtensions.

By default, only recognize files with a Java extension, but specialized compilers can recognize multiple kinds of files.

Returns:String[]

Doc from org.apache.tools.ant.taskdefs.compilers.CompilerAdapterExtension.getSupportedFileExtensions.

list of source file extensions recognized by this compiler adapter.

Annotations
@Override
getUpgrademodulepathback to summary
protected Path getUpgrademodulepath()

Builds the upgrademodulepath.

Returns:Path

the upgrademodulepath

Since
1.9.7
logAndAddFilesToCompileback to summary
protected void logAndAddFilesToCompile(final Commandline cmd)

Logs the compilation parameters, adds the files to compile and logs the "niceSourceList"

Parameters
cmd:Commandline

the command line

mustSetSourceForTargetback to summary
private boolean mustSetSourceForTarget(String t)

Whether the selected -target is known to be incompatible with the default -source value of the selected JDK's javac.

Assumes it will never be called unless the selected JDK is at least Java 1.5.

Parameters
t:String

the -target value, must not be null

setImplicitSourceSwitchback to summary
private void setImplicitSourceSwitch(final Commandline cmd, final String target, final String source)
setJavacback to summary
public void setJavac(final Javac attributes)

Implements org.apache.tools.ant.taskdefs.compilers.CompilerAdapter.setJavac.

Set the Javac instance which contains the configured compilation attributes.

Parameters
attributes:Javac

a configured Javac task.

Annotations
@Override
setupJavacCommandback to summary
protected Commandline setupJavacCommand()

Set up the command line.

Returns:Commandline

the command line

setupJavacCommandback to summary
protected Commandline setupJavacCommand(final boolean debugLevelCheck)

Does the command line argument processing for classic and adds the files to compile as well.

Parameters
debugLevelCheck:boolean

if true set the debug level with the -g switch

Returns:Commandline

the command line

setupJavacCommandlineSwitchesback to summary
protected Commandline setupJavacCommandlineSwitches(final Commandline cmd)

Get the command line arguments for the switches.

Parameters
cmd:Commandline

the command line

Returns:Commandline

the command line

setupJavacCommandlineSwitchesback to summary
protected Commandline setupJavacCommandlineSwitches(final Commandline cmd, final boolean useDebugLevel)

Does the command line argument processing common to classic and modern. Doesn't add the files to compile.

Parameters
cmd:Commandline

the command line

useDebugLevel:boolean

if true set set the debug level with the -g switch

Returns:Commandline

the command line

setupModernJavacCommandback to summary
protected Commandline setupModernJavacCommand()

Does the command line argument processing for modern and adds the files to compile as well.

Returns:Commandline

the command line

setupModernJavacCommandlineSwitchesback to summary
protected Commandline setupModernJavacCommandlineSwitches(final Commandline cmd)

Does the command line argument processing for modern. Doesn't add the files to compile.

Parameters
cmd:Commandline

the command line

Returns:Commandline

the command line