Search in sources :

Example 11 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class CliTest method checkLocalRepositoryWithExplicitMavenRepoAndSettings.

@Test
public void checkLocalRepositoryWithExplicitMavenRepoAndSettings() throws Exception {
    File folder = temp.newFolder();
    Cli c = new Cli();
    executeMethod(c, "run", new Object[] { new String[] { "-settings=" + getClass().getResource("/settings-test.xml").getFile(), "-Dmaven.repo.local=" + folder.toString() } });
    ManipulationSession session = (ManipulationSession) FieldUtils.readField(c, "session", true);
    MavenSession ms = (MavenSession) FieldUtils.readField(session, "mavenSession", true);
    assertTrue(ms.getLocalRepository().getBasedir().equals(folder.toString()));
    assertTrue(ms.getRequest().getLocalRepository().getBasedir().equals(ms.getRequest().getLocalRepositoryPath().toString()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) File(java.io.File) Test(org.junit.Test)

Example 12 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class CliTest method checkTargetMatchesWithRun.

@Test
public void checkTargetMatchesWithRun() throws Exception {
    Cli c = new Cli();
    File pom1 = temp.newFile();
    executeMethod(c, "run", new Object[] { new String[] { "-f", pom1.toString() } });
    assertTrue("Session file should match", pom1.equals(((ManipulationSession) FieldUtils.readField(c, "session", true)).getPom()));
}
Also used : ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) File(java.io.File) Test(org.junit.Test)

Example 13 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class CliTest method checkLocalRepositoryWithSettings.

@Test
public void checkLocalRepositoryWithSettings() throws Exception {
    Cli c = new Cli();
    executeMethod(c, "run", new Object[] { new String[] { "-settings=" + getClass().getResource("/settings-test.xml").getFile() } });
    ManipulationSession session = (ManipulationSession) FieldUtils.readField(c, "session", true);
    MavenSession ms = (MavenSession) FieldUtils.readField(session, "mavenSession", true);
    assertTrue(ms.getRequest().getLocalRepository().getBasedir().equals(ms.getRequest().getLocalRepositoryPath().toString()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Example 14 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class CliTest method checkTargetMatches.

@Test
public void checkTargetMatches() throws Exception {
    Cli c = new Cli();
    File pom1 = temp.newFile();
    File settings = writeSettings(temp.newFile());
    executeMethod(c, "createSession", new Object[] { pom1, settings });
    assertTrue("Session file should match", pom1.equals(((ManipulationSession) FieldUtils.readField(c, "session", true)).getPom()));
}
Also used : ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) File(java.io.File) Test(org.junit.Test)

Example 15 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class CliTest method checkLocalRepositoryWithDefaultsAndModifiedUserSettings.

@Test
public void checkLocalRepositoryWithDefaultsAndModifiedUserSettings() throws Exception {
    boolean restore = false;
    Path source = Paths.get(System.getProperty("user.home") + File.separatorChar + ".m2" + File.separatorChar + "settings.xml");
    Path backup = Paths.get(source.toString() + '.' + UUID.randomUUID().toString());
    Path tmpSettings = Paths.get(getClass().getResource("/settings-test.xml").getFile());
    try {
        if (source.toFile().exists()) {
            System.out.println("Backing up settings.xml to " + backup);
            restore = true;
            Files.move(source, backup, StandardCopyOption.ATOMIC_MOVE);
        }
        Files.copy(tmpSettings, source);
        Cli c = new Cli();
        executeMethod(c, "run", new Object[] { new String[] {} });
        ManipulationSession session = (ManipulationSession) FieldUtils.readField(c, "session", true);
        MavenSession ms = (MavenSession) FieldUtils.readField(session, "mavenSession", true);
        assertTrue(ms.getRequest().getLocalRepository().getBasedir().equals(ms.getRequest().getLocalRepositoryPath().toString()));
        assertTrue(ms.getLocalRepository().getBasedir().equals(System.getProperty("user.home") + File.separatorChar + ".m2-mead-test"));
    } finally {
        if (restore) {
            Files.move(backup, source, StandardCopyOption.ATOMIC_MOVE);
        } else {
            Files.delete(source);
        }
    }
}
Also used : Path(java.nio.file.Path) MavenSession(org.apache.maven.execution.MavenSession) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Aggregations

ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)23 Test (org.junit.Test)20 Project (org.commonjava.maven.ext.common.model.Project)9 File (java.io.File)8 MavenSession (org.apache.maven.execution.MavenSession)7 Model (org.apache.maven.model.Model)4 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 Dependency (org.apache.maven.model.Dependency)2 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)2 PlexusContainer (org.codehaus.plexus.PlexusContainer)2 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)2 VersioningState (org.commonjava.maven.ext.core.state.VersioningState)2 PomIO (org.commonjava.maven.ext.io.PomIO)2 GalleyAPIWrapper (org.commonjava.maven.ext.io.resolver.GalleyAPIWrapper)2 GalleyInfrastructure (org.commonjava.maven.ext.io.resolver.GalleyInfrastructure)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1