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

Revert JENKINS-20679 (support for plugin Java requirement metadata) #6549

Merged
merged 4 commits into from
May 11, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1412,16 +1412,6 @@ public HttpResponse doPluginsSearch(@QueryParameter String query, @QueryParamete
if (plugin.isForNewerHudson()) {
jsonObject.put("newerCoreRequired", Messages.PluginManager_coreWarning(plugin.requiredCore));
}
if (plugin.isForNewerJava()) {
jsonObject.put("newerJavaRequired", Messages.PluginManager_javaWarning(plugin.minimumJavaVersion));
}
if (plugin.isNeededDependenciesForNewerJava()) {
VersionNumber javaVersion = plugin.getNeededDependenciesMinimumJavaVersion();
if (javaVersion == null) {
throw new IllegalStateException("java version cannot be null here");
}
jsonObject.put("dependenciesNewerJava", Messages.PluginManager_depJavaWarning(javaVersion.toString()));
}
if (plugin.hasWarnings()) {
JSONObject unresolvedSecurityWarnings = new JSONObject();
unresolvedSecurityWarnings.put("text", Messages.PluginManager_securityWarning());
Expand Down Expand Up @@ -2057,9 +2047,6 @@ private void logPluginWarnings(Map.Entry<String, VersionNumber> requestedPlugin,
if (toInstall.isForNewerHudson()) {
LOGGER.log(WARNING, "{0}@{1} was built for a newer Jenkins", new Object[] {toInstall.name, toInstall.version});
}
if (toInstall.isForNewerJava()) {
LOGGER.log(WARNING, "{0}@{1} was built for a newer Java", new Object[] {toInstall.name, toInstall.version});
}
}

/**
Expand Down
24 changes: 0 additions & 24 deletions core/src/main/java/hudson/PluginWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import hudson.model.UpdateCenter;
import hudson.model.UpdateSite;
import hudson.util.VersionNumber;
import io.jenkins.lib.versionnumber.JavaSpecificationVersion;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -75,7 +74,6 @@
import jenkins.security.UpdateSiteWarningsMonitor;
import jenkins.util.AntClassLoader;
import jenkins.util.URLClassLoader2;
import jenkins.util.java.JavaUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.LogFactory;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -690,20 +688,6 @@ private String getVersionOf(Manifest manifest) {
return null;
}

/**
* Returns the minimum Java version of this plugin, as specified in the plugin metadata.
* Generally coming from the {@code java.level} extracted as MANIFEST's metadata with
* <a href="https://github.com/jenkinsci/plugin-pom/pull/134">this addition on the plugins' parent pom</a>.
*
* @see <a href="https://github.com/jenkinsci/maven-hpi-plugin/pull/75">maven-hpi-plugin#PR-75</a>
*
* @since 2.158
*/
@Exported
public @CheckForNull String getMinimumJavaVersion() {
return manifest.getMainAttributes().getValue("Minimum-Java-Version");
}

/**
* Returns the version number of this plugin
*/
Expand Down Expand Up @@ -958,14 +942,6 @@ public boolean hasLicensesXml() {
versionDependencyError(Messages.PluginWrapper_obsoleteCore(Jenkins.getVersion().toString(), requiredCoreVersion), Jenkins.getVersion().toString(), requiredCoreVersion);
}
}

String minimumJavaVersion = getMinimumJavaVersion();
if (minimumJavaVersion != null) {
JavaSpecificationVersion actualVersion = JavaUtils.getCurrentJavaRuntimeVersionNumber();
if (actualVersion.isOlderThan(new JavaSpecificationVersion(minimumJavaVersion))) {
versionDependencyError(Messages.PluginWrapper_obsoleteJava(actualVersion.toString(), minimumJavaVersion), actualVersion.toString(), minimumJavaVersion);
}
}
}
// make sure dependencies exist
for (Dependency d : dependencies) {
Expand Down
73 changes: 2 additions & 71 deletions core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import hudson.util.HttpResponses;
import hudson.util.TextFile;
import hudson.util.VersionNumber;
import io.jenkins.lib.versionnumber.JavaSpecificationVersion;
import java.io.File;
import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -80,7 +79,6 @@
import jenkins.util.JSONSignatureValidator;
import jenkins.util.PluginLabelUtil;
import jenkins.util.SystemProperties;
import jenkins.util.java.JavaUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -1141,13 +1139,6 @@ public final class Plugin extends Entry {
*/
@Exported
public final String requiredCore;
/**
* Version of Java this plugin requires to run.
*
* @since 2.158
*/
@Exported
public final String minimumJavaVersion;
/**
* Categories for grouping plugins, taken from labels assigned to wiki page.
* Can be {@code null} if the update center does not return categories.
Expand Down Expand Up @@ -1211,7 +1202,6 @@ public Plugin(String sourceId, JSONObject o) {
this.title = get(o, "title");
this.excerpt = get(o, "excerpt");
this.compatibleSinceVersion = Util.intern(get(o, "compatibleSinceVersion"));
this.minimumJavaVersion = Util.intern(get(o, "minimumJavaVersion"));
this.latest = get(o, "latest");
this.requiredCore = Util.intern(get(o, "requiredCore"));
final String releaseTimestamp = get(o, "releaseTimestamp");
Expand Down Expand Up @@ -1301,9 +1291,9 @@ public boolean isCompatible() {

@Restricted(NoExternalUse.class) // table.jelly
public boolean isCompatible(PluginManager.MetadataCache cache) {
return isCompatibleWithInstalledVersion() && !isForNewerHudson() && !isForNewerJava() &&
return isCompatibleWithInstalledVersion() && !isForNewerHudson() &&
isNeededDependenciesCompatibleWithInstalledVersion(cache) &&
!isNeededDependenciesForNewerJenkins(cache) && !isNeededDependenciesForNewerJava();
!isNeededDependenciesForNewerJenkins(cache);
}

/**
Expand Down Expand Up @@ -1387,21 +1377,6 @@ public boolean isForNewerHudson() {
}
}

/**
* Returns true iff the plugin declares a minimum Java version and it's newer than what the Jenkins master is running on.
* @since 2.158
*/
public boolean isForNewerJava() {
try {
final JavaSpecificationVersion currentRuntimeJavaVersion = JavaUtils.getCurrentJavaRuntimeVersionNumber();
return minimumJavaVersion != null && new JavaSpecificationVersion(minimumJavaVersion).isNewerThan(
currentRuntimeJavaVersion);
} catch (NumberFormatException nfe) {
logBadMinJavaVersion();
return false; // treat this as undeclared minimum Java version
}
}

public VersionNumber getNeededDependenciesRequiredCore() {
VersionNumber versionNumber = null;
try {
Expand All @@ -1416,36 +1391,6 @@ public VersionNumber getNeededDependenciesRequiredCore() {
return versionNumber;
}

/**
* Returns the minimum Java version needed to use the plugin and all its dependencies.
* @since 2.158
* @return the minimum Java version needed to use the plugin and all its dependencies, or null if unspecified.
*/
@CheckForNull
public VersionNumber getNeededDependenciesMinimumJavaVersion() {
VersionNumber versionNumber = null;
try {
versionNumber = minimumJavaVersion == null ? null : new VersionNumber(minimumJavaVersion);
} catch (NumberFormatException nfe) {
logBadMinJavaVersion();
}
for (Plugin p : getNeededDependencies()) {
VersionNumber v = p.getNeededDependenciesMinimumJavaVersion();
if (v == null) {
continue;
}
if (versionNumber == null || v.isNewerThan(versionNumber)) {
versionNumber = v;
}
}
return versionNumber;
}

private void logBadMinJavaVersion() {
LOGGER.log(Level.WARNING, "minimumJavaVersion was specified for plugin {0} but unparseable (received {1})",
new String[]{this.name, this.minimumJavaVersion});
}

public boolean isNeededDependenciesForNewerJenkins() {
return isNeededDependenciesForNewerJenkins(new PluginManager.MetadataCache());
}
Expand All @@ -1462,20 +1407,6 @@ public boolean isNeededDependenciesForNewerJenkins(PluginManager.MetadataCache c
});
}

/**
* Returns true iff any of the plugin dependencies require a newer Java than Jenkins is running on.
*
* @since 2.158
*/
public boolean isNeededDependenciesForNewerJava() {
for (Plugin p : getNeededDependencies()) {
if (p.isForNewerJava() || p.isNeededDependenciesForNewerJava()) {
return true;
}
}
return false;
}

/**
* If at least some of the plugin's needed dependencies are already installed, and the new version of the
* needed dependencies plugin have a "compatibleSinceVersion"
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/install/SetupWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public JSONArray getPlatformPluginUpdates() {
for (UpdateSite site : jenkins.getUpdateCenter().getSiteList()) {
UpdateSite.Plugin sitePlug = site.getPlugin(pluginName);
if (sitePlug != null
&& !sitePlug.isForNewerHudson() && !sitePlug.isForNewerJava()
&& !sitePlug.isForNewerHudson()
&& !sitePlug.isNeededDependenciesForNewerJenkins()) {
foundCompatibleVersion = true;
break;
Expand Down
22 changes: 4 additions & 18 deletions core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import hudson.ClassicPluginStrategy;
import hudson.PluginWrapper;
import hudson.util.VersionNumber;
import io.jenkins.lib.versionnumber.JavaSpecificationVersion;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -17,7 +16,6 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jenkins.util.java.JavaUtils;
import org.apache.commons.io.IOUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -54,11 +52,9 @@ public class DetachedPluginsUtil {
DETACHED_LIST = Collections.unmodifiableList(configLines(is).map(line -> {
String[] pieces = line.split(" ");

// defaults to Java 1.0 to install unconditionally if unspecified
return new DetachedPluginsUtil.DetachedPlugin(pieces[0],
pieces[1] + ".*",
pieces[2],
pieces.length == 4 ? pieces[3] : "1.0");
pieces[2]);
}).collect(Collectors.toList()));
} catch (IOException x) {
throw new ExceptionInInitializerError(x);
Expand Down Expand Up @@ -101,16 +97,13 @@ public static List<PluginWrapper.Dependency> getImpliedDependencies(String plugi
}

/**
* Get the list of all plugins that have ever been {@link DetachedPlugin detached} from Jenkins core, applicable to the current Java runtime.
* Get the list of all plugins that have ever been {@link DetachedPlugin detached} from Jenkins core.
*
* @return A {@link List} of {@link DetachedPlugin}s.
* @see JavaUtils#getCurrentJavaRuntimeVersionNumber()
*/
public static @NonNull
List<DetachedPlugin> getDetachedPlugins() {
return DETACHED_LIST.stream()
.filter(plugin -> JavaUtils.getCurrentJavaRuntimeVersionNumber().isNewerThanOrEqualTo(plugin.getMinimumJavaVersion()))
.collect(Collectors.toList());
return Collections.unmodifiableList(new ArrayList<>(DETACHED_LIST));
}

/**
Expand Down Expand Up @@ -174,13 +167,11 @@ public static final class DetachedPlugin {
*/
private final VersionNumber splitWhen;
private final String requiredVersion;
private final JavaSpecificationVersion minJavaVersion;

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

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

@NonNull
public JavaSpecificationVersion getMinimumJavaVersion() {
return minJavaVersion;
}
}
}
8 changes: 0 additions & 8 deletions core/src/main/resources/hudson/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ PluginManager.parentCompatWarning=The following plugins are affected by this:
PluginManager.coreWarning=\
Warning: This plugin is built for Jenkins {0} or newer. \
Jenkins will refuse to load this plugin if installed.
PluginManager.javaWarning=\
Warning: This plugin requires Java {0} or newer. \
Jenkins will refuse to load this plugin if installed.
PluginManager.depCompatWarning=\
Warning: This plugin requires newer versions of dependencies and at least one of those plugins is not compatible with the installed version. \
This is usually the case because its behavior or APIs changed, or it uses a different settings format than the installed version. \
Expand All @@ -87,10 +84,6 @@ PluginManager.depCoreWarning=\
Warning: This plugin has dependencies on other plugins that require Jenkins {0} or newer. \
Jenkins will refuse to load the dependencies requiring a newer version of Jenkins, \
and in turn loading this plugin will fail.
PluginManager.depJavaWarning=\
Warning: this plugin has dependencies on other plugins that require Java {0} or newer. \
Jenkins will refuse to load the dependencies requiring a newer version of Jenkins, \
and in turn loading this plugin will fail.
PluginManager.securityWarning=\
Warning: This plugin version may not be safe to use. Please review the following security notices:
PluginManager.ago={0} ago
Expand Down Expand Up @@ -129,7 +122,6 @@ PluginWrapper.failed_to_load_dependency_2=Failed to load: {0} ({1} {2})
PluginWrapper.disabled_2=Required plugin is disabled: {0} ({1})
PluginWrapper.obsolete_2=Update required: {0} ({1} {2}) to be updated to {3} or higher
PluginWrapper.obsoleteCore=Jenkins ({1}) or higher required
PluginWrapper.obsoleteJava=Java ({1}) or higher required
PluginWrapper.PluginWrapperAdministrativeMonitor.DisplayName=Plugins Failed To Load
PluginWrapper.Already.Disabled=The plugin ''{0}'' was already disabled
PluginWrapper.Plugin.Has.Dependent=The plugin ''{0}'' has, at least, one dependent plugin ({1}) and the disable strategy is {2}, so it cannot be disabled
Expand Down
8 changes: 0 additions & 8 deletions core/src/main/resources/hudson/Messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ PluginManager.parentCompatWarning=Esto afecta a los siguientes plugins:
PluginManager.coreWarning=\
Aviso: Este plugin está construido para Jenkins {0} o posterior. \
Jenkins no cargará este plugin aunque está instalado.
PluginManager.javaWarning=\
Aviso: Este plugin requiere Java {0} o más reciente. \
Jenkins no cargará este plugin aunque está instalado.
PluginManager.depCompatWarning=\
Aviso: Este plugin requiere versiones más recientes de dependencias y al menos uno de esos plugins no es compatible con la versión instalada. \
Esto puede ocurrir porque su comportamiento ha cambiado o utiliza un formato de configuración diferente que la versión instalada. \
Expand All @@ -88,10 +85,6 @@ PluginManager.depCoreWarning=\
Aviso: Este plugin tiene dependencias de otros plugins que requieren Jenkins {0} o más reciente. \
Jenkins no se cargará las dependencias que requieren una versión más reciente de Jenkins. \
Por lo que no poderá cargar este plugin.
PluginManager.depJavaWarning=\
Aviso: Este plugin tiene dependencias de otros plugins que requieren Java {0} o más reciente. \
Jenkins no se cargará las dependencias que requieren una versión más reciente de Jenkins. \
Por lo que no poderá cargar este plugin.
PluginManager.securityWarning=\
Aviso: Esta versión del plugin puede no ser segura. Por favor, revise los siguientes avisos de seguridad:
PluginManager.ago=Hace {0}
Expand Down Expand Up @@ -126,7 +119,6 @@ PluginWrapper.disabledAndObsolete=Acutalización requerida: {0} ({1}) a {2} o su
PluginWrapper.disabled=El plugin requerido está desactivado: {0}
PluginWrapper.obsolete=Acutalización requerida: {0} ({1}) va a actualizar a {2} o superior
PluginWrapper.obsoleteCore=Se requiere Jenkins ({1}) o superior
PluginWrapper.obsoleteJava=Se requiere Java ({1}) o superior
PluginWrapper.PluginWrapperAdministrativeMonitor.DisplayName=No se pueden cargar los plugins
PluginWrapper.Already.Disabled=El plugin {0} ya estaba deshabilitado
PluginWrapper.Plugin.Has.Dependant=El plugin {0} tiene, al menos, un plugin dependiente ({1}) y la estrategia de deshabilitaci\u00F3n es {2}, as\u00ED que no puede ser deshabilitado
Expand Down
1 change: 0 additions & 1 deletion core/src/main/resources/hudson/Messages_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ PluginWrapper.NoSuchPlugin=Non
PluginWrapper.obsolete=Aggiornamento richiesto: {0} ({1}) deve essere \
aggiornato alla versione {2} o successiva
PluginWrapper.obsoleteCore=� richiesto Jenkins ({1}) o una versione successiva
PluginWrapper.obsoleteJava=� richiesto Java ({1}) o una versione successiva
PluginWrapper.Plugin.Disabled=Componente aggiuntivo "{0}" disabilitato
PluginWrapper.Plugin.Has.Dependent=Il componente aggiuntivo "{0}" ha almeno \
un componente aggiuntivo dipendente ({1}) e la strategia di disabilitazione \
Expand Down
Loading