Search in sources :

Example 1 with MavenArtifactKey

use of org.eclipse.che.maven.data.MavenArtifactKey in project che by eclipse.

the class ClasspathEntryHelper method setClasspathEntry.

//Copied from org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor
private void setClasspathEntry(IClasspathEntry entry) {
    this.kind = entry.getEntryKind();
    this.path = entry.getPath();
    this.exported = entry.isExported();
    this.outputLocation = entry.getOutputLocation();
    this.accessRules = new ArrayList<>();
    for (IAccessRule rule : entry.getAccessRules()) {
        this.accessRules.add(rule);
    }
    this.attributes = new HashMap<>();
    for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
        attributes.put(attribute.getName(), attribute.getValue());
    }
    this.sourcePath = entry.getSourceAttachmentPath();
    this.sourceRootPath = entry.getSourceAttachmentRootPath();
    setInclusionPatterns(entry.getInclusionPatterns());
    setExclusionPatterns(entry.getExclusionPatterns());
    this.combineAccessRules = entry.combineAccessRules();
    String groupId = attributes.get(ClasspathManager.GROUP_ID_ATTRIBUTE);
    String artifactId = attributes.get(ClasspathManager.ARTIFACT_ID_ATTRIBUTE);
    String version = attributes.get(ClasspathManager.VERSION_ATTRIBUTE);
    String packaging = attributes.get(ClasspathManager.PACKAGING_ATTRIBUTE);
    String classifier = attributes.get(ClasspathManager.CLASSIFIER_ATTRIBUTE);
    if (groupId != null && artifactId != null && version != null) {
        this.artifactKey = new MavenArtifactKey(groupId, artifactId, version, packaging, classifier);
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 2 with MavenArtifactKey

use of org.eclipse.che.maven.data.MavenArtifactKey in project che by eclipse.

the class ClasspathManager method getArtifactKey.

private MavenArtifactKey getArtifactKey(IClasspathEntry classpathEntry) {
    IClasspathAttribute[] attributes = classpathEntry.getExtraAttributes();
    String groupId = null;
    String artifactId = null;
    String version = null;
    String packaging = null;
    String classifier = null;
    for (IClasspathAttribute attribute : attributes) {
        if (ClasspathManager.GROUP_ID_ATTRIBUTE.equals(attribute.getName())) {
            groupId = attribute.getValue();
        } else if (ClasspathManager.ARTIFACT_ID_ATTRIBUTE.equals(attribute.getName())) {
            artifactId = attribute.getValue();
        } else if (ClasspathManager.VERSION_ATTRIBUTE.equals(attribute.getName())) {
            version = attribute.getValue();
        } else if (ClasspathManager.PACKAGING_ATTRIBUTE.equals(attribute.getName())) {
            packaging = attribute.getValue();
        } else if (ClasspathManager.CLASSIFIER_ATTRIBUTE.equals(attribute.getName())) {
            classifier = attribute.getValue();
        }
    }
    if (groupId != null && artifactId != null && version != null) {
        return new MavenArtifactKey(groupId, artifactId, version, packaging, classifier);
    }
    return null;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey)

Example 3 with MavenArtifactKey

use of org.eclipse.che.maven.data.MavenArtifactKey in project che by eclipse.

the class ClasspathManager method getClasspath.

private IClasspathEntry[] getClasspath(MavenProject mavenProject) {
    ClasspathHelper helper = new ClasspathHelper(true);
    List<MavenArtifact> dependencies = mavenProject.getDependencies();
    for (MavenArtifact dependency : dependencies) {
        File file = dependency.getFile();
        if (file == null) {
            continue;
        }
        ClasspathEntryHelper entry;
        if (file.getPath().endsWith("pom.xml")) {
            String path = file.getParentFile().getPath();
            entry = helper.addProjectEntry(new Path(path.substring(workspacePath.length())));
        } else {
            entry = helper.addLibraryEntry(new Path(file.getPath()));
        }
        if (entry != null) {
            MavenArtifactKey artifactKey = new MavenArtifactKey(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getExtension(), dependency.getClassifier());
            entry.setArtifactKey(artifactKey);
            attachSources(entry);
        }
    }
    return helper.getEntries();
}
Also used : Path(org.eclipse.core.runtime.Path) MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) IClassFile(org.eclipse.jdt.core.IClassFile) File(java.io.File)

Example 4 with MavenArtifactKey

use of org.eclipse.che.maven.data.MavenArtifactKey in project che by eclipse.

the class ProjectResolverTest method testResolveArtifact.

@Test
public void testResolveArtifact() throws Exception {
    MavenArtifactKey artifactKey = new MavenArtifactKey("junit", "junit", "3.7", "jar", "");
    MavenArtifact artifact = mavenServer.resolveArtifact(artifactKey, Collections.emptyList());
    assertNotNull(artifact);
    assertTrue(artifact.isResolved());
}
Also used : MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Test(org.testng.annotations.Test)

Example 5 with MavenArtifactKey

use of org.eclipse.che.maven.data.MavenArtifactKey in project che by eclipse.

the class ProjectResolverTest method testResolveNotExistingArtifact.

@Test
public void testResolveNotExistingArtifact() throws Exception {
    MavenArtifactKey artifactKey = new MavenArtifactKey("junit", "junit", "3.56", "jar", "");
    MavenArtifact artifact = mavenServer.resolveArtifact(artifactKey, Collections.emptyList());
    assertNotNull(artifact);
    assertFalse(artifact.isResolved());
}
Also used : MavenArtifactKey(org.eclipse.che.maven.data.MavenArtifactKey) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Test(org.testng.annotations.Test)

Aggregations

MavenArtifactKey (org.eclipse.che.maven.data.MavenArtifactKey)8 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)6 Test (org.testng.annotations.Test)4 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)2 File (java.io.File)1 MavenServerWrapper (org.eclipse.che.plugin.maven.server.MavenServerWrapper)1 Path (org.eclipse.core.runtime.Path)1 IAccessRule (org.eclipse.jdt.core.IAccessRule)1 IClassFile (org.eclipse.jdt.core.IClassFile)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1