use of org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor in project tycho by eclipse.
the class DefaultDependencyArtifactsTest method testDoNotCacheArtifactsThatRepresentReactorProjects.
@Test
public void testDoNotCacheArtifactsThatRepresentReactorProjects() {
// IInstallableUnit #hashCode and #equals methods only use (version,id) tuple to determine IU equality
// Reactor projects are expected to produce different IUs potentially with the same (version,id) during the build
// This test verifies that different DefaultTargetPlatform can have the same reactor project with different IUs
// even when IUs (version,id) are the same
ReactorProject project = new DefaultReactorProject(new MavenProject());
ArtifactKey key = new DefaultArtifactKey("type", "id", "version");
File location = new File("location");
DefaultDependencyArtifacts tp1 = new DefaultDependencyArtifacts();
tp1.addArtifact(new DefaultArtifactDescriptor(key, location, project, null, asSet(new FunnyEquals("id", "a"))));
DefaultDependencyArtifacts tp2 = new DefaultDependencyArtifacts();
tp2.addArtifact(new DefaultArtifactDescriptor(key, location, project, null, asSet(new FunnyEquals("id", "b"))));
//
Assert.assertEquals(//
"a", ((FunnyEquals) tp1.getArtifact(location).get(null).getInstallableUnits().iterator().next()).getData());
//
Assert.assertEquals(//
"b", ((FunnyEquals) tp2.getArtifact(location).get(null).getInstallableUnits().iterator().next()).getData());
}
use of org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor 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.core.osgitools.DefaultArtifactDescriptor in project tycho by eclipse.
the class ArtifactCollection method addReactorArtifact.
public void addReactorArtifact(ArtifactKey key, ReactorProject project, String classifier, Set<Object> installableUnits) {
DefaultArtifactDescriptor artifact = new DefaultArtifactDescriptor(key, project.getBasedir(), project, classifier, installableUnits);
addArtifact(artifact);
}
use of org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor in project tycho by eclipse.
the class ProvisionedInstallationDescription method getSystemBundle.
@Override
public ArtifactDescriptor getSystemBundle() {
if (systemBundleDescriptor != null) {
return systemBundleDescriptor;
}
File pluginsDir = new File(location, "plugins");
File[] systemBundles = pluginsDir.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isFile() && file.getName().startsWith(EquinoxContainer.NAME + "_");
}
});
File systemBundle;
if (systemBundles.length == 0) {
throw new IllegalArgumentException("No framework bundle " + EquinoxContainer.NAME + " found in " + pluginsDir);
} else if (systemBundles.length > 1) {
throw new IllegalArgumentException("Multiple versions of the framework bundle " + EquinoxContainer.NAME + " found in " + pluginsDir);
} else {
systemBundle = systemBundles[0];
}
String version = bundleReader.loadManifest(systemBundle).getBundleVersion();
ArtifactKey systemBundleKey = new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, EquinoxContainer.NAME, version);
systemBundleDescriptor = new DefaultArtifactDescriptor(systemBundleKey, systemBundle, null, null, null);
return systemBundleDescriptor;
}
Aggregations