Search in sources :

Example 16 with ArtifactKey

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

the class TargetPlatformTest method testResolveProduct.

@Test
public void testResolveProduct() throws Exception {
    candidateIUs = createSet(createBundleIU("unit", "2.0.0"), createProductIU("unit", "1.99.0"));
    subject = createTP();
    ArtifactKey key = subject.resolveArtifact("eclipse-product", "unit", ANY_VERSION);
    assertThat(key.getType(), is(ArtifactType.TYPE_ECLIPSE_PRODUCT));
    assertThat(key.getId(), is("unit"));
    assertThat(key.getVersion(), is("1.99.0"));
}
Also used : ArtifactKey(org.eclipse.tycho.ArtifactKey) Test(org.junit.Test)

Example 17 with ArtifactKey

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

the class ArtifactCollection method getArtifact.

public ArtifactDescriptor getArtifact(String type, String id, String version) {
    if (type == null || id == null) {
        // TODO should we throw something instead?
        return null;
    }
    // features with matching id, sorted by version, highest version first
    SortedMap<Version, ArtifactDescriptor> relevantArtifacts = new TreeMap<>(new Comparator<Version>() {

        @Override
        public int compare(Version o1, Version o2) {
            return -o1.compareTo(o2);
        }
    });
    for (Map.Entry<ArtifactKey, ArtifactDescriptor> entry : this.artifacts.entrySet()) {
        ArtifactKey key = entry.getKey();
        if (type.equals(key.getType()) && id.equals(key.getId())) {
            relevantArtifacts.put(Version.parseVersion(key.getVersion()), entry.getValue());
        }
    }
    if (relevantArtifacts.isEmpty()) {
        return null;
    }
    if (version == null) {
        // latest version
        return relevantArtifacts.get(relevantArtifacts.firstKey());
    }
    Version parsedVersion = new Version(version);
    if (VERSION_0_0_0.equals(parsedVersion)) {
        // latest version
        return relevantArtifacts.get(relevantArtifacts.firstKey());
    }
    String qualifier = parsedVersion.getQualifier();
    if (qualifier == null || "".equals(qualifier) || DependencyArtifacts.ANY_QUALIFIER.equals(qualifier)) {
        // latest qualifier
        for (Map.Entry<Version, ArtifactDescriptor> entry : relevantArtifacts.entrySet()) {
            if (baseVersionEquals(parsedVersion, entry.getKey())) {
                return entry.getValue();
            }
        }
    }
    // perfect match or nothing
    return relevantArtifacts.get(parsedVersion);
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) Version(org.osgi.framework.Version) DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 18 with ArtifactKey

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

the class ArtifactCollection method addArtifact.

protected void addArtifact(ArtifactDescriptor artifact, boolean merge) {
    if (artifact.getClass() != DefaultArtifactDescriptor.class) {
        throw new IllegalAccessError();
    }
    ArtifactKey key = normalizePluginType(artifact.getKey());
    File location = normalizeLocation(artifact.getLocation());
    ArtifactDescriptor original = artifacts.get(key);
    Set<Object> units = null;
    if (original != null) {
        // can't use DefaultArtifactDescriptor.equals because artifact.location is not normalized
        if (!eq(original.getLocation(), location) || !eq(original.getClassifier(), artifact.getClassifier()) || !eq(original.getMavenProject(), artifact.getMavenProject())) {
            // TODO better error message
            throw new IllegalStateException("Inconsistent artifact with key " + artifact.getKey());
        }
        // artifact equals to original
        if (eq(original.getInstallableUnits(), artifact.getInstallableUnits())) {
            return;
        }
        if (!merge) {
            // TODO better error message
            throw new IllegalStateException("Inconsistent artifact with key " + artifact.getKey());
        }
        units = new LinkedHashSet<>(original.getInstallableUnits());
        units.addAll(artifact.getInstallableUnits());
    } else {
        units = artifact.getInstallableUnits();
    }
    // reuse artifact keys to reduce memory usage
    key = normalize(key);
    if (units != null) {
        units = Collections.unmodifiableSet(units);
    }
    // recreate artifact descriptor to use normalized location, key and units
    artifact = new DefaultArtifactDescriptor(key, location, artifact.getMavenProject(), artifact.getClassifier(), units);
    // do not cache reactor project artifact descriptors because their IUs can change without changing (id,version)
    if (artifact.getMavenProject() == null) {
        artifact = normalize(artifact);
    }
    artifacts.put(artifact.getKey(), artifact);
    Map<String, ArtifactDescriptor> classified = locations.get(location);
    if (classified == null) {
        classified = new LinkedHashMap<>();
        locations.put(location, classified);
    }
    // sanity check, all artifacts at the same location have the same reactor project
    for (ArtifactDescriptor other : classified.values()) {
        if (!eq(artifact.getMavenProject(), other.getMavenProject())) {
            throw new IllegalStateException("Inconsistent reactor project at location " + location + ". " + artifact.getMavenProject() + " is not the same as " + other.getMavenProject());
        }
    }
    classified.put(artifact.getClassifier(), artifact);
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) File(java.io.File)

Example 19 with ArtifactKey

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

the class ArtifactCollection method removeAll.

public void removeAll(String type, String id) {
    Iterator<Entry<ArtifactKey, ArtifactDescriptor>> iter = artifacts.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<ArtifactKey, ArtifactDescriptor> entry = iter.next();
        ArtifactKey key = entry.getKey();
        if (key.getType().equals(type) && key.getId().equals(id)) {
            locations.remove(entry.getValue().getLocation());
            iter.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor)

Example 20 with ArtifactKey

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

Aggregations

ArtifactKey (org.eclipse.tycho.ArtifactKey)41 File (java.io.File)19 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)15 Test (org.junit.Test)14 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)13 ReactorProject (org.eclipse.tycho.ReactorProject)8 DefaultArtifactDescriptor (org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor)6 DefaultDependencyArtifacts (org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts)6 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)5 LinkedHashMap (java.util.LinkedHashMap)3 MavenProject (org.apache.maven.project.MavenProject)3 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)3 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)3 FeatureRef (org.eclipse.tycho.model.FeatureRef)3 PluginRef (org.eclipse.tycho.model.PluginRef)3 Version (org.osgi.framework.Version)3 Element (de.pdark.decentxml.Element)2 Map (java.util.Map)2 Artifact (org.apache.maven.artifact.Artifact)2 Dependency (org.apache.maven.model.Dependency)2