You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sk...@apache.org on 2020/05/07 10:54:09 UTC

[netbeans] branch master updated: [NETBEANSINFRA-6] Dynamically get the latest nbm-maven-plugin version number

This is an automated email from the ASF dual-hosted git repository.

skygo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 57e21b8  [NETBEANSINFRA-6] Dynamically get the latest nbm-maven-plugin version number
     new 7787aef  Merge pull request #2017 from oyarzun/NETBEANSINFRA-6
57e21b8 is described below

commit 57e21b83150cc4d7e380c53c2b990c6c6e69bc52
Author: Christian Oyarzun <co...@oyarzun.net>
AuthorDate: Thu Mar 12 14:43:55 2020 -0400

    [NETBEANSINFRA-6] Dynamically get the latest nbm-maven-plugin version number
---
 .../AddOSGiParamToNbmPluginConfiguration.java      |  4 +--
 .../maven/apisupport/MavenNbModuleImpl.java        | 35 ++++++++++++++++++----
 .../modules/maven/apisupport/NBMNativeMWI.java     |  2 +-
 .../apisupport/NetBeansRunParamsIDEChecker.java    |  2 +-
 .../modules/maven/apisupport/NBMNativeMWITest.java | 12 ++++----
 5 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AddOSGiParamToNbmPluginConfiguration.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AddOSGiParamToNbmPluginConfiguration.java
index c3a69ad..8d4a8df 100644
--- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AddOSGiParamToNbmPluginConfiguration.java
+++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/AddOSGiParamToNbmPluginConfiguration.java
@@ -56,14 +56,14 @@ class AddOSGiParamToNbmPluginConfiguration implements ModelOperation<POMModel> {
             //check plugin management first.
             PluginManagement pm = bld.getPluginManagement();
             if (pm != null) {
-                plg = PluginBackwardPropertyUtils.findPluginFromPluginManagement(pm);                
+                plg = PluginBackwardPropertyUtils.findPluginFromPluginManagement(pm);
             }
             if (plg == null) { // should not happen to begin with
                 plg = model.getFactory().createPlugin();
                 bld.addPlugin(plg);
                 plg.setGroupId(MavenNbModuleImpl.GROUPID_APACHE);
                 plg.setArtifactId(MavenNbModuleImpl.NBM_PLUGIN);
-                plg.setVersion(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION);
+                plg.setVersion(MavenNbModuleImpl.getLatestNbmPluginVersion());
             }
         }
         Configuration cnf = plg.getConfiguration();
diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenNbModuleImpl.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenNbModuleImpl.java
index 4203df1..daf3923 100644
--- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenNbModuleImpl.java
+++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenNbModuleImpl.java
@@ -80,6 +80,9 @@ import org.openide.filesystems.XMLFileSystem;
 import org.openide.modules.SpecificationVersion;
 import org.openide.util.RequestProcessor;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 /**
  *
  * @author mkleint
@@ -107,10 +110,11 @@ 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";
-    public static final String LATEST_NBM_PLUGIN_VERSION = "4.3";
-    
-    public static final String NETBEANSAPI_GROUPID = "org.netbeans.api";  
-    
+    private static final String LATEST_NBM_PLUGIN_VERSION = "4.3";
+
+    public static final String NETBEANSAPI_GROUPID = "org.netbeans.api";
+
+    private static final Logger LOG = Logger.getLogger("org.netbeans.modules.maven.apisupport.MavenNbModuleImpl");
 
     /** Creates a new instance of MavenNbModuleImpl 
      * @param project 
@@ -123,7 +127,28 @@ public class MavenNbModuleImpl implements NbModuleProvider {
         return Arrays.asList(
                 RepositoryPreferences.getInstance().getRepositoryInfoById(MAVEN_CENTRAL));
     }
-    
+
+    public static String getLatestNbmPluginVersion() {
+        try {
+            RepositoryQueries.Result<NBVersionInfo> versionsResult = RepositoryQueries.getVersionsResult(GROUPID_APACHE, NBM_PLUGIN, null);
+
+            if (versionsResult.isPartial()) {
+                versionsResult.waitForSkipped();
+            }
+
+            // Versions are sorted in descending order
+            List<NBVersionInfo> results = versionsResult.getResults();
+            if (!results.isEmpty()) {
+                return results.get(0).getVersion();
+            }
+        }
+        catch (NullPointerException ex) {
+            // This exceptions occurs during unit tests so default to LATEST_NBM_PLUGIN_VERSION
+            LOG.log(Level.WARNING, "Unable to get latest nbm-maven-plugin version number");
+        }
+        return LATEST_NBM_PLUGIN_VERSION;
+    }
+
     private File getModuleXmlLocation() {
         String file = PluginBackwardPropertyUtils.getPluginProperty(project, 
                     "descriptor", null, null); //NOI18N
diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java
index c3d0ac7..b1f38ce 100644
--- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java
+++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java
@@ -247,7 +247,7 @@ final class NBMNativeMWI {
                 //nbm-maven-plugin
                 boolean addPlugin = true;
                 String managedPVersion = null;
-                String pVersion = MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION;
+                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?
diff --git a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NetBeansRunParamsIDEChecker.java b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NetBeansRunParamsIDEChecker.java
index c764ea7..d0e45ef 100644
--- a/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NetBeansRunParamsIDEChecker.java
+++ b/apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NetBeansRunParamsIDEChecker.java
@@ -123,7 +123,7 @@ public class NetBeansRunParamsIDEChecker implements PrerequisitesChecker {
                     plg.setExtensions(Boolean.TRUE);
                     bld.addPlugin(plg);
                 }
-                plg.setVersion(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION); //
+                plg.setVersion(MavenNbModuleImpl.getLatestNbmPluginVersion()); //
             }
         };
     }
diff --git a/apisupport/maven.apisupport/test/unit/src/org/netbeans/modules/maven/apisupport/NBMNativeMWITest.java b/apisupport/maven.apisupport/test/unit/src/org/netbeans/modules/maven/apisupport/NBMNativeMWITest.java
index ebf12c2..e2f1991 100644
--- a/apisupport/maven.apisupport/test/unit/src/org/netbeans/modules/maven/apisupport/NBMNativeMWITest.java
+++ b/apisupport/maven.apisupport/test/unit/src/org/netbeans/modules/maven/apisupport/NBMNativeMWITest.java
@@ -58,7 +58,7 @@ public class NBMNativeMWITest extends NbTestCase {
         Model model = reader.read(new FileReader(FileUtil.toFile(builtpom)));
 
         assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
-        assertEquals(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION, model.getBuild().getPlugins().get(0).getVersion());
+        assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
         assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
         assertEquals("3.8.1", model.getBuild().getPlugins().get(1).getVersion());
         assertEquals(0, model.getRepositories().size());
@@ -76,7 +76,7 @@ public class NBMNativeMWITest extends NbTestCase {
         MavenXpp3Reader reader = new MavenXpp3Reader();
         Model model = reader.read(new FileReader(FileUtil.toFile(builtpom)));
         assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
-        assertEquals(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION, model.getBuild().getPlugins().get(0).getVersion());
+        assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
         assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
         assertEquals("3.8.1", model.getBuild().getPlugins().get(1).getVersion());
         assertEquals(1, model.getRepositories().size());
@@ -103,7 +103,7 @@ public class NBMNativeMWITest extends NbTestCase {
         Model model = reader.read(new FileReader(FileUtil.toFile(builtpom)));
 
         assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
-        assertEquals(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION, model.getBuild().getPlugins().get(0).getVersion());
+        assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
         assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
         assertEquals("3.8.1", model.getBuild().getPlugins().get(1).getVersion());
         assertEquals(0, model.getRepositories().size());
@@ -129,7 +129,7 @@ public class NBMNativeMWITest extends NbTestCase {
         Model model = reader.read(new FileReader(FileUtil.toFile(builtpom)));
 
         assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
-        assertEquals(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION, model.getBuild().getPlugins().get(0).getVersion());
+        assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
         assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
         assertEquals("3.8.1", model.getBuild().getPlugins().get(1).getVersion());
         assertEquals(1, model.getRepositories().size());
@@ -157,7 +157,7 @@ public class NBMNativeMWITest extends NbTestCase {
         Model modeloutput = readeroutput.read(new FileReader(FileUtil.toFile(builtpom)));
 
         assertEquals("nbm-maven-plugin", modeloutput.getBuild().getPlugins().get(0).getArtifactId());
-        assertEquals(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION, modeloutput.getBuild().getPlugins().get(0).getVersion());
+        assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), modeloutput.getBuild().getPlugins().get(0).getVersion());
         assertEquals("maven-compiler-plugin", modeloutput.getBuild().getPlugins().get(1).getArtifactId());
         assertEquals(null, modeloutput.getBuild().getPlugins().get(1).getVersion());
         assertEquals(0, model.getRepositories().size());
@@ -184,7 +184,7 @@ public class NBMNativeMWITest extends NbTestCase {
         Model modeloutput = readeroutput.read(new FileReader(FileUtil.toFile(builtpom)));
 
         assertEquals("nbm-maven-plugin", modeloutput.getBuild().getPlugins().get(0).getArtifactId());
-        assertEquals(MavenNbModuleImpl.LATEST_NBM_PLUGIN_VERSION, modeloutput.getBuild().getPlugins().get(0).getVersion());
+        assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), modeloutput.getBuild().getPlugins().get(0).getVersion());
         assertEquals("maven-compiler-plugin", modeloutput.getBuild().getPlugins().get(1).getArtifactId());
         assertEquals("3.8.1", modeloutput.getBuild().getPlugins().get(1).getVersion());
         assertEquals(0, model.getRepositories().size());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists