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

feat(java): Migrate pom.xml to JDK8. #307

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6860f85
Merge branch 'jenkinsci:main' into main
gounthar Sep 14, 2024
5a50643
Merge pull request #18 from gounthar/ghcr
gounthar Sep 14, 2024
8d92da7
Merge pull request #19 from gounthar/ghcr
gounthar Sep 23, 2024
f637964
Merge branch 'jenkinsci:main' into main
gounthar Sep 24, 2024
dfe8d05
Merge branch 'jenkinsci:main' into main
gounthar Sep 26, 2024
7343d74
Merge branch 'jenkinsci:main' into main
gounthar Sep 30, 2024
788652d
Add POM modifier to handle POM modifications
gounthar Sep 30, 2024
6e2fb32
fix(pom): Compiles at last.
gounthar Sep 30, 2024
a8a11f5
fix(pom): Compiles at last.
gounthar Sep 30, 2024
2310c46
Merge pull request #21 from gounthar/add-pom-modifier
gounthar Sep 30, 2024
6b9176e
fix(pom): BOM version
gounthar Sep 30, 2024
2786cf3
Merge pull request #22 from gounthar/add-pom-modifier
gounthar Sep 30, 2024
da047fc
fix(pom): BOM base
gounthar Sep 30, 2024
b77064e
Merge pull request #23 from gounthar/add-pom-modifier
gounthar Sep 30, 2024
3e241ed
fix(pom): BOM base
gounthar Sep 30, 2024
45348ad
fix(pom): mvn spotless:apply
gounthar Sep 30, 2024
97f626a
fix(java): Javadoc
gounthar Oct 1, 2024
7d58035
Merge pull request #25 from gounthar/add-pom-modifier
gounthar Oct 1, 2024
86bc306
Add command line option to ignore JDK7 error
gounthar Oct 1, 2024
2bd525d
fix(java): Can deal with the Vagrant plugin.
gounthar Oct 1, 2024
4316c0c
fix(java): Changed the jenkins.version name and value after Valentin…
gounthar Oct 2, 2024
c7e5067
fix(updatecli): Changed the key to update.
gounthar Oct 2, 2024
e3e15e1
fix(java): Changed the constant name.
gounthar Oct 2, 2024
2235578
fix(java): Changed the constant name.
gounthar Oct 2, 2024
510f12e
fix(java): Changed the constant name.
gounthar Oct 2, 2024
3497b26
Merge remote-tracking branch 'upstream/main' into add-ignore-jdk7-error
gounthar Oct 2, 2024
98f4791
fix(java): Parent POM version for JDK8.
gounthar Oct 2, 2024
460c0df
Merge branch 'jenkinsci:main' into add-ignore-jdk7-error
gounthar Oct 4, 2024
36d0c91
fix(recipes): No need for the Non Null detection.
gounthar Oct 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ static class PluginOptions {
description = "List available recipes.")
public boolean listRecipes;

@Option(
names = {"--ignore-jdk7-error"},
description = "Ignore errors for plugins using JDK7 or older and launch PomModifier on the faulty pom.xml.")
public boolean ignoreJdk7Error;

