Search in sources :

Example 6 with IArtifactFacade

use of org.eclipse.tycho.p2.metadata.IArtifactFacade in project tycho by eclipse.

the class TargetPlatformBundlePublisherTest method testPomDependencyOnBundle.

@Test
public void testPomDependencyOnBundle() throws Exception {
    String bundleId = "org.eclipse.osgi";
    String bundleVersion = "3.5.2.R35x_v20100126";
    FileUtils.copyDirectory(resourceFile("platformbuilder/pom-dependencies/bundle-repo"), localRepositoryRoot);
    File bundleFile = new File(localRepositoryRoot, RepositoryLayoutHelper.getRelativePath(GROUP_ID, ARTIFACT_ID, VERSION, null, "jar"));
    IArtifactFacade bundleArtifact = new ArtifactMock(bundleFile, GROUP_ID, ARTIFACT_ID, VERSION, "jar");
    IInstallableUnit publishedUnit = subject.attemptToPublishBundle(bundleArtifact);
    assertThat(publishedUnit, is(unit(bundleId, bundleVersion)));
    assertThat(publishedUnit.getProperties(), containsGAV(GROUP_ID, ARTIFACT_ID, VERSION));
    assertThat(publishedUnit.getArtifacts().size(), is(1));
    IArtifactKey referencedArtifact = publishedUnit.getArtifacts().iterator().next();
    IRawArtifactProvider artifactRepo = subject.getArtifactRepoOfPublishedBundles();
    assertThat(artifactRepo, contains(referencedArtifact));
    IArtifactDescriptor[] artifactDescriptors = artifactRepo.getArtifactDescriptors(referencedArtifact);
    assertThat(artifactDescriptors.length, is(1));
    assertThat(artifactDescriptors[0].getProperties(), containsGAV(GROUP_ID, ARTIFACT_ID, VERSION));
    assertThat(artifactDescriptors[0].getProperties(), hasProperty("download.md5", "6303323acc98658c0fed307c84db4411"));
    // test that reading the artifact succeeds (because the way it is added to the repository is a bit special)
    assertThat(artifactMD5Of(referencedArtifact, artifactRepo), is("6303323acc98658c0fed307c84db4411"));
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) ArtifactMock(org.eclipse.tycho.p2.impl.test.ArtifactMock) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IRawArtifactProvider(org.eclipse.tycho.repository.p2base.artifact.provider.IRawArtifactProvider) ResourceUtil.resourceFile(org.eclipse.tycho.p2.impl.test.ResourceUtil.resourceFile) File(java.io.File) Test(org.junit.Test)

Example 7 with IArtifactFacade

use of org.eclipse.tycho.p2.metadata.IArtifactFacade in project tycho by eclipse.

the class P2GeneratorImpl method getPublisherActions.

