Search in sources :

Example 1 with DependencyMetadata

use of org.eclipse.tycho.p2.impl.publisher.DependencyMetadata in project tycho by eclipse.

the class P2ResolverTest method testSourceBundle.

@Test
public void testSourceBundle() throws Exception {
    String featureId = "org.eclipse.tycho.p2.impl.resolver.test.feature01";
    projectToResolve = createReactorProject(resourceFile("sourcebundles/feature01"), TYPE_ECLIPSE_FEATURE, featureId);
    File bundle = resourceFile("sourcebundles/bundle01");
    String bundleId = "org.eclipse.tycho.p2.impl.resolver.test.bundle01";
    String bundleVersion = "1.0.0-SNAPSHOT";
    reactorProjects.add(createReactorProject(bundle, TYPE_ECLIPSE_PLUGIN, bundleId));
    ReactorProjectStub sb = new ReactorProjectStub(bundle, bundleId, bundleId, bundleVersion, TYPE_ECLIPSE_PLUGIN);
    DependencyMetadata metadata = new SourcesBundleDependencyMetadataGenerator().generateMetadata(new ArtifactMock(sb, "source"), getEnvironments(), null);
    sb.setDependencyMetadata(metadata);
    reactorProjects.add(sb);
    result = singleEnv(impl.resolveDependencies(getTargetPlatform(), projectToResolve));
    assertEquals(3, result.getArtifacts().size());
    List<P2ResolutionResult.Entry> entries = new ArrayList<>(result.getArtifacts());
    Collections.sort(entries, new Comparator<Entry>() {

        @Override
        public int compare(Entry entry1, Entry entry2) {
            return entry1.getId().compareTo(entry2.getId());
        }
    });
    assertEquals("org.eclipse.tycho.p2.impl.resolver.test.bundle01", entries.get(0).getId());
    assertEquals("org.eclipse.tycho.p2.impl.resolver.test.bundle01.source", entries.get(1).getId());
    assertEquals("org.eclipse.tycho.p2.impl.resolver.test.feature01", entries.get(2).getId());
    assertEquals(bundle, entries.get(0).getLocation());
    assertEquals(bundle, entries.get(1).getLocation());
    assertEquals("sources", entries.get(1).getClassifier());
}
Also used : Entry(org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult.Entry) ReactorProjectStub(org.eclipse.tycho.p2.impl.test.ReactorProjectStub) ArrayList(java.util.ArrayList) DependencyMetadata(org.eclipse.tycho.p2.impl.publisher.DependencyMetadata) ArtifactMock(org.eclipse.tycho.p2.impl.test.ArtifactMock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ResourceUtil.resourceFile(org.eclipse.tycho.p2.impl.test.ResourceUtil.resourceFile) File(java.io.File) SourcesBundleDependencyMetadataGenerator(org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator) Test(org.junit.Test)

Example 2 with DependencyMetadata

use of org.eclipse.tycho.p2.impl.publisher.DependencyMetadata in project tycho by eclipse.

the class P2ResolverTestBase method addContextProject.

protected final void addContextProject(File projectRoot, String packaging) throws IOException {
    ArtifactMock artifact = new ArtifactMock(projectRoot.getAbsoluteFile(), DEFAULT_GROUP_ID, projectRoot.getName(), DEFAULT_VERSION, packaging);
    DependencyMetadata metadata = fullGenerator.generateMetadata(artifact, getEnvironments());
    pomDependencies.addMavenArtifact(artifact, metadata.getInstallableUnits());
}
Also used : DependencyMetadata(org.eclipse.tycho.p2.impl.publisher.DependencyMetadata) IDependencyMetadata(org.eclipse.tycho.p2.metadata.IDependencyMetadata) ArtifactMock(org.eclipse.tycho.p2.impl.test.ArtifactMock)

Example 3 with DependencyMetadata

use of org.eclipse.tycho.p2.impl.publisher.DependencyMetadata in project tycho by eclipse.

the class P2GeneratorImpl method generateMetadata.

public DependencyMetadata generateMetadata(IArtifactFacade artifact, List<TargetEnvironment> environments) {
    PublisherInfo publisherInfo = new PublisherInfo();
    publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH);
    publisherInfo.setArtifactRepository(new TransientArtifactRepository());
    return super.generateMetadata(artifact, environments, publisherInfo, null);
}
Also used : IPublisherInfo(org.eclipse.equinox.p2.publisher.IPublisherInfo) PublisherInfo(org.eclipse.equinox.p2.publisher.PublisherInfo) TransientArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository)

