diff --git a/java/maven/src/org/netbeans/modules/maven/actions/RefreshAction.java b/java/maven/src/org/netbeans/modules/maven/actions/RefreshAction.java index 7b4ee043db6b..85c61df18dbc 100644 --- a/java/maven/src/org/netbeans/modules/maven/actions/RefreshAction.java +++ b/java/maven/src/org/netbeans/modules/maven/actions/RefreshAction.java @@ -21,14 +21,18 @@ import java.awt.event.ActionEvent; import java.util.Collection; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import javax.swing.AbstractAction; import javax.swing.Action; import org.netbeans.modules.maven.NbMavenProjectImpl; import static org.netbeans.modules.maven.actions.Bundle.*; -import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.modules.project.dependency.ProjectReload; +import org.netbeans.modules.project.dependency.ProjectReload.ProjectState; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.awt.ActionRegistration; +import org.openide.awt.StatusDisplayer; import org.openide.util.ContextAwareAction; import org.openide.util.Lookup; import org.openide.util.NbBundle.Messages; @@ -37,7 +41,7 @@ @ActionID(id = "org.netbeans.modules.maven.refresh", category = "Project") @ActionRegistration(displayName = "#ACT_Reload_Project", lazy=false) @ActionReference(position = 1700, path = "Projects/org-netbeans-modules-maven/Actions") -@Messages("ACT_Reload_Project=Reload POM") +@Messages("ACT_Reload_Project=Reload Project") public class RefreshAction extends AbstractAction implements ContextAwareAction { private final Lookup context; @@ -59,11 +63,18 @@ private RefreshAction(Lookup lkp) { @Override public void actionPerformed(ActionEvent event) { // #166919 - need to run in RP to prevent RPing later in fireProjectReload() //since #227101 fireMavenProjectReload() always posts to the RP... - //#211217 in 3.x should not be necessary.. - //EmbedderFactory.resetCachedEmbedders(); - for (NbMavenProjectImpl prj : context.lookupAll(NbMavenProjectImpl.class)) { - NbMavenProject.fireMavenProjectReload(prj); + for (NbMavenProjectImpl prj : context.lookupAll(NbMavenProjectImpl.class)) { + CompletableFuture f = ProjectReload.withProjectState(prj, + ProjectReload.StateRequest.reload().saveModifications().toQuality(ProjectReload.Quality.SIMPLE)); + f.whenComplete((s, err) -> { + if (err instanceof CompletionException) { + err = err.getCause(); } + if (err != null) { + StatusDisplayer.getDefault().setStatusText(err.getMessage()); + } + }); + } } @Override public Action createContextAwareInstance(Lookup actionContext) { diff --git a/java/maven/src/org/netbeans/modules/maven/queries/MavenReloadImplementation.java b/java/maven/src/org/netbeans/modules/maven/queries/MavenReloadImplementation.java index 5d10d829f472..0dab9eb76010 100644 --- a/java/maven/src/org/netbeans/modules/maven/queries/MavenReloadImplementation.java +++ b/java/maven/src/org/netbeans/modules/maven/queries/MavenReloadImplementation.java @@ -38,6 +38,7 @@ import org.netbeans.modules.maven.embedder.EmbedderFactory; import org.netbeans.modules.maven.modelcache.MavenProjectCache; import org.netbeans.modules.project.dependency.ProjectReload; +import org.netbeans.modules.project.dependency.ProjectReload.Quality; import org.netbeans.modules.project.dependency.ProjectReload.StateRequest; import org.netbeans.modules.project.dependency.spi.ProjectReloadImplementation; import org.netbeans.spi.project.LookupProvider; @@ -152,12 +153,15 @@ Set findProjectFiles0(MavenProject mp) { private static class CF extends CompletableFuture> {} static ProjectReload.Quality getProjectQuality(MavenProject mp) { + if (mp == null) { + return ProjectReload.Quality.NONE; + } if (MavenProjectCache.isFallbackproject(mp)) { // could not load at all. MavenProject fallback = MavenProjectCache.getPartialProject(mp); return fallback != null ? ProjectReload.Quality.BROKEN: - ProjectReload.Quality.NONE; + ProjectReload.Quality.FALLBACK; } if (!MavenProjectCache.getPlaceholderArtifacts(mp).isEmpty()) { return ProjectReload.Quality.LOADED; @@ -165,10 +169,14 @@ static ProjectReload.Quality getProjectQuality(MavenProject mp) { return ProjectReload.Quality.RESOLVED; } - private ProjectStateData createStateData(MavenProject mp) { + private ProjectStateData createStateData(MavenProject mp, Quality q) { ProjectStateData d; - ProjectStateBuilder builder = ProjectStateData.builder(getProjectQuality(mp)). + if (q == null) { + q = getProjectQuality(mp); + } + + ProjectStateBuilder builder = ProjectStateData.builder(q). files(findProjectFiles()). timestamp(MavenProjectCache.getLoadTimestamp(mp)); builder.data(mp); @@ -222,7 +230,7 @@ private void loadMavenProject2(MavenProject p, StateRequest request, CF future) ProjectReload.Quality q = getProjectQuality(p); if (q.isAtLeast(request.getMinQuality())) { if (!request.isConsistent()) { - future.complete(createStateData(p)); + future.complete(createStateData(p, null)); return; } @@ -236,7 +244,7 @@ private void loadMavenProject2(MavenProject p, StateRequest request, CF future) } } if (!obsolete) { - future.complete(createStateData(p)); + future.complete(createStateData(p, null)); return; } } @@ -246,6 +254,7 @@ private void loadMavenProject2(MavenProject p, StateRequest request, CF future) private void loadMavenProject3(CF future) { NbMavenProjectImpl nbImpl = project.getLookup().lookup(NbMavenProjectImpl.class); + MavenProject current = nbImpl.getOriginalMavenProjectOrNull(); RequestProcessor.Task t = nbImpl.fireProjectReload(true); t.addTaskListener(new TaskListener() { @Override @@ -253,7 +262,17 @@ public void taskFinished(Task task) { task.removeTaskListener(this); // retain initial = true for the first project load. nbImpl.getFreshOriginalMavenProject().thenAccept((mp) -> { - future.complete(createStateData(mp)); + future.complete(createStateData(mp, null)); + }).exceptionally(ex -> { + MavenProject renewed = nbImpl.getOriginalMavenProjectOrNull(); + if (renewed == current) { + ProjectStateData sd = createStateData(current, Quality.BROKEN); + sd.fireChanged(false, true); + future.complete(sd); + } else { + future.complete(createStateData(renewed, Quality.BROKEN)); + } + return null; }); } });