Skip to content

Commit

Permalink
Prevent endless download of artifact sources/javadoc (#252)
Browse files Browse the repository at this point in the history
+ fix total-work computation in classpath-update
+ minor clean up
  • Loading branch information
HannesWell authored and mickaelistria committed Sep 5, 2021
1 parent f23d3f8 commit 7a56eef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ private void configureAttachedSourcesAndJavadoc(IMavenProjectFacade facade, Prop
if(aKey != null) { // maybe we should try to find artifactKey little harder here?
boolean isSnapshot = aKey.getVersion().endsWith("-SNAPSHOT");
// We should update a sources/javadoc jar for a snapshot in case they're already downloaded.
File mainFile = desc.getPath() != null ? desc.getPath().toFile() : null;
File jarFile = desc.getPath() != null ? desc.getPath().toFile() : null;
File srcFile = srcPath != null ? srcPath.toFile() : null;
boolean downloadSources = (srcPath == null && mavenConfiguration.isDownloadSources())
|| (isSnapshot && isLastModifiedBefore(srcFile, mainFile));
|| (isSnapshot && isLastModifiedBefore(srcFile, jarFile));
File javaDocFile = javaDocUrl != null ? getAttachedArtifactFile(aKey, CLASSIFIER_JAVADOC) : null;
boolean downloadJavaDoc = (javaDocUrl == null && mavenConfiguration.isDownloadJavaDoc())
|| (isSnapshot && isLastModifiedBefore(javaDocFile, mainFile));
|| (isSnapshot && isLastModifiedBefore(javaDocFile, jarFile));
scheduleDownload(facade.getProject(), facade.getMavenProject(monitor), aKey, downloadSources,
downloadJavaDoc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public boolean isNotEmpty() {

private final BlockingQueue<DownloadRequest> queue = new LinkedBlockingQueue<>();

private Set<DownloadRequest> requests = new HashSet<>();

private final Set<IProject> toUpdateMavenProjects = new HashSet<>();

private final Map<IPackageFragmentRoot, Attachments> toUpdateAttachments = new HashMap<>();
Expand All @@ -156,6 +158,7 @@ public IStatus run(IProgressMonitor monitor) {
if(!status.isOK()) {
// or maybe just log and ignore?
queue.clear();
requests.clear();
toUpdateAttachments.clear();
toUpdateMavenProjects.clear();
return status;
Expand All @@ -166,6 +169,7 @@ public IStatus run(IProgressMonitor monitor) {
}
if(monitor.isCanceled()) {
queue.clear();
requests.clear();
toUpdateAttachments.clear();
toUpdateMavenProjects.clear();
return Status.CANCEL_STATUS;
Expand All @@ -179,6 +183,8 @@ public IStatus run(IProgressMonitor monitor) {
toUpdateAttachments.clear();
toUpdateMavenProjects.clear();
}
requests.clear(); // retain all elements in queue (in an efficient manner)
requests.addAll(queue); // queue might not be empty anymore (filled by updateClasspath)
subMonitor.done();
return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
Expand Down Expand Up @@ -326,8 +332,10 @@ private void scheduleDownload(IProject project, IPackageFragmentRoot fragment, A
return;
}
DownloadRequest request = new DownloadRequest(project, fragment, artifact, downloadSources, downloadJavadoc);
queue.add(request);
schedule(SCHEDULE_INTERVAL);
if(requests.add(request)) { // guard against new requests that are/will be already downloaded in this run to prevent endless loops
queue.add(request);
schedule(SCHEDULE_INTERVAL);
}
}

/**
Expand Down

0 comments on commit 7a56eef

Please sign in to comment.