Package org.apache.maven.plugin.ant
Class AntBuildWriter
- java.lang.Object
-
- org.apache.maven.plugin.ant.AntBuildWriter
-
public class AntBuildWriter extends java.lang.Object
Write Ant build files fromMaven Project
for Ant 1.6.2 or above:- build.xml
- maven-build.xml
- maven-build.properties
- Version:
- $Id: AntBuildWriter.java 1645084 2014-12-12 22:28:31Z khmarbaise $
-
-
Field Summary
Fields Modifier and Type Field Description private ArtifactResolverWrapper
artifactResolverWrapper
protected static java.lang.String
DEFAULT_BUILD_FILENAME
The default build file name (build.xml)protected static int
DEFAULT_INDENTATION_SIZE
The default line indenterprotected static java.lang.String
DEFAULT_MAVEN_BUILD_FILENAME
The default generated build file nameprotected static java.lang.String
DEFAULT_MAVEN_PROPERTIES_FILENAME
The default build properties file nameprivate java.util.Properties
executionProperties
private java.io.File
localRepository
private boolean
overwrite
private org.apache.maven.project.MavenProject
project
private org.apache.maven.settings.Settings
settings
-
Constructor Summary
Constructors Constructor Description AntBuildWriter(org.apache.maven.project.MavenProject project, ArtifactResolverWrapper artifactResolverWrapper, org.apache.maven.settings.Settings settings, boolean overwrite, java.util.Properties executionProperties)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
addProperty(java.util.Properties properties, java.lang.String name, java.lang.String value)
Put a property in properties defined by a name and a valueprivate static java.lang.String
getCommaSeparatedList(java.util.Map[] includes, java.lang.String key)
private java.lang.String
getLocalRepositoryPath()
Check if the local repository is in the default location:${user.home}/.m2/repository
.(package private) static java.lang.String
getProjectRepoDirectory(java.lang.String repoUrl, java.lang.String projectDir)
Gets the relative path to a repository that is rooted in the project.private static java.util.List
getSelectorList(java.util.Map[] options)
Flattens the specified file selector options into a simple string list.private java.util.List
getTestExcludes()
Gets the exclude patterns for the unit tests.private java.util.List
getTestIncludes()
Gets the include patterns for the unit tests.private java.lang.String
getUninterpolatedSystemPath(org.apache.maven.artifact.Artifact artifact)
private void
writeBuildPathDefinition(org.codehaus.plexus.util.xml.XMLWriter writer)
Write path definition in the writer only for a non-POM project.private void
writeBuildPathDefinition(org.codehaus.plexus.util.xml.XMLWriter writer, java.lang.String id, java.util.List artifacts)
protected void
writeBuildProperties()
Generatemaven-build.properties
only for a non-POM projectprivate void
writeBuildXml()
Generate an genericbuild.xml
if not already existprotected void
writeBuildXmls()
Generate Ant build XML filesprivate void
writeCleanTarget(org.codehaus.plexus.util.xml.XMLWriter writer)
Write clean target in the writer depending the packaging of the project.private void
writeCompileTarget(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List compileSourceRoots)
Write compile target in the writer depending the packaging of the project.private void
writeCompileTasks(org.codehaus.plexus.util.xml.XMLWriter writer, java.lang.String outputDirectory, java.util.List compileSourceRoots, java.util.List resources, java.lang.String additionalClassesDirectory, boolean isTest)
private void
writeCompileTestsTarget(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List testCompileSourceRoots)
Write compile-test target in the writer depending the packaging of the project.private void
writeGeneratedBuildXml()
Generate anmaven-build.xml
private void
writeGetDepsTarget(org.codehaus.plexus.util.xml.XMLWriter writer)
Write get-deps target in the writer only for a non-POM projectprivate void
writeJavadocTarget(org.codehaus.plexus.util.xml.XMLWriter writer)
Write javadoc target in the writer depending the packaging of the project.private void
writePackageTarget(org.codehaus.plexus.util.xml.XMLWriter writer)
Write package target in the writer depending the packaging of the project.private void
writePomParts(org.codehaus.plexus.util.xml.XMLWriter writer)
private void
writeProperties(org.codehaus.plexus.util.xml.XMLWriter writer)
Write properties in the writer only for a non-POM project.private void
writeTestFilesets(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List testCompileSourceRoots, java.util.List includes, java.util.List excludes)
Write the<fileset>
elements for the test compile source roots.private void
writeTestTargets(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List testCompileSourceRoots)
Write test target in the writer depending the packaging of the project.
-
-
-
Field Detail
-
DEFAULT_INDENTATION_SIZE
protected static final int DEFAULT_INDENTATION_SIZE
The default line indenter- See Also:
- Constant Field Values
-
DEFAULT_BUILD_FILENAME
protected static final java.lang.String DEFAULT_BUILD_FILENAME
The default build file name (build.xml)- See Also:
- Constant Field Values
-
DEFAULT_MAVEN_BUILD_FILENAME
protected static final java.lang.String DEFAULT_MAVEN_BUILD_FILENAME
The default generated build file name- See Also:
- Constant Field Values
-
DEFAULT_MAVEN_PROPERTIES_FILENAME
protected static final java.lang.String DEFAULT_MAVEN_PROPERTIES_FILENAME
The default build properties file name- See Also:
- Constant Field Values
-
project
private final org.apache.maven.project.MavenProject project
-
artifactResolverWrapper
private final ArtifactResolverWrapper artifactResolverWrapper
-
localRepository
private final java.io.File localRepository
-
settings
private final org.apache.maven.settings.Settings settings
-
overwrite
private final boolean overwrite
-
executionProperties
private final java.util.Properties executionProperties
-
-
Constructor Detail
-
AntBuildWriter
public AntBuildWriter(org.apache.maven.project.MavenProject project, ArtifactResolverWrapper artifactResolverWrapper, org.apache.maven.settings.Settings settings, boolean overwrite, java.util.Properties executionProperties)
- Parameters:
project
-MavenProject
artifactResolverWrapper
-ArtifactResolverWrapper
settings
-Settings
overwrite
- true/false to overwrite or not.executionProperties
-Properties
-
-
Method Detail
-
writeBuildXmls
protected void writeBuildXmls() throws java.io.IOException
Generate Ant build XML files- Throws:
java.io.IOException
- In case of an error.
-
writeBuildProperties
protected void writeBuildProperties() throws java.io.IOException
Generatemaven-build.properties
only for a non-POM project- Throws:
java.io.IOException
- In case of an failureIOException
- See Also:
DEFAULT_MAVEN_PROPERTIES_FILENAME
-
writeGeneratedBuildXml
private void writeGeneratedBuildXml() throws java.io.IOException
Generate anmaven-build.xml
- Throws:
java.io.IOException
- See Also:
DEFAULT_MAVEN_BUILD_FILENAME
-
writeBuildXml
private void writeBuildXml() throws java.io.IOException
Generate an genericbuild.xml
if not already exist- Throws:
java.io.IOException
- See Also:
DEFAULT_BUILD_FILENAME
-
writeProperties
private void writeProperties(org.codehaus.plexus.util.xml.XMLWriter writer)
Write properties in the writer only for a non-POM project.- Parameters:
writer
-
-
getLocalRepositoryPath
private java.lang.String getLocalRepositoryPath()
Check if the local repository is in the default location:${user.home}/.m2/repository
. If that is the case then return the path with the system property "user.home" in it. If not then just return the absolute path to the local repository.
-
writeBuildPathDefinition
private void writeBuildPathDefinition(org.codehaus.plexus.util.xml.XMLWriter writer)
Write path definition in the writer only for a non-POM project.- Parameters:
writer
-
-
writeBuildPathDefinition
private void writeBuildPathDefinition(org.codehaus.plexus.util.xml.XMLWriter writer, java.lang.String id, java.util.List artifacts)
-
getUninterpolatedSystemPath
private java.lang.String getUninterpolatedSystemPath(org.apache.maven.artifact.Artifact artifact)
-
writeCleanTarget
private void writeCleanTarget(org.codehaus.plexus.util.xml.XMLWriter writer)
Write clean target in the writer depending the packaging of the project.- Parameters:
writer
- the writer
-
writeCompileTarget
private void writeCompileTarget(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List compileSourceRoots) throws java.io.IOException
Write compile target in the writer depending the packaging of the project.- Parameters:
writer
-compileSourceRoots
-- Throws:
java.io.IOException
- if any
-
writeCompileTestsTarget
private void writeCompileTestsTarget(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List testCompileSourceRoots) throws java.io.IOException
Write compile-test target in the writer depending the packaging of the project.- Parameters:
writer
-testCompileSourceRoots
-- Throws:
java.io.IOException
- if any
-
writeTestTargets
private void writeTestTargets(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List testCompileSourceRoots) throws java.io.IOException
Write test target in the writer depending the packaging of the project.- Parameters:
writer
-testCompileSourceRoots
-- Throws:
java.io.IOException
-
writePomParts
private void writePomParts(org.codehaus.plexus.util.xml.XMLWriter writer)
- Parameters:
writer
-XMLWriter
-
getTestIncludes
private java.util.List getTestIncludes() throws java.io.IOException
Gets the include patterns for the unit tests.- Returns:
- A list of strings with include patterns, might be empty but never
null
. - Throws:
java.io.IOException
-
getTestExcludes
private java.util.List getTestExcludes() throws java.io.IOException
Gets the exclude patterns for the unit tests.- Returns:
- A list of strings with exclude patterns, might be empty but never
null
. - Throws:
java.io.IOException
-
writeTestFilesets
private void writeTestFilesets(org.codehaus.plexus.util.xml.XMLWriter writer, java.util.List testCompileSourceRoots, java.util.List includes, java.util.List excludes)
Write the<fileset>
elements for the test compile source roots.- Parameters:
writer
-testCompileSourceRoots
-includes
-excludes
-
-
writeJavadocTarget
private void writeJavadocTarget(org.codehaus.plexus.util.xml.XMLWriter writer) throws java.io.IOException
Write javadoc target in the writer depending the packaging of the project.- Parameters:
writer
-- Throws:
java.io.IOException
- if any
-
writePackageTarget
private void writePackageTarget(org.codehaus.plexus.util.xml.XMLWriter writer) throws java.io.IOException
Write package target in the writer depending the packaging of the project.- Parameters:
writer
-- Throws:
java.io.IOException
- if any
-
writeCompileTasks
private void writeCompileTasks(org.codehaus.plexus.util.xml.XMLWriter writer, java.lang.String outputDirectory, java.util.List compileSourceRoots, java.util.List resources, java.lang.String additionalClassesDirectory, boolean isTest) throws java.io.IOException
- Throws:
java.io.IOException
-
writeGetDepsTarget
private void writeGetDepsTarget(org.codehaus.plexus.util.xml.XMLWriter writer)
Write get-deps target in the writer only for a non-POM project- Parameters:
writer
-
-
getProjectRepoDirectory
static java.lang.String getProjectRepoDirectory(java.lang.String repoUrl, java.lang.String projectDir)
Gets the relative path to a repository that is rooted in the project. The returned path (if any) will always use the forward slash ('/') as the directory separator. For example, the path "target/it-repo" will be returned for a repository constructed from the URL "file://${basedir}/target/it-repo".- Parameters:
repoUrl
- The URL to the repository, must not benull
.projectDir
- The absolute path to the base directory of the project, must not benull
- Returns:
- The path to the repository (relative to the project base directory) or
null
if the repository is not rooted in the project.
-
addProperty
private static void addProperty(java.util.Properties properties, java.lang.String name, java.lang.String value)
Put a property in properties defined by a name and a value- Parameters:
properties
- not nullname
-value
- not null
-
getCommaSeparatedList
private static java.lang.String getCommaSeparatedList(java.util.Map[] includes, java.lang.String key)
- Parameters:
includes
- an array of includes or exludes mapkey
- a key wanted in the map, likeinclude
orexclude
- Returns:
- a String with comma-separated value of a key in each map
-
getSelectorList
private static java.util.List getSelectorList(java.util.Map[] options)
Flattens the specified file selector options into a simple string list. For instance, the input[ {include="*Test.java"}, {include="*TestCase.java"} ]
is converted to[ "*Test.java", "*TestCase.java" ]
- Parameters:
options
- The file selector options to flatten, may benull
.- Returns:
- The string list, might be empty but never
null
.
-
-