Search in sources :

Example 1 with ClasspathEntry

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

the class TychoTest method testBundleExtraClasspath.

public void testBundleExtraClasspath() throws Exception {
    File basedir = getBasedir("projects/extraclasspath");
    File platformLocation = new File("src/test/resources/targetplatforms/basic");
    List<MavenProject> projects = getSortedProjects(basedir, platformLocation);
    assertEquals(3, projects.size());
    MavenProject b01 = projects.get(1);
    MavenProject b02 = projects.get(2);
    OsgiBundleProject projectType = (OsgiBundleProject) lookup(TychoProject.class, b02.getPackaging());
    List<ClasspathEntry> classpath = projectType.getClasspath(b02);
    assertEquals(5, classpath.size());
    // this bundle
    assertEquals(1, classpath.get(0).getLocations().size());
    assertEquals(canonicalFile("target/projects/extraclasspath/b02/target/classes"), classpath.get(0).getLocations().get(0).getCanonicalFile());
    // reference to external bundle entry not on classpath
    assertEquals(1, classpath.get(1).getLocations().size());
    assertEquals(canonicalFile("target/local-repo/.cache/tycho/org.eclipse.equinox.launcher_1.0.101.R34x_v20081125.jar/launcher.properties"), classpath.get(1).getLocations().get(0).getCanonicalFile());
    // reference to reactor project entry
    assertEquals(1, classpath.get(2).getLocations().size());
    assertEquals(canonicalFile("target/projects/extraclasspath/b01/target/lib/nested.jar-classes"), classpath.get(2).getLocations().get(0).getCanonicalFile());
    // reference to external bundle
    assertEquals(1, classpath.get(3).getLocations().size());
    assertEquals(canonicalFile("src/test/resources/targetplatforms/basic/plugins/org.eclipse.equinox.launcher_1.0.101.R34x_v20081125.jar"), classpath.get(3).getLocations().get(0).getCanonicalFile());
    // reference to project local folder
    assertEquals(1, classpath.get(4).getLocations().size());
    assertEquals(new File(basedir, "b02/classes").getCanonicalFile(), classpath.get(4).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 2 with ClasspathEntry

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

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

the class AbstractJUnitProvider method isEnabled.

@Override
public boolean isEnabled(List<ClasspathEntry> testBundleClassPath, Properties surefireProperties) {
    Set<String> junitBundleNames = getJUnitBundleNames();
    VersionRange range = getJUnitVersionRange();
    for (ClasspathEntry classpathEntry : testBundleClassPath) {
        ArtifactKey artifactKey = classpathEntry.getArtifactKey();
        if (junitBundleNames.contains(artifactKey.getId())) {
            Version version = Version.parseVersion(artifactKey.getVersion());
            if (range.includes(version)) {
                return true;
            }
        }
    }
    return false;
}
Also used : ArtifactKey(org.eclipse.tycho.ArtifactKey) Version(org.osgi.framework.Version) VersionRange(org.osgi.framework.VersionRange) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry)

Example 4 with ClasspathEntry

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

the class OsgiBundleProject method getDependencyWalker.

@Override
public ArtifactDependencyWalker getDependencyWalker(MavenProject project) {
    final DependencyArtifacts artifacts = getDependencyArtifacts(project);
    final List<ClasspathEntry> cp = getClasspath(project);
    return new ArtifactDependencyWalker() {

        @Override
        public void walk(ArtifactDependencyVisitor visitor) {
            for (ClasspathEntry entry : cp) {
                ArtifactDescriptor artifact = artifacts.getArtifact(entry.getArtifactKey());
                ArtifactKey key = artifact.getKey();
                File location = artifact.getLocation();
                ReactorProject project = artifact.getMavenProject();
                String classifier = artifact.getClassifier();
                Set<Object> installableUnits = artifact.getInstallableUnits();
                PluginDescription plugin = new DefaultPluginDescription(key, location, project, classifier, null, installableUnits);
                visitor.visitPlugin(plugin);
            }
        }

        @Override
        public void traverseFeature(File location, Feature feature, ArtifactDependencyVisitor visitor) {
        }

        @Override
        public void traverseUpdateSite(UpdateSite site, ArtifactDependencyVisitor artifactDependencyVisitor) {
        }

        @Override
        public void traverseProduct(ProductConfiguration productConfiguration, ArtifactDependencyVisitor visitor) {
        }
    };
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) ArtifactKey(org.eclipse.tycho.ArtifactKey) ProductConfiguration(org.eclipse.tycho.model.ProductConfiguration) ReactorProject(org.eclipse.tycho.ReactorProject) ArtifactDependencyWalker(org.eclipse.tycho.core.ArtifactDependencyWalker) Feature(org.eclipse.tycho.model.Feature) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) File(java.io.File) PluginDescription(org.eclipse.tycho.core.PluginDescription) UpdateSite(org.eclipse.tycho.model.UpdateSite)

