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

[JENKINS-55681] - Make JAXB a detached plugin only on Java 11 #3865

Merged
merged 15 commits into from Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -63,7 +63,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>version-number</artifactId>
<version>1.4</version>
<version>1.5-20190125.122831-1</version>
oleg-nenashev marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
Expand Down
47 changes: 30 additions & 17 deletions core/src/main/java/jenkins/plugins/DetachedPluginsManager.java
@@ -1,10 +1,12 @@
package jenkins.plugins;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import hudson.ClassicPluginStrategy;
import hudson.PluginWrapper;
import hudson.util.VersionNumber;
import jenkins.util.java.JavaUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand Down Expand Up @@ -36,11 +38,12 @@
public class DetachedPluginsManager {
batmat marked this conversation as resolved.
Show resolved Hide resolved
private static final Logger LOGGER = Logger.getLogger(DetachedPluginsManager.class.getName());


/**
* Record of which plugins which removed from core and when.
*/
private static final List<DetachedPlugin> DETACHED_LIST;
@VisibleForTesting
static final List<DetachedPlugin> DETACHED_LIST;

/**
* Implicit dependencies that are known to be unnecessary and which must be cut out to prevent a dependency cycle among bundled plugins.
*/
Expand All @@ -50,7 +53,12 @@ public class DetachedPluginsManager {
try (InputStream is = ClassicPluginStrategy.class.getResourceAsStream("/jenkins/split-plugins.txt")) {
DETACHED_LIST = ImmutableList.copyOf(configLines(is).map(line -> {
String[] pieces = line.split(" ");
return new DetachedPluginsManager.DetachedPlugin(pieces[0], pieces[1] + ".*", pieces[2]);

// defaults to Java 1.0 to install unconditionally if unspecified
return new DetachedPluginsManager.DetachedPlugin(pieces[0],
pieces[1] + ".*",
pieces[2],
pieces.length == 4 ? pieces[3] : "1.0");
}).collect(Collectors.toList()));
} catch (IOException x) {
throw new ExceptionInInitializerError(x);
Expand All @@ -73,7 +81,7 @@ private DetachedPluginsManager() {
@Nonnull
public static List<PluginWrapper.Dependency> getImpliedDependencies(String pluginName, String jenkinsVersion) {
List<PluginWrapper.Dependency> out = new ArrayList<>();
for (DetachedPlugin detached : DETACHED_LIST) {
for (DetachedPlugin detached : getDetachedPlugins()) {
// don't fix the dependency for itself, or else we'll have a cycle
if (detached.shortName.equals(pluginName)) {
continue;
Expand All @@ -93,34 +101,32 @@ public static List<PluginWrapper.Dependency> getImpliedDependencies(String plugi
}

/**
* Get the list of all plugins that have ever been {@link DetachedPlugin detached} from Jenkins core.
* Get the list of all plugins that have ever been {@link DetachedPlugin detached} from Jenkins core, applicable to the current Java runtime.
*
* @return A {@link List} of {@link DetachedPlugin}s.
* @see JavaUtils#getCurrentJavaRuntimeVersionNumber()
*/
@Restricted(NoExternalUse.class)
batmat marked this conversation as resolved.
Show resolved Hide resolved
public static @Nonnull
List<DetachedPlugin> getDetachedPlugins() {
return DETACHED_LIST;
return DETACHED_LIST.stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this be done in the initialization of the DETACHED_LIST directly? If possible, we don't need extra changes along the class changing DETACHED_LIST by getDetachedPlugins

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I considered it already, not 100% sure why I chose this path. I'll have another look.

.filter(plugin -> JavaUtils.getCurrentJavaRuntimeVersionNumber().isNewerOrEqualTo(plugin.getMinJavaVersion()))
.collect(Collectors.toList());
}

/**
* Get the list of plugins that have been detached since a specific Jenkins release version.
*
* @param since The Jenkins version.
* @return A {@link List} of {@link DetachedPlugin}s.
* @see #getDetachedPlugins()
*/
@Restricted(NoExternalUse.class)
public static @Nonnull
List<DetachedPlugin> getDetachedPlugins(@Nonnull VersionNumber since) {
List<DetachedPlugin> detachedPlugins = new ArrayList<>();

for (DetachedPlugin detachedPlugin : DETACHED_LIST) {
if (!detachedPlugin.getSplitWhen().isOlderThan(since)) {
detachedPlugins.add(detachedPlugin);
}
}

return detachedPlugins;
return getDetachedPlugins().stream()
.filter(detachedPlugin -> !detachedPlugin.getSplitWhen().isOlderThan(since))
.collect(Collectors.toList());
}

/**
Expand All @@ -132,7 +138,7 @@ List<DetachedPlugin> getDetachedPlugins(@Nonnull VersionNumber since) {
*/
@Restricted(NoExternalUse.class)
public static boolean isDetachedPlugin(@Nonnull String pluginId) {
for (DetachedPlugin detachedPlugin : DETACHED_LIST) {
for (DetachedPlugin detachedPlugin : getDetachedPlugins()) {
if (detachedPlugin.getShortName().equals(pluginId)) {
return true;
}
Expand Down Expand Up @@ -171,11 +177,13 @@ public static final class DetachedPlugin {
*/
private final VersionNumber splitWhen;
private final String requiredVersion;
private final VersionNumber minJavaVersion;

private DetachedPlugin(String shortName, String splitWhen, String requiredVersion) {
private DetachedPlugin(String shortName, String splitWhen, String requiredVersion, String minJavaVersion) {
this.shortName = shortName;
this.splitWhen = new VersionNumber(splitWhen);
this.requiredVersion = requiredVersion;
this.minJavaVersion = new VersionNumber(minJavaVersion);
}

/**
Expand Down Expand Up @@ -210,5 +218,10 @@ public VersionNumber getRequiredVersion() {
public String toString() {
return shortName + " " + splitWhen.toString().replace(".*", "") + " " + requiredVersion;
}

@Nonnull
public VersionNumber getMinJavaVersion() {
batmat marked this conversation as resolved.
Show resolved Hide resolved
return minJavaVersion;
}
}
}
3 changes: 3 additions & 0 deletions core/src/main/resources/jenkins/split-plugin-cycles.txt
Expand Up @@ -10,3 +10,6 @@ script-security command-launcher
script-security matrix-auth
script-security matrix-project
script-security windows-slaves
script-security jaxb
oleg-nenashev marked this conversation as resolved.
Show resolved Hide resolved
command-launcher jaxb
jdk-tool jaxb
5 changes: 4 additions & 1 deletion core/src/main/resources/jenkins/split-plugins.txt
@@ -1,6 +1,6 @@
# See ClassicPluginStrategy.DETACHED_LIST. As of JENKINS-47634 also used by plugin-compat-tester.

# Columns are: plugin ID, last core release still containing the plugin's functionality, plugin version that's implied.
# Columns are: plugin ID, last core release still containing the plugin's functionality, plugin version that's implied, min jdk version where to install the plugin
batmat marked this conversation as resolved.
Show resolved Hide resolved

# Note that all split plugins between and including matrix-auth and jdk-tool incorrectly use the first
# core release without the plugin's functionality when they should use the immediately prior release.
Expand All @@ -25,3 +25,6 @@ bouncycastle-api 2.16 2.16.0
command-launcher 2.86 1.0
# JENKINS-22367
jdk-tool 2.112 1.0

# JENKINS-55681
jaxb 2.161 2.2.11 11
34 changes: 34 additions & 0 deletions core/src/test/java/jenkins/plugins/DetachedPluginsManagerTest.java
@@ -0,0 +1,34 @@
package jenkins.plugins;

import hudson.model.UpdateSite;
import hudson.util.VersionNumber;
import jenkins.util.java.JavaUtils;
import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;

public class DetachedPluginsManagerTest {
@Test
public void checkJaxb() {
final List<DetachedPluginsManager.DetachedPlugin> plugins =
DetachedPluginsManager.DETACHED_LIST.stream()
.filter(plugin -> plugin.getShortName().equals("jaxb"))
.collect(Collectors.toList());
assertEquals(1, plugins.size());

DetachedPluginsManager.DetachedPlugin jaxb = plugins.get(0);

assertEquals(new VersionNumber("11"), jaxb.getMinJavaVersion());

if (JavaUtils.isRunningWithJava8OrBelow()) {
assertEquals(0, DetachedPluginsManager.getDetachedPlugins().stream()
.filter(plugin -> plugin.getShortName().equals("jaxb"))
.collect(Collectors.toList()).size());
}
}


}
6 changes: 6 additions & 0 deletions war/pom.xml
Expand Up @@ -414,6 +414,12 @@ THE SOFTWARE.
<version>1.0</version>
<type>hpi</type>
</artifactItem>
<artifactItem>
<groupId>io.jenkins.plugins</groupId>
<artifactId>jaxb</artifactId>
<version>2.2.11</version>
<type>hpi</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/detached-plugins</outputDirectory>
<stripVersion>true</stripVersion>
Expand Down