Search in sources :

Example 1 with MavenSourceReference

use of org.apache.sling.ide.osgi.MavenSourceReference in project sling by apache.

the class MavenSourceReferenceResolver method resolve.

@Override
public IRuntimeClasspathEntry resolve(SourceReference reference) throws CoreException {
    if (reference == null || reference.getType() != SourceReference.Type.MAVEN) {
        return null;
    }
    MavenSourceReference sr = (MavenSourceReference) reference;
    List<ArtifactRepository> repos = MavenPlugin.getMaven().getArtifactRepositories();
    Artifact jarArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "", repos, new NullProgressMonitor());
    Artifact sourcesArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "sources", repos, new NullProgressMonitor());
    IPath jarPath = Path.fromOSString(jarArtifact.getFile().getAbsolutePath());
    IPath sourcePath = Path.fromOSString(sourcesArtifact.getFile().getAbsolutePath());
    IRuntimeClasspathEntry mavenEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jarPath);
    mavenEntry.setSourceAttachmentPath(sourcePath);
    return mavenEntry;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) MavenSourceReference(org.apache.sling.ide.osgi.MavenSourceReference) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 MavenSourceReference (org.apache.sling.ide.osgi.MavenSourceReference)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)1