Search in sources :

Example 1 with DependencyResolverConfiguration

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

the class TestMojo method createEclipseInstallation.

private EquinoxInstallation createEclipseInstallation() throws MojoExecutionException {
    DependencyResolver platformResolver = dependencyResolverLocator.lookupDependencyResolver(project);
    final List<Dependency> extraDependencies = getExtraDependencies();
    List<ReactorProject> reactorProjects = getReactorProjects();
    final DependencyResolverConfiguration resolverConfiguration = new DependencyResolverConfiguration() {

        @Override
        public OptionalResolutionAction getOptionalResolutionAction() {
            return OptionalResolutionAction.IGNORE;
        }

        @Override
        public List<Dependency> getExtraRequirements() {
            return extraDependencies;
        }
    };
    DependencyArtifacts testRuntimeArtifacts = platformResolver.resolveDependencies(session, project, null, reactorProjects, resolverConfiguration);
    if (testRuntimeArtifacts == null) {
        throw new MojoExecutionException("Cannot determinate build target platform location -- not executing tests");
    }
    work.mkdirs();
    EquinoxInstallationDescription testRuntime = new DefaultEquinoxInstallationDescription();
    testRuntime.setDefaultBundleStartLevel(defaultStartLevel);
    testRuntime.addBundlesToExplode(getBundlesToExplode());
    testRuntime.addFrameworkExtensions(getFrameworkExtensions());
    if (bundleStartLevel != null) {
        for (BundleStartLevel level : bundleStartLevel) {
            testRuntime.addBundleStartLevel(level);
        }
    }
    TestFrameworkProvider provider = providerHelper.selectProvider(getProjectType().getClasspath(project), getMergedProviderProperties(), providerHint);
    createSurefireProperties(provider);
    for (ArtifactDescriptor artifact : testRuntimeArtifacts.getArtifacts(ArtifactType.TYPE_ECLIPSE_PLUGIN)) {
        // note that this project is added as directory structure rooted at project basedir.
        // project classes and test-classes are added via dev.properties file (see #createDevProperties())
        // all other projects are added as bundle jars.
        ReactorProject otherProject = artifact.getMavenProject();
        if (otherProject != null) {
            if (otherProject.sameProject(project)) {
                testRuntime.addBundle(artifact.getKey(), project.getBasedir());
                continue;
            }
            File file = otherProject.getArtifact(artifact.getClassifier());
            if (file != null) {
                testRuntime.addBundle(artifact.getKey(), file);
                continue;
            }
        }
        testRuntime.addBundle(artifact);
    }
    Set<Artifact> testFrameworkBundles = providerHelper.filterTestFrameworkBundles(provider, pluginArtifacts);
    for (Artifact artifact : testFrameworkBundles) {
        DevBundleInfo devInfo = workspaceState.getBundleInfo(session, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), project.getPluginArtifactRepositories());
        if (devInfo != null) {
            testRuntime.addBundle(devInfo.getArtifactKey(), devInfo.getLocation(), true);
            testRuntime.addDevEntries(devInfo.getSymbolicName(), devInfo.getDevEntries());
        } else {
            File bundleLocation = artifact.getFile();
            ArtifactKey bundleArtifactKey = getBundleArtifactKey(bundleLocation);
            testRuntime.addBundle(bundleArtifactKey, bundleLocation, true);
        }
    }
    testRuntime.addDevEntries(getTestBundleSymbolicName(), getBuildOutputDirectories());
    reportsDirectory.mkdirs();
    return installationFactory.createInstallation(testRuntime, work);
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) ArtifactKey(org.eclipse.tycho.ArtifactKey) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) Dependency(org.apache.maven.model.Dependency) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) Artifact(org.apache.maven.artifact.Artifact) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) EquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) DevBundleInfo(org.eclipse.tycho.dev.DevBundleInfo) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider) File(java.io.File)

Example 2 with DependencyResolverConfiguration

use of org.eclipse.tycho.core.DependencyResolverConfiguration 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 3 with DependencyResolverConfiguration

use of org.eclipse.tycho.core.DependencyResolverConfiguration 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)

Aggregations

DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)3 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)3 DependencyResolverConfiguration (org.eclipse.tycho.core.DependencyResolverConfiguration)3 File (java.io.File)2 Dependency (org.apache.maven.model.Dependency)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 TargetPlatform (org.eclipse.tycho.artifacts.TargetPlatform)2 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)2 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Artifact (org.apache.maven.artifact.Artifact)1 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)1 DefaultEquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription)1 EquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription)1 ArtifactKey (org.eclipse.tycho.ArtifactKey)1 AbstractTychoProject (org.eclipse.tycho.core.osgitools.AbstractTychoProject)1