Search in sources :

Example 1 with Feature

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

the class EclipseModelTest method testFeature.

public void testFeature() throws Exception {
    Feature feature = Feature.read(new File("src/test/resources/modelio/feature.xml"));
    assertEquals("1.0.0", feature.getVersion());
    List<PluginRef> plugins = feature.getPlugins();
    assertEquals(1, plugins.size());
    assertEquals("pluginA", plugins.get(0).getId());
    List<FeatureRef> features = feature.getIncludedFeatures();
    assertEquals(1, features.size());
    List<Feature.RequiresRef> requires = feature.getRequires();
    assertEquals(1, requires.size());
    assertEquals("pluginB", requires.get(0).getImports().get(0).getPlugin());
    assertEquals("featureC", requires.get(0).getImports().get(1).getFeature());
    // not structural data - getters
    assertEquals("featureA", feature.getLabel());
    assertEquals("COMPANY", feature.getProvider());
    assertEquals("Test License", feature.getLicense().trim());
    assertEquals("http://www.example.com/license", feature.getLicenseURL());
    assertEquals(null, feature.getCopyrightURL());
    assertEquals(null, feature.getCopyright());
    feature.setVersion("1.2.3");
    plugins.get(0).setVersion("3.4.5");
    // not structural data - setters
    feature.setLabel("featureA_MODIFIED");
    feature.setProvider("COMPANY_MODIFIED");
    feature.setLicense("Test License MODIFIED");
    feature.setLicenseURL("http://www.example.com/license_MODIFIED");
    feature.setCopyright("Test Copyright");
    feature.setCopyrightURL("http://www.example.com/copyright");
    File updatedFile = new File(target, "feature.xml");
    Feature.write(feature, updatedFile);
    Feature updated = Feature.read(updatedFile);
    assertEquals("1.2.3", updated.getVersion());
    assertEquals("3.4.5", updated.getPlugins().get(0).getVersion());
    // not structural data - persistence
    assertEquals("featureA_MODIFIED", feature.getLabel());
    assertEquals("COMPANY_MODIFIED", feature.getProvider());
    assertEquals("Test License MODIFIED", feature.getLicense());
    assertEquals("http://www.example.com/license_MODIFIED", feature.getLicenseURL());
    assertEquals("http://www.example.com/copyright", feature.getCopyrightURL());
    assertEquals("Test Copyright", feature.getCopyright());
}
Also used : PluginRef(org.eclipse.tycho.model.PluginRef) FeatureRef(org.eclipse.tycho.model.FeatureRef) Feature(org.eclipse.tycho.model.Feature) File(java.io.File)

Example 2 with Feature

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

the class FeatureXmlManipulator method applyChanges.

@Override
public void applyChanges(ProjectMetadata project, VersionChangesDescriptor versionChangeContext) {
    if (isFeature(project)) {
        Feature feature = getFeatureXml(project);
        for (PomVersionChange change : versionChangeContext.getVersionChanges()) {
            if (isFeature(change.getProject().getPackaging())) {
                if (change.getArtifactId().equals(feature.getId()) && change.getVersion().equals(feature.getVersion())) {
                    logger.info("  feature.xml//feature/@version: " + change.getVersion() + " => " + change.getNewVersion());
                    feature.setVersion(change.getNewVersion());
                }
                changeLicenseFeature(change, feature);
                // could be included feature
                changeIncludedFeatures(change, feature);
                changeRequiredFeatures(change, feature, versionChangeContext.getVersionRangeUpdateStrategy());
            } else if (isBundle(change.getProject())) {
                changeIncludedPlugins(change, feature);
                changeRequiredPlugins(change, feature, versionChangeContext.getVersionRangeUpdateStrategy());
            }
        }
    }
}
Also used : Feature(org.eclipse.tycho.model.Feature) PomVersionChange(org.eclipse.tycho.versions.engine.PomVersionChange)

Example 3 with Feature

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

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

the class EclipseFeatureProject method newDependencyWalker.

@Override
protected ArtifactDependencyWalker newDependencyWalker(MavenProject project, TargetEnvironment environment) {
    final File location = project.getBasedir();
    final Feature feature = Feature.loadFeature(location);
    return new AbstractArtifactDependencyWalker(getDependencyArtifacts(project, environment), getEnvironments(project, environment)) {

        @Override
        public void walk(ArtifactDependencyVisitor visitor) {
            traverseFeature(location, feature, visitor);
        }
    };
}
Also used : File(java.io.File) Feature(org.eclipse.tycho.model.Feature) ArtifactDependencyVisitor(org.eclipse.tycho.core.ArtifactDependencyVisitor)

Example 5 with Feature

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

the class LicenseFeatureTest method assertFeatureJar.

protected void assertFeatureJar(File feature) throws ZipException, IOException {
    assertTrue(feature.canRead());
    ZipFile zip = new ZipFile(feature);
    try {
        Assert.assertNotNull(zip.getEntry("file1.txt"));
        Assert.assertNotNull(zip.getEntry("file2.txt"));
        Properties p = new Properties();
        InputStream is = zip.getInputStream(zip.getEntry("feature.properties"));
        try {
            p.load(is);
        } finally {
            IOUtil.close(is);
        }
        Feature featureXML = Feature.readJar(feature);
        // make sure that the properties file contains the keys
        Assert.assertEquals("file1.txt", p.getProperty("licenseURL"));
        Assert.assertEquals("License - The More The Merrier.", p.getProperty("license"));
        // make sure that the feature.xml references the keys from the properties file
        Assert.assertEquals("%licenseURL", featureXML.getLicenseURL());
        Assert.assertEquals("%license", featureXML.getLicense().trim());
    } finally {
        zip.close();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) Properties(java.util.Properties) Feature(org.eclipse.tycho.model.Feature)

Aggregations

Feature (org.eclipse.tycho.model.Feature)16 File (java.io.File)13 IOException (java.io.IOException)3 ZipFile (java.util.zip.ZipFile)3 PluginRef (org.eclipse.tycho.model.PluginRef)3 Test (org.junit.Test)3 Properties (java.util.Properties)2 Verifier (org.apache.maven.it.Verifier)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 ArtifactKey (org.eclipse.tycho.ArtifactKey)2 ArtifactDependencyVisitor (org.eclipse.tycho.core.ArtifactDependencyVisitor)2 FeatureRef (org.eclipse.tycho.model.FeatureRef)2 UpdateSite (org.eclipse.tycho.model.UpdateSite)2 AbstractTychoIntegrationTest (org.eclipse.tycho.test.AbstractTychoIntegrationTest)2 Document (de.pdark.decentxml.Document)1 Element (de.pdark.decentxml.Element)1 InputStream (java.io.InputStream)1 LinkedHashSet (java.util.LinkedHashSet)1 MavenArchiveConfiguration (org.apache.maven.archiver.MavenArchiveConfiguration)1