aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2016-11-21 15:40:11 -0500
committerFred Bricon2018-05-23 15:04:20 -0400
commit45ec0e8a197d226ca4ee52070b2e369f106603c6 (patch)
tree73124c6f475418345dcfc9ae5eb18a227183e266
parenta1e24f9f417719d3685824383291f05a111a409e (diff)
downloadm2e-core-45ec0e8a197d226ca4ee52070b2e369f106603c6.tar.gz
m2e-core-45ec0e8a197d226ca4ee52070b2e369f106603c6.tar.xz
m2e-core-45ec0e8a197d226ca4ee52070b2e369f106603c6.zip
Bug 507911 : trigger Sources/Javadoc download when preferences are changed
The JDT configuration listener now listens to changes in MavenConfigurationChangeEvent.P_DOWNLOAD_JAVADOC and MavenConfigurationChangeEvent.P_DOWNLOAD_SOURCES preference properties. It schedules a new IBackgroundProcessingQueue to queue source/javadoc download request for all Maven workspace projects. Change-Id: I06f462d87db673e067373a509c538b76e487d1d9 Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java60
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java2
2 files changed, 59 insertions, 3 deletions
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java
index cc21a0d7..5d22261e 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java
@@ -23,6 +23,7 @@ import java.io.File;
import org.osgi.framework.BundleContext;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
@@ -34,6 +35,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.m2e.core.MavenPlugin;
@@ -42,7 +44,9 @@ import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.embedder.MavenConfigurationChangeEvent;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.index.IndexManager;
+import org.eclipse.m2e.core.internal.jobs.IBackgroundProcessingQueue;
import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.jdt.internal.BuildPathManager;
import org.eclipse.m2e.jdt.internal.MavenClassifierManager;
import org.eclipse.m2e.jdt.internal.Messages;
@@ -65,6 +69,8 @@ public class MavenJdtPlugin extends Plugin {
IMavenClassifierManager mavenClassifierManager;
+ WorkspaceSourceDownloadJob workspaceSourceDownloadJob;
+
/**
* @noreference see class javadoc
*/
@@ -102,9 +108,24 @@ public class MavenJdtPlugin extends Plugin {
projectManager.addMavenProjectChangedListener(this.buildpathManager);
+ workspaceSourceDownloadJob = new WorkspaceSourceDownloadJob();
+
mavenConfiguration.addConfigurationChangeListener(new AbstractMavenConfigurationChangeListener() {
public void mavenConfigurationChange(MavenConfigurationChangeEvent event) {
- if(!MavenConfigurationChangeEvent.P_USER_SETTINGS_FILE.equals(event.getKey())) {
+ String key = event.getKey();
+ if((MavenConfigurationChangeEvent.P_DOWNLOAD_JAVADOC.equals(key) && mavenConfiguration.isDownloadJavaDoc())
+ || (MavenConfigurationChangeEvent.P_DOWNLOAD_SOURCES.equals(key)
+ && mavenConfiguration.isDownloadSources())) {
+ if(workspaceSourceDownloadJob.getState() == Job.SLEEPING
+ || workspaceSourceDownloadJob.getState() == Job.WAITING) {
+ //Cancel previously scheduled job
+ workspaceSourceDownloadJob.cancel();
+ }
+ workspaceSourceDownloadJob.schedule(500);
+ return;
+ }
+
+ if(!MavenConfigurationChangeEvent.P_USER_SETTINGS_FILE.equals(key)) {
return;
}
@@ -138,7 +159,7 @@ public class MavenJdtPlugin extends Plugin {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.removeResourceChangeListener(this.buildpathManager);
-
+ workspaceSourceDownloadJob = null;
MavenPluginActivator mplugin = MavenPluginActivator.getDefault();
if(mplugin != null) {
MavenProjectManager projectManager = mplugin.getMavenProjectManager();
@@ -171,4 +192,39 @@ public class MavenJdtPlugin extends Plugin {
return this.mavenClassifierManager;
}
+ private class WorkspaceSourceDownloadJob extends Job implements IBackgroundProcessingQueue {
+
+ private boolean done;
+
+ public WorkspaceSourceDownloadJob() {
+ super("Scheduling source/javadoc downloads");
+ setPriority(BuildPathManager.SOURCE_DOWNLOAD_PRIORITY);//low priority job
+ }
+
+ public boolean isEmpty() {
+ return done;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus run(IProgressMonitor monitor) {
+ done = false;
+ IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration();
+ if(mavenConfiguration.isDownloadSources() || mavenConfiguration.isDownloadJavaDoc()) {
+ IMavenProjectFacade[] facades = MavenPlugin.getMavenProjectRegistry().getProjects();
+ for(IMavenProjectFacade facade : facades) {
+ if(monitor.isCanceled()) {
+ break;
+ }
+ IProject project = facade.getProject();
+ buildpathManager.scheduleDownload(project, mavenConfiguration.isDownloadSources(),
+ mavenConfiguration.isDownloadJavaDoc());
+ }
+ }
+ done = true;
+ return Status.OK_STATUS;
+ }
+
+ }
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
index 2667cad9..ceb28be6 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
@@ -100,7 +100,7 @@ import org.eclipse.m2e.jdt.MavenJdtPlugin;
public class BuildPathManager implements IMavenProjectChangedListener, IResourceChangeListener, IClasspathManager {
private static final Logger log = LoggerFactory.getLogger(BuildPathManager.class);
- public static final int SOURCE_DOWNLOAD_PRIORITY = 50;//Low priority
+ public static final int SOURCE_DOWNLOAD_PRIORITY = Job.DECORATE;//Low priority
// local repository variable
public static final String M2_REPO = "M2_REPO"; //$NON-NLS-1$