Skip to content
Merged
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.0-beta-4</version>
<version>1.2</version>
</extension>
</extensions>
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<connection>scm:git:git://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:[email protected]:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>
<repositories>
Expand All @@ -64,17 +64,18 @@
<properties>
<revision>2.42</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.176.4</jenkins.version>
<jenkins.version>2.222.4</jenkins.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.176.x</artifactId>
<version>16</version>
<artifactId>bom-2.222.x</artifactId>
<version>25</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.inject.Inject;
import hudson.Extension;
import hudson.ExtensionList;
Expand All @@ -20,10 +21,13 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
Expand Down Expand Up @@ -194,7 +198,7 @@ public void onFailure(Throwable t) {
LOGGER.log(WARNING, "Failed to load " + e, t);
}
}
});
}, newExecutorService());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I get it. The original code was not specifying an executor service, so why do we need to add this code now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}
Expand Down Expand Up @@ -230,7 +234,7 @@ public void onSuccess(List<StepExecution> result) {
public void onFailure(Throwable t) {
LOGGER.log(Level.WARNING, null, t);
}
});
}, newExecutorService());
}

return Futures.allAsList(all);
Expand All @@ -254,4 +258,25 @@ public void onFailure(Throwable t) {
executor.awaitTermination(1, TimeUnit.MINUTES);
}

/**
* Returns an {@link ExecutorService} to be used as a parameter in other methods.
* It calls {@code MoreExecutors#sameThreadExecutor} or falls back to {@code MoreExecutors#newDirectExecutorService}
* for compatibility with newer (> 18.0) versions of guava.
*/
private static ExecutorService newExecutorService() {
try {
try {
// guava older than 18
Method method = MoreExecutors.class.getMethod("sameThreadExecutor");
return (ExecutorService) method.invoke(null);
} catch (NoSuchMethodException e) {
// TODO invert this to prefer the newer guava method once guava is upgraded in Jenkins core
Method method = MoreExecutors.class.getMethod("newDirectExecutorService");
return (ExecutorService) method.invoke(null);
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) {
throw new RuntimeException(e);
}
}

}