Class EmbeddedMavenExecutor
java.lang.Object
org.apache.maven.cling.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
Modifier and TypeClassDescriptionprotected static final class
protected static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
protected final AtomicBoolean
protected final ConcurrentHashMap<EmbeddedMavenExecutor.Key,
EmbeddedMavenExecutor.Context> protected final ClassLoader
protected final Properties
protected final PrintStream
protected final PrintStream
Fields inherited from interface org.apache.maven.api.cli.Executor
IS_WINDOWS, UNKNOWN_VERSION
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes and disposes of thisExecutor
instance, releasing any resources it may hold.protected URLClassLoader
createMavenBootClassLoader
(Path boot, List<URL> extraClasspath) protected void
protected void
doClose
(EmbeddedMavenExecutor.Context context) protected EmbeddedMavenExecutor.Context
doCreate
(Path mavenHome, ExecutorRequest executorRequest) int
execute
(ExecutorRequest executorRequest) Invokes the tool application using the providedExecutorRequest
.protected String
getMavenVersion
(Class<?> clazz) mavenVersion
(ExecutorRequest executorRequest) Returns the Maven version that providedExecutorRequest
point at (would use).protected EmbeddedMavenExecutor.Context
mayCreate
(ExecutorRequest executorRequest) protected Properties
prepareProperties
(ExecutorRequest request) protected void
validate
(ExecutorRequest executorRequest)
-
Field Details
-
MAIN_CLASSES
-
cacheContexts
protected final boolean cacheContexts -
closed
-
originalStdout
-
originalStderr
-
originalProperties
-
originalClassLoader
-
contexts
-
-
Constructor Details
-
EmbeddedMavenExecutor
public EmbeddedMavenExecutor() -
EmbeddedMavenExecutor
public EmbeddedMavenExecutor(boolean cacheContexts)
-
-
Method Details
-
execute
Description copied from interface:Executor
Invokes 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:
execute
in interfaceExecutor
- Parameters:
executorRequest
- the request containing all necessary information for the execution- Returns:
- an integer representing the exit code of the execution (0 typically indicates success)
- Throws:
ExecutorException
- if an error occurs during the execution process
-
disposeRuntimeCreatedRealms
-
mavenVersion
Description copied from interface:Executor
Returns the Maven version that providedExecutorRequest
point at (would use). Please note, that this operation, depending on underlying implementation may be costly. If caller use this method often, it is caller responsibility to properly cache returned values (key can beExecutorRequest.installationDirectory()
.- Specified by:
mavenVersion
in interfaceExecutor
- Parameters:
executorRequest
- the request containing all necessary information for the execution- Returns:
- a string representing the Maven version or
Executor.UNKNOWN_VERSION
- Throws:
ExecutorException
- if an error occurs during the execution process
-
mayCreate
-
doCreate
-
prepareProperties
-
close
Description copied from interface:Executor
Closes and disposes of thisExecutor
instance, 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceExecutor
- Throws:
ExecutorException
- if an error occurs while closing theExecutor
-
doClose
- Throws:
ExecutorException
-
validate
- Throws:
ExecutorException
-
createMavenBootClassLoader
-
getMavenVersion
- Throws:
IOException
-