Search in sources :

Example 1 with UpdateSite

use of org.eclipse.tycho.model.UpdateSite in project tycho by eclipse.

the class OsgiBundleProject method getDependencyWalker.

@Override
public ArtifactDependencyWalker getDependencyWalker(MavenProject project) {
    final DependencyArtifacts artifacts = getDependencyArtifacts(project);
    final List<ClasspathEntry> cp = getClasspath(project);
    return new ArtifactDependencyWalker() {

        @Override
        public void walk(ArtifactDependencyVisitor visitor) {
            for (ClasspathEntry entry : cp) {
                ArtifactDescriptor artifact = artifacts.getArtifact(entry.getArtifactKey());
                ArtifactKey key = artifact.getKey();
                File location = artifact.getLocation();
                ReactorProject project = artifact.getMavenProject();
                String classifier = artifact.getClassifier();
                Set<Object> installableUnits = artifact.getInstallableUnits();
                PluginDescription plugin = new DefaultPluginDescription(key, location, project, classifier, null, installableUnits);
                visitor.visitPlugin(plugin);
            }
        }

        @Override
        public void traverseFeature(File location, Feature feature, ArtifactDependencyVisitor visitor) {
        }

        @Override
        public void traverseUpdateSite(UpdateSite site, ArtifactDependencyVisitor artifactDependencyVisitor) {
        }

        @Override
        public void traverseProduct(ProductConfiguration productConfiguration, ArtifactDependencyVisitor visitor) {
        }
    };
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) ArtifactKey(org.eclipse.tycho.ArtifactKey) ProductConfiguration(org.eclipse.tycho.model.ProductConfiguration) ReactorProject(org.eclipse.tycho.ReactorProject) ArtifactDependencyWalker(org.eclipse.tycho.core.ArtifactDependencyWalker) Feature(org.eclipse.tycho.model.Feature) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) File(java.io.File) PluginDescription(org.eclipse.tycho.core.PluginDescription) UpdateSite(org.eclipse.tycho.model.UpdateSite)

Example 2 with UpdateSite

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

use of org.eclipse.tycho.model.UpdateSite in project tycho by eclipse.

the class EclipseModelTest method testUpdateSite.

public void testUpdateSite() throws Exception {
    UpdateSite site = UpdateSite.read(new File("src/test/resources/modelio/site.xml"));
    List<UpdateSite.SiteFeatureRef> features = site.getFeatures();
    assertEquals(2, features.size());
    assertEquals("featureB", features.get(1).getId());
    assertEquals("2.0.0", features.get(1).getVersion());
    Map<String, String> archives = site.getArchives();
    assertEquals(2, archives.size());
    assertEquals("http://www.company.com/updates/plugins/pluginA_1.0.0.jar", archives.get("plugins/pluginA_1.0.0.jar"));
    features.get(0).setVersion("3.0.0");
    site.removeArchives();
    assertTrue(site.getArchives().isEmpty());
    File updatedFile = new File(target, "site.xml");
    UpdateSite.write(site, updatedFile);
    UpdateSite updated = UpdateSite.read(updatedFile);
    assertEquals("3.0.0", updated.getFeatures().get(0).getVersion());
    assertTrue(updated.getArchives().isEmpty());
}
Also used : UpdateSite(org.eclipse.tycho.model.UpdateSite) File(java.io.File)

Example 4 with UpdateSite

use of org.eclipse.tycho.model.UpdateSite in project tycho by eclipse.

the class SiteXmlManipulator method applyChanges.

@Override
public void applyChanges(ProjectMetadata project, VersionChangesDescriptor versionChangeContext) {
    if (isSite(project)) {
        for (PomVersionChange change : versionChangeContext.getVersionChanges()) {
            if (isFeature(change.getProject().getPackaging())) {
                UpdateSite site = getSiteXml(project);
                for (FeatureRef feature : site.getFeatures()) {
                    if (change.getArtifactId().equals(feature.getId()) && change.getVersion().equals(feature.getVersion())) {
                        logger.info("  site.xml//site/feature/@id=" + feature.getId() + "/@version: " + change.getVersion() + " => " + change.getNewVersion());
                        feature.setVersion(change.getNewVersion());
                        SiteFeatureRef siteFeature = (SiteFeatureRef) feature;
                        String oldUrl = siteFeature.getUrl();
                        String newUrl = rewriteFeatureUrl(oldUrl, change);
                        logger.info("  site.xml//site/feature/@id=" + feature.getId() + "/@url: " + oldUrl + " => " + newUrl);
                        siteFeature.setUrl(newUrl);
                    }
                }
            }
        }
    }
}
Also used : SiteFeatureRef(org.eclipse.tycho.model.UpdateSite.SiteFeatureRef) SiteFeatureRef(org.eclipse.tycho.model.UpdateSite.SiteFeatureRef) FeatureRef(org.eclipse.tycho.model.FeatureRef) UpdateSite(org.eclipse.tycho.model.UpdateSite) PomVersionChange(org.eclipse.tycho.versions.engine.PomVersionChange)

Example 5 with UpdateSite

use of org.eclipse.tycho.model.UpdateSite in project tycho by eclipse.

the class SiteXmlManipulator method getSiteXml.

private UpdateSite getSiteXml(ProjectMetadata project) {
    UpdateSite site = project.getMetadata(UpdateSite.class);
    if (site == null) {
        File file = new File(project.getBasedir(), UpdateSite.SITE_XML);
        try {
            site = UpdateSite.read(file);
            project.putMetadata(site);
        } catch (IOException e) {
            throw new IllegalArgumentException("Could not read update site " + file, e);
        }
    }
    return site;
}
Also used : IOException(java.io.IOException) UpdateSite(org.eclipse.tycho.model.UpdateSite) PomFile(org.eclipse.tycho.versions.pom.PomFile) File(java.io.File)

Aggregations

UpdateSite (org.eclipse.tycho.model.UpdateSite)8 File (java.io.File)7 IOException (java.io.IOException)3 FeatureRef (org.eclipse.tycho.model.FeatureRef)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 ArtifactDependencyVisitor (org.eclipse.tycho.core.ArtifactDependencyVisitor)2 Feature (org.eclipse.tycho.model.Feature)2 SiteFeatureRef (org.eclipse.tycho.model.UpdateSite.SiteFeatureRef)2 PomFile (org.eclipse.tycho.versions.pom.PomFile)2 LinkedHashSet (java.util.LinkedHashSet)1 Verifier (org.apache.maven.it.Verifier)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ArtifactKey (org.eclipse.tycho.ArtifactKey)1 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)1 ClasspathEntry (org.eclipse.tycho.classpath.ClasspathEntry)1 ArtifactDependencyWalker (org.eclipse.tycho.core.ArtifactDependencyWalker)1 FeatureDescription (org.eclipse.tycho.core.FeatureDescription)1