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 and preferences for overwrites
  • Loading branch information
mbien committed Nov 26, 2023
1 parent 5fe7d3d commit cc86fe1
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 176 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.NbArtifactVersionPreferences;
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 NbArtifactVersionPreferences.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.NbArtifactVersionPreferences;
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) {
NbArtifactVersionPreferences prefs = NbArtifactVersionPreferences.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 @@ -38,6 +38,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.NbArtifactVersionPreferences;
import org.netbeans.validation.api.Problems;
import org.netbeans.validation.api.Severity;
import org.netbeans.validation.api.Validator;
Expand Down Expand Up @@ -144,6 +145,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(NbArtifactVersionPreferences.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
16 changes: 9 additions & 7 deletions java/maven/nbproject/org-netbeans-modules-maven.sig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Signature file v4.1
#Version 2.159.0
#Version 2.160.0

CLSS public abstract java.awt.Component
cons protected init()
Expand Down Expand Up @@ -159,6 +159,8 @@ meth public java.awt.im.InputMethodRequests getInputMethodRequests()
meth public java.awt.image.ColorModel getColorModel()
meth public java.awt.image.VolatileImage createVolatileImage(int,int)
meth public java.awt.image.VolatileImage createVolatileImage(int,int,java.awt.ImageCapabilities) throws java.awt.AWTException
meth public java.awt.peer.ComponentPeer getPeer()
anno 0 java.lang.Deprecated()
meth public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
meth public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String)
meth public java.lang.String getName()
Expand Down Expand Up @@ -2361,7 +2363,7 @@ meth public void setUseBestMaven(boolean)
meth public void setUseBestMavenAltLocation(boolean)
meth public void setVMOptionsWrap(boolean)
supr java.lang.Object
hfds INSTANCE,MAVEN_CORE_JAR_PATTERN,PROP_ALWAYS_OUTPUT,PROP_BINARY_DOWNLOAD,PROP_CHECKSUM_POLICY,PROP_COLLAPSE_FOLDS,PROP_DEBUG,PROP_DEFAULT_JDK,PROP_DEFAULT_OPTIONS,PROP_ERRORS,PROP_EXPERIMENTAL_ALTERNATE_LOCATION,PROP_EXPERIMENTAL_USE_ALTERNATE_LOCATION,PROP_EXPERIMENTAL_USE_BEST_MAVEN,PROP_FAILURE_BEHAVIOUR,PROP_JAVADOC_DOWNLOAD,PROP_LAST_ARCHETYPE_GROUPID,PROP_LAST_ARCHETYPE_VERSION,PROP_MAVEN_RUNTIMES,PROP_OUTPUT_TAB_CONFIG,PROP_OUTPUT_TAB_NAME,PROP_PLUGIN_POLICY,PROP_PREFER_WRAPPER,PROP_REUSE_OUTPUT,PROP_SHOW_LOGGING_LEVEL,PROP_SKIP_TESTS,PROP_SOURCE_DOWNLOAD,PROP_USE_REGISTRY,PROP_VM_OPTIONS_WRAP,listeners
hfds DEFAULT_PROXY_BEHAVIOUR,INSTANCE,MAVEN_CORE_JAR_PATTERN,PROP_ALWAYS_OUTPUT,PROP_BINARY_DOWNLOAD,PROP_CHECKSUM_POLICY,PROP_COLLAPSE_FOLDS,PROP_DEBUG,PROP_DEFAULT_JDK,PROP_DEFAULT_OPTIONS,PROP_ERRORS,PROP_EXPERIMENTAL_ALTERNATE_LOCATION,PROP_EXPERIMENTAL_USE_ALTERNATE_LOCATION,PROP_EXPERIMENTAL_USE_BEST_MAVEN,PROP_FAILURE_BEHAVIOUR,PROP_JAVADOC_DOWNLOAD,PROP_LAST_ARCHETYPE_GROUPID,PROP_LAST_ARCHETYPE_VERSION,PROP_MAVEN_RUNTIMES,PROP_OUTPUT_TAB_CONFIG,PROP_OUTPUT_TAB_NAME,PROP_PLUGIN_POLICY,PROP_PREFER_WRAPPER,PROP_REUSE_OUTPUT,PROP_SHOW_LOGGING_LEVEL,PROP_SKIP_TESTS,PROP_SOURCE_DOWNLOAD,PROP_USE_REGISTRY,PROP_VM_OPTIONS_WRAP,SYSPROP_DEFAULT_PROXY_BEHAVIOUR,listeners

CLSS public final static !enum org.netbeans.modules.maven.options.MavenSettings$DownloadStrategy
outer org.netbeans.modules.maven.options.MavenSettings
Expand All @@ -2380,16 +2382,16 @@ meth public static org.netbeans.modules.maven.options.MavenSettings$OutputTabNam
meth public static org.netbeans.modules.maven.options.MavenSettings$OutputTabName[] values()
supr java.lang.Enum<org.netbeans.modules.maven.options.MavenSettings$OutputTabName>

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"
CLSS public final org.netbeans.modules.maven.options.NbArtifactVersionPreferences
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 static org.netbeans.modules.maven.options.MavenVersionSettings getDefault()
meth public java.lang.String getVersion(java.lang.String,java.lang.String)
meth public static org.netbeans.modules.maven.options.NbArtifactVersionPreferences 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
11 changes: 5 additions & 6 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 @@ -56,7 +55,7 @@
import org.netbeans.modules.maven.model.pom.Project;
import org.netbeans.modules.maven.model.pom.Repository;
import org.netbeans.modules.maven.options.MavenSettings;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.modules.maven.options.NbArtifactVersionPreferences;
import org.netbeans.modules.maven.spi.nodes.NodeUtils;
import org.openide.cookies.EditCookie;
import org.openide.cookies.LineCookie;
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(NbArtifactVersionPreferences.getDefault().getVersion(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 @@ -63,12 +58,10 @@
import org.netbeans.modules.maven.model.pom.Plugin;
import org.netbeans.modules.maven.model.pom.Properties;
import org.netbeans.modules.maven.options.DontShowAgainSettings;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.modules.maven.options.NbArtifactVersionPreferences;
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(NbArtifactVersionPreferences.getDefault().getVersion(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 All @@ -48,7 +46,7 @@
import org.netbeans.modules.maven.model.pom.Plugin;
import org.netbeans.modules.maven.model.pom.Project;
import org.netbeans.modules.maven.model.pom.Properties;
import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.modules.maven.options.NbArtifactVersionPreferences;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
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(NbArtifactVersionPreferences.getDefault().getVersion(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(NbArtifactVersionPreferences.getDefault().getVersion(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

0 comments on commit cc86fe1

Please sign in to comment.