Search in sources :

Example 26 with ReactorProject

use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.

the class P2DependencyResolver method collectPomDependencies.

private PomDependencyCollector collectPomDependencies(MavenProject project, List<ReactorProject> reactorProjects, MavenSession session) {
    Set<String> projectIds = new HashSet<>();
    for (ReactorProject p : reactorProjects) {
        String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
        projectIds.add(key);
    }
    ArrayList<String> scopes = new ArrayList<>();
    scopes.add(Artifact.SCOPE_COMPILE);
    Collection<Artifact> artifacts;
    try {
        artifacts = projectDependenciesResolver.resolve(project, scopes, session);
    } catch (MultipleArtifactsNotFoundException e) {
        Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
        for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
            Artifact a = it.next();
            String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
            if (projectIds.contains(key)) {
                it.remove();
            }
        }
        if (!missing.isEmpty()) {
            throw new RuntimeException("Could not resolve project dependencies", e);
        }
        artifacts = e.getResolvedArtifacts();
        artifacts.removeAll(e.getMissingArtifacts());
    } catch (AbstractArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve project dependencies", e);
    }
    List<Artifact> externalArtifacts = new ArrayList<>(artifacts.size());
    for (Artifact artifact : artifacts) {
        String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
        if (projectIds.contains(key)) {
            // resolved to an older snapshot from the repo, we only want the current project in the reactor
            continue;
        }
        externalArtifacts.add(artifact);
    }
    PomDependencyProcessor pomDependencyProcessor = new PomDependencyProcessor(session, repositorySystem, resolverFactory, equinox.getService(LocalRepositoryP2Indices.class), getLogger());
    return pomDependencyProcessor.collectPomDependencies(project, externalArtifacts);
}
Also used : AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact) AttachedArtifact(org.eclipse.tycho.p2.facade.internal.AttachedArtifact) LocalRepositoryP2Indices(org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices) Iterator(java.util.Iterator) Collection(java.util.Collection) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 27 with ReactorProject

use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.

the class P2DependencyResolver method getThisReactorProject.

private ReactorProject getThisReactorProject(MavenSession session, MavenProject project, TargetPlatformConfiguration configuration) {
    // 'this' project should obey optionalDependencies configuration
    final List<TargetEnvironment> environments = configuration.getEnvironments();
    final OptionalResolutionAction optionalAction = configuration.getDependencyResolverConfiguration().getOptionalResolutionAction();
    Map<String, IDependencyMetadata> dependencyMetadata = getDependencyMetadata(session, project, environments, optionalAction);
    final Set<Object> metadata = new LinkedHashSet<>();
    final Set<Object> secondaryMetadata = new LinkedHashSet<>();
    for (Map.Entry<String, IDependencyMetadata> entry : dependencyMetadata.entrySet()) {
        metadata.addAll(entry.getValue().getMetadata(true));
        secondaryMetadata.addAll(entry.getValue().getMetadata(false));
    }
    ReactorProject reactorProjet = new DefaultReactorProject(project) {

        @Override
        public Set<?> getDependencyMetadata(boolean primary) {
            return primary ? metadata : secondaryMetadata;
        }
    };
    return reactorProjet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) OptionalResolutionAction(org.eclipse.tycho.core.resolver.shared.OptionalResolutionAction) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) TargetEnvironment(org.eclipse.tycho.core.shared.TargetEnvironment) IDependencyMetadata(org.eclipse.tycho.p2.metadata.IDependencyMetadata) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with ReactorProject

use of org.eclipse.tycho.ReactorProject 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 29 with ReactorProject

use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.

the class UpdateSiteAssembler method visitPlugin.

@Override
public void visitPlugin(PluginDescription plugin) {
    String bundleId = plugin.getKey().getId();
    String version = plugin.getKey().getVersion();
    String relPath = PLUGINS_DIR + bundleId + "_" + version + ".jar";
    if (archives != null && archives.containsKey(relPath)) {
        copyUrl(archives.get(relPath), new File(target, relPath));
        return;
    }
    if (plugin.getLocation() == null) {
        throw new IllegalStateException("Unresolved bundle reference " + bundleId + "_" + version);
    }
    ReactorProject bundleProject = plugin.getMavenProject();
    File location = null;
    if (bundleProject != null) {
        location = bundleProject.getArtifact(plugin.getClassifier());
        if (location == null) {
            throw new IllegalStateException(bundleProject.getId() + " does not provide an artifact with classifier '" + plugin.getClassifier() + "'");
        }
        if (location.isDirectory()) {
            throw new RuntimeException("Bundle project " + bundleProject.getId() + " artifact is a directory. The build should at least run ``package'' phase.");
        }
        version = bundleProject.getExpandedVersion();
    } else {
        location = plugin.getLocation();
    }
    if (unpackPlugins && isDirectoryShape(plugin, location)) {
        // need a directory
        File outputJar = getOutputFile(PLUGINS_DIR, bundleId, version, null);
        if (location.isDirectory()) {
            copyDir(location, outputJar);
        } else {
            unpackJar(location, outputJar);
        }
    } else {
        // need a jar
        File outputJar = getOutputFile(PLUGINS_DIR, bundleId, version, ".jar");
        if (location.isDirectory()) {
            packDir(location, outputJar);
        } else {
            copyFile(location, outputJar);
        }
    }
}
Also used : ReactorProject(org.eclipse.tycho.ReactorProject) File(java.io.File)

Example 30 with ReactorProject

use of org.eclipse.tycho.ReactorProject in project tycho by eclipse.

the class LicenseFeatureHelper method getLicenseFeature.

/**
 * Get the license feature jar for feature (or <code>null</code> if it has no license feature).
 *
 * See {@linkplain http://wiki.eclipse.org/Equinox/p2/License_Mechanism }.
 *
 * @param feature
 *            original feature
 * @param mavenProject
 *            original feature project
 * @return the license feature jar
 */
public File getLicenseFeature(Feature feature, MavenProject mavenProject) {
    String id = feature.getLicenseFeature();
    if (id == null) {
        return null;
    }
    ArtifactDescriptor licenseFeature = TychoProjectUtils.getDependencyArtifacts(mavenProject).getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, id, feature.getLicenseFeatureVersion());
    if (licenseFeature == null) {
        throw new IllegalStateException("License feature with id " + id + " is not found among project dependencies");
    }
    ReactorProject licenseProject = licenseFeature.getMavenProject();
    if (licenseProject == null) {
        return licenseFeature.getLocation();
    }
    File artifact = licenseProject.getArtifact();
    if (!artifact.isFile()) {
        throw new IllegalStateException("At least ''package'' phase need to be executed");
    }
    return artifact;
}
Also used : ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ReactorProject(org.eclipse.tycho.ReactorProject) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Aggregations

ReactorProject (org.eclipse.tycho.ReactorProject)32 File (java.io.File)20 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)16 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)10 ArtifactKey (org.eclipse.tycho.ArtifactKey)8 MavenProject (org.apache.maven.project.MavenProject)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedHashSet (java.util.LinkedHashSet)4 Artifact (org.apache.maven.artifact.Artifact)4 Dependency (org.apache.maven.model.Dependency)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)4 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)4 DefaultDependencyArtifacts (org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)3