Search in sources :

Example 1 with DefaultAccessRule

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

the class AbstractOsgiCompilerMojo method configureBootclasspathAccessRules.

private void configureBootclasspathAccessRules(CompilerConfiguration compilerConfiguration) throws MojoExecutionException {
    List<AccessRule> accessRules = new ArrayList<>();
    if (requireJREPackageImports) {
        accessRules.addAll(getStrictBootClasspathAccessRules());
    } else {
        accessRules.add(new DefaultAccessRule("java/**", false));
        for (String pkg : getTargetExecutionEnvironment().getSystemPackages()) {
            accessRules.add(new DefaultAccessRule(pkg.trim().replace('.', '/') + "/*", false));
        }
        // now add packages exported by framework extension bundles
        accessRules.addAll(getBundleProject().getBootClasspathExtraAccessRules(project));
    }
    if (accessRules.size() > 0) {
        compilerConfiguration.addCompilerCustomArgument("org.osgi.framework.system.packages", toString(accessRules));
    }
}
Also used : DefaultAccessRule(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule) ArrayList(java.util.ArrayList) DefaultAccessRule(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule) AccessRule(org.eclipse.tycho.classpath.ClasspathEntry.AccessRule)

Example 2 with DefaultAccessRule

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

ArrayList (java.util.ArrayList)2 AccessRule (org.eclipse.tycho.classpath.ClasspathEntry.AccessRule)2 DefaultAccessRule (org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule)2 File (java.io.File)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 State (org.eclipse.osgi.service.resolver.State)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)1 ClasspathEntry (org.eclipse.tycho.classpath.ClasspathEntry)1 DependencyEntry (org.eclipse.tycho.core.osgitools.DependencyComputer.DependencyEntry)1