Skip to content

Commit

Permalink
NB module project wizard should not use snapshot versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbien committed Sep 23, 2023
1 parent 3c33616 commit bfab626
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
Expand Down Expand Up @@ -120,18 +119,18 @@ static List<RepositoryInfo> netbeansRepo() {
}

/**
* Returns the latest known version of the NetBeans maven plugin.
* Returns the latest known version of the NetBeans maven plugin which is not a SNAPSHOT release.
* 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
List<NBVersionInfo> results = versionsResult.getResults();
if (!results.isEmpty()) {
return results.get(0).getVersion();
}
return LATEST_NBM_PLUGIN_VERSION;
return versionsResult.getResults().stream()
.map(NBVersionInfo::getVersion)
.filter(v -> !v.endsWith("-SNAPSHOT"))
.findFirst()
.orElse(LATEST_NBM_PLUGIN_VERSION);
}

private File getModuleXmlLocation() {
Expand All @@ -153,12 +152,8 @@ private Xpp3Dom getModuleDom() throws IOException, XmlPullParserException {
if (!file.exists()) {
return null;
}
FileInputStream is = new FileInputStream(file);
Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
try {
try (Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
return Xpp3DomBuilder.build(reader);
} finally {
IOUtil.close(reader);
}
}

Expand Down Expand Up @@ -188,9 +183,7 @@ public String getCodeNameBase() {
return val;
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
} catch (IOException | XmlPullParserException e) {
e.printStackTrace();
}
MavenProject prj = project.getLookup().lookup(NbMavenProject.class).getMavenProject();
Expand Down Expand Up @@ -220,8 +213,7 @@ public FileObject getSourceDirectory() {
try {
fo = FileUtil.createFolder(project.getProjectDirectory(),
getSourceDirectoryPath());
}
catch (IOException ex) {
} catch (IOException ex) {
ex.printStackTrace();
}
}
Expand All @@ -245,9 +237,7 @@ public FileObject getManifestFile() {
path = cnb.getValue();
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
} catch (IOException | XmlPullParserException e) {
e.printStackTrace();
}
return project.getProjectDirectory().getFileObject(path);
Expand Down Expand Up @@ -427,7 +417,7 @@ public File getModuleJarLocation() {
}

private class DependencyAdder implements Runnable {
List<Dependency> toAdd = new ArrayList<Dependency>();
List<Dependency> toAdd = new ArrayList<>();

private synchronized void addDependency(Dependency dep) {
toAdd.add(dep);
Expand Down Expand Up @@ -581,7 +571,7 @@ static Project findAppProject(Project nbmProject) {
}
String groupId = mp.getMavenProject().getGroupId();
String artifactId = mp.getMavenProject().getArtifactId();
List<Project> candidates = new ArrayList<Project>();
List<Project> candidates = new ArrayList<>();
for (Project p : OpenProjects.getDefault().getOpenProjects()) {
NbMavenProject mp2 = p.getLookup().lookup(NbMavenProject.class);
if (mp2 != null && NbMavenProject.TYPE_NBM_APPLICATION.equals(mp2.getPackagingType())) {
Expand All @@ -600,7 +590,7 @@ static Project findAppProject(Project nbmProject) {
if (size > 1) {
//heuristic storm
//1. similar path? colocation?
List<Project> colocated = new ArrayList<Project>();
List<Project> colocated = new ArrayList<>();
URI moduleUri = nbmProject.getProjectDirectory().toURI();
for (Project p : candidates) {
if (CollocationQuery.areCollocated(moduleUri, p.getProjectDirectory().toURI())) {
Expand Down Expand Up @@ -652,17 +642,17 @@ private File findPlatformFolder() {

@Override public FileSystem getEffectiveSystemFilesystem() throws IOException {
FileSystem projectLayer = LayerHandle.forProject(project).layer(false);
Collection<FileSystem> platformLayers = new ArrayList<FileSystem>();
Collection<FileSystem> platformLayers = new ArrayList<>();
PlatformJarProvider pjp = project.getLookup().lookup(PlatformJarProvider.class);
if (pjp != null) {
List<URL> urls = new ArrayList<URL>();
List<URL> urls = new ArrayList<>();
for (File jar : pjp.getPlatformJars()) {
// XXX use LayerHandle.forProject on this and sister modules instead
urls.addAll(LayerUtil.layersOf(jar));
}
XMLFileSystem xmlfs = new XMLFileSystem();
try {
xmlfs.setXmlUrls(urls.toArray(new URL[urls.size()]));
xmlfs.setXmlUrls(urls.toArray(new URL[0]));
} catch (PropertyVetoException x) {
throw new IOException(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static org.netbeans.modules.maven.apisupport.Bundle.*;

/**
* Panel just asking for nb platform relatd information.
* Panel just asking for nb platform related information.
* @author mkleint
*/
public class NbmWizardPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
Expand Down

0 comments on commit bfab626

Please sign in to comment.