Example 4 with DependencyMetadata

use of org.eclipse.tycho.p2.impl.publisher.DependencyMetadata in project tycho by eclipse.

the class P2GeneratorImpl method generateMetadata.

@Override
public Map<String, IP2Artifact> generateMetadata(List<IArtifactFacade> artifacts, final File targetDir) throws IOException {
    Map<String, IP2Artifact> result = new LinkedHashMap<>();
    for (IArtifactFacade artifact : artifacts) {
        PublisherInfo publisherInfo = new PublisherInfo();
        DependencyMetadata metadata;
        // meta data handling for root files
        if (PackagingType.TYPE_ECLIPSE_FEATURE.equals(artifact.getPackagingType())) {
            publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH | IPublisherInfo.A_NO_MD5);
            FeatureRootfileArtifactRepository artifactsRepository = new FeatureRootfileArtifactRepository(publisherInfo, targetDir);
            publisherInfo.setArtifactRepository(artifactsRepository);
            metadata = super.generateMetadata(artifact, null, publisherInfo, null);
            result.putAll(artifactsRepository.getPublishedArtifacts());
        } else if (PackagingType.TYPE_P2_IU.equals(artifact.getPackagingType())) {
            TransientArtifactRepository artifactsRepository = new TransientArtifactRepository();
            publisherInfo.setArtifactRepository(artifactsRepository);
            final IArtifactFacade currentArtifact = artifact;
            IArtifactFacade targetDirAsArtifact = new IArtifactFacade() {

                @Override
                public String getVersion() {
                    return currentArtifact.getVersion();
                }

                @Override
                public String getPackagingType() {
                    return currentArtifact.getPackagingType();
                }

                @Override
                public File getLocation() {
                    return targetDir;
                }

                @Override
                public String getGroupId() {
                    return currentArtifact.getGroupId();
                }

                @Override
                public String getClassifier() {
                    return currentArtifact.getClassifier();
                }

                @Override
                public String getArtifactId() {
                    return currentArtifact.getArtifactId();
                }
            };
            metadata = super.generateMetadata(targetDirAsArtifact, null, publisherInfo, null);
        } else {
            publisherInfo.setArtifactOptions(IPublisherInfo.A_PUBLISH | IPublisherInfo.A_NO_MD5);
            TransientArtifactRepository artifactsRepository = new TransientArtifactRepository();
            publisherInfo.setArtifactRepository(artifactsRepository);
            metadata = super.generateMetadata(artifact, null, publisherInfo, null);
        }
        // secondary metadata is meant to represent installable units that are provided by this project
        // but do not affect dependencies of the project itself. generateMetadata is called at the end
        // of project build lifecycle, and primary/secondary metadata separation is irrelevant at this point
        P2Artifact p2artifact = new P2Artifact(artifact.getLocation(), metadata.getInstallableUnits(), getCanonicalArtifact(artifact.getClassifier(), metadata.getArtifactDescriptors()));
        result.put(artifact.getClassifier(), p2artifact);
        IArtifactDescriptor packed = getPackedArtifactDescriptor(metadata.getArtifactDescriptors());
        if (packed != null) {
            File packedLocation = new File(artifact.getLocation().getAbsolutePath() + ".pack.gz");
            if (!packedLocation.canRead()) {
                throw new IllegalArgumentException("Could not find packed artifact " + packed + " at " + packedLocation);
            }
            if (result.containsKey(RepositoryLayoutHelper.PACK200_CLASSIFIER)) {
                throw new IllegalArgumentException();
            }
            // workaround for bug 412497
            Map<String, String> additionalProperties = new HashMap<>(5);
            additionalProperties.put(RepositoryLayoutHelper.PROP_GROUP_ID, artifact.getGroupId());
            additionalProperties.put(RepositoryLayoutHelper.PROP_ARTIFACT_ID, artifact.getArtifactId());
            additionalProperties.put(RepositoryLayoutHelper.PROP_VERSION, artifact.getVersion());
            additionalProperties.put(RepositoryLayoutHelper.PROP_CLASSIFIER, RepositoryLayoutHelper.PACK200_CLASSIFIER);
            additionalProperties.put(RepositoryLayoutHelper.PROP_EXTENSION, RepositoryLayoutHelper.PACK200_EXTENSION);
            ((ArtifactDescriptor) packed).addProperties(additionalProperties);
            result.put(RepositoryLayoutHelper.PACK200_CLASSIFIER, new P2Artifact(packedLocation, Collections.<IInstallableUnit>emptySet(), packed));
        }
    }
    return result;
}
Also used : IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) IPublisherInfo(org.eclipse.equinox.p2.publisher.IPublisherInfo) PublisherInfo(org.eclipse.equinox.p2.publisher.PublisherInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FeatureRootfileArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.FeatureRootfileArtifactRepository) TransientArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository) LinkedHashMap(java.util.LinkedHashMap) ArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) File(java.io.File)

