Search in sources :

Example 21 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class DefaultTychoResolver method resolveProject.

@Override
public void resolveProject(MavenSession session, MavenProject project, List<ReactorProject> reactorProjects) {
    AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
    if (dr == null) {
        return;
    }
    DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
    logger.info("Computing target platform for " + project);
    TargetPlatform preliminaryTargetPlatform = resolver.computePreliminaryTargetPlatform(session, project, reactorProjects);
    TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
    DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
    logger.info("Resolving dependencies of " + project);
    DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, preliminaryTargetPlatform, reactorProjects, resolverConfiguration);
    if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Resolved target platform for ").append(project).append("\n");
        dependencyArtifacts.toDebugString(sb, "  ");
        logger.debug(sb.toString());
    }
    dr.setDependencyArtifacts(session, project, dependencyArtifacts);
    logger.info("Resolving class path of " + project);
    dr.resolveClassPath(session, project);
    resolver.injectDependenciesIntoMavenModel(project, dr, dependencyArtifacts, logger);
    if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(session, project)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Injected dependencies for ").append(project.toString()).append("\n");
        for (Dependency dependency : project.getDependencies()) {
            sb.append("  ").append(dependency.toString());
        }
        logger.debug(sb.toString());
    }
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) AbstractTychoProject(org.eclipse.tycho.core.osgitools.AbstractTychoProject) TargetPlatform(org.eclipse.tycho.artifacts.TargetPlatform) Dependency(org.apache.maven.model.Dependency) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) DependencyResolver(org.eclipse.tycho.core.DependencyResolver)

Example 22 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class TychoTest method testImplicitTargetEnvironment.

public void testImplicitTargetEnvironment() throws Exception {
    File basedir = getBasedir("projects/implicitenvironment/simple");
    List<MavenProject> projects = getSortedProjects(basedir);
    assertEquals(1, projects.size());
    // assertEquals("ambiguous", projects.get(0).getArtifactId());
    // assertEquals("none", projects.get(0).getArtifactId());
    assertEquals("simple", projects.get(0).getArtifactId());
    DefaultTargetPlatformConfigurationReader resolver = lookup(DefaultTargetPlatformConfigurationReader.class);
    MavenSession session;
    TargetPlatformConfiguration configuration;
    List<TargetEnvironment> environments;
    // ambiguous
    // session = newMavenSession(projects.get(0), projects);
    // configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
    // environments = configuration.getEnvironments();
    // assertEquals(0, environments.size());
    // none
    // session = newMavenSession(projects.get(0), projects);
    // configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
    // environments = configuration.getEnvironments();
    // assertEquals(0, environments.size());
    // simple
    session = newMavenSession(projects.get(0), projects);
    configuration = resolver.getTargetPlatformConfiguration(session, session.getCurrentProject());
    environments = configuration.getEnvironments();
    assertEquals(1, environments.size());
    TargetEnvironment env = environments.get(0);
    assertEquals("foo", env.getOs());
    assertEquals("bar", env.getWs());
    assertEquals("munchy", env.getArch());
}
Also used : DefaultTargetPlatformConfigurationReader(org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) File(java.io.File) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Example 23 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class P2DependencyResolver method resolveDependencies.

@Override
public DependencyArtifacts resolveDependencies(final MavenSession session, final MavenProject project, TargetPlatform targetPlatform, List<ReactorProject> reactorProjects, DependencyResolverConfiguration resolverConfiguration) {
    if (targetPlatform == null) {
        targetPlatform = TychoProjectUtils.getTargetPlatform(project);
    }
    // TODO 364134 For compatibility reasons, target-platform-configuration includes settings for the dependency resolution
    // --> split this information logically, e.g. through two distinct interfaces
    TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
    P2Resolver osgiResolverImpl = resolverFactory.createResolver(new MavenLoggerAdapter(getLogger(), DebugUtils.isDebugEnabled(session, project)));
    return doResolveDependencies(session, project, reactorProjects, resolverConfiguration, targetPlatform, osgiResolverImpl, configuration);
}
Also used : MavenLoggerAdapter(org.eclipse.tycho.osgi.adapters.MavenLoggerAdapter) P2Resolver(org.eclipse.tycho.p2.resolver.facade.P2Resolver) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration)

Example 24 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class RepositoryReferenceTool method addTargetPlatformRepository.

/**
 * Restores the p2 metadata view on the module's build target platform that was calculated
 * during the initial dependency resolution (see
 * org.eclipse.tycho.p2.resolver.P2ResolverImpl.toResolutionResult(...)).
 */