@Override
protected List<IPublisherAction> getPublisherActions(IArtifactFacade artifact, List<TargetEnvironment> environments, OptionalResolutionAction optionalAction) {
    if (!dependenciesOnly && optionalAction != null) {
        throw new IllegalArgumentException();
    }
    List<IPublisherAction> actions = new ArrayList<>();
    String packaging = artifact.getPackagingType();
    File location = artifact.getLocation();
    if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging)) {
        if (dependenciesOnly && optionalAction != null) {
            actions.add(new BundleDependenciesAction(location, optionalAction));
        } else {
            actions.add(new BundlesAction(new File[] { location }));
        }
    } else if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(packaging)) {
        Feature feature = new FeatureParser().parse(location);
        feature.setLocation(location.getAbsolutePath());
        if (dependenciesOnly) {
            actions.add(new FeatureDependenciesAction(feature));
        } else {
            actions.add(new FeaturesAction(new Feature[] { feature }));
        }
    } else if (PackagingType.TYPE_ECLIPSE_APPLICATION.equals(packaging)) {
        String product = new File(location, artifact.getArtifactId() + ".product").getAbsolutePath();
        try {
            IProductDescriptor productDescriptor = new ProductFile2(product);
            if (dependenciesOnly) {
                actions.add(new ProductDependenciesAction(productDescriptor));
            } else {
                actions.add(new ProductAction(product, productDescriptor, null, null));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (PackagingType.TYPE_ECLIPSE_UPDATE_SITE.equals(packaging)) {
        if (dependenciesOnly) {
            actions.add(new SiteDependenciesAction(location, artifact.getArtifactId(), artifact.getVersion()));
        } else {
            actions.add(new SiteXMLAction(location.toURI(), null));
        }
    } else if (PackagingType.TYPE_ECLIPSE_REPOSITORY.equals(packaging)) {
        for (File productFile : getProductFiles(location)) {
            String product = productFile.getAbsolutePath();
            IProductDescriptor productDescriptor;
            try {
                productDescriptor = new ProductFile2(product);
            } catch (Exception e) {
                throw new RuntimeException("Unable to parse the product file " + product, e);
            }
            if (dependenciesOnly) {
                actions.add(new ProductDependenciesAction(productDescriptor));
            }
        }
        for (File categoryFile : getCategoryFiles(location)) {
            CategoryParser cp = new CategoryParser(null);
            FileInputStream ins = null;
            try {
                try {
                    ins = new FileInputStream(categoryFile);
                    SiteModel siteModel = cp.parse(ins);
                    actions.add(new CategoryDependenciesAction(siteModel, artifact.getArtifactId(), artifact.getVersion()));
                } finally {
                    if (ins != null) {
                        ins.close();
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException("Unable to read category File", e);
            }
        }
    } else if (PackagingType.TYPE_P2_IU.equals(packaging)) {
        actions.add(new AuthoredIUAction(location));
    } else if (location.isFile() && location.getName().endsWith(".jar")) {
        actions.add(new BundlesAction(new File[] { location }));
    } else {
        throw new IllegalArgumentException("Unknown type of packaging " + packaging);
    }
    return actions;
}
Also used : BundlesAction(org.eclipse.equinox.p2.publisher.eclipse.BundlesAction) ArrayList(java.util.ArrayList) ProductAction(org.eclipse.equinox.p2.publisher.eclipse.ProductAction) Feature(org.eclipse.equinox.p2.publisher.eclipse.Feature) CategoryParser(org.eclipse.equinox.internal.p2.updatesite.CategoryParser) FeaturesAction(org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction) FeatureParser(org.eclipse.equinox.internal.p2.publisher.eclipse.FeatureParser) IPublisherAction(org.eclipse.equinox.p2.publisher.IPublisherAction) IProductDescriptor(org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor) SiteXMLAction(org.eclipse.equinox.internal.p2.updatesite.SiteXMLAction) SiteModel(org.eclipse.equinox.internal.p2.updatesite.SiteModel) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ProductFile2(org.eclipse.tycho.p2.impl.publisher.model.ProductFile2) File(java.io.File)

Example 8 with IArtifactFacade

use of org.eclipse.tycho.p2.metadata.IArtifactFacade in project tycho by eclipse.

the class P2ResolverImpl method addUnit.

private void addUnit(DefaultP2ResolutionResult result, IInstallableUnit iu, ReactorProject currentProject, Set<String> missingArtifacts) {
    if (currentProjectUnits.contains(iu)) {
        addReactorProject(result, currentProject.getIdentities(), iu);
        return;
    }
    ReactorProjectIdentities otherProject = context.getOriginalReactorProjectMap().get(iu);
    if (otherProject != null) {
        addReactorProject(result, otherProject, iu);
        return;
    }
    IArtifactFacade mavenArtifact = context.getOriginalMavenArtifactMap().get(iu);
    if (mavenArtifact != null) {
        addExternalMavenArtifact(result, mavenArtifact, iu);
        return;
    }
    for (IArtifactKey key : iu.getArtifacts()) {
        // this downloads artifacts if necessary; TODO parallelize download?
        File artifactLocation = context.getLocalArtifactFile(key);
        if (artifactLocation == null) {
            missingArtifacts.add(key.toString());
        } else {
            addArtifactFile(result, iu, key, artifactLocation);
        }
    }
}
Also used : IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) ReactorProjectIdentities(org.eclipse.tycho.ReactorProjectIdentities) File(java.io.File)

Aggregations

File (java.io.File)7 IArtifactFacade (org.eclipse.tycho.p2.metadata.IArtifactFacade)6 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)4 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)3 ResourceUtil.resourceFile (org.eclipse.tycho.p2.impl.test.ResourceUtil.resourceFile)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2 IPublisherInfo (org.eclipse.equinox.p2.publisher.IPublisherInfo)2 PublisherInfo (org.eclipse.equinox.p2.publisher.PublisherInfo)2 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)2 TransientArtifactRepository (org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository)2 IP2Artifact (org.eclipse.tycho.p2.metadata.IP2Artifact)2 FileInputStream (java.io.FileInputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Artifact (org.apache.maven.artifact.Artifact)1