public Config setup() {
Config.DEBUG = debug;
return Config.builder()
Expand All @@ -175,6 +180,7 @@ public Config setup() {
? cachePath.resolve(Settings.CACHE_SUBDIR)
: cachePath)
.withMavenHome(mavenHome)
.withIgnoreJdk7Error(ignoreJdk7Error)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Config {
private final boolean removeForks;
private final boolean exportDatatables;
private final String githubOwner;
private final boolean ignoreJdk7Error;

private Config(
String version,
Expand All @@ -45,7 +46,8 @@ private Config(
boolean skipPullRequest,
boolean removeLocalData,
boolean removeForks,
boolean exportDatatables) {
boolean exportDatatables,
boolean ignoreJdk7Error) {
this.version = version;
this.githubOwner = githubOwner;
this.plugins = plugins;
Expand All @@ -62,6 +64,7 @@ private Config(
this.removeLocalData = removeLocalData;
this.removeForks = removeForks;
this.exportDatatables = exportDatatables;
this.ignoreJdk7Error = ignoreJdk7Error;
}

public String getVersion() {
Expand Down Expand Up @@ -140,6 +143,10 @@ public boolean isExportDatatables() {
return exportDatatables;
}

public boolean isIgnoreJdk7Error() {
return ignoreJdk7Error;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -161,6 +168,7 @@ public static class Builder {
private boolean exportDatatables = false;
public boolean removeLocalData = false;
public boolean removeForks = false;
private boolean ignoreJdk7Error = false;

public Builder withVersion(String version) {
this.version = version;
Expand Down Expand Up @@ -252,6 +260,11 @@ public Builder withExportDatatables(boolean exportDatatables) {
return this;
}

public Builder withIgnoreJdk7Error(boolean ignoreJdk7Error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this flag becomes obsolete if by default we try to fix precondition error

this.ignoreJdk7Error = ignoreJdk7Error;
return this;
}

public Config build() {
return new Config(
version,
Expand All @@ -269,7 +282,8 @@ public Config build() {
skipPullRequest,
removeLocalData,
removeForks,
exportDatatables);
exportDatatables,
ignoreJdk7Error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public class Settings {

public static final String MAVEN_REWRITE_PLUGIN_VERSION;

public static final String JENKINS_MINIMUM_VERSION;

public static final String PLUGIN_PARENT_VERSION;

public static final String BOM_BASE;

public static final String BOM_VERSION;

public static final String GITHUB_TOKEN;

public static final String GITHUB_OWNER;
Expand Down Expand Up @@ -72,6 +80,10 @@ private Settings() {}
}
DEFAULT_MAVEN_HOME = getDefaultMavenHome();
MAVEN_REWRITE_PLUGIN_VERSION = getRewritePluginVersion();
JENKINS_MINIMUM_VERSION = getJenkinsMinimumVersion();
BOM_BASE = getBomBase();
BOM_VERSION = getBomVersion();
PLUGIN_PARENT_VERSION = getPluginParentVersion();
GITHUB_TOKEN = getGithubToken();
GITHUB_OWNER = getGithubOwner();
try {
Expand Down Expand Up @@ -128,6 +140,22 @@ private static Path getDefaultMavenHome() {
return readProperty("openrewrite.maven.plugin.version", "versions.properties");
}

private static @Nullable String getJenkinsMinimumVersion() {
return readProperty("jenkins.minimum.version", "versions.properties");
}

private static @Nullable String getPluginParentVersion() {
return readProperty("jenkins.plugin.parent.version", "versions.properties");
}

private static @Nullable String getBomBase() {
return readProperty("bom.base", "versions.properties");
}

private static @Nullable String getBomVersion() {
return readProperty("bom.version", "versions.properties");
}

private static @Nullable URL getUpdateCenterUrl() throws MalformedURLException {
String url = System.getenv("JENKINS_UC");
if (url != null) {
Expand Down Expand Up @@ -180,7 +208,8 @@ public static Path getPluginsDirectory(Plugin plugin) {

/**
* Read a property from a resource file.
* @param key The key to read
*
* @param key The key to read
* @param resource The resource file to read from
* @return The value of the property or null if it could not be read
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.jenkins.tools.pluginmodernizer.core.utils.HealthScoreUtils;
import io.jenkins.tools.pluginmodernizer.core.utils.JdkFetcher;
import io.jenkins.tools.pluginmodernizer.core.utils.PluginVersionUtils;
import io.jenkins.tools.pluginmodernizer.core.utils.PomModifier;
import io.jenkins.tools.pluginmodernizer.core.utils.UpdateCenterUtils;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -35,6 +36,7 @@ public class PluginModernizer {

/**
* Create a new PluginModernizer
*
* @param config The configuration to use
*/
public PluginModernizer(Config config) {
Expand Down Expand Up @@ -81,6 +83,7 @@ public void start() {

/**
* Process a plugin
*
* @param plugin The plugin to process
*/
private void process(Plugin plugin) {
Expand Down Expand Up @@ -134,7 +137,7 @@ private void process(Plugin plugin) {
LOG.debug("Plugin {} compiled successfully with JDK {}", plugin.getName(), jdk.getMajor());
} else {
LOG.debug(
"No metadata or precondition errors found for plugin {}. Skipping initial compilation.",
"There are no metadata or we found precondition errors for plugin {}. Skipping initial compilation.",
plugin.getName());
}
}
Expand All @@ -152,6 +155,23 @@ private void process(Plugin plugin) {
LOG.debug("Metadata already computed for plugin {}. Using cached metadata.", plugin.getName());
}

// Check for ignoreJdk7Error option and use PomModifier if set
if (config.isIgnoreJdk7Error() && plugin.hasPreconditionErrors()) {
LOG.info("Ignoring JDK7 error for plugin {} and modifying pom.xml", plugin.getName());
PomModifier pomModifier = new PomModifier(
plugin.getLocalRepository().resolve("pom.xml").toString());
jonesbusy marked this conversation as resolved.
Show resolved Hide resolved
pomModifier.removeOffendingProperties();
pomModifier.addBom("io.jenkins.tools.bom", Settings.BOM_BASE, Settings.BOM_VERSION);
pomModifier.updateParentPom("org.jenkins-ci.plugins", "plugin", Settings.PLUGIN_PARENT_VERSION);
pomModifier.updateJenkinsMinimalVersion(Settings.JENKINS_MINIMUM_VERSION);

pomModifier.savePom(
plugin.getLocalRepository().resolve("pom.xml").toString());
plugin.withoutErrors();
// Retry the metadata fetching
plugin.collectMetadata(mavenInvoker);
plugin.moveMetadata(cacheManager);
} else
// Abort here if we have errors
if (plugin.hasErrors() || plugin.hasPreconditionErrors()) {
plugin.addPreconditionErrors(plugin.getMetadata());
Expand Down Expand Up @@ -216,6 +236,7 @@ private void process(Plugin plugin) {

/**
* Compile a plugin
*
* @param plugin The plugin to compile
*/
private JDK compilePlugin(Plugin plugin) {
Expand All @@ -229,6 +250,7 @@ private JDK compilePlugin(Plugin plugin) {

/**
* Verify a plugin and return the first JDK that successfully verifies it, starting from the target JDK and moving backward
*
* @param plugin The plugin to verify
* @return The JDK that verifies the plugin
*/
Expand Down Expand Up @@ -268,6 +290,7 @@ private JDK verifyPlugin(Plugin plugin) {

/**
* Collect results from the plugins and display a summary
*
* @param plugins The plugins
*/
private void printResults(List<Plugin> plugins) {
Expand Down
Loading
Loading