Java7 here too...

This commit is contained in:
Kristian Rosenvold 2015-06-20 15:26:59 +02:00
parent 184f474c44
commit 248f1b4be5
93 changed files with 854 additions and 1037 deletions

View File

@ -1,17 +1,6 @@
package org.apache.maven.it; package org.apache.maven.it;
import java.io.File; import com.google.common.io.ByteStreams;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Collections;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.security.HashLoginService;
@ -25,13 +14,22 @@ import org.eclipse.jetty.util.security.Password;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
import com.google.common.io.ByteStreams; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Collections;
/** /**
* An HTTP server that handles all requests on a given port from a specified source, optionally secured using BASIC auth * An HTTP server that handles all requests on a given port from a specified source, optionally secured using BASIC auth
* by providing a username and password. The source can either be a URL or a directory. When a request is made the * by providing a username and password. The source can either be a URL or a directory. When a request is made the
* request is satisfied from the provided source. * request is satisfied from the provided source.
* *
* @author Jason van Zyl * @author Jason van Zyl
*/ */
public class HttpServer public class HttpServer
@ -89,7 +87,7 @@ public class HttpServer
if ( username != null && password != null ) if ( username != null && password != null )
{ {
HashLoginService loginService = new HashLoginService( "Test Server" ); HashLoginService loginService = new HashLoginService( "Test Server" );
loginService.putUser( username, new Password( password ), new String[] { "user" } ); loginService.putUser( username, new Password( password ), new String[]{ "user" } );
server.addBean( loginService ); server.addBean( loginService );
ConstraintSecurityHandler security = new ConstraintSecurityHandler(); ConstraintSecurityHandler security = new ConstraintSecurityHandler();
@ -98,7 +96,7 @@ public class HttpServer
Constraint constraint = new Constraint(); Constraint constraint = new Constraint();
constraint.setName( "auth" ); constraint.setName( "auth" );
constraint.setAuthenticate( true ); constraint.setAuthenticate( true );
constraint.setRoles( new String[] { "user", "admin" } ); constraint.setRoles( new String[]{ "user", "admin" } );
ConstraintMapping mapping = new ConstraintMapping(); ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec( "/*" ); mapping.setPathSpec( "/*" );
@ -184,7 +182,7 @@ public class HttpServer
} }
} }
public static interface StreamSource public interface StreamSource
{ {
InputStream stream( String path ) InputStream stream( String path )
throws IOException; throws IOException;
@ -204,13 +202,15 @@ public class HttpServer
@Override @Override
public void handle( String target, Request baseRequest, HttpServletRequest request, public void handle( String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response ) HttpServletResponse response )
throws IOException, ServletException throws IOException, ServletException
{ {
response.setContentType( "application/octet-stream" ); response.setContentType( "application/octet-stream" );
response.setStatus( HttpServletResponse.SC_OK ); response.setStatus( HttpServletResponse.SC_OK );
try(InputStream in = source.stream( target.substring( 1 ) ); OutputStream out = response.getOutputStream() ) { try ( InputStream in = source.stream(
ByteStreams.copy( in, out ); target.substring( 1 ) ); OutputStream out = response.getOutputStream() )
} {
ByteStreams.copy( in, out );
}
baseRequest.setHandled( true ); baseRequest.setHandled( true );
} }
} }
@ -219,11 +219,11 @@ public class HttpServer
throws Exception throws Exception
{ {
HttpServer server = HttpServer.builder() // HttpServer server = HttpServer.builder() //
.port( 0 ) // .port( 0 ) //
.username( "maven" ) // .username( "maven" ) //
.password( "secret" ) // .password( "secret" ) //
.source( new File( "/tmp/repo" ) ) // .source( new File( "/tmp/repo" ) ) //
.build(); .build();
server.start(); server.start();
} }
} }

View File

