Search in sources :

Example 6 with ReactorProject

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

the class TargetPlatformFactoryImpl method getPreliminaryReactorProjectUIs.

private Map<IInstallableUnit, ReactorProjectIdentities> getPreliminaryReactorProjectUIs(List<ReactorProject> reactorProjects) throws DuplicateReactorIUsException {
    if (reactorProjects == null) {
        return Collections.emptyMap();
    }
    Map<IInstallableUnit, ReactorProjectIdentities> reactorUIs = new HashMap<>();
    Map<IInstallableUnit, Set<File>> duplicateReactorUIs = new HashMap<>();
    for (ReactorProject project : reactorProjects) {
        @SuppressWarnings("unchecked") Set<IInstallableUnit> projectIUs = (Set<IInstallableUnit>) project.getDependencyMetadata();
        if (projectIUs == null)
            continue;
        for (IInstallableUnit iu : projectIUs) {
            ReactorProjectIdentities otherOrigin = reactorUIs.put(iu, project.getIdentities());
            if (otherOrigin != null && !otherOrigin.equals(project.getIdentities())) {
                Set<File> duplicateLocations = duplicateReactorUIs.get(iu);
                if (duplicateLocations == null) {
                    duplicateLocations = new LinkedHashSet<>();
                    duplicateReactorUIs.put(iu, duplicateLocations);
                }
                duplicateLocations.add(otherOrigin.getBasedir());
                duplicateLocations.add(project.getBasedir());
            }
        }
    }
    if (!duplicateReactorUIs.isEmpty()) {
        // TODO 392320 we should only fail if IUs with same id and version but different content are found
        throw new DuplicateReactorIUsException(duplicateReactorUIs);
    }
    return reactorUIs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ReactorProject(org.eclipse.tycho.ReactorProject) ReactorProjectIdentities(org.eclipse.tycho.ReactorProjectIdentities) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File)

Example 7 with ReactorProject

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

the class TargetPlatformFactoryTest method testConfiguredFiltersOnReactorIUsInPreliminaryTP.

// TODO 372035 test logging for potential bugs in the explicit filters configuration
@Test
public void testConfiguredFiltersOnReactorIUsInPreliminaryTP() throws Exception {
    TargetPlatformFilter filter = TargetPlatformFilter.removeAllFilter(CapabilityPattern.patternWithoutVersion(CapabilityType.P2_INSTALLABLE_UNIT, "iu.p2.inf"));
    tpConfig.addFilters(Arrays.asList(filter));
    ReactorProject reactorProject = createReactorProject("artifactId", "test.feature.feature.group", "iu.p2.inf");
    P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, Collections.singletonList(reactorProject), null);
    assertThat(preliminaryTP.getInstallableUnits(), hasItem(unitWithId("test.feature.feature.group")));
    assertThat(preliminaryTP.getInstallableUnits(), not(hasItem(unitWithId("iu.p2.inf"))));
}
Also used : ReactorProject(org.eclipse.tycho.ReactorProject) TargetPlatformFilter(org.eclipse.tycho.artifacts.TargetPlatformFilter) Test(org.junit.Test)

Example 8 with ReactorProject

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

the class TargetPlatformFactoryTest method testOtherVersionsOfReactorIUsAreFilteredFromExternalContent.

@Test
public void testOtherVersionsOfReactorIUsAreFilteredFromExternalContent() throws Exception {
    // contains trt.bundle/1.0.0.201108051343
    tpConfig.addP2Repository(ResourceUtil.resourceFile("targetresolver/v1_content").toURI());
    // reactor artifact produces a unit with same ID
    ReactorProject reactorProject = createReactorProject("artifactId", "trt.bundle/1.5.5.qualifier", null);
    P2TargetPlatform preliminaryTP = subject.createTargetPlatform(tpConfig, NOOP_EE_RESOLUTION_HANDLER, Collections.singletonList(reactorProject), null);
    assertThat(preliminaryTP.getInstallableUnits(), hasItem(unit("trt.bundle", "1.5.5.qualifier")));
    assertThat(preliminaryTP.getInstallableUnits(), not(hasItem(unit("trt.bundle", "1.0.0.201108051343"))));
    Map<IInstallableUnit, ReactorProjectIdentities> finalUnits = Collections.singletonMap(InstallableUnitUtil.createIU("trt.bundle", "1.5.5.20140216"), reactorProject.getIdentities());
    P2TargetPlatform finalTP = subject.createTargetPlatformWithUpdatedReactorUnits(preliminaryTP, finalUnits, REACTOR_ARTIFACTS);
    assertThat(finalTP.getInstallableUnits(), hasItem(unit("trt.bundle", "1.5.5.20140216")));
    assertThat(finalTP.getInstallableUnits(), not(hasItem(unit("trt.bundle", "1.0.0.201108051343"))));
}
Also used : ReactorProject(org.eclipse.tycho.ReactorProject) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ReactorProjectIdentities(org.eclipse.tycho.ReactorProjectIdentities) Test(org.junit.Test)

Example 9 with ReactorProject

use of org.eclipse.tycho.ReactorProject 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 10 with ReactorProject

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

the class AbstractArtifactDependencyWalker method traverseFeature.

protected void traverseFeature(File location, Feature feature, FeatureRef featureRef, ArtifactDependencyVisitor visitor, WalkbackPath visited) {
    ArtifactDescriptor artifact = getArtifact(location, feature.getId());
    if (artifact == null) {
        // ah?
        throw new IllegalStateException("Feature " + location + " with id " + feature.getId() + " is not part of the project build target platform");
    }
    ArtifactKey key = artifact.getKey();
    ReactorProject project = artifact.getMavenProject();
    String classifier = artifact.getClassifier();
    Set<Object> installableUnits = artifact.getInstallableUnits();
    DefaultFeatureDescription description = new DefaultFeatureDescription(key, location, project, classifier, feature, featureRef, installableUnits);
    if (visitor.visitFeature(description)) {
        for (PluginRef ref : feature.getPlugins()) {
            traversePlugin(ref, visitor, visited);
        }
        for (FeatureRef ref : feature.getIncludedFeatures()) {
            traverseFeature(ref, visitor, visited);
        }
    }
}
Also used : ArtifactKey(org.eclipse.tycho.ArtifactKey) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ReactorProject(org.eclipse.tycho.ReactorProject) PluginRef(org.eclipse.tycho.model.PluginRef) FeatureRef(org.eclipse.tycho.model.FeatureRef)

Aggregations

ReactorProject (org.eclipse.tycho.ReactorProject)32 File (java.io.File)20 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)16 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)10 ArtifactKey (org.eclipse.tycho.ArtifactKey)8 MavenProject (org.apache.maven.project.MavenProject)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)4 Artifact (org.apache.maven.artifact.Artifact)4 Dependency (org.apache.maven.model.Dependency)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)4 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)4 DefaultDependencyArtifacts (org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)3