Example 5 with ClasspathEntry

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

the class OsgiBundleProject method resolveClassPath.

@Override
public void resolveClassPath(MavenSession session, MavenProject project) {
    DependencyArtifacts artifacts = getDependencyArtifacts(project);
    State state = getResolverState(project, artifacts);
    if (getLogger().isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
        getLogger().debug(resolver.toDebugString(state));
    }
    BundleDescription bundleDescription = state.getBundleByLocation(project.getBasedir().getAbsolutePath());
    List<ClasspathEntry> classpath = new ArrayList<>();
    // project itself
    ArtifactDescriptor artifact = getArtifact(artifacts, project.getBasedir(), bundleDescription.getSymbolicName());
    ReactorProject projectProxy = DefaultReactorProject.adapt(project);
    List<File> projectClasspath = getThisProjectClasspath(artifact, projectProxy);
    classpath.add(new DefaultClasspathEntry(projectProxy, artifact.getKey(), projectClasspath, null));
    // build.properties/jars.extra.classpath
    addExtraClasspathEntries(classpath, projectProxy, artifacts);
    // dependencies
    List<AccessRule> strictBootClasspathAccessRules = new ArrayList<>();
    strictBootClasspathAccessRules.add(new DefaultAccessRule("java/**", false));
    for (DependencyEntry entry : dependencyComputer.computeDependencies(state.getStateHelper(), bundleDescription)) {
        if (EquinoxResolver.SYSTEM_BUNDLE_ID == entry.desc.getBundleId()) {
            if (entry.rules != null) {
                strictBootClasspathAccessRules.addAll(entry.rules);
            }
            if (EquinoxResolver.SYSTEM_BUNDLE_SYMBOLIC_NAME.equals(entry.desc.getSymbolicName())) {
                // synthetic system.bundle has no filesystem location
                continue;
            }
        }
        File location = new File(entry.desc.getLocation());
        ArtifactDescriptor otherArtifact = getArtifact(artifacts, location, entry.desc.getSymbolicName());
        ReactorProject otherProject = otherArtifact.getMavenProject();
        List<File> locations;
        if (otherProject != null) {
            locations = getOtherProjectClasspath(otherArtifact, otherProject, null);
        } else {
            locations = getBundleClasspath(otherArtifact);
        }
        if (locations.isEmpty() && !entry.rules.isEmpty()) {
            getLogger().warn("Empty classpath of required bundle " + otherArtifact);
        }
        classpath.add(new DefaultClasspathEntry(otherProject, otherArtifact.getKey(), locations, entry.rules));
    }
    project.setContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_CLASSPATH, classpath);
    project.setContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_STRICT_BOOTCLASSPATH_ACCESSRULES, strictBootClasspathAccessRules);
    project.setContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_BOOTCLASSPATH_EXTRA_ACCESSRULES, dependencyComputer.computeBootClasspathExtraAccessRules(state.getStateHelper(), bundleDescription));
    addPDESourceRoots(project);
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ArrayList(java.util.ArrayList) ReactorProject(org.eclipse.tycho.ReactorProject) DependencyEntry(org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry) DefaultAccessRule(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) State(org.eclipse.osgi.service.resolver.State) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) File(java.io.File) DefaultAccessRule(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule) AccessRule(org.eclipse.tycho.classpath.ClasspathEntry.AccessRule)

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