Search in sources :

Example 16 with ReactorProject

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

the class P2DependencyResolver method newDefaultTargetPlatform.

protected DefaultDependencyArtifacts newDefaultTargetPlatform(ReactorProject project, Map<File, ReactorProject> projects, P2ResolutionResult result) {
    DefaultDependencyArtifacts platform = new DefaultDependencyArtifacts(project);
    platform.addNonReactorUnits(result.getNonReactorUnits());
    for (P2ResolutionResult.Entry entry : result.getArtifacts()) {
        ArtifactKey key = new DefaultArtifactKey(entry.getType(), entry.getId(), entry.getVersion());
        ReactorProject otherProject = projects.get(entry.getLocation());
        if (otherProject != null) {
            platform.addReactorArtifact(key, otherProject, entry.getClassifier(), entry.getInstallableUnits());
        } else {
            platform.addArtifactFile(key, entry.getLocation(), entry.getInstallableUnits());
        }
    }
    return platform;
}
Also used : DefaultDependencyArtifacts(org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) P2ResolutionResult(org.eclipse.tycho.p2.resolver.facade.P2ResolutionResult) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey)

Example 17 with ReactorProject

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

the class UpdateSiteAssembler method visitFeature.

@Override
public boolean visitFeature(FeatureDescription feature) {
    File location = feature.getLocation();
    String artifactId = feature.getKey().getId();
    String version = feature.getKey().getVersion();
    ReactorProject featureProject = feature.getMavenProject();
    if (featureProject != null) {
        version = featureProject.getExpandedVersion();
        location = featureProject.getArtifact(feature.getClassifier());
        if (location == null) {
            throw new IllegalStateException(featureProject.getId() + " does not provide an artifact with classifier '" + feature.getClassifier() + "'");
        }
        if (location.isDirectory()) {
            throw new IllegalStateException("Should at least run ``package'' phase");
        }
    }
    if (unpackFeatures) {
        File outputJar = getOutputFile(FEATURES_DIR, artifactId, version, null);
        if (location.isDirectory()) {
            copyDir(location, outputJar);
        } else {
            unpackJar(location, outputJar);
        }
    } else {
        File outputJar = getOutputFile(FEATURES_DIR, artifactId, version, ".jar");
        if (location.isDirectory()) {
            packDir(location, outputJar);
        } else {
            copyFile(location, outputJar);
        }
    }
    // keep visiting
    return true;
}
Also used : ReactorProject(org.eclipse.tycho.ReactorProject) File(java.io.File)

Example 18 with ReactorProject

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

