Search in sources :

Example 1 with DefaultArtifactDescriptor

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());
}
Also used : DefaultDependencyArtifacts(org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) MavenProject(org.apache.maven.project.MavenProject) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) File(java.io.File) Test(org.junit.Test)

Example 2 with DefaultArtifactDescriptor

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);
}
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 3 with DefaultArtifactDescriptor

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);
}
Also used : DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor)

Example 4 with DefaultArtifactDescriptor

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;
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) DefaultArtifactDescriptor(org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

DefaultArtifactDescriptor (org.eclipse.tycho.core.osgitools.DefaultArtifactDescriptor)4 File (java.io.File)3 ArtifactKey (org.eclipse.tycho.ArtifactKey)3 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)3 FileFilter (java.io.FileFilter)1 MavenProject (org.apache.maven.project.MavenProject)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1 DefaultDependencyArtifacts (org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts)1 Test (org.junit.Test)1