Search in sources :

Example 6 with ClasspathEntry

use of org.eclipse.tycho.classpath.ClasspathEntry in project tycho by eclipse.

the class TychoTest method testMissingClasspathEntries.

public void testMissingClasspathEntries() throws Exception {
    File basedir = getBasedir("projects/missingentry");
    File platformLocation = new File("src/test/resources/targetplatforms/missingentry");
    MavenProject project = getSortedProjects(basedir, platformLocation).get(0);
    OsgiBundleProject projectType = (OsgiBundleProject) lookup(TychoProject.class, project.getPackaging());
    List<ClasspathEntry> classpath = projectType.getClasspath(project);
    assertEquals(3, classpath.size());
    assertEquals(1, classpath.get(1).getLocations().size());
    assertEquals(canonicalFile("src/test/resources/targetplatforms/missingentry/plugins/dirbundle_0.0.1"), classpath.get(1).getLocations().get(0).getCanonicalFile());
    assertEquals(1, classpath.get(2).getLocations().size());
    assertEquals(canonicalFile("src/test/resources/targetplatforms/missingentry/plugins/jarbundle_0.0.1.jar"), classpath.get(2).getLocations().get(0).getCanonicalFile());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) TychoProject(org.eclipse.tycho.core.TychoProject) OsgiBundleProject(org.eclipse.tycho.core.osgitools.OsgiBundleProject) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) File(java.io.File)

Example 7 with ClasspathEntry

use of org.eclipse.tycho.classpath.ClasspathEntry 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

ClasspathEntry (org.eclipse.tycho.classpath.ClasspathEntry)7 File (java.io.File)5 ArrayList (java.util.ArrayList)3 MavenProject (org.apache.maven.project.MavenProject)3 TychoProject (org.eclipse.tycho.core.TychoProject)3 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 ArtifactKey (org.eclipse.tycho.ArtifactKey)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)2 DefaultClasspathEntry (org.eclipse.tycho.core.osgitools.DefaultClasspathEntry)2 OsgiBundleProject (org.eclipse.tycho.core.osgitools.OsgiBundleProject)2 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 ProjectArtifact (org.apache.maven.project.artifact.ProjectArtifact)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 State (org.eclipse.osgi.service.resolver.State)1