Search in sources :

Example 11 with Repository

use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository in project tycho by eclipse.

the class BaselineValidator method validateAndReplace.

public Map<String, IP2Artifact> validateAndReplace(MavenProject project, MojoExecution execution, Map<String, IP2Artifact> reactorMetadata, List<Repository> baselineRepositories, BaselineMode baselineMode, BaselineReplace baselineReplace) throws IOException, MojoExecutionException {
    Map<String, IP2Artifact> result = reactorMetadata;
    if (baselineMode != disable && baselineRepositories != null && !baselineRepositories.isEmpty()) {
        List<MavenRepositoryLocation> _repositories = new ArrayList<>();
        for (Repository repository : baselineRepositories) {
            if (repository.getUrl() != null) {
                _repositories.add(new MavenRepositoryLocation(repository.getId(), repository.getUrl()));
            }
        }
        File baselineBasedir = new File(project.getBuild().getDirectory(), "baseline");
        BaselineService baselineService = getService(BaselineService.class);
        Map<String, IP2Artifact> baselineMetadata = baselineService.getProjectBaseline(_repositories, reactorMetadata, baselineBasedir);
        if (baselineMetadata != null) {
            CompoundArtifactDelta delta = getDelta(baselineService, baselineMetadata, reactorMetadata, execution);
            if (delta != null) {
                if (System.getProperties().containsKey("tycho.debug.artifactcomparator")) {
                    File logdir = new File(project.getBuild().getDirectory(), "artifactcomparison");
                    log.info("Artifact comparison detailed log directory " + logdir.getAbsolutePath());
                    for (Map.Entry<String, ArtifactDelta> classifier : delta.getMembers().entrySet()) {
                        if (classifier.getValue() instanceof CompoundArtifactDelta) {
                            ((CompoundArtifactDelta) classifier.getValue()).writeDetails(new File(logdir, classifier.getKey()));
                        }
                    }
                }
                if (baselineMode == fail || (baselineMode == failCommon && !isMissingOnlyDelta(delta))) {
                    throw new MojoExecutionException(delta.getDetailedMessage());
                } else {
                    log.warn(project.toString() + ": " + delta.getDetailedMessage());
                }
            }
            if (baselineReplace != none) {
                result = new LinkedHashMap<>();
                // replace reactor artifacts with baseline
                ArrayList<String> replaced = new ArrayList<>();
                for (Map.Entry<String, IP2Artifact> artifact : baselineMetadata.entrySet()) {
                    File baseLineFile = artifact.getValue().getLocation();
                    String classifier = artifact.getKey();
                    File reactorFile = reactorMetadata.get(classifier).getLocation();
                    if (baseLineFile.isFile() && baseLineFile.length() == 0L) {
                        // workaround for possibly corrupted download - bug 484003
                        log.error("baseline file " + baseLineFile.getAbsolutePath() + " is empty. Will not replace " + reactorFile);
                    } else {
                        FileUtils.copyFile(baseLineFile, reactorFile);
                        result.put(classifier, artifact.getValue());
                        if (classifier != null) {
                            replaced.add(classifier);
                        }
                    }
                }
                // un-attach and delete artifacts present in reactor but not in baseline
                ArrayList<String> removed = new ArrayList<>();
                ArrayList<String> inconsistent = new ArrayList<>();
                for (Map.Entry<String, IP2Artifact> entry : reactorMetadata.entrySet()) {
                    String classifier = entry.getKey();
                    IP2Artifact artifact = entry.getValue();
                    if (classifier == null || artifact == null) {
                        continue;
                    }
                    if (baselineReplace == all && !baselineMetadata.containsKey(classifier)) {
                        List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
                        ListIterator<Artifact> iterator = attachedArtifacts.listIterator();
                        while (iterator.hasNext()) {
                            if (classifier.equals(iterator.next().getClassifier())) {
                                iterator.remove();
                                break;
                            }
                        }
                        artifact.getLocation().delete();
                        removed.add(classifier);
                    } else {
                        inconsistent.add(classifier);
                        result.put(classifier, artifact);
                    }
                }
                if (log.isInfoEnabled()) {
                    StringBuilder msg = new StringBuilder();
                    msg.append(project.toString());
                    msg.append("\n    The main artifact has been replaced with the baseline version.\n");
                    if (!replaced.isEmpty()) {
                        msg.append("    The following attached artifacts have been replaced with the baseline version: ");
                        msg.append(replaced.toString());
                        msg.append("\n");
                    }
                    if (!removed.isEmpty()) {
                        msg.append("    The following attached artifacts are not present in the baseline and have been removed: ");
                        msg.append(removed.toString());
                        msg.append("\n");
                    }
                    log.info(msg.toString());
                }
            }
        } else {
            log.info("No baseline version " + project);
        }
    }
    return result;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) Artifact(org.apache.maven.artifact.Artifact) BaselineService(org.eclipse.tycho.p2.tools.baseline.facade.BaselineService) MavenRepositoryLocation(org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation) CompoundArtifactDelta(org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) ArtifactDelta(org.eclipse.tycho.artifactcomparator.ArtifactDelta) SimpleArtifactDelta(org.eclipse.tycho.zipcomparator.internal.SimpleArtifactDelta) CompoundArtifactDelta(org.eclipse.tycho.zipcomparator.internal.CompoundArtifactDelta) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 12 with Repository

use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository in project tycho by eclipse.

the class VerifyIntegrityRepositoryMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    File repositoryDir = getBuildDirectory().getChild("repository");
    logger.info("Verifying p2 repositories in " + repositoryDir);
    VerifierService verifier = p2.getService(VerifierService.class);
    URI repositoryUri = repositoryDir.toURI();
    try {
        if (!verifier.verify(repositoryUri, repositoryUri, getBuildDirectory())) {
            throw new MojoFailureException("The repository is invalid.");
        }
    } catch (FacadeException e) {
        throw new MojoExecutionException("Verification failed", e);
    }
}
Also used : FacadeException(org.eclipse.tycho.p2.tools.FacadeException) VerifierService(org.eclipse.tycho.p2.tools.verifier.facade.VerifierService) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) File(java.io.File) URI(java.net.URI)

Example 13 with Repository

use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository 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 14 with Repository

use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository in project tycho by eclipse.

the class TargetDefinitionResolverExecutionEnvironmentTest method testRestrictedExecutionEnvironment.

@Test
public void testRestrictedExecutionEnvironment() throws Exception {
    subject = targetResolverForEE("CDC-1.0/Foundation-1.0");
    TargetDefinition definition = definitionWith(new AlternatePackageProviderLocationStub());
    Collection<IInstallableUnit> units = subject.resolveContent(definition).getUnits();
    // expect that resolver included a bundle providing org.w3c.dom (here javax.xml)...
    assertThat(units, hasItem(unit("javax.xml", "0.0.1.SNAPSHOT")));
    // ... and did not match the import against the "a.jre" IU also in the repository
    assertThat(units, not(hasItem(unitWithId("a.jre"))));
}
Also used : TargetDefinition(org.eclipse.tycho.p2.target.facade.TargetDefinition) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 15 with Repository

use of org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository in project tycho by eclipse.

the class PomDependencyProcessor method collectPomDependencies.

PomDependencyCollector collectPomDependencies(MavenProject project, Collection<Artifact> transitivePomDependencies) {
    final TychoRepositoryIndex p2ArtifactsInLocalRepo = localRepoIndices.getArtifactsIndex();
    PomDependencyCollector result = resolverFactory.newPomDependencyCollector();
    result.setProjectLocation(project.getBasedir());
    for (Artifact artifact : transitivePomDependencies) {
        if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
            // ignore
            continue;
        }
        P2DataArtifacts p2Data = new P2DataArtifacts(artifact);
        p2Data.resolve(session, project.getRemoteArtifactRepositories());
        if (p2Data.p2MetadataXml.isAvailable() && p2Data.p2ArtifactsXml.isAvailable()) {
            /*
                 * The POM dependency has (probably) been built by Tycho, so we can re-use the
                 * existing p2 data in the target platform. The data is stored in the attached
                 * artifacts p2metadata.xml and p2artifacts.xml, which are now present in the local
                 * Maven repository.
                 */
            if (logger.isDebugEnabled()) {
                logger.debug("P2TargetPlatformResolver: Using existing metadata of " + artifact.toString());
            }
            result.addArtifactWithExistingMetadata(new ArtifactFacade(artifact), new ArtifactFacade(p2Data.p2MetadataXml.artifact));
            /*
                 * Since the p2artifacts.xml exists on disk, we can add the artifact to the (global)
                 * p2 artifact repository view of local Maven repository. Then, the artifact is
                 * available in the build.
                 */
            // TODO this should happen in resolution context
            p2ArtifactsInLocalRepo.addGav(new GAV(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()));
        } else if (!p2Data.p2MetadataXml.isAvailable() && !p2Data.p2ArtifactsXml.isAvailable()) {
            /*
                 * The POM dependency has not been built by Tycho. If the dependency is a bundle,
                 * run the p2 bundle publisher on it and add the result to the resolution context.
                 */
            if (logger.isDebugEnabled()) {
                logger.debug("P2resolver.addMavenArtifact " + artifact.toString());
            }
            result.publishAndAddArtifactIfBundleArtifact(new ArtifactFacade(artifact));
        } else {
            failDueToPartialP2Data(artifact, p2Data);
        }
    }
    return result;
}
Also used : PomDependencyCollector(org.eclipse.tycho.p2.target.facade.PomDependencyCollector) TychoRepositoryIndex(org.eclipse.tycho.p2.repository.TychoRepositoryIndex) ArtifactFacade(org.eclipse.tycho.p2.facade.internal.ArtifactFacade) GAV(org.eclipse.tycho.p2.repository.GAV) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

File (java.io.File)11 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)10 IOException (java.io.IOException)5 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)5 FacadeException (org.eclipse.tycho.p2.tools.FacadeException)5 Test (org.junit.Test)5 GAV (org.eclipse.tycho.p2.repository.GAV)4 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)4 TargetDefinition (org.eclipse.tycho.p2.target.facade.TargetDefinition)4 FileInputStream (java.io.FileInputStream)3 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)3 MavenRepositoryLocation (org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation)3 DestinationRepositoryDescriptor (org.eclipse.tycho.p2.tools.DestinationRepositoryDescriptor)3 RepositoryReferences (org.eclipse.tycho.p2.tools.RepositoryReferences)3 InputStream (java.io.InputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2