Skip to content

Commit

Permalink
Merge pull request apache#7628 from mbien/nbm-wizard-version-fixes_de…
Browse files Browse the repository at this point in the history
…livery

Minor NBM wizard pom generation fixes and plugin version bumps
  • Loading branch information
ebarboni authored Aug 7, 2024
2 parents fd8c7ae + 4f80c4d commit be2a72c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
Expand All @@ -49,6 +47,7 @@
import org.netbeans.modules.maven.model.pom.Project;
import org.netbeans.modules.maven.model.pom.Repository;
import org.netbeans.modules.maven.model.pom.RepositoryPolicy;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.modules.maven.spi.newproject.CreateProjectBuilder;
import org.openide.util.Exceptions;

Expand All @@ -58,12 +57,12 @@
*/
final class NBMNativeMWI {

static void instantiate(ProjectInfo vi, File projFile, String version, boolean useOsgi, MavenProject mp) {
static void instantiate(ProjectInfo vi, File projFile, String nbVersion, boolean useOsgi, MavenProject mp) {
CreateProjectBuilder builder = new CreateProjectBuilder(projFile, vi.groupId, vi.artifactId, vi.version)
.setPackageName(vi.packageName)
.setPackaging("nbm")
.setAdditionalNonPomWork(new AdditionalFiles())
.setAdditionalOperations(new AdditionalOperations(version, useOsgi));
.setAdditionalOperations(new AdditionalOperations(nbVersion, useOsgi));
if (mp != null) {
builder = builder.setParentProject(mp);
}
Expand Down Expand Up @@ -237,7 +236,6 @@ public void performOperation(POMModel model) {
//nbm-maven-plugin
boolean addPlugin = true;
String managedPVersion = null;
String pVersion = MavenNbModuleImpl.getLatestNbmPluginVersion();
// boolean useOsgiDepsSet = false;
if (parent != null) {
//TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
Expand All @@ -259,12 +257,13 @@ public void performOperation(POMModel model) {
}
}
}
MavenVersionSettings settings = MavenVersionSettings.getDefault();
if (addPlugin) {
Plugin p = model.getFactory().createPlugin();
p.setGroupId(MavenNbModuleImpl.GROUPID_APACHE);
p.setArtifactId(MavenNbModuleImpl.NBM_PLUGIN);
if (managedPVersion == null) {
p.setVersion(pVersion);
p.setVersion(MavenNbModuleImpl.getLatestNbmPluginVersion());
}
p.setExtensions(true);
if (useOsgi) {
Expand All @@ -278,52 +277,44 @@ public void performOperation(POMModel model) {
//now comes the compiler plugin
addPlugin = true;
managedPVersion = null;
String source = null;
String target = null;
pVersion = "3.11.0";
if (parent != null) {
//TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
PluginManagement pm = parent.getPluginManagement();
if (pm != null) {
for (org.apache.maven.model.Plugin p : pm.getPlugins()) {
if (Constants.GROUP_APACHE_PLUGINS.equals(p.getGroupId()) && Constants.PLUGIN_COMPILER.equals(p.getArtifactId())) {
managedPVersion = p.getVersion();
Xpp3Dom conf = (Xpp3Dom) p.getConfiguration();
if (conf != null) {
Xpp3Dom sourceEl = conf.getChild("source");
if (sourceEl != null) {
source = sourceEl.getValue();
}
Xpp3Dom targetEl = conf.getChild("target");
if (targetEl != null) {
target = targetEl.getValue();
if (parent.getProperties().getProperty("maven.compiler.release") != null) {
addPlugin = false;
} else {
for (org.apache.maven.model.Plugin p : pm.getPlugins()) {
if (Constants.GROUP_APACHE_PLUGINS.equals(p.getGroupId()) && Constants.PLUGIN_COMPILER.equals(p.getArtifactId())) {
managedPVersion = p.getVersion();
Xpp3Dom conf = (Xpp3Dom) p.getConfiguration();
if (conf != null) {
if ( conf.getChild("release") != null
|| conf.getChild("source") != null
|| conf.getChild("target") != null) {
addPlugin = false;
}
}
break;
}
break;
}
}
}
}
addPlugin = target == null || source == null;
if (addPlugin) {
Plugin p = model.getFactory().createPlugin();
p.setGroupId(Constants.GROUP_APACHE_PLUGINS);
p.setArtifactId(Constants.PLUGIN_COMPILER);
if (managedPVersion == null) {
p.setVersion(pVersion);
p.setVersion(settings.getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER));
}
Configuration c = model.getFactory().createConfiguration();
c.setSimpleParameter("source", "1.8");
c.setSimpleParameter("target", "1.8");
p.setConfiguration(c);
getOrCreateBuild(model).addPlugin(p);
model.getProject().getProperties().setProperty("maven.compiler.release", "17");
}

//now the jar plugin
addPlugin = true;
managedPVersion = null;
String useManifest = null;
pVersion = "3.3.0";
if (parent != null) {
//TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
PluginManagement pm = parent.getPluginManagement();
Expand Down Expand Up @@ -359,6 +350,7 @@ public void performOperation(POMModel model) {
p.setGroupId(Constants.GROUP_APACHE_PLUGINS);
p.setArtifactId(Constants.PLUGIN_JAR);
if (managedPVersion == null) {
String pVersion = settings.getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_JAR);
p.setVersion(pVersion);
managedPVersion = pVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

public class NBMNativeMWITest extends NbTestCase {

private static final String EXPECTED_JAVAC_PLUGIN_VERSION = "3.13.0";

private FileObject wd;

public NBMNativeMWITest(String testName) {
Expand All @@ -64,7 +66,7 @@ public void testPathNoParent() throws IOException, XmlPullParserException {
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
assertEquals(0, model.getRepositories().size());
}

Expand All @@ -82,7 +84,7 @@ public void testPathNoParentSnapshot() throws IOException, XmlPullParserExceptio
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
assertEquals(1, model.getRepositories().size());
}

Expand All @@ -109,7 +111,7 @@ public void testPathParent() throws IOException, XmlPullParserException {
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
assertEquals(0, model.getRepositories().size());
}

Expand All @@ -135,7 +137,7 @@ public void testPathParentSnapshot() throws IOException, XmlPullParserException
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
assertEquals(1, model.getRepositories().size());
}

Expand Down Expand Up @@ -190,7 +192,7 @@ public void testPathParentJar() throws IOException, XmlPullParserException {
assertEquals("nbm-maven-plugin", modeloutput.getBuild().getPlugins().get(0).getArtifactId());
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), modeloutput.getBuild().getPlugins().get(0).getVersion());
assertEquals("maven-compiler-plugin", modeloutput.getBuild().getPlugins().get(1).getArtifactId());
assertEquals("3.11.0", modeloutput.getBuild().getPlugins().get(1).getVersion());
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, modeloutput.getBuild().getPlugins().get(1).getVersion());
assertEquals(0, model.getRepositories().size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public final class MavenVersionSettings {

static {
// TODO update periodically - modifications might require unit test adjustments
String nb_version = "RELEASE220";
String nb_utilities_version = "14.1";
String nb_version = "RELEASE230";
String nb_utilities_version = "14.2";
fallback = Map.ofEntries(
entry(key("org.netbeans.api", "org-netbeans-modules-editor"), nb_version), // represents all other nb artifacts
entry(key(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER), "3.13.0"),
entry(key(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_JAR), "3.4.2"),
entry(key(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_RESOURCES), "3.3.1"),
entry(key(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_FAILSAFE), "3.3.1"),
entry(key(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_SUREFIRE), "3.3.1"),
Expand All @@ -57,8 +58,8 @@ public final class MavenVersionSettings {
entry(key("org.apache.netbeans.utilities", "nbm-shared"), nb_utilities_version),
entry(key("org.apache.netbeans.utilities", "nbm-repository-plugin"), nb_utilities_version),
entry(key("org.apache.netbeans.utilities", "nbm-maven-plugin"), nb_utilities_version),
entry(key("org.apache.netbeans.archetypes", "nbm-archetype"), "1.18"),
entry(key("org.apache.netbeans.archetypes", "netbeans-platform-app-archetype"), "1.23")
entry(key("org.apache.netbeans.archetypes", "nbm-archetype"), "1.19"),
entry(key("org.apache.netbeans.archetypes", "netbeans-platform-app-archetype"), "1.24")
);
}

Expand Down

0 comments on commit be2a72c

Please sign in to comment.