Search in sources :

Example 21 with Repository

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

the class BaselineServiceImpl method getProjectBaseline.

@Override
public Map<String, IP2Artifact> getProjectBaseline(Collection<MavenRepositoryLocation> baselineLocations, Map<String, IP2Artifact> reactor, File target) {
    // baseline repository may contain artifacts with the same id/version but different contents
    // compared to what is installed (or cached) locally.
    // current local repository layout does not track per-repository artifacts and does not allow
    // multiple different artifacts with same id/version.
    CompositeMetadataRepository baselineUnits;
    CompositeArtifactRepository baselineArtifacts;
    try {
        IProvisioningAgent remoteAgent = remoteAgentManager.getProvisioningAgent();
        IRepositoryIdManager remoteRepositoryIdManager = (IRepositoryIdManager) remoteAgent.getService(IRepositoryIdManager.SERVICE_NAME);
        IMetadataRepositoryManager remoteMetadataRepositoryManager = (IMetadataRepositoryManager) remoteAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        IArtifactRepositoryManager remoteArtifactRepositoryManager = (IArtifactRepositoryManager) remoteAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
        baselineUnits = CompositeMetadataRepository.createMemoryComposite(remoteAgent);
        baselineArtifacts = CompositeArtifactRepository.createMemoryComposite(remoteAgent);
        for (MavenRepositoryLocation location : baselineLocations) {
            URI url = location.getURL();
            try {
                remoteRepositoryIdManager.addMapping(location.getId(), url);
                // TODO offline mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=337022
                // not strictly necessary, but makes sure metadata download is visible in the console/log
                remoteMetadataRepositoryManager.loadRepository(url, monitor);
                remoteArtifactRepositoryManager.loadRepository(url, monitor);
                baselineUnits.addChild(url);
                baselineArtifacts.addChild(url);
            } catch (ProvisionException e) {
                // baseline repository may not exist yet
                mavenContext.getLogger().warn(e.getMessage(), e);
            }
        }
    } catch (ProvisionException e) {
        throw new RuntimeException(e);
    }
    Map<String, IP2Artifact> result = new LinkedHashMap<>();
    for (Map.Entry<String, IP2Artifact> reactorArtifact : reactor.entrySet()) {
        IArtifactDescriptor descriptor = (IArtifactDescriptor) reactorArtifact.getValue().getArtifactDescriptor();
        IArtifactDescriptor baselineDescriptor = getBaselineDescriptor(baselineArtifacts, descriptor);
        if (baselineDescriptor == null) {
            continue;
        }
        IArtifactKey baslineKey = baselineDescriptor.getArtifactKey();
        String format = baselineDescriptor.getProperty(IArtifactDescriptor.FORMAT);
        File baselineArtifact = new File(target, baslineKey.getClassifier() + "/" + baslineKey.getId() + "/" + baslineKey.getVersion() + (format != null ? "." + format : ""));
        try {
            baselineArtifact.getParentFile().mkdirs();
            OutputStream os = new BufferedOutputStream(new FileOutputStream(baselineArtifact));
            try {
                IStatus status = baselineArtifacts.getRawArtifact(baselineDescriptor, os, monitor);
                if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
                    String repository = baselineDescriptor.getRepository().getLocation().toString();
                    String artifactId = baselineDescriptor.getArtifactKey().getId();
                    String artifactVersion = baselineDescriptor.getArtifactKey().getVersion().toString();
                    String statusMessage = StatusTool.toLogMessage(status);
                    throw new RuntimeException(String.format("Error trying to download %s version %s from %s:\n%s", artifactId, artifactVersion, repository, statusMessage), StatusTool.findException(status));
                }
            } finally {
                try {
                    os.close();
                } catch (IOException e) {
                // ignored
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        List<IInstallableUnit> units = new ArrayList<>();
        for (Object _unit : reactorArtifact.getValue().getInstallableUnits()) {
            IInstallableUnit unit = (IInstallableUnit) _unit;
            IInstallableUnit baselineUnit = getBaselineUnit(baselineUnits, unit.getId(), unit.getVersion());
            if (baselineUnit != null) {
                units.add(baselineUnit);
            }
        }
        result.put(reactorArtifact.getKey(), new P2Artifact(baselineArtifact, units, descriptor));
    }
    return !result.isEmpty() ? result : null;
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IStatus(org.eclipse.core.runtime.IStatus) CompositeArtifactRepository(org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) IRepositoryIdManager(org.eclipse.tycho.p2.remote.IRepositoryIdManager) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IArtifactKey(org.eclipse.equinox.p2.metadata.IArtifactKey) CompositeMetadataRepository(org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) BufferedOutputStream(java.io.BufferedOutputStream) IArtifactDescriptor(org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IOException(java.io.IOException) MavenRepositoryLocation(org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation) IArtifactRepositoryManager(org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager) FileOutputStream(java.io.FileOutputStream) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) P2Artifact(org.eclipse.tycho.p2.impl.publisher.P2Artifact) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 22 with Repository

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

the class MirrorApplicationServiceImpl method toInstallableUnitList.

private static List<IInstallableUnit> toInstallableUnitList(Collection<DependencySeed> seeds, IMetadataRepository sourceRepository, RepositoryReferences sourceRepositoryNames) throws FacadeException {
    List<IInstallableUnit> result = new ArrayList<>(seeds.size());
    for (DependencySeed seed : seeds) {
        if (seed.getInstallableUnit() == null) {
            // TODO 372780 drop this when getInstallableUnit can no longer be null
            String unitId = seed.getId() + (ArtifactType.TYPE_ECLIPSE_FEATURE.equals(seed.getType()) ? ".feature.group" : "");
            result.addAll(querySourceIus(Collections.singletonList(new IUDescription(unitId, null)), sourceRepository, sourceRepositoryNames));
        } else {
            result.add((IInstallableUnit) seed.getInstallableUnit());
        }
    }
    if (result.isEmpty()) {
        throw new IllegalArgumentException("List of seed units for repository aggregation must not be empty");
    }
    return result;
}
Also used : DependencySeed(org.eclipse.tycho.core.resolver.shared.DependencySeed) IUDescription(org.eclipse.tycho.p2.tools.mirroring.facade.IUDescription) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 23 with Repository

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

the class MirrorApplicationServiceImpl method recreateArtifactRepository.

private void recreateArtifactRepository(DestinationRepositoryDescriptor destination) throws FacadeException {
    // create the missing md5 checksums
    if (destination.isMetaDataOnly()) {
        return;
    }
    RepositoryDescriptor descriptor = new RepositoryDescriptor();
    descriptor.setAppend(true);
    descriptor.setFormat(null);
    // $NON-NLS-1$
    descriptor.setKind("artifact");
    descriptor.setLocation(destination.getLocation().toURI());
    RecreateRepositoryApplication application = new RecreateRepositoryApplication();
    application.setArtifactRepository(descriptor);
    try {
        application.run(new NullProgressMonitor());
    } catch (ProvisionException e) {
        throw new FacadeException("Recreate artifact repository failed", e);
    }
}
Also used : FacadeException(org.eclipse.tycho.p2.tools.FacadeException) DestinationRepositoryDescriptor(org.eclipse.tycho.p2.tools.DestinationRepositoryDescriptor) RepositoryDescriptor(org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) RecreateRepositoryApplication(org.eclipse.equinox.p2.internal.repository.tools.RecreateRepositoryApplication)

Example 24 with Repository

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

the class MirrorApplicationServiceImpl method querySourceIus.

private static List<IInstallableUnit> querySourceIus(Collection<IUDescription> sourceIUs, IMetadataRepository repository, RepositoryReferences sources) throws FacadeException {
    if (sourceIUs == null || sourceIUs.isEmpty()) {
        return null;
    }
    List<IInstallableUnit> result = new ArrayList<>();
    for (IUDescription iu : sourceIUs) {
        IQuery<IInstallableUnit> iuQuery = createQuery(iu);
        Iterator<IInstallableUnit> queryResult = repository.query(iuQuery, null).iterator();
        if (!queryResult.hasNext()) {
            throw new FacadeException("Could not find IU " + iu.toString() + " in any of the source repositories " + sources.getMetadataRepositories(), null);
        }
        while (queryResult.hasNext()) {
            result.add(queryResult.next());
        }
    }
    return result;
}
Also used : FacadeException(org.eclipse.tycho.p2.tools.FacadeException) IUDescription(org.eclipse.tycho.p2.tools.mirroring.facade.IUDescription) ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 25 with Repository

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

the class MirrorApplicationServiceImpl method createSourceRepositories.

private static void createSourceRepositories(List<RepositoryDescriptor> result, Collection<URI> repositoryLocations, String repositoryKind) {
    for (URI repositoryLocation : repositoryLocations) {
        RepositoryDescriptor repository = new RepositoryDescriptor();
        repository.setKind(repositoryKind);
        repository.setLocation(repositoryLocation);
        result.add(repository);
    }
}
Also used : DestinationRepositoryDescriptor(org.eclipse.tycho.p2.tools.DestinationRepositoryDescriptor) RepositoryDescriptor(org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor) URI(java.net.URI)

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