Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-09-14 07:45:56 +0000
committerFred Bricon2016-11-20 17:21:29 +0000
commite259783a7484bacb251a80081e5112b8847165f8 (patch)
tree772727c703fb51b12df6bcf41c2f172a2d950c78
parenta084af349d44c4d9a9f1fe1d34b1dc61c4cd6c19 (diff)
downloadm2e-core-e259783a7484bacb251a80081e5112b8847165f8.tar.gz
m2e-core-e259783a7484bacb251a80081e5112b8847165f8.tar.xz
m2e-core-e259783a7484bacb251a80081e5112b8847165f8.zip
Bug 500552 - Automatic download of src/javadoc run after project config
Run automatic download of sources/javadocs after project configuration rather than in parallel with "regular" dependency resolution. So downloading src/javadoc doesn't slow down download of regular jars. Make source/javadoc downloaded by default as they have now no time cost for user to get regular classpath resolution. + Added better progress reporting in the downloadSourcesJob. Change-Id: I18bf42d678cea07c8242280889358f96776f64e6 Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.m2e.core/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java2
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java47
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java39
4 files changed, 56 insertions, 34 deletions
diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
index 30d2df30..bbb25061 100644
--- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
@@ -11,7 +11,7 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.10.0",
org.eclipse.m2e.archetype.common;bundle-version="[1.8.0,1.9.0)",
org.eclipse.m2e.maven.indexer;bundle-version="[1.8.0,1.9.0)",
org.eclipse.m2e.workspace.cli;bundle-version="0.1.0",
- org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.core.resources;bundle-version="3.9.0",
com.google.guava;bundle-version="[14.0.1,16.0.0)"
Bundle-ActivationPolicy: lazy
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java
index 80688dc3..223395c7 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java
@@ -34,7 +34,7 @@ public class MavenPreferenceInitializer extends AbstractPreferenceInitializer {
store.putBoolean(MavenPreferenceConstants.P_OFFLINE, false);
store.putBoolean(MavenPreferenceConstants.P_GLOBAL_UPDATE_NEVER, true);
- store.putBoolean(MavenPreferenceConstants.P_DOWNLOAD_SOURCES, false);
+ store.putBoolean(MavenPreferenceConstants.P_DOWNLOAD_SOURCES, true);
store.putBoolean(MavenPreferenceConstants.P_DOWNLOAD_JAVADOC, false);
store.put(MavenPreferenceConstants.P_OUTPUT_FOLDER, "target-eclipse"); //$NON-NLS-1$
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 012ad9db..69f486f4 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
@@ -180,6 +180,16 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
updateClasspath(project, monitor);
}
}
+ projects.clear();
+ if(mavenConfiguration.isDownloadSources() || mavenConfiguration.isDownloadJavaDoc()) {
+ for(MavenProjectChangedEvent event : events) {
+ IFile pom = event.getSource();
+ IProject project = pom.getProject();
+ if(project.isAccessible() && projects.add(project)) {
+ scheduleDownload(project, mavenConfiguration.isDownloadSources(), mavenConfiguration.isDownloadJavaDoc());
+ }
+ }
+ }
}
public void updateClasspath(IProject project, IProgressMonitor monitor) {
@@ -308,23 +318,13 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
desc.setSourceAttachment(srcPath, srcRoot);
desc.setJavadocUrl(javaDocUrl);
-
- ArtifactKey aKey = desc.getArtifactKey();
- if(aKey != null) { // maybe we should try to find artifactKey little harder here?
- boolean downloadSources = desc.getSourceAttachmentPath() == null && srcPath == null
- && mavenConfiguration.isDownloadSources();
- boolean downloadJavaDoc = desc.getJavadocUrl() == null && javaDocUrl == null
- && mavenConfiguration.isDownloadJavaDoc();
-
- scheduleDownload(facade.getProject(), facade.getMavenProject(monitor), aKey, downloadSources, downloadJavaDoc);
- }
}
}
}
private boolean isUnavailable(ArtifactKey a, List<ArtifactRepository> repositories) throws CoreException {
- return maven.isUnavailable(a.getGroupId(), a.getArtifactId(), a.getVersion(),
- "jar" /*type*/, a.getClassifier(), repositories); //$NON-NLS-1$
+ return maven.isUnavailable(a.getGroupId(), a.getArtifactId(), a.getVersion(), "jar" /*type*/, a.getClassifier(), //$NON-NLS-1$
+ repositories);
}
// public void downloadSources(IProject project, ArtifactKey artifact, boolean downloadSources, boolean downloadJavaDoc) throws CoreException {
@@ -449,8 +449,8 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
private ArtifactKey findArtifactInIndex(IProject project, IClasspathEntry entry) throws CoreException {
IFile jarFile = project.getWorkspace().getRoot().getFile(entry.getPath());
- File file = jarFile == null || jarFile.getLocation() == null ? entry.getPath().toFile() : jarFile.getLocation()
- .toFile();
+ File file = jarFile == null || jarFile.getLocation() == null ? entry.getPath().toFile()
+ : jarFile.getLocation().toFile();
IndexedArtifactFile iaf = indexManager.getIndex(project).identify(file);
if(iaf != null) {
@@ -542,8 +542,8 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
os.close();
}
} catch(IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, -1,
- "Can't save classpath container changes", e));
+ throw new CoreException(
+ new Status(IStatus.ERROR, MavenJdtPlugin.PLUGIN_ID, -1, "Can't save classpath container changes", e));
}
// update classpath container. suboptimal as this will re-calculate classpath
@@ -650,8 +650,8 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
// can't use Maven resolve methods since they mark artifacts as not-found even if they could be resolved remotely
try {
ArtifactRepository localRepository = maven.getLocalRepository();
- String relPath = maven.getArtifactPath(localRepository, a.getGroupId(), a.getArtifactId(), a.getVersion(),
- "jar", classifier); //$NON-NLS-1$
+ String relPath = maven.getArtifactPath(localRepository, a.getGroupId(), a.getArtifactId(), a.getVersion(), "jar", //$NON-NLS-1$
+ classifier);
File file = new File(localRepository.getBasedir(), relPath).getCanonicalFile();
if(file.canRead()) {
return file;
@@ -785,7 +785,8 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
boolean downloadSources, boolean downloadJavaDoc) throws CoreException {
ArtifactKey sourcesArtifact = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getVersion(),
getSourcesClassifier(a.getClassifier()));
- ArtifactKey javadocArtifact = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getVersion(), CLASSIFIER_JAVADOC);
+ ArtifactKey javadocArtifact = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getVersion(),
+ CLASSIFIER_JAVADOC);
if(repositories != null) {
downloadSources = downloadSources && !isUnavailable(sourcesArtifact, repositories);
@@ -816,14 +817,14 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
for(int i = 0; i < cp.length; i++ ) {
IClasspathEntry entry = cp[i];
if(IClasspathEntry.CPE_LIBRARY == entry.getEntryKind() && entry.equals(fragment.getRawClasspathEntry())) {
- List<IClasspathAttribute> attributes = new ArrayList<IClasspathAttribute>(Arrays.asList(entry
- .getExtraAttributes()));
+ List<IClasspathAttribute> attributes = new ArrayList<IClasspathAttribute>(
+ Arrays.asList(entry.getExtraAttributes()));
if(srcPath == null) {
// configure javadocs if available
if(javaDocUrl != null) {
- attributes.add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
- javaDocUrl));
+ attributes
+ .add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javaDocUrl));
}
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java
index a7728698..b1babf70 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java
@@ -30,6 +30,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -142,20 +143,28 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
}
IStatus run(ArrayList<DownloadRequest> downloadRequests, IProgressMonitor monitor) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 3 * downloadRequests.size() + 5);
final ArrayList<IStatus> exceptions = new ArrayList<IStatus>();
final Set<IProject> mavenProjects = new LinkedHashSet<IProject>();
final Map<IPackageFragmentRoot, File[]> nonMavenProjects = new LinkedHashMap<IPackageFragmentRoot, File[]>();
for(DownloadRequest request : downloadRequests) {
+ SubMonitor requestMonitor = subMonitor.split(3);
try {
- IMavenProjectFacade projectFacade = projectManager.create(request.project, monitor);
+ if(request.artifact != null) {
+ requestMonitor.setTaskName(getName() + ": " + request.artifact.getArtifactId());
+ } else if(request.project != null) {
+ requestMonitor.setTaskName(getName() + ": " + request.project.getName());
+ }
+ IMavenProjectFacade projectFacade = projectManager.create(request.project, requestMonitor.split(1));
if(projectFacade != null) {
- downloadMaven(projectFacade, request.artifact, request.downloadSources, request.downloadJavaDoc, monitor);
+ downloadMaven(projectFacade, request.artifact, request.downloadSources, request.downloadJavaDoc,
+ requestMonitor.split(2));
mavenProjects.add(request.project);
} else if(request.artifact != null) {
List<ArtifactRepository> repositories = maven.getArtifactRepositories();
File[] files = downloadAttachments(request.artifact, repositories, request.downloadSources,
- request.downloadJavaDoc, monitor);
+ request.downloadJavaDoc, requestMonitor.split(2));
if(request.fragment == null) {
log.warn(
"IPackageFragmentRoot is missing, skipping javadoc/source attachment for project " + request.project);
@@ -166,19 +175,25 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
} catch(CoreException ex) {
exceptions.add(ex.getStatus());
}
+ requestMonitor.done();
}
+ // consider update classpath after each individual download?
+ // pro: user gets sources progressively (then faster)
+ // con: more save operations
+ SubMonitor updateMonitor = SubMonitor.convert(subMonitor.split(5),
+ 1 + mavenProjects.size() + nonMavenProjects.size());
if(!mavenProjects.isEmpty() || !nonMavenProjects.isEmpty()) {
ISchedulingRule schedulingRule = ResourcesPlugin.getWorkspace().getRuleFactory().buildRule();
- getJobManager().beginRule(schedulingRule, monitor);
+ getJobManager().beginRule(schedulingRule, updateMonitor.split(1));
try {
for(IProject mavenProject : mavenProjects) {
- manager.updateClasspath(mavenProject, monitor);
+ manager.updateClasspath(mavenProject, updateMonitor.split(1));
}
for(Map.Entry<IPackageFragmentRoot, File[]> entry : nonMavenProjects.entrySet()) {
File[] files = entry.getValue();
- manager.attachSourcesAndJavadoc(entry.getKey(), files[0], files[1], monitor);
+ manager.attachSourcesAndJavadoc(entry.getKey(), files[0], files[1], updateMonitor.split(1));
}
} finally {
getJobManager().endRule(schedulingRule);
@@ -258,6 +273,13 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
private void scheduleDownload(IProject project, IPackageFragmentRoot fragment, ArtifactKey artifact,
boolean downloadSources, boolean downloadJavadoc) {
+ addDownloadRequest(project, fragment, artifact, downloadSources, downloadJavadoc);
+
+ schedule(SCHEDULE_INTERVAL);
+ }
+
+ public void addDownloadRequest(IProject project, IPackageFragmentRoot fragment, ArtifactKey artifact,
+ boolean downloadSources, boolean downloadJavadoc) {
if(project == null || !project.isAccessible()) {
return;
}
@@ -265,8 +287,6 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
synchronized(this.queue) {
queue.add(new DownloadRequest(project, fragment, artifact, downloadSources, downloadJavadoc));
}
-
- schedule(SCHEDULE_INTERVAL);
}
/**
@@ -274,7 +294,8 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
* and/or javadoc of all project dependencies. Entire project classpath is updated after download. Does nothing if
* both downloadSources and downloadJavadoc are false.
*/
- public void scheduleDownload(IProject project, ArtifactKey artifact, boolean downloadSources, boolean downloadJavadoc) {
+ public void scheduleDownload(IProject project, ArtifactKey artifact, boolean downloadSources,
+ boolean downloadJavadoc) {
scheduleDownload(project, null, artifact, downloadSources, downloadJavadoc);
}

Back to the top