diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 0000000..9ac2968 --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + io.jenkins.tools.incrementals + git-changelist-maven-extension + 1.4 + + diff --git a/.mvn/maven.config b/.mvn/maven.config new file mode 100644 index 0000000..2a0299c --- /dev/null +++ b/.mvn/maven.config @@ -0,0 +1,2 @@ +-Pconsume-incrementals +-Pmight-produce-incrementals diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..59bd0f9 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,9 @@ +/* + * While this is not a plugin, it is much simpler to reuse the pipeline code for CI. This allows for + * easy Linux/Windows testing and produces incrementals. The only feature that relates to plugins is + * allowing one to test against multiple Jenkins versions. + */ +buildPlugin(useContainerAgent: true, configurations: [ + [ platform: 'linux', jdk: '11' ], + [ platform: 'linux', jdk: '17' ], +]) diff --git a/pom.xml b/pom.xml index 12ce764..665d369 100644 --- a/pom.xml +++ b/pom.xml @@ -1,34 +1,39 @@ + - org.kohsuke - pom - 17 + org.jenkins-ci + jenkins + 1.88 + 4.0.0 org.jvnet.winp winp - 1.29-SNAPSHOT + ${revision}${changelist} winp Kill process tree in Windows + https://github.com/jenkinsci/${project.artifactId} - 3.0.4 - true + 1.29 + -SNAPSHOT + jenkinsci/${project.artifactId} + + High - scm:git:git@github.com/kohsuke/${project.artifactId}.git - scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git - http://${project.artifactId}.kohsuke.org/ - HEAD + scm:git:https://github.com/${gitHubRepo}.git + scm:git:git@github.com:${gitHubRepo}.git + https://github.com/${gitHubRepo} + ${scmTag} maven-jar-plugin - 3.0.2 @@ -39,78 +44,63 @@ maven-surefire-plugin - 2.19.1 - -XX:+CreateMinidumpOnCrash - false - - - - org.codehaus.mojo - findbugs-maven-plugin - ${findbugs-maven-plugin.version} - - Max - - true - false - - - - findbugs - - check - - verify - - - - - maven-release-plugin - 2.5.2 - - release + -XX:+CreateCoredumpOnCrash - - - - maven-javadoc-plugin - 2.10.4 - - - - - junit - junit - 4.13.1 + com.github.spotbugs + spotbugs-annotations + true + + + com.google.code.findbugs + jsr305 + + + + + org.junit.jupiter + junit-jupiter test - com.google.code.findbugs - annotations - 3.0.0 - provided + org.junit.vintage + junit-vintage-engine + test - github-pages - gitsite:git@github.com/kohsuke/${project.artifactId}.git + github.com + gitsite:git@github.com/${gitHubRepo}.git - The MIT license - http://www.opensource.org/licenses/mit-license.php + MIT License + https://opensource.org/licenses/MIT repo + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + diff --git a/src/main/java/org/jvnet/winp/Native.java b/src/main/java/org/jvnet/winp/Native.java index 7fd2bb6..7cf5950 100755 --- a/src/main/java/org/jvnet/winp/Native.java +++ b/src/main/java/org/jvnet/winp/Native.java @@ -2,7 +2,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import javax.annotation.CheckReturnValue; +import edu.umd.cs.findbugs.annotations.CheckReturnValue; import java.math.BigInteger; import java.net.URL; import java.net.URLDecoder; @@ -104,18 +104,16 @@ public static boolean sendCtrlC(int pid) throws WinpException { } } + @SuppressFBWarnings(value = "WEAK_MESSAGE_DIGEST_MD5", justification = "TODO needs triage") private static String md5(URL res) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); - InputStream in = res.openStream(); - try { + try (InputStream in = res.openStream()) { byte[] buf = new byte[8192]; int len; while((len=in.read(buf))>=0) md5.update(buf, 0, len); return toHex32(md5.digest()); - } finally { - in.close(); } } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); diff --git a/src/main/java/org/jvnet/winp/UserErrorType.java b/src/main/java/org/jvnet/winp/UserErrorType.java index 51f00c2..b5bbac6 100644 --- a/src/main/java/org/jvnet/winp/UserErrorType.java +++ b/src/main/java/org/jvnet/winp/UserErrorType.java @@ -23,8 +23,6 @@ */ package org.jvnet.winp; -import javax.annotation.Nonnegative; - /** * User-scope error codes in WinP. * @author Oleg Nenashev @@ -35,7 +33,7 @@ enum UserErrorType { private final int shortCode; - UserErrorType(@Nonnegative int shortCode) { + UserErrorType(/* @java.annotation.Nonnegative */ int shortCode) { this.shortCode = shortCode; } diff --git a/src/main/java/org/jvnet/winp/WinProcess.java b/src/main/java/org/jvnet/winp/WinProcess.java index 7295422..77e3bf7 100755 --- a/src/main/java/org/jvnet/winp/WinProcess.java +++ b/src/main/java/org/jvnet/winp/WinProcess.java @@ -1,7 +1,6 @@ package org.jvnet.winp; -import javax.annotation.CheckReturnValue; -import java.lang.reflect.Field; +import edu.umd.cs.findbugs.annotations.CheckReturnValue; import java.util.Comparator; import java.util.TreeMap; import java.util.Iterator; @@ -39,15 +38,10 @@ public WinProcess(int pid) { * Wraps {@link Process} into {@link WinProcess}. */ public WinProcess(Process proc) { - try { - Field f = proc.getClass().getDeclaredField("handle"); - f.setAccessible(true); - long handle = f.getLong(proc); - pid = Native.getProcessId(handle); - } catch (NoSuchFieldException e) { - throw new NotWindowsException(e); - } catch (IllegalAccessException e) { - throw new NotWindowsException(e); + long pidLong = proc.pid(); + this.pid = (int) pidLong; + if (this.pid != pidLong) { + throw new IllegalArgumentException("Out of range: " + pidLong); } } diff --git a/src/site/site.xml b/src/site/site.xml index d5d65b5..316774b 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -16,7 +16,7 @@ - + diff --git a/src/test/java/org/jvnet/winp/Junit4TestsRanTest.java b/src/test/java/org/jvnet/winp/Junit4TestsRanTest.java new file mode 100644 index 0000000..fb552b0 --- /dev/null +++ b/src/test/java/org/jvnet/winp/Junit4TestsRanTest.java @@ -0,0 +1,14 @@ +package org.jvnet.winp; + +import org.junit.Test; + +public class Junit4TestsRanTest { + + @Test + public void anything() { + /* + * Intentionally blank. We just want a test that runs with JUnit so that buildPlugin() works + * in the Jenkinsfile. + */ + } +} diff --git a/src/test/java/org/jvnet/winp/PlatformSpecificProcessTest.java b/src/test/java/org/jvnet/winp/PlatformSpecificProcessTest.java index c0da3cb..af3dd86 100644 --- a/src/test/java/org/jvnet/winp/PlatformSpecificProcessTest.java +++ b/src/test/java/org/jvnet/winp/PlatformSpecificProcessTest.java @@ -39,7 +39,6 @@ import org.junit.runners.Parameterized.Parameters; import org.jvnet.winp.util.ExecutablePlatform; import org.jvnet.winp.util.ProcessSpawningTest; -import static org.jvnet.winp.util.ProcessSpawningTest.isAlive; import org.jvnet.winp.util.TestHelper; /** @@ -94,7 +93,7 @@ public void getCommandLine_shouldNotFailIfTheProcessIsDead() throws Exception { int pid = wp.getPid(); wp.killRecursively(); Thread.sleep(1000); - assertFalse("The process has not been stopped yet", isAlive(p)); + assertFalse("The process has not been stopped yet", p.isAlive()); try { new WinProcess(p).getCommandLine(); @@ -114,7 +113,7 @@ public void getEnvironmentVariables_shouldFailIfTheProcessIsDead() throws Except int pid = wp.getPid(); wp.killRecursively(); Thread.sleep(1000); - assertFalse("The process has not been stopped yet", isAlive(p)); + assertFalse("The process has not been stopped yet", p.isAlive()); try { new WinProcess(p).getEnvironmentVariables(); diff --git a/src/test/java/org/jvnet/winp/util/ProcessSpawningTest.java b/src/test/java/org/jvnet/winp/util/ProcessSpawningTest.java index 2f93539..3763f7e 100644 --- a/src/test/java/org/jvnet/winp/util/ProcessSpawningTest.java +++ b/src/test/java/org/jvnet/winp/util/ProcessSpawningTest.java @@ -25,8 +25,7 @@ import java.io.File; import java.io.IOException; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; +import edu.umd.cs.findbugs.annotations.CheckForNull; import static org.hamcrest.CoreMatchers.containsString; import org.junit.After; import org.junit.Assert; @@ -47,10 +46,9 @@ public class ProcessSpawningTest extends NativeWinpTest { @After public void killSpawnedProcess() { - if (spawnedProcess != null && isAlive(spawnedProcess)) { + if (spawnedProcess != null && spawnedProcess.isAlive()) { System.err.println("Killing process " + spawnedProcess.toString()); - //TODO: destroyForcibly() in Java8 - spawnedProcess.destroy(); + spawnedProcess.destroyForcibly(); } spawnedProcess = null; @@ -85,16 +83,6 @@ public Process spawnProcess(boolean delayAfterCreate, boolean spotcheckProcess, return spawnedProcess; } - //TODO: replace by Process#isAlive() in Java8 - public static boolean isAlive(@Nonnull Process proc) { - try { - int exitCode = proc.exitValue(); - return false; - } catch (IllegalThreadStateException ex) { - return true; - } - } - protected static File getTestAppExecutable(ExecutablePlatform executablePlatform) { final String executable; switch (executablePlatform) {