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 classContext holds things loaded up from given Maven Installation Directory. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final AtomicBooleanprotected final ConcurrentHashMap<Path, EmbeddedMavenExecutor.Context> Maven4 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.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 voidUnloads dynamically loaded things, like extensions created realms.protected 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
-
MVN4_MAIN_CLASSES
-
cacheContexts
protected final boolean cacheContexts -
useMavenArgsEnv
protected final boolean useMavenArgsEnv -
closed
-
originalStdin
-
originalStdout
-
originalStderr
-
originalProperties
-
originalClassLoader
-
contexts
-
-
Constructor Details
-
EmbeddedMavenExecutor
public EmbeddedMavenExecutor() -
EmbeddedMavenExecutor
public EmbeddedMavenExecutor(boolean cacheContexts, boolean useMavenArgsEnv)
-
-
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
Unloads dynamically loaded things, like extensions created realms. Makes sure we go back to "initial state". -
mavenVersion
Description copied from interface:ExecutorReturns the Maven version that providedExecutorRequestpoint 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. (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
-