> enumerations) {
this.enumerations = enumerations;
}
@Override
- public boolean hasMoreElements()
- {
- if (current == null || !current.hasMoreElements())
- {
- if (!enumerations.hasNext())
- {
+ public boolean hasMoreElements() {
+ if (current == null || !current.hasMoreElements()) {
+ if (!enumerations.hasNext()) {
return false;
}
current = enumerations.next();
@@ -556,8 +443,7 @@ public boolean hasMoreElements()
}
@Override
- public URL nextElement()
- {
+ public URL nextElement() {
return current.nextElement();
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/DummyMain.java b/src/test/java/org/codehaus/mojo/exec/DummyMain.java
index 591efa16..7619d34c 100644
--- a/src/test/java/org/codehaus/mojo/exec/DummyMain.java
+++ b/src/test/java/org/codehaus/mojo/exec/DummyMain.java
@@ -2,26 +2,23 @@
/**
* Simple class with a main method to call from unit tests
- *
+ *
* @author Jerome Lacoste
* @version $Id$
*/
-public class DummyMain
-{
+public class DummyMain {
/**
* Prints Hello followed by each argument, then a new line. Use a space character as separator.
- *
+ *
* @param args the arguments
*/
- public static void main( String... args )
- {
- StringBuilder buffer = new StringBuilder( "Hello" );
+ public static void main(String... args) {
+ StringBuilder buffer = new StringBuilder("Hello");
- for ( String arg : args )
- {
- buffer.append( System.getProperty( "line.separator" ) ).append( arg );
+ for (String arg : args) {
+ buffer.append(System.getProperty("line.separator")).append(arg);
}
- System.out.println( buffer.toString() );
+ System.out.println(buffer.toString());
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java b/src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java
index f177dd2e..28daf2c9 100644
--- a/src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java
+++ b/src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java
@@ -15,9 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -39,20 +36,21 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
/**
* @author Jerome Lacoste
* @version $Id$
*/
-public class ExecJavaMojoTest
- extends AbstractMojoTestCase
-{
+public class ExecJavaMojoTest extends AbstractMojoTestCase {
@Mock
private MavenSession session;
-
- private static final File LOCAL_REPO = new File( "src/test/repository" );
+
+ private static final File LOCAL_REPO = new File("src/test/repository");
private static final int JAVA_VERSION_MAJOR =
- Integer.parseInt( System.getProperty( "java.version" ).replaceFirst( "[.].*", "" ) );
+ Integer.parseInt(System.getProperty("java.version").replaceFirst("[.].*", ""));
/*
* This one won't work yet public void xxtestSimpleRunPropertiesAndArguments() throws MojoExecutionException,
@@ -63,37 +61,33 @@ public class ExecJavaMojoTest
/**
* Check that a simple execution with no arguments and no system properties produces the expected result.
* We load the config from a pom file and fill up the MavenProject property ourselves
- *
+ *
* @throws Exception if any exception occurs
*/
- public void testSimpleRun()
- throws Exception
- {
- File pom = new File( getBasedir(), "src/test/projects/project4/pom.xml" );
+ public void testSimpleRun() throws Exception {
+ File pom = new File(getBasedir(), "src/test/projects/project4/pom.xml");
- String output = execute( pom, "java" );
+ String output = execute(pom, "java");
- assertEquals( "Hello" + System.getProperty( "line.separator" ), output );
+ assertEquals("Hello" + System.getProperty("line.separator"), output);
}
/**
* MEXEC-10 Check that an execution with no arguments and an system property with no value produces the expected
* result
* We load the config from a pom file and fill up the MavenProject property ourselves
- *
+ *
* @throws Exception if any exception occurs
*/
- public void testEmptySystemProperty()
- throws Exception
- {
- File pom = new File( getBasedir(), "src/test/projects/project5/pom.xml" );
+ public void testEmptySystemProperty() throws Exception {
+ File pom = new File(getBasedir(), "src/test/projects/project5/pom.xml");
- assertNull( "System property not yet created", System.getProperty( "test.name" ) );
+ assertNull("System property not yet created", System.getProperty("test.name"));
- assertEquals( "Hello " + System.lineSeparator(), execute( pom, "java" ) );
+ assertEquals("Hello " + System.lineSeparator(), execute(pom, "java"));
// ensure we get back in the original state and didn't leak the execution config
- assertNull( "System property not yet created", System.getProperty( "test.name" ) );
+ assertNull("System property not yet created", System.getProperty("test.name"));
}
/**
@@ -103,25 +97,20 @@ public void testEmptySystemProperty()
* @author Lukasz Cwik
* @throws Exception if any exception occurs
*/
- public void testRunWhichThrowsExceptionIsNotWrappedInInvocationTargetException()
- throws Exception
- {
- File pom = new File( getBasedir(), "src/test/projects/project15/pom.xml" );
+ public void testRunWhichThrowsExceptionIsNotWrappedInInvocationTargetException() throws Exception {
+ File pom = new File(getBasedir(), "src/test/projects/project15/pom.xml");
- try
- {
- execute( pom, "java" );
+ try {
+ execute(pom, "java");
- fail( "Expected Exception to be thrown but none was thrown" );
- }
- catch ( Throwable e )
- {
- assertTrue( e instanceof MojoExecutionException );
+ fail("Expected Exception to be thrown but none was thrown");
+ } catch (Throwable e) {
+ assertTrue(e instanceof MojoExecutionException);
- assertTrue( e.getCause() instanceof IOException );
+ assertTrue(e.getCause() instanceof IOException);
- assertEquals( "expected IOException thrown by test", e.getCause().getMessage() );
- }
+ assertEquals("expected IOException thrown by test", e.getCause().getMessage());
+ }
}
/**
@@ -170,34 +159,30 @@ public void testRunWhichThrowsExceptionIsNotWrappedInInvocationTargetException()
/**
* For cases where the Java code spawns Threads and main returns soon. See
* MEXEC-6.
- *
+ *
* @throws Exception if any exception occurs
*/
- public void testWaitNoDaemonThreads()
- throws Exception
- {
- File pom = new File( getBasedir(), "src/test/projects/project7/pom.xml" );
+ public void testWaitNoDaemonThreads() throws Exception {
+ File pom = new File(getBasedir(), "src/test/projects/project7/pom.xml");
- String output = execute( pom, "java" );
+ String output = execute(pom, "java");
- assertEquals( MainWithThreads.ALL_EXITED, output.trim() );
+ assertEquals(MainWithThreads.ALL_EXITED, output.trim());
}
/**
* For cases where the Java code spawns Threads and main returns soon, but code contains non interruptible threads.
* User is required to timeout the execution, otherwise it will hang. See
* MEXEC-15.
- *
+ *
* @throws Exception if any exception occurs
*/
- public void testWaitNonInterruptibleDaemonThreads()
- throws Exception
- {
- File pom = new File( getBasedir(), "src/test/projects/project9/pom.xml" );
+ public void testWaitNonInterruptibleDaemonThreads() throws Exception {
+ File pom = new File(getBasedir(), "src/test/projects/project9/pom.xml");
- String output = execute( pom, "java" );
+ String output = execute(pom, "java");
- assertEquals( MainWithThreads.TIMER_IGNORED, output.trim() );
+ assertEquals(MainWithThreads.TIMER_IGNORED, output.trim());
}
/**
@@ -205,12 +190,10 @@ public void testWaitNonInterruptibleDaemonThreads()
* GitHub-391.
*
* FIXME: This sometimes fails with {@code unit.framework.ComparisonFailure: expected:<...>; but was:<...3(f)>}.
- *
+ *
* @throws Exception if any exception occurs
*/
- public void testUncooperativeThread()
- throws Exception
- {
+ public void testUncooperativeThread() throws Exception {
// FIXME:
// This will fail the test, because Assume is a JUnit 4 thing, but we are running in JUnit 3 mode, because
// AbstractMojoTestCase extends PlexusTestCase extends TestCase. The latter is a JUnit 3 compatibility class.
@@ -219,17 +202,14 @@ public void testUncooperativeThread()
// versions. In JUnit 5, we could even conveniently use @EnabledOnJre.
// Assume.assumeTrue( JAVA_VERSION_MAJOR < 20 );
- File pom = new File( getBasedir(), "src/test/projects/project10/pom.xml" );
- String output = execute( pom, "java" );
+ File pom = new File(getBasedir(), "src/test/projects/project10/pom.xml");
+ String output = execute(pom, "java");
// note: execute() will wait a little bit before returning the output,
// thereby allowing the stop()'ed thread to output the final "(f)".
- if ( JAVA_VERSION_MAJOR < 20 )
- {
- assertEquals( MainUncooperative.SUCCESS, output.trim() );
- }
- else
- {
- assertEquals( MainUncooperative.INTERRUPTED_BUT_NOT_STOPPED, output.trim() );
+ if (JAVA_VERSION_MAJOR < 20) {
+ assertEquals(MainUncooperative.SUCCESS, output.trim());
+ } else {
+ assertEquals(MainUncooperative.INTERRUPTED_BUT_NOT_STOPPED, output.trim());
}
}
@@ -250,49 +230,42 @@ public void testUncooperativeThread()
* Test the commandline parsing facilities of the {@link AbstractExecMojo} class
* @throws Exception if any exception occurs
*/
- public void testRunWithArgs()
- throws Exception
- {
+ public void testRunWithArgs() throws Exception {
- String resultString = execute( new File( getBasedir(), "src/test/projects/project8/pom.xml" ), "java" );
+ String resultString = execute(new File(getBasedir(), "src/test/projects/project8/pom.xml"), "java");
- String LS = System.getProperty( "line.separator" );
+ String LS = System.getProperty("line.separator");
String expectedResult = "Hello" + LS + "Arg1" + LS + "Arg2a Arg2b" + LS;
- assertEquals( expectedResult, resultString );
+ assertEquals(expectedResult, resultString);
}
/**
* Ensures that classpath can be filtered (exclude from plugin deps or project deps) to resolve conflicts.
* @throws Exception if something unexpected occurs.
*/
- public void testExcludedClasspathElement() throws Exception
- {
- String LS = System.getProperty( "line.separator" );
+ public void testExcludedClasspathElement() throws Exception {
+ String LS = System.getProperty("line.separator");
// slf4j-simple
{
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
- execute(
- new File( getBasedir(), "src/test/projects/project16/pom.xml" ), "java",
- stdout, stderr);
- assertEquals( "org.slf4j.impl.SimpleLogger", stdout.toString().trim() );
+ execute(new File(getBasedir(), "src/test/projects/project16/pom.xml"), "java", stdout, stderr);
+ assertEquals("org.slf4j.impl.SimpleLogger", stdout.toString().trim());
assertEquals(
"[org.codehaus.mojo.exec.Slf4jMain.main()] INFO org.codehaus.mojo.exec.Slf4jMain - hello[]" + LS,
- stderr.toString() );
+ stderr.toString());
}
// slf4j-jdk14
{
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
- execute(
- new File( getBasedir(), "src/test/projects/project17/pom.xml" ), "java",
- stdout, stderr);
- assertEquals( "org.slf4j.impl.JDK14LoggerAdapter", stdout.toString().trim() );
+ execute(new File(getBasedir(), "src/test/projects/project17/pom.xml"), "java", stdout, stderr);
+ assertEquals("org.slf4j.impl.JDK14LoggerAdapter", stdout.toString().trim());
final String stderrString = stderr.toString(); // simpler check, just validate it is not simple output
- assertTrue( stderrString.contains( " org.codehaus.mojo.exec.Slf4jMain main" ) );
- assertTrue( stderrString.contains( ": hello[]" ) );
+ assertTrue(stderrString.contains(" org.codehaus.mojo.exec.Slf4jMain main"));
+ assertTrue(stderrString.contains(": hello[]"));
}
}
@@ -301,87 +274,77 @@ public void testExcludedClasspathElement() throws Exception
*
* @throws Exception if any exception occurs
*/
- public void testProjectProperties()
- throws Exception
- {
- File pom = new File( getBasedir(), "src/test/projects/project18/pom.xml" );
+ public void testProjectProperties() throws Exception {
+ File pom = new File(getBasedir(), "src/test/projects/project18/pom.xml");
- String output = execute( pom, "java" );
+ String output = execute(pom, "java");
- assertEquals( "Hello project18 project" + System.lineSeparator(), output );
+ assertEquals("Hello project18 project" + System.lineSeparator(), output);
}
/**
* @return output from System.out during mojo execution
*/
- private String execute( File pom, String goal )
- throws Exception
- {
- return execute( pom, goal, new ByteArrayOutputStream(), new ByteArrayOutputStream() );
+ private String execute(File pom, String goal) throws Exception {
+ return execute(pom, goal, new ByteArrayOutputStream(), new ByteArrayOutputStream());
}
/**
* @return output from System.out during mojo execution
*/
- private String execute( File pom, String goal, ByteArrayOutputStream stringOutputStream, OutputStream stderr )
- throws Exception
- {
+ private String execute(File pom, String goal, ByteArrayOutputStream stringOutputStream, OutputStream stderr)
+ throws Exception {
ExecJavaMojo mojo;
- mojo = (ExecJavaMojo) lookupMojo( goal, pom );
+ mojo = (ExecJavaMojo) lookupMojo(goal, pom);
- setUpProject( pom, mojo );
+ setUpProject(pom, mojo);
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
// why isn't this set up by the harness based on the default-value? TODO get to bottom of this!
- setVariableValueToObject( mojo, "includeProjectDependencies", Boolean.TRUE );
- setVariableValueToObject( mojo, "cleanupDaemonThreads", Boolean.TRUE );
- setVariableValueToObject( mojo, "classpathScope", "compile" );
+ setVariableValueToObject(mojo, "includeProjectDependencies", Boolean.TRUE);
+ setVariableValueToObject(mojo, "cleanupDaemonThreads", Boolean.TRUE);
+ setVariableValueToObject(mojo, "classpathScope", "compile");
- assertNotNull( mojo );
- assertNotNull( project );
+ assertNotNull(mojo);
+ assertNotNull(project);
// trap System.out
PrintStream out = System.out;
PrintStream err = System.err;
- System.setOut( new PrintStream( stringOutputStream ) );
- System.setErr( new PrintStream( stderr ) );
+ System.setOut(new PrintStream(stringOutputStream));
+ System.setErr(new PrintStream(stderr));
// ensure we don't log unnecessary stuff which would interfere with assessing success of tests
- mojo.setLog( new DefaultLog( new ConsoleLogger( Logger.LEVEL_ERROR, "exec:java" ) ) );
+ mojo.setLog(new DefaultLog(new ConsoleLogger(Logger.LEVEL_ERROR, "exec:java")));
- try
- {
+ try {
mojo.execute();
- }
- finally
- {
+ } finally {
// see testUncooperativeThread() for explaination
- Thread.sleep( 300 ); // time seems about right
- System.setOut( out );
- System.setErr( err );
+ Thread.sleep(300); // time seems about right
+ System.setOut(out);
+ System.setErr(err);
}
return stringOutputStream.toString();
}
- private void setUpProject( File pomFile, AbstractMojo mojo )
- throws Exception
- {
+ private void setUpProject(File pomFile, AbstractMojo mojo) throws Exception {
super.setUp();
-
- MockitoAnnotations.initMocks( this );
-
- ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+
+ MockitoAnnotations.initMocks(this);
+
+ ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
+ when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
RepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
- ProjectBuilder builder = lookup( ProjectBuilder.class );
+ when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
+
+ ProjectBuilder builder = lookup(ProjectBuilder.class);
- MavenProject project = builder.build( pomFile, buildingRequest ).getProject();
+ MavenProject project = builder.build(pomFile, buildingRequest).getProject();
// this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test
- project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() );
- setVariableValueToObject( mojo, "project", project );
+ project.getBuild().setOutputDirectory(new File("target/test-classes").getAbsolutePath());
+ setVariableValueToObject(mojo, "project", project);
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java b/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java
index 2231c7db..4e4bcbde 100644
--- a/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java
+++ b/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java
@@ -1,7 +1,5 @@
package org.codehaus.mojo.exec;
-import static java.util.Collections.emptyMap;
-
/*
* Copyright 2005 The Codehaus. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
@@ -31,29 +29,27 @@
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.mockito.Mock;
+import static java.util.Collections.emptyMap;
+
/**
* @author Jerome Lacoste
* @version $Id$
*/
-public class ExecMojoTest
- extends AbstractMojoTestCase
-{
+public class ExecMojoTest extends AbstractMojoTestCase {
@Mock
private MavenSession session;
-
- private static final File LOCAL_REPO = new File( "src/test/repository" );
-
+
+ private static final File LOCAL_REPO = new File("src/test/repository");
+
/*
* Finding a file actually on disk of the test system makes some of the tests fail.
- * Hence a purely random UUID is used to prevent this situation.
+ * Hence a purely random UUID is used to prevent this situation.
*/
private static final String SOME_EXECUTABLE = UUID.randomUUID().toString();
private MockExecMojo mojo;
- static class MockExecMojo
- extends ExecMojo
- {
+ static class MockExecMojo extends ExecMojo {
public int executeResult;
public List commandLines = new ArrayList();
@@ -62,53 +58,44 @@ static class MockExecMojo
public Map systemProperties = new HashMap();
- protected int executeCommandLine( Executor exec, CommandLine commandLine, Map enviro, OutputStream out,
- OutputStream err )
- throws IOException, ExecuteException
- {
- commandLines.add( commandLine );
- if ( failureMsg != null )
- {
- throw new ExecuteException( failureMsg, executeResult );
+ protected int executeCommandLine(
+ Executor exec, CommandLine commandLine, Map enviro, OutputStream out, OutputStream err)
+ throws IOException, ExecuteException {
+ commandLines.add(commandLine);
+ if (failureMsg != null) {
+ throw new ExecuteException(failureMsg, executeResult);
}
return executeResult;
}
- protected String getSystemProperty( String key )
- {
- return systemProperties.get( key );
+ protected String getSystemProperty(String key) {
+ return systemProperties.get(key);
}
- int getAmountExecutedCommandLines()
- {
+ int getAmountExecutedCommandLines() {
return commandLines.size();
}
- CommandLine getExecutedCommandline( int index )
- {
- return commandLines.get( index );
+ CommandLine getExecutedCommandline(int index) {
+ return commandLines.get(index);
}
}
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
mojo = new MockExecMojo();
// note: most of the tests below assume that the specified
// executable path is not fully specicied. See ExecMojo#getExecutablePath
- mojo.setExecutable( SOME_EXECUTABLE );
- mojo.setArguments( Arrays.asList( new String[] { "--version" } ) );
+ mojo.setExecutable(SOME_EXECUTABLE);
+ mojo.setArguments(Arrays.asList(new String[] {"--version"}));
mojo.executeResult = 0;
- mojo.setBasedir( File.createTempFile( "mvn-temp", "txt" ).getParentFile() );
+ mojo.setBasedir(File.createTempFile("mvn-temp", "txt").getParentFile());
}
- public void testRunOK()
- throws MojoExecutionException
- {
+ public void testRunOK() throws MojoExecutionException {
mojo.execute();
- checkMojo( SOME_EXECUTABLE + " --version" );
+ checkMojo(SOME_EXECUTABLE + " --version");
}
/*
@@ -124,232 +111,205 @@ public void testRunOK()
* generate a file whose contains are compared to expected output
*/
-
// MEXEC-12, MEXEC-72
- public void testGetExecutablePath()
- throws IOException
- {
+ public void testGetExecutablePath() throws IOException {
ExecMojo realMojo = new ExecMojo();
- File workdir = new File( System.getProperty( "user.dir" ) );
+ File workdir = new File(System.getProperty("user.dir"));
Map enviro = new HashMap();
String myJavaPath = "target" + File.separator + "javax";
- File f = new File( myJavaPath );
- assertTrue( "file created...", f.createNewFile() );
- assertTrue( "file exists...", f.exists() );
+ File f = new File(myJavaPath);
+ assertTrue("file created...", f.createNewFile());
+ assertTrue("file exists...", f.exists());
- realMojo.setExecutable( myJavaPath );
+ realMojo.setExecutable(myJavaPath);
- CommandLine cmd = realMojo.getExecutablePath( enviro, workdir );
- assertTrue( "File exists so path is absolute",
- cmd.getExecutable().startsWith( System.getProperty( "user.dir" ) ) );
+ CommandLine cmd = realMojo.getExecutablePath(enviro, workdir);
+ assertTrue("File exists so path is absolute", cmd.getExecutable().startsWith(System.getProperty("user.dir")));
f.delete();
- assertFalse( "file deleted...", f.exists() );
- cmd = realMojo.getExecutablePath( enviro, workdir );
- assertEquals( "File doesn't exist. Let the system find it (in that PATH?)", myJavaPath, cmd.getExecutable() );
+ assertFalse("file deleted...", f.exists());
+ cmd = realMojo.getExecutablePath(enviro, workdir);
+ assertEquals("File doesn't exist. Let the system find it (in that PATH?)", myJavaPath, cmd.getExecutable());
- if ( OS.isFamilyWindows() ) // Exec Maven Plugin only supports Batch detection and PATH search on Windows
+ if (OS.isFamilyWindows()) // Exec Maven Plugin only supports Batch detection and PATH search on Windows
{
myJavaPath = "target" + File.separator + "javax.bat";
- f = new File( myJavaPath );
- assertTrue( "file created...", f.createNewFile() );
- assertTrue( "file exists...", f.exists() );
-
- final String comSpec = System.getenv( "ComSpec" );
-
- realMojo.setExecutable( "javax.bat" );
- cmd = realMojo.getExecutablePath( enviro, workdir );
- assertTrue( "is bat file on windows, execute using ComSpec.", cmd.getExecutable().equals( comSpec ) );
-
- enviro.put( "PATH", workdir.getAbsolutePath() + File.separator + "target" );
- cmd = realMojo.getExecutablePath( enviro, workdir );
- assertTrue( "is bat file on windows' PATH, execute using ComSpec.", cmd.getExecutable().equals( comSpec ) );
+ f = new File(myJavaPath);
+ assertTrue("file created...", f.createNewFile());
+ assertTrue("file exists...", f.exists());
+
+ final String comSpec = System.getenv("ComSpec");
+
+ realMojo.setExecutable("javax.bat");
+ cmd = realMojo.getExecutablePath(enviro, workdir);
+ assertTrue(
+ "is bat file on windows, execute using ComSpec.",
+ cmd.getExecutable().equals(comSpec));
+
+ enviro.put("PATH", workdir.getAbsolutePath() + File.separator + "target");
+ cmd = realMojo.getExecutablePath(enviro, workdir);
+ assertTrue(
+ "is bat file on windows' PATH, execute using ComSpec.",
+ cmd.getExecutable().equals(comSpec));
f.delete();
- assertFalse( "file deleted...", f.exists() );
+ assertFalse("file deleted...", f.exists());
}
}
-
+
// under Windows cmd/bat files should be preferred over files with the same prefix without extension, e.g.
// if there are "node" and "node.cmd" the mojo should pick "node.cmd"
// see https://github.com/mojohaus/exec-maven-plugin/issues/42
- public void testGetExecutablePathPreferExecutableExtensionsOnWindows()
- throws IOException
- {
- // this test is for Windows
- if (!OS.isFamilyWindows()) {
- return;
- }
- final ExecMojo realMojo = new ExecMojo();
-
- final String tmp = System.getProperty("java.io.tmpdir");
- final File workdir = new File(tmp, "testGetExecutablePathPreferExecutableExtensionsOnWindows");
- workdir.mkdirs();
-
- final Map enviro = new HashMap();
-
- final File f = new File(workdir, "mycmd");
- final File fCmd = new File(workdir, "mycmd.cmd");
- f.createNewFile();
- fCmd.createNewFile();
- assertTrue( "file exists...", f.exists() );
- assertTrue( "file exists...", fCmd.exists() );
-
- realMojo.setExecutable( "mycmd" );
-
- final CommandLine cmd = realMojo.getExecutablePath( enviro, workdir );
- // cmdline argumets are: [/c, %path-to-temp%\mycmd.cmd], so check second argument
- assertTrue( "File should have cmd extension",
- cmd.getArguments()[1].endsWith( "mycmd.cmd" ) );
-
- f.delete();
- fCmd.delete();
- assertFalse( "file deleted...", f.exists() );
- assertFalse( "file deleted...", fCmd.exists() );
-
+ public void testGetExecutablePathPreferExecutableExtensionsOnWindows() throws IOException {
+ // this test is for Windows
+ if (!OS.isFamilyWindows()) {
+ return;
+ }
+ final ExecMojo realMojo = new ExecMojo();
+
+ final String tmp = System.getProperty("java.io.tmpdir");
+ final File workdir = new File(tmp, "testGetExecutablePathPreferExecutableExtensionsOnWindows");
+ workdir.mkdirs();
+
+ final Map enviro = new HashMap();
+
+ final File f = new File(workdir, "mycmd");
+ final File fCmd = new File(workdir, "mycmd.cmd");
+ f.createNewFile();
+ fCmd.createNewFile();
+ assertTrue("file exists...", f.exists());
+ assertTrue("file exists...", fCmd.exists());
+
+ realMojo.setExecutable("mycmd");
+
+ final CommandLine cmd = realMojo.getExecutablePath(enviro, workdir);
+ // cmdline argumets are: [/c, %path-to-temp%\mycmd.cmd], so check second argument
+ assertTrue("File should have cmd extension", cmd.getArguments()[1].endsWith("mycmd.cmd"));
+
+ f.delete();
+ fCmd.delete();
+ assertFalse("file deleted...", f.exists());
+ assertFalse("file deleted...", fCmd.exists());
}
- public void testRunFailure()
- {
+ public void testRunFailure() {
mojo.executeResult = 1;
- try
- {
+ try {
mojo.execute();
- fail( "expected failure" );
- }
- catch ( MojoExecutionException e )
- {
- assertEquals( "Result of " + mojo.getExecutedCommandline( 0 ) + " execution is: '1'.", e.getMessage() );
+ fail("expected failure");
+ } catch (MojoExecutionException e) {
+ assertEquals("Result of " + mojo.getExecutedCommandline(0) + " execution is: '1'.", e.getMessage());
}
- checkMojo( SOME_EXECUTABLE + " --version" );
+ checkMojo(SOME_EXECUTABLE + " --version");
}
- public void testRunError()
- {
+ public void testRunError() {
mojo.failureMsg = "simulated failure";
- try
- {
+ try {
mojo.execute();
- fail( "expected failure" );
- }
- catch ( MojoExecutionException e )
- {
- assertEquals( "Command execution failed.", e.getMessage() );
+ fail("expected failure");
+ } catch (MojoExecutionException e) {
+ assertEquals("Command execution failed.", e.getMessage());
}
- checkMojo( SOME_EXECUTABLE + " --version" );
+ checkMojo(SOME_EXECUTABLE + " --version");
}
- public void testOverrides()
- throws MojoExecutionException
- {
- mojo.systemProperties.put( "exec.args", "-f pom.xml" );
+ public void testOverrides() throws MojoExecutionException {
+ mojo.systemProperties.put("exec.args", "-f pom.xml");
mojo.execute();
- checkMojo( SOME_EXECUTABLE + " -f pom.xml" );
+ checkMojo(SOME_EXECUTABLE + " -f pom.xml");
}
- public void testOverrides3()
- throws MojoExecutionException
- {
- mojo.systemProperties.put( "exec.args", null );
+ public void testOverrides3() throws MojoExecutionException {
+ mojo.systemProperties.put("exec.args", null);
mojo.execute();
- checkMojo( SOME_EXECUTABLE + " --version" );
+ checkMojo(SOME_EXECUTABLE + " --version");
mojo.commandLines.clear();
- mojo.systemProperties.put( "exec.args", "" );
+ mojo.systemProperties.put("exec.args", "");
mojo.execute();
- checkMojo( SOME_EXECUTABLE + " --version" );
+ checkMojo(SOME_EXECUTABLE + " --version");
}
- public void testIsResultCodeAFailure()
- {
+ public void testIsResultCodeAFailure() {
ExecMojo execMojo = new ExecMojo();
- assertTrue( execMojo.isResultCodeAFailure( 1 ) );
- assertFalse( execMojo.isResultCodeAFailure( 0 ) );
-
- execMojo.setSuccessCodes( new Integer[0] );
- assertTrue( execMojo.isResultCodeAFailure( 1 ) );
- assertFalse( execMojo.isResultCodeAFailure( 0 ) );
-
- execMojo.setSuccessCodes( new Integer[] { Integer.valueOf( "2" ), Integer.valueOf( "5" ) } );
- assertTrue( execMojo.isResultCodeAFailure( 0 ) );
- assertTrue( execMojo.isResultCodeAFailure( 10 ) );
- assertFalse( execMojo.isResultCodeAFailure( 2 ) );
- assertFalse( execMojo.isResultCodeAFailure( 5 ) );
+ assertTrue(execMojo.isResultCodeAFailure(1));
+ assertFalse(execMojo.isResultCodeAFailure(0));
+
+ execMojo.setSuccessCodes(new Integer[0]);
+ assertTrue(execMojo.isResultCodeAFailure(1));
+ assertFalse(execMojo.isResultCodeAFailure(0));
+
+ execMojo.setSuccessCodes(new Integer[] {Integer.valueOf("2"), Integer.valueOf("5")});
+ assertTrue(execMojo.isResultCodeAFailure(0));
+ assertTrue(execMojo.isResultCodeAFailure(10));
+ assertFalse(execMojo.isResultCodeAFailure(2));
+ assertFalse(execMojo.isResultCodeAFailure(5));
}
// MEXEC-81
- public void testParseCommandlineOSWin()
- throws Exception
- {
+ public void testParseCommandlineOSWin() throws Exception {
ExecMojo execMojo = new ExecMojo();
final String javaHome = "C:\\Java\\jdk1.5.0_15";
// can only be set by expression or plugin-configuration
- setVariableValueToObject( execMojo, "commandlineArgs", javaHome );
+ setVariableValueToObject(execMojo, "commandlineArgs", javaHome);
String[] args = execMojo.parseCommandlineArgs();
- assertEquals( javaHome, args[0] );
+ assertEquals(javaHome, args[0]);
}
-
- public void test_exec_receives_all_parameters() throws MojoExecutionException
- {
+ public void test_exec_receives_all_parameters() throws MojoExecutionException {
// given
ExecMojo execMojo = new ExecMojo();
- execMojo.setExecutable( "mkdir" );
- execMojo.setArguments( Arrays.asList( "-p", "dist/mails" ) );
- execMojo.setBasedir( new File("target") );
+ execMojo.setExecutable("mkdir");
+ execMojo.setArguments(Arrays.asList("-p", "dist/mails"));
+ execMojo.setBasedir(new File("target"));
// when
- final CommandLine commandLine = execMojo.getExecutablePath( emptyMap(), new File( "target" ) );
+ final CommandLine commandLine = execMojo.getExecutablePath(emptyMap(), new File("target"));
execMojo.execute();
// then
- assertTrue( "dir should have been created",
- Paths.get( "target", "dist", "mails" ).toFile().exists() );
+ assertTrue(
+ "dir should have been created",
+ Paths.get("target", "dist", "mails").toFile().exists());
}
- private void checkMojo( String expectedCommandLine )
- {
- assertEquals( 1, mojo.getAmountExecutedCommandLines() );
- CommandLine commandline = mojo.getExecutedCommandline( 0 );
+ private void checkMojo(String expectedCommandLine) {
+ assertEquals(1, mojo.getAmountExecutedCommandLines());
+ CommandLine commandline = mojo.getExecutedCommandline(0);
// do NOT depend on Commandline toString()
- assertEquals( expectedCommandLine, getCommandLineAsString( commandline ) );
+ assertEquals(expectedCommandLine, getCommandLineAsString(commandline));
}
- private String getCommandLineAsString( CommandLine commandline )
- {
+ private String getCommandLineAsString(CommandLine commandline) {
// for the sake of the test comparisons, cut out the eventual
// cmd /c *.bat conversion
String result = commandline.getExecutable();
boolean isCmd = false;
- if ( OS.isFamilyWindows() && result.equals( "cmd" ) )
- {
+ if (OS.isFamilyWindows() && result.equals("cmd")) {
result = "";
isCmd = true;
}
String[] arguments = commandline.getArguments();
- for ( int i = 0; i < arguments.length; i++ )
- {
+ for (int i = 0; i < arguments.length; i++) {
String arg = arguments[i];
- if ( isCmd && i == 0 && "/c".equals( arg ) )
- {
+ if (isCmd && i == 0 && "/c".equals(arg)) {
continue;
}
- if ( isCmd && i == 1 && arg.endsWith( ".bat" ) )
- {
- arg = arg.substring( 0, arg.length() - ".bat".length() );
+ if (isCmd && i == 1 && arg.endsWith(".bat")) {
+ arg = arg.substring(0, arg.length() - ".bat".length());
}
- result += ( result.length() == 0 ? "" : " " ) + arg;
+ result += (result.length() == 0 ? "" : " ") + arg;
}
return result;
}
-
}
diff --git a/src/test/java/org/codehaus/mojo/exec/FindClassInClasspath.java b/src/test/java/org/codehaus/mojo/exec/FindClassInClasspath.java
index 2c4915f9..f4f09612 100644
--- a/src/test/java/org/codehaus/mojo/exec/FindClassInClasspath.java
+++ b/src/test/java/org/codehaus/mojo/exec/FindClassInClasspath.java
@@ -3,36 +3,28 @@
/**
* @author Jerome Lacoste
*/
-public class FindClassInClasspath
-{
+public class FindClassInClasspath {
public static final String FOUND_ALL = "OK";
/**
* @param args the names of classes to search in the classpath prints 'OK' if all classes found
**/
- public static void main( String... args )
- {
- for ( String arg : args )
- {
- if ( !isClassInClasspath( arg ) )
- {
- System.out.println( "ERROR: class + " + arg + " not found in classpath" );
- System.exit( 1 );
+ public static void main(String... args) {
+ for (String arg : args) {
+ if (!isClassInClasspath(arg)) {
+ System.out.println("ERROR: class + " + arg + " not found in classpath");
+ System.exit(1);
}
}
- System.out.println( FOUND_ALL );
+ System.out.println(FOUND_ALL);
}
- private static boolean isClassInClasspath( String className )
- {
- try
- {
- Class.forName( className );
+ private static boolean isClassInClasspath(String className) {
+ try {
+ Class.forName(className);
return true;
- }
- catch ( Exception e )
- {
- System.out.println( "ERROR: " + e.getMessage() );
+ } catch (Exception e) {
+ System.out.println("ERROR: " + e.getMessage());
return false;
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/HelloSystemProperty.java b/src/test/java/org/codehaus/mojo/exec/HelloSystemProperty.java
index 603ad753..ffc14140 100644
--- a/src/test/java/org/codehaus/mojo/exec/HelloSystemProperty.java
+++ b/src/test/java/org/codehaus/mojo/exec/HelloSystemProperty.java
@@ -3,16 +3,14 @@
/**
* Simple class with a main method reading a system property
*/
-public class HelloSystemProperty
-{
+public class HelloSystemProperty {
/**
* Print on stdout hello and the system property test.name value.
- *
+ *
* @param args the arguments
*/
- public static void main( String... args )
- {
+ public static void main(String... args) {
// important: do not default on empty due to testEmptySystemProperty()
- System.out.println( "Hello " + System.getProperty( "test.name" ) );
+ System.out.println("Hello " + System.getProperty("test.name"));
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/LineRedirectOutputStreamTest.java b/src/test/java/org/codehaus/mojo/exec/LineRedirectOutputStreamTest.java
index f1da2c63..32d07f84 100644
--- a/src/test/java/org/codehaus/mojo/exec/LineRedirectOutputStreamTest.java
+++ b/src/test/java/org/codehaus/mojo/exec/LineRedirectOutputStreamTest.java
@@ -1,14 +1,14 @@
package org.codehaus.mojo.exec;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Test;
-
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+
public class LineRedirectOutputStreamTest {
@Test
@@ -26,7 +26,9 @@ public void givenExtendedUnicodeCharacterOutput_whenRedirectingWithIso8859Charse
@Test
public void givenExtendedUnicodeCharacterOutput_whenRedirectingWithCp1252_thenShouldDecodeProperly()
throws IOException {
- Assume.assumeTrue("The JVM does not contain the cp-1252 charset", Charset.availableCharsets().containsKey("windows-1252"));
+ Assume.assumeTrue(
+ "The JVM does not contain the cp-1252 charset",
+ Charset.availableCharsets().containsKey("windows-1252"));
internalTestForCharset(Charset.forName("windows-1252"));
}
@@ -56,8 +58,9 @@ private void internalTestForCharset(Charset charset) throws IOException {
internalTestForCharset(sb -> new LineRedirectOutputStream(sb::append, charset), charset);
}
- private void internalTestForCharset(Function lineRedirectOutputStream,
- Charset charset) throws IOException {
+ private void internalTestForCharset(
+ Function lineRedirectOutputStream, Charset charset)
+ throws IOException {
StringBuilder sb = new StringBuilder();
String firstLine = "Hello, 你好, नमस्ते, مرحبا, γεια σας, שלום, こんにちは, 안녕하세요!";
String secondLine = "🌍 Welcome to the world! 🌟✨🎉🔥";
diff --git a/src/test/java/org/codehaus/mojo/exec/MainUncooperative.java b/src/test/java/org/codehaus/mojo/exec/MainUncooperative.java
index 956328d0..4a80f23a 100644
--- a/src/test/java/org/codehaus/mojo/exec/MainUncooperative.java
+++ b/src/test/java/org/codehaus/mojo/exec/MainUncooperative.java
@@ -4,59 +4,46 @@
* Created by IntelliJ IDEA. User: dsmiley Date: Jan 19, 2007 Time: 4:43:19 PM To change this template use File |
* Settings | File Templates.
*/
-public class MainUncooperative
- extends Thread
-{
+public class MainUncooperative extends Thread {
public static final String SUCCESS = "1(interrupted)(f)2(f)";
// In JDK 20+, Thread::stop has been removed and just throws an UnsupportedOperationException
public static final String INTERRUPTED_BUT_NOT_STOPPED = "1(interrupted)(f)2";
- public static void main( String... args )
- throws InterruptedException
- {
+ public static void main(String... args) throws InterruptedException {
Thread daemonThread = new MainUncooperative();
- daemonThread.setDaemon( true );
+ daemonThread.setDaemon(true);
daemonThread.start();
- Thread.sleep( 1000 );
+ Thread.sleep(1000);
// returns to caller now
}
- final long SIMWORKTIME = 15 * 1000;// 15 seconds of work which is going to be more than exec:java wants to wait
+ final long SIMWORKTIME = 15 * 1000; // 15 seconds of work which is going to be more than exec:java wants to wait
- public void run()
- {
+ public void run() {
boolean interruptedOnce = false;
long startedTime = System.currentTimeMillis();
- for ( int lap = 1; true; lap++ )
- {
- long remainingWork = SIMWORKTIME - ( System.currentTimeMillis() - startedTime );
- if ( remainingWork <= 0 )
- {
- break;// done
+ for (int lap = 1; true; lap++) {
+ long remainingWork = SIMWORKTIME - (System.currentTimeMillis() - startedTime);
+ if (remainingWork <= 0) {
+ break; // done
}
- try
- {
- System.out.print( lap );
- Thread.sleep( remainingWork );// simulates doing work
- System.out.print( "(done)" );
+ try {
+ System.out.print(lap);
+ Thread.sleep(remainingWork); // simulates doing work
+ System.out.print("(done)");
break;
- }
- catch ( InterruptedException e )
- {
+ } catch (InterruptedException e) {
// We want to ensure this only gets reported once. It's possible depending on a race condition for
// ExecJavaMojo.terminateThreads() to interrupt this thread a second time.
- if ( !interruptedOnce )
- {
- System.out.print( "(interrupted)" );
+ if (!interruptedOnce) {
+ System.out.print("(interrupted)");
}
interruptedOnce = true;
// be uncooperative; don't quit and don't set interrupted status
- }
- finally
- {
- System.out.print( "(f)" );// we should see this if Thread.stop() is called
+ } finally {
+ System.out.print("(f)"); // we should see this if Thread.stop() is called
}
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/MainWithThreads.java b/src/test/java/org/codehaus/mojo/exec/MainWithThreads.java
index fc6585fa..62fb768e 100644
--- a/src/test/java/org/codehaus/mojo/exec/MainWithThreads.java
+++ b/src/test/java/org/codehaus/mojo/exec/MainWithThreads.java
@@ -6,9 +6,7 @@
/**
* @author David Smiley
*/
-public class MainWithThreads
- extends Thread
-{
+public class MainWithThreads extends Thread {
public static final String ALL_EXITED = "t1(interrupted td)(cancelled timer)";
public static final String TIMER_IGNORED = "t1(interrupted td)";
@@ -18,40 +16,35 @@ public class MainWithThreads
* will be interrupted right away. - if the timer is cancelled (using 'cancelTimer' as argument), the timer will die
* on itself after all the other threads - if not, one must use a time out to stop joining on that unresponsive
* daemon thread
- *
+ *
* @param args the arguments
**/
- public static void main( String... args )
- {
+ public static void main(String... args) {
// long run so that we interrupt it before it ends itself
- Thread responsiveDaemonThread = new MainWithThreads( 60000, "td" );
- responsiveDaemonThread.setDaemon( true );
+ Thread responsiveDaemonThread = new MainWithThreads(60000, "td");
+ responsiveDaemonThread.setDaemon(true);
responsiveDaemonThread.start();
- new MainWithThreads( 200, "t1" ).start();
+ new MainWithThreads(200, "t1").start();
// Timer in Java <= 6 aren't interruptible
- final Timer t = new Timer( true );
+ final Timer t = new Timer(true);
- if ( optionsContains( args, "cancelTimer" ) )
- {
- t.schedule( new TimerTask()
- {
- public void run()
- {
- System.out.print( "(cancelled timer)" );
- t.cancel();
- }
- }, 400 );
+ if (optionsContains(args, "cancelTimer")) {
+ t.schedule(
+ new TimerTask() {
+ public void run() {
+ System.out.print("(cancelled timer)");
+ t.cancel();
+ }
+ },
+ 400);
}
}
- private static boolean optionsContains( String[] args, String option )
- {
- for ( String arg : args )
- {
- if ( arg.equals( option ) )
- {
+ private static boolean optionsContains(String[] args, String option) {
+ for (String arg : args) {
+ if (arg.equals(option)) {
return true;
}
}
@@ -62,23 +55,19 @@ private static boolean optionsContains( String[] args, String option )
private String message;
- public MainWithThreads( int millisecsToSleep, String message )
- {
+ public MainWithThreads(int millisecsToSleep, String message) {
this.millisecsToSleep = millisecsToSleep;
this.message = message;
}
- public void run()
- {
- try
- {
- Thread.sleep( millisecsToSleep );
- }
- catch ( InterruptedException e ) // IE's are a way to cancel a thread
+ public void run() {
+ try {
+ Thread.sleep(millisecsToSleep);
+ } catch (InterruptedException e) // IE's are a way to cancel a thread
{
- System.out.print( "(interrupted " + message + ")" );
+ System.out.print("(interrupted " + message + ")");
return;
}
- System.out.print( message );
+ System.out.print(message);
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/NoMain.java b/src/test/java/org/codehaus/mojo/exec/NoMain.java
index dc694298..9635eec7 100644
--- a/src/test/java/org/codehaus/mojo/exec/NoMain.java
+++ b/src/test/java/org/codehaus/mojo/exec/NoMain.java
@@ -20,12 +20,7 @@
* @author Jerome Lacoste
* @version $Id$
*/
-public class NoMain
-{
+public class NoMain {
// MEXEC-29 wrong interface for main method causes NPE
- public static void main()
- throws Exception
- {
-
- }
+ public static void main() throws Exception {}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/Slf4jMain.java b/src/test/java/org/codehaus/mojo/exec/Slf4jMain.java
index 142580b8..64a92f4e 100644
--- a/src/test/java/org/codehaus/mojo/exec/Slf4jMain.java
+++ b/src/test/java/org/codehaus/mojo/exec/Slf4jMain.java
@@ -8,18 +8,16 @@
/**
* Simple class with a main method to call from unit tests
*/
-public class Slf4jMain
-{
+public class Slf4jMain {
/**
* Print on stdout the logger class (slf4j binding) and then
* logs at info level args with Hello as suffix.
- *
+ *
* @param args the arguments
*/
- public static void main( String... args )
- {
- final Logger logger = LoggerFactory.getLogger( Slf4jMain.class );
- System.out.println( logger.getClass().getName() );
- logger.info( "hello" + asList( args ) );
+ public static void main(String... args) {
+ final Logger logger = LoggerFactory.getLogger(Slf4jMain.class);
+ System.out.println(logger.getClass().getName());
+ logger.info("hello" + asList(args));
}
}
diff --git a/src/test/java/org/codehaus/mojo/exec/ThrowingMain.java b/src/test/java/org/codehaus/mojo/exec/ThrowingMain.java
index 04d91371..6e91f156 100644
--- a/src/test/java/org/codehaus/mojo/exec/ThrowingMain.java
+++ b/src/test/java/org/codehaus/mojo/exec/ThrowingMain.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.codehaus.mojo.exec;
import java.io.IOException;
@@ -23,12 +22,8 @@
*
* @author Lukasz Cwik
*/
-public class ThrowingMain
-{
- public static void main( String... args )
- throws Exception
- {
- throw new IOException( "expected IOException thrown by test" );
+public class ThrowingMain {
+ public static void main(String... args) throws Exception {
+ throw new IOException("expected IOException thrown by test");
}
}
-
diff --git a/src/test/java/org/codehaus/mojo/exec/URLClassLoaderBuilderTest.java b/src/test/java/org/codehaus/mojo/exec/URLClassLoaderBuilderTest.java
index ff0898b8..946c6c05 100644
--- a/src/test/java/org/codehaus/mojo/exec/URLClassLoaderBuilderTest.java
+++ b/src/test/java/org/codehaus/mojo/exec/URLClassLoaderBuilderTest.java
@@ -19,49 +19,43 @@
* under the License.
*/
-import org.junit.Test;
-
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
+import org.junit.Test;
+
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
/**
* Basic tests about the custom classloader we set to execute the project.
*/
-public class URLClassLoaderBuilderTest
-{
+public class URLClassLoaderBuilderTest {
@Test
- public void childFirst() throws Exception
- {
+ public void childFirst() throws Exception {
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
PrintStream originalStderr = System.err;
Thread thread = Thread.currentThread();
ClassLoader testLoader = thread.getContextClassLoader();
- try ( URLClassLoader loader = URLClassLoaderBuilder.builder()
- .setPaths( asList(
- Paths.get( "target/test-dependencies/slf4j-api.jar" ),
- Paths.get( "target/test-dependencies/slf4j-jdk14.jar" )
- ) )
- .build();
- PrintStream tmpStderr = new PrintStream( stderr ) )
- {
- System.setErr( tmpStderr );
- assertEquals( tmpStderr, System.err );
- thread.setContextClassLoader( loader );
- Class> lf = loader.loadClass( "org.slf4j.LoggerFactory" );
- Object logger = lf.getMethod( "getLogger", Class.class ).invoke( null, String.class );
- assertEquals( "org.slf4j.impl.JDK14LoggerAdapter", logger.getClass().getName() );
- }
- finally
- {
- thread.setContextClassLoader( testLoader );
+ try (URLClassLoader loader = URLClassLoaderBuilder.builder()
+ .setPaths(asList(
+ Paths.get("target/test-dependencies/slf4j-api.jar"),
+ Paths.get("target/test-dependencies/slf4j-jdk14.jar")))
+ .build();
+ PrintStream tmpStderr = new PrintStream(stderr)) {
+ System.setErr(tmpStderr);
+ assertEquals(tmpStderr, System.err);
+ thread.setContextClassLoader(loader);
+ Class> lf = loader.loadClass("org.slf4j.LoggerFactory");
+ Object logger = lf.getMethod("getLogger", Class.class).invoke(null, String.class);
+ assertEquals("org.slf4j.impl.JDK14LoggerAdapter", logger.getClass().getName());
+ } finally {
+ thread.setContextClassLoader(testLoader);
}
- assertEquals("", new String( stderr.toByteArray(), StandardCharsets.UTF_8 ) );
- System.setErr( originalStderr );
+ assertEquals("", new String(stderr.toByteArray(), StandardCharsets.UTF_8));
+ System.setErr(originalStderr);
}
}
diff --git a/src/test/java/org/codehaus/plexus/util/interpolation/Interpolator.java b/src/test/java/org/codehaus/plexus/util/interpolation/Interpolator.java
index 4f6c9d02..1c54fd73 100644
--- a/src/test/java/org/codehaus/plexus/util/interpolation/Interpolator.java
+++ b/src/test/java/org/codehaus/plexus/util/interpolation/Interpolator.java
@@ -3,12 +3,9 @@
/**
* COPIED FROM plexus-utils-1.5.15 TO SATISFY TESTS Interpolator interface. Based on existing RegexBasedInterpolator
* interface.
- *
+ *
* @author cstamas
* @deprecated Use plexus-interpolation APIs instead.
* @version $Id$
*/
-public interface Interpolator
- extends org.codehaus.plexus.interpolation.Interpolator
-{
-}
+public interface Interpolator extends org.codehaus.plexus.interpolation.Interpolator {}
diff --git a/src/test/java/org/codehaus/plexus/util/interpolation/RegexBasedInterpolator.java b/src/test/java/org/codehaus/plexus/util/interpolation/RegexBasedInterpolator.java
index 4622be30..4c151c8a 100644
--- a/src/test/java/org/codehaus/plexus/util/interpolation/RegexBasedInterpolator.java
+++ b/src/test/java/org/codehaus/plexus/util/interpolation/RegexBasedInterpolator.java
@@ -4,41 +4,33 @@
/**
* COPIED FROM plexus-utils-1.5.15 TO SATISFY TESTS
- *
+ *
* @version $Id$
* @deprecated Use plexus-interpolation APIs instead.
*/
-public class RegexBasedInterpolator
- extends org.codehaus.plexus.interpolation.RegexBasedInterpolator
- implements Interpolator
-{
- public RegexBasedInterpolator()
- {
+public class RegexBasedInterpolator extends org.codehaus.plexus.interpolation.RegexBasedInterpolator
+ implements Interpolator {
+ public RegexBasedInterpolator() {
super();
}
- public RegexBasedInterpolator( List valueSources )
- {
- super( valueSources );
+ public RegexBasedInterpolator(List valueSources) {
+ super(valueSources);
}
- public RegexBasedInterpolator( String startRegex, String endRegex, List valueSources )
- {
- super( startRegex, endRegex, valueSources );
+ public RegexBasedInterpolator(String startRegex, String endRegex, List valueSources) {
+ super(startRegex, endRegex, valueSources);
}
- public RegexBasedInterpolator( String startRegex, String endRegex )
- {
- super( startRegex, endRegex );
+ public RegexBasedInterpolator(String startRegex, String endRegex) {
+ super(startRegex, endRegex);
}
- public void addValueSource( ValueSource valueSource )
- {
- super.addValueSource( valueSource );
+ public void addValueSource(ValueSource valueSource) {
+ super.addValueSource(valueSource);
}
- public void removeValuesSource( ValueSource valueSource )
- {
- super.removeValuesSource( valueSource );
+ public void removeValuesSource(ValueSource valueSource) {
+ super.removeValuesSource(valueSource);
}
}
diff --git a/src/test/java/org/codehaus/plexus/util/interpolation/ValueSource.java b/src/test/java/org/codehaus/plexus/util/interpolation/ValueSource.java
index a68a2680..d7cf5e5e 100644
--- a/src/test/java/org/codehaus/plexus/util/interpolation/ValueSource.java
+++ b/src/test/java/org/codehaus/plexus/util/interpolation/ValueSource.java
@@ -2,13 +2,9 @@
/**
* COPIED FROM plexus-utils-1.5.15 TO SATISFY TESTS
- *
+ *
* @author jdcasey
* @deprecated Use plexus-interpolation APIs instead.
* @version $Id$
*/
-public interface ValueSource
- extends org.codehaus.plexus.interpolation.ValueSource
-{
-
-}
+public interface ValueSource extends org.codehaus.plexus.interpolation.ValueSource {}