Search in sources :

Example 1 with FeatureDescription

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

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

the class ArtifactDependencyWalkerTest method walkProduct.

protected void walkProduct(String productFile, final ArrayList<PluginDescription> plugins, final ArrayList<FeatureDescription> features) throws Exception, IOException, XmlPullParserException {
    DependencyArtifacts platform = getTargetPlatform();
    final ProductConfiguration product = ProductConfiguration.read(new File(productFile));
    ArtifactDependencyWalker walker = new AbstractArtifactDependencyWalker(platform) {

        @Override
        public void walk(ArtifactDependencyVisitor visitor) {
            traverseProduct(product, visitor);
        }
    };
    walker.walk(new ArtifactDependencyVisitor() {

        @Override
        public void visitPlugin(PluginDescription plugin) {
            plugins.add(plugin);
        }

        @Override
        public boolean visitFeature(FeatureDescription feature) {
            features.add(feature);
            return true;
        }
    });
}
Also used : AbstractArtifactDependencyWalker(org.eclipse.tycho.core.osgitools.AbstractArtifactDependencyWalker) DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) ProductConfiguration(org.eclipse.tycho.model.ProductConfiguration) FeatureDescription(org.eclipse.tycho.core.FeatureDescription) AbstractArtifactDependencyWalker(org.eclipse.tycho.core.osgitools.AbstractArtifactDependencyWalker) ArtifactDependencyWalker(org.eclipse.tycho.core.ArtifactDependencyWalker) File(java.io.File) PluginDescription(org.eclipse.tycho.core.PluginDescription) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor)

Example 3 with FeatureDescription

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

the class BuildQualifierAggregatorMojo method getBuildTimestamp.

@Override
protected Date getBuildTimestamp() throws MojoExecutionException {
    Date timestamp = super.getBuildTimestamp();
    if (timestampProvider == null) {
        // no included bundle/feature can have more recent timestamp
        return timestamp;
    }
    final Date[] latestTimestamp = new Date[] { timestamp };
    TychoProject projectType = projectTypes.get(project.getPackaging());
    if (projectType == null) {
        throw new IllegalStateException("Unknown or unsupported packaging type " + packaging);
    }
    final ReactorProject thisProject = DefaultReactorProject.adapt(project);
    projectType.getDependencyWalker(project).walk(new ArtifactDependencyVisitor() {

        @Override
        public boolean visitFeature(FeatureDescription feature) {
            if (feature.getFeatureRef() == null || thisProject.equals(feature.getMavenProject())) {
                // visit immediately included features
                return true;
            }
            visitArtifact(feature);
            // do not visit indirectly included features/bundles
            return false;
        }

        @Override
        public void visitPlugin(PluginDescription plugin) {
            if (plugin.getPluginRef() == null || thisProject.equals(plugin.getMavenProject())) {
                // 'this' bundle
                return;
            }
            visitArtifact(plugin);
        }

        private void visitArtifact(ArtifactDescriptor artifact) {
            ReactorProject otherProject = artifact.getMavenProject();
            String otherVersion = (otherProject != null) ? otherProject.getExpandedVersion() : artifact.getKey().getVersion();
            Version v = Version.parseVersion(otherVersion);
            String otherQualifier = v.getQualifier();
            if (otherQualifier != null) {
                Date timestamp = parseQualifier(otherQualifier);
                if (timestamp != null) {
                    if (latestTimestamp[0].compareTo(timestamp) < 0) {
                        if (getLog().isDebugEnabled()) {
                            getLog().debug("Found '" + format.format(timestamp) + "' from qualifier '" + otherQualifier + "' for artifact " + artifact);
                        }
                        latestTimestamp[0] = timestamp;
                    }
                } else {
                    getLog().debug("Could not parse qualifier timestamp " + otherQualifier);
                }
            }
        }

        private Date parseQualifier(String qualifier) {
            Date timestamp = parseQualifier(qualifier, format);
            if (timestamp != null) {
                return timestamp;
            }
            return discoverTimestamp(qualifier);
        }

        private Date parseQualifier(String qualifier, SimpleDateFormat format) {
            ParsePosition pos = new ParsePosition(0);
            Date timestamp = format.parse(qualifier, pos);
            if (timestamp != null && pos.getIndex() == qualifier.length()) {
                return timestamp;
            }
            return null;
        }

        private Date discoverTimestamp(String qualifier) {
            return timestampFinder.findInString(qualifier);
        }
    });
    return latestTimestamp[0];
}
Also used : FeatureDescription(org.eclipse.tycho.core.FeatureDescription) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) Date(java.util.Date) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor) TychoProject(org.eclipse.tycho.core.TychoProject) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) Version(org.osgi.framework.Version) PluginDescription(org.eclipse.tycho.core.PluginDescription) SimpleDateFormat(java.text.SimpleDateFormat) ParsePosition(java.text.ParsePosition)

Aggregations

ArtifactDependencyVisitor (org.eclipse.tycho.core.ArtifactDependencyVisitor)3 FeatureDescription (org.eclipse.tycho.core.FeatureDescription)3 File (java.io.File)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 PluginDescription (org.eclipse.tycho.core.PluginDescription)2 IOException (java.io.IOException)1 ParsePosition (java.text.ParsePosition)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)1 ArtifactDependencyWalker (org.eclipse.tycho.core.ArtifactDependencyWalker)1 TychoProject (org.eclipse.tycho.core.TychoProject)1 AbstractArtifactDependencyWalker (org.eclipse.tycho.core.osgitools.AbstractArtifactDependencyWalker)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1 FeatureRef (org.eclipse.tycho.model.FeatureRef)1 ProductConfiguration (org.eclipse.tycho.model.ProductConfiguration)1 UpdateSite (org.eclipse.tycho.model.UpdateSite)1