Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download java sources lazily for Maven projects #986

Merged
merged 1 commit into from
Apr 9, 2019

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Apr 8, 2019

Fixes #979
Requires redhat-developer/vscode-java#870

Signed-off-by: Snjezana Peco snjezana.peco@redhat.com

* @throws JavaModelException
* @throws CoreException
*/
default void getSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException {

This comment was marked as resolved.


/**
* @author Fred Bricon
*
*/
public class MavenBuildSupport implements IBuildSupport {

private static final int MAX_WAIT_MILLIS = 3000;
private static Cache<String, Boolean> cache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(1, TimeUnit.HOURS).build();

This comment was marked as resolved.

@@ -76,4 +78,17 @@ default void refresh(IResource resource, CHANGE_TYPE changeType, IProgressMonito
}
}

/**
* download source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're actually discovering AND attaching the source

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the javadoc

IClasspathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager();
buildpathManager.scheduleDownload(fragment, true, true);
waitForDownload(monitor);
buildpathManager.scheduleDownload(project, true, true);

This comment was marked as resolved.

@snjeza
Copy link
Contributor Author

snjeza commented Apr 8, 2019

@fbricon I have updated the PR.

@fbricon fbricon changed the title Download java sources lazily Download java sources lazily for Maven projects Apr 9, 2019
}
}

private void waitForDownload(IProgressMonitor monitor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use JobHelpers.waitForJobs(IJobMatcher)

IClasspathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager();
buildpathManager.scheduleDownload(fragment, true, true);
waitForDownload(monitor);
downloadRequestsCache.put(path.toString(), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move before buildpathManager.scheduleDownload(fragment, true, true); else you might get simultaneous multiple download attempts

Copy link
Contributor

@fbricon fbricon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests checking source downloads, timeouts

IJavaProject javaProject = JavaCore.create(project);
IType type = javaProject.findType("org.apache.commons.lang3.StringUtils");
IClassFile classFile = ((BinaryType) type).getClassFile();
assertTrue(classFile.getBuffer() == null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertNull

waitForJobs(DownloadSourcesJobMatcher.INSTANCE, WAIT_FOR_DOWNLOAD_SOURCE_JOB_MILLIS);
}

public static void waitForDownloadSourcesJobsTest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this class shouldn't have test specific methods. I'd rather prefer you added
public static void waitForDownloadSourcesJobs(int maxWaitMillis)

@@ -76,4 +78,17 @@ default void refresh(IResource resource, CHANGE_TYPE changeType, IProgressMonito
}
}

/**
* discover source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discover the source for classFile and attach it to the project it belongs to.

* - a class file
* @param monitor
* - a progress monitor
* @throws JavaModelException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaModelException is not in the signature

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
@snjeza
Copy link
Contributor Author

snjeza commented Apr 9, 2019

@fbricon I have updated the PR.

@fbricon fbricon merged commit 075f497 into eclipse-jdtls:master Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants