Skip to content

Commit

Permalink
Centralize internal maven artifact version queries.
Browse files Browse the repository at this point in the history
 - put all hardcoded fallback versions in one place
 - use index for updates if available
  • Loading branch information
mbien committed Dec 8, 2023
1 parent 0ce04e9 commit 92080ad
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.netbeans.modules.maven.model.pom.POMExtensibilityElement;
import org.netbeans.modules.maven.model.pom.POMModel;
import org.netbeans.modules.maven.model.pom.Plugin;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.spi.project.AuxiliaryProperties;
import org.netbeans.spi.project.ProjectServiceProvider;
import org.netbeans.spi.project.ui.ProjectOpenedHook;
Expand Down Expand Up @@ -102,7 +103,6 @@ public class MavenNbModuleImpl implements NbModuleProvider {
public static final String GROUPID_MOJO = "org.codehaus.mojo";
public static final String GROUPID_APACHE = "org.apache.netbeans.utilities";
public static final String NBM_PLUGIN = "nbm-maven-plugin";
static final String LATEST_NBM_PLUGIN_VERSION = "4.8";

public static final String NETBEANSAPI_GROUPID = "org.netbeans.api";

Expand All @@ -123,14 +123,7 @@ static List<RepositoryInfo> netbeansRepo() {
* This method will not wait for the index to be downloaded, it will return a default value instead.
*/
public static String getLatestNbmPluginVersion() {
RepositoryQueries.Result<NBVersionInfo> versionsResult = RepositoryQueries.getVersionsResult(GROUPID_APACHE, NBM_PLUGIN, null);

// Versions are sorted in descending order
return versionsResult.getResults().stream()
.map(NBVersionInfo::getVersion)
.filter(v -> !v.endsWith("-SNAPSHOT"))
.findFirst()
.orElse(LATEST_NBM_PLUGIN_VERSION);
return MavenVersionSettings.getDefault().getVersion(GROUPID_APACHE, NBM_PLUGIN);
}

private File getModuleXmlLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Set;
import javax.swing.JComponent;
import javax.swing.event.ChangeListener;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.project.MavenProject;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
Expand All @@ -52,29 +51,26 @@
import static org.netbeans.modules.maven.apisupport.Bundle.*;
import static org.netbeans.modules.maven.apisupport.MavenNbModuleImpl.APACHE_SNAPSHOT_REPO_ID;
import org.netbeans.modules.maven.embedder.EmbedderFactory;
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
import org.netbeans.modules.maven.model.pom.Plugin;
import org.netbeans.modules.maven.model.pom.PluginManagement;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.spi.project.ui.support.CommonProjectActions;

public class NbmWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> {

public static final String NBM_ARTIFACTID = "nbm_artifactId";

static final Archetype NB_MODULE_ARCH, NB_APP_ARCH;
public static final String SNAPSHOT_VERSION = "dev-SNAPSHOT";

static final Archetype NB_MODULE_ARCH;
static final Archetype NB_APP_ARCH;
static {
NB_MODULE_ARCH = new Archetype();
NB_MODULE_ARCH.setGroupId("org.apache.netbeans.archetypes"); //NOI18N
NB_MODULE_ARCH.setVersion("1.18"); //NOI18N
NB_MODULE_ARCH.setArtifactId("nbm-archetype"); //NOI18N

NB_APP_ARCH = new Archetype();
NB_APP_ARCH.setGroupId("org.apache.netbeans.archetypes"); //NOI18N
NB_APP_ARCH.setVersion("1.23"); //NOI18N
NB_APP_ARCH.setArtifactId("netbeans-platform-app-archetype"); //NOI18N

}

static final String OSGIDEPENDENCIES = "osgi.dependencies";
Expand Down Expand Up @@ -120,20 +116,9 @@ private String[] createSteps() {
}

// non blocking
private static void updateToLatestKnownArchetypeVersion(Archetype archetype) {
RepositoryQueries.Result<NBVersionInfo> versionsResult = RepositoryQueries.getVersionsResult(archetype.getGroupId(), archetype.getArtifactId(), null);

// Versions are sorted in descending order
List<NBVersionInfo> results = versionsResult.getResults();
for (NBVersionInfo result : results) {
String betterVersion = result.getVersion();
if (!betterVersion.contains("SNAPSHOT")) { // skip snapshots
if (new ComparableVersion(betterVersion).compareTo(new ComparableVersion(archetype.getVersion())) > 0) {
archetype.setVersion(betterVersion);
}
return;
}
}
private static void updateToLatestKnownArchetypeVersion(Archetype arch) {
MavenVersionSettings prefs = MavenVersionSettings.getDefault();
arch.setVersion(prefs.getVersion(arch.getGroupId(), arch.getArtifactId()));
}

@Override
Expand All @@ -151,7 +136,6 @@ public Set<FileObject> instantiate() throws IOException {
if (archetype == NB_MODULE_ARCH) {
updateToLatestKnownArchetypeVersion(NB_MODULE_ARCH);
NBMNativeMWI.instantiate(vi, projFile, version, Boolean.TRUE.equals(wiz.getProperty(OSGIDEPENDENCIES)), null);

} else {
updateToLatestKnownArchetypeVersion(NB_APP_ARCH);
ArchetypeWizards.createFromArchetype(projFile, vi, archetype, additional, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
import org.netbeans.modules.maven.indexer.api.RepositoryQueries.Result;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.validation.api.Problems;
import org.netbeans.validation.api.Severity;
import org.netbeans.validation.api.Validator;
Expand Down Expand Up @@ -152,6 +153,9 @@ private static List<String> filterVersions(Result<NBVersionInfo> result) {
.filter((v) -> !IGNORE_RELEASES.contains(v))
.sorted((v1, v2) -> v2.compareTo(v1))
.collect(Collectors.toCollection(ArrayList::new)); // must be mutable
if (versions.isEmpty()) {
versions.add(MavenVersionSettings.getDefault().getNBVersion()); // add a fallback version
}
versions.add(NbmWizardIterator.SNAPSHOT_VERSION);
return versions;
}
Expand Down
1 change: 1 addition & 0 deletions java/maven/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ OpenIDE-Module-Layer: org/netbeans/modules/maven/layer.xml
AutoUpdate-Show-In-Client: false
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
OpenIDE-Module-Recommends: org.netbeans.modules.maven.archetype
OpenIDE-Module-Java-Dependencies: Java > 11
7 changes: 3 additions & 4 deletions java/maven/nbproject/org-netbeans-modules-maven.sig
Original file line number Diff line number Diff line change
Expand Up @@ -2383,13 +2383,12 @@ supr java.lang.Enum<org.netbeans.modules.maven.options.MavenSettings$OutputTabNa
CLSS public final org.netbeans.modules.maven.options.MavenVersionSettings
fld public final static java.lang.String VERSION_COMPILER = "maven-compiler-plugin"
fld public final static java.lang.String VERSION_RESOURCES = "maven-resources-plugin"
meth protected final java.lang.String getProperty(java.lang.String)
meth protected final java.lang.String putProperty(java.lang.String,java.lang.String)
meth protected final java.util.prefs.Preferences getPreferences()
meth public java.lang.String getNBVersion()
meth public java.lang.String getVersion(java.lang.String)
meth public java.lang.String getVersion(java.lang.String,java.lang.String)
meth public static org.netbeans.modules.maven.options.MavenVersionSettings getDefault()
supr java.lang.Object
hfds INSTANCE
hfds INSTANCE,fallback

CLSS public final !enum org.netbeans.modules.maven.options.NetworkProxySettings
fld public final static org.netbeans.modules.maven.options.NetworkProxySettings ASK
Expand Down
1 change: 0 additions & 1 deletion java/maven/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial
cp.extra=${tools.jar}
javadoc.apichanges=${basedir}/apichanges.xml
javadoc.arch=${basedir}/arch.xml
javahelp.hs=maven.hs
Expand Down
9 changes: 4 additions & 5 deletions java/maven/src/org/netbeans/modules/maven/api/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
Expand Down Expand Up @@ -121,7 +120,7 @@ public void performOperation(POMModel model) {
}
}
};
Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
Utilities.performPOMModelOperations(pom, List.of(operation));
}

public static Dependency checkModelDependency(POMModel pom, String groupId, String artifactId, boolean add) {
Expand Down Expand Up @@ -331,7 +330,7 @@ public static void setSourceLevel(POMModel mdl, String sourceLevel) {
plugin = mdl.getFactory().createPlugin();
plugin.setGroupId(Constants.GROUP_APACHE_PLUGINS);
plugin.setArtifactId(Constants.PLUGIN_COMPILER);
plugin.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_COMPILER));
plugin.setVersion(MavenVersionSettings.getDefault().getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER));
mdl.getProject().getBuild().addPlugin(plugin);
}
Configuration conf = plugin.getConfiguration();
Expand Down Expand Up @@ -435,8 +434,8 @@ public static Descriptor checkLibraries(Library library) {
}
//for tests
static Descriptor checkLibraries(Map<String, String> properties) {
List<LibraryDescriptor> libs = new ArrayList<LibraryDescriptor>();
List<RepositoryDescriptor> reps = new ArrayList<RepositoryDescriptor>();
List<LibraryDescriptor> libs = new ArrayList<>();
List<RepositoryDescriptor> reps = new ArrayList<>();

String dependencies = properties.get(LIBRARY_PROP_DEPENDENCIES);
if (dependencies != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@

import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -67,8 +62,6 @@
import org.netbeans.spi.project.AuxiliaryProperties;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.HtmlBrowser;
import org.openide.util.Exceptions;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.Pair;
Expand Down Expand Up @@ -511,33 +504,33 @@ public String getValue() {

@Override
public void performOperation(POMModel model) {
Plugin old = null;
Plugin plugin;
Build bld = model.getProject().getBuild();
if (bld != null) {
old = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
} else {
bld = model.getFactory().createBuild();
model.getProject().setBuild(bld);
}
if (old != null) {
plugin = old;
} else {
plugin = model.getFactory().createPlugin();
plugin.setGroupId(Constants.GROUP_APACHE_PLUGINS);
plugin.setArtifactId(Constants.PLUGIN_COMPILER);
plugin.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_COMPILER));
bld.addPlugin(plugin);
}
Configuration config = plugin.getConfiguration();
if (config == null) {
config = model.getFactory().createConfiguration();
plugin.setConfiguration(config);
Plugin old = null;
Plugin plugin;
Build bld = model.getProject().getBuild();
if (bld != null) {
old = bld.findPluginById(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
} else {
bld = model.getFactory().createBuild();
model.getProject().setBuild(bld);
}
if (old != null) {
plugin = old;
} else {
plugin = model.getFactory().createPlugin();
plugin.setGroupId(Constants.GROUP_APACHE_PLUGINS);
plugin.setArtifactId(Constants.PLUGIN_COMPILER);
plugin.setVersion(MavenVersionSettings.getDefault().getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER));
bld.addPlugin(plugin);
}
Configuration config = plugin.getConfiguration();
if (config == null) {
config = model.getFactory().createConfiguration();
plugin.setConfiguration(config);
}
config.setSimpleParameter(param, value);
}
config.setSimpleParameter(param, value);
}

}
}

String getCompilerParam(ModelHandle2 handle, String param) {
CompilerParamOperation oper = operations.get(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package org.netbeans.modules.maven.customizer;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand Down Expand Up @@ -150,7 +148,7 @@ public void performOperation(POMModel model) {
plugin = fact.createPlugin();
plugin.setGroupId(Constants.GROUP_APACHE_PLUGINS);
plugin.setArtifactId(Constants.PLUGIN_COMPILER);
plugin.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_COMPILER));
plugin.setVersion(MavenVersionSettings.getDefault().getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER));
bld.addPlugin(plugin);
}
if (plugin != null) {
Expand All @@ -169,7 +167,7 @@ public void performOperation(POMModel model) {
plugin2 = fact.createPlugin();
plugin2.setGroupId(Constants.GROUP_APACHE_PLUGINS);
plugin2.setArtifactId(Constants.PLUGIN_RESOURCES);
plugin2.setVersion(MavenVersionSettings.getDefault().getVersion(MavenVersionSettings.VERSION_RESOURCES));
plugin2.setVersion(MavenVersionSettings.getDefault().getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_RESOURCES));
bld.addPlugin(plugin2);
}
if (plugin2 != null) {
Expand Down Expand Up @@ -225,20 +223,10 @@ public SourcesPanel( ModelHandle2 handle, NbMavenProjectImpl project, MavenProje

comEncoding.setModel(ProjectCustomizer.encodingModel(oldEncoding));
comEncoding.setRenderer(ProjectCustomizer.encodingRenderer());

comSourceLevel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handleSourceLevelChange();
}
});

comEncoding.addActionListener(new ActionListener () {
@Override
public void actionPerformed(ActionEvent e) {
handleEncodingChange();
}
});

comSourceLevel.addActionListener(e -> handleSourceLevelChange());
comEncoding.addActionListener(e -> handleEncodingChange());

txtSrc.setText(handle.getProject().getBuild().getSourceDirectory());
txtTestSrc.setText(handle.getProject().getBuild().getTestSourceDirectory());
}
Expand Down Expand Up @@ -502,7 +490,7 @@ private synchronized String[] getSourceLevels() {
current = incJavaSpecVersion(current);
}
}
sourceLevelCache = sourceLevels.toArray(new String[sourceLevels.size()]);
sourceLevelCache = sourceLevels.toArray(String[]::new);
}
return sourceLevelCache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class BootCPNodeFactory implements NodeFactory {
Collections.<Void>emptyList() :
Collections.<Void>singletonList(null);
}
@Override public Node node(Void _) {
@Override public Node node(Void v) {
return new BootCPNode(p);
}
};
Expand Down
Loading

0 comments on commit 92080ad

Please sign in to comment.