private void addTargetPlatformRepository(RepositoryReferences sources, MavenSession session, MavenProject project) throws MojoExecutionException, MojoFailureException {
    try {
        File repositoryLocation = new File(project.getBuild().getDirectory(), "targetPlatformRepository");
        repositoryLocation.mkdirs();
        FileOutputStream stream = new FileOutputStream(new File(repositoryLocation, "content.xml"));
        try {
            MetadataSerializable serializer = osgiServices.getService(MetadataSerializable.class);
            TargetPlatform targetPlatform = TychoProjectUtils.getTargetPlatform(project);
            DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
            TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
            DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
            DependencyArtifacts dependencyArtifacts = resolver.resolveDependencies(session, project, targetPlatform, DefaultReactorProject.adapt(session), resolverConfiguration);
            // this contains dependency-only metadata for 'this' project
            Set<Object> targetPlatformInstallableUnits = new HashSet<>(dependencyArtifacts.getInstallableUnits());
            for (ArtifactDescriptor artifact : dependencyArtifacts.getArtifacts()) {
                ReactorProject otherProject = artifact.getMavenProject();
                if (otherProject == null) {
                    // can't really happen
                    continue;
                }
                File artifactXml = otherProject.getArtifact(RepositoryLayoutHelper.CLASSIFIER_P2_ARTIFACTS);
                if (artifactXml != null && artifactXml.isFile()) {
                    sources.addArtifactRepository(artifactXml.getParentFile());
                }
            }
            serializer.serialize(stream, targetPlatformInstallableUnits);
        } finally {
            stream.close();
        }
        sources.addMetadataRepository(repositoryLocation);
    } catch (IOException e) {
        throw new MojoExecutionException("I/O exception while writing the build target platform to disk", e);
    }
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) IOException(java.io.IOException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) MetadataSerializable(org.eclipse.tycho.p2.metadata.MetadataSerializable) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) FileOutputStream(java.io.FileOutputStream) TargetPlatform(org.eclipse.tycho.artifacts.TargetPlatform) File(java.io.File) HashSet(java.util.HashSet)

Example 25 with TargetPlatformConfiguration

use of org.eclipse.tycho.core.TargetPlatformConfiguration in project tycho by eclipse.

the class AssembleRepositoryMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        File destination = getAssemblyRepositoryLocation();
        destination.mkdirs();
        copyResources(destination);
        Collection<DependencySeed> projectSeeds = TychoProjectUtils.getDependencySeeds(getProject());
        if (projectSeeds.size() == 0) {
            throw new MojoFailureException("No content specified for p2 repository");
        }
        RepositoryReferences sources = getVisibleRepositories();
        TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(getProject());
        MirrorApplicationService mirrorApp = p2.getService(MirrorApplicationService.class);
        DestinationRepositoryDescriptor destinationRepoDescriptor = new DestinationRepositoryDescriptor(destination, repositoryName, compress, xzCompress, keepNonXzIndexFiles, !createArtifactRepository, true);
        mirrorApp.mirrorReactor(sources, destinationRepoDescriptor, projectSeeds, getBuildContext(), includeAllDependencies, configuration.isIncludePackedArtifacts(), profileProperties);
    } catch (FacadeException e) {
        throw new MojoExecutionException("Could not assemble p2 repository", e);
    }
}
Also used : DependencySeed(org.eclipse.tycho.core.resolver.shared.DependencySeed) FacadeException(org.eclipse.tycho.p2.tools.FacadeException) RepositoryReferences(org.eclipse.tycho.p2.tools.RepositoryReferences) MirrorApplicationService(org.eclipse.tycho.p2.tools.mirroring.facade.MirrorApplicationService) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) File(java.io.File) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) DestinationRepositoryDescriptor(org.eclipse.tycho.p2.tools.DestinationRepositoryDescriptor)

Aggregations

TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)25 File (java.io.File)8 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)8 Test (org.junit.Test)7 MavenSession (org.apache.maven.execution.MavenSession)6 BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)6 TargetEnvironment (org.eclipse.tycho.core.shared.TargetEnvironment)6 Properties (java.util.Properties)4 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)4 Dependency (org.apache.maven.model.Dependency)3 MavenProject (org.apache.maven.project.MavenProject)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)2 TargetPlatform (org.eclipse.tycho.artifacts.TargetPlatform)2 DependencyResolverConfiguration (org.eclipse.tycho.core.DependencyResolverConfiguration)2 ExecutionEnvironmentConfiguration (org.eclipse.tycho.core.ee.shared.ExecutionEnvironmentConfiguration)2