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"));
}
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);
}
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);
}
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();
}
}
}
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);
}
}
}
}
}
}
Aggregations