Search in sources :

Example 1 with Arg

use of org.codehaus.plexus.util.cli.Arg in project maven-release by apache.

the class ForkedMavenExecutorTest method testEncryptSettings.

@Test
public void testEncryptSettings() throws Exception {
    // prepare
    File workingDirectory = getTestFile("target/working-directory");
    Process mockProcess = mock(Process.class);
    when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class));
    when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class));
    when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class));
    when(mockProcess.waitFor()).thenReturn(0);
    Commandline commandLineMock = mock(Commandline.class);
    when(commandLineMock.execute()).thenReturn(mockProcess);
    Arg valueArgument = mock(Arg.class);
    when(commandLineMock.createArg()).thenReturn(valueArgument);
    CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class);
    when(commandLineFactoryMock.createCommandLine(isA(String.class))).thenReturn(commandLineMock);
    ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock);
    Settings settings = new Settings();
    Server server = new Server();
    server.setPassphrase("server_passphrase");
    server.setPassword("server_password");
    settings.addServer(server);
    Proxy proxy = new Proxy();
    proxy.setPassword("proxy_password");
    settings.addProxy(proxy);
    DefaultReleaseEnvironment releaseEnvironment = new DefaultReleaseEnvironment();
    releaseEnvironment.setSettings(settings);
    AbstractMavenExecutor executorSpy = spy(executor);
    SettingsXpp3Writer settingsWriter = mock(SettingsXpp3Writer.class);
    ArgumentCaptor<Settings> encryptedSettings = ArgumentCaptor.forClass(Settings.class);
    when(executorSpy.getSettingsWriter()).thenReturn(settingsWriter);
    executorSpy.executeGoals(workingDirectory, "validate", releaseEnvironment, false, null, null, new ReleaseResult());
    verify(settingsWriter).write(isA(Writer.class), encryptedSettings.capture());
    assertNotSame(settings, encryptedSettings.getValue());
    Server encryptedServer = encryptedSettings.getValue().getServers().get(0);
    assertEquals("server_passphrase", secDispatcher.decrypt(encryptedServer.getPassphrase()));
    assertEquals("server_password", secDispatcher.decrypt(encryptedServer.getPassword()));
    Proxy encryptedProxy = encryptedSettings.getValue().getProxies().get(0);
    assertEquals("proxy_password", secDispatcher.decrypt(encryptedProxy.getPassword()));
    File settingsSecurity = new File(System.getProperty("user.home"), ".m2/settings-security.xml");
    if (settingsSecurity.exists()) {
        assertNotEquals("server_passphrase", encryptedServer.getPassphrase());
        assertNotEquals("server_password", encryptedServer.getPassword());
        assertNotEquals("proxy_password", encryptedProxy.getPassword());
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) Server(org.apache.maven.settings.Server) ReleaseResult(org.apache.maven.shared.release.ReleaseResult) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) DefaultReleaseEnvironment(org.apache.maven.shared.release.env.DefaultReleaseEnvironment) Proxy(org.apache.maven.settings.Proxy) Arg(org.codehaus.plexus.util.cli.Arg) File(java.io.File) Settings(org.apache.maven.settings.Settings) SettingsXpp3Writer(org.apache.maven.settings.io.xpp3.SettingsXpp3Writer) Writer(java.io.Writer) SettingsXpp3Writer(org.apache.maven.settings.io.xpp3.SettingsXpp3Writer) Test(org.junit.Test)

Example 2 with Arg

use of org.codehaus.plexus.util.cli.Arg in project maven-release by apache.

the class ForkedMavenExecutorTest method testExecutionWithArguments.

@Test
public void testExecutionWithArguments() throws Exception {
    File workingDirectory = getTestFile("target/working-directory");
    Process mockProcess = mock(Process.class);
    when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class));
    when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class));
    when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class));
    when(mockProcess.waitFor()).thenReturn(0);
    Commandline commandLineMock = mock(Commandline.class);
    when(commandLineMock.execute()).thenReturn(mockProcess);
    Arg argMock = mock(Arg.class);
    when(commandLineMock.createArg()).thenReturn(argMock);
    CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class);
    when(commandLineFactoryMock.createCommandLine(endsWith("mvn"))).thenReturn(commandLineMock);
    ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock);
    // execute
    String arguments = "-DperformRelease=true -Dmaven.test.skip=true";
    executor.executeGoals(workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, arguments, null, new ReleaseResult());
    // verify
    verify(mockProcess).getInputStream();
    verify(mockProcess).getErrorStream();
    verify(mockProcess).getOutputStream();
    verify(mockProcess).waitFor();
    verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath());
    verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on");
    verify(commandLineMock).addEnvironment(eq("M2_HOME"), isNull());
    verify(commandLineMock).execute();
    verify(commandLineMock, times(4)).createArg();
    verify(argMock).setValue("clean");
    verify(argMock).setValue("integration-test");
    verify(argMock).setValue("--batch-mode");
    verify(argMock).setLine("-DperformRelease=true -Dmaven.test.skip=true");
    verify(commandLineFactoryMock).createCommandLine(endsWith("mvn"));
    verifyNoMoreInteractions(mockProcess, commandLineMock, argMock, commandLineFactoryMock);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ReleaseResult(org.apache.maven.shared.release.ReleaseResult) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Arg(org.codehaus.plexus.util.cli.Arg) File(java.io.File) DefaultReleaseEnvironment(org.apache.maven.shared.release.env.DefaultReleaseEnvironment) Test(org.junit.Test)

