o Removed the parsing of ~/.m2/pom.xml using unix tools to extract the local repo

o Added the ability to specify -Dmaven.repo.local=xxx to the it shell script, and the Verifier class
o Added to the Verifier class the ability to parse ~/.m2/pom.xml and retrieve the local repo location in the event ${maven.repo.local} is unspecified


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163029 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2004-09-03 21:34:13 +00:00
parent 528863b613
commit 984d4644ef
2 changed files with 50 additions and 18 deletions

View File

@ -11,36 +11,47 @@ import java.util.Properties;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xml.utils.DOMBuilder;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$ * @version $Id$
*/ */
public class Verifier public class Verifier
{ {
private String basedir; private String basedir;
private String mavenRepoLocal; private File homeDir;
public Verifier( String basedir, String mavenRepoLocal ) private String localRepo;
public Verifier( String basedir, String homeDir )
{ {
this.basedir = basedir; this.basedir = basedir;
this.mavenRepoLocal = mavenRepoLocal; this.homeDir = new File( homeDir );
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public void verify() public void verify() throws VerificationException
throws VerificationException
{ {
try try
{ {
retrieveLocalRepo();
BufferedReader reader = new BufferedReader( new FileReader( new File( basedir, "expected-results.txt" ) ) ); BufferedReader reader = new BufferedReader( new FileReader( new File( basedir, "expected-results.txt" ) ) );
String line = ""; String line = "";
while ( ( line = reader.readLine() ) != null ) while ( (line = reader.readLine()) != null )
{ {
verifyExpectedResult( line ); verifyExpectedResult( line );
} }
@ -50,13 +61,28 @@ public class Verifier
throw new VerificationException( e ); throw new VerificationException( e );
} }
System.out.println( "-----------------------------------------------------------------------------------> OK" ); System.out.println( "-----------------------------------------------------------------------------------> OK" );
} }
private void verifyExpectedResult( String line ) private void retrieveLocalRepo() throws Exception
throws VerificationException
{ {
line = replace( line, "${localRepository}", mavenRepoLocal ); localRepo = System.getProperty( "maven.repo.local" );
if ( localRepo == null )
{
// parse ~/.m2/pom.xml for it...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
File pom = new File( homeDir, ".m2/pom.xml" );
Document dom = builder.parse( pom );
localRepo = XPathAPI.selectSingleNode( dom, "/project/local/repository/text()" ).getNodeValue();
}
}
private void verifyExpectedResult( String line ) throws VerificationException
{
line = replace( line, "${localRepository}", localRepo );
if ( line.indexOf( "!/" ) > 0 ) if ( line.indexOf( "!/" ) > 0 )
{ {
@ -128,7 +154,7 @@ public class Verifier
StringBuffer buf = new StringBuffer( text.length() ); StringBuffer buf = new StringBuffer( text.length() );
int start = 0, end = 0; int start = 0, end = 0;
while ( ( end = text.indexOf( repl, start ) ) != -1 ) while ( (end = text.indexOf( repl, start )) != -1 )
{ {
buf.append( text.substring( start, end ) ).append( with ); buf.append( text.substring( start, end ) ).append( with );
start = end + repl.length(); start = end + repl.length();
@ -142,7 +168,6 @@ public class Verifier
return buf.toString(); return buf.toString();
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -164,4 +189,4 @@ public class Verifier
System.exit( 0 ); System.exit( 0 );
} }
} }

View File

@ -10,8 +10,8 @@ verifier=org.apache.maven.it.Verifier
integration_tests=`cat integration-tests.txt | egrep -v '^#'` integration_tests=`cat integration-tests.txt | egrep -v '^#'`
# TODO: this is rubbish. Let's rewrite this in java #If this doesn't have a value, we'll parse $HOME/.m2/pom.xml in the Verifier.
local_repo=`cat $HOME/.m2/pom.xml | tr '\n' ' ' | sed 's/^.*<local> *<repository>//' | sed 's#</repository> *</local>.*$##'` local_repo=
for i in "$@" for i in "$@"
do do
@ -33,7 +33,13 @@ do
echo echo
fi fi
m2 -Dmaven.repo.local="$local_repo" clean:clean `cat goals.txt` jvm_opts=
if [ "$local_repo" != "" ]
then
jvm_opts="-Dmaven.repo.local=$local_repo"
fi
m2 $jvm_opts clean:clean `cat goals.txt`
if [ -f postbuild.hook ] if [ -f postbuild.hook ]
then then
@ -44,7 +50,8 @@ do
basedir=. basedir=.
java -cp "$cp" $verifier "$basedir" "$local_repo" java $jvm_opts -cp "$cp" $verifier "$basedir" "$HOME"
) > ${integration_test}-log.txt ) > ${integration_test}-log.txt
if [ "$?" = "0" ] if [ "$?" = "0" ]