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);
}
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());
}
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));
}
}
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);
}
Aggregations