Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public ExecutorResult execute(ExecutorRequest executorRequest) throws ExecutorEx
if (closed.get()) {
throw new ExecutorException("Executor is closed");
}
Properties originalProperties = new Properties();
originalProperties.putAll(System.getProperties());
validate(executorRequest);
String command = executorRequest.command();
Context context = contextMap.computeIfAbsent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,63 @@
*/
package org.apache.maven.executor.embedded;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

import org.apache.maven.executor.Environment;
import org.apache.maven.executor.Executor;
import org.apache.maven.executor.ExecutorRequest;
import org.apache.maven.executor.MavenExecutorTestSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Embedded executor UT
*/
public class EmbeddedMavenExecutorTest extends MavenExecutorTestSupport {

@TempDir
Path tempDir;

@Override
protected Executor doSelectExecutor(Path installationDirectory) {
return new EmbeddedMavenExecutor(installationDirectory);
}

@Test
void preservesSystemPropertiesSetBetweenExecutions() throws Exception {
String propertyName = "maven.executor.test.property";
String originalValue = System.getProperty(propertyName);
EmbeddedMavenExecutor executor = new EmbeddedMavenExecutor(Paths.get(Environment.MAVEN4_HOME));
try {
Files.createDirectories(tempDir.resolve("home"));
ExecutorRequest request = ExecutorRequest.mavenBuilder()
.cwd(tempDir)
.userHomeDirectory(tempDir.resolve("home"))
.argument("--version")
.build();

System.clearProperty(propertyName);
executor.execute(request);
Properties properties = new Properties();
properties.putAll(System.getProperties());
properties.setProperty(propertyName, "set-between-executions");
System.setProperties(properties);

executor.execute(request);

assertEquals("set-between-executions", System.getProperty(propertyName));
} finally {
executor.close();
if (originalValue == null) {
System.clearProperty(propertyName);
} else {
System.setProperty(propertyName, originalValue);
}
}
}
}