the class UpdateSiteMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    target.mkdirs();
    try {
        // remove content collected in former builds.
        // Even without clean goal the build result must not assembly out dated content
        FileUtils.cleanDirectory(target);
    } catch (IOException e) {
        throw new MojoFailureException("Unable to delete old update site content: " + target.getAbsolutePath(), e);
    }
    try {
        UpdateSite site = UpdateSite.read(new File(basedir, UpdateSite.SITE_XML));
        UpdateSiteAssembler assembler = new UpdateSiteAssembler(session, target);
        if (inlineArchives) {
            assembler.setArchives(site.getArchives());
        }
        getDependencyWalker().walk(assembler);
        getDependencyWalker().traverseUpdateSite(site, new ArtifactDependencyVisitor() {

            @Override
            public boolean visitFeature(FeatureDescription feature) {
                FeatureRef featureRef = feature.getFeatureRef();
                String id = featureRef.getId();
                ReactorProject otherProject = feature.getMavenProject();
                String version;
                if (otherProject != null) {
                    version = otherProject.getExpandedVersion();
                } else {
                    version = feature.getKey().getVersion();
                }
                String url = UpdateSiteAssembler.FEATURES_DIR + id + "_" + version + ".jar";
                ((SiteFeatureRef) featureRef).setUrl(url);
                featureRef.setVersion(version);
                // don't traverse included features
                return false;
            }
        });
        if (inlineArchives) {
            site.removeArchives();
        }
        File file = new File(target, "site.xml");
        UpdateSite.write(site, file);
        // Copy the associate sites file, if necessary
        if (site.getAssociateSitesUrl() != null) {
            File srcAssociateSitesFile = new File(basedir, site.getAssociateSitesUrl());
            if (srcAssociateSitesFile.exists()) {
                FileUtils.copyFile(srcAssociateSitesFile, new File(target + File.separator + site.getAssociateSitesUrl()));
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : FeatureDescription(org.eclipse.tycho.core.FeatureDescription) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ReactorProject(org.eclipse.tycho.ReactorProject) IOException(java.io.IOException) SiteFeatureRef(org.eclipse.tycho.model.UpdateSite.SiteFeatureRef) FeatureRef(org.eclipse.tycho.model.FeatureRef) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) UpdateSite(org.eclipse.tycho.model.UpdateSite) File(java.io.File)

Example 19 with ReactorProject

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

the class P2MetadataMojo method attachP2Metadata.

protected void attachP2Metadata() throws MojoExecutionException {
    if (!attachP2Metadata || !supportedProjectTypes.contains(project.getPackaging())) {
        return;
    }
    File file = project.getArtifact().getFile();
    if (file == null || !file.canRead()) {
        throw new IllegalStateException();
    }
    File targetDir = new File(project.getBuild().getDirectory());
    ArtifactFacade projectDefaultArtifact = new ArtifactFacade(project.getArtifact());
    try {
        List<IArtifactFacade> artifacts = new ArrayList<>();
        artifacts.add(projectDefaultArtifact);
        for (Artifact attachedArtifact : project.getAttachedArtifacts()) {
            if (attachedArtifact.getFile() != null && (attachedArtifact.getFile().getName().endsWith(".jar") || (attachedArtifact.getFile().getName().endsWith(".zip") && project.getPackaging().equals(ArtifactType.TYPE_INSTALLABLE_UNIT)))) {
                artifacts.add(new ArtifactFacade(attachedArtifact));
            }
        }
        P2Generator p2generator = getService(P2Generator.class);
        Map<String, IP2Artifact> generatedMetadata = p2generator.generateMetadata(artifacts, targetDir);
        if (baselineMode != BaselineMode.disable) {
            generatedMetadata = baselineValidator.validateAndReplace(project, execution, generatedMetadata, baselineRepositories, baselineMode, baselineReplace);
        }
        File contentsXml = new File(targetDir, FILE_NAME_P2_METADATA);
        File artifactsXml = new File(targetDir, FILE_NAME_P2_ARTIFACTS);
        p2generator.persistMetadata(generatedMetadata, contentsXml, artifactsXml);
        projectHelper.attachArtifact(project, EXTENSION_P2_METADATA, CLASSIFIER_P2_METADATA, contentsXml);
        projectHelper.attachArtifact(project, EXTENSION_P2_ARTIFACTS, CLASSIFIER_P2_ARTIFACTS, artifactsXml);
        ReactorProject reactorProject = DefaultReactorProject.adapt(project);
        Set<Object> installableUnits = new LinkedHashSet<>();
        for (Map.Entry<String, IP2Artifact> entry : generatedMetadata.entrySet()) {
            String classifier = entry.getKey();
            IP2Artifact p2artifact = entry.getValue();
            installableUnits.addAll(p2artifact.getInstallableUnits());
            // attach any new classified artifacts, like feature root files for example
            if (classifier != null && !hasAttachedArtifact(project, classifier)) {
                projectHelper.attachArtifact(project, getExtension(p2artifact.getLocation()), classifier, p2artifact.getLocation());
            }
        }
        // TODO 353889 distinguish between dependency resolution seed units ("primary") and other units of the project
        reactorProject.setDependencyMetadata(true, installableUnits);
        reactorProject.setDependencyMetadata(false, Collections.emptySet());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not generate P2 metadata", e);
    }
    File localArtifactsFile = new File(project.getBuild().getDirectory(), FILE_NAME_LOCAL_ARTIFACTS);
    writeArtifactLocations(localArtifactsFile, getAllProjectArtifacts(project));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) ArtifactFacade(org.eclipse.tycho.p2.facade.internal.ArtifactFacade) IArtifactFacade(org.eclipse.tycho.p2.metadata.IArtifactFacade) IOException(java.io.IOException) P2Generator(org.eclipse.tycho.p2.metadata.P2Generator) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) Artifact(org.apache.maven.artifact.Artifact) IP2Artifact(org.eclipse.tycho.p2.metadata.IP2Artifact) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with ReactorProject

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

the class BuildQualifierTest method testAggregateAttachedFeatureQualifier.

public void testAggregateAttachedFeatureQualifier() throws Exception {
    File basedir = getBasedir("projects/stablebuildqualifier/attachedfeature");
    List<MavenProject> projects = getSortedProjects(basedir, new File(basedir, "targetplatform"));
    MavenProject project = getProject(projects, "attachedfeature");
    ReactorProject reactorProject = DefaultReactorProject.adapt(project);
    DefaultDependencyArtifacts dependencyArtifacts = (DefaultDependencyArtifacts) TychoProjectUtils.getDependencyArtifacts(project);
    // replace target platform dependencies with fake attached feature and bundle atrifacts
    ArtifactDescriptor attachedFeature = dependencyArtifacts.getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, "attachedfeature.attached.feature", null);
    dependencyArtifacts.removeAll(attachedFeature.getKey().getType(), attachedFeature.getKey().getId());
    dependencyArtifacts.addReactorArtifact(attachedFeature.getKey(), reactorProject, "attached-feature", attachedFeature.getInstallableUnits());
    ArtifactDescriptor attachedBundle = dependencyArtifacts.getArtifact(ArtifactType.TYPE_ECLIPSE_PLUGIN, "attachedfeature.attached.bundle", null);
    dependencyArtifacts.removeAll(attachedBundle.getKey().getType(), attachedBundle.getKey().getId());
    dependencyArtifacts.addReactorArtifact(attachedBundle.getKey(), reactorProject, "attached-bundle", attachedBundle.getInstallableUnits());
    MavenSession session = newMavenSession(projects.get(0), projects);
    executeMojo(session, project, "build-qualifier-aggregator");
    assertQualifier("201206180600", projects, "attachedfeature");
}
Also used : DefaultDependencyArtifacts(org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) File(java.io.File)

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