Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2018-01-14 12:10:22 -0500
committerFred Bricon2018-01-19 09:44:56 -0500
commit572a4db7f0a4782df8191a3719eeaa8d688de702 (patch)
tree2de0fee729ab565e4cbb0d6283a653d415bb0d66 /org.eclipse.m2e.jdt
parenta1df29e32218c8dbc6df88703c930f3f702676f6 (diff)
downloadm2e-core-572a4db7f0a4782df8191a3719eeaa8d688de702.tar.gz
m2e-core-572a4db7f0a4782df8191a3719eeaa8d688de702.tar.xz
m2e-core-572a4db7f0a4782df8191a3719eeaa8d688de702.zip
501553: download Javadoc when sources are missing
Change-Id: Ib99bbcdd4c552c769a28da616502b35c68a54910 Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.jdt')
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java42
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DownloadSourcesJob.java35
2 files changed, 49 insertions, 28 deletions
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 de0d25ba..25da83b0 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
@@ -785,28 +785,34 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
}
}
+ /**
+ * Returns an array of {@link ArtifactKey}s. ArtifactKey[0], holds the sources {@link ArtifactKey}, if source download
+ * was requested and sources are available. ArtifactKey[1], holds the javadoc {@link ArtifactKey}, if javadoc download
+ * was requested, or requested sources are unavailable, and javadoc is available
+ */
ArtifactKey[] getAttachedSourcesAndJavadoc(ArtifactKey a, List<ArtifactRepository> repositories,
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);
-
- if(repositories != null) {
- downloadSources = downloadSources && !isUnavailable(sourcesArtifact, repositories);
- downloadJavaDoc = downloadJavaDoc && !isUnavailable(javadocArtifact, repositories);
- }
-
ArtifactKey[] result = new ArtifactKey[2];
-
- if(downloadSources) {
- result[0] = sourcesArtifact;
- }
-
- if(downloadJavaDoc) {
- result[1] = javadocArtifact;
+ if(repositories != null) {
+ 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);
+ if(downloadSources) {
+ if(isUnavailable(sourcesArtifact, repositories)) {
+ // 501553: fall back to requesting JavaDoc, if requested sources are missing,
+ // but only if it doesn't exist locally
+ if(getAttachedArtifactFile(a, CLASSIFIER_JAVADOC) == null) {
+ downloadJavaDoc = true;
+ }
+ } else {
+ result[0] = sourcesArtifact;
+ }
+ }
+ if(downloadJavaDoc && !isUnavailable(javadocArtifact, repositories)) {
+ result[1] = javadocArtifact;
+ }
}
-
return result;
}
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 b1babf70..457607d1 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
@@ -158,9 +158,12 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
}
IMavenProjectFacade projectFacade = projectManager.create(request.project, requestMonitor.split(1));
if(projectFacade != null) {
- downloadMaven(projectFacade, request.artifact, request.downloadSources, request.downloadJavaDoc,
- requestMonitor.split(2));
- mavenProjects.add(request.project);
+ boolean hasDownloadedFiles = downloadMaven(projectFacade, request.artifact, request.downloadSources,
+ request.downloadJavaDoc, requestMonitor.split(2));
+ if(hasDownloadedFiles) {
+ //only perform later classpath update if something changed
+ mavenProjects.add(request.project);
+ }
} else if(request.artifact != null) {
List<ArtifactRepository> repositories = maven.getArtifactRepositories();
File[] files = downloadAttachments(request.artifact, repositories, request.downloadSources,
@@ -208,19 +211,27 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
return Status.OK_STATUS;
}
- private void downloadMaven(IMavenProjectFacade projectFacade, ArtifactKey artifact, boolean downloadSources,
+ private boolean downloadMaven(IMavenProjectFacade projectFacade, ArtifactKey artifact, boolean downloadSources,
boolean downloadJavadoc, IProgressMonitor monitor) throws CoreException {
MavenProject mavenProject = projectFacade.getMavenProject(monitor);
List<ArtifactRepository> repositories = mavenProject.getRemoteArtifactRepositories();
-
+ boolean hasDownloadedFiles = false;
+ File[] files = null;
if(artifact != null) {
- downloadAttachments(artifact, repositories, downloadSources, downloadJavadoc, monitor);
+ files = downloadAttachments(artifact, repositories, downloadSources, downloadJavadoc, monitor);
+ hasDownloadedFiles = isNotEmpty(files);
} else {
for(Artifact a : mavenProject.getArtifacts()) {
ArtifactKey aKey = new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier());
- downloadAttachments(aKey, repositories, downloadSources, downloadJavadoc, monitor);
+ files = downloadAttachments(aKey, repositories, downloadSources, downloadJavadoc, monitor);
+ hasDownloadedFiles = hasDownloadedFiles || isNotEmpty(files);
}
}
+ return hasDownloadedFiles;
+ }
+
+ private boolean isNotEmpty(File[] files) {
+ return files != null && (files[0] != null || files[1] != null);
}
private File[] downloadAttachments(ArtifactKey artifact, List<ArtifactRepository> repositories,
@@ -246,16 +257,20 @@ class DownloadSourcesJob extends Job implements IBackgroundProcessingQueue {
log.error("Could not download sources for " + artifact.toString(), e); //$NON-NLS-1$
}
}
-
+ if(monitor != null) {
+ monitor.worked(1);
+ }
if(attached[1] != null) {
try {
files[1] = download(attached[1], repositories, monitor);
log.info("Downloaded javadoc for " + artifact.toString());
} catch(CoreException e) {
- log.error("Could not download sources for " + artifact.toString(), e); //$NON-NLS-1$
+ log.error("Could not download javadoc for " + artifact.toString(), e); //$NON-NLS-1$
}
}
-
+ if(monitor != null) {
+ monitor.worked(1);
+ }
return files;
}

Back to the top