Class Maven
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.defaultInstantiators.AbstractFileInstantiator
-
- net.ssehub.easy.instantiation.maven.Maven
-
- All Implemented Interfaces:
IVilType
public class Maven extends AbstractFileInstantiator
Builds Java applications with Maven.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMaven.CliMessageManipulatorGets rid of the class name / logging level in Maven CLI mode.private static classMaven.PlexusMessageManipulatorGets rid of the logging level.
-
Field Summary
Fields Modifier and Type Field Description private static booleanAS_PROCESSprivate static java.lang.StringCLASSPATHprivate static java.lang.StringCLASSPATH_EXCLUDEprivate static booleanCMD_TESTprivate static java.lang.StringMAVEN_HOMEprivate static java.lang.StringREPO_LOCALprivate static java.lang.StringSETTINGSprivate static java.lang.StringTMP_FOLDER
-
Constructor Summary
Constructors Constructor Description Maven()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringaddFilesToClasspath(java.lang.String classpath, java.io.File base)Adds files inbasetoclasspath.private static java.lang.StringaddToClasspath(java.lang.String classpath, java.lang.String path)Addspathtoclasspath.private static Set<FileArtifact>build(Path root, java.lang.String buildFilePath, boolean updateSnapshots, java.lang.String[] targets)Executes a specific MAVEN build specification.private static voidcloseQuietly(java.io.InputStream stream)private static voidcopyResourceToFile(java.lang.String resource, java.io.File target, java.lang.String sub)Copies a resource to a target file.private static java.lang.StringgetClasspath()ANT is a bit different regarding its class loader...private static EASyLoggerFactory.EASyLoggergetLogger()Returns the logger instance.private static java.io.InputStreamgetResourceAsStream(java.lang.String name)private static java.lang.StringgetSub(java.lang.String line)Returns the target sub-directory in line.static Set<FileArtifact>maven(Path root)Executes a specific MAVEN build specification with "clean" and "install" targets.static Set<FileArtifact>maven(Path root, boolean updateSnapshots)Executes a specific MAVEN build specification with "clean" and "install" targets.static Set<FileArtifact>maven(Path root, boolean updateSnapshots, Sequence<java.lang.String> buildtargets)Executes a specific MAVEN build specification.static Set<FileArtifact>maven(Path root, java.lang.String buildFilePath)Executes a specific MAVEN build specification with "clean" and "install" targets.static Set<FileArtifact>maven(Path root, java.lang.String buildFilePath, boolean updateSnapshots)Executes a specific MAVEN build specification with "clean" and "install" targets.static Set<FileArtifact>maven(Path root, java.lang.String buildFilePath, boolean updateSnapshots, Sequence<java.lang.String> buildtargets)Executes a specific MAVEN build specification.static Set<FileArtifact>maven(Path root, java.lang.String buildFilePath, Sequence<java.lang.String> buildtargets)Executes a specific MAVEN build specification.static Set<FileArtifact>maven(Path root, Sequence<java.lang.String> buildtargets)Executes a specific MAVEN build specification.private static java.lang.StringobtainProcessClasspath(java.lang.ClassLoader contextClassLoader)Obtains the classpath for running Maven as a process.private static java.lang.StringrewriteIfUnbundled(java.lang.String classpath)In case that we have the standalone and a classpath that does not contain any (expected) maven library, take eitherMAVEN_HOME, the easy-headless or the first jar as location into account and add the contents of the library folder in this location.private static intrunAsProcess(java.lang.String buildFilePath, boolean updateSnapshots, java.lang.String[] targets)Runs Maven as a separate process.private static java.lang.String[]toTargets(Sequence<java.lang.String> buildtargets)Turns the given targets into an array.private static java.io.FiletryUnpack(java.lang.String classpath)Tries to unpack the Maven libraries to tmpDirTMP_FOLDERby readinglib/dir.list.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.defaultInstantiators.AbstractFileInstantiator
determineTargetPath, toString
-
-
-
-
Field Detail
-
TMP_FOLDER
private static final java.lang.String TMP_FOLDER
- See Also:
- Constant Field Values
-
CMD_TEST
private static final boolean CMD_TEST
- See Also:
- Constant Field Values
-
AS_PROCESS
private static final boolean AS_PROCESS
-
MAVEN_HOME
private static final java.lang.String MAVEN_HOME
-
CLASSPATH
private static final java.lang.String CLASSPATH
-
SETTINGS
private static final java.lang.String SETTINGS
-
REPO_LOCAL
private static final java.lang.String REPO_LOCAL
-
CLASSPATH_EXCLUDE
private static final java.lang.String CLASSPATH_EXCLUDE
-
-
Method Detail
-
maven
public static Set<FileArtifact> maven(Path root) throws VilException
Executes a specific MAVEN build specification with "clean" and "install" targets.- Parameters:
root- the root-path- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, boolean updateSnapshots) throws VilException
Executes a specific MAVEN build specification with "clean" and "install" targets.- Parameters:
root- the root-pathupdateSnapshots- whether snapshots shall be updated- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, java.lang.String buildFilePath) throws VilException
Executes a specific MAVEN build specification with "clean" and "install" targets.- Parameters:
root- the root-pathbuildFilePath- the path where the MAVEN file is located- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, java.lang.String buildFilePath, boolean updateSnapshots) throws VilException
Executes a specific MAVEN build specification with "clean" and "install" targets.- Parameters:
root- the root-pathupdateSnapshots- whether snapshots shall be updatedbuildFilePath- the path where the MAVEN file is located- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, Sequence<java.lang.String> buildtargets) throws VilException
Executes a specific MAVEN build specification.- Parameters:
root- the root-pathbuildtargets- the targets to be executed- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, boolean updateSnapshots, Sequence<java.lang.String> buildtargets) throws VilException
Executes a specific MAVEN build specification.- Parameters:
root- the root-pathupdateSnapshots- whether snapshots shall be updatedbuildtargets- the targets to be executed- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, java.lang.String buildFilePath, Sequence<java.lang.String> buildtargets) throws VilException
Executes a specific MAVEN build specification.- Parameters:
root- the root-pathbuildFilePath- the path where the MAVEN file is locatedbuildtargets- the targets to be executed- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
maven
public static Set<FileArtifact> maven(Path root, java.lang.String buildFilePath, boolean updateSnapshots, Sequence<java.lang.String> buildtargets) throws VilException
Executes a specific MAVEN build specification.- Parameters:
root- the root-pathbuildFilePath- the path where the MAVEN file is locatedupdateSnapshots- whether snapshots shall be updatedbuildtargets- the targets to be executed- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
toTargets
private static java.lang.String[] toTargets(Sequence<java.lang.String> buildtargets)
Turns the given targets into an array.- Parameters:
buildtargets- the targets as VIL sequence- Returns:
- the targets as string array
-
build
private static Set<FileArtifact> build(Path root, java.lang.String buildFilePath, boolean updateSnapshots, java.lang.String[] targets) throws VilException
Executes a specific MAVEN build specification.- Parameters:
root- the root-pathbuildFilePath- the path where the MAVEN file is locatedupdateSnapshots- whether snapshots shall be updated (-U)targets- the targets to be executed- Returns:
- the created artifacts
- Throws:
VilException- in case of artifact / parameter problems
-
getClasspath
private static java.lang.String getClasspath()
ANT is a bit different regarding its class loader...- Returns:
- the classpath if available
-
rewriteIfUnbundled
private static java.lang.String rewriteIfUnbundled(java.lang.String classpath)
In case that we have the standalone and a classpath that does not contain any (expected) maven library, take eitherMAVEN_HOME, the easy-headless or the first jar as location into account and add the contents of the library folder in this location.- Parameters:
classpath- the classpath- Returns:
- the rewritten classpath
-
getResourceAsStream
private static java.io.InputStream getResourceAsStream(java.lang.String name)
-
closeQuietly
private static void closeQuietly(java.io.InputStream stream)
-
tryUnpack
private static java.io.File tryUnpack(java.lang.String classpath)
Tries to unpack the Maven libraries to tmpDirTMP_FOLDERby readinglib/dir.list.- Parameters:
classpath- the classpath (assuming a single entry) as fallback result- Returns:
- the folder with the unpacked libraries or the fallback folder based on
classpath
-
getSub
private static java.lang.String getSub(java.lang.String line)
Returns the target sub-directory in line.- Parameters:
line- the line- Returns:
- the sub-directory, may be null for none
-
copyResourceToFile
private static void copyResourceToFile(java.lang.String resource, java.io.File target, java.lang.String sub)Copies a resource to a target file.- Parameters:
resource- the resourcetarget- the target filesub- optional target sub-directory withintarget, may be null for none
-
addToClasspath
private static java.lang.String addToClasspath(java.lang.String classpath, java.lang.String path)Addspathtoclasspath.- Parameters:
classpath- the classpath thepathshall be added topath- the file be added- Returns:
- the augmented classpath
-
addFilesToClasspath
private static java.lang.String addFilesToClasspath(java.lang.String classpath, java.io.File base)Adds files inbasetoclasspath.- Parameters:
classpath- the classpath the file names shall be added tobase- the base file/folder to list the file names from- Returns:
- the augmented classpath if files were found
-
runAsProcess
private static int runAsProcess(java.lang.String buildFilePath, boolean updateSnapshots, java.lang.String[] targets) throws java.io.IOException, java.lang.InterruptedExceptionRuns Maven as a separate process. This might be needed to avoid unnecessary file locks caused by Maven.- Parameters:
buildFilePath- the path where the MAVEN file is locatedupdateSnapshots- whether snapshots shall be updated (-U)targets- the targets to be executed- Returns:
- the command line execution code of Maven
- Throws:
java.io.IOException- in case that execution or process creation failsjava.lang.InterruptedException- in case that the created process was interrupted
-
getLogger
private static EASyLoggerFactory.EASyLogger getLogger()
Returns the logger instance.- Returns:
- the logger instance
-
obtainProcessClasspath
private static java.lang.String obtainProcessClasspath(java.lang.ClassLoader contextClassLoader)
Obtains the classpath for running Maven as a process.- Parameters:
contextClassLoader- the context class loader to obtain the classpath from if possible at all- Returns:
- the classpath
-
-