Example 5 with DependencyMetadata

use of org.eclipse.tycho.p2.impl.publisher.DependencyMetadata in project tycho by eclipse.

the class AbstractMetadataGenerator method publish.

private DependencyMetadata publish(PublisherInfo publisherInfo, List<IPublisherAction> actions) {
    PublisherResult result = new PublisherResult();
    Publisher publisher = new Publisher(publisherInfo, result);
    IStatus status = publisher.publish(actions.toArray(new IPublisherAction[actions.size()]), monitor);
    if (!status.isOK()) {
        throw new RuntimeException(StatusTool.collectProblems(status), status.getException());
    }
    DependencyMetadata metadata = new DependencyMetadata();
    metadata.setMetadata(true, result.getIUs(null, PublisherResult.ROOT));
    metadata.setMetadata(false, result.getIUs(null, PublisherResult.NON_ROOT));
    IArtifactRepository artifactRepository = publisherInfo.getArtifactRepository();
    if (artifactRepository instanceof TransientArtifactRepository) {
        metadata.setArtifacts(((TransientArtifactRepository) artifactRepository).getArtifactDescriptors());
    }
    return metadata;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPublisherAction(org.eclipse.equinox.p2.publisher.IPublisherAction) PublisherResult(org.eclipse.equinox.p2.publisher.PublisherResult) IArtifactRepository(org.eclipse.equinox.p2.repository.artifact.IArtifactRepository) Publisher(org.eclipse.equinox.p2.publisher.Publisher) TransientArtifactRepository(org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository)

Aggregations

File (java.io.File)5 DependencyMetadata (org.eclipse.tycho.p2.impl.publisher.DependencyMetadata)4 ArrayList (java.util.ArrayList)3 TargetEnvironment (org.eclipse.tycho.core.shared.TargetEnvironment)3 TransientArtifactRepository (org.eclipse.tycho.p2.impl.publisher.repo.TransientArtifactRepository)3 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)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 ReactorProjectStub (org.eclipse.tycho.p2.impl.test.ReactorProjectStub)2 IDependencyMetadata (org.eclipse.tycho.p2.metadata.IDependencyMetadata)2 Test (org.junit.Test)2 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 IPublisherAction (org.eclipse.equinox.p2.publisher.IPublisherAction)1 Publisher (org.eclipse.equinox.p2.publisher.Publisher)1