Search in sources :

Example 6 with Feature

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

the class SetLicenseFeatureVersionTest method test.

@Test
public void test() throws Exception {
    Verifier verifier = getVerifier("/licenseFeature.setVersion", false);
    verifier.getCliOptions().add("-DnewVersion=" + NEW_MAVEN_VERSION);
    verifier.executeGoal("org.eclipse.tycho:tycho-versions-plugin:" + TychoVersion.getTychoVersion() + ":set-version");
    verifier.verifyErrorFreeLog();
    File licenseFeatureDir = new File(verifier.getBasedir(), "license.feature");
    Feature licenseFeature = Feature.read(new File(licenseFeatureDir, "feature.xml"));
    assertEquals(NEW_OSGI_VERSION, licenseFeature.getVersion());
    File otherFeatureDir = new File(verifier.getBasedir(), "other.feature");
    Feature otherFeature = Feature.read(new File(otherFeatureDir, "feature.xml"));
    assertEquals(NEW_OSGI_VERSION, otherFeature.getLicenseFeatureVersion());
}
Also used : Verifier(org.apache.maven.it.Verifier) File(java.io.File) Feature(org.eclipse.tycho.model.Feature) Test(org.junit.Test) AbstractTychoIntegrationTest(org.eclipse.tycho.test.AbstractTychoIntegrationTest)

Example 7 with Feature

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

the class GeneratePomsMojo method getFeatureFeaturesAndPlugins.

private Set<File> getFeatureFeaturesAndPlugins(File basedir) throws MojoExecutionException {
    try {
        Set<File> result = new LinkedHashSet<>();
        Feature feature = Feature.read(new File(basedir, "feature.xml"));
        for (PluginRef plugin : feature.getPlugins()) {
            addPlugin(result, plugin.getId());
        }
        for (FeatureRef includedFeature : feature.getIncludedFeatures()) {
            addFeature(result, includedFeature.getId());
        }
        for (Feature.RequiresRef require : feature.getRequires()) {
            for (Feature.ImportRef imp : require.getImports()) {
                addPlugin(result, imp.getPlugin());
                addFeature(result, imp.getFeature());
            }
        }
        return result;
    } catch (IOException e) {
        throw new MojoExecutionException("Exception processing feature " + toString(basedir), e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Exception processing feature " + toString(basedir), e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PluginRef(org.eclipse.tycho.model.PluginRef) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FeatureRef(org.eclipse.tycho.model.FeatureRef) IOException(java.io.IOException) File(java.io.File) Feature(org.eclipse.tycho.model.Feature)

Example 8 with Feature

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

the class PackageFeatureMojo method updateLicenseProperties.

private void updateLicenseProperties(Feature feature, File licenseFeatureFile) {
    // remove license feature id and version from feature.xml
    feature.setLicenseFeature(null);
    feature.setLicenseFeatureVersion(null);
    // copy the license text and URL from the license feature
    if (licenseFeatureFile != null) {
        Feature licenseFeature = Feature.loadFeature(licenseFeatureFile);
        if (licenseFeature.getLicenseURL() != null) {
            feature.setLicenseURL(licenseFeature.getLicenseURL());
        }
        if (licenseFeature.getLicense() != null) {
            feature.setLicense(licenseFeature.getLicense());
        }
    }
}
Also used : Feature(org.eclipse.tycho.model.Feature)

Example 9 with Feature

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

the class PackageFeatureMojoTest method testLicenseFeature.

public void testLicenseFeature() throws Exception {
    File basedir = getBasedir("projects/licenseFeature/feature");
    File platform = new File("src/test/resources/projects/licenseFeature/eclipse");
    List<MavenProject> projects = getSortedProjects(basedir, platform);
    MavenProject project = getProject(projects, "licenseFeature.feature");
    MavenSession session = newMavenSession(project, projects);
    // set build qualifier
    lookupMojoWithDefaultConfiguration(project, session, "build-qualifier").execute();
    PackageFeatureMojo mojo = (PackageFeatureMojo) lookupMojo("package-feature", project.getFile());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "session", session);
    setVariableValueToObject(mojo, "finalName", "feature");
    mojo.execute();
    ZipFile zip = new ZipFile(new File(basedir, "target/feature.jar"));
    try {
        // igorf: input streams are closed by zip.close() at the end, sloppy but should work
        // all bin.includes files from license features are included
        assertNotNull(zip.getEntry("file-license.txt"));
        assertNull(zip.getEntry("file-unlicense.txt"));
        // do not leak build.properties into 'this' feature
        assertNull(zip.getEntry("build.properties"));
        // license feature id/version are stripped off
        Feature feature = Feature.read(zip.getInputStream(zip.getEntry(Feature.FEATURE_XML)));
        assertNull(feature.getLicenseFeature());
        assertNull(feature.getLicenseFeatureVersion());
        assertEquals("http://www.foo.bar", feature.getLicenseURL());
        assertEquals("This is the license", feature.getLicense().trim());
        // feature.properties merged
        Properties p = new Properties();
        p.load(zip.getInputStream(zip.getEntry("feature.properties")));
        assertEquals("test property value", p.getProperty("test"));
        assertEquals("license test property value", p.getProperty("license-test"));
        // when present both in 'this' and license feature, files from 'this' feature are included
        assertEquals("file.txt contents", IOUtil.toString(zip.getInputStream(zip.getEntry("file.txt"))));
    } finally {
        zip.close();
    }
}
Also used : PackageFeatureMojo(org.eclipse.tycho.packaging.PackageFeatureMojo) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) ZipFile(java.util.zip.ZipFile) Properties(java.util.Properties) ZipFile(java.util.zip.ZipFile) File(java.io.File) Feature(org.eclipse.tycho.model.Feature)

Example 10 with Feature

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

the class LocalDependencyResolver method resolveDependencies.

@Override
public DependencyArtifacts resolveDependencies(MavenSession session, MavenProject project, TargetPlatform resolutionContext, List<ReactorProject> reactorProjects, DependencyResolverConfiguration resolverConfiguration) {
    DefaultDependencyArtifacts platform = new DefaultDependencyArtifacts(DefaultReactorProject.adapt(project));
    for (File site : layout.getSites()) {
        for (File plugin : layout.getPlugins(site)) {
            ArtifactKey artifactKey = getArtifactKey(session, plugin);
            if (artifactKey != null) {
                platform.addArtifactFile(artifactKey, plugin, null);
            }
        }
        for (File feature : layout.getFeatures(site)) {
            Feature desc = Feature.loadFeature(feature);
            ArtifactKey key = new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_FEATURE, desc.getId(), desc.getVersion());
            platform.addArtifactFile(key, feature, null);
        }
    }
    addProjects(session, platform);
    addDependencies(session, project, platform);
    if (platform.isEmpty()) {
        getLogger().warn("Could not find any bundles or features in " + layout.getLocation());
    }
    return platform;
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) File(java.io.File) 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