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 ca...@apache.org on 2005/01/09 23:38:43 UTC
cvs commit: maven-components m2-bootstrap-all.bat m2-bootstrap-all.sh README.txt
carlos 2005/01/09 14:38:43
Modified: maven-mboot2/src/main/java MBoot.java
maven-mboot2/src/main/java/compile JavacCompiler.java
CompilerError.java AbstractCompiler.java
. m2-bootstrap-all.bat m2-bootstrap-all.sh README.txt
Added: maven-mboot2/src/main/java/compile Compiler.java
CompilerConfiguration.java
Log:
Added debug option to compiler configuration.
Copied compiler classes from plexus compiler.
Allow bootstrapping with debug info.
Revision Changes Path
1.43 +21 -3 maven-components/maven-mboot2/src/main/java/MBoot.java
Index: MBoot.java
===================================================================
RCS file: /home/cvs/maven-components/maven-mboot2/src/main/java/MBoot.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- MBoot.java 23 Dec 2004 23:46:42 -0000 1.42
+++ MBoot.java 9 Jan 2005 22:38:43 -0000 1.43
@@ -1,4 +1,5 @@
+import compile.CompilerConfiguration;
import compile.JavacCompiler;
import download.ArtifactDownloader;
import jar.JarMojo;
@@ -860,14 +861,31 @@
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" );
+
+ if ( debugAsString != null )
+ {
+ if ( Boolean.valueOf( debugAsString ).booleanValue() )
+ {
+ compilerConfiguration.setDebug( true );
+ }
+ }
+
+ List messages = compiler.compile(compilerConfiguration);
- for ( Iterator i = errors.iterator(); i.hasNext(); )
+ 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." );
}
1.2 +50 -31 maven-components/maven-mboot2/src/main/java/compile/JavacCompiler.java
Index: JavacCompiler.java
===================================================================
RCS file: /home/cvs/maven-components/maven-mboot2/src/main/java/compile/JavacCompiler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JavacCompiler.java 5 Dec 2004 04:12:24 -0000 1.1
+++ JavacCompiler.java 9 Jan 2005 22:38:43 -0000 1.2
@@ -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.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 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 );
+
+ Map compilerOptions = config.getCompilerOptions();
+
+ List args = new ArrayList( sources.length + 5 + compilerOptions.size() * 2 );
- int j = 5;
+ args.add( "-d" );
- String[] args = new String[sources.length + j];
+ args.add( destinationDir.getAbsolutePath() );
- args[0] = "-d";
+ args.add( "-nowarn" );
- args[1] = destinationDir.getAbsolutePath();
+ args.add( "-classpath" );
- args[2] = "-nowarn";
+ args.add( getClasspathString( config.getClasspathEntries() ) );
- args[3] = "-classpath";
+ Iterator it = compilerOptions.entrySet().iterator();
- args[4] = getClasspathString( classpathElements );
+ 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 @@
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 @@
// most errors terminate with the '^' char
do
{
- if ( ( line = input.readLine() ) == null )
+ if ( (line = input.readLine()) == null )
{
return errors;
}
@@ -111,8 +131,7 @@
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 @@
{
return "Sun Javac Compiler";
}
-}
+}
\ No newline at end of file
1.2 +36 -17 maven-components/maven-mboot2/src/main/java/compile/CompilerError.java
Index: CompilerError.java
===================================================================
RCS file: /home/cvs/maven-components/maven-mboot2/src/main/java/compile/CompilerError.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CompilerError.java 5 Dec 2004 04:12:24 -0000 1.1
+++ CompilerError.java 9 Jan 2005 22:38:43 -0000 1.2
@@ -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 @@
/**
* 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
- */
- public CompilerError( String file,
- boolean error,
- int startline,
- int startcolumn,
- int endline,
- int endcolumn,
- String message )
+ * @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
+ )
{
this.file = file;
this.error = error;
@@ -113,7 +132,7 @@
* error
*
* @return The starting column number of the program text originating this
- * error
+ * error
*/
public int getStartColumn()
{
@@ -135,7 +154,7 @@
* error
*
* @return The ending column number of the program text originating this
- * error
+ * error
*/
public int getEndColumn()
{
1.2 +32 -9 maven-components/maven-mboot2/src/main/java/compile/AbstractCompiler.java
Index: AbstractCompiler.java
===================================================================
RCS file: /home/cvs/maven-components/maven-mboot2/src/main/java/compile/AbstractCompiler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractCompiler.java 5 Dec 2004 04:12:24 -0000 1.1
+++ AbstractCompiler.java 9 Jan 2005 22:38:43 -0000 1.2
@@ -5,41 +5,64 @@
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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
+ *
* @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 @@
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() );
}
1.1 maven-components/maven-mboot2/src/main/java/compile/Compiler.java
Index: Compiler.java
===================================================================
package compile;
import java.util.List;
import java.util.Map;
/**
*
*
* @author <a href="mailto:jason@plexus.org">Jason van Zyl</a>
*
* @version $Id: Compiler.java,v 1.1 2005/01/09 22:38:43 carlos Exp $
*/
public interface Compiler
{
static String ROLE = Compiler.class.getName();
List compile( CompilerConfiguration configuration )
throws Exception;
}
1.1 maven-components/maven-mboot2/src/main/java/compile/CompilerConfiguration.java
Index: CompilerConfiguration.java
===================================================================
/* 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;
}
}
1.6 +1 -1 maven-components/m2-bootstrap-all.bat
Index: m2-bootstrap-all.bat
===================================================================
RCS file: /home/cvs/maven-components/m2-bootstrap-all.bat,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- m2-bootstrap-all.bat 30 Sep 2004 08:49:20 -0000 1.5
+++ m2-bootstrap-all.bat 9 Jan 2005 22:38:43 -0000 1.6
@@ -111,7 +111,7 @@
@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
1.5 +1 -1 maven-components/m2-bootstrap-all.sh
Index: m2-bootstrap-all.sh
===================================================================
RCS file: /home/cvs/maven-components/m2-bootstrap-all.sh,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- m2-bootstrap-all.sh 9 Sep 2004 11:13:10 -0000 1.4
+++ m2-bootstrap-all.sh 9 Jan 2005 22:38:43 -0000 1.5
@@ -26,7 +26,7 @@
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
1.4 +8 -10 maven-components/README.txt
Index: README.txt
===================================================================
RCS file: /home/cvs/maven-components/README.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- README.txt 27 Jul 2004 16:57:59 -0000 1.3
+++ README.txt 9 Jan 2005 22:38:43 -0000 1.4
@@ -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.