use of org.eclipse.m2e.jdt.internal.BuildPathManager in project eclipse.jdt.ls by eclipse.
the class MavenSourceDownloader method discoverSource.
@Override
public void discoverSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException {
if (classFile == null) {
return;
}
IJavaElement element = classFile;
while (element.getParent() != null) {
element = element.getParent();
if (element instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot fragment = (IPackageFragmentRoot) element;
IPath attachmentPath = fragment.getSourceAttachmentPath();
if (attachmentPath != null && !attachmentPath.isEmpty() && attachmentPath.toFile().exists()) {
break;
}
if (fragment.isArchive()) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fragment.getPath());
IPath path = file.getFullPath();
if (path == null || !path.toFile().exists()) {
path = file.getLocation();
if (path == null) {
return;
}
}
Boolean downloaded = downloadRequestsCache.getIfPresent(path.toString());
if (downloaded == null) {
downloadRequestsCache.put(path.toString(), true);
ArtifactKey artifact = new MavenPropertiesIdentifier().identify(path, monitor);
if (artifact == null) {
artifact = new MavenCentralIdentifier().identify(path, monitor);
}
if (artifact != null) {
if (!ProjectUtils.isMavenProject(element.getJavaProject().getProject())) {
// see https://github.com/eclipse-m2e/m2e-core/commit/b547ecc358c990e182a5eaf8d36f121e43f4a8c9#diff-3967743078be6a24ba1e3ec28bfc22bdf2c88a740695411f6d20e2444fef042fR943
long lastModified;
try {
File artifactFile = DependencyUtil.getArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier());
lastModified = artifactFile.lastModified();
} catch (FileNotFoundException | CoreException e1) {
lastModified = -1;
}
if (lastModified > -1) {
try {
File sources = DependencyUtil.getSources(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
sources.setLastModified(lastModified - 1);
} catch (FileNotFoundException | CoreException e) {
// ignore
}
try {
File javadoc = DependencyUtil.getJavadoc(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
javadoc.setLastModified(lastModified - 1);
} catch (FileNotFoundException | CoreException e) {
// ignore
}
}
}
BuildPathManager buildpathManager = (BuildPathManager) MavenJdtPlugin.getDefault().getBuildpathManager();
buildpathManager.scheduleDownload(fragment, artifact, true, true);
JobHelpers.waitForDownloadSourcesJobs(MAX_TIME_MILLIS);
}
}
break;
}
}
}
}
Aggregations