Search in sources :

Example 21 with Location

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

the class TargetDefinitionFileTest method testIncludeSource.

@Test
public void testIncludeSource() throws Exception {
    List<? extends Location> locations = readTarget("includeSource.target", IncludeSourceMode.honor).getLocations();
    InstallableUnitLocation locationWithSources = (InstallableUnitLocation) locations.get(0);
    InstallableUnitLocation locationWithoutSources = (InstallableUnitLocation) locations.get(1);
    InstallableUnitLocation locationWithoutIncludeSourceAttribute = (InstallableUnitLocation) locations.get(2);
    assertEquals(true, locationWithSources.includeSource());
    assertEquals(false, locationWithoutSources.includeSource());
    assertEquals(false, locationWithoutIncludeSourceAttribute.includeSource());
}
Also used : InstallableUnitLocation(org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation) Test(org.junit.Test)

Example 22 with Location

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

the class TargetDefinitionUtil method makeURLsAbsolute.

/**
 * Resolves relative URLs in the given target definition file, with the specified resource as
 * base URL.
 *
 * @param targetDefinitionFile
 *            The target definition file in which relative URLs shall be replaced.
 * @param base
 * @throws IOException
 */
public static void makeURLsAbsolute(File targetDefinitionFile, File relocationBasedir) throws IOException {
    TargetDefinitionFile platform = TargetDefinitionFile.read(targetDefinitionFile, null);
    List<? extends TargetDefinition.Location> locations = platform.getLocations();
    for (TargetDefinition.Location location : locations) {
        List<Repository> repositories = ((IULocation) location).getRepositoryImpls();
        for (Repository repository : repositories) {
            makeRepositoryElementAbsolute(repository, relocationBasedir);
        }
    }
    TargetDefinitionFile.write(platform, targetDefinitionFile);
}
Also used : TargetDefinitionFile(org.eclipse.tycho.p2.resolver.TargetDefinitionFile) Repository(org.eclipse.tycho.p2.resolver.TargetDefinitionFile.Repository) IULocation(org.eclipse.tycho.p2.resolver.TargetDefinitionFile.IULocation) TargetDefinition(org.eclipse.tycho.p2.target.facade.TargetDefinition)

Example 23 with Location

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

the class TargetDefinitionUtil method setRepositoryURLs.

/**
 * Overwrites all repository URLs in the target file.
 */
public static void setRepositoryURLs(File targetDefinitionFile, String url) throws IOException {
    TargetDefinitionFile platform = TargetDefinitionFile.read(targetDefinitionFile, null);
    for (TargetDefinition.Location location : platform.getLocations()) {
        for (Repository repository : ((IULocation) location).getRepositoryImpls()) {
            repository.setLocation(url);
        }
    }
    TargetDefinitionFile.write(platform, targetDefinitionFile);
}
Also used : TargetDefinitionFile(org.eclipse.tycho.p2.resolver.TargetDefinitionFile) Repository(org.eclipse.tycho.p2.resolver.TargetDefinitionFile.Repository) IULocation(org.eclipse.tycho.p2.resolver.TargetDefinitionFile.IULocation) TargetDefinition(org.eclipse.tycho.p2.target.facade.TargetDefinition)

Example 24 with Location

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

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

the class TargetDefinitionResolver method resolveContentWithExceptions.

TargetDefinitionContent resolveContentWithExceptions(TargetDefinition definition) throws TargetDefinitionSyntaxException, TargetDefinitionResolutionException, ResolverException {
    List<URI> artifactRepositories = new ArrayList<>();
    ResolverRun resolverRun = new ResolverRun();
    for (Location locationDefinition : definition.getLocations()) {
        if (locationDefinition instanceof InstallableUnitLocation) {
            resolverRun.addLocation((InstallableUnitLocation) locationDefinition);
            for (Repository repository : ((InstallableUnitLocation) locationDefinition).getRepositories()) {
                artifactRepositories.add(repository.getLocation());
            }
        } else {
            logger.warn("Target location type '" + locationDefinition.getTypeDescription() + "' is not supported");
        }
    }
    if (definition.hasIncludedBundles()) {
        // the bundle selection list is currently not taken into account (see bug 373776)
        logger.warn("De-selecting bundles in a target definition file is not supported. See http://wiki.eclipse.org/Tycho_Messages_Explained#Target_File_Include_Bundles for alternatives.");
    }
    return new TargetDefinitionContent(resolverRun.resolve(), artifactRepositories);
}
Also used : IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) Repository(org.eclipse.tycho.p2.target.facade.TargetDefinition.Repository) InstallableUnitLocation(org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation) ArrayList(java.util.ArrayList) URI(java.net.URI) InstallableUnitLocation(org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation) Location(org.eclipse.tycho.p2.target.facade.TargetDefinition.Location)

Aggregations

Test (org.junit.Test)16 File (java.io.File)14 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)11 ArrayList (java.util.ArrayList)10 DefaultDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.DefaultDependencyMetadataGenerator)8 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)8 SourcesBundleDependencyMetadataGenerator (org.eclipse.tycho.p2.impl.publisher.SourcesBundleDependencyMetadataGenerator)7 DependencyMetadataGenerator (org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator)7 InstallableUnitLocation (org.eclipse.tycho.p2.target.facade.TargetDefinition.InstallableUnitLocation)7 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)6 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)4 TargetDefinition (org.eclipse.tycho.p2.target.facade.TargetDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)3 TychoRepositoryIndex (org.eclipse.tycho.p2.repository.TychoRepositoryIndex)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2