Skip to content
Open
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 @@ -18,7 +18,6 @@
*/
package org.apache.maven.executor.batch.internal;

import java.io.ByteArrayOutputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
Expand All @@ -28,6 +27,7 @@
import org.apache.maven.executor.Executor;
import org.apache.maven.executor.ExecutorException;
import org.apache.maven.executor.ExecutorRequest;
import org.apache.maven.executor.ExecutorResult;
import org.apache.maven.executor.ExecutorTool;
import org.apache.maven.executor.batch.steps.Environment;
import org.apache.maven.executor.batch.steps.Execution;
Expand Down Expand Up @@ -97,24 +97,22 @@ public Execution.Result execute(Execution.Request execution) throws ExecutorExce
execution.environmentVariables().ifPresent(ev -> ev.forEach(builder::environmentVariable));
execution.jvmSystemProperties().ifPresent(sp -> sp.forEach(builder::jvmSystemProperty));
execution.jvmArguments().ifPresent(ja -> ja.forEach(builder::jvmArgument));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();

int exitCode = executor.execute(builder.stdOut(out).stdErr(err).build());
ExecutorResult res = executor.execute(builder.build());
Execution.Result result = new Execution.Result() {
@Override
public int exitCode() {
return exitCode;
return res.exitCode().orElseThrow();
}

@Override
public String stdOut() {
return out.toString();
return res.stdOutString().orElseThrow();
}

@Override
public String stdErr() {
return err.toString();
return res.stdErrString().orElseThrow();
}
};
resultList.add(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
Expand All @@ -32,11 +29,13 @@
import org.apache.maven.executor.Executor;
import org.apache.maven.executor.ExecutorException;
import org.apache.maven.executor.ExecutorRequest;
import org.apache.maven.executor.ExecutorResult;
import org.apache.maven.executor.batch.steps.ContextStep;
import org.apache.maven.executor.batch.steps.Environment;
import org.apache.maven.executor.batch.steps.ExecuteStep;
import org.apache.maven.executor.batch.steps.Execution;
import org.apache.maven.executor.batch.steps.Step;
import org.apache.maven.executor.support.SimpleExecutionResult;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -48,16 +47,8 @@ public class BatchExecutorTest {
void smoke() {
Executor executor = new Executor() {
@Override
public int execute(ExecutorRequest executorRequest) throws ExecutorException {
try {
executorRequest
.stdOut()
.orElse(OutputStream.nullOutputStream())
.write("Executed!".getBytes(StandardCharsets.UTF_8));
return 0;
} catch (IOException e) {
throw new ExecutorException(e);
}
public ExecutorResult execute(ExecutorRequest executorRequest) throws ExecutorException {
return new SimpleExecutionResult(executorRequest, true, 0, "Executed", null);
}

@Override
Expand Down
22 changes: 21 additions & 1 deletion maven-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<description />

<properties>
<version.toolbox>0.15.8</version.toolbox>
<javaVersion>8</javaVersion>
<version.toolbox>0.15.9</version.toolbox>
</properties>

<dependencies>
Expand All @@ -53,6 +54,25 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile-java17</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<release>17</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java17</compileSourceRoot>
</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public interface Executor extends AutoCloseable {
* process based on the information contained in the request.
*
* @param executorRequest the request containing all necessary information for the execution
* @return an integer representing the exit code of the execution (0 typically indicates success)
* @return ExecutorResult carrying the result of the execution
* @throws ExecutorException if an error occurs during the execution process
*/
int execute(ExecutorRequest executorRequest) throws ExecutorException;
ExecutorResult execute(ExecutorRequest executorRequest) throws ExecutorException;

/**
* Returns the Maven version that this executor points at (would use). This operation, depending on the underlying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ enum Mode {
/**
* Executes the request with preferred mode executor.
*/
default int execute(ExecutorRequest executorRequest) throws ExecutorException {
default ExecutorResult execute(ExecutorRequest executorRequest) throws ExecutorException {
return execute(getDefaultMode(), executorRequest);
}

/**
* Executes the request with passed in mode executor.
*/
int execute(Mode mode, ExecutorRequest executorRequest) throws ExecutorException;
ExecutorResult execute(Mode mode, ExecutorRequest executorRequest) throws ExecutorException;
}
Loading
Loading