-
Notifications
You must be signed in to change notification settings - Fork 89
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
Generate automatically a marker file for a maven profile depending on java level to use #578
Merged
MarkEWaite
merged 3 commits into
jenkinsci:master
from
Vlatombe:generate-java-level-markerfile
Feb 9, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/it/ensure-java-level-marker-11-migration/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
# | ||
|
||
invoker.goals=-ntp validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>4.77</version> | ||
<relativePath /> | ||
</parent> | ||
<groupId>org.jenkins-ci.tools.hpi.its</groupId> | ||
<artifactId>ensure-java-level-marker-11-migration</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>hpi</packaging> | ||
<name>MyNewPlugin</name> | ||
<properties> | ||
<jenkins.version>2.361.4</jenkins.version> | ||
<hpi-plugin.version>@project.version@</hpi-plugin.version> | ||
<spotless.check.skip>false</spotless.check.skip> | ||
</properties> | ||
</project> |
Empty file.
24 changes: 24 additions & 0 deletions
24
src/it/ensure-java-level-marker-11-migration/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
assert new File(basedir, 'target/java-level').list().length == 1 | ||
assert new File(basedir, 'target/java-level/11').exists() | ||
assert new File(basedir, 'build.log').getText('UTF-8').contains("Removing old marker file") | ||
|
||
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
# | ||
|
||
invoker.goals=-ntp validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>4.77</version> | ||
<relativePath /> | ||
</parent> | ||
<groupId>org.jenkins-ci.tools.hpi.its</groupId> | ||
<artifactId>ensure-java-level-marker-11</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>hpi</packaging> | ||
<name>MyNewPlugin</name> | ||
<properties> | ||
<jenkins.version>2.361.4</jenkins.version> | ||
<hpi-plugin.version>@project.version@</hpi-plugin.version> | ||
<spotless.check.skip>false</spotless.check.skip> | ||
</properties> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
assert new File(basedir, 'target/java-level').list().length == 1 | ||
assert new File(basedir, 'target/java-level/11').exists() | ||
|
||
return true |
73 changes: 73 additions & 0 deletions
73
src/main/java/org/jenkinsci/maven/plugins/hpi/InitializeMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.jenkinsci.maven.plugins.hpi; | ||
|
||
import hudson.util.VersionNumber; | ||
import io.jenkins.lib.versionnumber.JavaSpecificationVersion; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
|
||
/** | ||
* Configure Maven for the desired version of Java. | ||
* | ||
* @author Basil Crow | ||
*/ | ||
@Mojo(name = "initialize", defaultPhase = LifecyclePhase.INITIALIZE) | ||
public class InitializeMojo extends AbstractJenkinsMojo { | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException { | ||
setCompilerProperties(); | ||
} | ||
|
||
private void setCompilerProperties() throws MojoExecutionException { | ||
if (!project.getProperties().containsKey("maven.compiler.source") | ||
&& !project.getProperties().containsKey("maven.compiler.release")) { | ||
// On an older plugin parent POM that predates the setting of these values as Maven properties. | ||
return; | ||
} | ||
|
||
JavaSpecificationVersion javaVersion = getMinimumJavaVersion(); | ||
if (JavaSpecificationVersion.forCurrentJVM().isOlderThan(new VersionNumber("9"))) { | ||
// Should always be set already, but just in case... | ||
setProperty("maven.compiler.source", javaVersion.toString()); | ||
setProperty("maven.compiler.target", javaVersion.toString()); | ||
setProperty("maven.compiler.testSource", javaVersion.toString()); | ||
setProperty("maven.compiler.testTarget", javaVersion.toString()); | ||
// Should never be set already, but just in case... | ||
unsetProperty("maven.compiler.release"); | ||
unsetProperty("maven.compiler.testRelease"); | ||
} else { | ||
/* | ||
* When compiling with a Java 9+ compiler, we always rely on "release" in favor of "source" and "target", | ||
* even when compiling to Java 8 bytecode. | ||
*/ | ||
setProperty("maven.compiler.release", Integer.toString(javaVersion.toReleaseVersion())); | ||
setProperty("maven.compiler.testRelease", Integer.toString(javaVersion.toReleaseVersion())); | ||
|
||
/* | ||
* While it does not hurt to have these set to the Java specification version, it is also not needed when | ||
* "release" is in use. | ||
*/ | ||
unsetProperty("maven.compiler.source"); | ||
unsetProperty("maven.compiler.target"); | ||
unsetProperty("maven.compiler.testSource"); | ||
unsetProperty("maven.compiler.testTarget"); | ||
} | ||
} | ||
|
||
private void setProperty(String key, String value) { | ||
String currentValue = project.getProperties().getProperty(key); | ||
if (currentValue == null || !currentValue.equals(value)) { | ||
getLog().info("Setting " + key + " to " + value); | ||
project.getProperties().setProperty(key, value); | ||
} | ||
} | ||
|
||
private void unsetProperty(String key) { | ||
String currentValue = project.getProperties().getProperty(key); | ||
if (currentValue != null && !currentValue.isEmpty()) { | ||
getLog().info("Unsetting " + key); | ||
project.getProperties().remove(key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Better to update to reflect its new more limited purpose.