Search in sources :

Example 21 with MavenSession

use of org.apache.maven.execution.MavenSession in project tycho by eclipse.

the class PackageFeatureMojoTest method testAddMavenDescriptorSetToTrue.

public void testAddMavenDescriptorSetToTrue() throws Exception {
    File basedir = getBasedir("projects/addMavenDescriptor/featureForcedToTrue");
    File platform = new File("src/test/resources/eclipse");
    List<MavenProject> projects = getSortedProjects(basedir, platform);
    MavenProject project = getProject(projects, "featureForcedToTrue");
    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);
    mojo.execute();
    ZipFile zip = new ZipFile(new File(basedir, "target/featureForcedToTrue.jar"));
    try {
        ZipEntry entry = zip.getEntry("META-INF/maven");
        assertNotNull("There must be a 'META-INF/maven/' entry in the feature.jar!", entry);
    } 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) ZipEntry(java.util.zip.ZipEntry) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 22 with MavenSession

use of org.apache.maven.execution.MavenSession 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 23 with MavenSession

use of org.apache.maven.execution.MavenSession in project tycho by eclipse.

the class PackageFeatureMojoTest method testAddMavenDescriptorNotAddedPerDefault.

public void testAddMavenDescriptorNotAddedPerDefault() throws Exception {
    File basedir = getBasedir("projects/addMavenDescriptor/featureDefault/");
    File platform = new File("src/test/resources/eclipse");
    List<MavenProject> projects = getSortedProjects(basedir, platform);
    MavenProject project = getProject(projects, "featureDefault");
    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);
    mojo.execute();
    ZipFile zip = new ZipFile(new File(basedir, "target/featureDefault.jar"));
    try {
        ZipEntry entry = zip.getEntry("META-INF/maven");
        assertNull("No 'META-INF/maven/' entry must be in the feature.jar!", entry);
    } 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) ZipEntry(java.util.zip.ZipEntry) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 24 with MavenSession

use of org.apache.maven.execution.MavenSession in project tycho by eclipse.

the class PackageIUMojoTest method testThatArtifactPayloadIsCorrect.

public void testThatArtifactPayloadIsCorrect() throws Exception {
    File basedir = getBasedir("projects/iuWithPayload/");
    File platform = new File("src/test/resources/eclipse");
    List<MavenProject> projects = getSortedProjects(basedir, platform);
    MavenProject project = getProject(projects, "iuWithPayload");
    MavenSession session = newMavenSession(project, projects);
    // set build qualifier
    lookupMojoWithDefaultConfiguration(project, session, "build-qualifier").execute();
    PackageIUMojo mojo = (PackageIUMojo) lookupConfiguredMojo(project, "package-iu");
    setVariableValueToObject(mojo, "artifactContentFolder", new File(basedir, "src/main/resources").getAbsolutePath());
    mojo.execute();
    assertThat(getFilesInZip(new File(basedir, "target/iuWithPayload-1.0.0.zip")), hasItem("file.txt"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) PackageIUMojo(org.eclipse.tycho.packaging.PackageIUMojo) File(java.io.File)

Example 25 with MavenSession

use of org.apache.maven.execution.MavenSession in project tycho by eclipse.

the class PackageIUMojoTest method testArtifactWithoutPayload.

public void testArtifactWithoutPayload() throws Exception {
    File basedir = getBasedir("projects/iuWithoutPayload");
    File platform = new File("src/test/resources/eclipse");
    List<MavenProject> projects = getSortedProjects(basedir, platform);
    MavenProject project = getProject(projects, "iuWithoutPayload");
    MavenSession session = newMavenSession(project, projects);
    // set build qualifier
    lookupMojoWithDefaultConfiguration(project, session, "build-qualifier").execute();
    PackageIUMojo mojo = (PackageIUMojo) lookupConfiguredMojo(project, "package-iu");
    mojo.execute();
    IU iu = IU.loadIU(new File(basedir, "target"));
    Element artifact = iu.getSelfArtifact();
    assertThat(artifact, nullValue());
    assertThat(new File(basedir, "target/iuWithoutPayload-1.0.0.zip").exists(), is(true));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) Element(de.pdark.decentxml.Element) PackageIUMojo(org.eclipse.tycho.packaging.PackageIUMojo) IU(org.eclipse.tycho.model.IU) File(java.io.File)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)117 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)19 Properties (java.util.Properties)18 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)11 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6