Search in sources :

Example 1 with DependencyEntry

use of org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry in project tycho by eclipse.

the class DependencyComputerTest method testStrictBootClasspathAccessRules.

@Test
public void testStrictBootClasspathAccessRules() throws Exception {
    File basedir = getBasedir("projects/bootclasspath");
    Map<File, MavenProject> basedirMap = MavenSessionUtils.getBasedirMap(getSortedProjects(basedir, null, getBasedir("p2repo")));
    // 1. bundle importing a JRE package only
    MavenProject bundle1Project = basedirMap.get(new File(basedir, "bundle1"));
    List<DependencyEntry> bundle1Dependencies = computeDependencies(bundle1Project);
    assertEquals(1, bundle1Dependencies.size());
    DependencyEntry dependency = bundle1Dependencies.get(0);
    assertEquals(1, dependency.rules.size());
    assertEquals("javax/net/ssl/*", dependency.rules.get(0).getPattern());
    // 2. bundle importing both a JRE package and an OSGi framework package
    MavenProject bundle2Project = basedirMap.get(new File(basedir, "bundle2"));
    List<DependencyEntry> bundle2Dependencies = computeDependencies(bundle2Project);
    assertEquals(1, bundle2Dependencies.size());
    DependencyEntry dependencyBundle2 = bundle2Dependencies.get(0);
    Set<String> accessRules = new HashSet<>();
    for (AccessRule rule : dependencyBundle2.rules) {
        accessRules.add(rule.getPattern());
    }
    assertEquals(new HashSet<>(asList("javax/net/ssl/*", "org/osgi/framework/*")), accessRules);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DependencyEntry(org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry) File(java.io.File) HashSet(java.util.HashSet) AccessRule(org.eclipse.tycho.classpath.ClasspathEntry.AccessRule) Test(org.junit.Test)

Example 2 with DependencyEntry

use of org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry in project tycho by eclipse.

the class DependencyComputerTest method testExportPackage.

@Test
public void testExportPackage() throws Exception {
    File basedir = getBasedir("projects/exportpackage");
    Map<File, MavenProject> basedirMap = MavenSessionUtils.getBasedirMap(getSortedProjects(basedir, null));
    MavenProject project = basedirMap.get(new File(basedir, "bundle"));
    DependencyArtifacts platform = (DependencyArtifacts) project.getContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS);
    ExecutionEnvironment executionEnvironment = TychoProjectUtils.getExecutionEnvironmentConfiguration(project).getFullSpecification();
    State state = resolver.newResolvedState(project, executionEnvironment, false, platform);
    BundleDescription bundle = state.getBundleByLocation(project.getBasedir().getAbsolutePath());
    List<DependencyEntry> dependencies = dependencyComputer.computeDependencies(state.getStateHelper(), bundle);
    Assert.assertEquals(3, dependencies.size());
    Assert.assertEquals("dep", dependencies.get(0).desc.getSymbolicName());
    Assert.assertEquals("dep2", dependencies.get(1).desc.getSymbolicName());
    Assert.assertEquals("dep3", dependencies.get(2).desc.getSymbolicName());
    Assert.assertTrue(dependencies.get(2).rules.isEmpty());
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) CustomExecutionEnvironment(org.eclipse.tycho.core.ee.CustomExecutionEnvironment) ExecutionEnvironment(org.eclipse.tycho.core.ee.shared.ExecutionEnvironment) MavenProject(org.apache.maven.project.MavenProject) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) DependencyEntry(org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry) File(java.io.File) Test(org.junit.Test)

Example 3 with DependencyEntry

use of org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry in project tycho by eclipse.

the class DependencyComputerTest method testWiringToPackageFromCustomProfile.

// TODO code reuse
@Test
public void testWiringToPackageFromCustomProfile() throws Exception {
    File basedir = getBasedir("projects/customProfile");
    Map<File, MavenProject> basedirMap = MavenSessionUtils.getBasedirMap(getSortedProjects(basedir, null));
    MavenProject project = basedirMap.get(new File(basedir, "bundle"));
    DependencyArtifacts platform = (DependencyArtifacts) project.getContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS);
    CustomExecutionEnvironment customProfile = new CustomExecutionEnvironment("custom", Arrays.asList(// 
    new SystemCapability(Type.JAVA_PACKAGE, "package.historically.not.in.jdk", "1.2.1"), // 
    new SystemCapability(Type.OSGI_EE, "OSGi/Minimum", "1.0.0"), // 
    new SystemCapability(Type.OSGI_EE, "JavaSE", "1.0.0"), // 
    new SystemCapability(Type.OSGI_EE, "JavaSE", "1.1.0"), new SystemCapability(Type.OSGI_EE, "JavaSE", "1.2.0")));
    State state = resolver.newResolvedState(project, customProfile, false, platform);
    BundleDescription bundle = state.getBundleByLocation(project.getBasedir().getAbsolutePath());
    List<DependencyEntry> dependencies = dependencyComputer.computeDependencies(state.getStateHelper(), bundle);
    if (dependencies.size() > 0) {
        assertThat(dependencies.size(), is(1));
        assertThat(dependencies.get(0).desc.getSymbolicName(), is(Constants.SYSTEM_BUNDLE_SYMBOLICNAME));
    }
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) MavenProject(org.apache.maven.project.MavenProject) SystemCapability(org.eclipse.tycho.core.ee.shared.SystemCapability) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) CustomExecutionEnvironment(org.eclipse.tycho.core.ee.CustomExecutionEnvironment) DependencyEntry(org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry) File(java.io.File) Test(org.junit.Test)

Example 4 with DependencyEntry

use of org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry 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

File (java.io.File)4 DependencyEntry (org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry)4 MavenProject (org.apache.maven.project.MavenProject)3 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)3 State (org.eclipse.osgi.service.resolver.State)3 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)3 Test (org.junit.Test)3 AccessRule (org.eclipse.tycho.classpath.ClasspathEntry.AccessRule)2 CustomExecutionEnvironment (org.eclipse.tycho.core.ee.CustomExecutionEnvironment)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 ClasspathEntry (org.eclipse.tycho.classpath.ClasspathEntry)1 ExecutionEnvironment (org.eclipse.tycho.core.ee.shared.ExecutionEnvironment)1 SystemCapability (org.eclipse.tycho.core.ee.shared.SystemCapability)1 DefaultAccessRule (org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule)1