Example 3 with Arg

use of org.codehaus.plexus.util.cli.Arg in project maven-release by apache.

the class ForkedMavenExecutorTest method testExecutionWithCommandLineException.

@Test
public void testExecutionWithCommandLineException() throws Exception {
    // prepare
    File workingDirectory = getTestFile("target/working-directory");
    Commandline commandLineMock = mock(Commandline.class);
    when(commandLineMock.execute()).thenThrow(new CommandLineException("..."));
    Arg argMock = mock(Arg.class);
    when(commandLineMock.createArg()).thenReturn(argMock);
    CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class);
    when(commandLineFactoryMock.createCommandLine(endsWith("mvn"))).thenReturn(commandLineMock);
    ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock);
    // execute
    try {
        executor.executeGoals(workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, null, null, new ReleaseResult());
        fail("Should have thrown an exception");
    } catch (MavenExecutorException e) {
        assertEquals("Check cause", CommandLineException.class, e.getCause().getClass());
    }
    // verify
    verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath());
    verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on");
    verify(commandLineMock).addEnvironment(eq("M2_HOME"), isNull());
    verify(commandLineMock).execute();
    verify(commandLineMock, times(3)).createArg();
    verify(argMock).setValue("clean");
    verify(argMock).setValue("integration-test");
    verify(argMock).setValue("--batch-mode");
    verify(commandLineFactoryMock).createCommandLine(endsWith("mvn"));
    verifyNoMoreInteractions(commandLineMock, argMock, commandLineFactoryMock);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ReleaseResult(org.apache.maven.shared.release.ReleaseResult) Arg(org.codehaus.plexus.util.cli.Arg) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) DefaultReleaseEnvironment(org.apache.maven.shared.release.env.DefaultReleaseEnvironment) Test(org.junit.Test)

Example 4 with Arg

use of org.codehaus.plexus.util.cli.Arg in project vertx-maven-plugin by reactiverse.

the class JavaProcessExecutor method argsLine.

private void argsLine(Commandline commandline) {
    if (jvmArgs == null) {
        return;
    }
    List<String> full = new ArrayList<>(jvmArgs);
    full.addAll(argsList);
    full.forEach(arg -> {
        Arg cliArg = commandline.createArg();
        cliArg.setValue(arg);
    });
}
Also used : Arg(org.codehaus.plexus.util.cli.Arg)

Example 5 with Arg

use of org.codehaus.plexus.util.cli.Arg in project maven-release by apache.

the class ForkedMavenExecutorTest method testExecution.

@Test
public void testExecution() throws Exception {
    // prepare
    File workingDirectory = getTestFile("target/working-directory");
    Process mockProcess = mock(Process.class);
    when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class));
    when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class));
    when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class));
    when(mockProcess.waitFor()).thenReturn(0);
    Commandline commandLineMock = mock(Commandline.class);
    when(commandLineMock.execute()).thenReturn(mockProcess);
    Arg valueArgument = mock(Arg.class);
    when(commandLineMock.createArg()).thenReturn(valueArgument);
    CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class);
    when(commandLineFactoryMock.createCommandLine(isA(String.class))).thenReturn(commandLineMock);
    ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock);
    // execute
    executor.executeGoals(workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, null, null, new ReleaseResult());
    // verify
    verify(mockProcess).getInputStream();
    verify(mockProcess).getErrorStream();
    verify(mockProcess).getOutputStream();
    verify(mockProcess).waitFor();
    verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath());
    verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on");
    verify(commandLineMock).addEnvironment(eq("M2_HOME"), isNull());
    verify(commandLineMock).execute();
    verify(commandLineMock, times(3)).createArg();
    verify(valueArgument).setValue("clean");
    verify(valueArgument).setValue("integration-test");
    verify(valueArgument).setValue("--batch-mode");
    verify(commandLineFactoryMock).createCommandLine(endsWith("mvn"));
    verifyNoMoreInteractions(mockProcess, commandLineFactoryMock, commandLineMock, valueArgument);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ReleaseResult(org.apache.maven.shared.release.ReleaseResult) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Arg(org.codehaus.plexus.util.cli.Arg) File(java.io.File) DefaultReleaseEnvironment(org.apache.maven.shared.release.env.DefaultReleaseEnvironment) Test(org.junit.Test)

Aggregations

Arg (org.codehaus.plexus.util.cli.Arg)7 File (java.io.File)6 ReleaseResult (org.apache.maven.shared.release.ReleaseResult)6 DefaultReleaseEnvironment (org.apache.maven.shared.release.env.DefaultReleaseEnvironment)6 Commandline (org.codehaus.plexus.util.cli.Commandline)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 OutputStream (java.io.OutputStream)5 Writer (java.io.Writer)1 Proxy (org.apache.maven.settings.Proxy)1 Server (org.apache.maven.settings.Server)1 Settings (org.apache.maven.settings.Settings)1 SettingsXpp3Writer (org.apache.maven.settings.io.xpp3.SettingsXpp3Writer)1 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)1