-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* command lines module upgrades * new tests * missing dep * missing dep * release notes * [Gradle Release Plugin] - new version commit: '3.27.0-snapshot'.
- Loading branch information
Showing
16 changed files
with
589 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=3.26.0-snapshot | ||
version=3.27.0-snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/mageddo/commons/exec/DelegateOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.mageddo.commons.exec; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class DelegateOutputStream extends OutputStream { | ||
|
||
private final List<OutputStream> delegateOuts; | ||
|
||
public DelegateOutputStream(OutputStream... delegateOuts) { | ||
this.delegateOuts = Stream.of(delegateOuts).toList(); | ||
} | ||
|
||
public DelegateOutputStream(List<OutputStream> delegateOuts) { | ||
this.delegateOuts = delegateOuts; | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
for (final var delegateOut : this.delegateOuts) { | ||
delegateOut.write(b); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
for (final var out : this.delegateOuts) { | ||
try { | ||
out.close(); | ||
} catch (IOException e) { | ||
} | ||
} | ||
} | ||
} |
10 changes: 7 additions & 3 deletions
10
src/main/java/com/mageddo/commons/exec/ExecutionValidationFailedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package com.mageddo.commons.exec; | ||
|
||
public class ExecutionValidationFailedException extends RuntimeException { | ||
private final CommandLines.Result result; | ||
private final Result result; | ||
|
||
public ExecutionValidationFailedException(CommandLines.Result result) { | ||
public ExecutionValidationFailedException(Result result) { | ||
super(String.format("error, code=%d, error=%s", result.getExitCode(), result.getOutAsString())); | ||
this.result = result; | ||
} | ||
|
||
public CommandLines.Result result() { | ||
public Result result() { | ||
return this.result; | ||
} | ||
|
||
public int getExitCode() { | ||
return this.result.getExitCode(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/mageddo/commons/exec/NopResultHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.mageddo.commons.exec; | ||
|
||
import org.apache.commons.exec.ExecuteException; | ||
import org.apache.commons.exec.ExecuteResultHandler; | ||
|
||
public class NopResultHandler implements ExecuteResultHandler { | ||
@Override | ||
public void onProcessComplete(int exitValue) { | ||
|
||
} | ||
|
||
@Override | ||
public void onProcessFailed(ExecuteException e) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.mageddo.commons.exec; | ||
|
||
import lombok.Getter; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.PipedInputStream; | ||
import java.io.PipedOutputStream; | ||
import java.io.UncheckedIOException; | ||
|
||
public class PipedStream extends OutputStream { | ||
|
||
@Getter | ||
private final PipedInputStream pipedIn; | ||
|
||
private final DelegateOutputStream delegateOut; | ||
private final OutputStream originalOut; | ||
|
||
public PipedStream(final OutputStream out) { | ||
try { | ||
this.pipedIn = new PipedInputStream(); | ||
this.originalOut = out; | ||
final var pout = new PipedOutputStream(this.pipedIn); | ||
this.delegateOut = new DelegateOutputStream(out, pout); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
this.delegateOut.write(b); | ||
} | ||
|
||
public void close() throws IOException { | ||
this.delegateOut.close(); | ||
} | ||
|
||
OutputStream getOriginalOut() { | ||
return originalOut; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mageddo/commons/exec/ProcessAccessibleDaemonExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mageddo.commons.exec; | ||
|
||
import lombok.Getter; | ||
import org.apache.commons.exec.CommandLine; | ||
import org.apache.commons.exec.DaemonExecutor; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
@Getter | ||
class ProcessAccessibleDaemonExecutor extends DaemonExecutor { | ||
|
||
private Process process = null; | ||
|
||
@Override | ||
protected Process launch(CommandLine command, Map<String, String> env, File dir) throws IOException { | ||
return this.process = super.launch(command, env, dir); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/mageddo/commons/exec/ProcessesWatchDog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.mageddo.commons.exec; | ||
|
||
import com.mageddo.commons.lang.Singletons; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
@Slf4j | ||
public class ProcessesWatchDog { | ||
|
||
private List<Supplier<Process>> processes = new ArrayList<>(); | ||
|
||
public static ProcessesWatchDog instance() { | ||
return Singletons.createOrGet(ProcessesWatchDog.class, ProcessesWatchDog::new); | ||
} | ||
|
||
public void watch(Supplier<Process> sup) { | ||
this.processes.add(sup); | ||
} | ||
|
||
public void watch(Process process) { | ||
this.processes.add(() -> process); | ||
} | ||
|
||
public void killAllProcesses() { | ||
final var validProcesses = this.findValidProcesses(); | ||
|
||
log.debug("status=killing all processes, processes={}, valid={}", this.processes.size(), validProcesses.size()); | ||
|
||
validProcesses.forEach(process -> { | ||
try { | ||
process.destroy(); | ||
log.trace("status=killed, pid={}", process.pid()); | ||
} catch (Exception e) { | ||
log.warn("status=unable to destroy, processId={}, msg={}", process.pid(), e.getMessage(), e); | ||
} | ||
}); | ||
} | ||
|
||
private List<Process> findValidProcesses() { | ||
return this.processes.stream() | ||
.map(Supplier::get) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
} | ||
} |
Oops, something went wrong.