Search in sources :

Example 21 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class EquinoxResolver method newState.

protected State newState(DependencyArtifacts artifacts, Properties properties, boolean ignoreEE) throws BundleException {
    State state = factory.createState(true);
    Map<File, Dictionary<String, String>> systemBundles = new LinkedHashMap<>();
    Map<File, Dictionary<String, String>> externalBundles = new LinkedHashMap<>();
    Map<File, Dictionary<String, String>> projects = new LinkedHashMap<>();
    for (ArtifactDescriptor artifact : artifacts.getArtifacts(ArtifactType.TYPE_ECLIPSE_PLUGIN)) {
        File location = artifact.getLocation();
        Dictionary<String, String> mf = loadManifest(location);
        if (isFrameworkImplementation(location, mf)) {
            systemBundles.put(location, mf);
        } else if (artifact.getMavenProject() != null) {
            projects.put(location, mf);
        } else {
            externalBundles.put(location, mf);
        }
    }
    long id = SYSTEM_BUNDLE_ID;
    if (systemBundles.isEmpty()) {
        // there were no OSGi framework implementations among bundles being resolve
        // fabricate system.bundle to export visible JRE packages
        state.addBundle(factory.createBundleDescription(state, getSystemBundleManifest(properties), "", id++));
    } else {
        // TODO test what happens when multiple framework implementations are present
        for (Map.Entry<File, Dictionary<String, String>> entry : systemBundles.entrySet()) {
            addBundle(state, id++, entry.getKey(), entry.getValue(), false);
        }
    }
    for (Map.Entry<File, Dictionary<String, String>> entry : externalBundles.entrySet()) {
        addBundle(state, id++, entry.getKey(), entry.getValue(), false);
    }
    for (Map.Entry<File, Dictionary<String, String>> entry : projects.entrySet()) {
        // make sure reactor projects override anything from the target platform
        // that has the same bundle symbolic name
        addBundle(state, id++, entry.getKey(), entry.getValue(), true);
    }
    List<Dictionary<Object, Object>> allProps = new ArrayList<>();
    // force our system.bundle
    Hashtable<Object, Object> platformProperties = new Hashtable<>(properties);
    platformProperties.put(StateImpl.STATE_SYSTEM_BUNDLE, state.getBundle(SYSTEM_BUNDLE_ID).getSymbolicName());
    allProps.add(platformProperties);
    if (ignoreEE) {
        // ignoring EE by adding all known EEs
        for (String profile : ExecutionEnvironmentUtils.getProfileNames()) {
            Properties envProps = ExecutionEnvironmentUtils.getExecutionEnvironment(profile).getProfileProperties();
            String systemPackages = envProps.getProperty("org.osgi.framework.system.packages");
            String execEnv = envProps.getProperty("org.osgi.framework.executionenvironment");
            Dictionary<Object, Object> prop = new Hashtable<>();
            prop.put("org.osgi.framework.system.packages", systemPackages);
            prop.put("org.osgi.framework.executionenvironment", execEnv);
            allProps.add(prop);
        }
    }
    Dictionary<Object, Object>[] stateProperties = allProps.toArray(new Dictionary[allProps.size()]);
    state.setPlatformProperties(stateProperties);
    return state;
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) State(org.eclipse.osgi.service.resolver.State) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 22 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor 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)

Example 23 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class OsgiBundleProject method addExtraClasspathEntries.

private void addExtraClasspathEntries(List<ClasspathEntry> classpath, ReactorProject project, DependencyArtifacts artifacts) {
    EclipsePluginProject pdeProject = getEclipsePluginProject(project);
    Collection<BuildOutputJar> outputJars = pdeProject.getOutputJarMap().values();
    for (BuildOutputJar buildOutputJar : outputJars) {
        List<String> entries = buildOutputJar.getExtraClasspathEntries();
        for (String entry : entries) {
            Pattern platformURL = Pattern.compile("platform:/(plugin|fragment)/([^/]*)/*(.*)");
            Matcher m = platformURL.matcher(entry.trim());
            String bundleId = null;
            String path = null;
            if (m.matches()) {
                bundleId = m.group(2).trim();
                path = m.group(3).trim();
                if (path != null && path.length() <= 0) {
                    path = null;
                }
                ArtifactDescriptor matchingBundle = artifacts.getArtifact(ArtifactType.TYPE_ECLIPSE_PLUGIN, bundleId, null);
                if (matchingBundle != null) {
                    List<File> locations;
                    if (matchingBundle.getMavenProject() != null) {
                        locations = getOtherProjectClasspath(matchingBundle, matchingBundle.getMavenProject(), path);
                    } else if (path != null) {
                        locations = getBundleEntry(matchingBundle, path);
                    } else {
                        locations = getBundleClasspath(matchingBundle);
                    }
                    classpath.add(new DefaultClasspathEntry(matchingBundle.getMavenProject(), matchingBundle.getKey(), locations, null));
                } else {
                    getLogger().warn("Missing extra classpath entry " + entry.trim());
                }
            } else {
                entry = entry.trim();
                File file = new File(project.getBasedir(), entry).getAbsoluteFile();
                if (file.exists()) {
                    List<File> locations = Collections.singletonList(file);
                    ArtifactKey projectKey = getArtifactKey(project);
                    classpath.add(new DefaultClasspathEntry(project, projectKey, locations, null));
                } else {
                    getLogger().warn("Missing extra classpath entry " + entry);
                }
            }
        }
    }
}
Also used : EclipsePluginProject(org.eclipse.tycho.core.osgitools.project.EclipsePluginProject) Pattern(java.util.regex.Pattern) ArtifactKey(org.eclipse.tycho.ArtifactKey) BuildOutputJar(org.eclipse.tycho.core.osgitools.project.BuildOutputJar) Matcher(java.util.regex.Matcher) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) File(java.io.File)

Example 24 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class ArtifactCollection method toDebugString.

public void toDebugString(StringBuilder sb, String linePrefix) {
    for (ArtifactDescriptor artifact : artifacts.values()) {
        sb.append(linePrefix);
        sb.append(artifact.getKey().toString());
        sb.append(": ");
        ReactorProject project = artifact.getMavenProject();
        if (project != null) {
            sb.append(project.toString());
        } else {
            sb.append(artifact.getLocation());
        }
        sb.append("\n");
    }
}
Also used : DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ReactorProject(org.eclipse.tycho.ReactorProject)

Example 25 with ArtifactDescriptor

use of org.eclipse.tycho.ArtifactDescriptor in project tycho by eclipse.

the class MultiEnvironmentDependencyArtifacts method addPlatform.

public void addPlatform(TargetEnvironment environment, DefaultDependencyArtifacts platform) {
    platforms.put(environment, platform);
    for (ArtifactDescriptor artifact : platform.artifacts.values()) {
        addArtifact(artifact, true);
    }
    nonReactorUnits.addAll(platform.nonReactorUnits);
}
Also used : ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor)

Aggregations

ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)32 File (java.io.File)20 ArtifactKey (org.eclipse.tycho.ArtifactKey)13 ReactorProject (org.eclipse.tycho.ReactorProject)10 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 IOException (java.io.IOException)4 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)4 DefaultArtifactDescriptor (org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor)4 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 PluginDescription (org.eclipse.tycho.core.PluginDescription)3 Version (org.osgi.framework.Version)3 FileOutputStream (java.io.FileOutputStream)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ZipFile (java.util.zip.ZipFile)2