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
Nested ClassesModifier and TypeClassDescriptionprotected static final classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final AtomicBooleanprotected final ConcurrentHashMap<EmbeddedMavenExecutor.Key,EmbeddedMavenExecutor.Context> protected final ClassLoaderprotected final Propertiesprotected final PrintStreamprotected final PrintStreamFields inherited from interface org.apache.maven.api.cli.Executor
IS_WINDOWS, UNKNOWN_VERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and disposes of thisExecutorinstance, releasing any resources it may hold.protected URLClassLoadercreateMavenBootClassLoader(Path boot, List<URL> extraClasspath) protected voidprotected voiddoClose(EmbeddedMavenExecutor.Context context) protected EmbeddedMavenExecutor.ContextdoCreate(Path mavenHome, ExecutorRequest executorRequest) intexecute(ExecutorRequest executorRequest) Invokes the tool application using the providedExecutorRequest.protected StringgetMavenVersion(Class<?> clazz) mavenVersion(ExecutorRequest executorRequest) Returns the Maven version that providedExecutorRequestpoint at (would use).protected EmbeddedMavenExecutor.ContextmayCreate(ExecutorRequest executorRequest) protected PropertiesprepareProperties(ExecutorRequest request) protected voidvalidate(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: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:
- 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:ExecutorReturns the Maven version that providedExecutorRequestpoint 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:
mavenVersionin 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: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
-