You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by jd...@apache.org on 2004/09/03 23:34:13 UTC
cvs commit: maven-components/maven-core-it maven-core-it.sh
jdcasey 2004/09/03 14:34:13
Modified: maven-core-it-verifier/src/main/java/org/apache/maven/it
Verifier.java
maven-core-it maven-core-it.sh
Log:
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
Revision Changes Path
1.12 +40 -15 maven-components/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java
Index: Verifier.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Verifier.java 2 Sep 2004 12:34:18 -0000 1.11
+++ Verifier.java 3 Sep 2004 21:34:13 -0000 1.12
@@ -11,36 +11,47 @@
import java.util.Iterator;
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$
*/
public class Verifier
{
private String basedir;
- private String mavenRepoLocal;
+ private File homeDir;
+
+ private String localRepo;
- public Verifier( String basedir, String mavenRepoLocal )
+ public Verifier( String basedir, String homeDir )
{
this.basedir = basedir;
- this.mavenRepoLocal = mavenRepoLocal;
+ this.homeDir = new File( homeDir );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- public void verify()
- throws VerificationException
+ public void verify() throws VerificationException
{
try
{
+ retrieveLocalRepo();
+
BufferedReader reader = new BufferedReader( new FileReader( new File( basedir, "expected-results.txt" ) ) );
String line = "";
- while ( ( line = reader.readLine() ) != null )
+ while ( (line = reader.readLine()) != null )
{
verifyExpectedResult( line );
}
@@ -50,13 +61,28 @@
throw new VerificationException( e );
}
- System.out.println( "-----------------------------------------------------------------------------------> OK" );
+ System.out.println( "-----------------------------------------------------------------------------------> OK" );
}
- private void verifyExpectedResult( String line )
- throws VerificationException
+ private void retrieveLocalRepo() throws Exception
{
- 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 )
{
@@ -128,7 +154,7 @@
StringBuffer buf = new StringBuffer( text.length() );
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 );
start = end + repl.length();
@@ -142,7 +168,6 @@
return buf.toString();
}
-
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@@ -164,4 +189,4 @@
System.exit( 0 );
}
-}
+}
\ No newline at end of file
1.15 +11 -4 maven-components/maven-core-it/maven-core-it.sh
Index: maven-core-it.sh
===================================================================
RCS file: /home/cvs/maven-components/maven-core-it/maven-core-it.sh,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- maven-core-it.sh 2 Sep 2004 12:34:18 -0000 1.14
+++ maven-core-it.sh 3 Sep 2004 21:34:13 -0000 1.15
@@ -10,8 +10,8 @@
integration_tests=`cat integration-tests.txt | egrep -v '^#'`
-# TODO: this is rubbish. Let's rewrite this in java
-local_repo=`cat $HOME/.m2/pom.xml | tr '\n' ' ' | sed 's/^.*<local> *<repository>//' | sed 's#</repository> *</local>.*$##'`
+#If this doesn't have a value, we'll parse $HOME/.m2/pom.xml in the Verifier.
+local_repo=
for i in "$@"
do
@@ -33,7 +33,13 @@
echo
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 ]
then
@@ -44,7 +50,8 @@
basedir=.
- java -cp "$cp" $verifier "$basedir" "$local_repo"
+ java $jvm_opts -cp "$cp" $verifier "$basedir" "$HOME"
+
) > ${integration_test}-log.txt
if [ "$?" = "0" ]