Search in sources :

Example 1 with DefaultClasspathEntry

use of org.eclipse.tycho.core.osgitools.DefaultClasspathEntry in project tycho by eclipse.

the class AbstractJUnitProviderTest method classPath.

static List<ClasspathEntry> classPath(String... entries) {
    List<ClasspathEntry> result = new ArrayList<>();
    for (String entry : entries) {
        int colonIndex = entry.indexOf(':');
        assertNotSame(-1, colonIndex);
        String id = entry.substring(0, colonIndex);
        String version = entry.substring(colonIndex + 1);
        result.add(new DefaultClasspathEntry(null, new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, id, version), null, null));
    }
    return result;
}
Also used : DefaultClasspathEntry(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry) ArrayList(java.util.ArrayList) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) DefaultClasspathEntry(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry)

Example 2 with DefaultClasspathEntry

use of org.eclipse.tycho.core.osgitools.DefaultClasspathEntry in project tycho by eclipse.

the class AbstractOsgiCompilerMojo method getClasspath.

@Override
public List<ClasspathEntry> getClasspath() throws MojoExecutionException {
    TychoProject projectType = getBundleProject();
    ArrayList<ClasspathEntry> classpath = new ArrayList<>(((BundleProject) projectType).getClasspath(project));
    if (extraClasspathElements != null) {
        ArtifactRepository localRepository = session.getLocalRepository();
        List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
        for (Dependency extraDependency : extraClasspathElements) {
            Artifact artifact = repositorySystem.createDependencyArtifact(extraDependency);
            ArtifactResolutionRequest request = new ArtifactResolutionRequest();
            request.setArtifact(artifact);
            request.setLocalRepository(localRepository);
            request.setRemoteRepositories(remoteRepositories);
            request.setResolveRoot(true);
            request.setResolveTransitively(true);
            ArtifactResolutionResult result = repositorySystem.resolve(request);
            if (result.hasExceptions()) {
                throw new MojoExecutionException("Could not resolve extra classpath entry", result.getExceptions().get(0));
            }
            for (Artifact b : result.getArtifacts()) {
                MavenProject bProject = null;
                if (b instanceof ProjectArtifact) {
                    bProject = ((ProjectArtifact) b).getProject();
                }
                ArrayList<File> bLocations = new ArrayList<>();
                // TODO properly handle multiple project locations maybe
                bLocations.add(b.getFile());
                classpath.add(new DefaultClasspathEntry(DefaultReactorProject.adapt(bProject), null, bLocations, null));
            }
        }
    }
    return classpath;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact) ProjectArtifact(org.apache.maven.project.artifact.ProjectArtifact) DefaultClasspathEntry(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry) MavenProject(org.apache.maven.project.MavenProject) TychoProject(org.eclipse.tycho.core.TychoProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ProjectArtifact(org.apache.maven.project.artifact.ProjectArtifact) DefaultClasspathEntry(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)2 ClasspathEntry (org.eclipse.tycho.classpath.ClasspathEntry)2 DefaultClasspathEntry (org.eclipse.tycho.core.osgitools.DefaultClasspathEntry)2 File (java.io.File)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1 Dependency (org.apache.maven.model.Dependency)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectArtifact (org.apache.maven.project.artifact.ProjectArtifact)1 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)1 TychoProject (org.eclipse.tycho.core.TychoProject)1