diff --git a/bootstrap/bootstrap-installer/pom.xml b/bootstrap/bootstrap-installer/pom.xml new file mode 100644 index 0000000000..ae78e0b5af --- /dev/null +++ b/bootstrap/bootstrap-installer/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + org.apache.maven.bootstrap + bootstrap-installer + 2.0.1-SNAPSHOT + Maven Bootstrap Installer + Tool used to bootstrap m2. + + + org.apache.maven.bootstrap + bootstrap-mini + 2.0.1-SNAPSHOT + + + diff --git a/bootstrap/bootstrap-installer/src/main/java/org/apache/maven/bootstrap/installer/BootstrapInstaller.java b/bootstrap/bootstrap-installer/src/main/java/org/apache/maven/bootstrap/installer/BootstrapInstaller.java new file mode 100644 index 0000000000..8db905ed85 --- /dev/null +++ b/bootstrap/bootstrap-installer/src/main/java/org/apache/maven/bootstrap/installer/BootstrapInstaller.java @@ -0,0 +1,121 @@ +package org.apache.maven.bootstrap.installer; + +/* + * Copyright 2001-2005 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 org.apache.maven.bootstrap.model.Dependency; +import org.apache.maven.bootstrap.model.ModelReader; +import org.apache.maven.bootstrap.util.FileUtils; +import org.apache.maven.bootstrap.Bootstrap; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; + +/** + * Main class for bootstrap module. + * + * @author Brett Porter + * @version $Id$ + */ +public class BootstrapInstaller +{ + private final Bootstrap bootstrapper; + + public BootstrapInstaller( String[] args ) + throws Exception + { + this.bootstrapper = new Bootstrap( args ); + } + + public static void main( String[] args ) + throws Exception + { + BootstrapInstaller bootstrap = new BootstrapInstaller( args ); + + bootstrap.run(); + } + + private void run() + throws Exception + { + Date fullStart = new Date(); + + String basedir = System.getProperty( "user.dir" ); + + // TODO: only build this guy, then move the next part to a new phase using it for resolution + // Root POM +// buildProject( basedir, "", resolver, false ); +// buildProject( basedir, "maven-artifact-manager", resolver ); + + bootstrapper.buildProject( new File( basedir ), true ); + + createInstallation( new File( basedir, "target/installation" ) ); + + Bootstrap.stats( fullStart, new Date() ); + } + + private void createInstallation( File dir ) + throws IOException + { + FileUtils.deleteDirectory( dir ); + + dir.mkdirs(); + + File libDirectory = new File( dir, "lib" ); + libDirectory.mkdir(); + + File binDirectory = new File( dir, "bin" ); + + File coreDirectory = new File( dir, "core" ); + coreDirectory.mkdir(); + + File bootDirectory = new File( coreDirectory, "boot" ); + bootDirectory.mkdir(); + + ModelReader reader = bootstrapper.getCachedModel( "org.apache.maven", "maven-core" ); + + for ( Iterator i = reader.getDependencies().iterator(); i.hasNext(); ) + { + Dependency dep = (Dependency) i.next(); + + if ( dep.getArtifactId().equals( "classworlds" ) ) + { + FileUtils.copyFileToDirectory( bootstrapper.getArtifactFile( dep ), bootDirectory ); + } + else if ( dep.getArtifactId().equals( "plexus-container-default" ) || + dep.getArtifactId().equals( "plexus-utils" ) ) + { + FileUtils.copyFileToDirectory( bootstrapper.getArtifactFile( dep ), coreDirectory ); + } + else + { + FileUtils.copyFileToDirectory( bootstrapper.getArtifactFile( dep ), libDirectory ); + } + } + + Dependency coreAsDep = new Dependency( reader.getGroupId(), reader.getArtifactId(), reader.getVersion(), + reader.getPackaging(), Collections.EMPTY_LIST ); + + FileUtils.copyFileToDirectory( bootstrapper.getArtifactFile( coreAsDep ), libDirectory ); + + File srcBinDirectory = new File( reader.getProjectFile().getParentFile(), "src/bin" ); + + FileUtils.copyDirectory( srcBinDirectory, binDirectory, null, "**/.svn/**" ); + } +} diff --git a/bootstrap/bootstrap-installer/src/main/resources/META-INF/MANIFEST.MF b/bootstrap/bootstrap-installer/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..29d4216433 --- /dev/null +++ b/bootstrap/bootstrap-installer/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Main-Class: org.apache.maven.bootstrap.installer.BootstrapInstaller diff --git a/bootstrap/build b/bootstrap/bootstrap-mini/build similarity index 64% rename from bootstrap/build rename to bootstrap/bootstrap-mini/build index 273130fb97..a2412df6da 100755 --- a/bootstrap/build +++ b/bootstrap/bootstrap-mini/build @@ -10,4 +10,4 @@ mkdir -p ${classesDir} "$JAVA_HOME/bin/javac" -g -d ${classesDir} `find ${srcDir} -name '*.java'` -( cd ${classesDir} ; "$JAVA_HOME/bin/jar" -cfm ../bootstrap.jar ../../src/main/resources/META-INF/MANIFEST.MF * ) +( cd ${classesDir} ; "$JAVA_HOME/bin/jar" -cfm ../bootstrap-mini.jar ../../src/main/resources/META-INF/MANIFEST.MF * ) diff --git a/bootstrap/build.bat b/bootstrap/bootstrap-mini/build.bat similarity index 77% rename from bootstrap/build.bat rename to bootstrap/bootstrap-mini/build.bat index 84b5934108..fe4751d009 100644 --- a/bootstrap/build.bat +++ b/bootstrap/bootstrap-mini/build.bat @@ -15,5 +15,5 @@ dir /B /s %srcDir%\*.java >sources del /F/Q sources cd %classesDir% -"%JAVA_HOME%\bin\jar" -cfm ..\bootstrap.jar ..\..\src\main\resources\META-INF\MANIFEST.MF *.* +"%JAVA_HOME%\bin\jar" -cfm ..\bootstrap-mini.jar ..\..\src\main\resources\META-INF\MANIFEST.MF *.* cd ..\.. diff --git a/bootstrap/bootstrap-mini/pom.xml b/bootstrap/bootstrap-mini/pom.xml new file mode 100644 index 0000000000..4bee4657e3 --- /dev/null +++ b/bootstrap/bootstrap-mini/pom.xml @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven.bootstrap + bootstrap-mini + 2.0.1-SNAPSHOT + Maven Bootstrap Mini Builder + Tool used to bootstrap m2. + diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/Bootstrap.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java similarity index 84% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/Bootstrap.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java index f141dc20a2..e606b77895 100644 --- a/bootstrap/src/main/java/org/apache/maven/bootstrap/Bootstrap.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/Bootstrap.java @@ -21,6 +21,7 @@ import org.apache.maven.bootstrap.compile.JavacCompiler; import org.apache.maven.bootstrap.download.ArtifactResolver; import org.apache.maven.bootstrap.download.OfflineArtifactResolver; import org.apache.maven.bootstrap.download.OnlineArtifactDownloader; +import org.apache.maven.bootstrap.download.RepositoryMetadata; import org.apache.maven.bootstrap.model.Dependency; import org.apache.maven.bootstrap.model.ModelReader; import org.apache.maven.bootstrap.model.Plugin; @@ -45,7 +46,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -55,6 +55,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TimeZone; +import java.util.Collections; /** * Main class for bootstrap module. @@ -72,12 +73,45 @@ public class Bootstrap private Map modelCache = new HashMap(); + private final ArtifactResolver resolver; + + public Bootstrap( String[] args ) + throws Exception + { + String userHome = System.getProperty( "user.home" ); + + File settingsXml = getSettingsPath( userHome, args ); + + System.out.println( "Using settings from " + settingsXml ); + + Settings settings = Settings.read( userHome, settingsXml ); + + // TODO: have an alternative implementation of ArtifactResolver for source compiles + // - if building from source, checkout and build then resolve to built jar (still download POM?) + resolver = setupRepositories( settings ); + } + public static void main( String[] args ) throws Exception { - Bootstrap bootstrap = new Bootstrap(); + Bootstrap bootstrap = new Bootstrap( args ); - bootstrap.run( args ); + String goal = null; + for ( int i = 0; i < args.length && goal == null; i++ ) + { + if ( args[i].equals( "install" ) || args[i].equals( "package" ) ) + { + goal = args[i]; + } + } + + if ( goal == null ) + { + System.err.println( "Goal 'package' or 'install' must be specified" ); + return; + } + + bootstrap.run( goal ); } private static File getSettingsPath( String userHome, String[] args ) @@ -97,88 +131,78 @@ public class Bootstrap return new File( userHome, ".m2/settings.xml" ); } - private void run( String[] args ) + private void run( String goal ) throws Exception { Date fullStart = new Date(); - String userHome = System.getProperty( "user.home" ); - - File settingsXml = getSettingsPath( userHome, args ); - - System.out.println( "Using settings from " + settingsXml ); - - Settings settings = Settings.read( userHome, settingsXml ); - - // TODO: have an alternative implementation of ArtifactDownloader for source compiles - // - if building from source, checkout and build then resolve to built jar (still download POM?) - ArtifactResolver resolver = setupRepositories( settings ); - String basedir = System.getProperty( "user.dir" ); - // TODO: only build this guy, then move the next part to a new phase using it for resolution - // Root POM -// buildProject( basedir, "", resolver, false ); -// buildProject( basedir, "maven-artifact-manager", resolver ); - - // Pre-cache models so we know where they are for dependencies - cacheModels( new File( basedir ), resolver ); - - buildProject( new File( basedir ), resolver, true ); - - createInstallation( new File( basedir, "target/installation" ), resolver ); + if ( "install".equals( goal ) ) + { + File pom = new File( basedir, "pom.xml" ); + ModelReader reader = readModel( resolver, pom, true ); + File jar = buildProject( reader ); + install( reader, pom, jar ); + } + else + { + buildProject( new File( basedir ), false ); + } stats( fullStart, new Date() ); } - private void createInstallation( File dir, ArtifactResolver resolver ) + private void install( ModelReader reader, File pom, File jar ) + throws Exception + { + String artifactId = reader.getArtifactId(); + + String version = reader.getVersion(); + + String groupId = reader.getGroupId(); + + String type = reader.getPackaging(); + + Repository localRepository = resolver.getLocalRepository(); + File file = localRepository.getArtifactFile( + new Dependency( groupId, artifactId, version, type, Collections.EMPTY_LIST ) ); + + System.out.println( "Installing: " + file ); + + FileUtils.copyFile( jar, file ); + + installPomFile( reader, pom ); + + RepositoryMetadata metadata = new RepositoryMetadata(); + metadata.setReleaseVersion( version ); + metadata.setLatestVersion( version ); + file = localRepository.getMetadataFile( groupId, artifactId, null, type, "maven-metadata-local.xml" ); + metadata.write( file ); + + metadata = new RepositoryMetadata(); + metadata.setLocalCopy( true ); + metadata.setLastUpdated( getCurrentUtcDate() ); + file = localRepository.getMetadataFile( groupId, artifactId, version, type, "maven-metadata-local.xml" ); + metadata.write( file ); + } + + private void installPomFile( ModelReader reader, File source ) throws IOException { - FileUtils.deleteDirectory( dir ); + String artifactId = reader.getArtifactId(); - dir.mkdirs(); + String version = reader.getVersion(); - File libDirectory = new File( dir, "lib" ); - libDirectory.mkdir(); + String groupId = reader.getGroupId(); - File binDirectory = new File( dir, "bin" ); + Repository localRepository = resolver.getLocalRepository(); + File pom = localRepository.getMetadataFile( groupId, artifactId, version, reader.getPackaging(), + artifactId + "-" + version + ".pom" ); - File coreDirectory = new File( dir, "core" ); - coreDirectory.mkdir(); + System.out.println( "Installing POM: " + pom ); - File bootDirectory = new File( coreDirectory, "boot" ); - bootDirectory.mkdir(); - - ModelReader reader = (ModelReader) modelCache.get( "org.apache.maven:maven-core" ); - - for ( Iterator i = reader.getDependencies().iterator(); i.hasNext(); ) - { - Dependency dep = (Dependency) i.next(); - - if ( dep.getArtifactId().equals( "classworlds" ) ) - { - FileUtils.copyFileToDirectory( resolver.getArtifactFile( dep ), bootDirectory ); - } - else if ( dep.getArtifactId().equals( "plexus-container-default" ) || - dep.getArtifactId().equals( "plexus-utils" ) ) - { - FileUtils.copyFileToDirectory( resolver.getArtifactFile( dep ), coreDirectory ); - } - else - { - FileUtils.copyFileToDirectory( resolver.getArtifactFile( dep ), libDirectory ); - } - } - - Dependency coreAsDep = new Dependency( reader.getGroupId(), reader.getArtifactId(), reader.getVersion(), - reader.getPackaging(), Collections.EMPTY_LIST ); - - FileUtils.copyFileToDirectory( resolver.getArtifactFile( coreAsDep ), libDirectory ); - - File srcBinDirectory = (File) modelFileCache.get( "org.apache.maven:maven-core" ); - srcBinDirectory = new File( srcBinDirectory.getParentFile(), "src/bin" ); - - FileUtils.copyDirectory( srcBinDirectory, binDirectory, null, "**/.svn/**" ); + FileUtils.copyFile( source, pom ); } private void cacheModels( File basedir, ArtifactResolver resolver ) @@ -194,9 +218,15 @@ public class Bootstrap } } - private void buildProject( File basedir, ArtifactResolver resolver, boolean buildModules ) + public void buildProject( File basedir, boolean buildModules ) throws Exception { + if ( buildModules ) + { + // Pre-cache models so we know where they are for dependencies + cacheModels( basedir, resolver ); + } + System.setProperty( "basedir", basedir.getAbsolutePath() ); File file = new File( basedir, "pom.xml" ); @@ -217,7 +247,7 @@ public class Bootstrap { String module = (String) i.next(); - buildProject( new File( basedir, module ), resolver, true ); + buildProject( new File( basedir, module ), true ); } } @@ -231,6 +261,16 @@ public class Bootstrap return; } + buildProject( reader ); + + inProgress.remove( key ); + } + + private File buildProject( ModelReader reader ) + throws Exception + { + File basedir = reader.getProjectFile().getParentFile(); + String sources = new File( basedir, "src/main/java" ).getAbsolutePath(); String resources = new File( basedir, "src/main/resources" ).getAbsolutePath(); @@ -248,7 +288,7 @@ public class Bootstrap if ( modelFileCache.containsKey( dep.getId() ) ) { - buildProject( resolver.getArtifactFile( dep.getPomDependency() ).getParentFile(), resolver, false ); + buildProject( resolver.getArtifactFile( dep.getPomDependency() ).getParentFile(), false ); } } @@ -336,7 +376,7 @@ public class Bootstrap line(); - inProgress.remove( key ); + return jarFile; } private ModelReader readModel( ArtifactResolver resolver, File file, boolean resolveTransitiveDependencies ) @@ -528,7 +568,7 @@ public class Bootstrap } } - private void stats( Date fullStart, Date fullStop ) + public static void stats( Date fullStart, Date fullStop ) { long fullDiff = fullStop.getTime() - fullStart.getTime(); @@ -696,4 +736,14 @@ public class Bootstrap return cl; } + + public ModelReader getCachedModel( String groupId, String artifactId ) + { + return (ModelReader) modelCache.get( groupId + ":" + artifactId ); + } + + public File getArtifactFile( Dependency dep ) + { + return resolver.getArtifactFile( dep ); + } } diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/compile/AbstractCompiler.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/AbstractCompiler.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/compile/AbstractCompiler.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/AbstractCompiler.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/compile/Compiler.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/Compiler.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/compile/Compiler.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/Compiler.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/compile/CompilerConfiguration.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/CompilerConfiguration.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/compile/CompilerConfiguration.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/CompilerConfiguration.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/compile/CompilerError.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/CompilerError.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/compile/CompilerError.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/CompilerError.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/compile/JavacCompiler.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/JavacCompiler.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/compile/JavacCompiler.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/compile/JavacCompiler.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/AbstractArtifactResolver.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/AbstractArtifactResolver.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/AbstractArtifactResolver.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/AbstractArtifactResolver.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/ArtifactResolver.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/ArtifactResolver.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/ArtifactResolver.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/ArtifactResolver.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/Base64.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/Base64.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/Base64.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/Base64.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/DownloadFailedException.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/DownloadFailedException.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/DownloadFailedException.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/DownloadFailedException.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/HttpUtils.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/HttpUtils.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/HttpUtils.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/HttpUtils.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/OfflineArtifactResolver.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/OfflineArtifactResolver.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/OfflineArtifactResolver.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/OfflineArtifactResolver.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/OnlineArtifactDownloader.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/OnlineArtifactDownloader.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/OnlineArtifactDownloader.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/OnlineArtifactDownloader.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/Dependency.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Dependency.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/model/Dependency.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Dependency.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/Exclusion.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Exclusion.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/model/Exclusion.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Exclusion.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java similarity index 98% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java index 86785fb2d5..a57495cff1 100644 --- a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/ModelReader.java @@ -16,13 +16,14 @@ package org.apache.maven.bootstrap.model; * limitations under the License. */ -import org.apache.maven.bootstrap.download.DownloadFailedException; import org.apache.maven.bootstrap.download.ArtifactResolver; +import org.apache.maven.bootstrap.download.DownloadFailedException; import org.apache.maven.bootstrap.util.AbstractReader; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -34,8 +35,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import com.sun.corba.se.impl.ior.ObjectAdapterIdArray; - /** * Parse a POM. * @@ -276,7 +275,7 @@ public class ModelReader } // actually, these should be transtive (see MNG-77) - but some projects have circular deps that way - ModelReader p = retrievePom( parentGroupId, parentArtifactId, parentVersion, "pom", inheritedScope, false, + ModelReader p = retrievePom( parentGroupId, parentArtifactId, parentVersion, inheritedScope, false, excluded, Collections.EMPTY_LIST ); addDependencies( p.getDependencies(), parentDependencies, inheritedScope, excluded ); @@ -529,7 +528,7 @@ public class ModelReader excluded.addAll( dependency.getExclusions() ); ModelReader p = retrievePom( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getVersion(), dependency.getType(), + dependency.getVersion(), dependency.getScope(), resolveTransitiveDependencies, excluded, dependency.getChain() ); @@ -586,9 +585,8 @@ public class ModelReader return false; } - private ModelReader retrievePom( String groupId, String artifactId, String version, String type, - String inheritedScope, boolean resolveTransitiveDependencies, Set excluded, - List chain ) + private ModelReader retrievePom( String groupId, String artifactId, String version, String inheritedScope, + boolean resolveTransitiveDependencies, Set excluded, List chain ) throws SAXException { String key = groupId + ":" + artifactId + ":" + version; @@ -657,4 +655,9 @@ public class ModelReader { return modules; } + + public File getProjectFile() + { + return pomFile; + } } diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/Plugin.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Plugin.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/model/Plugin.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Plugin.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/Repository.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Repository.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/model/Repository.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Repository.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/model/Resource.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Resource.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/model/Resource.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/model/Resource.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/settings/Mirror.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/settings/Mirror.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/settings/Mirror.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/settings/Mirror.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/settings/Proxy.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/settings/Proxy.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/settings/Proxy.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/settings/Proxy.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/settings/Settings.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/settings/Settings.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/settings/Settings.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/settings/Settings.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/AbstractReader.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/AbstractReader.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/AbstractReader.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/AbstractReader.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/DirectoryScanner.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/DirectoryScanner.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/DirectoryScanner.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/DirectoryScanner.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/FileUtils.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/FileUtils.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/FileUtils.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/FileUtils.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/IOUtil.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/IOUtil.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/IOUtil.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/IOUtil.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/IsolatedClassLoader.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/IsolatedClassLoader.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/IsolatedClassLoader.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/IsolatedClassLoader.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/JarMojo.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/JarMojo.java similarity index 78% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/JarMojo.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/JarMojo.java index d440550613..6828ea0a9d 100644 --- a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/JarMojo.java +++ b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/JarMojo.java @@ -32,6 +32,8 @@ public class JarMojo { private byte[] buffer = new byte[4096]; + private static final String MF = "META-INF/MANIFEST.MF"; + public void execute( File basedir, File jarFile ) throws Exception { @@ -46,9 +48,10 @@ public class JarMojo * Add all files in the specified directory to the archive. * * @param includes a map of items to be include in the outpur - * @param baseDir the directory to add + * @param baseDir the directory to add */ - protected void addDirectory( Map includes, File baseDir ) throws IOException + protected void addDirectory( Map includes, File baseDir ) + throws IOException { addDirectory( includes, "", baseDir ); } @@ -57,10 +60,11 @@ public class JarMojo * Add all files in the specified directory to the archive. * * @param includes a map of items to be include in the outpur - * @param prefix value to be added to the front of jar entry names - * @param baseDir the directory to add + * @param prefix value to be added to the front of jar entry names + * @param baseDir the directory to add */ - protected void addDirectory( Map includes, String prefix, File baseDir ) throws IOException + protected void addDirectory( Map includes, String prefix, File baseDir ) + throws IOException { addDirectory( includes, null, null, prefix, baseDir ); } @@ -68,13 +72,14 @@ public class JarMojo /** * Add all files in the specified directory to the archive. * - * @param includes a map of items to be include in the outpur + * @param includes a map of items to be include in the outpur * @param includesPattern Sets the list of include patterns to use * @param excludesPattern Sets the list of exclude patterns to use - * @param prefix value to be added to the front of jar entry names - * @param baseDir the directory to add + * @param prefix value to be added to the front of jar entry names + * @param baseDir the directory to add */ - protected void addDirectory( Map includes, String includesPattern, String excludesPattern, String prefix, File baseDir ) + protected void addDirectory( Map includes, String includesPattern, String excludesPattern, String prefix, + File baseDir ) throws IOException { if ( !baseDir.exists() ) @@ -106,18 +111,19 @@ public class JarMojo /** * Create the jar file specified and include the listed files. * - * @param jarFile the jar file to create + * @param jarFile the jar file to create * @param includes a Mapof items to include; the key is the jar entry name * @throws IOException if there is a problem writing the archive or reading the sources */ - protected void createJar( File jarFile, Map includes ) throws IOException + protected void createJar( File jarFile, Map includes ) + throws IOException { File parentJarFile = jarFile.getParentFile(); if ( !parentJarFile.exists() ) { parentJarFile.mkdirs(); } - JarOutputStream jos = createJar( jarFile, createManifest() ); + JarOutputStream jos = createJar( jarFile, includes.containsKey( "META-INF/MANIFEST.MF" ) ); try { addEntries( jos, includes ); @@ -138,7 +144,7 @@ public class JarMojo Manifest mf = new Manifest(); Attributes attrs = mf.getMainAttributes(); attrs.putValue( Attributes.Name.MANIFEST_VERSION.toString(), "1.0" ); - attrs.putValue( "Created-By", "2.0 (Apache Maven)" ); + attrs.putValue( "Created-By", "Apache Maven Bootstrap Mini" ); return mf; } @@ -146,17 +152,25 @@ public class JarMojo * Create the specified jar file and return a JarOutputStream to it * * @param jarFile the jar file to create - * @param mf the manifest to use + * @param manifestIncluded if the manifest is included * @return a JarOutputStream that can be used to write to that file * @throws IOException if there was a problem opening the file */ - protected JarOutputStream createJar( File jarFile, Manifest mf ) throws IOException + protected JarOutputStream createJar( File jarFile, boolean manifestIncluded ) + throws IOException { jarFile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream( jarFile ); try { - return new JarOutputStream( fos, mf ); + if ( manifestIncluded ) + { + return new JarOutputStream( fos ); + } + else + { + return new JarOutputStream( fos, createManifest() ); + } } catch ( IOException e ) { @@ -176,11 +190,12 @@ public class JarMojo /** * Add all entries in the supplied Map to the jar * - * @param jos a JarOutputStream that can be used to write to the jar + * @param jos a JarOutputStream that can be used to write to the jar * @param includes a Map of entries to add * @throws IOException if there is a problem writing the archive or reading the sources */ - protected void addEntries( JarOutputStream jos, Map includes ) throws IOException + protected void addEntries( JarOutputStream jos, Map includes ) + throws IOException { for ( Iterator i = includes.entrySet().iterator(); i.hasNext(); ) { @@ -194,12 +209,13 @@ public class JarMojo /** * Add a single entry to the jar * - * @param jos a JarOutputStream that can be used to write to the jar - * @param name the entry name to use; must be '/' delimited + * @param jos a JarOutputStream that can be used to write to the jar + * @param name the entry name to use; must be '/' delimited * @param source the file to add * @throws IOException if there is a problem writing the archive or reading the sources */ - protected void addEntry( JarOutputStream jos, String name, File source ) throws IOException + protected void addEntry( JarOutputStream jos, String name, File source ) + throws IOException { FileInputStream fis = new FileInputStream( source ); try diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/SelectorUtils.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/SelectorUtils.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/SelectorUtils.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/SelectorUtils.java diff --git a/bootstrap/src/main/java/org/apache/maven/bootstrap/util/StringUtils.java b/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/StringUtils.java similarity index 100% rename from bootstrap/src/main/java/org/apache/maven/bootstrap/util/StringUtils.java rename to bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/util/StringUtils.java diff --git a/bootstrap/src/main/resources/META-INF/MANIFEST.MF b/bootstrap/bootstrap-mini/src/main/resources/META-INF/MANIFEST.MF similarity index 100% rename from bootstrap/src/main/resources/META-INF/MANIFEST.MF rename to bootstrap/bootstrap-mini/src/main/resources/META-INF/MANIFEST.MF diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh new file mode 100755 index 0000000000..1d8687d9ed --- /dev/null +++ b/bootstrap/bootstrap.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# TODO: error checking + +( + cd bootstrap-mini + ./build + java -jar target/bootstrap-mini.jar install +) + +BOOTSTRAP_JAR=../bootstrap-mini/target/bootstrap-mini-2.0.1-SNAPSHOT.jar + +( + cd bootstrap-installer + java -jar $BOOTSTRAP_JAR package +) + +( + cd .. + java -classpath bootstrap/bootstrap-installer/target/bootstrap-installer-2.0.1-SNAPSHOT.jar:bootstrap/bootstrap-mini/target/bootstrap-mini-2.0.1-SNAPSHOT.jar org.apache.maven.bootstrap.installer.BootstrapInstaller +) +