Skip to content
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

Make workflow-api compatible with Guava 21.0 and newer #135

Merged
merged 12 commits into from
Mar 15, 2021
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:git@github.com: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:git@github.com:${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
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.jenkinsci.plugins.workflow.flow;

import com.google.common.annotations.GwtCompatible;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.util.concurrent.Executor;

/**
* An {@link Executor} that runs each task in the thread that invokes {@link Executor#execute
* execute}.
*/
@GwtCompatible
@Restricted(NoExternalUse.class)
enum DirectExecutor implements Executor {
INSTANCE;

@Override
public void execute(Runnable command) {
command.run();
}

@Override
public String toString() {
return "MoreExecutors.directExecutor()";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void onFailure(Throwable t) {
LOGGER.log(WARNING, "Failed to load " + e, t);
}
}
});
}, MoreExecutors.directExecutor());
}
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ public void onSuccess(List<StepExecution> result) {
public void onFailure(Throwable t) {
LOGGER.log(Level.WARNING, null, t);
}
});
}, MoreExecutors.directExecutor());
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.jenkinsci.plugins.workflow.flow;

import com.google.common.annotations.GwtCompatible;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;

/**
* Factory and utility methods for {@link java.util.concurrent.Executor}, {@link ExecutorService},
* and {@link java.util.concurrent.ThreadFactory}.
*
* @author Eric Fellheimer
* @author Kyle Littlefield
* @author Justin Mahoney
* @since 3.0
*/
@GwtCompatible(emulated = true)
@Restricted(NoExternalUse.class)
public final class MoreExecutors {
private MoreExecutors() {}

/**
* Returns an {@link Executor} that runs each task in the thread that invokes {@link
* Executor#execute execute}, as in {@code ThreadPoolExecutor.CallerRunsPolicy}.
*
* <p>This executor is appropriate for tasks that are lightweight and not deeply chained.
* Inappropriate {@code directExecutor} usage can cause problems, and these problems can be
* difficult to reproduce because they depend on timing. For example:
*
* <ul>
* <li>A call like {@code future.transform(function, directExecutor())} may execute the function
* immediately in the thread that is calling {@code transform}. (This specific case happens
* if the future is already completed.) If {@code transform} call was made from a UI thread
* or other latency-sensitive thread, a heavyweight function can harm responsiveness.
* <li>If the task will be executed later, consider which thread will trigger the execution --
* since that thread will execute the task inline. If the thread is a shared system thread
* like an RPC network thread, a heavyweight task can stall progress of the whole system or
* even deadlock it.
* <li>If many tasks will be triggered by the same event, one heavyweight task may delay other
* tasks -- even tasks that are not themselves {@code directExecutor} tasks.
* <li>If many such tasks are chained together (such as with {@code
* future.transform(...).transform(...).transform(...)....}), they may overflow the stack.
* (In simple cases, callers can avoid this by registering all tasks with the same {@code
* MoreExecutors#newSequentialExecutor} wrapper around {@code directExecutor()}. More
* complex cases may require using thread pools or making deeper changes.)
* </ul>
*
* Additionally, beware of executing tasks with {@code directExecutor} while holding a lock. Since
* the task you submit to the executor (or any other arbitrary work the executor does) may do slow
* work or acquire other locks, you risk deadlocks.
*
* <p>This instance is equivalent to:
*
* <pre>{@code
* final class DirectExecutor implements Executor {
* public void execute(Runnable r) {
* r.run();
* }
* }
* }</pre>
*
* <p>This should be preferred to {@code #newDirectExecutorService()} because implementing the
* {@link ExecutorService} subinterface necessitates significant performance overhead.
*
*
* @since 18.0
*/
public static Executor directExecutor() {
return DirectExecutor.INSTANCE;
}
}