Class EmbeddedMavenExecutor
java.lang.Object
org.apache.maven.executor.embedded.EmbeddedMavenExecutor
- All Implemented Interfaces:
AutoCloseable,Executor
Embedded executor implementation, that invokes Maven from installation directory within this same JVM but in isolated
classloader. This class supports Maven 4.x and Maven 3.x as well. The ClassWorld of Maven is kept in memory as
long as instance of this class is not closed. Subsequent execution requests over same installation home are cached.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classContext holds things loaded up from given Maven Installation Directory. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicBooleanprotected final Map<Path, EmbeddedMavenExecutor.Context> protected final PathMaven4 supports multiple commands from same installation directory.protected final ClassLoaderprotected final Propertiesprotected final PrintStreamprotected final InputStreamprotected final PrintStreamprotected final booleanFields inherited from interface org.apache.maven.executor.Executor
IS_WINDOWS, UNKNOWN_VERSION -
Constructor Summary
ConstructorsConstructorDescriptionEmbeddedMavenExecutor(Path installationDirectory) EmbeddedMavenExecutor(Path installationDirectory, boolean useMavenArgsEnv) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and disposes of thisExecutorinstance, releasing any resources it may hold.protected URLClassLoadercreateMavenBootClassLoader(Path boot, List<URL> extraClasspath) protected voidUnloads dynamically loaded things, like extensions created realms.protected voiddoClose(EmbeddedMavenExecutor.Context context) protected EmbeddedMavenExecutor.ContextdoCreate(Path mavenHome, ExecutorRequest executorRequest) execute(ExecutorRequest executorRequest) Invokes the tool application using the providedExecutorRequest.protected StringgetMavenVersion(Class<?> clazz) Returns the Maven version that this executor points at (would use).protected PropertiesprepareProperties(ExecutorRequest request) protected voidvalidate(ExecutorRequest executorRequest)
-
Field Details
-
MVN4_MAIN_CLASSES
Maven4 supports multiple commands from same installation directory. -
installationDirectory
-
useMavenArgsEnv
protected final boolean useMavenArgsEnv -
closed
-
originalStdin
-
originalStdout
-
originalStderr
-
originalProperties
-
originalClassLoader
-
contextMap
-
-
Constructor Details
-
EmbeddedMavenExecutor
-
EmbeddedMavenExecutor
-
-
Method Details
-
execute
Description copied from interface:ExecutorInvokes the tool application using the providedExecutorRequest. This method is responsible for executing the command or build process based on the information contained in the request.- Specified by:
executein interfaceExecutor- Parameters:
executorRequest- the request containing all necessary information for the execution- Returns:
- ExecutorResult carrying the result of the execution
- Throws:
ExecutorException- if an error occurs during the execution process
-
mavenVersion
Description copied from interface:ExecutorReturns the Maven version that this executor points at (would use). This operation, depending on the underlying implementation, can be costly. If a caller uses this method often, it is the caller's responsibility to properly cache returned values.- Specified by:
mavenVersionin interfaceExecutor- Returns:
- a string representing the Maven version or
Executor.UNKNOWN_VERSION - Throws:
ExecutorException- if an error occurs during the execution process
-
disposeRuntimeCreatedRealms
Unloads dynamically loaded things, like extensions created realms. Makes sure we go back to "initial state". -
doCreate
-
prepareProperties
-
close
Description copied from interface:ExecutorCloses and disposes of thisExecutorinstance, releasing any resources it may hold. This method is called automatically when using try-with-resources statements.The default implementation does nothing. Subclasses should override this method if they need to perform cleanup operations.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceExecutor- Throws:
ExecutorException- if an error occurs while closing theExecutor
-
doClose
- Throws:
ExecutorException
-
validate
- Throws:
ExecutorException
-
createMavenBootClassLoader
-
getMavenVersion
- Throws:
IOException
-