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());
}
}
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);
}
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);
}
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);
});
}
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);
}
Aggregations