Search in sources :

Example 6 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class LocalDependencyResolver method addDependencies.

private void addDependencies(MavenSession session, MavenProject project, DefaultDependencyArtifacts platform) {
    TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project.getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION);
    if (configuration != null && TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER.equals(configuration.getPomDependencies())) {
        Map<String, MavenProject> projectIds = new HashMap<>(session.getProjects().size() * 2);
        // make a list of reactor projects
        for (MavenProject p : session.getProjects()) {
            String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
            projectIds.put(key, p);
        }
        // handle dependencies that are in reactor
        for (Dependency dependency : project.getDependencies()) {
            if (Artifact.SCOPE_COMPILE.equals(dependency.getScope())) {
                String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
                if (projectIds.containsKey(key)) {
                    MavenProject dependent = projectIds.get(key);
                    ArtifactKey artifactKey = getArtifactKey(session, dependent);
                    if (artifactKey != null) {
                        platform.removeAll(artifactKey.getType(), artifactKey.getId());
                        ReactorProject projectProxy = DefaultReactorProject.adapt(dependent);
                        platform.addReactorArtifact(artifactKey, projectProxy, null, null);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("Add Maven project " + artifactKey);
                        }
                    }
                }
            }
        }
        // handle rest of dependencies
        ArrayList<String> scopes = new ArrayList<>();
        scopes.add(Artifact.SCOPE_COMPILE);
        Collection<Artifact> artifacts;
        try {
            artifacts = projectDependenciesResolver.resolve(project, scopes, session);
        } catch (MultipleArtifactsNotFoundException e) {
            Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
            for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
                Artifact a = it.next();
                String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
                if (projectIds.containsKey(key)) {
                    it.remove();
                }
            }
            if (!missing.isEmpty()) {
                throw new RuntimeException("Could not resolve project dependencies", e);
            }
            artifacts = e.getResolvedArtifacts();
            artifacts.removeAll(e.getMissingArtifacts());
        } catch (AbstractArtifactResolutionException e) {
            throw new RuntimeException("Could not resolve project dependencies", e);
        }
        for (Artifact artifact : artifacts) {
            String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
            if (!projectIds.containsKey(key)) {
                File plugin = artifact.getFile();
                ArtifactKey artifactKey = getArtifactKey(session, plugin);
                if (artifactKey != null) {
                    platform.addArtifactFile(artifactKey, plugin, null);
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Add Maven artifact " + artifactKey);
                    }
                }
            }
        }
    }
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) HashMap(java.util.HashMap) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Artifact(org.apache.maven.artifact.Artifact) MavenProject(org.apache.maven.project.MavenProject) Iterator(java.util.Iterator) Collection(java.util.Collection) File(java.io.File)

Example 7 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class AbstractArtifactBasedProject method checkForMissingDependencies.

@Override
public void checkForMissingDependencies(MavenProject project) {
    TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
    // this throws exceptions when dependencies are missing
    getDependencyWalker(project).walk(new ArtifactDependencyVisitor() {
    });
}
Also used : TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor)

Example 8 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class EquinoxResolver method getPlatformProperties.

protected Properties getPlatformProperties(MavenProject project, ExecutionEnvironment ee) {
    TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
    TargetEnvironment environment = configuration.getEnvironments().get(0);
    Properties properties = new Properties();
    properties.putAll((Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES));
    return getPlatformProperties(properties, environment, ee);
}
Also used : TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) Properties(java.util.Properties) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Example 9 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class OsgiBundleProject method readExecutionEnvironmentConfiguration.

@Override
public void readExecutionEnvironmentConfiguration(MavenProject project, ExecutionEnvironmentConfiguration sink) {
    // read packaging-type independent configuration
    super.readExecutionEnvironmentConfiguration(project, sink);
    // only in plugin projects, the profile may also be ...
    // ... specified in build.properties (for PDE compatibility)
    String pdeProfile = getEclipsePluginProject(DefaultReactorProject.adapt(project)).getBuildProperties().getJreCompilationProfile();
    if (pdeProfile != null) {
        sink.setProfileConfiguration(pdeProfile.trim(), "build.properties");
    } else {
        // ... derived from BREE in bundle manifest
        StandardExecutionEnvironment[] manifestBREEs = getManifest(project).getExecutionEnvironments();
        if (manifestBREEs.length > 0) {
            TargetPlatformConfiguration tpConfiguration = TychoProjectUtils.getTargetPlatformConfiguration(project);
            switch(tpConfiguration.getBREEHeaderSelectionPolicy()) {
                case first:
                    sink.setProfileConfiguration(manifestBREEs[0].getProfileName(), "Bundle-RequiredExecutionEnvironment (first entry)");
                    break;
                case minimal:
                    ExecutionEnvironment manifestMinimalEE = Collections.min(Arrays.asList(manifestBREEs));
                    sink.setProfileConfiguration(manifestMinimalEE.getProfileName(), "Bundle-RequiredExecutionEnvironment (minimal entry)");
            }
        }
    }
}
Also used : StandardExecutionEnvironment(org.eclipse.tycho.core.ee.StandardExecutionEnvironment) StandardExecutionEnvironment(org.eclipse.tycho.core.ee.StandardExecutionEnvironment) ExecutionEnvironment(org.eclipse.tycho.core.ee.shared.ExecutionEnvironment) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Example 10 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class P2DependencyResolver method setupProjects.

@Override
public void setupProjects(final MavenSession session, final MavenProject project, final ReactorProject reactorProject) {
    TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project.getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION);
    List<TargetEnvironment> environments = configuration.getEnvironments();
    Map<String, IDependencyMetadata> metadata = getDependencyMetadata(session, project, environments, OptionalResolutionAction.OPTIONAL);
    Set<Object> primaryMetadata = new LinkedHashSet<>();
    Set<Object> secondaryMetadata = new LinkedHashSet<>();
    for (Map.Entry<String, IDependencyMetadata> entry : metadata.entrySet()) {
        primaryMetadata.addAll(entry.getValue().getMetadata(true));
        secondaryMetadata.addAll(entry.getValue().getMetadata(false));
    }
    reactorProject.setDependencyMetadata(true, primaryMetadata);
    reactorProject.setDependencyMetadata(false, secondaryMetadata);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IDependencyMetadata(org.eclipse.tycho.p2.metadata.IDependencyMetadata) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)25 File (java.io.File)8 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)8 Test (org.junit.Test)7 MavenSession (org.apache.maven.execution.MavenSession)6 BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)6 TargetEnvironment (org.eclipse.tycho.core.shared.TargetEnvironment)6 Properties (java.util.Properties)4 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)4 Dependency (org.apache.maven.model.Dependency)3 MavenProject (org.apache.maven.project.MavenProject)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)2 TargetPlatform (org.eclipse.tycho.artifacts.TargetPlatform)2 DependencyResolverConfiguration (org.eclipse.tycho.core.DependencyResolverConfiguration)2 ExecutionEnvironmentConfiguration (org.eclipse.tycho.core.ee.shared.ExecutionEnvironmentConfiguration)2