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

Minor NBM wizard pom generation fixes and plugin version bumps #7628

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading