diff --git a/README.txt b/README.txt
index d3db38056e..7b407f4931 100644
--- a/README.txt
+++ b/README.txt
@@ -2,20 +2,18 @@
Bootstrapping Maven
-------------------------------------------------------------------------------
-To bootstrap Maven you must have a ~/maven.properties file with the following
-entries:
+To bootstrap Maven you must have a ~/.m2/maven.properties file with the following
+entry:
-maven.home = /path/to/your/maven/installation
maven.repo.local = /path/to/your/local/repository
-Once you have your ~/maven.properties setup then:
+Set the environment variable M2_HOME pointing to the dir where you want Maven2 installed.
-java -jar mboot.jar
+You can set the parameters passed to the Java VM when running Maven2 bootstrap,
+setting the environment variable MAVEN_OPTS, e.g.
+e.g. to run in offline mode, set MAVEN_OPTS=-Dmaven.online=false
+e.g. to build maven with debug info, set MAVEN_OPTS=-Dmaven.compiler.debug=true
-Should do the trick to produce a working installation of Maven
-in ${maven.home}.
+Then run m2-bootstrap-all.bat (in Windows) or m2-bootstrap-all.sh (in Unix)
NOTE: You must run these instructions from this directory!
-
-NOTE: If you want to run in offline mode where no downloading is done
- then add: 'maven.online = false' to your ~/maven.properties file.
diff --git a/m2-bootstrap-all.bat b/m2-bootstrap-all.bat
index 7af7f6413f..4b88a26b72 100644
--- a/m2-bootstrap-all.bat
+++ b/m2-bootstrap-all.bat
@@ -111,7 +111,7 @@ call .\build
@REM Build Maven2
cd ..
-%MAVEN_JAVA_EXE% %MAVEN_CMD_LINE_ARGS% -jar mboot.jar
+%MAVEN_JAVA_EXE% %MAVEN_CMD_LINE_ARGS% %MAVEN_OPTS% -jar mboot.jar
echo Running integration tests
cd maven-core-it
diff --git a/m2-bootstrap-all.sh b/m2-bootstrap-all.sh
index 3ab354bdd1..b771312862 100644
--- a/m2-bootstrap-all.sh
+++ b/m2-bootstrap-all.sh
@@ -26,7 +26,7 @@ ret=$?; if [ $ret != 0 ]; then exit $ret; fi
echo " Building maven2 components ... "
echo "-----------------------------------------------------------------------"
- $JAVA_HOME/bin/java $ARGS -jar mboot.jar
+ $JAVA_HOME/bin/java $ARGS $MAVEN_OPTS -jar mboot.jar
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
)
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
diff --git a/maven-mboot2/src/main/java/MBoot.java b/maven-mboot2/src/main/java/MBoot.java
index 77c91963ef..5e53db1b33 100644
--- a/maven-mboot2/src/main/java/MBoot.java
+++ b/maven-mboot2/src/main/java/MBoot.java
@@ -1,4 +1,5 @@
+import compile.CompilerConfiguration;
import compile.JavacCompiler;
import download.ArtifactDownloader;
import jar.JarMojo;
@@ -860,14 +861,31 @@ public class MBoot
if ( sourceDirectories != null )
{
- List errors = compiler.compile( classpath( dependencies, extraClasspath ), sourceDirectories, outputDirectory );
+ CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
+
+ compilerConfiguration.setOutputLocation(outputDirectory);
+ compilerConfiguration.setClasspathEntries(Arrays.asList(classpath( dependencies, extraClasspath )));
+ compilerConfiguration.setSourceLocations(Arrays.asList(sourceDirectories));
+
+ /* Compile with debugging info */
+ String debugAsString = System.getProperty( "maven.compiler.debug" );
- for ( Iterator i = errors.iterator(); i.hasNext(); )
+ if ( debugAsString != null )
+ {
+ if ( Boolean.valueOf( debugAsString ).booleanValue() )
+ {
+ compilerConfiguration.setDebug( true );
+ }
+ }
+
+ List messages = compiler.compile(compilerConfiguration);
+
+ for ( Iterator i = messages.iterator(); i.hasNext(); )
{
System.out.println( i.next() );
}
- if ( errors.size() > 0 )
+ if ( messages.size() > 0 )
{
throw new Exception( "Compilation error." );
}
diff --git a/maven-mboot2/src/main/java/compile/AbstractCompiler.java b/maven-mboot2/src/main/java/compile/AbstractCompiler.java
index cf9efb1e46..0a51f4acd9 100644
--- a/maven-mboot2/src/main/java/compile/AbstractCompiler.java
+++ b/maven-mboot2/src/main/java/compile/AbstractCompiler.java
@@ -5,41 +5,64 @@ import util.DirectoryScanner;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
/**
+ *
+ *
* @author Jason van Zyl
* @author Michal Maczka
+ *
* @version $Id$
*/
public abstract class AbstractCompiler
+ implements Compiler
{
private static String PS = System.getProperty( "path.separator" );
- public String getClasspathString( String[] classpathElements )
+ public String getClasspathString( List classpathElements )
throws Exception
{
StringBuffer sb = new StringBuffer();
- for ( int i = 0; i < classpathElements.length; i++ )
+ for ( Iterator it = classpathElements.iterator(); it.hasNext(); )
{
- sb.append( classpathElements[i] ).append( PS );
+ String element = (String) it.next();
+
+ sb.append( element ).append( PS );
}
return sb.toString();
}
- protected String[] getSourceFiles( String[] sourceDirectories )
+ protected String[] getSourceFiles( CompilerConfiguration config )
{
List sources = new ArrayList();
- for ( int i = 0; i < sourceDirectories.length; i++ )
+ for ( Iterator it = config.getSourceLocations().iterator(); it.hasNext(); )
{
+ String sourceLocation = (String) it.next();
+
DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( sourceDirectories[i] );
+ scanner.setBasedir( sourceLocation );
- scanner.setIncludes( new String[]{"**/*.java"} );
+ Set includes = config.getIncludes();
+ if(includes != null && !includes.isEmpty()) {
+ String[] inclStrs = (String[])includes.toArray(new String[includes.size()]);
+ scanner.setIncludes( inclStrs );
+ }
+ else {
+ scanner.setIncludes(new String[] {"**/*.java"});
+ }
+
+ Set excludes = config.getIncludes();
+ if(excludes != null && !excludes.isEmpty()) {
+ String[] exclStrs = (String[])excludes.toArray(new String[excludes.size()]);
+ scanner.setIncludes( exclStrs );
+ }
scanner.scan();
@@ -47,7 +70,7 @@ public abstract class AbstractCompiler
for ( int j = 0; j < sourceDirectorySources.length; j++ )
{
- File f = new File( sourceDirectories[i], sourceDirectorySources[j] );
+ File f = new File( sourceLocation, sourceDirectorySources[j] );
sources.add( f.getPath() );
}
diff --git a/maven-mboot2/src/main/java/compile/Compiler.java b/maven-mboot2/src/main/java/compile/Compiler.java
new file mode 100644
index 0000000000..68145a1f89
--- /dev/null
+++ b/maven-mboot2/src/main/java/compile/Compiler.java
@@ -0,0 +1,20 @@
+package compile;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ *
+ * @author Jason van Zyl
+ *
+ * @version $Id$
+ */
+public interface Compiler
+{
+ static String ROLE = Compiler.class.getName();
+
+ List compile( CompilerConfiguration configuration )
+ throws Exception;
+}
+
diff --git a/maven-mboot2/src/main/java/compile/CompilerConfiguration.java b/maven-mboot2/src/main/java/compile/CompilerConfiguration.java
new file mode 100644
index 0000000000..999aa60a38
--- /dev/null
+++ b/maven-mboot2/src/main/java/compile/CompilerConfiguration.java
@@ -0,0 +1,116 @@
+/* Created on Oct 4, 2004 */
+package compile;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+
+/**
+ * @author jdcasey
+ */
+public class CompilerConfiguration
+{
+
+ private String outputLocation;
+ private List classpathEntries = new LinkedList();
+ private List sourceLocations = new LinkedList();
+ private Set includes = new HashSet();
+ private Set excludes = new HashSet();
+ private Map compilerOptions = new TreeMap();
+ private boolean debug = false;
+
+ public void setOutputLocation(String outputLocation)
+ {
+ this.outputLocation = outputLocation;
+ }
+
+ public String getOutputLocation()
+ {
+ return outputLocation;
+ }
+
+ public void addClasspathEntry(String classpathEntry)
+ {
+ this.classpathEntries.add(classpathEntry);
+ }
+
+ public void setClasspathEntries(List classpathEntries) {
+ this.classpathEntries = new LinkedList(classpathEntries);
+ }
+
+ public List getClasspathEntries() {
+ return Collections.unmodifiableList(classpathEntries);
+ }
+
+ public void addSourceLocation(String sourceLocation) {
+ this.sourceLocations.add(sourceLocation);
+ }
+
+ public void setSourceLocations(List sourceLocations) {
+ this.sourceLocations = new LinkedList(sourceLocations);
+ }
+
+ public List getSourceLocations() {
+ return Collections.unmodifiableList(sourceLocations);
+ }
+
+ public void addInclude(String include) {
+ this.includes.add(include);
+ }
+
+ public void setIncludes(Set includes) {
+ this.includes = new HashSet(includes);
+ }
+
+ public Set getIncludes() {
+ return Collections.unmodifiableSet(includes);
+ }
+
+ public void addExclude(String exclude) {
+ this.excludes.add(exclude);
+ }
+
+ public void setExcludes(Set excludes) {
+ this.excludes = new HashSet(excludes);
+ }
+
+ public Set getExcludes() {
+ return Collections.unmodifiableSet(excludes);
+ }
+
+ public void addCompilerOption(String optionName, String optionValue) {
+ this.compilerOptions.put(optionName, optionValue);
+ }
+
+ public void setCompilerOptions(Map compilerOptions) {
+ this.compilerOptions = new TreeMap(compilerOptions);
+ }
+
+ public Map getCompilerOptions() {
+ return Collections.unmodifiableMap(compilerOptions);
+ }
+
+ /**
+ * @param debug The debug to set.
+ */
+ public void setDebug( boolean debug )
+ {
+ this.debug = debug;
+ }
+
+ /**
+ * Compile with debug info
+ *
+ * @return Returns the debug.
+ */
+ public boolean isDebug()
+ {
+ return debug;
+ }
+
+}
diff --git a/maven-mboot2/src/main/java/compile/CompilerError.java b/maven-mboot2/src/main/java/compile/CompilerError.java
index 68ece67e7b..186517f1f3 100644
--- a/maven-mboot2/src/main/java/compile/CompilerError.java
+++ b/maven-mboot2/src/main/java/compile/CompilerError.java
@@ -1,3 +1,20 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package compile;
/**
@@ -43,21 +60,23 @@ public class CompilerError
/**
* The error message constructor.
*
- * @param file The name of the file containing the offending program text
- * @param error The actual error text produced by the language processor
- * @param startline The start line number of the offending program text
+ * @param file The name of the file containing the offending program text
+ * @param error The actual error text produced by the language processor
+ * @param startline The start line number of the offending program text
* @param startcolumn The start column number of the offending program text
- * @param endline The end line number of the offending program text
- * @param endcolumn The end column number of the offending program text
- * @param message The actual error text produced by the language processor
+ * @param endline The end line number of the offending program text
+ * @param endcolumn The end column number of the offending program text
+ * @param message The actual error text produced by the language processor
*/
- public CompilerError( String file,
- boolean error,
- int startline,
- int startcolumn,
- int endline,
- int endcolumn,
- String message )
+ public CompilerError(
+ String file,
+ boolean error,
+ int startline,
+ int startcolumn,
+ int endline,
+ int endcolumn,
+ String message
+ )
{
this.file = file;
this.error = error;
@@ -113,7 +132,7 @@ public class CompilerError
* error
*
* @return The starting column number of the program text originating this
- * error
+ * error
*/
public int getStartColumn()
{
@@ -135,7 +154,7 @@ public class CompilerError
* error
*
* @return The ending column number of the program text originating this
- * error
+ * error
*/
public int getEndColumn()
{
diff --git a/maven-mboot2/src/main/java/compile/JavacCompiler.java b/maven-mboot2/src/main/java/compile/JavacCompiler.java
index 141797055e..748b94dfb0 100644
--- a/maven-mboot2/src/main/java/compile/JavacCompiler.java
+++ b/maven-mboot2/src/main/java/compile/JavacCompiler.java
@@ -1,6 +1,21 @@
-package compile;
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
-import util.IsolatedClassLoader;
+package compile;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -12,10 +27,14 @@ import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
+import util.IsolatedClassLoader;
+
public class JavacCompiler
extends AbstractCompiler
{
@@ -25,42 +44,44 @@ public class JavacCompiler
{
}
- public List compile( String[] classpathElements, String[] sourceDirectories, String destinationDirectory )
- throws Exception
+ public List compile( CompilerConfiguration config ) throws Exception
{
- /*
- for ( int i = 0; i < classpathElements.length; i++ )
- {
- System.out.println( "classpathElement = " + classpathElements[i] );
- }
- */
-
- File destinationDir = new File( destinationDirectory );
+ File destinationDir = new File( config.getOutputLocation() );
if ( !destinationDir.exists() )
{
destinationDir.mkdirs();
}
- String[] sources = getSourceFiles( sourceDirectories );
+ String[] sources = getSourceFiles( config );
- int j = 5;
+ Map compilerOptions = config.getCompilerOptions();
- String[] args = new String[sources.length + j];
+ List args = new ArrayList( sources.length + 5 + compilerOptions.size() * 2 );
- args[0] = "-d";
+ args.add( "-d" );
- args[1] = destinationDir.getAbsolutePath();
+ args.add( destinationDir.getAbsolutePath() );
- args[2] = "-nowarn";
+ args.add( "-nowarn" );
- args[3] = "-classpath";
+ args.add( "-classpath" );
- args[4] = getClasspathString( classpathElements );
+ args.add( getClasspathString( config.getClasspathEntries() ) );
+
+ Iterator it = compilerOptions.entrySet().iterator();
+
+ while ( it.hasNext() )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ args.add( entry.getKey() );
+ if ( (entry.getValue() != null) )
+ args.add( entry.getValue() );
+ }
for ( int i = 0; i < sources.length; i++ )
{
- args[i + j] = sources[i];
+ args.add( sources[i] );
}
IsolatedClassLoader cl = new IsolatedClassLoader();
@@ -71,23 +92,22 @@ public class JavacCompiler
Class c = cl.loadClass( "sun.tools.javac.Main" );
- Constructor cons = c.getConstructor( new Class[]{OutputStream.class, String.class} );
+ Constructor cons = c.getConstructor( new Class[] { OutputStream.class, String.class } );
ByteArrayOutputStream err = new ByteArrayOutputStream();
- Object compiler = cons.newInstance( new Object[]{err, "javac"} );
+ Object compiler = cons.newInstance( new Object[] { err, "javac" } );
- Method compile = c.getMethod( "compile", new Class[]{String[].class} );
+ Method compile = c.getMethod( "compile", new Class[] { String[].class } );
- Boolean ok = (Boolean) compile.invoke( compiler, new Object[]{args} );
+ Boolean ok = (Boolean) compile.invoke( compiler, new Object[] { args.toArray( new String[0] ) } );
List messages = parseModernStream( new BufferedReader( new InputStreamReader( new ByteArrayInputStream( err.toByteArray() ) ) ) );
return messages;
}
- protected List parseModernStream( BufferedReader input )
- throws IOException
+ protected List parseModernStream( BufferedReader input ) throws IOException
{
List errors = new ArrayList();
@@ -103,7 +123,7 @@ public class JavacCompiler
// most errors terminate with the '^' char
do
{
- if ( ( line = input.readLine() ) == null )
+ if ( (line = input.readLine()) == null )
{
return errors;
}
@@ -111,8 +131,7 @@ public class JavacCompiler
buffer.append( line );
buffer.append( '\n' );
- }
- while ( !line.endsWith( "^" ) );
+ } while ( !line.endsWith( "^" ) );
// add the error bean
errors.add( parseModernError( buffer.toString() ) );
@@ -165,4 +184,4 @@ public class JavacCompiler
{
return "Sun Javac Compiler";
}
-}
+}
\ No newline at end of file