@ -35,9 +35,8 @@ class ItUtils
{ {
MessageDigest digester = MessageDigest.getInstance( algo ); MessageDigest digester = MessageDigest.getInstance( algo );
FileInputStream is = new FileInputStream( file );
DigestInputStream dis; DigestInputStream dis;
try try ( FileInputStream is = new FileInputStream( file ) )
{ {
dis = new DigestInputStream( is, digester ); dis = new DigestInputStream( is, digester );
@ -46,18 +45,14 @@ class ItUtils
// just read it // just read it
} }
} }
finally
{
is.close();
}
byte[] digest = digester.digest(); byte[] digest = digester.digest();
StringBuffer hash = new StringBuffer( digest.length * 2 ); StringBuilder hash = new StringBuilder( digest.length * 2 );
for ( int i = 0; i < digest.length; i++ ) for ( byte aDigest : digest )
{ {
int b = digest[i] & 0xFF; int b = aDigest & 0xFF;
if ( b < 0x10 ) if ( b < 0x10 )
{ {

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -45,7 +44,7 @@ public class MavenIT0090EnvVarInterpolationTest
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/it0090" ); File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/it0090" );
Verifier verifier = newVerifier( testDir.getAbsolutePath() ); Verifier verifier = newVerifier( testDir.getAbsolutePath() );
Map<String, String> envVars = new HashMap<String, String>(); Map<String, String> envVars = new HashMap<>();
envVars.put( "MAVEN_TEST_ENVAR", "MAVEN_TEST_ENVAR_VALUE" ); envVars.put( "MAVEN_TEST_ENVAR", "MAVEN_TEST_ENVAR_VALUE" );
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -28,7 +27,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -52,11 +50,11 @@ public class MavenIT0144LifecycleExecutionOrderTest
Verifier verifier = newVerifier( testDir.getAbsolutePath() ); Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.executeGoals( Arrays.asList( new String[] { "post-clean", "deploy", "site-deploy" } ) ); verifier.executeGoals( Arrays.asList( new String[]{ "post-clean", "deploy", "site-deploy" } ) );
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "pre-clean" ); expected.add( "pre-clean" );
expected.add( "clean" ); expected.add( "clean" );

View File

@ -19,20 +19,18 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-187">MNG-187</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-187">MNG-187</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng0187CollectedProjectsTest public class MavenITmng0187CollectedProjectsTest
@ -66,24 +64,24 @@ public class MavenITmng0187CollectedProjectsTest
props = verifier.loadProperties( "target/project.properties" ); props = verifier.loadProperties( "target/project.properties" );
assertEquals( "2", props.getProperty( "project.collectedProjects.size" ) ); assertEquals( "2", props.getProperty( "project.collectedProjects.size" ) );
assertEquals( Arrays.asList( new String[] { "sub-1", "sub-2" } ), getProjects( props ) ); assertEquals( Arrays.asList( new String[]{ "sub-1", "sub-2" } ), getProjects( props ) );
props = verifier.loadProperties( "sub-1/target/project.properties" ); props = verifier.loadProperties( "sub-1/target/project.properties" );
assertEquals( "1", props.getProperty( "project.collectedProjects.size" ) ); assertEquals( "1", props.getProperty( "project.collectedProjects.size" ) );
assertEquals( Arrays.asList( new String[] { "sub-2" } ), getProjects( props ) ); assertEquals( Arrays.asList( new String[]{ "sub-2" } ), getProjects( props ) );
props = verifier.loadProperties( "sub-1/sub-2/target/project.properties" ); props = verifier.loadProperties( "sub-1/sub-2/target/project.properties" );
assertEquals( "0", props.getProperty( "project.collectedProjects.size" ) ); assertEquals( "0", props.getProperty( "project.collectedProjects.size" ) );
assertEquals( Arrays.asList( new String[] {} ), getProjects( props ) ); assertEquals( Arrays.asList( new String[]{} ), getProjects( props ) );
} }
private List<String> getProjects( Properties props ) private List<String> getProjects( Properties props )
{ {
List<String> projects = new ArrayList<String>(); List<String> projects = new ArrayList<>();
for ( Iterator<?> it = props.keySet().iterator(); it.hasNext(); ) for ( Object o : props.keySet() )
{ {
String key = it.next().toString(); String key = o.toString();
if ( key.startsWith( "project.collectedProjects." ) && !key.endsWith( ".size" ) ) if ( key.startsWith( "project.collectedProjects." ) && !key.endsWith( ".size" ) )
{ {
projects.add( props.getProperty( key ) ); projects.add( props.getProperty( key ) );

View File

@ -19,14 +19,13 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-1021">MNG-1021</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-1021">MNG-1021</a>.
* *
* @author John Casey * @author John Casey
* @version $Id$ * @version $Id$
*/ */
@ -81,9 +80,9 @@ public class MavenITmng1021EqualAttachmentBuildNumberTest
private String getSnapshotVersion( File artifactDir ) private String getSnapshotVersion( File artifactDir )
{ {
File[] files = artifactDir.listFiles(); File[] files = artifactDir.listFiles();
for ( int i = 0; i < files.length; i++ ) for ( File file : files )
{ {
String name = files[i].getName(); String name = file.getName();
if ( name.endsWith( ".pom" ) ) if ( name.endsWith( ".pom" ) )
{ {
return name.substring( "test-".length(), name.length() - ".pom".length() ); return name.substring( "test-".length(), name.length() - ".pom".length() );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -27,7 +26,7 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-1803">MNG-1803</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-1803">MNG-1803</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng1803PomValidationErrorIncludesLineNumberTest public class MavenITmng1803PomValidationErrorIncludesLineNumberTest
@ -67,7 +66,7 @@ public class MavenITmng1803PomValidationErrorIncludesLineNumberTest
List<String> lines = verifier.loadLines( verifier.getLogFileName(), null ); List<String> lines = verifier.loadLines( verifier.getLogFileName(), null );
for ( String line : lines ) for ( String line : lines )
{ {
if ( line.indexOf( ":bad/id:" ) >= 0 ) if ( line.contains( ":bad/id:" ) )
{ {
assertTrue( "Line number not found in: " + line, line.indexOf( "38" ) > 0 ); assertTrue( "Line number not found in: " + line, line.indexOf( "38" ) > 0 );
assertTrue( "Column number not found in: " + line, line.indexOf( "19" ) > 0 ); assertTrue( "Column number not found in: " + line, line.indexOf( "19" ) > 0 );

View File

@ -19,14 +19,14 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils;
import java.io.File;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2362">MNG-2362</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2362">MNG-2362</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng2362DeployedPomEncodingTest public class MavenITmng2362DeployedPomEncodingTest
@ -92,8 +92,8 @@ public class MavenITmng2362DeployedPomEncodingTest
{ {
String prefix = "TEST-CHARS: "; String prefix = "TEST-CHARS: ";
int pos = pom.indexOf( prefix ); int pos = pom.indexOf( prefix );
assertTrue( "Corrupt data " + pom.substring( pos, pos + prefix.length() + chars.length() ) + " in " + pomFile, assertTrue( "Corrupt data " + pom.substring( pos, pos + prefix.length() + chars.length() ) + " in " + pomFile,
pom.indexOf( prefix + chars ) >= 0 ); pom.contains( prefix + chars ) );
} }
} }

View File

@ -19,8 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -29,11 +27,9 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2739">MNG-2739</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2739">MNG-2739</a>.
* *
* @todo Fill in a better description of what this test verifies!
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a> * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @author jdcasey * @author jdcasey
* * @todo Fill in a better description of what this test verifies!
*/ */
public class MavenITmng2739RequiredRepositoryElementsTest public class MavenITmng2739RequiredRepositoryElementsTest
extends AbstractMavenIntegrationTestCase extends AbstractMavenIntegrationTestCase
@ -57,8 +53,8 @@ public class MavenITmng2739RequiredRepositoryElementsTest
{ {
verifier.executeGoal( "validate" ); verifier.executeGoal( "validate" );
fail( "POM should NOT validate: repository <id/> element is missing in: " fail(
+ new File( testDir, "pom.xml" ) ); "POM should NOT validate: repository <id/> element is missing in: " + new File( testDir, "pom.xml" ) );
} }
catch ( VerificationException e ) catch ( VerificationException e )
{ {
@ -71,7 +67,7 @@ public class MavenITmng2739RequiredRepositoryElementsTest
boolean foundNpe = false; boolean foundNpe = false;
for ( String line : listing ) for ( String line : listing )
{ {
if ( line.indexOf( "NullPointerException" ) > -1 ) if ( line.contains( "NullPointerException" ) )
{ {
foundNpe = true; foundNpe = true;
break; break;
@ -97,8 +93,8 @@ public class MavenITmng2739RequiredRepositoryElementsTest
{ {
verifier.executeGoal( "validate" ); verifier.executeGoal( "validate" );
fail( "POM should NOT validate: repository <url/> element is missing in: " fail(
+ new File( testDir, "pom.xml" ) ); "POM should NOT validate: repository <url/> element is missing in: " + new File( testDir, "pom.xml" ) );
} }
catch ( VerificationException e ) catch ( VerificationException e )
{ {
@ -111,7 +107,7 @@ public class MavenITmng2739RequiredRepositoryElementsTest
boolean foundNpe = false; boolean foundNpe = false;
for ( String line : listing ) for ( String line : listing )
{ {
if ( line.indexOf( "NullPointerException" ) > -1 ) if ( line.contains( "NullPointerException" ) )
{ {
foundNpe = true; foundNpe = true;
break; break;

View File

@ -19,14 +19,14 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils;
import java.io.File;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2820">MNG-2820</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2820">MNG-2820</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng2820PomCommentsTest public class MavenITmng2820PomCommentsTest
@ -78,7 +78,7 @@ public class MavenITmng2820PomCommentsTest
private void assertPomComment( String pom, String comment ) private void assertPomComment( String pom, String comment )
throws Exception throws Exception
{ {
assertTrue( "Missing comment: " + comment, pom.indexOf( comment ) >= 0 ); assertTrue( "Missing comment: " + comment, pom.contains( comment ) );
} }
} }

View File

@ -19,8 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -32,7 +30,6 @@ import java.util.List;
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2883">MNG-2883</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2883">MNG-2883</a>.
* *
* @author <a href="mailto:brianf@apache.org">Brian Fox</a> * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
*
*/ */
public class MavenITmng2883LegacyRepoOfflineTest public class MavenITmng2883LegacyRepoOfflineTest
extends AbstractMavenIntegrationTestCase extends AbstractMavenIntegrationTestCase
@ -56,7 +53,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng2883" ); verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
verifier.newDefaultFilterProperties() ); verifier.newDefaultFilterProperties() );
// used to inject the remote repository // used to inject the remote repository
@ -72,7 +69,8 @@ public class MavenITmng2883LegacyRepoOfflineTest
} }
catch ( VerificationException e ) catch ( VerificationException e )
{ {
throw new VerificationException( "Build should succeed the first time through when NOT in offline mode!", e ); throw new VerificationException( "Build should succeed the first time through when NOT in offline mode!",
e );
} }
// the centerpiece of these tests! // the centerpiece of these tests!
@ -97,7 +95,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
// expected // expected
} }
List<String> missingMessages = new ArrayList<String>(); List<String> missingMessages = new ArrayList<>();
missingMessages.add( " is offline" ); missingMessages.add( " is offline" );
missingMessages.add( "org.apache.maven.its.mng2883:parent:pom:1.0-SNAPSHOT" ); missingMessages.add( "org.apache.maven.its.mng2883:parent:pom:1.0-SNAPSHOT" );
@ -109,7 +107,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
{ {
String message = messageIt.next(); String message = messageIt.next();
if ( line.indexOf( message ) > -1 ) if ( line.contains( message ) )
{ {
messageIt.remove(); messageIt.remove();
} }
@ -118,7 +116,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
if ( !missingMessages.isEmpty() ) if ( !missingMessages.isEmpty() )
{ {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
buffer.append( "The following key messages were missing from build output:\n\n" ); buffer.append( "The following key messages were missing from build output:\n\n" );
@ -148,7 +146,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng2883" ); verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
verifier.newDefaultFilterProperties() ); verifier.newDefaultFilterProperties() );
// used to inject the remote repository // used to inject the remote repository
@ -164,7 +162,8 @@ public class MavenITmng2883LegacyRepoOfflineTest
} }
catch ( VerificationException e ) catch ( VerificationException e )
{ {
throw new VerificationException( "Build should succeed the first time through when NOT in offline mode!", e ); throw new VerificationException( "Build should succeed the first time through when NOT in offline mode!",
e );
} }
// the centerpiece of these tests! // the centerpiece of these tests!
@ -189,7 +188,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
// expected // expected
} }
List<String> missingMessages = new ArrayList<String>(); List<String> missingMessages = new ArrayList<>();
// FIXME: We need a more prominent diagnosis including system being in offline mode for 2.0.x. // FIXME: We need a more prominent diagnosis including system being in offline mode for 2.0.x.
missingMessages.add( "offline mode." ); missingMessages.add( "offline mode." );
@ -203,7 +202,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
{ {
String message = (String) messageIt.next(); String message = (String) messageIt.next();
if ( line.indexOf( message ) > -1 ) if ( line.contains( message ) )
{ {
messageIt.remove(); messageIt.remove();
} }
@ -212,7 +211,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
if ( !missingMessages.isEmpty() ) if ( !missingMessages.isEmpty() )
{ {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
buffer.append( "The following key messages were missing from build output:\n\n" ); buffer.append( "The following key messages were missing from build output:\n\n" );
@ -242,7 +241,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng2883" ); verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
verifier.newDefaultFilterProperties() ); verifier.newDefaultFilterProperties() );
// used to inject the remote repository // used to inject the remote repository
@ -274,7 +273,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
// expected // expected
} }
List<String> missingMessages = new ArrayList<String>(); List<String> missingMessages = new ArrayList<>();
missingMessages.add( " is offline" ); missingMessages.add( " is offline" );
missingMessages.add( "org.apache.maven.its.mng2883:plugin" ); missingMessages.add( "org.apache.maven.its.mng2883:plugin" );
@ -286,7 +285,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
{ {
String message = messageIt.next(); String message = messageIt.next();
if ( line.indexOf( message ) > -1 ) if ( line.contains( message ) )
{ {
messageIt.remove(); messageIt.remove();
} }
@ -295,7 +294,7 @@ public class MavenITmng2883LegacyRepoOfflineTest
if ( !missingMessages.isEmpty() ) if ( !missingMessages.isEmpty() )
{ {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
buffer.append( "The following key messages were missing from build output:\n\n" ); buffer.append( "The following key messages were missing from build output:\n\n" );

View File

@ -19,8 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -28,7 +26,7 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3220">MNG-3220</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3220">MNG-3220</a>.
* *
* @version $Id$ * @version $Id$
*/ */
public class MavenITmng3220ImportScopeTest public class MavenITmng3220ImportScopeTest
@ -50,7 +48,8 @@ public class MavenITmng3220ImportScopeTest
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng3220" ); verifier.deleteArtifacts( "org.apache.maven.its.mng3220" );
verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() ); verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
verifier.newDefaultFilterProperties() );
verifier.addCliOption( "--settings" ); verifier.addCliOption( "--settings" );
verifier.addCliOption( "settings.xml" ); verifier.addCliOption( "settings.xml" );
verifier.executeGoal( "validate" ); verifier.executeGoal( "validate" );
@ -69,7 +68,8 @@ public class MavenITmng3220ImportScopeTest
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng3220" ); verifier.deleteArtifacts( "org.apache.maven.its.mng3220" );
verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() ); verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
verifier.newDefaultFilterProperties() );
verifier.addCliOption( "--settings" ); verifier.addCliOption( "--settings" );
verifier.addCliOption( "settings.xml" ); verifier.addCliOption( "settings.xml" );
@ -91,8 +91,8 @@ public class MavenITmng3220ImportScopeTest
boolean found = false; boolean found = false;
for ( String line : lines ) for ( String line : lines )
{ {
if ( line.indexOf( "\'dependencies.dependency.version\' is missing for junit:junit" ) > -1 if ( line.contains( "\'dependencies.dependency.version\' is missing for junit:junit" ) || line.contains(
|| line.indexOf( "\'dependencies.dependency.version\' for junit:junit:jar is missing" ) > -1 ) "\'dependencies.dependency.version\' for junit:junit:jar is missing" ) )
{ {
found = true; found = true;
break; break;

View File

@ -19,15 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils;
import org.mortbay.jetty.Handler; import org.mortbay.jetty.Handler;
@ -35,9 +26,17 @@ import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler; import org.mortbay.jetty.handler.AbstractHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3415">MNG-3415</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3415">MNG-3415</a>.
* *
* @version $Id$ * @version $Id$
*/ */
public class MavenITmng3415JunkRepositoryMetadataTest public class MavenITmng3415JunkRepositoryMetadataTest
@ -56,25 +55,25 @@ public class MavenITmng3415JunkRepositoryMetadataTest
/** /**
* This test simply verifies that when a metadata transfer fails (network error, etc.) * This test simply verifies that when a metadata transfer fails (network error, etc.)
* no metadata file is written to the local repository. * no metadata file is written to the local repository.
* * <p/>
* Steps executed to verify this test: * Steps executed to verify this test:
* * <p/>
* 0. Find the local repository directory: * 0. Find the local repository directory:
* a. build the maven-find-local-repo-plugin, then run it, to spit out the path of the * a. build the maven-find-local-repo-plugin, then run it, to spit out the path of the
* local repository in use by default. Read the output file to get this path. * local repository in use by default. Read the output file to get this path.
* (Yes, it's heavy, but it's reliable.) * (Yes, it's heavy, but it's reliable.)
* 1. Setup the test: * 1. Setup the test:
* a. Make sure the metadata for the test-repo is NOT in the local repository. * a. Make sure the metadata for the test-repo is NOT in the local repository.
* b. Make sure the dependency POM IS in the local repository, so we're not * b. Make sure the dependency POM IS in the local repository, so we're not
* distracted by failed builds that are unrelated. * distracted by failed builds that are unrelated.
* c. Create the settings file for use in this test, which contains the invalid * c. Create the settings file for use in this test, which contains the invalid
* remote repository entry. * remote repository entry.
* 2. Build the test project the first time * 2. Build the test project the first time
* a. Verify that a TransferFailedException is in the build output for the test-repo * a. Verify that a TransferFailedException is in the build output for the test-repo
* b. Verify that the metadata for the dependency POM is NOT in the local * b. Verify that the metadata for the dependency POM is NOT in the local
* repository afterwards. * repository afterwards.
* 3. Build the test project the second time * 3. Build the test project the second time
* a. See (2.a) and (2.b) above; the same criteria applies here. * a. See (2.a) and (2.b) above; the same criteria applies here.
*/ */
public void testitTransferFailed() public void testitTransferFailed()
throws Exception throws Exception
@ -126,25 +125,25 @@ public class MavenITmng3415JunkRepositoryMetadataTest
/** /**
* This test simply verifies that when metadata doesn't exist on the remote * This test simply verifies that when metadata doesn't exist on the remote
* repository, a basic metadata file is written to the local repository. * repository, a basic metadata file is written to the local repository.
* * <p/>
* Steps executed to verify this test: * Steps executed to verify this test:
* * <p/>
* 0. Find the local repository directory: * 0. Find the local repository directory:
* a. build the maven-find-local-repo-plugin, then run it, to spit out the path of the * a. build the maven-find-local-repo-plugin, then run it, to spit out the path of the
* local repository in use by default. Read the output file to get this path. * local repository in use by default. Read the output file to get this path.
* (Yes, it's heavy, but it's reliable.) * (Yes, it's heavy, but it's reliable.)
* 1. Setup the test: * 1. Setup the test:
* a. Make sure the metadata for the test-repo is NOT in the local repository. * a. Make sure the metadata for the test-repo is NOT in the local repository.
* b. Make sure the dependency POM IS in the local repository, so we're not * b. Make sure the dependency POM IS in the local repository, so we're not
* distracted by failed builds that are unrelated. * distracted by failed builds that are unrelated.
* c. Create the settings file for use in this test, which contains the VALID * c. Create the settings file for use in this test, which contains the VALID
* remote repository entry. * remote repository entry.
* 2. Build the test project the first time * 2. Build the test project the first time
* a. Verify that the remote repository is checked for the metadata file * a. Verify that the remote repository is checked for the metadata file
* 3. Build the test project the second time * 3. Build the test project the second time
* a. Verify that the remote repository is NOT checked for the metadata file again * a. Verify that the remote repository is NOT checked for the metadata file again
* b. Verify that the file used for updateInterval calculations was NOT changed from * b. Verify that the file used for updateInterval calculations was NOT changed from
* the first build. * the first build.
*/ */
public void testShouldNotRepeatedlyUpdateOnResourceNotFoundException() public void testShouldNotRepeatedlyUpdateOnResourceNotFoundException()
throws Exception throws Exception
@ -159,7 +158,7 @@ public class MavenITmng3415JunkRepositoryMetadataTest
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.deleteArtifacts( "org.apache.maven.its.mng3415" ); verifier.deleteArtifacts( "org.apache.maven.its.mng3415" );
final List<String> requestUris = new ArrayList<String>(); final List<String> requestUris = new ArrayList<>();
Handler repoHandler = new AbstractHandler() Handler repoHandler = new AbstractHandler()
{ {
@ -199,8 +198,8 @@ public class MavenITmng3415JunkRepositoryMetadataTest
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
assertTrue( requestUris.toString(), assertTrue( requestUris.toString(), requestUris.contains(
requestUris.contains( "/org/apache/maven/its/mng3415/missing/1.0-SNAPSHOT/maven-metadata.xml" ) ); "/org/apache/maven/its/mng3415/missing/1.0-SNAPSHOT/maven-metadata.xml" ) );
requestUris.clear(); requestUris.clear();
@ -215,10 +214,13 @@ public class MavenITmng3415JunkRepositoryMetadataTest
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
assertFalse( requestUris.toString(), assertFalse( requestUris.toString(), requestUris.contains(
requestUris.contains( "/org/apache/maven/its/mng3415/missing/1.0-SNAPSHOT/maven-metadata.xml" ) ); "/org/apache/maven/its/mng3415/missing/1.0-SNAPSHOT/maven-metadata.xml" ) );
assertEquals( "Last-modified time should be unchanged from first build through second build for the file we use for updateInterval checks.", firstLastMod, updateCheckFile.lastModified() ); assertEquals(
"Last-modified time should be unchanged from first build through second build for the file we use for"
+ " updateInterval checks.",
firstLastMod, updateCheckFile.lastModified() );
} }
finally finally
{ {
@ -231,8 +233,8 @@ public class MavenITmng3415JunkRepositoryMetadataTest
{ {
File metadata = getMetadataFile( verifier ); File metadata = getMetadataFile( verifier );
assertFalse( "Metadata file should NOT be present in local repository: " assertFalse( "Metadata file should NOT be present in local repository: " + metadata.getAbsolutePath(),
+ metadata.getAbsolutePath(), metadata.exists() ); metadata.exists() );
} }
private void setupDummyDependency( Verifier verifier, File testDir, boolean resetUpdateInterval ) private void setupDummyDependency( Verifier verifier, File testDir, boolean resetUpdateInterval )

View File

@ -19,19 +19,19 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3441">MNG-3441</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3441">MNG-3441</a>.
* *
* @version $Id$ * @version $Id$
*/ */
public class MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest public class MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest
@ -45,8 +45,7 @@ public class MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest
public void testitMNG3441() public void testitMNG3441()
throws Exception throws Exception
{ {
File testDir = File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3441" );
ResourceExtractor.simpleExtractResources( getClass(), "/mng-3441" );
File targetRepository = new File( testDir, "target-repo" ); File targetRepository = new File( testDir, "target-repo" );
FileUtils.deleteDirectory( targetRepository ); FileUtils.deleteDirectory( targetRepository );
@ -63,7 +62,8 @@ public class MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
Xpp3Dom dom = readDom( new File( targetRepository, Xpp3Dom dom = readDom( new File( targetRepository,
"org/apache/maven/its/mng3441/test-artifact/1.0-SNAPSHOT/maven-metadata.xml" ) ); "org/apache/maven/its/mng3441/test-artifact/1.0-SNAPSHOT/maven-metadata.xml"
) );
assertEquals( "2", dom.getChild( "versioning" ).getChild( "snapshot" ).getChild( "buildNumber" ).getValue() ); assertEquals( "2", dom.getChild( "versioning" ).getChild( "snapshot" ).getChild( "buildNumber" ).getValue() );
dom = readDom( new File( targetRepository, "org/apache/maven/its/mng3441/maven-metadata.xml" ) ); dom = readDom( new File( targetRepository, "org/apache/maven/its/mng3441/maven-metadata.xml" ) );
@ -77,14 +77,9 @@ public class MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest
private Xpp3Dom readDom( File file ) private Xpp3Dom readDom( File file )
throws XmlPullParserException, IOException throws XmlPullParserException, IOException
{ {
FileReader reader = new FileReader( file ); try ( FileReader reader = new FileReader( file ) )
try
{ {
return Xpp3DomBuilder.build( reader ); return Xpp3DomBuilder.build( reader );
} }
finally
{
reader.close();
}
} }
} }

View File

@ -19,19 +19,18 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3710">MNG-3710</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3710">MNG-3710</a>.
* *
* @todo Fill in a better description of what this test verifies!
* @author <a href="mailto:brianf@apache.org">Brian Fox</a> * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @author jdcasey * @author jdcasey
* @todo Fill in a better description of what this test verifies!
*/ */
public class MavenITmng3710PollutedClonedPluginsTest public class MavenITmng3710PollutedClonedPluginsTest
extends AbstractMavenIntegrationTestCase extends AbstractMavenIntegrationTestCase
@ -44,8 +43,7 @@ public class MavenITmng3710PollutedClonedPluginsTest
public void testitMNG3710_POMInheritance() public void testitMNG3710_POMInheritance()
throws Exception throws Exception
{ {
File testDir = File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3710/pom-inheritance" );
ResourceExtractor.simpleExtractResources( getClass(), "/mng-3710/pom-inheritance" );
File pluginDir = new File( testDir, "maven-mng3710-pomInheritance-plugin" ); File pluginDir = new File( testDir, "maven-mng3710-pomInheritance-plugin" );
File projectsDir = new File( testDir, "projects" ); File projectsDir = new File( testDir, "projects" );
@ -77,8 +75,7 @@ public class MavenITmng3710PollutedClonedPluginsTest
public void testitMNG3710_OriginalModel() public void testitMNG3710_OriginalModel()
throws Exception throws Exception
{ {
File testDir = File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3710/original-model" );
ResourceExtractor.simpleExtractResources( getClass(), "/mng-3710/original-model" );
File pluginsDir = new File( testDir, "plugins" ); File pluginsDir = new File( testDir, "plugins" );
File projectDir = new File( testDir, "project" ); File projectDir = new File( testDir, "project" );
@ -91,11 +88,11 @@ public class MavenITmng3710PollutedClonedPluginsTest
verifier.resetStreams(); verifier.resetStreams();
verifier = newVerifier( projectDir.getAbsolutePath() ); verifier = newVerifier( projectDir.getAbsolutePath() );
List<String> goals = new ArrayList<String>(); List<String> goals = new ArrayList<>();
goals.add( "org.apache.maven.its.mng3710:mavenit-mng3710-directInvoke-plugin:1:run" ); goals.add( "org.apache.maven.its.mng3710:mavenit-mng3710-directInvoke-plugin:1:run" );
goals.add( "validate" ); goals.add( "validate" );
verifier.executeGoals( goals ); verifier.executeGoals( goals );
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();

View File

@ -19,16 +19,16 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.maven.it.util.ResourceExtractor;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3719">MNG-3719</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3719">MNG-3719</a>.
* *
* @author Brett Porter * @author Brett Porter
* @version $Id$ * @version $Id$
*/ */
@ -63,11 +63,11 @@ public class MavenITmng3719PomExecutionOrderingTest
for ( int i = 0; i < content.size(); i++ ) for ( int i = 0; i < content.size(); i++ )
{ {
String line = (String) content.get( i ); String line = (String) content.get( i );
Matcher m = pattern.matcher( line ); Matcher m = pattern.matcher( line );
if ( m.matches() ) if ( m.matches() )
{ {
int step = Integer.valueOf( m.group( 1 ) ).intValue(); int step = Integer.valueOf( m.group( 1 ) );
stepLines[step - 1] = i + 1; stepLines[step - 1] = i + 1;
} }
} }

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -31,7 +30,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3732">MNG-3732</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3732">MNG-3732</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -63,7 +62,7 @@ public class MavenITmng3732ActiveProfilesTest
verifier.resetStreams(); verifier.resetStreams();
Properties props = verifier.loadProperties( "target/profile.properties" ); Properties props = verifier.loadProperties( "target/profile.properties" );
List<String> ids = new ArrayList<String>(); List<String> ids = new ArrayList<>();
// support for profiles.xml removed from 3.x (see MNG-4060) // support for profiles.xml removed from 3.x (see MNG-4060)
if ( matchesVersionRange( "[2.0,3.0-alpha-1)" ) ) if ( matchesVersionRange( "[2.0,3.0-alpha-1)" ) )
@ -75,7 +74,7 @@ public class MavenITmng3732ActiveProfilesTest
ids.remove( "it-defaults" ); ids.remove( "it-defaults" );
Collections.sort( ids ); Collections.sort( ids );
assertEquals( Arrays.asList( new String[] { "pom", "profiles", "settings" } ), ids ); assertEquals( Arrays.asList( new String[]{ "pom", "profiles", "settings" } ), ids );
assertEquals( "4", props.getProperty( "project.activeProfiles" ) ); assertEquals( "4", props.getProperty( "project.activeProfiles" ) );
assertEquals( "PASSED-1", props.getProperty( "project.properties.pomProperty" ) ); assertEquals( "PASSED-1", props.getProperty( "project.properties.pomProperty" ) );
@ -90,9 +89,9 @@ public class MavenITmng3732ActiveProfilesTest
ids.remove( "it-defaults" ); ids.remove( "it-defaults" );
Collections.sort( ids ); Collections.sort( ids );
assertEquals( Arrays.asList( new String[] { "pom", "settings" } ), ids ); assertEquals( Arrays.asList( new String[]{ "pom", "settings" } ), ids );
assertEquals( "3", props.getProperty( "project.activeProfiles" ) ); assertEquals( "3", props.getProperty( "project.activeProfiles" ) );
assertEquals( "PASSED-1", props.getProperty( "project.properties.pomProperty" ) ); assertEquals( "PASSED-1", props.getProperty( "project.properties.pomProperty" ) );
assertEquals( "PASSED-2", props.getProperty( "project.properties.settingsProperty" ) ); assertEquals( "PASSED-2", props.getProperty( "project.properties.settingsProperty" ) );
} }

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -27,7 +26,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3807">MNG-3807</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3807">MNG-3807</a>.
* *
* @version $Id$ * @version $Id$
*/ */
public class MavenITmng3807PluginConfigExpressionEvaluationTest public class MavenITmng3807PluginConfigExpressionEvaluationTest
@ -73,7 +72,7 @@ public class MavenITmng3807PluginConfigExpressionEvaluationTest
{ {
assertNotNull( value ); assertNotNull( value );
assertTrue( value.length() > 0 ); assertTrue( value.length() > 0 );
assertTrue( value, value.indexOf( "${" ) < 0 ); assertTrue( value, !value.contains( "${" ) );
} }
} }

View File

@ -19,18 +19,16 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.TreeSet; import java.util.TreeSet;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3843">MNG-3843</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3843">MNG-3843</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -100,7 +98,8 @@ public class MavenITmng3843PomInheritanceTest
assertEquals( "1", props.getProperty( "project.build.resources" ) ); assertEquals( "1", props.getProperty( "project.build.resources" ) );
assertPathEquals( basedir, "src/main/resources", props.getProperty( "project.build.resources.0.directory" ) ); assertPathEquals( basedir, "src/main/resources", props.getProperty( "project.build.resources.0.directory" ) );
assertEquals( "1", props.getProperty( "project.build.testResources" ) ); assertEquals( "1", props.getProperty( "project.build.testResources" ) );
assertPathEquals( basedir, "src/test/resources", props.getProperty( "project.build.testResources.0.directory" ) ); assertPathEquals( basedir, "src/test/resources",
props.getProperty( "project.build.testResources.0.directory" ) );
assertPathEquals( basedir, "target", props.getProperty( "project.build.directory" ) ); assertPathEquals( basedir, "target", props.getProperty( "project.build.directory" ) );
assertPathEquals( basedir, "target/classes", props.getProperty( "project.build.outputDirectory" ) ); assertPathEquals( basedir, "target/classes", props.getProperty( "project.build.outputDirectory" ) );
assertPathEquals( basedir, "target/test-classes", props.getProperty( "project.build.testOutputDirectory" ) ); assertPathEquals( basedir, "target/test-classes", props.getProperty( "project.build.testOutputDirectory" ) );
@ -147,9 +146,11 @@ public class MavenITmng3843PomInheritanceTest
assertEquals( "http://parent.url/ci", props.getProperty( "project.ciManagement.url" ) ); assertEquals( "http://parent.url/ci", props.getProperty( "project.ciManagement.url" ) );
assertEquals( "http://parent.url/issues", props.getProperty( "project.issueManagement.url" ) ); assertEquals( "http://parent.url/issues", props.getProperty( "project.issueManagement.url" ) );
assertEquals( "http://parent.url/dist", props.getProperty( "project.distributionManagement.repository.url" ) ); assertEquals( "http://parent.url/dist", props.getProperty( "project.distributionManagement.repository.url" ) );
assertEquals( "http://parent.url/snaps", props.getProperty( "project.distributionManagement.snapshotRepository.url" ) ); assertEquals( "http://parent.url/snaps",
props.getProperty( "project.distributionManagement.snapshotRepository.url" ) );
assertUrlCommon( "http://parent.url/site", props.getProperty( "project.distributionManagement.site.url" ) ); assertUrlCommon( "http://parent.url/site", props.getProperty( "project.distributionManagement.site.url" ) );
assertUrlCommon( "http://parent.url/download", props.getProperty( "project.distributionManagement.downloadUrl" ) ); assertUrlCommon( "http://parent.url/download",
props.getProperty( "project.distributionManagement.downloadUrl" ) );
if ( matchesVersionRange( "(2.0.2,)" ) ) if ( matchesVersionRange( "(2.0.2,)" ) )
{ {
assertMissing( props, "project.distributionManagement.relocation." ); assertMissing( props, "project.distributionManagement.relocation." );
@ -214,9 +215,11 @@ public class MavenITmng3843PomInheritanceTest
assertEquals( "http://child.url/ci", props.getProperty( "project.ciManagement.url" ) ); assertEquals( "http://child.url/ci", props.getProperty( "project.ciManagement.url" ) );
assertEquals( "http://child.url/issues", props.getProperty( "project.issueManagement.url" ) ); assertEquals( "http://child.url/issues", props.getProperty( "project.issueManagement.url" ) );
assertEquals( "http://child.url/dist", props.getProperty( "project.distributionManagement.repository.url" ) ); assertEquals( "http://child.url/dist", props.getProperty( "project.distributionManagement.repository.url" ) );
assertEquals( "http://child.url/snaps", props.getProperty( "project.distributionManagement.snapshotRepository.url" ) ); assertEquals( "http://child.url/snaps",
props.getProperty( "project.distributionManagement.snapshotRepository.url" ) );
assertUrlCommon( "http://child.url/site", props.getProperty( "project.distributionManagement.site.url" ) ); assertUrlCommon( "http://child.url/site", props.getProperty( "project.distributionManagement.site.url" ) );
assertUrlCommon( "http://child.url/download", props.getProperty( "project.distributionManagement.downloadUrl" ) ); assertUrlCommon( "http://child.url/download",
props.getProperty( "project.distributionManagement.downloadUrl" ) );
assertEquals( "child-reloc-msg", props.getProperty( "project.distributionManagement.relocation.message" ) ); assertEquals( "child-reloc-msg", props.getProperty( "project.distributionManagement.relocation.message" ) );
assertMissing( props, "project.profiles." ); assertMissing( props, "project.profiles." );
assertEquals( "coreit", props.getProperty( "project.build.finalName" ) ); assertEquals( "coreit", props.getProperty( "project.build.finalName" ) );
@ -239,22 +242,22 @@ public class MavenITmng3843PomInheritanceTest
assertEquals( "1", props.getProperty( "project.build.plugins" ) ); assertEquals( "1", props.getProperty( "project.build.plugins" ) );
} }
assertEquals( "4", props.getProperty( "project.dependencies" ) ); assertEquals( "4", props.getProperty( "project.dependencies" ) );
Collection<String> actualDeps = new TreeSet<String>(); Collection<String> actualDeps = new TreeSet<>();
actualDeps.add( props.getProperty( "project.dependencies.0.artifactId" ) ); actualDeps.add( props.getProperty( "project.dependencies.0.artifactId" ) );
actualDeps.add( props.getProperty( "project.dependencies.1.artifactId" ) ); actualDeps.add( props.getProperty( "project.dependencies.1.artifactId" ) );
actualDeps.add( props.getProperty( "project.dependencies.2.artifactId" ) ); actualDeps.add( props.getProperty( "project.dependencies.2.artifactId" ) );
actualDeps.add( props.getProperty( "project.dependencies.3.artifactId" ) ); actualDeps.add( props.getProperty( "project.dependencies.3.artifactId" ) );
Collection<String> expectedDeps = new TreeSet<String>(); Collection<String> expectedDeps = new TreeSet<>();
expectedDeps.add( "parent-dep-b" ); expectedDeps.add( "parent-dep-b" );
expectedDeps.add( "child-dep-b" ); expectedDeps.add( "child-dep-b" );
expectedDeps.add( "child-dep-c" ); expectedDeps.add( "child-dep-c" );
expectedDeps.add( "child-dep-d" ); expectedDeps.add( "child-dep-d" );
assertEquals( expectedDeps, actualDeps ); assertEquals( expectedDeps, actualDeps );
assertEquals( "2", props.getProperty( "project.dependencyManagement.dependencies" ) ); assertEquals( "2", props.getProperty( "project.dependencyManagement.dependencies" ) );
Collection<String> actualMngtDeps = new TreeSet<String>(); Collection<String> actualMngtDeps = new TreeSet<>();
actualMngtDeps.add( props.getProperty( "project.dependencyManagement.dependencies.0.artifactId" ) ); actualMngtDeps.add( props.getProperty( "project.dependencyManagement.dependencies.0.artifactId" ) );
actualMngtDeps.add( props.getProperty( "project.dependencyManagement.dependencies.1.artifactId" ) ); actualMngtDeps.add( props.getProperty( "project.dependencyManagement.dependencies.1.artifactId" ) );
Collection<String> expectedMngtDeps = new TreeSet<String>(); Collection<String> expectedMngtDeps = new TreeSet<>();
expectedMngtDeps.add( "parent-dep-a" ); expectedMngtDeps.add( "parent-dep-a" );
expectedMngtDeps.add( "child-dep-a" ); expectedMngtDeps.add( "child-dep-a" );
assertEquals( expectedMngtDeps, actualMngtDeps ); assertEquals( expectedMngtDeps, actualMngtDeps );
@ -286,9 +289,9 @@ public class MavenITmng3843PomInheritanceTest
private void assertMissing( Properties props, String prefix ) private void assertMissing( Properties props, String prefix )
{ {
for ( Iterator<?> it = props.keySet().iterator(); it.hasNext(); ) for ( Object o : props.keySet() )
{ {
String key = it.next().toString(); String key = o.toString();
assertFalse( "Found unexpected key: " + key, key.startsWith( prefix ) ); assertFalse( "Found unexpected key: " + key, key.startsWith( prefix ) );
} }
} }

View File

@ -19,17 +19,17 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.Os;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.Os;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3940">MNG-3940</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3940">MNG-3940</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -51,7 +51,7 @@ public class MavenITmng3940EnvVarInterpolationTest
{ {
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3940" ); File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3940" );
Map<String, String> envVars = new HashMap<String, String>(); Map<String, String> envVars = new HashMap<>();
/* /*
* NOTE: The POM is using MAVEN_MNG_3940 to reference the var (just as one would refer to PATH). On Windows, * NOTE: The POM is using MAVEN_MNG_3940 to reference the var (just as one would refer to PATH). On Windows,
* this must resolve case-insensitively so we use different character casing for the variable here. * this must resolve case-insensitively so we use different character casing for the variable here.
@ -64,7 +64,7 @@ public class MavenITmng3940EnvVarInterpolationTest
{ {
envVars.put( "MAVEN_MNG_3940", "PASSED" ); envVars.put( "MAVEN_MNG_3940", "PASSED" );
} }
Verifier verifier = newVerifier( testDir.getAbsolutePath() ); Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.deleteDirectory( "target" ); verifier.deleteDirectory( "target" );

View File

@ -19,12 +19,12 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.it.util.ResourceExtractor;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4091">MNG-4091</a>: * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4091">MNG-4091</a>:
* Bad plugin descriptor error handling * Bad plugin descriptor error handling
@ -61,7 +61,6 @@ public class MavenITmng4091BadPluginDescriptorTest
verifier.resetStreams(); verifier.resetStreams();
} }
List<String> logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false ); List<String> logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
String msg = "Plugin's descriptor contains the wrong version: 2.0-SNAPSHOT"; String msg = "Plugin's descriptor contains the wrong version: 2.0-SNAPSHOT";
@ -69,7 +68,7 @@ public class MavenITmng4091BadPluginDescriptorTest
boolean foundMessage = false; boolean foundMessage = false;
for ( String line : logFile ) for ( String line : logFile )
{ {
if ( line.indexOf( msg ) > -1 ) if ( line.contains( msg ) )
{ {
foundMessage = true; foundMessage = true;
break; break;

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -29,7 +28,7 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4180">MNG-4180</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4180">MNG-4180</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4180PerDependencyExclusionsTest public class MavenITmng4180PerDependencyExclusionsTest
@ -64,7 +63,7 @@ public class MavenITmng4180PerDependencyExclusionsTest
List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" ); List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" );
Collections.sort( artifacts ); Collections.sort( artifacts );
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "org.apache.maven.its.mng4180:a:jar:0.1" ); expected.add( "org.apache.maven.its.mng4180:a:jar:0.1" );
expected.add( "org.apache.maven.its.mng4180:b:jar:0.1" ); expected.add( "org.apache.maven.its.mng4180:b:jar:0.1" );
expected.add( "org.apache.maven.its.mng4180:c:jar:0.1" ); expected.add( "org.apache.maven.its.mng4180:c:jar:0.1" );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -30,7 +29,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4190">MNG-4190</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4190">MNG-4190</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4190MirrorRepoMergingTest public class MavenITmng4190MirrorRepoMergingTest
@ -66,7 +65,7 @@ public class MavenITmng4190MirrorRepoMergingTest
List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" ); List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" );
Collections.sort( artifacts ); Collections.sort( artifacts );
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "org.apache.maven.its.mng4190:a:jar:0.1" ); expected.add( "org.apache.maven.its.mng4190:a:jar:0.1" );
expected.add( "org.apache.maven.its.mng4190:b:jar:0.1-SNAPSHOT" ); expected.add( "org.apache.maven.its.mng4190:b:jar:0.1-SNAPSHOT" );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -29,7 +28,7 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4203">MNG-4203</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4203">MNG-4203</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4203TransitiveDependencyExclusionTest public class MavenITmng4203TransitiveDependencyExclusionTest
@ -63,7 +62,7 @@ public class MavenITmng4203TransitiveDependencyExclusionTest
List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" ); List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" );
Collections.sort( artifacts ); Collections.sort( artifacts );
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "org.apache.maven.its.mng4203:b:jar:0.1" ); expected.add( "org.apache.maven.its.mng4203:b:jar:0.1" );
expected.add( "org.apache.maven.its.mng4203:c:jar:0.1" ); expected.add( "org.apache.maven.its.mng4203:c:jar:0.1" );

View File

@ -175,7 +175,7 @@ public class MavenITmng4235HttpAuthDeploymentChecksumsTest
public static class RepoHandler public static class RepoHandler
extends ResourceHandler extends ResourceHandler
{ {
List<DeployedResource> deployedResources = new ArrayList<DeployedResource>(); List<DeployedResource> deployedResources = new ArrayList<>();
public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch ) public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
throws IOException, ServletException throws IOException, ServletException
@ -193,18 +193,12 @@ public class MavenITmng4235HttpAuthDeploymentChecksumsTest
dir.mkdirs(); dir.mkdirs();
} }
OutputStream os = resource.getOutputStream();
request.getContentLength(); request.getContentLength();
try try ( OutputStream os = resource.getOutputStream() )
{ {
IO.copy( request.getInputStream(), os ); IO.copy( request.getInputStream(), os );
} }
finally
{
os.close();
}
DeployedResource deployedResource = new DeployedResource(); DeployedResource deployedResource = new DeployedResource();

View File

@ -56,29 +56,30 @@ public class MavenITmng4275RelocationWarningTest
verifier.executeGoal( "validate" ); verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
List<String> lines = verifier.loadFile( new File( testDir, verifier.getLogFileName() ), false ); List<String> lines = verifier.loadFile( new File( testDir, verifier.getLogFileName() ), false );
boolean foundWarning = false; boolean foundWarning = false;
for ( String line : lines ) for ( String line : lines )
{ {
if ( foundWarning ) if ( foundWarning )
{ {
assertTrue( assertTrue( "Relocation target should have been logged right after warning.", line.contains(
"Relocation target should have been logged right after warning.", "This artifact has been relocated to org.apache.maven.its.mng4275:relocated:1" ) );
line.indexOf( "This artifact has been relocated to org.apache.maven.its.mng4275:relocated:1" ) > -1 );
break; break;
} }
else if ( line.startsWith( "[WARNING] While downloading org.apache.maven.its.mng4275:relocation:1" ) ) else if ( line.startsWith( "[WARNING] While downloading org.apache.maven.its.mng4275:relocation:1" ) )
{ {
foundWarning = true; foundWarning = true;
} }
else if ( line.matches( "\\[WARNING\\].* org.apache.maven.its.mng4275:relocation:jar:1 .* org.apache.maven.its.mng4275:relocated:jar:1.*" ) ) else if ( line.matches(
"\\[WARNING\\].* org.apache.maven.its.mng4275:relocation:jar:1 .* org.apache.maven.its"
+ ".mng4275:relocated:jar:1.*" ) )
{ {
foundWarning = true; foundWarning = true;
break; break;
} }
} }
assertTrue( "Relocation warning should haven been logged.", foundWarning ); assertTrue( "Relocation warning should haven been logged.", foundWarning );
} }

View File

@ -19,9 +19,15 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -30,18 +36,9 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4326">MNG-4326</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4326">MNG-4326</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest public class MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest
@ -71,7 +68,7 @@ public class MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
final List<String> uris = new ArrayList<String>(); final List<String> uris = new ArrayList<>();
Handler repoHandler = new AbstractHandler() Handler repoHandler = new AbstractHandler()
{ {
@ -82,8 +79,8 @@ public class MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest
String uri = request.getRequestURI(); String uri = request.getRequestURI();
if ( uri.startsWith( "/repo/org/apache/maven/its/mng4326" ) if ( uri.startsWith( "/repo/org/apache/maven/its/mng4326" ) && !uri.endsWith( ".md5" ) && !uri.endsWith(
&& !uri.endsWith( ".md5" ) && !uri.endsWith( ".sha1" ) ) ".sha1" ) )
{ {
uris.add( uri.substring( 34 ) ); uris.add( uri.substring( 34 ) );
} }

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -27,7 +26,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4353">MNG-4353</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4353">MNG-4353</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4353PluginDependencyResolutionFromPomRepoTest public class MavenITmng4353PluginDependencyResolutionFromPomRepoTest
@ -53,15 +52,17 @@ public class MavenITmng4353PluginDependencyResolutionFromPomRepoTest
verifier.deleteArtifacts( "org.apache.maven.its.mng4353" ); verifier.deleteArtifacts( "org.apache.maven.its.mng4353" );
Properties filterProps = verifier.newDefaultFilterProperties(); Properties filterProps = verifier.newDefaultFilterProperties();
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps ); verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
verifier.filterFile( "repo-1/org/apache/maven/its/mng4353/maven-mng4353-plugin/0.1/template.pom", verifier.filterFile( "repo-1/org/apache/maven/its/mng4353/maven-mng4353-plugin/0.1/template.pom",
"repo-1/org/apache/maven/its/mng4353/maven-mng4353-plugin/0.1/maven-mng4353-plugin-0.1.pom", "UTF-8", filterProps ); "repo-1/org/apache/maven/its/mng4353/maven-mng4353-plugin/0.1/maven-mng4353-plugin-0.1"
+ ".pom",
"UTF-8", filterProps );
verifier.addCliOption( "--settings" ); verifier.addCliOption( "--settings" );
verifier.addCliOption( "settings.xml" ); verifier.addCliOption( "settings.xml" );
verifier.executeGoal( "validate" ); verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
Properties props = verifier.loadProperties( "target/touch.properties" );; Properties props = verifier.loadProperties( "target/touch.properties" );
assertEquals( "passed", props.getProperty( "test" ) ); assertEquals( "passed", props.getProperty( "test" ) );
} }

View File

@ -19,14 +19,14 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils;
import java.io.File;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4368">MNG-4368</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4368">MNG-4368</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4368TimestampAwareArtifactInstallerTest public class MavenITmng4368TimestampAwareArtifactInstallerTest
@ -63,11 +63,12 @@ public class MavenITmng4368TimestampAwareArtifactInstallerTest
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
File installedPom = new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "pom" ) ); File installedPom =
new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "pom" ) );
String pom = FileUtils.fileRead( installedPom, "UTF-8" ); String pom = FileUtils.fileRead( installedPom, "UTF-8" );
assertTrue( pom.indexOf( "Branch-A" ) > 0 ); assertTrue( pom.indexOf( "Branch-A" ) > 0 );
assertTrue( pom.indexOf( "Branch-B" ) < 0 ); assertTrue( !pom.contains( "Branch-B" ) );
assertEquals( aPom.length(), bPom.length() ); assertEquals( aPom.length(), bPom.length() );
assertTrue( aPom.lastModified() > bPom.lastModified() ); assertTrue( aPom.lastModified() > bPom.lastModified() );
@ -81,7 +82,7 @@ public class MavenITmng4368TimestampAwareArtifactInstallerTest
verifier.resetStreams(); verifier.resetStreams();
pom = FileUtils.fileRead( installedPom, "UTF-8" ); pom = FileUtils.fileRead( installedPom, "UTF-8" );
assertTrue( pom.indexOf( "Branch-A" ) < 0 ); assertTrue( !pom.contains( "Branch-A" ) );
assertTrue( pom.indexOf( "Branch-B" ) > 0 ); assertTrue( pom.indexOf( "Branch-B" ) > 0 );
} }
@ -114,11 +115,12 @@ public class MavenITmng4368TimestampAwareArtifactInstallerTest
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
verifier.resetStreams(); verifier.resetStreams();
File installedArtifact = new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "jar" ) ); File installedArtifact =
new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "jar" ) );
String data = FileUtils.fileRead( installedArtifact, "UTF-8" ); String data = FileUtils.fileRead( installedArtifact, "UTF-8" );
assertTrue( data.indexOf( "Branch-A" ) > 0 ); assertTrue( data.indexOf( "Branch-A" ) > 0 );
assertTrue( data.indexOf( "Branch-B" ) < 0 ); assertTrue( !data.contains( "Branch-B" ) );
assertEquals( aArtifact.length(), bArtifact.length() ); assertEquals( aArtifact.length(), bArtifact.length() );
assertTrue( aArtifact.lastModified() > bArtifact.lastModified() ); assertTrue( aArtifact.lastModified() > bArtifact.lastModified() );
@ -132,7 +134,7 @@ public class MavenITmng4368TimestampAwareArtifactInstallerTest
verifier.resetStreams(); verifier.resetStreams();
data = FileUtils.fileRead( installedArtifact, "UTF-8" ); data = FileUtils.fileRead( installedArtifact, "UTF-8" );
assertTrue( data.indexOf( "Branch-A" ) < 0 ); assertTrue( !data.contains( "Branch-A" ) );
assertTrue( data.indexOf( "Branch-B" ) > 0 ); assertTrue( data.indexOf( "Branch-B" ) > 0 );
long lastModified = installedArtifact.lastModified(); long lastModified = installedArtifact.lastModified();
@ -148,7 +150,7 @@ public class MavenITmng4368TimestampAwareArtifactInstallerTest
verifier.resetStreams(); verifier.resetStreams();
data = FileUtils.fileRead( installedArtifact, "UTF-8" ); data = FileUtils.fileRead( installedArtifact, "UTF-8" );
assertTrue( data.indexOf( "Branch-B" ) < 0 ); assertTrue( !data.contains( "Branch-B" ) );
assertTrue( data.indexOf( "Branch-C" ) > 0 ); assertTrue( data.indexOf( "Branch-C" ) > 0 );
} }

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -29,7 +28,7 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4403">MNG-4403</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4403">MNG-4403</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4403LenientDependencyPomParsingTest public class MavenITmng4403LenientDependencyPomParsingTest
@ -65,7 +64,7 @@ public class MavenITmng4403LenientDependencyPomParsingTest
List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" ); List<String> artifacts = verifier.loadLines( "target/artifacts.txt", "UTF-8" );
Collections.sort( artifacts ); Collections.sort( artifacts );
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "org.apache.maven.its.mng4403:a:jar:0.1" ); expected.add( "org.apache.maven.its.mng4403:a:jar:0.1" );
expected.add( "org.apache.maven.its.mng4403:b:jar:0.1" ); expected.add( "org.apache.maven.its.mng4403:b:jar:0.1" );
expected.add( "org.apache.maven.its.mng4403:c:jar:0.1" ); expected.add( "org.apache.maven.its.mng4403:c:jar:0.1" );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -29,7 +28,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4415">MNG-4415</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4415">MNG-4415</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4415InheritedPluginOrderTest public class MavenITmng4415InheritedPluginOrderTest
@ -62,7 +61,7 @@ public class MavenITmng4415InheritedPluginOrderTest
Properties props = verifier.loadProperties( "target/it.properties" ); Properties props = verifier.loadProperties( "target/it.properties" );
assertNotNull( props.getProperty( "project.build.plugins" ) ); assertNotNull( props.getProperty( "project.build.plugins" ) );
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "maven-it-plugin-error" ); expected.add( "maven-it-plugin-error" );
expected.add( "maven-it-plugin-configuration" ); expected.add( "maven-it-plugin-configuration" );
expected.add( "maven-it-plugin-dependency-resolution" ); expected.add( "maven-it-plugin-dependency-resolution" );
@ -72,7 +71,7 @@ public class MavenITmng4415InheritedPluginOrderTest
expected.add( "maven-it-plugin-fork" ); expected.add( "maven-it-plugin-fork" );
expected.add( "maven-it-plugin-touch" ); expected.add( "maven-it-plugin-touch" );
List<String> actual = new ArrayList<String>(); List<String> actual = new ArrayList<>();
int count = Integer.parseInt( props.getProperty( "project.build.plugins" ) ); int count = Integer.parseInt( props.getProperty( "project.build.plugins" ) );
for ( int i = 0; i < count; i++ ) for ( int i = 0; i < count; i++ )

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -29,7 +28,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4416">MNG-4416</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4416">MNG-4416</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4416PluginOrderAfterProfileInjectionTest public class MavenITmng4416PluginOrderAfterProfileInjectionTest
@ -62,7 +61,7 @@ public class MavenITmng4416PluginOrderAfterProfileInjectionTest
Properties props = verifier.loadProperties( "target/it.properties" ); Properties props = verifier.loadProperties( "target/it.properties" );
assertNotNull( props.getProperty( "project.build.plugins" ) ); assertNotNull( props.getProperty( "project.build.plugins" ) );
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<>();
expected.add( "maven-it-plugin-error" ); expected.add( "maven-it-plugin-error" );
expected.add( "maven-it-plugin-configuration" ); expected.add( "maven-it-plugin-configuration" );
expected.add( "maven-it-plugin-dependency-resolution" ); expected.add( "maven-it-plugin-dependency-resolution" );
@ -72,7 +71,7 @@ public class MavenITmng4416PluginOrderAfterProfileInjectionTest
expected.add( "maven-it-plugin-fork" ); expected.add( "maven-it-plugin-fork" );
expected.add( "maven-it-plugin-touch" ); expected.add( "maven-it-plugin-touch" );
List<String> actual = new ArrayList<String>(); List<String> actual = new ArrayList<>();
int count = Integer.parseInt( props.getProperty( "project.build.plugins" ) ); int count = Integer.parseInt( props.getProperty( "project.build.plugins" ) );
for ( int i = 0; i < count; i++ ) for ( int i = 0; i < count; i++ )

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -28,7 +27,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4421">MNG-4421</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4421">MNG-4421</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4421DeprecatedPomInterpolationExpressionsTest public class MavenITmng4421DeprecatedPomInterpolationExpressionsTest
@ -60,19 +59,19 @@ public class MavenITmng4421DeprecatedPomInterpolationExpressionsTest
assertEquals( "0.1", props.getProperty( "project.properties.property2" ) ); assertEquals( "0.1", props.getProperty( "project.properties.property2" ) );
List<String> lines = verifier.loadLines( "log.txt", null ); List<String> lines = verifier.loadLines( "log.txt", null );
boolean warnedPomPrefix = false; boolean warnedPomPrefix = false;
boolean warnedEmptyPrefix = false; boolean warnedEmptyPrefix = false;
for ( String line : lines ) for ( String line : lines )
{ {
if ( line.startsWith( "[WARN" ) ) if ( line.startsWith( "[WARN" ) )
{ {
if ( line.indexOf( "${pom.version}" ) >= 0 ) if ( line.contains( "${pom.version}" ) )
{ {
warnedPomPrefix = true; warnedPomPrefix = true;
} }
if ( line.indexOf( "${version}" ) >= 0 ) if ( line.contains( "${version}" ) )
{ {
warnedEmptyPrefix = true; warnedEmptyPrefix = true;
} }

View File

@ -19,17 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.it.utils.DeployedResource; import org.apache.maven.it.utils.DeployedResource;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
@ -44,9 +33,18 @@ import org.mortbay.jetty.security.ConstraintMapping;
import org.mortbay.jetty.security.HashUserRealm; import org.mortbay.jetty.security.HashUserRealm;
import org.mortbay.jetty.security.SecurityHandler; import org.mortbay.jetty.security.SecurityHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4470">MNG-4470</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4470">MNG-4470</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -60,7 +58,7 @@ public class MavenITmng4470AuthenticatedDeploymentToProxyTest
private volatile boolean deployed; private volatile boolean deployed;
List<DeployedResource> deployedResources = new ArrayList<DeployedResource>(); List<DeployedResource> deployedResources = new ArrayList<>();
public MavenITmng4470AuthenticatedDeploymentToProxyTest() public MavenITmng4470AuthenticatedDeploymentToProxyTest()
{ {
@ -138,7 +136,7 @@ public class MavenITmng4470AuthenticatedDeploymentToProxyTest
Constraint constraint = new Constraint(); Constraint constraint = new Constraint();
constraint.setName( Constraint.__BASIC_AUTH ); constraint.setName( Constraint.__BASIC_AUTH );
constraint.setRoles( new String[] { "deployer" } ); constraint.setRoles( new String[]{ "deployer" } );
constraint.setAuthenticate( true ); constraint.setAuthenticate( true );
ConstraintMapping constraintMapping = new ConstraintMapping(); ConstraintMapping constraintMapping = new ConstraintMapping();
@ -151,7 +149,7 @@ public class MavenITmng4470AuthenticatedDeploymentToProxyTest
SecurityHandler securityHandler = new SecurityHandler(); SecurityHandler securityHandler = new SecurityHandler();
securityHandler.setUserRealm( userRealm ); securityHandler.setUserRealm( userRealm );
securityHandler.setConstraintMappings( new ConstraintMapping[] { constraintMapping } ); securityHandler.setConstraintMappings( new ConstraintMapping[]{ constraintMapping } );
HandlerList handlerList = new HandlerList(); HandlerList handlerList = new HandlerList();
handlerList.addHandler( proxyHandler ); handlerList.addHandler( proxyHandler );
@ -201,14 +199,14 @@ public class MavenITmng4470AuthenticatedDeploymentToProxyTest
throws Exception throws Exception
{ {
deployedResources = new ArrayList<DeployedResource>(); deployedResources = new ArrayList<>();
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4470/" + project ); File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4470/" + project );
Verifier verifier = newVerifier( testDir.getAbsolutePath() ); Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8",
Collections.singletonMap( "@port@", Integer.toString( port ) ) ); Collections.singletonMap( "@port@", Integer.toString( port ) ) );
verifier.addCliOption( "--settings" ); verifier.addCliOption( "--settings" );
verifier.addCliOption( "settings.xml" ); verifier.addCliOption( "settings.xml" );
verifier.executeGoal( "validate" ); verifier.executeGoal( "validate" );

View File

@ -19,26 +19,23 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4555">MNG-4555</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4555">MNG-4555</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4555MetaversionResolutionOfflineTest public class MavenITmng4555MetaversionResolutionOfflineTest
@ -58,7 +55,7 @@ public class MavenITmng4555MetaversionResolutionOfflineTest
{ {
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4555" ); File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4555" );
final List<String> uris = new ArrayList<String>(); final List<String> uris = new ArrayList<>();
Handler repoHandler = new AbstractHandler() Handler repoHandler = new AbstractHandler()
{ {

View File

@ -19,18 +19,16 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4666">MNG-4666</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4666">MNG-4666</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4666CoreRealmImportTest public class MavenITmng4666CoreRealmImportTest
@ -97,10 +95,10 @@ public class MavenITmng4666CoreRealmImportTest
private List<String> getTypes( Properties props ) private List<String> getTypes( Properties props )
{ {
List<String> types = new ArrayList<String>(); List<String> types = new ArrayList<>();
for ( Iterator<?> it = props.keySet().iterator(); it.hasNext(); ) for ( Object o : props.keySet() )
{ {
String key = it.next().toString(); String key = o.toString();
if ( key.startsWith( "core." ) ) if ( key.startsWith( "core." ) )
{ {
String type = key.substring( 5 ); String type = key.substring( 5 );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -28,7 +27,7 @@ import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4696">MNG-4696</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4696">MNG-4696</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4696MavenProjectDependencyArtifactsTest public class MavenITmng4696MavenProjectDependencyArtifactsTest
@ -63,7 +62,7 @@ public class MavenITmng4696MavenProjectDependencyArtifactsTest
Properties props = verifier.loadProperties( "target/artifact.properties" ); Properties props = verifier.loadProperties( "target/artifact.properties" );
assertEquals( "3", props.getProperty( "project.dependencyArtifacts.size" ) ); assertEquals( "3", props.getProperty( "project.dependencyArtifacts.size" ) );
HashSet<String> ids = new HashSet<String>(); HashSet<String> ids = new HashSet<>();
ids.add( props.getProperty( "project.dependencyArtifacts.0.artifactId" ) ); ids.add( props.getProperty( "project.dependencyArtifacts.0.artifactId" ) );
ids.add( props.getProperty( "project.dependencyArtifacts.1.artifactId" ) ); ids.add( props.getProperty( "project.dependencyArtifacts.1.artifactId" ) );
ids.add( props.getProperty( "project.dependencyArtifacts.2.artifactId" ) ); ids.add( props.getProperty( "project.dependencyArtifacts.2.artifactId" ) );

View File

@ -19,15 +19,15 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import java.util.Properties;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.io.FileUtils;
import java.io.File;
import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4745">MNG-4745</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4745">MNG-4745</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4745PluginVersionUpdateTest public class MavenITmng4745PluginVersionUpdateTest
@ -142,7 +142,7 @@ public class MavenITmng4745PluginVersionUpdateTest
private static void writeMetadata( File testdir, String version, String timestamp ) private static void writeMetadata( File testdir, String version, String timestamp )
throws Exception throws Exception
{ {
StringBuffer content = new StringBuffer( 1024 ); StringBuilder content = new StringBuilder( 1024 );
content.append( "<?xml version=\"1.0\"?>\n" ); content.append( "<?xml version=\"1.0\"?>\n" );
content.append( "<metadata>\n" ); content.append( "<metadata>\n" );
content.append( " <groupId>org.apache.maven.its.mng4745</groupId>\n" ); content.append( " <groupId>org.apache.maven.its.mng4745</groupId>\n" );

View File

@ -19,7 +19,6 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
@ -28,7 +27,7 @@ import java.util.List;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4814">MNG-4814</a>. * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4814">MNG-4814</a>.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class MavenITmng4814ReResolutionOfDependenciesDuringReactorTest public class MavenITmng4814ReResolutionOfDependenciesDuringReactorTest
@ -57,7 +56,7 @@ public class MavenITmng4814ReResolutionOfDependenciesDuringReactorTest
verifier.addCliOption( "-s" ); verifier.addCliOption( "-s" );
verifier.addCliOption( "settings.xml" ); verifier.addCliOption( "settings.xml" );
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() ); verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
List<String> goals = new ArrayList<String>(); List<String> goals = new ArrayList<>();
goals.add( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:aggregate-test" ); goals.add( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:aggregate-test" );
goals.add( "validate" ); goals.add( "validate" );
verifier.executeGoals( goals ); verifier.executeGoals( goals );

View File

@ -1,11 +1,10 @@
package org.apache.maven.it; package org.apache.maven.it;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File;
import java.util.List;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -26,22 +25,23 @@ import org.apache.maven.it.util.ResourceExtractor;
*/ */
public class MavenITmng5214DontMapWsdlToJar extends AbstractMavenIntegrationTestCase public class MavenITmng5214DontMapWsdlToJar
extends AbstractMavenIntegrationTestCase
{ {
public MavenITmng5214DontMapWsdlToJar() public MavenITmng5214DontMapWsdlToJar()
{ {
super( "[3.1,)" ); super( "[3.1,)" );
} }
/** /**
* Test that the code that allows test-jar and ejb-client dependencies to resolve to the * Test that the code that allows test-jar and ejb-client dependencies to resolve to the
* target/classes or target/test-class is *not* applies to other types, e.g. wsdl. * target/classes or target/test-class is *not* applies to other types, e.g. wsdl.
*/ */
public void testitTestPhase() public void testitTestPhase()
throws Exception throws Exception
{ {
File setupDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5214/dependency" ); File setupDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5214/dependency" );
Verifier setupVerifier = newVerifier( setupDir.getAbsolutePath() ); Verifier setupVerifier = newVerifier( setupDir.getAbsolutePath() );
setupVerifier.setAutoclean( false ); setupVerifier.setAutoclean( false );
setupVerifier.setMavenDebug( true ); setupVerifier.setMavenDebug( true );
@ -52,7 +52,7 @@ public class MavenITmng5214DontMapWsdlToJar extends AbstractMavenIntegrationTest
setupVerifier.executeGoal( "generate-resources" ); setupVerifier.executeGoal( "generate-resources" );
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5214" ); File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5214" );
Verifier verifier = newVerifier( testDir.getAbsolutePath() ); Verifier verifier = newVerifier( testDir.getAbsolutePath() );
verifier.setAutoclean( false ); verifier.setAutoclean( false );
verifier.deleteDirectory( "consumer/target" ); verifier.deleteDirectory( "consumer/target" );
@ -61,12 +61,11 @@ public class MavenITmng5214DontMapWsdlToJar extends AbstractMavenIntegrationTest
verifier.executeGoal( "test" ); verifier.executeGoal( "test" );
verifier.verifyErrorFreeLog(); verifier.verifyErrorFreeLog();
List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false ); List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
Iterator<String> lineIt = lines.iterator(); // RESOLVE-ONE-DEPENDENCY org.apache.maven.its.mng5214:dependency:wsdl:1.0-SNAPSHOT $ /tmp/it
// RESOLVE-ONE-DEPENDENCY org.apache.maven.its.mng5214:dependency:wsdl:1.0-SNAPSHOT $ /tmp/it.repo/org/apache/maven/its/mng5214/dependency/1.0-SNAPSHOT/dependency-1.0-SNAPSHOT.wsdl // .repo/org/apache/maven/its/mng5214/dependency/1.0-SNAPSHOT/dependency-1.0-SNAPSHOT.wsdl
while ( lineIt.hasNext() ) for ( String line : lines )
{ {
String line = (String) lineIt.next(); if ( line.contains( "RESOLVE-ONE-DEPENDENCY org.apache.maven.its.mng5214:dependency:wsdl:1.0-SNAPSHOT" ) )
if ( line.contains( "RESOLVE-ONE-DEPENDENCY org.apache.maven.its.mng5214:dependency:wsdl:1.0-SNAPSHOT" ) )
{ {
assertFalse( line.contains( "classes-main" ) ); assertFalse( line.contains( "classes-main" ) );
assertTrue( line.endsWith( ".wsdl" ) ); assertTrue( line.endsWith( ".wsdl" ) );

View File

@ -99,7 +99,7 @@ public class MavenITmng5224InjectedSettings
</profiles> </profiles>
**/ **/
List<String> profileIds = new ArrayList<String>( 4 ); List<String> profileIds = new ArrayList<>( 4 );
for ( Xpp3Dom node : profileNodes ) for ( Xpp3Dom node : profileNodes )
{ {
@ -149,7 +149,7 @@ public class MavenITmng5224InjectedSettings
assertEquals( 1, activeProfilesNode.getChildCount() ); assertEquals( 1, activeProfilesNode.getChildCount() );
} }
List<String> activeProfiles = new ArrayList<String>( 2 ); List<String> activeProfiles = new ArrayList<>( 2 );
for ( Xpp3Dom node : activeProfilesNode.getChildren() ) for ( Xpp3Dom node : activeProfilesNode.getChildren() )
{ {

View File

@ -19,12 +19,11 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import java.io.File;
import java.util.List;
import java.util.Properties;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File;
import java.util.Properties;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5452">MNG-5452</a> * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5452">MNG-5452</a>
* Make sure that the maven.build.timestamp is in UTC. * Make sure that the maven.build.timestamp is in UTC.

View File

@ -19,13 +19,12 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.maven.it.util.ResourceExtractor;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5608">MNG-5608</a>: * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5608">MNG-5608</a>:
* Profile activation warning test when file specification contains <code>${project.basedir}</code> * Profile activation warning test when file specification contains <code>${project.basedir}</code>
@ -63,12 +62,13 @@ public class MavenITmng5608ProfileActivationWarningTest
private void assertFileExists( File dir, String filename ) private void assertFileExists( File dir, String filename )
{ {
File file = new File( dir, filename ); File file = new File( dir, filename );
assertTrue( "expected file: " + file , file.exists() ); assertTrue( "expected file: " + file, file.exists() );
} }
private String findWarning( List<String> logLines, String profileId ) private String findWarning( List<String> logLines, String profileId )
{ {
Pattern pattern = Pattern.compile( "(?i).*Failed to interpolate file location ..project.basedir./pom.xml for profile " + profileId + ": .*" ); Pattern pattern = Pattern.compile(
"(?i).*Failed to interpolate file location ..project.basedir./pom.xml for profile " + profileId + ": .*" );
for ( String logLine : logLines ) for ( String logLine : logLines )
{ {

View File

@ -22,9 +22,6 @@ package org.apache.maven.it;
import org.apache.maven.it.util.ResourceExtractor; import org.apache.maven.it.util.ResourceExtractor;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
/** /**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5639">MNG-5639</a>: * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-5639">MNG-5639</a>:
@ -60,5 +57,4 @@ public class MavenITmng5639ImportScopePomResolutionTest
} }
} }

View File

@ -30,7 +30,7 @@ import java.util.regex.Pattern;
/** /**
* A simple HTTP proxy that only understands the CONNECT method to check HTTPS tunneling. * A simple HTTP proxy that only understands the CONNECT method to check HTTPS tunneling.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class TunnelingProxyServer public class TunnelingProxyServer
@ -166,7 +166,7 @@ public class TunnelingProxyServer
private String readLine( PushbackInputStream is ) private String readLine( PushbackInputStream is )
throws IOException throws IOException
{ {
StringBuffer buffer = new StringBuffer( 1024 ); StringBuilder buffer = new StringBuilder( 1024 );
while ( true ) while ( true )
{ {
@ -217,7 +217,7 @@ public class TunnelingProxyServer
{ {
try try
{ {
for ( byte[] buffer = new byte[1024 * 8];; ) for ( byte[] buffer = new byte[1024 * 8]; ; )
{ {
int n = is.read( buffer ); int n = is.read( buffer );
if ( n < 0 ) if ( n < 0 )

View File

@ -25,7 +25,7 @@ import java.io.IOException;
import java.util.Properties; import java.util.Properties;
/** /**
* *
*/ */
public class DefaultStatefulSingleton public class DefaultStatefulSingleton
implements StatefulSingleton implements StatefulSingleton
@ -48,15 +48,10 @@ public class DefaultStatefulSingleton
{ {
propertiesFile.getParentFile().mkdirs(); propertiesFile.getParentFile().mkdirs();
FileOutputStream os = new FileOutputStream( propertiesFile ); try ( FileOutputStream os = new FileOutputStream( propertiesFile ) )
try
{ {
properties.store( os, "MAVEN-CORE-IT" ); properties.store( os, "MAVEN-CORE-IT" );
} }
finally
{
os.close();
}
} }
} }

View File

@ -26,7 +26,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -34,11 +33,10 @@ import java.util.Vector;
/** /**
* Checks the thread-safe retrieval of components from active component collections. * Checks the thread-safe retrieval of components from active component collections.
* *
* @author Benjamin Bentmann
* @goal check-thread-safety * @goal check-thread-safety
* @phase validate * @phase validate
*
* @author Benjamin Bentmann
*/ */
public class CheckThreadSafetyMojo public class CheckThreadSafetyMojo
extends AbstractMojo extends AbstractMojo
@ -46,7 +44,7 @@ public class CheckThreadSafetyMojo
/** /**
* Project base directory used for manual path alignment. * Project base directory used for manual path alignment.
* *
* @parameter default-value="${basedir}" * @parameter default-value="${basedir}"
* @readonly * @readonly
*/ */
@ -54,28 +52,28 @@ public class CheckThreadSafetyMojo
/** /**
* The available components, as a map. * The available components, as a map.
* *
* @component role="org.apache.maven.plugin.coreit.Component" * @component role="org.apache.maven.plugin.coreit.Component"
*/ */
private Map componentMap; private Map componentMap;
/** /**
* The available components, as a list. * The available components, as a list.
* *
* @component role="org.apache.maven.plugin.coreit.Component" * @component role="org.apache.maven.plugin.coreit.Component"
*/ */
private List componentList; private List componentList;
/** /**
* The path to the properties file to create. * The path to the properties file to create.
* *
* @parameter property="collections.outputFile" * @parameter property="collections.outputFile"
*/ */
private File outputFile; private File outputFile;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the output file could not be created. * @throws MojoFailureException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -114,13 +112,13 @@ public class CheckThreadSafetyMojo
{ {
try try
{ {
for ( Iterator it = map.values().iterator(); it.hasNext(); ) for ( Object o : map.values() )
{ {
it.next().toString(); o.toString();
} }
for ( Iterator it = list.iterator(); it.hasNext(); ) for ( Object aList : list )
{ {
it.next().toString(); aList.toString();
} }
} }
catch ( Exception e ) catch ( Exception e )
@ -135,15 +133,15 @@ public class CheckThreadSafetyMojo
} }
go.add( null ); go.add( null );
for ( int i = 0; i < threads.length; i++ ) for ( Thread thread : threads )
{ {
try try
{ {
threads[i].join(); thread.join();
} }
catch ( InterruptedException e ) catch ( InterruptedException e )
{ {
getLog().warn( "[MAVEN-CORE-IT-LOG] Interrupted while joining " + threads[i] ); getLog().warn( "[MAVEN-CORE-IT-LOG] Interrupted while joining " + thread );
} }
} }

View File

@ -27,18 +27,16 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
* Dumps the role hints of the available repository layouts to a properties file. * Dumps the role hints of the available repository layouts to a properties file.
* *
* @author Benjamin Bentmann
* @goal dump-repo-layouts * @goal dump-repo-layouts
* @phase validate * @phase validate
*
* @author Benjamin Bentmann
*/ */
public class DumpRepoLayoutsMojo public class DumpRepoLayoutsMojo
extends AbstractMojo extends AbstractMojo
@ -46,7 +44,7 @@ public class DumpRepoLayoutsMojo
/** /**
* Project base directory used for manual path alignment. * Project base directory used for manual path alignment.
* *
* @parameter default-value="${basedir}" * @parameter default-value="${basedir}"
* @readonly * @readonly
*/ */
@ -54,28 +52,28 @@ public class DumpRepoLayoutsMojo
/** /**
* The available repository layouts, as a map. * The available repository layouts, as a map.
* *
* @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
*/ */
private Map repositoryLayouts; private Map repositoryLayouts;
/** /**
* The available repository layouts, as a list. * The available repository layouts, as a list.
* *
* @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" * @component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
*/ */
private List repoLayouts; private List repoLayouts;
/** /**
* The path to the properties file used to dump the repository layouts. * The path to the properties file used to dump the repository layouts.
* *
* @parameter property="collections.layoutsFile" * @parameter property="collections.layoutsFile"
*/ */
private File layoutsFile; private File layoutsFile;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the output file could not be created. * @throws MojoFailureException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -87,9 +85,9 @@ public class DumpRepoLayoutsMojo
layoutProperties.setProperty( "layouts", Integer.toString( repositoryLayouts.size() ) ); layoutProperties.setProperty( "layouts", Integer.toString( repositoryLayouts.size() ) );
for ( Iterator it = repositoryLayouts.keySet().iterator(); it.hasNext(); ) for ( Object o : repositoryLayouts.keySet() )
{ {
String roleHint = (String) it.next(); String roleHint = (String) o;
Object repoLayout = repositoryLayouts.get( roleHint ); Object repoLayout = repositoryLayouts.get( roleHint );
if ( repoLayout != null ) if ( repoLayout != null )
{ {

View File

@ -36,11 +36,10 @@ import java.util.Set;
/** /**
* Collects user-specified artifacts. This mimics in part the Maven Assembly Plugin. * Collects user-specified artifacts. This mimics in part the Maven Assembly Plugin.
* *
* @goal collect
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal collect
*/ */
public class CollectMojo public class CollectMojo
extends AbstractMojo extends AbstractMojo
@ -48,7 +47,7 @@ public class CollectMojo
/** /**
* The local repository. * The local repository.
* *
* @parameter default-value="${localRepository}" * @parameter default-value="${localRepository}"
* @readonly * @readonly
* @required * @required
@ -57,7 +56,7 @@ public class CollectMojo
/** /**
* The remote repositories of the current Maven project. * The remote repositories of the current Maven project.
* *
* @parameter default-value="${project.remoteArtifactRepositories}" * @parameter default-value="${project.remoteArtifactRepositories}"
* @readonly * @readonly
* @required * @required
@ -66,35 +65,35 @@ public class CollectMojo
/** /**
* The artifact collector. * The artifact collector.
* *
* @component * @component
*/ */
private ArtifactCollector collector; private ArtifactCollector collector;
/** /**
* The artifact factory. * The artifact factory.
* *
* @component * @component
*/ */
private ArtifactFactory factory; private ArtifactFactory factory;
/** /**
* The metadata source. * The metadata source.
* *
* @component * @component
*/ */
private ArtifactMetadataSource metadataSource; private ArtifactMetadataSource metadataSource;
/** /**
* The dependencies to resolve. * The dependencies to resolve.
* *
* @parameter * @parameter
*/ */
private Dependency[] dependencies; private Dependency[] dependencies;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the artifact file has not been set. * @throws MojoFailureException If the artifact file has not been set.
*/ */
public void execute() public void execute()
@ -110,10 +109,8 @@ public class CollectMojo
if ( dependencies != null ) if ( dependencies != null )
{ {
for ( int i = 0; i < dependencies.length; i++ ) for ( Dependency dependency : dependencies )
{ {
Dependency dependency = dependencies[i];
Artifact artifact = Artifact artifact =
factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion(), dependency.getType(), dependency.getVersion(), dependency.getType(),

View File

@ -36,7 +36,7 @@ public class CustomRepositoryLayout
{ {
ArtifactHandler artifactHandler = artifact.getArtifactHandler(); ArtifactHandler artifactHandler = artifact.getArtifactHandler();
StringBuffer path = new StringBuffer(); StringBuilder path = new StringBuilder();
path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );

View File

@ -24,16 +24,13 @@ import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import java.util.Iterator;
/** /**
* Deploys the project artifacts to the distribution repository. This is the essence of the Maven Deploy Plugin. * Deploys the project artifacts to the distribution repository. This is the essence of the Maven Deploy Plugin.
* *
* @goal deploy
* @phase deploy
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal deploy
* @phase deploy
*/ */
public class DeployMojo public class DeployMojo
extends AbstractRepoMojo extends AbstractRepoMojo
@ -41,7 +38,7 @@ public class DeployMojo
/** /**
* The distribution repository. * The distribution repository.
* *
* @parameter default-value="${project.distributionManagementArtifactRepository}" * @parameter default-value="${project.distributionManagementArtifactRepository}"
* @readonly * @readonly
* @required * @required
@ -50,14 +47,14 @@ public class DeployMojo
/** /**
* The artifact deployer. * The artifact deployer.
* *
* @component * @component
*/ */
private ArtifactDeployer deployer; private ArtifactDeployer deployer;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If any artifact could not be installed. * @throws MojoExecutionException If any artifact could not be installed.
*/ */
public void execute() public void execute()
@ -78,9 +75,9 @@ public class DeployMojo
if ( attachedArtifacts != null ) if ( attachedArtifacts != null )
{ {
for ( Iterator it = attachedArtifacts.iterator(); it.hasNext(); ) for ( Object attachedArtifact1 : attachedArtifacts )
{ {
Artifact attachedArtifact = (Artifact) it.next(); Artifact attachedArtifact = (Artifact) attachedArtifact1;
deployer.deploy( attachedArtifact.getFile(), attachedArtifact, deploymentRepository, deployer.deploy( attachedArtifact.getFile(), attachedArtifact, deploymentRepository,
localRepository ); localRepository );
} }

View File

@ -32,7 +32,6 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import java.io.File; import java.io.File;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
@ -87,9 +86,9 @@ public class InstallArtifactsMojo
ArtifactRepository artifactRepository = ArtifactRepository artifactRepository =
artifactRepositoryFactory.createDeploymentArtifactRepository( "appassembler", "file://" artifactRepositoryFactory.createDeploymentArtifactRepository( "appassembler", "file://"
+ assembleDirectory.getAbsolutePath() + "/" + repositoryName, artifactRepositoryLayout, false ); + assembleDirectory.getAbsolutePath() + "/" + repositoryName, artifactRepositoryLayout, false );
for ( Iterator it = artifacts.iterator(); it.hasNext(); ) for ( Object artifact1 : artifacts )
{ {
Artifact artifact = (Artifact) it.next(); Artifact artifact = (Artifact) artifact1;
installArtifact( artifactRepository, artifact ); installArtifact( artifactRepository, artifact );
} }
@ -115,7 +114,7 @@ public class InstallArtifactsMojo
} }
/** /**
* *
*/ */
public static class FlatRepositoryLayout public static class FlatRepositoryLayout
implements ArtifactRepositoryLayout implements ArtifactRepositoryLayout
@ -128,7 +127,7 @@ public class InstallArtifactsMojo
{ {
ArtifactHandler artifactHandler = artifact.getArtifactHandler(); ArtifactHandler artifactHandler = artifact.getArtifactHandler();
StringBuffer path = new StringBuffer(); StringBuilder path = new StringBuilder();
path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() ); path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() );
@ -152,7 +151,7 @@ public class InstallArtifactsMojo
private String pathOfRepositoryMetadata( String filename ) private String pathOfRepositoryMetadata( String filename )
{ {
StringBuffer path = new StringBuffer(); StringBuilder path = new StringBuilder();
path.append( filename ); path.append( filename );

View File

@ -23,16 +23,13 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.installer.ArtifactInstaller; import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import java.util.Iterator;
/** /**
* Installs the project artifacts into the local repository. This is the essence of the Maven Install Plugin. * Installs the project artifacts into the local repository. This is the essence of the Maven Install Plugin.
* *
* @goal install
* @phase install
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal install
* @phase install
*/ */
public class InstallMojo public class InstallMojo
extends AbstractRepoMojo extends AbstractRepoMojo
@ -40,14 +37,14 @@ public class InstallMojo
/** /**
* The artifact installer. * The artifact installer.
* *
* @component * @component
*/ */
private ArtifactInstaller installer; private ArtifactInstaller installer;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If any artifact could not be installed. * @throws MojoExecutionException If any artifact could not be installed.
*/ */
public void execute() public void execute()
@ -68,9 +65,9 @@ public class InstallMojo
if ( attachedArtifacts != null ) if ( attachedArtifacts != null )
{ {
for ( Iterator it = attachedArtifacts.iterator(); it.hasNext(); ) for ( Object attachedArtifact1 : attachedArtifacts )
{ {
Artifact attachedArtifact = (Artifact) it.next(); Artifact attachedArtifact = (Artifact) attachedArtifact1;
installer.install( attachedArtifact.getFile(), attachedArtifact, localRepository ); installer.install( attachedArtifact.getFile(), attachedArtifact, localRepository );
} }
} }

View File

@ -35,11 +35,10 @@ import java.util.Properties;
/** /**
* Resolves user-specified artifacts. This mimics in part the Maven Dependency Plugin and the Maven Surefire Plugin. * Resolves user-specified artifacts. This mimics in part the Maven Dependency Plugin and the Maven Surefire Plugin.
* *
* @goal resolve
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal resolve
*/ */
public class ResolveMojo public class ResolveMojo
extends AbstractMojo extends AbstractMojo
@ -47,7 +46,7 @@ public class ResolveMojo
/** /**
* The local repository. * The local repository.
* *
* @parameter default-value="${localRepository}" * @parameter default-value="${localRepository}"
* @readonly * @readonly
* @required * @required
@ -56,7 +55,7 @@ public class ResolveMojo
/** /**
* The remote repositories of the current Maven project. * The remote repositories of the current Maven project.
* *
* @parameter default-value="${project.remoteArtifactRepositories}" * @parameter default-value="${project.remoteArtifactRepositories}"
* @readonly * @readonly
* @required * @required
@ -65,35 +64,35 @@ public class ResolveMojo
/** /**
* The artifact resolver. * The artifact resolver.
* *
* @component * @component
*/ */
private ArtifactResolver resolver; private ArtifactResolver resolver;
/** /**
* The artifact factory. * The artifact factory.
* *
* @component * @component
*/ */
private ArtifactFactory factory; private ArtifactFactory factory;
/** /**
* The dependencies to resolve. * The dependencies to resolve.
* *
* @parameter * @parameter
*/ */
private Dependency[] dependencies; private Dependency[] dependencies;
/** /**
* The path to a properties file to store the resolved artifact paths in. * The path to a properties file to store the resolved artifact paths in.
* *
* @parameter * @parameter
*/ */
private File propertiesFile; private File propertiesFile;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the artifact could not be resolved * @throws MojoFailureException If the artifact could not be resolved
*/ */
public void execute() public void execute()
@ -107,10 +106,8 @@ public class ResolveMojo
{ {
if ( dependencies != null ) if ( dependencies != null )
{ {
for ( int i = 0; i < dependencies.length; i++ ) for ( Dependency dependency : dependencies )
{ {
Dependency dependency = dependencies[i];
Artifact artifact = Artifact artifact =
factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion(), dependency.getType(), dependency.getVersion(), dependency.getType(),
@ -142,15 +139,10 @@ public class ResolveMojo
{ {
propertiesFile.getParentFile().mkdirs(); propertiesFile.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream( propertiesFile ); try ( FileOutputStream fos = new FileOutputStream( propertiesFile ) )
try
{ {
props.store( fos, "MAVEN-CORE-IT" ); props.store( fos, "MAVEN-CORE-IT" );
} }
finally
{
fos.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -31,7 +31,6 @@ import org.apache.maven.plugin.MojoExecutionException;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -40,10 +39,9 @@ import java.util.Set;
/** /**
* Resolves user-specified artifacts transitively. As an additional exercise, the resolution happens in a forked thread * Resolves user-specified artifacts transitively. As an additional exercise, the resolution happens in a forked thread
* to test access to any shared session state. * to test access to any shared session state.
* *
* @goal resolve-transitive
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @goal resolve-transitive
*/ */
public class ResolveTransitiveMojo public class ResolveTransitiveMojo
extends AbstractMojo extends AbstractMojo
@ -51,7 +49,7 @@ public class ResolveTransitiveMojo
/** /**
* The local repository. * The local repository.
* *
* @parameter default-value="${localRepository}" * @parameter default-value="${localRepository}"
* @readonly * @readonly
* @required * @required
@ -60,7 +58,7 @@ public class ResolveTransitiveMojo
/** /**
* The remote repositories of the current Maven project. * The remote repositories of the current Maven project.
* *
* @parameter default-value="${project.remoteArtifactRepositories}" * @parameter default-value="${project.remoteArtifactRepositories}"
* @readonly * @readonly
* @required * @required
@ -69,42 +67,42 @@ public class ResolveTransitiveMojo
/** /**
* The artifact resolver. * The artifact resolver.
* *
* @component * @component
*/ */
private ArtifactResolver resolver; private ArtifactResolver resolver;
/** /**
* The artifact factory. * The artifact factory.
* *
* @component * @component
*/ */
private ArtifactFactory factory; private ArtifactFactory factory;
/** /**
* The metadata source. * The metadata source.
* *
* @component * @component
*/ */
private ArtifactMetadataSource metadataSource; private ArtifactMetadataSource metadataSource;
/** /**
* The dependencies to resolve. * The dependencies to resolve.
* *
* @parameter * @parameter
*/ */
private Dependency[] dependencies; private Dependency[] dependencies;
/** /**
* The path to a properties file to store the resolved artifact paths in. * The path to a properties file to store the resolved artifact paths in.
* *
* @parameter * @parameter
*/ */
private File propertiesFile; private File propertiesFile;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the artifacts couldn't be resolved. * @throws MojoExecutionException If the artifacts couldn't be resolved.
*/ */
public void execute() public void execute()
@ -140,15 +138,10 @@ public class ResolveTransitiveMojo
{ {
propertiesFile.getParentFile().mkdirs(); propertiesFile.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream( propertiesFile ); try ( FileOutputStream fos = new FileOutputStream( propertiesFile ) )
try
{ {
thread.props.store( fos, "MAVEN-CORE-IT" ); thread.props.store( fos, "MAVEN-CORE-IT" );
} }
finally
{
fos.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {
@ -179,30 +172,27 @@ public class ResolveTransitiveMojo
{ {
Set artifacts = new LinkedHashSet(); Set artifacts = new LinkedHashSet();
for ( int i = 0; i < dependencies.length; i++ ) for ( Dependency dependency : dependencies )
{ {
Dependency dependency = dependencies[i];
Artifact artifact = Artifact artifact =
factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion(), dependency.getType(), dependency.getVersion(), dependency.getType(),
dependency.getClassifier() ); dependency.getClassifier() );
getLog().info( "[MAVEN-CORE-IT-LOG] Resolving " getLog().info(
+ ResolveTransitiveMojo.this.getId( artifact ) ); "[MAVEN-CORE-IT-LOG] Resolving " + ResolveTransitiveMojo.this.getId( artifact ) );
artifacts.add( artifact ); artifacts.add( artifact );
} }
Artifact origin = factory.createArtifact( "it", "it", "0.1", null, "pom" ); Artifact origin = factory.createArtifact( "it", "it", "0.1", null, "pom" );
artifacts = artifacts = resolver.resolveTransitively( artifacts, origin, remoteRepositories, localRepository,
resolver.resolveTransitively( artifacts, origin, remoteRepositories, localRepository, metadataSource ).getArtifacts();
metadataSource ).getArtifacts();
for ( Iterator it = artifacts.iterator(); it.hasNext(); ) for ( Object artifact1 : artifacts )
{ {
Artifact artifact = (Artifact) it.next(); Artifact artifact = (Artifact) artifact1;
if ( artifact.getFile() != null ) if ( artifact.getFile() != null )
{ {

View File

@ -30,13 +30,12 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
/** /**
* Loads classes and/or resources from a class loader and records the results in a properties file. * Loads classes and/or resources from a class loader and records the results in a properties file.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -50,7 +49,7 @@ public abstract class AbstractLoadMojo
* key will be the hash code of the requested class. In addition, a key named <code>QCN.methods</code> holds the * key will be the hash code of the requested class. In addition, a key named <code>QCN.methods</code> holds the
* comma separated list of all public methods declared directly in that class, in alphabetic order and possibly with * comma separated list of all public methods declared directly in that class, in alphabetic order and possibly with
* duplicates to account for overloaded methods. * duplicates to account for overloaded methods.
* *
* @parameter property="clsldr.classNames" * @parameter property="clsldr.classNames"
*/ */
protected String classNames; protected String classNames;
@ -60,15 +59,15 @@ public abstract class AbstractLoadMojo
* successfully loaded, the generated properties files will contain a key named <code>ARP</code> whose value gives * successfully loaded, the generated properties files will contain a key named <code>ARP</code> whose value gives
* the URL to the resource. In addition, the keys <code>ARP.count</code>, <code>ARP.0</code>, <code>ARP.1</code> * the URL to the resource. In addition, the keys <code>ARP.count</code>, <code>ARP.0</code>, <code>ARP.1</code>
* etc. will enumerate all URLs matching the resource name. * etc. will enumerate all URLs matching the resource name.
* *
* @parameter property="clsldr.resourcePaths" * @parameter property="clsldr.resourcePaths"
*/ */
protected String resourcePaths; protected String resourcePaths;
/** /**
* Loads the classes/resources. * Loads the classes/resources.
* *
* @param outputFile The path to the properties file to generate, must not be <code>null</code>. * @param outputFile The path to the properties file to generate, must not be <code>null</code>.
* @param classLoader The class loader to use, must not be <code>null</code>. * @param classLoader The class loader to use, must not be <code>null</code>.
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
@ -94,9 +93,8 @@ public abstract class AbstractLoadMojo
if ( classNames != null && classNames.length() > 0 ) if ( classNames != null && classNames.length() > 0 )
{ {
String[] names = classNames.split( "," ); String[] names = classNames.split( "," );
for ( int i = 0; i < names.length; i++ ) for ( String name : names )
{ {
String name = names[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Loading class " + name ); getLog().info( "[MAVEN-CORE-IT-LOG] Loading class " + name );
// test ClassLoader.loadClass(String) and (indirectly) ClassLoader.loadClass(String, boolean) // test ClassLoader.loadClass(String) and (indirectly) ClassLoader.loadClass(String, boolean)
@ -120,22 +118,22 @@ public abstract class AbstractLoadMojo
Method[] methods = type.getDeclaredMethods(); Method[] methods = type.getDeclaredMethods();
List methodNames = new ArrayList(); List methodNames = new ArrayList();
for ( int j = 0; j < methods.length; j++ ) for ( Method method : methods )
{ {
if ( Modifier.isPublic( methods[j].getModifiers() ) ) if ( Modifier.isPublic( method.getModifiers() ) )
{ {
methodNames.add( methods[j].getName() ); methodNames.add( method.getName() );
} }
} }
Collections.sort( methodNames ); Collections.sort( methodNames );
StringBuffer buffer = new StringBuffer( 1024 ); StringBuilder buffer = new StringBuilder( 1024 );
for ( Iterator it = methodNames.iterator(); it.hasNext(); ) for ( Object methodName : methodNames )
{ {
if ( buffer.length() > 0 ) if ( buffer.length() > 0 )
{ {
buffer.append( ',' ); buffer.append( ',' );
} }
buffer.append( it.next() ); buffer.append( methodName );
} }
loaderProperties.setProperty( name + ".methods", buffer.toString() ); loaderProperties.setProperty( name + ".methods", buffer.toString() );
@ -156,9 +154,8 @@ public abstract class AbstractLoadMojo
if ( resourcePaths != null && resourcePaths.length() > 0 ) if ( resourcePaths != null && resourcePaths.length() > 0 )
{ {
String[] paths = resourcePaths.split( "," ); String[] paths = resourcePaths.split( "," );
for ( int i = 0; i < paths.length; i++ ) for ( String path : paths )
{ {
String path = paths[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Loading resource " + path ); getLog().info( "[MAVEN-CORE-IT-LOG] Loading resource " + path );
// test ClassLoader.getResource() // test ClassLoader.getResource()

View File

@ -29,11 +29,10 @@ import java.util.Properties;
/** /**
* Checks whether API classes exported by the Maven core are assignment-compatible with types loaded from the plugin * Checks whether API classes exported by the Maven core are assignment-compatible with types loaded from the plugin
* class loader. In other words, checks that types shared with the core realm are imported into the plugin realm. * class loader. In other words, checks that types shared with the core realm are imported into the plugin realm.
* *
* @author Benjamin Bentmann
* @goal assignment-compatible * @goal assignment-compatible
* @phase initialize * @phase initialize
*
* @author Benjamin Bentmann
*/ */
public class AssignmentCompatibleMojo public class AssignmentCompatibleMojo
extends AbstractMojo extends AbstractMojo
@ -41,21 +40,21 @@ public class AssignmentCompatibleMojo
/** /**
* The path to the properties file used to track the results of the assignment compatibility tests. * The path to the properties file used to track the results of the assignment compatibility tests.
* *
* @parameter property="clsldr.assigncompatPropertiesFile" * @parameter property="clsldr.assigncompatPropertiesFile"
*/ */
private File assigncompatPropertiesFile; private File assigncompatPropertiesFile;
/** /**
* The qualified names of the types to check. * The qualified names of the types to check.
* *
* @parameter * @parameter
*/ */
private String[] classNames; private String[] classNames;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -73,9 +72,8 @@ public class AssignmentCompatibleMojo
if ( classNames != null ) if ( classNames != null )
{ {
for ( int i = 0; i < classNames.length; i++ ) for ( String className : classNames )
{ {
String className = classNames[i];
String result; String result;
getLog().info( "[MAVEN-CORE-IT-LOG] Loading class " + className ); getLog().info( "[MAVEN-CORE-IT-LOG] Loading class " + className );

View File

@ -29,7 +29,7 @@ import java.util.Map;
/** /**
* Assists in evaluating expressions. * Assists in evaluating expressions.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -52,10 +52,11 @@ class ExpressionUtil
* root objects are available. For instance, if <code>contexts</code> maps the token "project" to a Maven project * root objects are available. For instance, if <code>contexts</code> maps the token "project" to a Maven project
* instance, the expression "project/build/resources/0/directory" specifies the first resource directory of the * instance, the expression "project/build/resources/0/directory" specifies the first resource directory of the
* project. * project.
* *
* @param expression The expression to evaluate, may be <code>null</code>. * @param expression The expression to evaluate, may be <code>null</code>.
* @param contexts The possible root objects for the expression evaluation, indexed by their identifying token, must * @param contexts The possible root objects for the expression evaluation, indexed by their identifying token,
* not be <code>null</code>. * must
* not be <code>null</code>.
* @return The value of the expression or <code>null</code> if the expression could not be evaluated. * @return The value of the expression or <code>null</code> if the expression could not be evaluated.
*/ */
public static Object evaluate( String expression, Map contexts ) public static Object evaluate( String expression, Map contexts )
@ -80,8 +81,8 @@ class ExpressionUtil
/** /**
* Evaluates the given expression segments against the specified object. * Evaluates the given expression segments against the specified object.
* *
* @param context The object to evaluate the segments against, may be <code>null</code>. * @param context The object to evaluate the segments against, may be <code>null</code>.
* @param segments The expression segments to evaluate, must not be <code>null</code>. * @param segments The expression segments to evaluate, must not be <code>null</code>.
* @return The value of the evaluation or <code>null</code> if the segments could not be evaluated. * @return The value of the evaluation or <code>null</code> if the segments could not be evaluated.
*/ */
@ -137,8 +138,8 @@ class ExpressionUtil
/** /**
* Gets the value of a (public) bean property from the specified object. * Gets the value of a (public) bean property from the specified object.
* *
* @param context The object whose bean property should be retrieved, must not be <code>null</code>. * @param context The object whose bean property should be retrieved, must not be <code>null</code>.
* @param property The name of the bean property, must not be <code>null</code>. * @param property The name of the bean property, must not be <code>null</code>.
* @return The value of the bean property or <code>null</code> if the property does not exist. * @return The value of the bean property or <code>null</code> if the property does not exist.
*/ */
@ -192,7 +193,7 @@ class ExpressionUtil
{ {
method = type.getMethod( "get", OBJECT_PARAM ); method = type.getMethod( "get", OBJECT_PARAM );
} }
value = method.invoke( context, new Object[] { property } ); value = method.invoke( context, new Object[]{ property } );
} }
catch ( NoSuchMethodException e3 ) catch ( NoSuchMethodException e3 )
{ {
@ -205,7 +206,7 @@ class ExpressionUtil
{ {
if ( "length".equals( property ) && type.isArray() ) if ( "length".equals( property ) && type.isArray() )
{ {
value = new Integer( Array.getLength( context ) ); value = Array.getLength( context );
} }
else else
{ {

View File

@ -25,7 +25,6 @@ import org.apache.maven.plugin.MojoFailureException;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -33,12 +32,11 @@ import java.util.Properties;
/** /**
* Checks whether objects obtained from the Maven core are assignment-compatible with types loaded from the plugin class * Checks whether objects obtained from the Maven core are assignment-compatible with types loaded from the plugin class
* loader. In other words, checks that types shared with the core realm are imported into the plugin realm. * loader. In other words, checks that types shared with the core realm are imported into the plugin realm.
* *
* @goal instanceof
* @phase initialize
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal instanceof
* @phase initialize
*/ */
public class InstanceofMojo public class InstanceofMojo
extends AbstractMojo extends AbstractMojo
@ -46,7 +44,7 @@ public class InstanceofMojo
/** /**
* The path to the properties file used to track the results of the instanceof tests. * The path to the properties file used to track the results of the instanceof tests.
* *
* @parameter property="clsldr.instanceofPropertiesFile" * @parameter property="clsldr.instanceofPropertiesFile"
*/ */
private File instanceofPropertiesFile; private File instanceofPropertiesFile;
@ -54,28 +52,28 @@ public class InstanceofMojo
/** /**
* The qualified name of the type to which the objects should be assignment-compatible. This type will be loaded * The qualified name of the type to which the objects should be assignment-compatible. This type will be loaded
* from the plugin class loader, just like as if it was imported in the plugin source code. * from the plugin class loader, just like as if it was imported in the plugin source code.
* *
* @parameter property="clsldr.className" * @parameter property="clsldr.className"
*/ */
private String className; private String className;
/** /**
* A list of expressions that denote the object instances that should be type-checked. * A list of expressions that denote the object instances that should be type-checked.
* *
* @parameter * @parameter
*/ */
private String[] objectExpressions; private String[] objectExpressions;
/** /**
* A list of injected component instances that should be type-checked. * A list of injected component instances that should be type-checked.
* *
* @component role="org.apache.maven.plugin.coreit.Component" * @component role="org.apache.maven.plugin.coreit.Component"
*/ */
private List components; private List components;
/** /**
* The current Maven project against which expressions are evaluated. * The current Maven project against which expressions are evaluated.
* *
* @parameter default-value="${project}" * @parameter default-value="${project}"
* @readonly * @readonly
*/ */
@ -83,7 +81,7 @@ public class InstanceofMojo
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -109,9 +107,8 @@ public class InstanceofMojo
contexts.put( "project", project ); contexts.put( "project", project );
contexts.put( "pom", project ); contexts.put( "pom", project );
for ( int i = 0; i < objectExpressions.length; i++ ) for ( String expression : objectExpressions )
{ {
String expression = objectExpressions[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Evaluating expression " + expression ); getLog().info( "[MAVEN-CORE-IT-LOG] Evaluating expression " + expression );
Object object = ExpressionUtil.evaluate( expression, contexts ); Object object = ExpressionUtil.evaluate( expression, contexts );
getLog().info( "[MAVEN-CORE-IT-LOG] Checking object " + object ); getLog().info( "[MAVEN-CORE-IT-LOG] Checking object " + object );
@ -127,9 +124,8 @@ public class InstanceofMojo
if ( components != null && !components.isEmpty() ) if ( components != null && !components.isEmpty() )
{ {
for ( Iterator it = components.iterator(); it.hasNext(); ) for ( Object object : components )
{ {
Object object = it.next();
getLog().info( "[MAVEN-CORE-IT-LOG] Checking component " + object ); getLog().info( "[MAVEN-CORE-IT-LOG] Checking component " + object );
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class " + object.getClass().getName() ); getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class " + object.getClass().getName() );
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class from " + object.getClass().getClassLoader() ); getLog().info( "[MAVEN-CORE-IT-LOG] Loaded class from " + object.getClass().getClassLoader() );

View File

@ -19,13 +19,13 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import junit.framework.TestCase;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase;
/** /**
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
@ -36,8 +36,8 @@ public class ExpressionUtilTest
public void testEvaluate() public void testEvaluate()
{ {
Object array = new String[] { "one", "two", "three" }; Object array = new String[]{ "one", "two", "three" };
Object list = Arrays.asList( new String[] { "0", "-1", "-2" } ); Object list = Arrays.asList( new String[]{ "0", "-1", "-2" } );
Object map = Collections.singletonMap( "some.key", "value" ); Object map = Collections.singletonMap( "some.key", "value" );
Object bean = new BeanTwo(); Object bean = new BeanTwo();
@ -54,20 +54,20 @@ public class ExpressionUtilTest
assertSame( bean, ExpressionUtil.evaluate( "bean", contexts ) ); assertSame( bean, ExpressionUtil.evaluate( "bean", contexts ) );
assertNull( ExpressionUtil.evaluate( "no-root", contexts ) ); assertNull( ExpressionUtil.evaluate( "no-root", contexts ) );
assertEquals( new Integer( 3 ), ExpressionUtil.evaluate( "array/length", contexts ) ); assertEquals( 3, ExpressionUtil.evaluate( "array/length", contexts ) );
assertEquals( "three", ExpressionUtil.evaluate( "array/2", contexts ) ); assertEquals( "three", ExpressionUtil.evaluate( "array/2", contexts ) );
assertEquals( new Integer( 5 ), ExpressionUtil.evaluate( "array/2/length", contexts ) ); assertEquals( 5, ExpressionUtil.evaluate( "array/2/length", contexts ) );
assertNull( ExpressionUtil.evaluate( "array/invalid", contexts ) ); assertNull( ExpressionUtil.evaluate( "array/invalid", contexts ) );
assertNull( ExpressionUtil.evaluate( "array/-1", contexts ) ); assertNull( ExpressionUtil.evaluate( "array/-1", contexts ) );
assertNull( ExpressionUtil.evaluate( "array/999", contexts ) ); assertNull( ExpressionUtil.evaluate( "array/999", contexts ) );
assertEquals( new Integer( 3 ), ExpressionUtil.evaluate( "list/size", contexts ) ); assertEquals( 3, ExpressionUtil.evaluate( "list/size", contexts ) );
assertEquals( "-2", ExpressionUtil.evaluate( "list/2", contexts ) ); assertEquals( "-2", ExpressionUtil.evaluate( "list/2", contexts ) );
assertNull( ExpressionUtil.evaluate( "list/invalid", contexts ) ); assertNull( ExpressionUtil.evaluate( "list/invalid", contexts ) );
assertNull( ExpressionUtil.evaluate( "list/-1", contexts ) ); assertNull( ExpressionUtil.evaluate( "list/-1", contexts ) );
assertNull( ExpressionUtil.evaluate( "list/999", contexts ) ); assertNull( ExpressionUtil.evaluate( "list/999", contexts ) );
assertEquals( new Integer( 1 ), ExpressionUtil.evaluate( "map/size", contexts ) ); assertEquals( 1, ExpressionUtil.evaluate( "map/size", contexts ) );
assertEquals( "value", ExpressionUtil.evaluate( "map/some.key", contexts ) ); assertEquals( "value", ExpressionUtil.evaluate( "map/some.key", contexts ) );
assertNull( ExpressionUtil.evaluate( "map/invalid", contexts ) ); assertNull( ExpressionUtil.evaluate( "map/invalid", contexts ) );
@ -91,7 +91,7 @@ public class ExpressionUtilTest
assertEquals( bean2.field, ExpressionUtil.getProperty( bean2, "field" ) ); assertEquals( bean2.field, ExpressionUtil.getProperty( bean2, "field" ) );
assertSame( bean2.bean, ExpressionUtil.getProperty( bean2, "bean" ) ); assertSame( bean2.bean, ExpressionUtil.getProperty( bean2, "bean" ) );
assertEquals( new Integer( 0 ), ExpressionUtil.getProperty( new String[0], "length" ) ); assertEquals( 0, ExpressionUtil.getProperty( new String[0], "length" ) );
} }
public static class BeanOne public static class BeanOne

View File

@ -19,6 +19,10 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -28,18 +32,13 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
/** /**
* Dumps this mojo's configuration into a properties file. * Dumps this mojo's configuration into a properties file.
* *
* @goal config
* @phase validate
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal config
* @phase validate
*/ */
public class ConfigMojo public class ConfigMojo
extends AbstractMojo extends AbstractMojo
@ -47,7 +46,7 @@ public class ConfigMojo
/** /**
* The current project's base directory, used for path alignment. * The current project's base directory, used for path alignment.
* *
* @parameter default-value="${basedir}" * @parameter default-value="${basedir}"
* @readonly * @readonly
*/ */
@ -55,210 +54,210 @@ public class ConfigMojo
/** /**
* The path to the properties file into which to save the mojo configuration. * The path to the properties file into which to save the mojo configuration.
* *
* @parameter property="config.propertiesFile" * @parameter property="config.propertiesFile"
*/ */
private File propertiesFile; private File propertiesFile;
/** /**
* A parameter with an alias. * A parameter with an alias.
* *
* @parameter alias="aliasParamLegacy" * @parameter alias="aliasParamLegacy"
*/ */
private String aliasParam; private String aliasParam;
/** /**
* A parameter with a constant default value. * A parameter with a constant default value.
* *
* @parameter default-value="maven-core-it" * @parameter default-value="maven-core-it"
*/ */
private String defaultParam; private String defaultParam;
/** /**
* A parameter with a default value using multiple expressions. * A parameter with a default value using multiple expressions.
* *
* @parameter default-value="${project.groupId}:${project.artifactId}:${project.version}" * @parameter default-value="${project.groupId}:${project.artifactId}:${project.version}"
*/ */
private String defaultParamWithExpression; private String defaultParamWithExpression;
/** /**
* A parameter that combines all of the annotations. * A parameter that combines all of the annotations.
* *
* @parameter alias="fullyAnnotatedParam" property="config.aliasDefaultExpressionParam" default-value="test" * @parameter alias="fullyAnnotatedParam" property="config.aliasDefaultExpressionParam" default-value="test"
*/ */
private String aliasDefaultExpressionParam; private String aliasDefaultExpressionParam;
/** /**
* A simple parameter of type {@link java.lang.Boolean}. * A simple parameter of type {@link java.lang.Boolean}.
* *
* @parameter property="config.booleanParam" * @parameter property="config.booleanParam"
*/ */
private Boolean booleanParam; private Boolean booleanParam;
/** /**
* A simple parameter of type {@link java.lang.Boolean#TYPE}. * A simple parameter of type {@link java.lang.Boolean#TYPE}.
* *
* @parameter property="config.primitiveBooleanParam" * @parameter property="config.primitiveBooleanParam"
*/ */
private boolean primitiveBooleanParam; private boolean primitiveBooleanParam;
/** /**
* A simple parameter of type {@link java.lang.Byte}. * A simple parameter of type {@link java.lang.Byte}.
* *
* @parameter property="config.byteParam" * @parameter property="config.byteParam"
*/ */
private Byte byteParam; private Byte byteParam;
/** /**
* A simple parameter of type {@link java.lang.Short}. * A simple parameter of type {@link java.lang.Short}.
* *
* @parameter property="config.shortParam" * @parameter property="config.shortParam"
*/ */
private Short shortParam; private Short shortParam;
/** /**
* A simple parameter of type {@link java.lang.Integer}. * A simple parameter of type {@link java.lang.Integer}.
* *
* @parameter property="config.intergerParam" * @parameter property="config.intergerParam"
*/ */
private Integer integerParam; private Integer integerParam;
/** /**
* A simple parameter of type {@link java.lang.Integer#TYPE}. * A simple parameter of type {@link java.lang.Integer#TYPE}.
* *
* @parameter property="config.primitiveIntegerParam" * @parameter property="config.primitiveIntegerParam"
*/ */
private int primitiveIntegerParam; private int primitiveIntegerParam;
/** /**
* A simple parameter of type {@link java.lang.Long}. * A simple parameter of type {@link java.lang.Long}.
* *
* @parameter property="config.longParam" * @parameter property="config.longParam"
*/ */
private Long longParam; private Long longParam;
/** /**
* A simple parameter of type {@link java.lang.Float}. * A simple parameter of type {@link java.lang.Float}.
* *
* @parameter property="config.floatParam" * @parameter property="config.floatParam"
*/ */
private Float floatParam; private Float floatParam;
/** /**
* A simple parameter of type {@link java.lang.Double}. * A simple parameter of type {@link java.lang.Double}.
* *
* @parameter property="config.doubleParam" * @parameter property="config.doubleParam"
*/ */
private Double doubleParam; private Double doubleParam;
/** /**
* A simple parameter of type {@link java.lang.Character}. * A simple parameter of type {@link java.lang.Character}.
* *
* @parameter property="config.characterParam" * @parameter property="config.characterParam"
*/ */
private Character characterParam; private Character characterParam;
/** /**
* A simple parameter of type {@link java.lang.String}. * A simple parameter of type {@link java.lang.String}.
* *
* @parameter property="config.stringParam" * @parameter property="config.stringParam"
*/ */
private String stringParam; private String stringParam;
/** /**
* A simple parameter of type {@link java.io.File}. * A simple parameter of type {@link java.io.File}.
* *
* @parameter property="config.fileParam" * @parameter property="config.fileParam"
*/ */
private File fileParam; private File fileParam;
/** /**
* A simple parameter of type {@link java.util.Date}. * A simple parameter of type {@link java.util.Date}.
* *
* @parameter property="config.dateParam" * @parameter property="config.dateParam"
*/ */
private Date dateParam; private Date dateParam;
/** /**
* A simple parameter of type {@link java.net.URL}. * A simple parameter of type {@link java.net.URL}.
* *
* @parameter property="config.urlParam" * @parameter property="config.urlParam"
*/ */
private URL urlParam; private URL urlParam;
/** /**
* A simple parameter of type {@link java.net.URI} (requires Maven 3.x). * A simple parameter of type {@link java.net.URI} (requires Maven 3.x).
* *
* @parameter * @parameter
*/ */
private URI uriParam; private URI uriParam;
/** /**
* An array parameter of component type {@link java.lang.String}. * An array parameter of component type {@link java.lang.String}.
* *
* @parameter * @parameter
*/ */
private String[] stringParams; private String[] stringParams;
/** /**
* An array parameter of component type {@link java.io.File}. * An array parameter of component type {@link java.io.File}.
* *
* @parameter * @parameter
*/ */
private File[] fileParams; private File[] fileParams;
/** /**
* A collection parameter of type {@link java.util.List}. * A collection parameter of type {@link java.util.List}.
* *
* @parameter * @parameter
*/ */
private List listParam; private List listParam;
/** /**
* A collection parameter of type {@link java.util.Set}. * A collection parameter of type {@link java.util.Set}.
* *
* @parameter * @parameter
*/ */
private Set setParam; private Set setParam;
/** /**
* A collection parameter of type {@link java.util.Map}. * A collection parameter of type {@link java.util.Map}.
* *
* @parameter * @parameter
*/ */
private Map mapParam; private Map mapParam;
/** /**
* A collection parameter of type {@link java.util.Properties}. * A collection parameter of type {@link java.util.Properties}.
* *
* @parameter * @parameter
*/ */
private Properties propertiesParam; private Properties propertiesParam;
/** /**
* A complex parameter with an alias. * A complex parameter with an alias.
* *
* @parameter alias="aliasStringParamsLegacy" * @parameter alias="aliasStringParamsLegacy"
*/ */
private String[] aliasStringParams; private String[] aliasStringParams;
/** /**
* A complex parameter of type {@link org.apache.maven.plugin.coreit.Bean}. * A complex parameter of type {@link org.apache.maven.plugin.coreit.Bean}.
* *
* @parameter * @parameter
*/ */
private Bean beanParam; private Bean beanParam;
/** /**
* A raw DOM snippet. * A raw DOM snippet.
* *
* @parameter * @parameter
*/ */
private PlexusConfiguration domParam; private PlexusConfiguration domParam;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -289,7 +288,7 @@ public class ConfigMojo
/** /**
* Dumps the mojo configuration into the specified properties. * Dumps the mojo configuration into the specified properties.
* *
* @param props The properties to dump the configuration into, must not be <code>null</code>. * @param props The properties to dump the configuration into, must not be <code>null</code>.
*/ */
private void dumpConfiguration( Properties props ) private void dumpConfiguration( Properties props )
@ -306,14 +305,14 @@ public class ConfigMojo
PropertiesUtil.serialize( props, "booleanParam", booleanParam ); PropertiesUtil.serialize( props, "booleanParam", booleanParam );
if ( primitiveBooleanParam ) if ( primitiveBooleanParam )
{ {
PropertiesUtil.serialize( props, "primitiveBooleanParam", Boolean.valueOf( primitiveBooleanParam ) ); PropertiesUtil.serialize( props, "primitiveBooleanParam", primitiveBooleanParam );
} }
PropertiesUtil.serialize( props, "byteParam", byteParam ); PropertiesUtil.serialize( props, "byteParam", byteParam );
PropertiesUtil.serialize( props, "shortParam", shortParam ); PropertiesUtil.serialize( props, "shortParam", shortParam );
PropertiesUtil.serialize( props, "integerParam", integerParam ); PropertiesUtil.serialize( props, "integerParam", integerParam );
if ( primitiveIntegerParam != 0 ) if ( primitiveIntegerParam != 0 )
{ {
PropertiesUtil.serialize( props, "primitiveIntegerParam", new Integer( primitiveIntegerParam ) ); PropertiesUtil.serialize( props, "primitiveIntegerParam", primitiveIntegerParam );
} }
PropertiesUtil.serialize( props, "longParam", longParam ); PropertiesUtil.serialize( props, "longParam", longParam );
PropertiesUtil.serialize( props, "floatParam", floatParam ); PropertiesUtil.serialize( props, "floatParam", floatParam );
@ -336,7 +335,7 @@ public class ConfigMojo
{ {
PropertiesUtil.serialize( props, "beanParam.fieldParam", beanParam.fieldParam ); PropertiesUtil.serialize( props, "beanParam.fieldParam", beanParam.fieldParam );
PropertiesUtil.serialize( props, "beanParam.setterParam", beanParam.setterParam ); PropertiesUtil.serialize( props, "beanParam.setterParam", beanParam.setterParam );
PropertiesUtil.serialize( props, "beanParam.setterCalled", Boolean.valueOf( beanParam.setterCalled ) ); PropertiesUtil.serialize( props, "beanParam.setterCalled", beanParam.setterCalled );
} }
} }

View File

@ -19,6 +19,9 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -34,12 +37,9 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
/** /**
* Assists in handling properties. * Assists in handling properties.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
class PropertiesUtil class PropertiesUtil
@ -164,18 +164,17 @@ class PropertiesUtil
PlexusConfiguration children[] = config.getChildren(); PlexusConfiguration children[] = config.getChildren();
props.setProperty( key + ".children", Integer.toString( children.length ) ); props.setProperty( key + ".children", Integer.toString( children.length ) );
Map indices = new HashMap(); Map<String, Integer> indices = new HashMap<>();
for ( int i = 0; i < children.length; i++ ) for ( PlexusConfiguration child : children )
{ {
PlexusConfiguration child = children[i];
String name = child.getName(); String name = child.getName();
Integer index = (Integer) indices.get( name ); Integer index = indices.get( name );
if ( index == null ) if ( index == null )
{ {
index = new Integer( 0 ); index = 0;
} }
serialize( props, key + ".children." + name + "." + index, child ); serialize( props, key + ".children." + name + "." + index, child );
indices.put( name, new Integer( index.intValue() + 1 ) ); indices.put( name, index + 1 );
} }
} }
else if ( value instanceof Date ) else if ( value instanceof Date )

View File

@ -31,12 +31,11 @@ import java.io.OutputStreamWriter;
/** /**
* Creates a text file in the project base directory. * Creates a text file in the project base directory.
* *
* @goal resources
* @phase process-resources
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal resources
* @phase process-resources
*/ */
public class ResourcesMojo public class ResourcesMojo
extends AbstractMojo extends AbstractMojo
@ -44,7 +43,7 @@ public class ResourcesMojo
/** /**
* The current Maven project. * The current Maven project.
* *
* @parameter default-value="${project}" * @parameter default-value="${project}"
* @required * @required
* @readonly * @readonly
@ -53,7 +52,7 @@ public class ResourcesMojo
/** /**
* The path to the output file, relative to the project base directory directory. * The path to the output file, relative to the project base directory directory.
* *
* @parameter * @parameter
*/ */
private String pathname = "target/resources-resources.txt"; private String pathname = "target/resources-resources.txt";
@ -61,16 +60,16 @@ public class ResourcesMojo
/** /**
* An optional message line to write to the output file (using UTF-8 encoding). If given, the output file will be * An optional message line to write to the output file (using UTF-8 encoding). If given, the output file will be
* opened in append mode. * opened in append mode.
* *
* @parameter * @parameter
*/ */
private String message; private String message;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
* @throws MojoFailureException If the output file has not been set. * @throws MojoFailureException If the output file has not been set.
*/ */
public void execute() public void execute()
throws MojoExecutionException, MojoFailureException throws MojoExecutionException, MojoFailureException
@ -98,16 +97,12 @@ public class ResourcesMojo
{ {
getLog().info( "[MAVEN-CORE-IT-LOG] " + message ); getLog().info( "[MAVEN-CORE-IT-LOG] " + message );
OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( outputFile, true ), "UTF-8" ); try ( OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( outputFile, true ),
try "UTF-8" ) )
{ {
writer.write( message ); writer.write( message );
writer.write( "\n" ); writer.write( "\n" );
} }
finally
{
writer.close();
}
} }
else else
{ {

View File

@ -30,11 +30,10 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
/** /**
* Provides common services for all mojos of this plugin. * Provides common services for all mojos of this plugin.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -44,7 +43,7 @@ public abstract class AbstractDependencyMojo
/** /**
* The current Maven project. * The current Maven project.
* *
* @parameter default-value="${project}" * @parameter default-value="${project}"
* @required * @required
* @readonly * @readonly
@ -53,9 +52,9 @@ public abstract class AbstractDependencyMojo
/** /**
* Writes the specified artifacts to the given output file. * Writes the specified artifacts to the given output file.
* *
* @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or * @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or
* empty if the output file should not be written. * empty if the output file should not be written.
* @param artifacts The list of artifacts to write to the file, may be <code>null</code>. * @param artifacts The list of artifacts to write to the file, may be <code>null</code>.
* @throws MojoExecutionException If the output file could not be written. * @throws MojoExecutionException If the output file could not be written.
*/ */
@ -80,9 +79,9 @@ public abstract class AbstractDependencyMojo
if ( artifacts != null ) if ( artifacts != null )
{ {
for ( Iterator it = artifacts.iterator(); it.hasNext(); ) for ( Object artifact1 : artifacts )
{ {
Artifact artifact = (Artifact) it.next(); Artifact artifact = (Artifact) artifact1;
writer.write( artifact.getId() ); writer.write( artifact.getId() );
writer.newLine(); writer.newLine();
getLog().info( "[MAVEN-CORE-IT-LOG] " + artifact.getId() ); getLog().info( "[MAVEN-CORE-IT-LOG] " + artifact.getId() );

View File

@ -19,24 +19,22 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.List;
/** /**
* Combines dependency collection with aggregation. The path parameters of this mojo support the token * Combines dependency collection with aggregation. The path parameters of this mojo support the token
* <code>&#64;artifactId&#64;</code> to dynamically adjust the output file for each project in the reactor whose * <code>&#64;artifactId&#64;</code> to dynamically adjust the output file for each project in the reactor whose
* dependencies are dumped. * dependencies are dumped.
* *
* @author Benjamin Bentmann
* @version $Id$
* @goal aggregate-test * @goal aggregate-test
* @requiresDependencyCollection test * @requiresDependencyCollection test
* @aggregator true * @aggregator true
*
* @author Benjamin Bentmann
* @version $Id$
*/ */
public class AggregateTestMojo public class AggregateTestMojo
extends AbstractDependencyMojo extends AbstractDependencyMojo
@ -47,14 +45,14 @@ public class AggregateTestMojo
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to * UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
* disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that * disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
* do not contribute to the class path. * do not contribute to the class path.
* *
* @parameter property="depres.projectArtifacts" * @parameter property="depres.projectArtifacts"
*/ */
private String projectArtifacts; private String projectArtifacts;
/** /**
* The Maven projects in the reactor. * The Maven projects in the reactor.
* *
* @parameter default-value="${reactorProjects}" * @parameter default-value="${reactorProjects}"
* @readonly * @readonly
*/ */
@ -62,7 +60,7 @@ public class AggregateTestMojo
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved. * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
*/ */
public void execute() public void execute()
@ -70,9 +68,9 @@ public class AggregateTestMojo
{ {
try try
{ {
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Object reactorProject : reactorProjects )
{ {
MavenProject project = (MavenProject) it.next(); MavenProject project = (MavenProject) reactorProject;
writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() ); writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() );

View File

@ -34,12 +34,11 @@ import java.security.DigestInputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
/** /**
* Provides common services for all mojos of this plugin. * Provides common services for all mojos of this plugin.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -49,7 +48,7 @@ public abstract class AbstractDependencyMojo
/** /**
* The current Maven project. * The current Maven project.
* *
* @parameter default-value="${project}" * @parameter default-value="${project}"
* @required * @required
* @readonly * @readonly
@ -62,16 +61,16 @@ public abstract class AbstractDependencyMojo
* this parameter to 1 to keep only the simple file name. The trimmed down paths will always use the forward slash * this parameter to 1 to keep only the simple file name. The trimmed down paths will always use the forward slash
* as directory separator. For non-positive values, the full/absolute path is returned, using the platform-specific * as directory separator. For non-positive values, the full/absolute path is returned, using the platform-specific
* separator. * separator.
* *
* @parameter property="depres.significantPathLevels" * @parameter property="depres.significantPathLevels"
*/ */
private int significantPathLevels; private int significantPathLevels;
/** /**
* Writes the specified artifacts to the given output file. * Writes the specified artifacts to the given output file.
* *
* @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or * @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or
* empty if the output file should not be written. * empty if the output file should not be written.
* @param artifacts The list of artifacts to write to the file, may be <code>null</code>. * @param artifacts The list of artifacts to write to the file, may be <code>null</code>.
* @throws MojoExecutionException If the output file could not be written. * @throws MojoExecutionException If the output file could not be written.
*/ */
@ -96,9 +95,9 @@ public abstract class AbstractDependencyMojo
if ( artifacts != null ) if ( artifacts != null )
{ {
for ( Iterator it = artifacts.iterator(); it.hasNext(); ) for ( Object artifact1 : artifacts )
{ {
Artifact artifact = (Artifact) it.next(); Artifact artifact = (Artifact) artifact1;
String id = getId( artifact ); String id = getId( artifact );
writer.write( id ); writer.write( id );
writer.newLine(); writer.newLine();
@ -134,9 +133,9 @@ public abstract class AbstractDependencyMojo
/** /**
* Writes the specified class path elements to the given output file. * Writes the specified class path elements to the given output file.
* *
* @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or * @param pathname The path to the output file, relative to the project base directory, may be <code>null</code> or
* empty if the output file should not be written. * empty if the output file should not be written.
* @param classPath The list of class path elements to write to the file, may be <code>null</code>. * @param classPath The list of class path elements to write to the file, may be <code>null</code>.
* @throws MojoExecutionException If the output file could not be written. * @throws MojoExecutionException If the output file could not be written.
*/ */
@ -161,9 +160,9 @@ public abstract class AbstractDependencyMojo
if ( classPath != null ) if ( classPath != null )
{ {
for ( Iterator it = classPath.iterator(); it.hasNext(); ) for ( Object aClassPath : classPath )
{ {
String element = it.next().toString(); String element = aClassPath.toString();
writer.write( stripLeadingDirs( element, significantPathLevels ) ); writer.write( stripLeadingDirs( element, significantPathLevels ) );
writer.newLine(); writer.newLine();
getLog().info( "[MAVEN-CORE-IT-LOG] " + element ); getLog().info( "[MAVEN-CORE-IT-LOG] " + element );
@ -206,9 +205,9 @@ public abstract class AbstractDependencyMojo
if ( classPath != null ) if ( classPath != null )
{ {
for ( Iterator it = classPath.iterator(); it.hasNext(); ) for ( Object aClassPath : classPath )
{ {
String element = it.next().toString(); String element = aClassPath.toString();
File jarFile = new File( element ); File jarFile = new File( element );
@ -274,8 +273,7 @@ public abstract class AbstractDependencyMojo
{ {
MessageDigest digester = MessageDigest.getInstance( "SHA-1" ); MessageDigest digester = MessageDigest.getInstance( "SHA-1" );
FileInputStream is = new FileInputStream( jarFile ); try ( FileInputStream is = new FileInputStream( jarFile ) )
try
{ {
DigestInputStream dis = new DigestInputStream( is, digester ); DigestInputStream dis = new DigestInputStream( is, digester );
@ -284,19 +282,14 @@ public abstract class AbstractDependencyMojo
// just read it // just read it
} }
} }
finally
{
is.close();
}
byte[] digest = digester.digest(); byte[] digest = digester.digest();
StringBuffer hash = new StringBuffer( digest.length * 2 ); StringBuilder hash = new StringBuilder( digest.length * 2 );
for ( int i = 0; i < digest.length; i++ ) for ( byte aDigest : digest )
{ {
@SuppressWarnings( "checkstyle:magicnumber" ) @SuppressWarnings( "checkstyle:magicnumber" ) int b = aDigest & 0xFF;
int b = digest[i] & 0xFF;
if ( b < 0x10 ) if ( b < 0x10 )
{ {
@ -341,7 +334,7 @@ public abstract class AbstractDependencyMojo
if ( pathname != null ) if ( pathname != null )
{ {
if ( pathname.indexOf( "@idx@" ) >= 0 ) if ( pathname.contains( "@idx@" ) )
{ {
// helps to distinguished forked executions of the same mojo // helps to distinguished forked executions of the same mojo
pathname = pathname.replaceAll( "@idx@", String.valueOf( nextCounter() ) ); pathname = pathname.replaceAll( "@idx@", String.valueOf( nextCounter() ) );
@ -366,7 +359,7 @@ public abstract class AbstractDependencyMojo
synchronized ( System.class ) synchronized ( System.class )
{ {
counter = Integer.getInteger( key, 0 ).intValue(); counter = Integer.getInteger( key, 0 );
System.setProperty( key, Integer.toString( counter + 1 ) ); System.setProperty( key, Integer.toString( counter + 1 ) );
} }

View File

@ -19,24 +19,22 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.List;
/** /**
* Combines dependency resolution with aggregation. The path parameters of this mojo support the token * Combines dependency resolution with aggregation. The path parameters of this mojo support the token
* <code>&#64;artifactId&#64;</code> to dynamically adjust the output file for each project in the reactor whose * <code>&#64;artifactId&#64;</code> to dynamically adjust the output file for each project in the reactor whose
* dependencies are dumped. * dependencies are dumped.
* *
* @author Benjamin Bentmann
* @version $Id$
* @goal aggregate-test * @goal aggregate-test
* @requiresDependencyResolution test * @requiresDependencyResolution test
* @aggregator true * @aggregator true
*
* @author Benjamin Bentmann
* @version $Id$
*/ */
public class AggregateTestMojo public class AggregateTestMojo
extends AbstractDependencyMojo extends AbstractDependencyMojo
@ -47,7 +45,7 @@ public class AggregateTestMojo
* UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to * UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
* disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that * disk. Unlike the test artifacts, the collection of project artifacts additionally contains those artifacts that
* do not contribute to the class path. * do not contribute to the class path.
* *
* @parameter property="depres.projectArtifacts" * @parameter property="depres.projectArtifacts"
*/ */
private String projectArtifacts; private String projectArtifacts;
@ -56,7 +54,7 @@ public class AggregateTestMojo
* The path to the output file for the test class path, relative to the project base directory. Each line of * The path to the output file for the test class path, relative to the project base directory. Each line of
* this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path * this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
* will not be written to disk. * will not be written to disk.
* *
* @parameter property="depres.testClassPath" * @parameter property="depres.testClassPath"
*/ */
private String testClassPath; private String testClassPath;
@ -65,14 +63,14 @@ public class AggregateTestMojo
* The path to the properties file for the checksums of the test class path elements, relative to the project base * The path to the properties file for the checksums of the test class path elements, relative to the project base
* directory. The (trimmed) path to a JAR is used as the property key, the property value is the SHA-1 hash of the * directory. The (trimmed) path to a JAR is used as the property key, the property value is the SHA-1 hash of the
* JAR. If not specified, the class path checksums will not be calculated. * JAR. If not specified, the class path checksums will not be calculated.
* *
* @parameter property="depres.testClassPathChecksums" * @parameter property="depres.testClassPathChecksums"
*/ */
private String testClassPathChecksums; private String testClassPathChecksums;
/** /**
* The Maven projects in the reactor. * The Maven projects in the reactor.
* *
* @parameter default-value="${reactorProjects}" * @parameter default-value="${reactorProjects}"
* @readonly * @readonly
*/ */
@ -80,7 +78,7 @@ public class AggregateTestMojo
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved. * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
*/ */
public void execute() public void execute()
@ -88,9 +86,9 @@ public class AggregateTestMojo
{ {
try try
{ {
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Object reactorProject : reactorProjects )
{ {
MavenProject project = (MavenProject) it.next(); MavenProject project = (MavenProject) reactorProject;
writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() ); writeArtifacts( filter( projectArtifacts, project ), project.getArtifacts() );
writeClassPath( filter( testClassPath, project ), project.getTestClasspathElements() ); writeClassPath( filter( testClassPath, project ), project.getTestClasspathElements() );

View File

@ -19,25 +19,23 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
/** /**
* Injects artifacts from the plugin into the dependency artifacts of the project. * Injects artifacts from the plugin into the dependency artifacts of the project.
* *
* @goal inject
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal inject
*/ */
public class InjectMojo public class InjectMojo
extends AbstractMojo extends AbstractMojo
@ -46,7 +44,7 @@ public class InjectMojo
/** /**
* The version-less keys in the form <code>groupId:artifactId</code> of the plugin artifacts to inject into * The version-less keys in the form <code>groupId:artifactId</code> of the plugin artifacts to inject into
* dependency artifacts of the project. * dependency artifacts of the project.
* *
* @parameter * @parameter
*/ */
private String[] artifacts; private String[] artifacts;
@ -59,7 +57,7 @@ public class InjectMojo
/** /**
* The current Maven project. * The current Maven project.
* *
* @parameter default-value="${project}" * @parameter default-value="${project}"
* @required * @required
* @readonly * @readonly
@ -68,14 +66,14 @@ public class InjectMojo
/** /**
* The artifact factory. * The artifact factory.
* *
* @component * @component
*/ */
private ArtifactFactory factory; private ArtifactFactory factory;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If an error occured. * @throws MojoExecutionException If an error occured.
*/ */
public void execute() public void execute()
@ -99,16 +97,17 @@ public class InjectMojo
dependencyArtifacts = new LinkedHashSet(); dependencyArtifacts = new LinkedHashSet();
} }
for ( Iterator it = pluginArtifacts.iterator(); it.hasNext(); ) for ( Object pluginArtifact : pluginArtifacts )
{ {
Artifact artifact = (Artifact) it.next(); Artifact artifact = (Artifact) pluginArtifact;
String artifactKey = artifact.getGroupId() + ':' + artifact.getArtifactId(); String artifactKey = artifact.getGroupId() + ':' + artifact.getArtifactId();
if ( artifactKeys.remove( artifactKey ) ) if ( artifactKeys.remove( artifactKey ) )
{ {
artifact = factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact =
artifact.getVersion(), Artifact.SCOPE_COMPILE, artifact.getType() ); factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
Artifact.SCOPE_COMPILE, artifact.getType() );
getLog().info( "[MAVEN-CORE-IT-LOG] Injecting dependency artifact " + artifact ); getLog().info( "[MAVEN-CORE-IT-LOG] Injecting dependency artifact " + artifact );

View File

@ -19,11 +19,6 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@ -36,13 +31,17 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
/** /**
* Attempts to resolve a single artifact from dependencies, and logs the results for the Verifier to look at. * Attempts to resolve a single artifact from dependencies, and logs the results for the Verifier to look at.
* *
* @goal resolve-one-dependency
* @requiresDependencyResolution runtime
* @author bimargulies * @author bimargulies
* @version $Id$ * @version $Id$
* @goal resolve-one-dependency
* @requiresDependencyResolution runtime
*/ */
public class ResolveOneDependencyMojo public class ResolveOneDependencyMojo
extends AbstractDependencyMojo extends AbstractDependencyMojo
@ -50,42 +49,46 @@ public class ResolveOneDependencyMojo
/** /**
* Group ID of the artifact to resolve. * Group ID of the artifact to resolve.
* *
* @parameter * @parameter
* @required * @required
*/ */
private String groupId; private String groupId;
/** /**
* Artifact ID of the artifact to resolve. * Artifact ID of the artifact to resolve.
* *
* @parameter * @parameter
* @required * @required
*/ */
private String artifactId; private String artifactId;
/** /**
* Version of the artifact to resolve. * Version of the artifact to resolve.
* *
* @parameter * @parameter
* @required * @required
*/ */
private String version; private String version;
/** /**
* Type of the artifact to resolve. * Type of the artifact to resolve.
* *
* @parameter * @parameter
* @required * @required
*/ */
private String type; private String type;
/** /**
* Classifier of the artifact to resolve. * Classifier of the artifact to resolve.
* *
* @parameter * @parameter
*/ */
private String classifier; private String classifier;
/** /**
* The scope to resolve for. * The scope to resolve for.
* *
* @parameter * @parameter
* @required * @required
*/ */
@ -111,7 +114,7 @@ public class ResolveOneDependencyMojo
/** /**
* The Maven session. * The Maven session.
* *
* @parameter default-value="${session}" * @parameter default-value="${session}"
* @readonly * @readonly
* @required * @required
@ -120,14 +123,14 @@ public class ResolveOneDependencyMojo
/** /**
* Metadata source object. * Metadata source object.
* *
* @component * @component
*/ */
private ArtifactMetadataSource metadataSource; private ArtifactMetadataSource metadataSource;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved. * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
*/ */
public void execute() public void execute()
@ -137,9 +140,8 @@ public class ResolveOneDependencyMojo
Artifact projectArtifact = project.getArtifact(); Artifact projectArtifact = project.getArtifact();
if ( projectArtifact == null ) if ( projectArtifact == null )
{ {
projectArtifact = projectArtifact = artifactFactory.createProjectArtifact( project.getGroupId(), project.getArtifactId(),
artifactFactory.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() );
project.getVersion() );
} }
Set depArtifacts = new HashSet(); Set depArtifacts = new HashSet();
@ -152,10 +154,10 @@ public class ResolveOneDependencyMojo
ArtifactResolutionResult result; ArtifactResolutionResult result;
try try
{ {
result = result = resolver.resolveTransitively( depArtifacts, projectArtifact, project.getManagedVersionMap(),
resolver.resolveTransitively( depArtifacts, projectArtifact, project.getManagedVersionMap(), session.getLocalRepository(),
session.getLocalRepository(), project.getRemoteArtifactRepositories(), project.getRemoteArtifactRepositories(), metadataSource,
metadataSource, scopeFilter ); scopeFilter );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
@ -173,13 +175,12 @@ public class ResolveOneDependencyMojo
else else
{ {
Set resolvedArtifacts = result.getArtifacts(); Set resolvedArtifacts = result.getArtifacts();
Iterator it = resolvedArtifacts.iterator();
/* /*
* Assume that the user of this is not interested in transitive deps and such, just report the one. * Assume that the user of this is not interested in transitive deps and such, just report the one.
*/ */
while ( it.hasNext() ) for ( Object resolvedArtifact : resolvedArtifacts )
{ {
Artifact a = (Artifact) it.next(); Artifact a = (Artifact) resolvedArtifact;
if ( a.equals( artifact ) ) if ( a.equals( artifact ) )
{ {
File file = a.getFile(); File file = a.getFile();

View File

@ -26,7 +26,6 @@ import org.apache.maven.plugin.MojoFailureException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -37,7 +36,7 @@ import java.util.Properties;
* value but can also be a collection/array or a bean-like object (from the Maven model). For example, the expression * value but can also be a collection/array or a bean-like object (from the Maven model). For example, the expression
* "project/dependencies/0" would extract the first project dependency. In more detail, this example expression could * "project/dependencies/0" would extract the first project dependency. In more detail, this example expression could
* output the following keys to the properties file: * output the following keys to the properties file:
* * <p/>
* <pre> * <pre>
* project.dependencies.0.groupId = org.apache.maven * project.dependencies.0.groupId = org.apache.maven
* project.dependencies.0.artifactId = maven-project * project.dependencies.0.artifactId = maven-project
@ -50,15 +49,14 @@ import java.util.Properties;
* project.dependencies.0.exclusions.1.groupId = plexus * project.dependencies.0.exclusions.1.groupId = plexus
* project.dependencies.0.exclusions.1.artifactId = plexus-container-default * project.dependencies.0.exclusions.1.artifactId = plexus-container-default
* </pre> * </pre>
* * <p/>
* Expressions that reference non-existing objects or use invalid collection/array indices silently resolve to * Expressions that reference non-existing objects or use invalid collection/array indices silently resolve to
* <code>null</code>. For collections and arrays, the special index "*" can be used to iterate all elements. * <code>null</code>. For collections and arrays, the special index "*" can be used to iterate all elements.
* *
* @goal eval
* @phase initialize
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal eval
* @phase initialize
*/ */
public class EvalMojo public class EvalMojo
extends AbstractMojo extends AbstractMojo
@ -66,7 +64,7 @@ public class EvalMojo
/** /**
* The project's base directory, used for manual path translation. * The project's base directory, used for manual path translation.
* *
* @parameter default-value="${basedir}" * @parameter default-value="${basedir}"
* @readonly * @readonly
*/ */
@ -76,28 +74,28 @@ public class EvalMojo
* The path to the output file for the properties with the expression values. For each expression given by the * The path to the output file for the properties with the expression values. For each expression given by the
* parameter {@link #expressions} an similar named properties key will be used to save the expression value. If an * parameter {@link #expressions} an similar named properties key will be used to save the expression value. If an
* expression evaluated to <code>null</code>, there will be no corresponding key in the properties file. * expression evaluated to <code>null</code>, there will be no corresponding key in the properties file.
* *
* @parameter property="expression.outputFile" * @parameter property="expression.outputFile"
*/ */
private File outputFile; private File outputFile;
/** /**
* The set of expressions to evaluate. * The set of expressions to evaluate.
* *
* @parameter * @parameter
*/ */
private String[] expressions; private String[] expressions;
/** /**
* The comma separated set of expressions to evaluate. * The comma separated set of expressions to evaluate.
* *
* @parameter property="expression.expressions" * @parameter property="expression.expressions"
*/ */
private String expressionList; private String expressionList;
/** /**
* The current Maven project against which expressions are evaluated. * The current Maven project against which expressions are evaluated.
* *
* @parameter default-value="${project}" * @parameter default-value="${project}"
* @readonly * @readonly
*/ */
@ -105,7 +103,7 @@ public class EvalMojo
/** /**
* The forked Maven project against which expressions are evaluated. * The forked Maven project against which expressions are evaluated.
* *
* @parameter default-value="${executedProject}" * @parameter default-value="${executedProject}"
* @readonly * @readonly
*/ */
@ -113,7 +111,7 @@ public class EvalMojo
/** /**
* The merged user/global settings of the current build against which expressions are evaluated. * The merged user/global settings of the current build against which expressions are evaluated.
* *
* @parameter default-value="${settings}" * @parameter default-value="${settings}"
* @readonly * @readonly
*/ */
@ -121,7 +119,7 @@ public class EvalMojo
/** /**
* The session context of the current build against which expressions are evaluated. * The session context of the current build against which expressions are evaluated.
* *
* @parameter default-value="${session}" * @parameter default-value="${session}"
* @readonly * @readonly
*/ */
@ -129,7 +127,7 @@ public class EvalMojo
/** /**
* The local repository of the current build against which expressions are evaluated. * The local repository of the current build against which expressions are evaluated.
* *
* @parameter default-value="${localRepository}" * @parameter default-value="${localRepository}"
* @readonly * @readonly
*/ */
@ -137,9 +135,9 @@ public class EvalMojo
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
* @throws MojoFailureException If the output file has not been set. * @throws MojoFailureException If the output file has not been set.
*/ */
public void execute() public void execute()
throws MojoExecutionException, MojoFailureException throws MojoExecutionException, MojoFailureException
@ -175,12 +173,11 @@ public class EvalMojo
contexts.put( "session", session ); contexts.put( "session", session );
contexts.put( "localRepository", localRepository ); contexts.put( "localRepository", localRepository );
for ( int i = 0; i < expressions.length; i++ ) for ( String expression : expressions )
{ {
Map values = ExpressionUtil.evaluate( expressions[i], contexts ); Map values = ExpressionUtil.evaluate( expression, contexts );
for ( Iterator it = values.keySet().iterator(); it.hasNext(); ) for ( Object key : values.keySet() )
{ {
Object key = it.next();
Object value = values.get( key ); Object value = values.get( key );
PropertyUtil.store( expressionProperties, key.toString().replace( '/', '.' ), value ); PropertyUtil.store( expressionProperties, key.toString().replace( '/', '.' ), value );
} }

View File

@ -32,7 +32,7 @@ import java.util.Map;
/** /**
* Assists in evaluating expressions. * Assists in evaluating expressions.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -55,11 +55,11 @@ class ExpressionUtil
* objects are available. For instance, if <code>contexts</code> maps the token "project" to a Maven project * objects are available. For instance, if <code>contexts</code> maps the token "project" to a Maven project
* instance, the expression "project/build/resources/0/directory" specifies the first resource directory of the * instance, the expression "project/build/resources/0/directory" specifies the first resource directory of the
* project. * project.
* *
* @param expression The expression to evaluate, may be <code>null</code>. * @param expression The expression to evaluate, may be <code>null</code>.
* @param context The object to start expression evaluation at, must not be <code>null</code>. * @param context The object to start expression evaluation at, must not be <code>null</code>.
* @return The values of the evaluation, indexed by expression, or an empty map if the segments could not be * @return The values of the evaluation, indexed by expression, or an empty map if the segments could not be
* evaluated. * evaluated.
*/ */
public static Map evaluate( String expression, Object context ) public static Map evaluate( String expression, Object context )
{ {
@ -76,12 +76,12 @@ class ExpressionUtil
/** /**
* Evaluates the given expression segments against the specified object. * Evaluates the given expression segments against the specified object.
* *
* @param prefix The expression prefix that led to the current context, must not be <code>null</code>. * @param prefix The expression prefix that led to the current context, must not be <code>null</code>.
* @param segments The expression segments to evaluate, must not be <code>null</code>. * @param segments The expression segments to evaluate, must not be <code>null</code>.
* @param context The object to evaluate the segments against, may be <code>null</code>. * @param context The object to evaluate the segments against, may be <code>null</code>.
* @return The values of the evaluation, indexed by expression, or an empty map if the segments could not be * @return The values of the evaluation, indexed by expression, or an empty map if the segments could not be
* evaluated. * evaluated.
*/ */
private static Map evaluate( String prefix, List segments, Object context ) private static Map evaluate( String prefix, List segments, Object context )
{ {
@ -142,12 +142,12 @@ class ExpressionUtil
} }
values = new LinkedHashMap(); values = new LinkedHashMap();
for ( Iterator it = targets.keySet().iterator(); it.hasNext(); ) for ( Object key : targets.keySet() )
{ {
Object key = it.next();
Object target = targets.get( key ); Object target = targets.get( key );
values.putAll( evaluate( concat( prefix, String.valueOf( key ) ), values.putAll(
segments.subList( 1, segments.size() ), target ) ); evaluate( concat( prefix, String.valueOf( key ) ), segments.subList( 1, segments.size() ),
target ) );
} }
} }
@ -161,8 +161,8 @@ class ExpressionUtil
/** /**
* Gets the value of a (public) bean property from the specified object. * Gets the value of a (public) bean property from the specified object.
* *
* @param context The object whose bean property should be retrieved, must not be <code>null</code>. * @param context The object whose bean property should be retrieved, must not be <code>null</code>.
* @param property The name of the bean property, must not be <code>null</code>. * @param property The name of the bean property, must not be <code>null</code>.
* @return The value of the bean property or <code>null</code> if the property does not exist. * @return The value of the bean property or <code>null</code> if the property does not exist.
*/ */
@ -220,7 +220,7 @@ class ExpressionUtil
method = type.getMethod( "get", OBJECT_PARAM ); method = type.getMethod( "get", OBJECT_PARAM );
} }
method.setAccessible( true ); method.setAccessible( true );
value = method.invoke( context, new Object[] { property } ); value = method.invoke( context, new Object[]{ property } );
} }
catch ( NoSuchMethodException e3 ) catch ( NoSuchMethodException e3 )
{ {
@ -234,7 +234,7 @@ class ExpressionUtil
{ {
if ( "length".equals( property ) && type.isArray() ) if ( "length".equals( property ) && type.isArray() )
{ {
value = new Integer( Array.getLength( context ) ); value = Array.getLength( context );
} }
else else
{ {

View File

@ -35,7 +35,7 @@ import java.util.Properties;
/** /**
* Assists in serializing primitives and beans into properties for later inspection/verification. * Assists in serializing primitives and beans into properties for later inspection/verification.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
*/ */
@ -49,10 +49,10 @@ class PropertyUtil
/** /**
* Serializes the specified object into the given properties, using the provided key. The object may be a scalar * Serializes the specified object into the given properties, using the provided key. The object may be a scalar
* value like a string or some array/collection/map or a bean. * value like a string or some array/collection/map or a bean.
* *
* @param props The properties to serialize into, must not be <code>null</code>. * @param props The properties to serialize into, must not be <code>null</code>.
* @param key The key to use for serialization of the object data, must not be <code>null</code>. * @param key The key to use for serialization of the object data, must not be <code>null</code>.
* @param obj The object to serialize, may be <code>null</code>. * @param obj The object to serialize, may be <code>null</code>.
*/ */
public static void store( Properties props, String key, Object obj ) public static void store( Properties props, String key, Object obj )
{ {
@ -62,12 +62,12 @@ class PropertyUtil
/** /**
* Serializes the specified object into the given properties, using the provided key. The object may be a scalar * Serializes the specified object into the given properties, using the provided key. The object may be a scalar
* value like a string or some array/collection/map or a bean. * value like a string or some array/collection/map or a bean.
* *
* @param props The properties to serialize into, must not be <code>null</code>. * @param props The properties to serialize into, must not be <code>null</code>.
* @param key The key to use for serialization of the object data, must not be <code>null</code>. * @param key The key to use for serialization of the object data, must not be <code>null</code>.
* @param obj The object to serialize, may be <code>null</code>. * @param obj The object to serialize, may be <code>null</code>.
* @param visited The set/stack of already visited objects, used to detect back references in the object graph, must * @param visited The set/stack of already visited objects, used to detect back references in the object graph, must
* not be <code>null</code>. * not be <code>null</code>.
*/ */
private static void store( Properties props, String key, Object obj, Collection visited ) private static void store( Properties props, String key, Object obj, Collection visited )
{ {
@ -132,21 +132,19 @@ class PropertyUtil
props.put( key + ".children", Integer.toString( children.length ) ); props.put( key + ".children", Integer.toString( children.length ) );
Map indices = new HashMap(); Map indices = new HashMap();
for ( int i = 0; i < children.length; i++ ) for ( Object child : children )
{ {
Object child = children[i];
String name = (String) getName.invoke( child, NO_ARGS ); String name = (String) getName.invoke( child, NO_ARGS );
Integer index = (Integer) indices.get( name ); Integer index = (Integer) indices.get( name );
if ( index == null ) if ( index == null )
{ {
index = new Integer( 0 ); index = 0;
} }
store( props, key + ".children." + name + "." + index, child, visited ); store( props, key + ".children." + name + "." + index, child, visited );
indices.put( name, new Integer( index.intValue() + 1 ) ); indices.put( name, index + 1 );
} }
} }
catch ( Exception e ) catch ( Exception e )
@ -158,13 +156,12 @@ class PropertyUtil
{ {
Class type = obj.getClass(); Class type = obj.getClass();
Method[] methods = type.getMethods(); Method[] methods = type.getMethods();
for ( int i = 0; i < methods.length; i++ ) for ( Method method : methods )
{ {
Method method = methods[i];
if ( Modifier.isStatic( method.getModifiers() ) || method.getParameterTypes().length > 0 if ( Modifier.isStatic( method.getModifiers() ) || method.getParameterTypes().length > 0
|| !method.getName().matches( "(get|is)\\p{Lu}.*" ) || method.getName().endsWith( "AsMap" ) || !method.getName().matches( "(get|is)\\p{Lu}.*" ) || method.getName().endsWith( "AsMap" )
|| Class.class.isAssignableFrom( method.getReturnType() ) || Class.class.isAssignableFrom( method.getReturnType() ) || Object.class.equals(
|| Object.class.equals( method.getReturnType() ) ) method.getReturnType() ) )
{ {
continue; continue;
} }
@ -186,7 +183,7 @@ class PropertyUtil
/** /**
* Derives the bean property name from the specified method for its getter. * Derives the bean property name from the specified method for its getter.
* *
* @param methodName The method name of the property's getter, must not be <code>null</code>. * @param methodName The method name of the property's getter, must not be <code>null</code>.
* @return The property name, never <code>null</code>. * @return The property name, never <code>null</code>.
*/ */
@ -206,9 +203,9 @@ class PropertyUtil
/** /**
* Writes the specified properties to the given file. * Writes the specified properties to the given file.
* *
* @param props The properties to write, must not be <code>null</code>. * @param props The properties to write, must not be <code>null</code>.
* @param file The output file for the properties, must not be <code>null</code>. * @param file The output file for the properties, must not be <code>null</code>.
* @throws IOException If the properties could not be written to the file. * @throws IOException If the properties could not be written to the file.
*/ */
public static void write( Properties props, File file ) public static void write( Properties props, File file )

View File

@ -19,13 +19,13 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import junit.framework.TestCase;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase;
/** /**
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
@ -36,8 +36,8 @@ public class ExpressionUtilTest
public void testEvaluate() public void testEvaluate()
{ {
Object array = new String[] { "one", "two", "three" }; Object array = new String[]{ "one", "two", "three" };
Object list = Arrays.asList( new String[] { "0", "-1", "-2" } ); Object list = Arrays.asList( new String[]{ "0", "-1", "-2" } );
Object map = Collections.singletonMap( "some.key", "value" ); Object map = Collections.singletonMap( "some.key", "value" );
Object bean = new BeanTwo(); Object bean = new BeanTwo();
@ -54,9 +54,9 @@ public class ExpressionUtilTest
assertSame( bean, evaluate( "bean", contexts ) ); assertSame( bean, evaluate( "bean", contexts ) );
assertNull( evaluate( "no-root", contexts ) ); assertNull( evaluate( "no-root", contexts ) );
assertEquals( new Integer( 3 ), evaluate( "array/length", contexts ) ); assertEquals( 3, evaluate( "array/length", contexts ) );
assertEquals( "three", evaluate( "array/2", contexts ) ); assertEquals( "three", evaluate( "array/2", contexts ) );
assertEquals( new Integer( 5 ), evaluate( "array/2/length", contexts ) ); assertEquals( 5, evaluate( "array/2/length", contexts ) );
assertNull( evaluate( "array/invalid", contexts ) ); assertNull( evaluate( "array/invalid", contexts ) );
assertNull( evaluate( "array/-1", contexts ) ); assertNull( evaluate( "array/-1", contexts ) );
assertNull( evaluate( "array/999", contexts ) ); assertNull( evaluate( "array/999", contexts ) );
@ -65,7 +65,7 @@ public class ExpressionUtilTest
assertEquals( "two", ExpressionUtil.evaluate( "array/*", contexts ).get( "array/1" ) ); assertEquals( "two", ExpressionUtil.evaluate( "array/*", contexts ).get( "array/1" ) );
assertEquals( "three", ExpressionUtil.evaluate( "array/*", contexts ).get( "array/2" ) ); assertEquals( "three", ExpressionUtil.evaluate( "array/*", contexts ).get( "array/2" ) );
assertEquals( new Integer( 3 ), evaluate( "list/size", contexts ) ); assertEquals( 3, evaluate( "list/size", contexts ) );
assertEquals( "-2", evaluate( "list/2", contexts ) ); assertEquals( "-2", evaluate( "list/2", contexts ) );
assertNull( evaluate( "list/invalid", contexts ) ); assertNull( evaluate( "list/invalid", contexts ) );
assertNull( evaluate( "list/-1", contexts ) ); assertNull( evaluate( "list/-1", contexts ) );
@ -75,7 +75,7 @@ public class ExpressionUtilTest
assertEquals( "-1", ExpressionUtil.evaluate( "list/*", contexts ).get( "list/1" ) ); assertEquals( "-1", ExpressionUtil.evaluate( "list/*", contexts ).get( "list/1" ) );
assertEquals( "-2", ExpressionUtil.evaluate( "list/*", contexts ).get( "list/2" ) ); assertEquals( "-2", ExpressionUtil.evaluate( "list/*", contexts ).get( "list/2" ) );
assertEquals( new Integer( 1 ), evaluate( "map/size", contexts ) ); assertEquals( 1, evaluate( "map/size", contexts ) );
assertEquals( "value", evaluate( "map/some.key", contexts ) ); assertEquals( "value", evaluate( "map/some.key", contexts ) );
assertNull( evaluate( "map/invalid", contexts ) ); assertNull( evaluate( "map/invalid", contexts ) );
@ -104,7 +104,7 @@ public class ExpressionUtilTest
assertEquals( bean2.field, ExpressionUtil.getProperty( bean2, "field" ) ); assertEquals( bean2.field, ExpressionUtil.getProperty( bean2, "field" ) );
assertSame( bean2.bean, ExpressionUtil.getProperty( bean2, "bean" ) ); assertSame( bean2.bean, ExpressionUtil.getProperty( bean2, "bean" ) );
assertEquals( new Integer( 0 ), ExpressionUtil.getProperty( new String[0], "length" ) ); assertEquals( 0, ExpressionUtil.getProperty( new String[0], "length" ) );
} }
public static class BeanOne public static class BeanOne

View File

@ -19,13 +19,13 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import junit.framework.TestCase;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Properties; import java.util.Properties;
import junit.framework.TestCase;
/** /**
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
@ -40,7 +40,7 @@ public class PropertyUtilTest
PropertyUtil.store( props, "null", null ); PropertyUtil.store( props, "null", null );
PropertyUtil.store( props, "string", "str" ); PropertyUtil.store( props, "string", "str" );
PropertyUtil.store( props, "boolean", Boolean.TRUE ); PropertyUtil.store( props, "boolean", Boolean.TRUE );
PropertyUtil.store( props, "int", new Integer( 7 ) ); PropertyUtil.store( props, "int", 7 );
PropertyUtil.store( props, "file", new File( "pom.xml" ) ); PropertyUtil.store( props, "file", new File( "pom.xml" ) );
assertNull( props.get( "null" ) ); assertNull( props.get( "null" ) );
@ -54,7 +54,7 @@ public class PropertyUtilTest
public void testStoreArray() public void testStoreArray()
{ {
Properties props = new Properties(); Properties props = new Properties();
PropertyUtil.store( props, "arr", new String[] { "one", "two" } ); PropertyUtil.store( props, "arr", new String[]{ "one", "two" } );
assertEquals( "2", props.get( "arr" ) ); assertEquals( "2", props.get( "arr" ) );
assertEquals( "one", props.get( "arr.0" ) ); assertEquals( "one", props.get( "arr.0" ) );
@ -65,7 +65,7 @@ public class PropertyUtilTest
public void testStoreList() public void testStoreList()
{ {
Properties props = new Properties(); Properties props = new Properties();
PropertyUtil.store( props, "arr", Arrays.asList( new String[] { "one", "two" } ) ); PropertyUtil.store( props, "arr", Arrays.asList( new String[]{ "one", "two" } ) );
assertEquals( "2", props.get( "arr" ) ); assertEquals( "2", props.get( "arr" ) );
assertEquals( "one", props.get( "arr.0" ) ); assertEquals( "one", props.get( "arr.0" ) );

View File

@ -19,17 +19,15 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.util.Iterator;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.List;
/** /**
* @goal fork-goal-aggregator * @goal fork-goal-aggregator
* @aggregator true * @aggregator true
*
* @execute goal="touch" * @execute goal="touch"
*/ */
public class ForkGoalAggregatorMojo public class ForkGoalAggregatorMojo
@ -48,22 +46,23 @@ public class ForkGoalAggregatorMojo
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Object reactorProject : reactorProjects )
{ {
MavenProject executedProject = ( (MavenProject) it.next() ).getExecutionProject(); MavenProject executedProject = ( (MavenProject) reactorProject ).getExecutionProject();
if ( !executedProject.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) ) if ( !executedProject.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) )
{ {
throw new MojoExecutionException( "Unexpected result, final name of executed project " throw new MojoExecutionException(
+ executedProject + " is " + executedProject.getBuild().getFinalName() + " (should be \'" "Unexpected result, final name of executed project " + executedProject + " is "
+ TouchMojo.FINAL_NAME + "\')." ); + executedProject.getBuild().getFinalName() + " (should be \'" + TouchMojo.FINAL_NAME
+ "\')." );
} }
} }
if ( project.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) ) if ( project.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) )
{ {
throw new MojoExecutionException( "forked project was polluted. (should NOT be \'" + TouchMojo.FINAL_NAME throw new MojoExecutionException(
+ "\')." ); "forked project was polluted. (should NOT be \'" + TouchMojo.FINAL_NAME + "\')." );
} }
} }
} }

View File

@ -19,17 +19,15 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.util.Iterator;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.List;
/** /**
* @goal fork-lifecycle-aggregator * @goal fork-lifecycle-aggregator
* @aggregator true * @aggregator true
*
* @execute phase="generate-sources" lifecycle="foo" * @execute phase="generate-sources" lifecycle="foo"
*/ */
public class ForkLifecycleAggregatorMojo public class ForkLifecycleAggregatorMojo
@ -49,22 +47,23 @@ public class ForkLifecycleAggregatorMojo
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
for ( Iterator it = reactorProjects.iterator(); it.hasNext(); ) for ( Object reactorProject : reactorProjects )
{ {
MavenProject executedProject = ( (MavenProject) it.next() ).getExecutionProject(); MavenProject executedProject = ( (MavenProject) reactorProject ).getExecutionProject();
if ( !executedProject.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) ) if ( !executedProject.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) )
{ {
throw new MojoExecutionException( "Unexpected result, final name of executed project " throw new MojoExecutionException(
+ executedProject + " is " + executedProject.getBuild().getFinalName() + " (should be \'" "Unexpected result, final name of executed project " + executedProject + " is "
+ TouchMojo.FINAL_NAME + "\')." ); + executedProject.getBuild().getFinalName() + " (should be \'" + TouchMojo.FINAL_NAME
+ "\')." );
} }
} }
if ( project.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) ) if ( project.getBuild().getFinalName().equals( TouchMojo.FINAL_NAME ) )
{ {
throw new MojoExecutionException( "forked project was polluted. (should NOT be \'" + TouchMojo.FINAL_NAME throw new MojoExecutionException(
+ "\')." ); "forked project was polluted. (should NOT be \'" + TouchMojo.FINAL_NAME + "\')." );
} }
} }

View File

@ -23,12 +23,11 @@ import org.apache.maven.plugin.MojoExecutionException;
/** /**
* Appends a separator line to the log file. * Appends a separator line to the log file.
* *
* @goal log-separator
* @phase initialize
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal log-separator
* @phase initialize
*/ */
public class LogSeparatorMojo public class LogSeparatorMojo
extends AbstractLogMojo extends AbstractLogMojo
@ -36,20 +35,20 @@ public class LogSeparatorMojo
/** /**
* The length of the separator line. * The length of the separator line.
* *
* @parameter property="log.length" default-value="80" * @parameter property="log.length" default-value="80"
*/ */
private int length; private int length;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
StringBuffer buffer = new StringBuffer( length ); StringBuilder buffer = new StringBuilder( length );
for ( int i = 0; i < length; i++ ) for ( int i = 0; i < length; i++ )
{ {
buffer.append( '-' ); buffer.append( '-' );

View File

@ -19,22 +19,21 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/** /**
* Requires a component with a non-default role hint and dumps this hint to a properties file. * Requires a component with a non-default role hint and dumps this hint to a properties file.
* *
* @goal it
* @phase initialize
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal it
* @phase initialize
*/ */
public class ItMojo public class ItMojo
extends AbstractMojo extends AbstractMojo
@ -42,21 +41,21 @@ public class ItMojo
/** /**
* The path to the output file. * The path to the output file.
* *
* @parameter property="touch.outputFile" default-value="target/comp.properties" * @parameter property="touch.outputFile" default-value="target/comp.properties"
*/ */
private File outputFile; private File outputFile;
/** /**
* NOTE: We don't specify a role hint here! * NOTE: We don't specify a role hint here!
* *
* @component * @component
*/ */
private Component component; private Component component;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -72,15 +71,10 @@ public class ItMojo
try try
{ {
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
FileOutputStream os = new FileOutputStream( outputFile ); try ( FileOutputStream os = new FileOutputStream( outputFile ) )
try
{ {
props.store( os, "MAVEN-CORE-IT-LOG" ); props.store( os, "MAVEN-CORE-IT-LOG" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -29,7 +29,7 @@ import java.io.OutputStreamWriter;
/** /**
* Appends a message to an UTF-8 encoded plain text file. * Appends a message to an UTF-8 encoded plain text file.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @goal append * @goal append
*/ */
@ -58,16 +58,12 @@ public class AppendMojo
getLog().info( "[MAVEN-CORE-IT-LOG] " + message ); getLog().info( "[MAVEN-CORE-IT-LOG] " + message );
OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( outputFile, true ), "UTF-8" ); try ( OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( outputFile, true ),
try "UTF-8" ) )
{ {
writer.write( message ); writer.write( message );
writer.write( "\n" ); writer.write( "\n" );
} }
finally
{
writer.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,14 +19,14 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/** /**
* Check that we correctly use the implementation parameter. * Check that we correctly use the implementation parameter.
* *
@ -38,14 +38,14 @@ public class ParameterImplementationMojo
/** /**
* The path to the properties file for the parameter information. * The path to the properties file for the parameter information.
* *
* @parameter * @parameter
*/ */
private File outputFile; private File outputFile;
/** /**
* A parameter whose type is an interface but with a default implementation class. * A parameter whose type is an interface but with a default implementation class.
* *
* @parameter implementation="org.apache.maven.plugin.coreit.sub.AnImplementation" * @parameter implementation="org.apache.maven.plugin.coreit.sub.AnImplementation"
*/ */
private AnInterface theParameter; private AnInterface theParameter;
@ -69,15 +69,10 @@ public class ParameterImplementationMojo
{ {
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
FileOutputStream os = new FileOutputStream( outputFile ); try ( FileOutputStream os = new FileOutputStream( outputFile ) )
try
{ {
props.store( os, "[MAVEN-CORE-IT-LOG]" ); props.store( os, "[MAVEN-CORE-IT-LOG]" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,15 +19,15 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import java.util.Enumeration;
import java.util.Properties;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.Enumeration;
import java.util.Properties;
/** /**
* @goal verify-property * @goal verify-property
* @phase validate * @phase validate
@ -65,7 +65,7 @@ public class PropertyInterpolationVerifierMojo
throw new MojoExecutionException( "Properties do not match: Name = " + name + ", Value = " + value ); throw new MojoExecutionException( "Properties do not match: Name = " + name + ", Value = " + value );
} }
if ( value.indexOf( "${" ) > -1 ) if ( value.contains( "${" ) )
{ {
throw new MojoExecutionException( "Unresolved value: Name = " + name + ", Value = " + value ); throw new MojoExecutionException( "Unresolved value: Name = " + name + ", Value = " + value );
} }

View File

@ -38,7 +38,7 @@ public abstract class AbstractPomMojo
/** /**
* The project builder. * The project builder.
* *
* @component * @component
*/ */
protected MavenProjectBuilder builder; protected MavenProjectBuilder builder;
@ -69,15 +69,10 @@ public abstract class AbstractPomMojo
{ {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
FileOutputStream os = new FileOutputStream( file ); try ( FileOutputStream os = new FileOutputStream( file ) )
try
{ {
props.store( os, "[MAVEN-CORE-IT-LOG]" ); props.store( os, "[MAVEN-CORE-IT-LOG]" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -28,9 +28,9 @@ import java.util.Properties;
/** /**
* Builds the local POMs. * Builds the local POMs.
* *
* @goal local-pom
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @goal local-pom
*/ */
public class BuildLocalPomMojo public class BuildLocalPomMojo
extends AbstractPomMojo extends AbstractPomMojo
@ -38,14 +38,14 @@ public class BuildLocalPomMojo
/** /**
* The properties file to dump the POM info to. * The properties file to dump the POM info to.
* *
* @parameter default-value="target/pom.properties" * @parameter default-value="target/pom.properties"
*/ */
private File propertiesFile; private File propertiesFile;
/** /**
* The local repository. * The local repository.
* *
* @parameter default-value="${localRepository}" * @parameter default-value="${localRepository}"
* @readonly * @readonly
* @required * @required
@ -54,14 +54,14 @@ public class BuildLocalPomMojo
/** /**
* The POM files to build. * The POM files to build.
* *
* @parameter * @parameter
*/ */
private File[] files; private File[] files;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the artifact file has not been set. * @throws MojoFailureException If the artifact file has not been set.
*/ */
public void execute() public void execute()
@ -73,10 +73,8 @@ public class BuildLocalPomMojo
if ( files != null ) if ( files != null )
{ {
for ( int i = 0; i < files.length; i++ ) for ( File file : files )
{ {
File file = files[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Building " + file ); getLog().info( "[MAVEN-CORE-IT-LOG] Building " + file );
try try

View File

@ -32,11 +32,10 @@ import java.util.Properties;
/** /**
* Builds the remote POMs of user-specified artifacts. This mimics in part the Maven Remote Resources Plugin. * Builds the remote POMs of user-specified artifacts. This mimics in part the Maven Remote Resources Plugin.
* *
* @goal remote-pom
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal remote-pom
*/ */
public class BuildRemotePomMojo public class BuildRemotePomMojo
extends AbstractPomMojo extends AbstractPomMojo
@ -44,14 +43,14 @@ public class BuildRemotePomMojo
/** /**
* The properties file to dump the POM info to. * The properties file to dump the POM info to.
* *
* @parameter default-value="target/pom.properties" * @parameter default-value="target/pom.properties"
*/ */
private File propertiesFile; private File propertiesFile;
/** /**
* The local repository. * The local repository.
* *
* @parameter default-value="${localRepository}" * @parameter default-value="${localRepository}"
* @readonly * @readonly
* @required * @required
@ -60,7 +59,7 @@ public class BuildRemotePomMojo
/** /**
* The remote repositories of the current Maven project. * The remote repositories of the current Maven project.
* *
* @parameter default-value="${project.remoteArtifactRepositories}" * @parameter default-value="${project.remoteArtifactRepositories}"
* @readonly * @readonly
* @required * @required
@ -69,21 +68,21 @@ public class BuildRemotePomMojo
/** /**
* The artifact factory. * The artifact factory.
* *
* @component * @component
*/ */
private ArtifactFactory factory; private ArtifactFactory factory;
/** /**
* The dependencies to resolve. * The dependencies to resolve.
* *
* @parameter * @parameter
*/ */
private Dependency[] dependencies; private Dependency[] dependencies;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the artifact file has not been set. * @throws MojoFailureException If the artifact file has not been set.
*/ */
public void execute() public void execute()
@ -95,10 +94,8 @@ public class BuildRemotePomMojo
if ( dependencies != null ) if ( dependencies != null )
{ {
for ( int i = 0; i < dependencies.length; i++ ) for ( Dependency dependency : dependencies )
{ {
Dependency dependency = dependencies[i];
Artifact artifact = Artifact artifact =
factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
dependency.getVersion(), dependency.getType(), dependency.getVersion(), dependency.getType(),

View File

@ -19,6 +19,9 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -26,17 +29,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/** /**
* Requires a singleton component in various ways and dumps the ids to a properties file. * Requires a singleton component in various ways and dumps the ids to a properties file.
* *
* @goal it
* @phase initialize
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal it
* @phase initialize
*/ */
public class ItMojo public class ItMojo
extends AbstractMojo extends AbstractMojo
@ -44,42 +43,42 @@ public class ItMojo
/** /**
* The path to the output file. * The path to the output file.
* *
* @parameter property="touch.outputFile" default-value="target/comp.properties" * @parameter property="touch.outputFile" default-value="target/comp.properties"
*/ */
private File outputFile; private File outputFile;
/** /**
* Component lookup without role hint. * Component lookup without role hint.
* *
* @component * @component
*/ */
private Component componentWithoutRoleHint; private Component componentWithoutRoleHint;
/** /**
* Component lookup with explicit role hint. * Component lookup with explicit role hint.
* *
* @component roleHint="default" * @component roleHint="default"
*/ */
private Component componentWithRoleHint; private Component componentWithRoleHint;
/** /**
* Component lookup via active map. * Component lookup via active map.
* *
* @component role="org.apache.maven.plugin.coreit.Component" * @component role="org.apache.maven.plugin.coreit.Component"
*/ */
private Map componentMap; private Map componentMap;
/** /**
* Component lookup via active list. * Component lookup via active list.
* *
* @component role="org.apache.maven.plugin.coreit.Component" * @component role="org.apache.maven.plugin.coreit.Component"
*/ */
private List componentList; private List componentList;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -104,15 +103,10 @@ public class ItMojo
try try
{ {
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
FileOutputStream os = new FileOutputStream( outputFile ); try ( FileOutputStream os = new FileOutputStream( outputFile ) )
try
{ {
props.store( os, "MAVEN-CORE-IT-LOG" ); props.store( os, "MAVEN-CORE-IT-LOG" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -34,13 +34,12 @@ import java.util.Locale;
/** /**
* Generates the available/configured reports. * Generates the available/configured reports.
* *
* @author Benjamin Bentmann
* @version $Id$
* @goal generate * @goal generate
* @phase site * @phase site
* @requiresReports true * @requiresReports true
*
* @author Benjamin Bentmann
* @version $Id$
*/ */
public class GenerateMojo public class GenerateMojo
extends AbstractMojo extends AbstractMojo
@ -48,28 +47,28 @@ public class GenerateMojo
/** /**
* The path to the output directory of the site. * The path to the output directory of the site.
* *
* @parameter default-value="${project.reporting.outputDirectory}" * @parameter default-value="${project.reporting.outputDirectory}"
*/ */
private File outputDirectory; private File outputDirectory;
/** /**
* The language for the reports. * The language for the reports.
* *
* @parameter default-value="en" * @parameter default-value="en"
*/ */
private String language = "en"; private String language = "en";
/** /**
* A flag whether to ignore errors from reports and continue the generation. * A flag whether to ignore errors from reports and continue the generation.
* *
* @parameter default-value="false" * @parameter default-value="false"
*/ */
private boolean ignoreErrors; private boolean ignoreErrors;
/** /**
* The reports configured for the current build. * The reports configured for the current build.
* *
* @parameter default-value="${reports}" * @parameter default-value="${reports}"
* @required * @required
* @readonly * @readonly
@ -78,7 +77,7 @@ public class GenerateMojo
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoExecutionException If the output file could not be created. * @throws MojoExecutionException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -99,11 +98,11 @@ public class GenerateMojo
} }
}; };
Sink sink = (Sink) Proxy.newProxyInstance( getClass().getClassLoader(), new Class[] { Sink.class }, handler ); Sink sink = (Sink) Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{ Sink.class }, handler );
for ( int i = 0; i < reports.size(); i++ ) for ( Object report1 : reports )
{ {
MavenReport report = (MavenReport) reports.get( i ); MavenReport report = (MavenReport) report1;
if ( report.canGenerateReport() ) if ( report.canGenerateReport() )
{ {

View File

@ -19,6 +19,12 @@ package org.apache.maven.plugin.coreit;
* under the License. * under the License.
*/ */
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.toolchain.ToolchainManagerPrivate;
import org.apache.maven.toolchain.ToolchainPrivate;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -29,12 +35,6 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.toolchain.ToolchainManagerPrivate;
import org.apache.maven.toolchain.ToolchainPrivate;
/** /**
* @goal toolchain * @goal toolchain
* @phase validate * @phase validate
@ -50,7 +50,7 @@ public class CoreItMojo
/** /**
* The current Maven session holding the selected toolchain. * The current Maven session holding the selected toolchain.
* *
* @parameter default-value="${session}" * @parameter default-value="${session}"
* @required * @required
* @readonly * @readonly
@ -59,28 +59,28 @@ public class CoreItMojo
/** /**
* The path to the output file for the properties. * The path to the output file for the properties.
* *
* @parameter property="toolchain.outputFile" default-value="${project.build.directory}/toolchains.properties" * @parameter property="toolchain.outputFile" default-value="${project.build.directory}/toolchains.properties"
*/ */
private File outputFile; private File outputFile;
/** /**
* The type identifier of the toolchain, e.g. "jdk". * The type identifier of the toolchain, e.g. "jdk".
* *
* @parameter property="toolchain.type" * @parameter property="toolchain.type"
*/ */
private String type; private String type;
/** /**
* The name of the tool, e.g. "javac". * The name of the tool, e.g. "javac".
* *
* @parameter property="toolchain.tool" * @parameter property="toolchain.tool"
*/ */
private String tool; private String tool;
/** /**
* The zero-based index of the toolchain to select and store in the build context. * The zero-based index of the toolchain to select and store in the build context.
* *
* @parameter property="toolchain.selected" * @parameter property="toolchain.selected"
*/ */
private int selected; private int selected;
@ -101,8 +101,8 @@ public class CoreItMojo
} }
else else
{ {
getLog().warn( "[MAVEN-CORE-IT-LOG] Toolchain #" + selected + " can't be selected, found only " getLog().warn(
+ tcs.length ); "[MAVEN-CORE-IT-LOG] Toolchain #" + selected + " can't be selected, found only " + tcs.length );
} }
} }
@ -157,28 +157,20 @@ public class CoreItMojo
try try
{ {
// try 2.x style API // try 2.x style API
Method oldMethod = managerClass.getMethod( "getToolchainsForType", new Class[] { String.class } ); Method oldMethod = managerClass.getMethod( "getToolchainsForType", new Class[]{ String.class } );
return (ToolchainPrivate[]) oldMethod.invoke( toolchainManager, new Object[] { type } ); return (ToolchainPrivate[]) oldMethod.invoke( toolchainManager, new Object[]{ type } );
} }
catch ( NoSuchMethodException e ) catch ( NoSuchMethodException e )
{ {
// try 3.x style API // try 3.x style API
Method newMethod = Method newMethod =
managerClass.getMethod( "getToolchainsForType", new Class[] { String.class, MavenSession.class } ); managerClass.getMethod( "getToolchainsForType", new Class[]{ String.class, MavenSession.class } );
return (ToolchainPrivate[]) newMethod.invoke( toolchainManager, new Object[] { type, session } ); return (ToolchainPrivate[]) newMethod.invoke( toolchainManager, new Object[]{ type, session } );
} }
} }
catch ( NoSuchMethodException e ) catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException e )
{
throw new MojoExecutionException( "Incompatible toolchain API", e );
}
catch ( IllegalAccessException e )
{
throw new MojoExecutionException( "Incompatible toolchain API", e );
}
catch ( InvocationTargetException e )
{ {
throw new MojoExecutionException( "Incompatible toolchain API", e ); throw new MojoExecutionException( "Incompatible toolchain API", e );
} }

View File

@ -33,12 +33,11 @@ import java.util.Properties;
/** /**
* Dumps the authentication info registered with the wagon manager for a server to a properties file. * Dumps the authentication info registered with the wagon manager for a server to a properties file.
* *
* @goal dump-auth
* @phase validate
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal dump-auth
* @phase validate
*/ */
public class DumpAuthMojo public class DumpAuthMojo
extends AbstractMojo extends AbstractMojo
@ -46,7 +45,7 @@ public class DumpAuthMojo
/** /**
* Project base directory used for manual path alignment. * Project base directory used for manual path alignment.
* *
* @parameter default-value="${basedir}" * @parameter default-value="${basedir}"
* @readonly * @readonly
*/ */
@ -54,28 +53,28 @@ public class DumpAuthMojo
/** /**
* The Wagon manager used to retrieve authentication infos. * The Wagon manager used to retrieve authentication infos.
* *
* @component * @component
*/ */
private WagonManager wagonManager; private WagonManager wagonManager;
/** /**
* The path to the properties file used to dump the auth infos. * The path to the properties file used to dump the auth infos.
* *
* @parameter property="wagon.propertiesFile" * @parameter property="wagon.propertiesFile"
*/ */
private File propertiesFile; private File propertiesFile;
/** /**
* The set of server identifiers whose auth infos should be dumped. * The set of server identifiers whose auth infos should be dumped.
* *
* @parameter * @parameter
*/ */
private String[] serverIds; private String[] serverIds;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the output file could not be created. * @throws MojoFailureException If the output file could not be created.
*/ */
public void execute() public void execute()
@ -83,9 +82,8 @@ public class DumpAuthMojo
{ {
Properties authProperties = new Properties(); Properties authProperties = new Properties();
for ( int i = 0; i < serverIds.length; i++ ) for ( String serverId : serverIds )
{ {
String serverId = serverIds[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Getting authentication info for server " + serverId ); getLog().info( "[MAVEN-CORE-IT-LOG] Getting authentication info for server " + serverId );
AuthenticationInfo authInfo = wagonManager.getAuthenticationInfo( serverId ); AuthenticationInfo authInfo = wagonManager.getAuthenticationInfo( serverId );

View File

@ -37,12 +37,11 @@ import java.util.Properties;
/** /**
* Loads resources from a class loader used to load a wagon provider. The wagon is merely used to access the extension * Loads resources from a class loader used to load a wagon provider. The wagon is merely used to access the extension
* class loader it came from which is otherwise not accessible to a plugin. * class loader it came from which is otherwise not accessible to a plugin.
* *
* @goal load-resource
* @phase validate
*
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @version $Id$ * @version $Id$
* @goal load-resource
* @phase validate
*/ */
public class LoadResourceMojo public class LoadResourceMojo
extends AbstractMojo extends AbstractMojo
@ -50,14 +49,14 @@ public class LoadResourceMojo
/** /**
* The Wagon manager used to retrieve wagon providers. * The Wagon manager used to retrieve wagon providers.
* *
* @component * @component
*/ */
private WagonManager wagonManager; private WagonManager wagonManager;
/** /**
* The path to the properties file used to track the results of the resource loading via the wagon's class loader. * The path to the properties file used to track the results of the resource loading via the wagon's class loader.
* *
* @parameter property="wagon.wagonClassLoaderOutput" * @parameter property="wagon.wagonClassLoaderOutput"
*/ */
private File wagonClassLoaderOutput; private File wagonClassLoaderOutput;
@ -65,14 +64,14 @@ public class LoadResourceMojo
/** /**
* The role hint for the wagon provider to load. The class loader of this provider will be used to load the * The role hint for the wagon provider to load. The class loader of this provider will be used to load the
* resources. * resources.
* *
* @parameter property="wagon.wagonProtocol" * @parameter property="wagon.wagonProtocol"
*/ */
private String wagonProtocol; private String wagonProtocol;
/** /**
* The repository to load the wagon for, if applicable. * The repository to load the wagon for, if applicable.
* *
* @parameter property="wagon.repositoryId" * @parameter property="wagon.repositoryId"
*/ */
private String repositoryId; private String repositoryId;
@ -82,14 +81,14 @@ public class LoadResourceMojo
* loaded, the generated properties files will contain a key named <code>ARP</code> whose value gives the URL to the * loaded, the generated properties files will contain a key named <code>ARP</code> whose value gives the URL to the
* resource. In addition, the keys <code>ARP.count</code>, <code>ARP.0</code>, <code>ARP.1</code> etc. will * resource. In addition, the keys <code>ARP.count</code>, <code>ARP.0</code>, <code>ARP.1</code> etc. will
* enumerate all URLs matching the resource name. * enumerate all URLs matching the resource name.
* *
* @parameter * @parameter
*/ */
private String[] resourcePaths; private String[] resourcePaths;
/** /**
* Runs this mojo. * Runs this mojo.
* *
* @throws MojoFailureException If the attached file has not been set. * @throws MojoFailureException If the attached file has not been set.
*/ */
public void execute() public void execute()
@ -123,18 +122,17 @@ public class LoadResourceMojo
if ( resourcePaths != null ) if ( resourcePaths != null )
{ {
for ( int i = 0; i < resourcePaths.length; i++ ) for ( String path : resourcePaths )
{ {
String path = resourcePaths[i];
getLog().info( "[MAVEN-CORE-IT-LOG] Loading resource " + path ); getLog().info( "[MAVEN-CORE-IT-LOG] Loading resource " + path );
URL url = classLoader.getResource( path ); URL url = classLoader.getResource( path );
getLog().info( "[MAVEN-CORE-IT-LOG] Loaded resource from " + url ); getLog().info( "[MAVEN-CORE-IT-LOG] Loaded resource from " + url );
if ( url != null ) if ( url != null )
{ {
loaderProperties.setProperty( path, url.toString() ); loaderProperties.setProperty( path, url.toString() );
} }
try try
{ {
List urls = Collections.list( classLoader.getResources( path ) ); List urls = Collections.list( classLoader.getResources( path ) );

View File

@ -19,15 +19,6 @@ package org.apache.maven.wagon.providers.coreit;
* under the License. * under the License.
*/ */
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.apache.maven.wagon.AbstractWagon; import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.InputData; import org.apache.maven.wagon.InputData;
@ -38,6 +29,15 @@ import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.resource.Resource; import org.apache.maven.wagon.resource.Resource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
/** /**
* Shamelessly copied from ScpExternalWagon in this same project... * Shamelessly copied from ScpExternalWagon in this same project...
* *
@ -63,8 +63,8 @@ public class CoreItHttpWagon
if ( is == null ) if ( is == null )
{ {
throw new TransferFailedException( getRepository().getUrl() throw new TransferFailedException(
+ " - Could not open input stream for resource: '" + resource + "'" ); getRepository().getUrl() + " - Could not open input stream for resource: '" + resource + "'" );
} }
createParentDirectories( destination ); createParentDirectories( destination );
@ -95,8 +95,8 @@ public class CoreItHttpWagon
if ( os == null ) if ( os == null )
{ {
throw new TransferFailedException( getRepository().getUrl() throw new TransferFailedException(
+ " - Could not open output stream for resource: '" + resource + "'" ); getRepository().getUrl() + " - Could not open output stream for resource: '" + resource + "'" );
} }
putTransfer( outputData.getResource(), source, os, true ); putTransfer( outputData.getResource(), source, os, true );
@ -153,16 +153,11 @@ public class CoreItHttpWagon
try try
{ {
new File( "target" ).mkdirs(); new File( "target" ).mkdirs();
OutputStream os = new FileOutputStream( "target/wagon.properties" ); try ( OutputStream os = new FileOutputStream( "target/wagon.properties" ) )
try
{ {
props.store( os, "MAVEN-CORE-IT-WAGON" ); props.store( os, "MAVEN-CORE-IT-WAGON" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,15 +19,6 @@ package org.apache.maven.wagon.providers.coreit;
* under the License. * under the License.
*/ */
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.apache.maven.wagon.AbstractWagon; import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.InputData; import org.apache.maven.wagon.InputData;
@ -39,6 +30,15 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.resource.Resource; import org.apache.maven.wagon.resource.Resource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
/** /**
* Shamelessly copied from ScpExternalWagon in this same project... * Shamelessly copied from ScpExternalWagon in this same project...
* *
@ -64,8 +64,8 @@ public class CoreItWagon
if ( is == null ) if ( is == null )
{ {
throw new TransferFailedException( getRepository().getUrl() throw new TransferFailedException(
+ " - Could not open input stream for resource: '" + resource + "'" ); getRepository().getUrl() + " - Could not open input stream for resource: '" + resource + "'" );
} }
createParentDirectories( destination ); createParentDirectories( destination );
@ -96,8 +96,8 @@ public class CoreItWagon
if ( os == null ) if ( os == null )
{ {
throw new TransferFailedException( getRepository().getUrl() throw new TransferFailedException(
+ " - Could not open output stream for resource: '" + resource + "'" ); getRepository().getUrl() + " - Could not open output stream for resource: '" + resource + "'" );
} }
putTransfer( outputData.getResource(), source, os, true ); putTransfer( outputData.getResource(), source, os, true );
@ -164,16 +164,11 @@ public class CoreItWagon
{ {
File file = new File( "target/wagon.properties" ).getAbsoluteFile(); File file = new File( "target/wagon.properties" ).getAbsoluteFile();
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
OutputStream os = new FileOutputStream( file ); try ( OutputStream os = new FileOutputStream( file ) )
try
{ {
props.store( os, "MAVEN-CORE-IT-WAGON" ); props.store( os, "MAVEN-CORE-IT-WAGON" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,15 +19,6 @@ package org.apache.maven.wagon.providers.ssh.external;
* under the License. * under the License.
*/ */
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.apache.maven.wagon.AbstractWagon; import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.ConnectionException; import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.InputData; import org.apache.maven.wagon.InputData;
@ -38,10 +29,19 @@ import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.resource.Resource; import org.apache.maven.wagon.resource.Resource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
/** /**
* NOTE: Plexus will only pick this correctly if the Class package and name are the same as that in core. This is * NOTE: Plexus will only pick this correctly if the Class package and name are the same as that in core. This is
* because the core component descriptor is read, but the class is read from the latter JAR. * because the core component descriptor is read, but the class is read from the latter JAR.
* *
* @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="scpexe" instantiation-strategy="per-lookup" * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="scpexe" instantiation-strategy="per-lookup"
*/ */
public class ScpExternalWagon public class ScpExternalWagon
@ -64,8 +64,8 @@ public class ScpExternalWagon
if ( is == null ) if ( is == null )
{ {
throw new TransferFailedException( getRepository().getUrl() throw new TransferFailedException(
+ " - Could not open input stream for resource: '" + resource + "'" ); getRepository().getUrl() + " - Could not open input stream for resource: '" + resource + "'" );
} }
createParentDirectories( destination ); createParentDirectories( destination );
@ -98,8 +98,8 @@ public class ScpExternalWagon
if ( os == null ) if ( os == null )
{ {
throw new TransferFailedException( getRepository().getUrl() throw new TransferFailedException(
+ " - Could not open output stream for resource: '" + resource + "'" ); getRepository().getUrl() + " - Could not open output stream for resource: '" + resource + "'" );
} }
putTransfer( outputData.getResource(), source, os, true ); putTransfer( outputData.getResource(), source, os, true );
@ -145,15 +145,10 @@ public class ScpExternalWagon
try try
{ {
OutputStream os = new FileOutputStream( new File( dir, "wagon.properties" ) ); try ( OutputStream os = new FileOutputStream( new File( dir, "wagon.properties" ) ) )
try
{ {
props.store( os, "MAVEN-CORE-IT-WAGON" ); props.store( os, "MAVEN-CORE-IT-WAGON" );
} }
finally
{
os.close();
}
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -19,6 +19,7 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import junit.framework.TestCase;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@ -34,8 +35,6 @@ import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import junit.framework.TestCase;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
* @author Kenney Westerhof * @author Kenney Westerhof
@ -58,7 +57,7 @@ public abstract class AbstractMavenIntegrationTestCase
* The zero-based column index where to print the test result. * The zero-based column index where to print the test result.
*/ */
private static final int RESULT_COLUMN = 60; private static final int RESULT_COLUMN = 60;
private boolean skip; private boolean skip;
private static ArtifactVersion javaVersion; private static ArtifactVersion javaVersion;
@ -99,13 +98,13 @@ public abstract class AbstractMavenIntegrationTestCase
else else
{ {
out.println( "WARNING: " + getITName() + ": version range '" + versionRange out.println( "WARNING: " + getITName() + ": version range '" + versionRange
+ "' supplied but no Maven version - not skipping test." ); + "' supplied but no Maven version - not skipping test." );
} }
} }
/** /**
* Gets the Java version used to run this test. * Gets the Java version used to run this test.
* *
* @return The Java version, never <code>null</code>. * @return The Java version, never <code>null</code>.
*/ */
private ArtifactVersion getJavaVersion() private ArtifactVersion getJavaVersion()
@ -126,7 +125,7 @@ public abstract class AbstractMavenIntegrationTestCase
/** /**
* Gets the Maven version used to run this test. * Gets the Maven version used to run this test.
* *
* @return The Maven version or <code>null</code> if unknown. * @return The Maven version or <code>null</code> if unknown.
*/ */
private ArtifactVersion getMavenVersion() private ArtifactVersion getMavenVersion()
@ -190,7 +189,7 @@ public abstract class AbstractMavenIntegrationTestCase
else else
{ {
out.println( "WARNING: " + getITName() + ": version range '" + versionRange out.println( "WARNING: " + getITName() + ": version range '" + versionRange
+ "' supplied but no Maven version found - returning true for match check." ); + "' supplied but no Maven version found - returning true for match check." );
return true; return true;
} }
@ -243,9 +242,9 @@ public abstract class AbstractMavenIntegrationTestCase
* Guards the execution of a test case by checking that the current Java version matches the specified version * Guards the execution of a test case by checking that the current Java version matches the specified version
* range. If the check fails, an exception will be thrown which aborts the current test and marks it as skipped. One * range. If the check fails, an exception will be thrown which aborts the current test and marks it as skipped. One
* would usually call this method right at the start of a test method. * would usually call this method right at the start of a test method.
* *
* @param versionRange The version range that specifies the acceptable Java versions for the test, must not be * @param versionRange The version range that specifies the acceptable Java versions for the test, must not be
* <code>null</code>. * <code>null</code>.
*/ */
protected void requiresJavaVersion( String versionRange ) protected void requiresJavaVersion( String versionRange )
{ {
@ -270,9 +269,9 @@ public abstract class AbstractMavenIntegrationTestCase
* Guards the execution of a test case by checking that the current Maven version matches the specified version * Guards the execution of a test case by checking that the current Maven version matches the specified version
* range. If the check fails, an exception will be thrown which aborts the current test and marks it as skipped. One * range. If the check fails, an exception will be thrown which aborts the current test and marks it as skipped. One
* would usually call this method right at the start of a test method. * would usually call this method right at the start of a test method.
* *
* @param versionRange The version range that specifies the acceptable Maven versions for the test, must not be * @param versionRange The version range that specifies the acceptable Maven versions for the test, must not be
* <code>null</code>. * <code>null</code>.
*/ */
protected void requiresMavenVersion( String versionRange ) protected void requiresMavenVersion( String versionRange )
{ {
@ -297,7 +296,7 @@ public abstract class AbstractMavenIntegrationTestCase
else else
{ {
out.println( "WARNING: " + getITName() + ": version range '" + versionRange out.println( "WARNING: " + getITName() + ": version range '" + versionRange
+ "' supplied but no Maven version found - not skipping test." ); + "' supplied but no Maven version found - not skipping test." );
} }
} }
@ -358,7 +357,7 @@ public abstract class AbstractMavenIntegrationTestCase
private String pad( int chars ) private String pad( int chars )
{ {
StringBuffer buffer = new StringBuffer( 128 ); StringBuilder buffer = new StringBuilder( 128 );
for ( int i = 0; i < chars; i++ ) for ( int i = 0; i < chars; i++ )
{ {
buffer.append( '.' ); buffer.append( '.' );
@ -449,7 +448,7 @@ public abstract class AbstractMavenIntegrationTestCase
// Make is easier to run ITs from m2e in Maven IT mode without having to set any additional // Make is easier to run ITs from m2e in Maven IT mode without having to set any additional
// properties. // properties.
// //
settingsFile = new File( "target/test-classes", settingsFile.getPath() ); settingsFile = new File( "target/test-classes", settingsFile.getPath() );
} }
} }