-
Notifications
You must be signed in to change notification settings - Fork 0
Fallback to old guava API if needed and avoid core bump #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,7 @@ | |
| <properties> | ||
| <revision>2.42</revision> | ||
| <changelist>-SNAPSHOT</changelist> | ||
| <jenkins.version>2.273-rc30689.09147672b85b</jenkins.version> | ||
| <jenkins.version>2.176.4</jenkins.version> | ||
| <java.level>8</java.level> | ||
| <no-test-jar>false</no-test-jar> | ||
| <useBeta>true</useBeta> | ||
|
|
@@ -105,11 +105,6 @@ | |
| <artifactId>workflow-basic-steps</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may need to re-add on newer core depending on why this was in here |
||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>trilead-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <!-- For Semaphore step --> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
|
|
@@ -139,18 +134,4 @@ | |
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <!-- TODO the tests depend on workflow-support and cps which both need api published first... --> | ||
| <!-- need to run at least one flag or the pipeline fails --> | ||
| <test>InjectedTest</test> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,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; | ||
|
|
@@ -181,11 +184,9 @@ public void onLoaded() { | |
| Futures.addCallback(e.getCurrentExecutions(false), new FutureCallback<List<StepExecution>>() { | ||
| @Override | ||
| public void onSuccess(List<StepExecution> result) { | ||
| if (result != null) { | ||
| LOGGER.log(FINE, "Will resume {0}", result); | ||
| for (StepExecution se : result) { | ||
| se.onResume(); | ||
| } | ||
| LOGGER.log(FINE, "Will resume {0}", result); | ||
| for (StepExecution se : result) { | ||
| se.onResume(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -197,7 +198,7 @@ public void onFailure(Throwable t) { | |
| LOGGER.log(WARNING, "Failed to load " + e, t); | ||
| } | ||
| } | ||
| }, MoreExecutors.newDirectExecutorService()); | ||
| }, newExecutorService()); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -220,13 +221,11 @@ public ListenableFuture<?> apply(final Function<StepExecution, Void> f) { | |
| Futures.addCallback(execs,new FutureCallback<List<StepExecution>>() { | ||
| @Override | ||
| public void onSuccess(List<StepExecution> result) { | ||
| if (result != null) { | ||
| for (StepExecution e : result) { | ||
| try { | ||
| f.apply(e); | ||
| } catch (RuntimeException x) { | ||
| LOGGER.log(Level.WARNING, null, x); | ||
| } | ||
| for (StepExecution e : result) { | ||
| try { | ||
| f.apply(e); | ||
| } catch (RuntimeException x) { | ||
| LOGGER.log(Level.WARNING, null, x); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -235,7 +234,7 @@ public void onSuccess(List<StepExecution> result) { | |
| public void onFailure(Throwable t) { | ||
| LOGGER.log(Level.WARNING, null, t); | ||
| } | ||
| }, MoreExecutors.newDirectExecutorService()); | ||
| }, newExecutorService()); | ||
| } | ||
|
|
||
| return Futures.allAsList(all); | ||
|
|
@@ -259,4 +258,24 @@ 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#newDirectExecutorService} or falls back to {@code MoreExecutors#sameThreadExecutor} | ||
| * for compatibility with older (< 18.0) versions of guava. | ||
| */ | ||
| private static ExecutorService newExecutorService() { | ||
| try { | ||
| try { | ||
| Method method = MoreExecutors.class.getMethod("newDirectExecutorService"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you invert this please as in |
||
| return (ExecutorService) method.invoke(null); | ||
| } catch (NoSuchMethodException e) { | ||
| // guava older than 18, fallback to `sameThreadExecutor` | ||
| Method method = MoreExecutors.class.getMethod("sameThreadExecutor"); | ||
| return (ExecutorService) method.invoke(null); | ||
| } | ||
| } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a supported one at least, most of the others were recently bumped to 2.222.4