mirror of
https://github.com/apache/maven.git
synced 2025-02-28 21:59:13 +00:00
o has now been replaced with the simplified bootstrap
o talking with jesse to get it hooked up in Continuum somewhere git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@465888 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9f47e18c85
commit
e13f6bd039
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2005-2006 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.bootstrap</groupId>
|
||||
<artifactId>bootstrap-installer</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<name>Maven Bootstrap Installer</name>
|
||||
<description>Tool used to bootstrap m2.</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.bootstrap</groupId>
|
||||
<artifactId>bootstrap-mini</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,286 +0,0 @@
|
||||
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.Bootstrap;
|
||||
import org.apache.maven.bootstrap.download.*;
|
||||
import org.apache.maven.bootstrap.model.*;
|
||||
import org.apache.maven.bootstrap.util.FileUtils;
|
||||
import org.apache.maven.bootstrap.util.SimpleArgumentParser;
|
||||
import org.codehaus.plexus.util.Expand;
|
||||
import org.codehaus.plexus.util.Os;
|
||||
import org.codehaus.plexus.util.cli.CommandLineException;
|
||||
import org.codehaus.plexus.util.cli.CommandLineUtils;
|
||||
import org.codehaus.plexus.util.cli.Commandline;
|
||||
import org.codehaus.plexus.util.cli.WriterStreamConsumer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Main class for bootstrap module.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BootstrapInstaller
|
||||
{
|
||||
private static final String MAVEN_GROUPID = "org.apache.maven";
|
||||
|
||||
private final Bootstrap bootstrapper;
|
||||
|
||||
private final String destDir;
|
||||
|
||||
private String pluginsDirectory;
|
||||
|
||||
private boolean buildPlugins;
|
||||
|
||||
private boolean updateSnapshots;
|
||||
|
||||
private boolean offline;
|
||||
|
||||
public BootstrapInstaller( SimpleArgumentParser parser )
|
||||
throws Exception
|
||||
{
|
||||
this.bootstrapper = new Bootstrap( parser );
|
||||
|
||||
this.destDir = parser.getArgumentValue( "--destDir" );
|
||||
|
||||
this.buildPlugins = parser.isArgumentSet( "--build-plugins" );
|
||||
|
||||
this.pluginsDirectory = parser.getArgumentValue( "--plugins-directory" );
|
||||
|
||||
// TODO: use from Bootstrap.java
|
||||
this.updateSnapshots = parser.isArgumentSet( "--update-snapshots" );
|
||||
|
||||
this.offline = parser.isArgumentSet( "--offline" );
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
throws Exception
|
||||
{
|
||||
SimpleArgumentParser parser = Bootstrap.createDefaultParser();
|
||||
parser.addArgument( "--destDir", "The location to install Maven", true, getDefaultPrefix() );
|
||||
parser.addArgument( "--build-plugins", "Build the plugins from SVN" );
|
||||
parser.addArgument( "--plugins-directory", "Where the plugins are located to build from", true );
|
||||
parser.addArgument( "--update-snapshots", "Update snapshots during build" );
|
||||
parser.addArgument( "--offline", "Run build in offline mode", "-o" );
|
||||
|
||||
parser.parseCommandLineArguments( args );
|
||||
|
||||
BootstrapInstaller bootstrap = new BootstrapInstaller( parser );
|
||||
|
||||
bootstrap.run();
|
||||
}
|
||||
|
||||
private static String getDefaultPrefix()
|
||||
{
|
||||
String value;
|
||||
if ( Os.isFamily( "windows" ) )
|
||||
{
|
||||
value = "c:\\program files";
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "/usr/local";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
Model mavenRootModel = bootstrapper.readModel(new File(basedir, "pom.xml"), false);
|
||||
|
||||
String finalName = "maven-" + mavenRootModel.getVersion();
|
||||
|
||||
File destDirFile = new File(destDir);
|
||||
if (!finalName.equals(destDirFile.getName())) {
|
||||
throw new Exception("The Maven install destination directory must end with '" + finalName + "'.\n"
|
||||
+ "Your destDir was = " + destDirFile.getAbsolutePath() + "\n"
|
||||
+ "we recommend = " + new File(destDirFile.getParent(), finalName).getAbsolutePath());
|
||||
}
|
||||
|
||||
bootstrapper.buildProject( new File( basedir ), true );
|
||||
|
||||
Model mavenCliModel = bootstrapper.getCachedModel( MAVEN_GROUPID, "maven-cli" );
|
||||
|
||||
File installation = new File( basedir, "bootstrap/target/installation" );
|
||||
createInstallation( installation, mavenCliModel );
|
||||
|
||||
// TODO: should just need assembly from basedir
|
||||
runMaven( installation, new File( basedir ), new String[]{"clean", "install"} );
|
||||
|
||||
File mavenCliDir = mavenCliModel.getProjectFile().getParentFile();
|
||||
runMaven( installation, mavenCliDir, new String[]{"clean", "assembly:assembly"} );
|
||||
|
||||
File file = new File( mavenCliDir, "target/" + finalName + "-bin.zip" );
|
||||
|
||||
File mavenHome = new File( destDir );
|
||||
|
||||
System.out.println( "Installing Maven in " + mavenHome );
|
||||
|
||||
FileUtils.deleteDirectory( mavenHome );
|
||||
|
||||
Expand expand = new Expand();
|
||||
expand.setSrc( file );
|
||||
expand.setDest( new File( destDir ).getParentFile() );
|
||||
expand.execute();
|
||||
|
||||
if ( !mavenHome.exists() )
|
||||
{
|
||||
throw new Exception( "Maven was not installed in " + mavenHome );
|
||||
}
|
||||
|
||||
fixScriptPermissions( new File( mavenHome, "bin" ) );
|
||||
|
||||
if ( buildPlugins )
|
||||
{
|
||||
if ( pluginsDirectory == null )
|
||||
{
|
||||
throw new UnsupportedOperationException( "SVN checkout of plugins not yet supported" );
|
||||
}
|
||||
|
||||
runMaven( installation, new File( pluginsDirectory ),
|
||||
new String[]{"--no-plugin-registry", "--fail-at-end", "clean", "install"} );
|
||||
}
|
||||
|
||||
Bootstrap.stats( fullStart, new Date() );
|
||||
}
|
||||
|
||||
private static void fixScriptPermissions( File binDirectory )
|
||||
throws InterruptedException, CommandLineException
|
||||
{
|
||||
if ( Os.isFamily( "unix" ) )
|
||||
{
|
||||
Commandline cli = new Commandline();
|
||||
|
||||
cli.setExecutable( "chmod" );
|
||||
|
||||
cli.createArgument().setValue( "+x" );
|
||||
|
||||
cli.createArgument().setValue( new File( binDirectory, "mvn" ).getAbsolutePath() );
|
||||
|
||||
cli.createArgument().setValue( new File( binDirectory, "m2" ).getAbsolutePath() );
|
||||
|
||||
cli.execute().waitFor();
|
||||
}
|
||||
}
|
||||
|
||||
private void runMaven( File installation, File basedir, String[] args )
|
||||
throws Exception, InterruptedException
|
||||
{
|
||||
Commandline cli = new Commandline();
|
||||
|
||||
cli.setExecutable( new File( installation, "bin/mvn" ).getAbsolutePath() );
|
||||
|
||||
cli.setWorkingDirectory( basedir.getAbsolutePath() );
|
||||
|
||||
cli.createArgument().setValue( "-e" );
|
||||
cli.createArgument().setValue( "--batch-mode" );
|
||||
|
||||
if ( offline )
|
||||
{
|
||||
cli.createArgument().setValue( "-o" );
|
||||
}
|
||||
if ( updateSnapshots )
|
||||
{
|
||||
cli.createArgument().setValue( "--update-snapshots" );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < args.length; i++ )
|
||||
{
|
||||
cli.createArgument().setValue( args[i] );
|
||||
}
|
||||
|
||||
System.out.println( "Running Maven... " );
|
||||
System.out.println( cli.toString() );
|
||||
|
||||
int exitCode = CommandLineUtils.executeCommandLine( cli,
|
||||
new WriterStreamConsumer( new PrintWriter( System.out ) ),
|
||||
new WriterStreamConsumer( new PrintWriter( System.err ) ) );
|
||||
|
||||
if ( exitCode != 0 )
|
||||
{
|
||||
throw new Exception( "Error executing Maven: exit code = " + exitCode );
|
||||
}
|
||||
}
|
||||
|
||||
private void createInstallation( File dir, Model mavenCliModel )
|
||||
throws IOException, CommandLineException, InterruptedException
|
||||
{
|
||||
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();
|
||||
|
||||
for ( Iterator i = mavenCliModel.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) i.next();
|
||||
|
||||
File artifactFile = bootstrapper.getArtifactFile( dep );
|
||||
if ( dep.getArtifactId().equals( "classworlds" ) )
|
||||
{
|
||||
FileUtils.copyFileToDirectory( artifactFile, bootDirectory );
|
||||
}
|
||||
else if ( dep.getArtifactId().equals( "plexus-container-default" ) ||
|
||||
dep.getArtifactId().equals( "plexus-utils" ) )
|
||||
{
|
||||
FileUtils.copyFileToDirectory( artifactFile, coreDirectory );
|
||||
}
|
||||
else
|
||||
{
|
||||
FileUtils.copyFileToDirectory( artifactFile, libDirectory );
|
||||
}
|
||||
}
|
||||
|
||||
Dependency coreAsDep = new Dependency( mavenCliModel.getGroupId(), mavenCliModel.getArtifactId(),
|
||||
mavenCliModel.getVersion(), mavenCliModel.getPackaging(),
|
||||
Collections.EMPTY_LIST );
|
||||
|
||||
FileUtils.copyFileToDirectory( bootstrapper.getArtifactFile( coreAsDep ), libDirectory );
|
||||
|
||||
File srcBinDirectory = new File( mavenCliModel.getProjectFile().getParentFile(), "src/bin" );
|
||||
|
||||
FileUtils.copyDirectory( srcBinDirectory, binDirectory, null, "**/.svn/**" );
|
||||
|
||||
fixScriptPermissions( binDirectory );
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: org.apache.maven.bootstrap.installer.BootstrapInstaller
|
||||
Class-Path: bootstrap-mini-2.1-SNAPSHOT.jar plexus-utils-1.0.4.jar
|
@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
buildDir=target
|
||||
classesDir=${buildDir}/classes
|
||||
srcDir=src/main/java
|
||||
|
||||
rm -rf bootstrap-mini.jar ${buildDir} > /dev/null 2>&1
|
||||
|
||||
mkdir -p ${classesDir}
|
||||
|
||||
"$JAVA_HOME/bin/javac" -g -d ${classesDir} `find ${srcDir} -name '*.java'`
|
||||
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
|
||||
|
||||
( cd ${classesDir} ; "$JAVA_HOME/bin/jar" -cfm ../../bootstrap-mini.jar ../../src/main/resources/META-INF/MANIFEST.MF * )
|
||||
ret=$?; if [ $ret != 0 ]; then exit $ret; fi
|
@ -1,19 +0,0 @@
|
||||
@echo off
|
||||
|
||||
set buildDir=target
|
||||
set classesDir=%buildDir%\classes
|
||||
set srcDir=src\main\java
|
||||
|
||||
if exist %classesDir% rmdir /S/Q %buildDir%
|
||||
if exist %buildDir% rmdir /S/Q %buildDir%
|
||||
|
||||
mkdir %buildDir%
|
||||
mkdir %classesDir%
|
||||
|
||||
dir /B /s %srcDir%\*.java >sources
|
||||
"%JAVA_HOME%\bin\javac" -d %classesDir% @sources
|
||||
del /F/Q sources
|
||||
|
||||
cd %classesDir%
|
||||
"%JAVA_HOME%\bin\jar" -cfm ..\bootstrap-mini.jar ..\..\src\main\resources\META-INF\MANIFEST.MF *.*
|
||||
cd ..\..
|
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright 2005-2006 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.bootstrap</groupId>
|
||||
<artifactId>bootstrap-mini</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<name>Maven Bootstrap Mini Builder</name>
|
||||
<description>Tool used to bootstrap m2.</description>
|
||||
</project>
|
@ -1,781 +0,0 @@
|
||||
package org.apache.maven.bootstrap;
|
||||
|
||||
/*
|
||||
* 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.compile.CompilerConfiguration;
|
||||
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.Model;
|
||||
import org.apache.maven.bootstrap.model.ModelReader;
|
||||
import org.apache.maven.bootstrap.model.Plugin;
|
||||
import org.apache.maven.bootstrap.model.Repository;
|
||||
import org.apache.maven.bootstrap.settings.Mirror;
|
||||
import org.apache.maven.bootstrap.settings.Proxy;
|
||||
import org.apache.maven.bootstrap.settings.Settings;
|
||||
import org.apache.maven.bootstrap.util.FileUtils;
|
||||
import org.apache.maven.bootstrap.util.IsolatedClassLoader;
|
||||
import org.apache.maven.bootstrap.util.JarMojo;
|
||||
import org.apache.maven.bootstrap.util.SimpleArgumentParser;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DateFormat;
|
||||
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;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
/**
|
||||
* Main class for bootstrap module.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Bootstrap
|
||||
{
|
||||
private static final String MODELLO_PLUGIN_ID = "org.codehaus.modello:modello-maven-plugin";
|
||||
|
||||
private Set inProgress = new HashSet();
|
||||
|
||||
private Map modelFileCache = new HashMap();
|
||||
|
||||
private Map modelCache = new HashMap();
|
||||
|
||||
private final ArtifactResolver resolver;
|
||||
|
||||
private static final String USER_HOME = System.getProperty( "user.home" );
|
||||
|
||||
public Bootstrap( SimpleArgumentParser parser )
|
||||
throws Exception
|
||||
{
|
||||
File settingsXml = new File( parser.getArgumentValue( "--settings" ) );
|
||||
|
||||
System.out.println( "Using settings from " + settingsXml );
|
||||
|
||||
Settings settings = Settings.read( USER_HOME, 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 SimpleArgumentParser createDefaultParser()
|
||||
{
|
||||
File defaultSettingsFile = new File( USER_HOME, ".m2/settings.xml" );
|
||||
SimpleArgumentParser parser = new SimpleArgumentParser();
|
||||
parser.addArgument( "--settings", "The location of the settings.xml file", "-s", true,
|
||||
defaultSettingsFile.getAbsolutePath() );
|
||||
return parser;
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
throws Exception
|
||||
{
|
||||
SimpleArgumentParser parser = createDefaultParser();
|
||||
|
||||
parser.parseCommandLineArguments( args );
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap( parser );
|
||||
|
||||
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 void run( String goal )
|
||||
throws Exception
|
||||
{
|
||||
Date fullStart = new Date();
|
||||
|
||||
String basedir = System.getProperty( "user.dir" );
|
||||
|
||||
File pom = new File( basedir, "pom.xml" );
|
||||
Model reader = readModel( pom, true );
|
||||
File jar = buildProject( reader );
|
||||
|
||||
if ( "install".equals( goal ) )
|
||||
{
|
||||
install( reader, pom, jar );
|
||||
}
|
||||
|
||||
for ( Iterator i = reader.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) i.next();
|
||||
|
||||
FileUtils.copyFileToDirectory( resolver.getArtifactFile( dep ), jar.getParentFile() );
|
||||
}
|
||||
|
||||
stats( fullStart, new Date() );
|
||||
}
|
||||
|
||||
private void install( Model model, File pom, File jar )
|
||||
throws Exception
|
||||
{
|
||||
String artifactId = model.getArtifactId();
|
||||
|
||||
String version = model.getVersion();
|
||||
|
||||
String groupId = model.getGroupId();
|
||||
|
||||
String type = model.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( model, 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( Model model, File source )
|
||||
throws IOException
|
||||
{
|
||||
String artifactId = model.getArtifactId();
|
||||
|
||||
String version = model.getVersion();
|
||||
|
||||
String groupId = model.getGroupId();
|
||||
|
||||
Repository localRepository = resolver.getLocalRepository();
|
||||
File pom = localRepository.getMetadataFile( groupId, artifactId, version, model.getPackaging(),
|
||||
artifactId + "-" + version + ".pom" );
|
||||
|
||||
System.out.println( "Installing POM: " + pom );
|
||||
|
||||
FileUtils.copyFile( source, pom );
|
||||
}
|
||||
|
||||
private void cacheModels( File basedir, ArtifactResolver resolver )
|
||||
throws IOException, ParserConfigurationException, SAXException
|
||||
{
|
||||
Model model = readModel( new File( basedir, "pom.xml" ), false );
|
||||
|
||||
for ( Iterator i = model.getModules().iterator(); i.hasNext(); )
|
||||
{
|
||||
String module = (String) i.next();
|
||||
|
||||
cacheModels( new File( basedir, module ), resolver );
|
||||
}
|
||||
}
|
||||
|
||||
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" );
|
||||
|
||||
Model model = readModel( file, true );
|
||||
|
||||
String key = model.getGroupId() + ":" + model.getArtifactId() + ":" + model.getPackaging();
|
||||
if ( inProgress.contains( key ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( model.getPackaging().equals( "pom" ) )
|
||||
{
|
||||
if ( buildModules )
|
||||
{
|
||||
for ( Iterator i = model.getModules().iterator(); i.hasNext(); )
|
||||
{
|
||||
String module = (String) i.next();
|
||||
|
||||
buildProject( new File( basedir, module ), true );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
inProgress.add( key );
|
||||
|
||||
if ( resolver.isAlreadyBuilt( key ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buildProject( model );
|
||||
|
||||
inProgress.remove( key );
|
||||
}
|
||||
|
||||
private File buildProject( Model model )
|
||||
throws Exception
|
||||
{
|
||||
File basedir = model.getProjectFile().getParentFile();
|
||||
|
||||
String sources = new File( basedir, "src/main/java" ).getAbsolutePath();
|
||||
|
||||
String resources = new File( basedir, "src/main/resources" ).getAbsolutePath();
|
||||
|
||||
String classes = new File( basedir, "target/classes" ).getAbsolutePath();
|
||||
|
||||
File buildDirFile = new File( basedir, "target" );
|
||||
String buildDir = buildDirFile.getAbsolutePath();
|
||||
|
||||
System.out.println( "Analysing dependencies ..." );
|
||||
|
||||
for ( Iterator i = model.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) i.next();
|
||||
|
||||
dep.getRepositories().addAll( model.getRepositories() );
|
||||
|
||||
if ( modelFileCache.containsKey( dep.getId() ) )
|
||||
{
|
||||
buildProject( resolver.getArtifactFile( dep.getPomDependency() ).getParentFile(), false );
|
||||
}
|
||||
}
|
||||
|
||||
resolver.downloadDependencies( model.getAllDependencies() );
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println( "Building project in " + basedir );
|
||||
|
||||
line();
|
||||
|
||||
// clean
|
||||
System.out.println( "Cleaning " + buildDirFile + "..." );
|
||||
FileUtils.forceDelete( buildDirFile );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Generate sources - modello
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
File generatedSourcesDirectory = null;
|
||||
if ( model.getPlugins().containsKey( MODELLO_PLUGIN_ID ) )
|
||||
{
|
||||
Plugin plugin = (Plugin) model.getPlugins().get( MODELLO_PLUGIN_ID );
|
||||
|
||||
File modelFile = new File( basedir, (String) plugin.getConfiguration().get( "model" ) );
|
||||
|
||||
System.out.println( "Model exists!" );
|
||||
|
||||
// acquire the version from the parent pom pluginManagement
|
||||
String version = plugin.getVersion();
|
||||
if ( ( version == null ) || ( version == "" ) )
|
||||
{
|
||||
Plugin managedPlugin = (Plugin) model.getManagedPlugins().get( MODELLO_PLUGIN_ID );
|
||||
|
||||
if ( managedPlugin == null )
|
||||
{
|
||||
throw new Exception( "can not determine version of " + MODELLO_PLUGIN_ID );
|
||||
}
|
||||
|
||||
plugin.setVersion( managedPlugin.getVersion() );
|
||||
}
|
||||
|
||||
String modelVersion = (String) plugin.getConfiguration().get( "version" );
|
||||
if ( modelVersion == null || modelVersion.trim().length() < 1 )
|
||||
{
|
||||
System.out.println( "No model version configured. Using \'1.0.0\'..." );
|
||||
modelVersion = "1.0.0";
|
||||
}
|
||||
|
||||
generatedSourcesDirectory = new File( basedir, "target/generated-sources/modello" );
|
||||
|
||||
if ( !generatedSourcesDirectory.exists() )
|
||||
{
|
||||
generatedSourcesDirectory.mkdirs();
|
||||
}
|
||||
|
||||
Dependency dependency = plugin.asDependencyPom();
|
||||
resolver.downloadDependencies( Collections.singletonList( dependency ) );
|
||||
File artifactFile = resolver.getArtifactFile( dependency );
|
||||
Model pluginReader = readModel( artifactFile, true );
|
||||
|
||||
List dependencies = new ArrayList();
|
||||
for ( Iterator i = pluginReader.getAllDependencies().iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
if ( !d.getGroupId().equals( "org.apache.maven" ) )
|
||||
{
|
||||
dependencies.add( d );
|
||||
}
|
||||
}
|
||||
|
||||
ClassLoader classLoader = createClassloaderFromDependencies( dependencies, null, resolver );
|
||||
|
||||
System.out.println( "Generating model bindings for version \'" + modelVersion + "\' from '" + model + "'" );
|
||||
|
||||
generateModelloSources( modelFile.getAbsolutePath(), "java", generatedSourcesDirectory, modelVersion, "false",
|
||||
classLoader );
|
||||
generateModelloSources( modelFile.getAbsolutePath(), "xpp3-reader", generatedSourcesDirectory, modelVersion,
|
||||
"false", classLoader );
|
||||
generateModelloSources( modelFile.getAbsolutePath(), "xpp3-writer", generatedSourcesDirectory, modelVersion,
|
||||
"false", classLoader );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Standard compile
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
System.out.println( "Compiling sources ..." );
|
||||
|
||||
compile( model.getAllDependencies(), sources, classes, null, generatedSourcesDirectory, Dependency.SCOPE_COMPILE,
|
||||
resolver );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Standard resources
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
System.out.println( "Packaging resources ..." );
|
||||
|
||||
copyResources( resources, classes );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Create JAR
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
File jarFile = createJar( new File( basedir, "pom.xml" ), classes, buildDir, model );
|
||||
|
||||
System.out.println( "Packaging " + jarFile + " ..." );
|
||||
|
||||
resolver.addBuiltArtifact( model.getGroupId(), model.getArtifactId(), "jar", jarFile );
|
||||
|
||||
line();
|
||||
|
||||
return jarFile;
|
||||
}
|
||||
|
||||
public Model readModel( File file, boolean resolveTransitiveDependencies )
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
ModelReader reader = new ModelReader( resolver, resolveTransitiveDependencies );
|
||||
|
||||
Model model = reader.parseModel( file, Collections.EMPTY_LIST );
|
||||
|
||||
resolver.addBuiltArtifact( model.getGroupId(), model.getArtifactId(), "pom", file );
|
||||
|
||||
String id = model.getGroupId() + ":" + model.getArtifactId();
|
||||
modelFileCache.put( id, file );
|
||||
|
||||
modelCache.put( id, model );
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public void line()
|
||||
{
|
||||
System.out.println( "------------------------------------------------------------------" );
|
||||
}
|
||||
|
||||
private File createJar( File pomFile, String classes, String buildDir, Model reader )
|
||||
throws Exception
|
||||
{
|
||||
JarMojo jarMojo = new JarMojo();
|
||||
|
||||
String artifactId = reader.getArtifactId();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Create pom.properties file
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
Properties p = new Properties();
|
||||
|
||||
p.setProperty( "groupId", reader.getGroupId() );
|
||||
|
||||
p.setProperty( "artifactId", reader.getArtifactId() );
|
||||
|
||||
p.setProperty( "version", reader.getVersion() );
|
||||
|
||||
File pomPropertiesDir =
|
||||
new File( new File( classes ), "META-INF/maven/" + reader.getGroupId() + "/" + reader.getArtifactId() );
|
||||
|
||||
pomPropertiesDir.mkdirs();
|
||||
|
||||
File pomPropertiesFile = new File( pomPropertiesDir, "pom.properties" );
|
||||
|
||||
OutputStream os = new FileOutputStream( pomPropertiesFile );
|
||||
|
||||
p.store( os, "Generated by Maven" );
|
||||
|
||||
os.close(); // stream is flushed but not closed by Properties.store()
|
||||
|
||||
FileUtils.copyFile( pomFile, new File( pomPropertiesDir, "pom.xml" ) );
|
||||
|
||||
File jarFile = new File( buildDir, artifactId + ".jar" );
|
||||
jarMojo.execute( new File( classes ), jarFile );
|
||||
|
||||
return jarFile;
|
||||
}
|
||||
|
||||
public String getCurrentUtcDate()
|
||||
{
|
||||
TimeZone timezone = TimeZone.getTimeZone( "UTC" );
|
||||
DateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss" );
|
||||
fmt.setTimeZone( timezone );
|
||||
return fmt.format( new Date() );
|
||||
}
|
||||
|
||||
private void copyResources( String sourceDirectory, String destinationDirectory )
|
||||
throws Exception
|
||||
{
|
||||
File sd = new File( sourceDirectory );
|
||||
|
||||
if ( !sd.exists() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List files = FileUtils.getFiles( sd, "**/**", "**/CVS/**,**/.svn/**", false );
|
||||
|
||||
for ( Iterator i = files.iterator(); i.hasNext(); )
|
||||
{
|
||||
File f = (File) i.next();
|
||||
|
||||
File source = new File( sourceDirectory, f.getPath() );
|
||||
|
||||
File dest = new File( destinationDirectory, f.getPath() );
|
||||
|
||||
if ( !dest.getParentFile().exists() )
|
||||
{
|
||||
dest.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
FileUtils.copyFile( source, dest );
|
||||
}
|
||||
}
|
||||
|
||||
private static ArtifactResolver setupRepositories( Settings settings )
|
||||
throws Exception
|
||||
{
|
||||
boolean online = true;
|
||||
|
||||
String onlineProperty = System.getProperty( "maven.online" );
|
||||
|
||||
if ( onlineProperty != null && onlineProperty.equals( "false" ) )
|
||||
{
|
||||
online = false;
|
||||
}
|
||||
|
||||
Repository localRepository =
|
||||
new Repository( "local", settings.getLocalRepository(), Repository.LAYOUT_DEFAULT, false, false );
|
||||
|
||||
File repoLocalFile = new File( localRepository.getBasedir() );
|
||||
repoLocalFile.mkdirs();
|
||||
|
||||
if ( !repoLocalFile.canWrite() )
|
||||
{
|
||||
throw new Exception( "Can't write to " + repoLocalFile );
|
||||
}
|
||||
|
||||
ArtifactResolver resolver;
|
||||
if ( online )
|
||||
{
|
||||
OnlineArtifactDownloader downloader = new OnlineArtifactDownloader( localRepository );
|
||||
resolver = downloader;
|
||||
if ( settings.getActiveProxy() != null )
|
||||
{
|
||||
Proxy proxy = settings.getActiveProxy();
|
||||
downloader.setProxy( proxy.getHost(), proxy.getPort(), proxy.getUserName(), proxy.getPassword() );
|
||||
}
|
||||
|
||||
List remoteRepos = downloader.getRemoteRepositories();
|
||||
List newRemoteRepos = new ArrayList();
|
||||
|
||||
for ( Iterator i = remoteRepos.iterator(); i.hasNext(); )
|
||||
{
|
||||
Repository repo = (Repository) i.next();
|
||||
|
||||
boolean foundMirror = false;
|
||||
for ( Iterator j = settings.getMirrors().iterator(); j.hasNext() && !foundMirror; )
|
||||
{
|
||||
Mirror m = (Mirror) j.next();
|
||||
if ( m.getMirrorOf().equals( repo.getId() ) )
|
||||
{
|
||||
newRemoteRepos.add( new Repository( m.getId(), m.getUrl(), repo.getLayout(), repo.isSnapshots(),
|
||||
repo.isReleases() ) );
|
||||
foundMirror = true;
|
||||
}
|
||||
}
|
||||
if ( !foundMirror )
|
||||
{
|
||||
newRemoteRepos.add( repo );
|
||||
}
|
||||
}
|
||||
|
||||
downloader.setRemoteRepositories( newRemoteRepos );
|
||||
|
||||
System.out.println( "Using the following for your local repository: " + localRepository );
|
||||
System.out.println( "Using the following for your remote repository: " + newRemoteRepos );
|
||||
}
|
||||
else
|
||||
{
|
||||
resolver = new OfflineArtifactResolver( localRepository );
|
||||
}
|
||||
|
||||
return resolver;
|
||||
}
|
||||
|
||||
protected static String formatTime( long ms )
|
||||
{
|
||||
long secs = ms / 1000;
|
||||
|
||||
long min = secs / 60;
|
||||
secs = secs % 60;
|
||||
|
||||
if ( min > 0 )
|
||||
{
|
||||
return min + " minutes " + secs + " seconds";
|
||||
}
|
||||
else
|
||||
{
|
||||
return secs + " seconds";
|
||||
}
|
||||
}
|
||||
|
||||
public static void stats( Date fullStart, Date fullStop )
|
||||
{
|
||||
long fullDiff = fullStop.getTime() - fullStart.getTime();
|
||||
|
||||
System.out.println( "Total time: " + formatTime( fullDiff ) );
|
||||
|
||||
System.out.println( "Finished at: " + fullStop );
|
||||
}
|
||||
|
||||
private void compile( Collection dependencies, String sourceDirectory, String outputDirectory,
|
||||
String extraClasspath, File generatedSources, String scope, ArtifactResolver resolver )
|
||||
throws Exception
|
||||
{
|
||||
JavacCompiler compiler = new JavacCompiler();
|
||||
|
||||
String[] sourceDirectories = null;
|
||||
|
||||
if ( generatedSources != null )
|
||||
{
|
||||
// We might only have generated sources
|
||||
|
||||
if ( new File( sourceDirectory ).exists() )
|
||||
{
|
||||
sourceDirectories = new String[]{sourceDirectory, generatedSources.getAbsolutePath()};
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceDirectories = new String[]{generatedSources.getAbsolutePath()};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( new File( sourceDirectory ).exists() )
|
||||
{
|
||||
sourceDirectories = new String[]{sourceDirectory};
|
||||
}
|
||||
}
|
||||
|
||||
if ( sourceDirectories != null )
|
||||
{
|
||||
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
||||
compilerConfiguration.setOutputLocation( outputDirectory );
|
||||
List classpathEntries = classpath( dependencies, extraClasspath, scope, resolver );
|
||||
compilerConfiguration.setNoWarn( true );
|
||||
compilerConfiguration.setClasspathEntries( classpathEntries );
|
||||
compilerConfiguration.setSourceLocations( Arrays.asList( sourceDirectories ) );
|
||||
|
||||
/* Compile with debugging info */
|
||||
String debugAsString = System.getProperty( "maven.compiler.debug", "true" );
|
||||
|
||||
if ( !Boolean.valueOf( debugAsString ).booleanValue() )
|
||||
{
|
||||
compilerConfiguration.setDebug( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
compilerConfiguration.setDebug( true );
|
||||
}
|
||||
|
||||
List messages = compiler.compile( compilerConfiguration );
|
||||
|
||||
for ( Iterator i = messages.iterator(); i.hasNext(); )
|
||||
{
|
||||
System.out.println( i.next() );
|
||||
}
|
||||
|
||||
if ( messages.size() > 0 )
|
||||
{
|
||||
throw new Exception( "Compilation error." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List classpath( Collection dependencies, String extraClasspath, String scope, ArtifactResolver resolver )
|
||||
{
|
||||
List classpath = new ArrayList( dependencies.size() + 1 );
|
||||
|
||||
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
||||
String element = resolver.getArtifactFile( d ).getAbsolutePath();
|
||||
|
||||
if ( Dependency.SCOPE_COMPILE.equals( scope ) )
|
||||
{
|
||||
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) )
|
||||
{
|
||||
classpath.add( element );
|
||||
}
|
||||
}
|
||||
else if ( Dependency.SCOPE_RUNTIME.equals( scope ) )
|
||||
{
|
||||
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) ||
|
||||
d.getScope().equals( Dependency.SCOPE_RUNTIME ) )
|
||||
{
|
||||
classpath.add( element );
|
||||
}
|
||||
}
|
||||
else if ( Dependency.SCOPE_TEST.equals( scope ) )
|
||||
{
|
||||
classpath.add( element );
|
||||
}
|
||||
}
|
||||
|
||||
if ( extraClasspath != null )
|
||||
{
|
||||
classpath.add( extraClasspath );
|
||||
}
|
||||
|
||||
return classpath;
|
||||
}
|
||||
|
||||
private void generateModelloSources( String model, String mode, File dir, String modelVersion,
|
||||
String packageWithVersion, ClassLoader modelloClassLoader )
|
||||
throws Exception
|
||||
{
|
||||
Class c = modelloClassLoader.loadClass( "org.codehaus.modello.ModelloCli" );
|
||||
|
||||
Object generator = c.newInstance();
|
||||
|
||||
Method m = c.getMethod( "main", new Class[]{String[].class} );
|
||||
|
||||
String[] args = new String[]{model, mode, dir.getAbsolutePath(), modelVersion, packageWithVersion};
|
||||
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
Thread.currentThread().setContextClassLoader( modelloClassLoader );
|
||||
|
||||
m.invoke( generator, new Object[]{args} );
|
||||
|
||||
Thread.currentThread().setContextClassLoader( old );
|
||||
}
|
||||
|
||||
private IsolatedClassLoader createClassloaderFromDependencies( Collection dependencies, ClassLoader parent,
|
||||
ArtifactResolver resolver )
|
||||
throws Exception
|
||||
{
|
||||
System.out.println( "Checking for dependencies ..." );
|
||||
|
||||
resolver.downloadDependencies( dependencies );
|
||||
|
||||
IsolatedClassLoader cl;
|
||||
if ( parent == null )
|
||||
{
|
||||
cl = new IsolatedClassLoader();
|
||||
}
|
||||
else
|
||||
{
|
||||
cl = new IsolatedClassLoader( parent );
|
||||
}
|
||||
|
||||
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency dependency = (Dependency) i.next();
|
||||
|
||||
File f = resolver.getArtifactFile( dependency );
|
||||
if ( !f.exists() )
|
||||
{
|
||||
String msg =
|
||||
( !resolver.isOnline() ? "; run again online" : "; there was a problem downloading it earlier" );
|
||||
throw new FileNotFoundException( "Missing dependency: " + dependency + msg );
|
||||
}
|
||||
|
||||
// Classes won't be unloaded, but we might delete the JAR, so they need to be copied to a temporary location
|
||||
File newFile = File.createTempFile( "maven-bootstrap", "dep" );
|
||||
newFile.deleteOnExit();
|
||||
FileUtils.copyFile( f, newFile );
|
||||
cl.addURL( newFile.toURL() );
|
||||
}
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
public Model getCachedModel( String groupId, String artifactId )
|
||||
{
|
||||
return (Model) modelCache.get( groupId + ":" + artifactId );
|
||||
}
|
||||
|
||||
public File getArtifactFile( Dependency dep )
|
||||
{
|
||||
return resolver.getArtifactFile( dep );
|
||||
}
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
package org.apache.maven.bootstrap.compile;
|
||||
|
||||
/*
|
||||
* 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.util.DirectoryScanner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
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 getPathString( List pathElements )
|
||||
throws Exception
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for ( Iterator it = pathElements.iterator(); it.hasNext(); )
|
||||
{
|
||||
String element = (String) it.next();
|
||||
|
||||
sb.append( element ).append( PS );
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected String[] getSourceFiles( CompilerConfiguration config )
|
||||
{
|
||||
Set sources = new HashSet();
|
||||
|
||||
Set sourceFiles = config.getSourceFiles();
|
||||
if ( sourceFiles != null && !sourceFiles.isEmpty() )
|
||||
{
|
||||
for ( Iterator it = sourceFiles.iterator(); it.hasNext(); )
|
||||
{
|
||||
File sourceFile = (File) it.next();
|
||||
sources.add( sourceFile.getAbsolutePath() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( Iterator it = config.getSourceLocations().iterator(); it.hasNext(); )
|
||||
{
|
||||
String sourceLocation = (String) it.next();
|
||||
|
||||
DirectoryScanner scanner = new DirectoryScanner();
|
||||
|
||||
scanner.setBasedir( sourceLocation );
|
||||
|
||||
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.getExcludes();
|
||||
if ( excludes != null && !excludes.isEmpty() )
|
||||
{
|
||||
String[] exclStrs = (String[]) excludes.toArray( new String[excludes.size()] );
|
||||
scanner.setIncludes( exclStrs );
|
||||
}
|
||||
|
||||
scanner.scan();
|
||||
|
||||
String[] sourceDirectorySources = scanner.getIncludedFiles();
|
||||
|
||||
for ( int j = 0; j < sourceDirectorySources.length; j++ )
|
||||
{
|
||||
File f = new File( sourceLocation, sourceDirectorySources[j] );
|
||||
|
||||
sources.add( f.getPath() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] result = null;
|
||||
|
||||
if ( sources.isEmpty() )
|
||||
{
|
||||
result = new String[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (String[]) sources.toArray( new String[sources.size()] );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String makeClassName( String fileName, String sourceDir )
|
||||
throws IOException
|
||||
{
|
||||
File origFile = new File( fileName );
|
||||
String canonical = null;
|
||||
|
||||
if ( origFile.exists() )
|
||||
{
|
||||
canonical = origFile.getCanonicalPath().replace( '\\', '/' );
|
||||
}
|
||||
|
||||
String str = fileName;
|
||||
str = str.replace( '\\', '/' );
|
||||
|
||||
if ( sourceDir != null )
|
||||
{
|
||||
String prefix = new File( sourceDir ).getCanonicalPath().replace( '\\', '/' );
|
||||
|
||||
if ( canonical != null )
|
||||
{
|
||||
if ( canonical.startsWith( prefix ) )
|
||||
{
|
||||
String result = canonical.substring( prefix.length() + 1, canonical.length() - 5 );
|
||||
|
||||
result = result.replace( '/', '.' );
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
File t = new File( sourceDir, fileName );
|
||||
|
||||
if ( t.exists() )
|
||||
{
|
||||
str = t.getCanonicalPath().replace( '\\', '/' );
|
||||
|
||||
String result = str.substring( prefix.length() + 1, str.length() - 5 ).replace( '/', '.' );
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( fileName.endsWith( ".java" ) )
|
||||
{
|
||||
fileName = fileName.substring( 0, fileName.length() - 5 );
|
||||
}
|
||||
|
||||
fileName = fileName.replace( '\\', '.' );
|
||||
|
||||
return fileName.replace( '/', '.' );
|
||||
}
|
||||
|
||||
protected String[] toStringArray( List arguments )
|
||||
{
|
||||
String[] args = new String[arguments.size()];
|
||||
|
||||
for ( int i = 0; i < arguments.size(); i++ )
|
||||
{
|
||||
args[i] = (String) arguments.get( i );
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package org.apache.maven.bootstrap.compile;
|
||||
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jason@plexus.org">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Compiler
|
||||
{
|
||||
static String ROLE = Compiler.class.getName();
|
||||
|
||||
List compile( CompilerConfiguration configuration )
|
||||
throws Exception;
|
||||
}
|
||||
|
@ -1,159 +0,0 @@
|
||||
package org.apache.maven.bootstrap.compile;
|
||||
|
||||
/*
|
||||
* 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 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;
|
||||
|
||||
private Set sourceFiles = new HashSet();
|
||||
|
||||
private boolean noWarn;
|
||||
|
||||
public void setSourceFiles(Set sourceFiles)
|
||||
{
|
||||
this.sourceFiles = sourceFiles;
|
||||
}
|
||||
|
||||
public Set getSourceFiles()
|
||||
{
|
||||
return sourceFiles;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void setNoWarn( boolean noWarn )
|
||||
{
|
||||
this.noWarn = noWarn;
|
||||
}
|
||||
|
||||
public boolean isNoWarn()
|
||||
{
|
||||
return noWarn;
|
||||
}
|
||||
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
package org.apache.maven.bootstrap.compile;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class encapsulates an error message produced by a programming language
|
||||
* processor (whether interpreted or compiled)
|
||||
*
|
||||
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
|
||||
* @version CVS $Id$
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
public class CompilerError
|
||||
{
|
||||
/**
|
||||
* Is this a severe error or a warning?
|
||||
*/
|
||||
private boolean error;
|
||||
/**
|
||||
* The start line number of the offending program text
|
||||
*/
|
||||
private int startline;
|
||||
/**
|
||||
* The start column number of the offending program text
|
||||
*/
|
||||
private int startcolumn;
|
||||
/**
|
||||
* The end line number of the offending program text
|
||||
*/
|
||||
private int endline;
|
||||
/**
|
||||
* The end column number of the offending program text
|
||||
*/
|
||||
private int endcolumn;
|
||||
/**
|
||||
* The name of the file containing the offending program text
|
||||
*/
|
||||
private String file;
|
||||
/**
|
||||
* The actual error text produced by the language processor
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
)
|
||||
{
|
||||
this.file = file;
|
||||
this.error = error;
|
||||
this.startline = startline;
|
||||
this.startcolumn = startcolumn;
|
||||
this.endline = endline;
|
||||
this.endcolumn = endcolumn;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* The error message constructor.
|
||||
*
|
||||
* @param message The actual error text produced by the language processor
|
||||
*/
|
||||
public CompilerError( String message )
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* The error message constructor.
|
||||
*
|
||||
* @param message The actual error text produced by the language processor
|
||||
* @param error whether it was an error or informational
|
||||
*/
|
||||
public CompilerError( String message, boolean error )
|
||||
{
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filename associated with this compiler error.
|
||||
*
|
||||
* @return The filename associated with this compiler error
|
||||
*/
|
||||
public String getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert whether this is a severe error or a warning
|
||||
*
|
||||
* @return Whether the error is severe
|
||||
*/
|
||||
public boolean isError()
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the starting line number of the program text originating this error
|
||||
*
|
||||
* @return The starting line number of the program text originating this error
|
||||
*/
|
||||
public int getStartLine()
|
||||
{
|
||||
return startline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the starting column number of the program text originating this
|
||||
* error
|
||||
*
|
||||
* @return The starting column number of the program text originating this
|
||||
* error
|
||||
*/
|
||||
public int getStartColumn()
|
||||
{
|
||||
return startcolumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ending line number of the program text originating this error
|
||||
*
|
||||
* @return The ending line number of the program text originating this error
|
||||
*/
|
||||
public int getEndLine()
|
||||
{
|
||||
return endline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ending column number of the program text originating this
|
||||
* error
|
||||
*
|
||||
* @return The ending column number of the program text originating this
|
||||
* error
|
||||
*/
|
||||
public int getEndColumn()
|
||||
{
|
||||
return endcolumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the message produced by the language processor
|
||||
*
|
||||
* @return The message produced by the language processor
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
if ( file != null )
|
||||
{
|
||||
return file + ":" + "[" + startline + "," + startcolumn + "] " + message;
|
||||
}
|
||||
else
|
||||
{
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,254 +0,0 @@
|
||||
package org.apache.maven.bootstrap.compile;
|
||||
|
||||
/*
|
||||
* 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.util.IsolatedClassLoader;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class JavacCompiler
|
||||
extends AbstractCompiler
|
||||
{
|
||||
static final int OUTPUT_BUFFER_SIZE = 1024;
|
||||
|
||||
public JavacCompiler()
|
||||
{
|
||||
}
|
||||
|
||||
public List compile( CompilerConfiguration config )
|
||||
throws Exception
|
||||
{
|
||||
File destinationDir = new File( config.getOutputLocation() );
|
||||
|
||||
if ( !destinationDir.exists() )
|
||||
{
|
||||
destinationDir.mkdirs();
|
||||
}
|
||||
|
||||
String[] sources = getSourceFiles( config );
|
||||
|
||||
if ( sources.length == 0 )
|
||||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
System.out.println( "Compiling " + sources.length + " source file" + ( sources.length == 1 ? "" : "s" ) +
|
||||
" to " + destinationDir.getAbsolutePath() );
|
||||
|
||||
Map compilerOptions = config.getCompilerOptions();
|
||||
|
||||
List args = new ArrayList( sources.length + 5 + compilerOptions.size() * 2 );
|
||||
|
||||
args.add( "-d" );
|
||||
|
||||
args.add( destinationDir.getAbsolutePath() );
|
||||
|
||||
if ( config.isNoWarn() )
|
||||
{
|
||||
args.add( "-nowarn" );
|
||||
}
|
||||
|
||||
List classpathEntries = config.getClasspathEntries();
|
||||
if ( classpathEntries != null && !classpathEntries.isEmpty() )
|
||||
{
|
||||
args.add( "-classpath" );
|
||||
|
||||
args.add( getPathString( classpathEntries ) );
|
||||
}
|
||||
|
||||
if ( config.isDebug() )
|
||||
{
|
||||
args.add( "-g" );
|
||||
}
|
||||
|
||||
List sourceLocations = config.getSourceLocations();
|
||||
if ( sourceLocations != null && !sourceLocations.isEmpty() )
|
||||
{
|
||||
args.add( "-sourcepath" );
|
||||
|
||||
args.add( getPathString( sourceLocations ) );
|
||||
}
|
||||
|
||||
// TODO: this could be much improved
|
||||
if ( !compilerOptions.containsKey( "-target" ) )
|
||||
{
|
||||
if ( !compilerOptions.containsKey( "-source" ) )
|
||||
{
|
||||
// If omitted, later JDKs complain about a 1.1 target
|
||||
args.add( "-source" );
|
||||
args.add( "1.3" );
|
||||
}
|
||||
|
||||
// Required, or it defaults to the target of your JDK (eg 1.5)
|
||||
args.add( "-target" );
|
||||
args.add( "1.1" );
|
||||
}
|
||||
|
||||
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.add( sources[i] );
|
||||
}
|
||||
|
||||
IsolatedClassLoader cl = new IsolatedClassLoader();
|
||||
|
||||
File toolsJar = new File( System.getProperty( "java.home" ), "../lib/tools.jar" );
|
||||
|
||||
if ( toolsJar.exists() )
|
||||
{
|
||||
cl.addURL( toolsJar.toURL() );
|
||||
}
|
||||
|
||||
Class c = cl.loadClass( "com.sun.tools.javac.Main" );
|
||||
|
||||
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||
|
||||
Method compile = c.getMethod( "compile", new Class[]{String[].class} );
|
||||
|
||||
Integer ok = (Integer) compile.invoke( null, new Object[]{args.toArray( new String[0] )} );
|
||||
|
||||
List messages = parseModernStream(
|
||||
new BufferedReader( new InputStreamReader( new ByteArrayInputStream( err.toByteArray() ) ) ) );
|
||||
|
||||
if ( ok.intValue() != 0 && messages.isEmpty() )
|
||||
{
|
||||
// TODO: exception?
|
||||
messages.add( new CompilerError(
|
||||
"Failure executing javac, but could not parse the error:\n\n" + err.toString(), true ) );
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
protected List parseModernStream( BufferedReader input )
|
||||
throws IOException
|
||||
{
|
||||
List errors = new ArrayList();
|
||||
|
||||
String line;
|
||||
|
||||
StringBuffer buffer;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
// cleanup the buffer
|
||||
buffer = new StringBuffer(); // this is quicker than clearing it
|
||||
|
||||
// most errors terminate with the '^' char
|
||||
do
|
||||
{
|
||||
if ( ( line = input.readLine() ) == null )
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
|
||||
// TODO: there should be a better way to parse these
|
||||
if ( buffer.length() == 0 && line.startsWith( "error: " ) )
|
||||
{
|
||||
errors.add( new CompilerError( line, true ) );
|
||||
}
|
||||
else if ( buffer.length() == 0 && line.startsWith( "Note: " ) )
|
||||
{
|
||||
// skip this one - it is JDK 1.5 telling us that the interface is deprecated.
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.append( line );
|
||||
|
||||
buffer.append( '\n' );
|
||||
}
|
||||
}
|
||||
while ( !line.endsWith( "^" ) );
|
||||
|
||||
// add the error bean
|
||||
errors.add( parseModernError( buffer.toString() ) );
|
||||
}
|
||||
}
|
||||
|
||||
private CompilerError parseModernError( String error )
|
||||
{
|
||||
StringTokenizer tokens = new StringTokenizer( error, ":" );
|
||||
|
||||
try
|
||||
{
|
||||
String file = tokens.nextToken();
|
||||
|
||||
if ( file.length() == 1 )
|
||||
{
|
||||
file = new StringBuffer( file ).append( ":" ).append( tokens.nextToken() ).toString();
|
||||
}
|
||||
|
||||
int line = Integer.parseInt( tokens.nextToken() );
|
||||
|
||||
String message = tokens.nextToken( "\n" ).substring( 1 );
|
||||
|
||||
String context = tokens.nextToken( "\n" );
|
||||
|
||||
String pointer = tokens.nextToken( "\n" );
|
||||
|
||||
int startcolumn = pointer.indexOf( "^" );
|
||||
|
||||
int endcolumn = context.indexOf( " ", startcolumn );
|
||||
|
||||
if ( endcolumn == -1 )
|
||||
{
|
||||
endcolumn = context.length();
|
||||
}
|
||||
|
||||
return new CompilerError( file, true, line, startcolumn, line, endcolumn, message );
|
||||
}
|
||||
catch ( NoSuchElementException nse )
|
||||
{
|
||||
// TODO: exception?
|
||||
return new CompilerError( "no more tokens - could not parse error message: " + error, true );
|
||||
}
|
||||
catch ( Exception nse )
|
||||
{
|
||||
// TODO: exception?
|
||||
return new CompilerError( "could not parse error message: " + error, true );
|
||||
}
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Sun Javac Compiler";
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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.Repository;
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*/
|
||||
public abstract class AbstractArtifactResolver
|
||||
implements ArtifactResolver
|
||||
{
|
||||
private Repository localRepository;
|
||||
|
||||
private Map builtArtifacts = new HashMap();
|
||||
|
||||
protected AbstractArtifactResolver( Repository localRepository )
|
||||
{
|
||||
if ( localRepository == null )
|
||||
{
|
||||
System.err.println( "local repository not specified" );
|
||||
|
||||
System.exit( 1 );
|
||||
}
|
||||
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
|
||||
public Repository getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public void addBuiltArtifact( String groupId, String artifactId, String type, File jarFile )
|
||||
{
|
||||
builtArtifacts.put( groupId + ":" + artifactId + ":" + type, jarFile );
|
||||
}
|
||||
|
||||
public boolean isAlreadyBuilt( Dependency dep )
|
||||
{
|
||||
return builtArtifacts.containsKey( dep.getConflictId() );
|
||||
}
|
||||
|
||||
public boolean isAlreadyBuilt( String conflictId )
|
||||
{
|
||||
return builtArtifacts.containsKey( conflictId );
|
||||
}
|
||||
|
||||
public File getArtifactFile( Dependency dependency )
|
||||
{
|
||||
if ( isAlreadyBuilt( dependency ) )
|
||||
{
|
||||
return (File) builtArtifacts.get( dependency.getConflictId() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return localRepository.getArtifactFile( dependency );
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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.Repository;
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Artifact resolver.
|
||||
*/
|
||||
public interface ArtifactResolver
|
||||
{
|
||||
void downloadDependencies( Collection dependencies )
|
||||
throws DownloadFailedException;
|
||||
|
||||
Repository getLocalRepository();
|
||||
|
||||
void addBuiltArtifact( String groupId, String artifactId, String type, File jarFile );
|
||||
|
||||
boolean isAlreadyBuilt( Dependency dep );
|
||||
|
||||
File getArtifactFile( Dependency dependency );
|
||||
|
||||
boolean isOnline();
|
||||
|
||||
boolean isAlreadyBuilt( String key );
|
||||
}
|
@ -1,383 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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 java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* Encode/Decode Base-64.
|
||||
*
|
||||
* @author John Casey
|
||||
*/
|
||||
public final class Base64
|
||||
{
|
||||
|
||||
// private static final Log LOG = LogFactory.getLog( Base64.class );
|
||||
|
||||
private static final String CRLF = System.getProperty( "line.separator" );
|
||||
|
||||
private static final int LINE_END = 64;
|
||||
|
||||
public static String encode( byte[] data )
|
||||
{
|
||||
return Base64.encode( data, true );
|
||||
}
|
||||
|
||||
public static String encode( byte[] data, boolean useLineDelimiter )
|
||||
{
|
||||
if ( data == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if ( data.length == 0 )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
int padding = 3 - ( data.length % 3 );
|
||||
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "padding = " + padding + "characters." );
|
||||
// }
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
for ( int i = 0; i < data.length; i += 3 )
|
||||
{
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "iteration base offset = " + i );
|
||||
// }
|
||||
|
||||
int neutral = ( data[i] < 0 ? data[i] + 256 : data[i] );
|
||||
|
||||
int block = ( neutral & 0xff );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "after first byte, block = " + Integer.toBinaryString( block ) );
|
||||
// }
|
||||
|
||||
boolean inLastSegment = false;
|
||||
|
||||
block <<= 8;
|
||||
if ( i + 1 < data.length )
|
||||
{
|
||||
neutral = ( data[i + 1] < 0 ? data[i + 1] + 256 : data[i + 1] );
|
||||
block |= ( neutral & 0xff );
|
||||
}
|
||||
else
|
||||
{
|
||||
inLastSegment = true;
|
||||
}
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "after second byte, block = " + Integer.toBinaryString( block ) + "; inLastSegment = "
|
||||
// + inLastSegment );
|
||||
// }
|
||||
|
||||
block <<= 8;
|
||||
if ( i + 2 < data.length )
|
||||
{
|
||||
neutral = ( data[i + 2] < 0 ? data[i + 2] + 256 : data[i + 2] );
|
||||
block |= ( neutral & 0xff );
|
||||
}
|
||||
else
|
||||
{
|
||||
inLastSegment = true;
|
||||
}
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "after third byte, block = " + Integer.toBinaryString( block ) + "; inLastSegment = "
|
||||
// + inLastSegment );
|
||||
// }
|
||||
|
||||
char[] encoded = new char[4];
|
||||
int encIdx = 0;
|
||||
encoded[0] = toBase64Char( ( block >>> 18 ) & 0x3f );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "first character = " + encoded[0] );
|
||||
// }
|
||||
|
||||
encoded[1] = toBase64Char( ( block >>> 12 ) & 0x3f );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "second character = " + encoded[1] );
|
||||
// }
|
||||
|
||||
if ( inLastSegment && padding > 1 )
|
||||
{
|
||||
encoded[2] = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
encoded[2] = toBase64Char( ( block >>> 6 ) & 0x3f );
|
||||
}
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "third character = " + encoded[2] );
|
||||
// }
|
||||
|
||||
if ( inLastSegment && padding > 0 )
|
||||
{
|
||||
encoded[3] = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
encoded[3] = toBase64Char( block & 0x3f );
|
||||
}
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "fourth character = " + encoded[3] );
|
||||
// }
|
||||
|
||||
buffer.append( encoded );
|
||||
}
|
||||
|
||||
if ( useLineDelimiter )
|
||||
{
|
||||
return canonicalize( buffer.toString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decode( String src )
|
||||
{
|
||||
return Base64.decode( src, true );
|
||||
}
|
||||
|
||||
public static byte[] decode( String src, boolean useLineDelimiter )
|
||||
{
|
||||
if ( src == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if ( src.length() < 1 )
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "pre-canonicalization = \n" + src );
|
||||
// }
|
||||
String data = src;
|
||||
|
||||
if ( useLineDelimiter )
|
||||
{
|
||||
data = deCanonicalize( src );
|
||||
}
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "post-canonicalization = \n" + data );
|
||||
// }
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
char[] input = data.toCharArray();
|
||||
|
||||
int index = 0;
|
||||
for ( int i = 0; i < input.length; i += 4 )
|
||||
{
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "iteration base offset = " + i );
|
||||
// }
|
||||
|
||||
int block = ( toBase64Int( input[i] ) & 0x3f );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "block after first char [" + input[i] + "] = " + Integer.toBinaryString( block ) );
|
||||
// }
|
||||
|
||||
block <<= 6;
|
||||
block |= ( toBase64Int( input[i + 1] ) & 0x3f );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "block after second char [" + input[i + 1] + "] = " + Integer.toBinaryString( block ) );
|
||||
// }
|
||||
|
||||
boolean inPadding = false;
|
||||
boolean twoCharPadding = false;
|
||||
block <<= 6;
|
||||
if ( input[i + 2] != '=' )
|
||||
{
|
||||
block |= ( toBase64Int( input[i + 2] ) & 0x3f );
|
||||
}
|
||||
else
|
||||
{
|
||||
twoCharPadding = true;
|
||||
inPadding = true;
|
||||
}
|
||||
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "block after third char [" + input[i + 2] + "] = " + Integer.toBinaryString( block ) );
|
||||
// }
|
||||
|
||||
block <<= 6;
|
||||
if ( input[i + 3] != '=' )
|
||||
{
|
||||
block |= ( toBase64Int( input[i + 3] ) & 0x3f );
|
||||
}
|
||||
else
|
||||
{
|
||||
inPadding = true;
|
||||
}
|
||||
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "block after fourth char [" + input[i + 3] + "] = " + Integer.toBinaryString( block ) );
|
||||
// }
|
||||
|
||||
baos.write( ( block >>> 16 ) & 0xff );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "byte[" + ( index++ ) + "] = " + ( ( block >>> 16 ) & 0xff ) );
|
||||
// }
|
||||
|
||||
if ( !inPadding || !twoCharPadding )
|
||||
{
|
||||
baos.write( ( block >>> 8 ) & 0xff );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "byte[" + ( index++ ) + "] = " + ( ( block >>> 8 ) & 0xff ) );
|
||||
// }
|
||||
}
|
||||
|
||||
if ( !inPadding )
|
||||
{
|
||||
baos.write( block & 0xff );
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "byte[" + ( index++ ) + "] = " + ( block & 0xff ) );
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
byte[] result = baos.toByteArray();
|
||||
// if ( LOG.isDebugEnabled() )
|
||||
// {
|
||||
// LOG.debug( "byte array is " + result.length + " bytes long." );
|
||||
// }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static char toBase64Char( int input )
|
||||
{
|
||||
if ( input > -1 && input < 26 )
|
||||
{
|
||||
return (char) ( 'A' + input );
|
||||
}
|
||||
else if ( input > 25 && input < 52 )
|
||||
{
|
||||
return (char) ( 'a' + input - 26 );
|
||||
}
|
||||
else if ( input > 51 && input < 62 )
|
||||
{
|
||||
return (char) ( '0' + input - 52 );
|
||||
}
|
||||
else if ( input == 62 )
|
||||
{
|
||||
return '+';
|
||||
}
|
||||
else if ( input == 63 )
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
|
||||
private static int toBase64Int( char input )
|
||||
{
|
||||
if ( input >= 'A' && input <= 'Z' )
|
||||
{
|
||||
return input - 'A';
|
||||
}
|
||||
else if ( input >= 'a' && input <= 'z' )
|
||||
{
|
||||
return input + 26 - 'a';
|
||||
}
|
||||
else if ( input >= '0' && input <= '9' )
|
||||
{
|
||||
return input + 52 - '0';
|
||||
}
|
||||
else if ( input == '+' )
|
||||
{
|
||||
return 62;
|
||||
}
|
||||
else if ( input == '/' )
|
||||
{
|
||||
return 63;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static String deCanonicalize( String data )
|
||||
{
|
||||
if ( data == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer( data.length() );
|
||||
for ( int i = 0; i < data.length(); i++ )
|
||||
{
|
||||
char c = data.charAt( i );
|
||||
if ( c != '\r' && c != '\n' )
|
||||
{
|
||||
buffer.append( c );
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static String canonicalize( String data )
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer( (int) ( data.length() * 1.1 ) );
|
||||
|
||||
int col = 0;
|
||||
for ( int i = 0; i < data.length(); i++ )
|
||||
{
|
||||
if ( col == LINE_END )
|
||||
{
|
||||
buffer.append( CRLF );
|
||||
col = 0;
|
||||
}
|
||||
|
||||
buffer.append( data.charAt( i ) );
|
||||
col++;
|
||||
}
|
||||
|
||||
buffer.append( CRLF );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.bootstrap.model.Dependency;
|
||||
import org.apache.maven.bootstrap.model.Model;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Failed download.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DownloadFailedException
|
||||
extends Exception
|
||||
{
|
||||
public DownloadFailedException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public DownloadFailedException( Dependency dep )
|
||||
{
|
||||
super( createMessage( dep ) );
|
||||
}
|
||||
|
||||
private static String createMessage( Dependency dep )
|
||||
{
|
||||
String msg = "Failed to download dependency: \n\n" + dep + "\n\nChain:\n";
|
||||
|
||||
List repos = new ArrayList();
|
||||
|
||||
for ( Iterator it = dep.getChain().iterator(); it.hasNext(); )
|
||||
{
|
||||
Model chainDep = (Model) it.next();
|
||||
msg += "\n\t" + chainDep;
|
||||
repos.addAll( chainDep.getRepositories() );
|
||||
}
|
||||
|
||||
msg += "\n\nfrom the following repositories:\n\n";
|
||||
|
||||
for ( Iterator it = repos.iterator(); it.hasNext(); )
|
||||
{
|
||||
msg += "\n\t" + it.next();
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
@ -1,359 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Authenticator;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* Http utils for retrieving files.
|
||||
*
|
||||
* @author costin@dnt.ro
|
||||
* @author gg@grtmail.com (Added Java 1.1 style HTTP basic auth)
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*/
|
||||
public class HttpUtils
|
||||
{
|
||||
/**
|
||||
* Use a proxy to bypass the firewall with or without authentication
|
||||
*
|
||||
* @param proxyHost Proxy Host (if proxy is required), or null
|
||||
* @param proxyPort Proxy Port (if proxy is required), or null
|
||||
* @param proxyUserName Proxy Username (if authentification is required),
|
||||
* or null
|
||||
* @param proxyPassword Proxy Password (if authentification is required),
|
||||
* or null
|
||||
* @throws SecurityException if an operation is not authorized by the
|
||||
* SecurityManager
|
||||
*/
|
||||
public static void useProxyUser( final String proxyHost, final String proxyPort, final String proxyUserName,
|
||||
final String proxyPassword )
|
||||
{
|
||||
if ( proxyHost != null && proxyPort != null )
|
||||
{
|
||||
System.getProperties().put( "proxySet", "true" );
|
||||
System.getProperties().put( "proxyHost", proxyHost );
|
||||
System.getProperties().put( "proxyPort", proxyPort );
|
||||
|
||||
if ( proxyUserName != null )
|
||||
{
|
||||
Authenticator.setDefault( new Authenticator()
|
||||
{
|
||||
protected PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new PasswordAuthentication( proxyUserName, proxyPassword == null ? new char[0]
|
||||
: proxyPassword.toCharArray() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a remote file. Throws an Exception on errors unless the
|
||||
* ifnoreErrors flag is set to True
|
||||
*
|
||||
* @param url the of the file to retrieve
|
||||
* @param destinationFile where to store it
|
||||
* @param ignoreErrors whether to ignore errors during I/O or throw an
|
||||
* exception when they happen
|
||||
* @param useTimestamp whether to check the modified timestamp on the
|
||||
* <code>destinationFile</code> against the remote <code>source</code>
|
||||
* @param proxyHost Proxy Host (if proxy is required), or null
|
||||
* @param proxyPort Proxy Port (if proxy is required), or null
|
||||
* @param proxyUserName Proxy Username (if authentification is required),
|
||||
* or null.
|
||||
* @param proxyPassword Proxy Password (if authentification is required),
|
||||
* or null.
|
||||
* @param useChecksum Flag to indicate the use of the checksum for the retrieved
|
||||
* artifact if it is available.
|
||||
* @throws IOException If an I/O exception occurs.
|
||||
*/
|
||||
public static void getFile( String url, File destinationFile, boolean ignoreErrors, boolean useTimestamp,
|
||||
String proxyHost, String proxyPort, String proxyUserName, String proxyPassword,
|
||||
boolean useChecksum )
|
||||
throws IOException
|
||||
{
|
||||
// Get the requested file.
|
||||
getFile( url, destinationFile, ignoreErrors, useTimestamp, proxyHost, proxyPort, proxyUserName, proxyPassword );
|
||||
|
||||
// Get the checksum if requested.
|
||||
if ( useChecksum )
|
||||
{
|
||||
File checksumFile = new File( destinationFile + ".md5" );
|
||||
|
||||
try
|
||||
{
|
||||
getFile( url + ".md5", checksumFile, ignoreErrors, useTimestamp, proxyHost, proxyPort, proxyUserName,
|
||||
proxyPassword );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// do nothing we will check later in the process
|
||||
// for the checksums.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a remote file. Throws an Exception on errors unless the
|
||||
* ifnoreErrors flag is set to True
|
||||
*
|
||||
* @param url the of the file to retrieve
|
||||
* @param destinationFile where to store it
|
||||
* @param ignoreErrors whether to ignore errors during I/O or throw an
|
||||
* exception when they happen
|
||||
* @param useTimestamp whether to check the modified timestamp on the
|
||||
* <code>destinationFile</code> against the remote <code>source</code>
|
||||
* @param proxyHost Proxy Host (if proxy is required), or null
|
||||
* @param proxyPort Proxy Port (if proxy is required), or null
|
||||
* @param proxyUserName Proxy Username (if authentification is required),
|
||||
* or null
|
||||
* @param proxyPassword Proxy Password (if authentification is required),
|
||||
* or null
|
||||
* @throws IOException If an I/O exception occurs.
|
||||
*/
|
||||
public static void getFile( String url, File destinationFile, boolean ignoreErrors, boolean useTimestamp,
|
||||
String proxyHost, String proxyPort, String proxyUserName, String proxyPassword )
|
||||
throws IOException
|
||||
{
|
||||
//set the timestamp to the file date.
|
||||
long timestamp = -1;
|
||||
if ( useTimestamp && destinationFile.exists() )
|
||||
{
|
||||
timestamp = destinationFile.lastModified();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
getFile( url, destinationFile, timestamp, proxyHost, proxyPort, proxyUserName, proxyPassword );
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
if ( !ignoreErrors )
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a remote file.
|
||||
*
|
||||
* @param url the URL of the file to retrieve
|
||||
* @param destinationFile where to store it
|
||||
* @param timestamp if provided, the remote URL is only retrieved if it was
|
||||
* modified more recently than timestamp. Otherwise, negative value indicates that
|
||||
* the remote URL should be retrieved unconditionally.
|
||||
* @param proxyHost Proxy Host (if proxy is required), or null
|
||||
* @param proxyPort Proxy Port (if proxy is required), or null
|
||||
* @param proxyUserName Proxy Username (if authentification is required),
|
||||
* or null
|
||||
* @param proxyPassword Proxy Password (if authentification is required),
|
||||
* or null
|
||||
* @throws IOException If an I/O exception occurs.
|
||||
*/
|
||||
public static void getFile( String url, File destinationFile, long timestamp, String proxyHost, String proxyPort,
|
||||
String proxyUserName, String proxyPassword )
|
||||
throws IOException
|
||||
{
|
||||
String[] s = parseUrl( url );
|
||||
String username = s[0];
|
||||
String password = s[1];
|
||||
String parsedUrl = s[2];
|
||||
|
||||
URL source = new URL( parsedUrl );
|
||||
|
||||
//set proxy connection
|
||||
useProxyUser( proxyHost, proxyPort, proxyUserName, proxyPassword );
|
||||
|
||||
//set up the URL connection
|
||||
URLConnection connection = source.openConnection();
|
||||
|
||||
//modify the headers
|
||||
if ( timestamp >= 0 )
|
||||
{
|
||||
connection.setIfModifiedSince( timestamp );
|
||||
}
|
||||
// prepare Java 1.1 style credentials
|
||||
if ( username != null || password != null )
|
||||
{
|
||||
String up = username + ":" + password;
|
||||
String encoding = Base64.encode( up.getBytes(), false );
|
||||
connection.setRequestProperty( "Authorization", "Basic " + encoding );
|
||||
}
|
||||
|
||||
connection.setRequestProperty( "Pragma", "no-cache" );
|
||||
|
||||
//connect to the remote site (may take some time)
|
||||
connection.connect();
|
||||
//next test for a 304 result (HTTP only)
|
||||
if ( connection instanceof HttpURLConnection )
|
||||
{
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||
// although HTTPUrlConnection javadocs says FileNotFoundException should be
|
||||
// thrown on a 404 error, that certainly does not appear to be the case, so
|
||||
// test for 404 ourselves, and throw FileNotFoundException as needed
|
||||
if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND )
|
||||
{
|
||||
throw new FileNotFoundException( url + " (HTTP Error: " + httpConnection.getResponseCode() +
|
||||
" " + httpConnection.getResponseMessage() + ")" );
|
||||
}
|
||||
if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// test for 401 result (HTTP only)
|
||||
if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED )
|
||||
{
|
||||
throw new IOException( "Not authorized." );
|
||||
}
|
||||
// test for 407 result (HTTP only)
|
||||
if ( httpConnection.getResponseCode() == HttpURLConnection.HTTP_PROXY_AUTH )
|
||||
{
|
||||
throw new IOException( "Not authorized by proxy." );
|
||||
}
|
||||
}
|
||||
|
||||
// REVISIT: at this point even non HTTP connections may support the
|
||||
// if-modified-since behaviour - we just check the date of the
|
||||
// content and skip the write if it is not newer.
|
||||
// Some protocols (FTP) dont include dates, of course.
|
||||
|
||||
InputStream is = null;
|
||||
IOException isException = null;
|
||||
for ( int i = 0; i < 3; i++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
is = connection.getInputStream();
|
||||
break;
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
isException = ex;
|
||||
}
|
||||
}
|
||||
if ( is == null )
|
||||
{
|
||||
throw isException;
|
||||
}
|
||||
|
||||
if ( connection.getLastModified() <= timestamp && connection.getLastModified() != 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FileOutputStream fos = new FileOutputStream( destinationFile );
|
||||
|
||||
byte[] buffer = new byte[100 * 1024];
|
||||
int length;
|
||||
|
||||
while ( ( length = is.read( buffer ) ) >= 0 )
|
||||
{
|
||||
fos.write( buffer, 0, length );
|
||||
System.out.print( "." );
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
fos.close();
|
||||
is.close();
|
||||
|
||||
// if (and only if) the use file time option is set, then the
|
||||
// saved file now has its timestamp set to that of the downloaded
|
||||
// file
|
||||
if ( timestamp >= 0 )
|
||||
{
|
||||
long remoteTimestamp = connection.getLastModified();
|
||||
if ( remoteTimestamp != 0 )
|
||||
{
|
||||
touchFile( destinationFile, remoteTimestamp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an url which might contain a username and password. If the
|
||||
* given url doesn't contain a username and password then return the
|
||||
* origin url unchanged.
|
||||
*
|
||||
* @param url The url to parse.
|
||||
* @return The username, password and url.
|
||||
* @throws RuntimeException if the url is (very) invalid
|
||||
*/
|
||||
static String[] parseUrl( String url )
|
||||
{
|
||||
String[] parsedUrl = new String[3];
|
||||
parsedUrl[0] = null;
|
||||
parsedUrl[1] = null;
|
||||
parsedUrl[2] = url;
|
||||
|
||||
// We want to be able to deal with Basic Auth where the username
|
||||
// and password are part of the URL. An example of the URL string
|
||||
// we would like to be able to parse is like the following:
|
||||
//
|
||||
// http://username:password@repository.mycompany.com
|
||||
|
||||
int i = url.indexOf( "@" );
|
||||
if ( i > 0 )
|
||||
{
|
||||
String protocol = url.substring( 0, url.indexOf( "://" ) ) + "://";
|
||||
String s = url.substring( protocol.length(), i );
|
||||
int j = s.indexOf( ":" );
|
||||
parsedUrl[0] = s.substring( 0, j );
|
||||
parsedUrl[1] = s.substring( j + 1 );
|
||||
parsedUrl[2] = protocol + url.substring( i + 1 );
|
||||
}
|
||||
|
||||
return parsedUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the timestamp of a named file to a specified time.
|
||||
*
|
||||
* @param file the file to touch
|
||||
* @param timemillis in milliseconds since the start of the era
|
||||
* @return true if it succeeded. False means that this is a java1.1 system
|
||||
* and that file times can not be set
|
||||
* @throws RuntimeException Thrown in unrecoverable error. Likely this
|
||||
* comes from file access failures.
|
||||
*/
|
||||
private static boolean touchFile( File file, long timemillis )
|
||||
{
|
||||
long modifiedTime;
|
||||
|
||||
if ( timemillis < 0 )
|
||||
{
|
||||
modifiedTime = System.currentTimeMillis();
|
||||
}
|
||||
else
|
||||
{
|
||||
modifiedTime = timemillis;
|
||||
}
|
||||
|
||||
file.setLastModified( modifiedTime );
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Resolve from the local repository - don't attempt to download or check out.
|
||||
*/
|
||||
public class OfflineArtifactResolver
|
||||
extends AbstractArtifactResolver
|
||||
{
|
||||
public OfflineArtifactResolver( Repository localRepository )
|
||||
{
|
||||
super( localRepository );
|
||||
}
|
||||
|
||||
public void downloadDependencies( Collection dependencies )
|
||||
throws DownloadFailedException
|
||||
{
|
||||
// Nothing to see here
|
||||
}
|
||||
|
||||
public boolean isOnline()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,342 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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.Model;
|
||||
import org.apache.maven.bootstrap.model.Repository;
|
||||
import org.apache.maven.bootstrap.util.FileUtils;
|
||||
import org.apache.maven.bootstrap.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OnlineArtifactDownloader
|
||||
extends AbstractArtifactResolver
|
||||
{
|
||||
public static final String SNAPSHOT_SIGNATURE = "-SNAPSHOT";
|
||||
|
||||
private boolean useTimestamp = true;
|
||||
|
||||
private boolean ignoreErrors = false;
|
||||
|
||||
private String proxyHost;
|
||||
|
||||
private String proxyPort;
|
||||
|
||||
private String proxyUserName;
|
||||
|
||||
private String proxyPassword;
|
||||
|
||||
private static final String REPO_URL = "http://repo1.maven.org/maven2";
|
||||
|
||||
private Map downloadedArtifacts = new HashMap();
|
||||
|
||||
private List remoteRepositories;
|
||||
|
||||
public OnlineArtifactDownloader( Repository localRepository )
|
||||
throws Exception
|
||||
{
|
||||
super( localRepository );
|
||||
}
|
||||
|
||||
public void setProxy( String host, String port, String userName, String password )
|
||||
{
|
||||
proxyHost = host;
|
||||
proxyPort = port;
|
||||
proxyUserName = userName;
|
||||
proxyPassword = password;
|
||||
System.out.println( "Using the following proxy : " + proxyHost + "/" + proxyPort );
|
||||
}
|
||||
|
||||
public void downloadDependencies( Collection dependencies )
|
||||
throws DownloadFailedException
|
||||
{
|
||||
for ( Iterator j = dependencies.iterator(); j.hasNext(); )
|
||||
{
|
||||
Dependency dep = (Dependency) j.next();
|
||||
|
||||
if ( isAlreadyBuilt( dep ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String dependencyConflictId = dep.getDependencyConflictId();
|
||||
if ( !downloadedArtifacts.containsKey( dependencyConflictId ) )
|
||||
{
|
||||
File destinationFile = getLocalRepository().getArtifactFile( dep );
|
||||
// The directory structure for this project may
|
||||
// not exists so create it if missing.
|
||||
File directory = destinationFile.getParentFile();
|
||||
|
||||
if ( !directory.exists() )
|
||||
{
|
||||
directory.mkdirs();
|
||||
}
|
||||
|
||||
if ( !getRemoteArtifact( dep, destinationFile ) && !destinationFile.exists() )
|
||||
{
|
||||
throw new DownloadFailedException( dep );
|
||||
}
|
||||
|
||||
downloadedArtifacts.put( dependencyConflictId, dep );
|
||||
}
|
||||
else
|
||||
{
|
||||
Dependency d = (Dependency) downloadedArtifacts.get( dependencyConflictId );
|
||||
dep.setResolvedVersion( d.getResolvedVersion() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOnline()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isSnapshot( Dependency dep )
|
||||
{
|
||||
return dep.getVersion().indexOf( SNAPSHOT_SIGNATURE ) >= 0;
|
||||
}
|
||||
|
||||
private boolean getRemoteArtifact( Dependency dep, File destinationFile )
|
||||
{
|
||||
boolean fileFound = false;
|
||||
|
||||
List repositories = new ArrayList();
|
||||
repositories.addAll( getRemoteRepositories() );
|
||||
repositories.addAll( dep.getRepositories() );
|
||||
|
||||
for ( Iterator i = dep.getChain().iterator(); i.hasNext(); )
|
||||
{
|
||||
repositories.addAll( ( (Model) i.next() ).getRepositories() );
|
||||
}
|
||||
|
||||
for ( Iterator i = repositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
Repository remoteRepo = (Repository) i.next();
|
||||
|
||||
boolean snapshot = isSnapshot( dep );
|
||||
if ( snapshot && !remoteRepo.isSnapshots() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( !snapshot && !remoteRepo.isReleases() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// The username and password parameters are not being used here.
|
||||
String url = remoteRepo.getBasedir() + "/" + remoteRepo.getArtifactPath( dep );
|
||||
|
||||
// Attempt to retrieve the artifact and set the checksum if retrieval
|
||||
// of the checksum file was successful.
|
||||
try
|
||||
{
|
||||
String version = dep.getVersion();
|
||||
if ( snapshot )
|
||||
{
|
||||
String filename = "maven-metadata-" + remoteRepo.getId() + ".xml";
|
||||
File localFile = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
|
||||
dep.getVersion(), dep.getType(),
|
||||
"maven-metadata-local.xml" );
|
||||
File remoteFile = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
|
||||
dep.getVersion(), dep.getType(), filename );
|
||||
String metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
|
||||
dep.getVersion(), dep.getType(),
|
||||
"maven-metadata.xml" );
|
||||
String metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
|
||||
log( "Downloading " + metaUrl );
|
||||
try
|
||||
{
|
||||
HttpUtils.getFile( metaUrl, remoteFile, ignoreErrors, true, proxyHost, proxyPort, proxyUserName,
|
||||
proxyPassword, false );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
log( "WARNING: remote metadata version not found, using local: " + e.getMessage() );
|
||||
remoteFile.delete();
|
||||
}
|
||||
|
||||
File file = localFile;
|
||||
if ( remoteFile.exists() )
|
||||
{
|
||||
if ( !localFile.exists() )
|
||||
{
|
||||
file = remoteFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
RepositoryMetadata localMetadata = RepositoryMetadata.read( localFile );
|
||||
|
||||
RepositoryMetadata remoteMetadata = RepositoryMetadata.read( remoteFile );
|
||||
|
||||
if ( remoteMetadata.getLastUpdatedUtc() > localMetadata.getLastUpdatedUtc() )
|
||||
{
|
||||
file = remoteFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
file = localFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( file.exists() )
|
||||
{
|
||||
log( "Using metadata: " + file );
|
||||
|
||||
RepositoryMetadata metadata = RepositoryMetadata.read( file );
|
||||
|
||||
if ( !file.equals( localFile ) )
|
||||
{
|
||||
version = metadata.constructVersion( version );
|
||||
}
|
||||
log( "Resolved version: " + version );
|
||||
dep.setResolvedVersion( version );
|
||||
if ( !version.endsWith( "SNAPSHOT" ) )
|
||||
{
|
||||
String ver =
|
||||
version.substring( version.lastIndexOf( "-", version.lastIndexOf( "-" ) - 1 ) + 1 );
|
||||
String extension = url.substring( url.length() - 4 );
|
||||
url = getSnapshotMetadataFile( url, ver + extension );
|
||||
}
|
||||
else if ( destinationFile.exists() )
|
||||
{
|
||||
// It's already there
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !"pom".equals( dep.getType() ) )
|
||||
{
|
||||
String name = dep.getArtifactId() + "-" + dep.getResolvedVersion() + ".pom";
|
||||
File file = getLocalRepository().getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
|
||||
dep.getVersion(), dep.getType(), name );
|
||||
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
if ( !file.exists() || version.indexOf( "SNAPSHOT" ) >= 0 )
|
||||
{
|
||||
String filename = dep.getArtifactId() + "-" + version + ".pom";
|
||||
String metadataPath = remoteRepo.getMetadataPath( dep.getGroupId(), dep.getArtifactId(),
|
||||
dep.getVersion(), dep.getType(), filename );
|
||||
String metaUrl = remoteRepo.getBasedir() + "/" + metadataPath;
|
||||
log( "Downloading " + metaUrl );
|
||||
|
||||
try
|
||||
{
|
||||
HttpUtils.getFile( metaUrl, file, ignoreErrors, false, proxyHost, proxyPort, proxyUserName,
|
||||
proxyPassword, false );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
log( "Couldn't find POM - ignoring: " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destinationFile = getLocalRepository().getArtifactFile( dep );
|
||||
if ( !destinationFile.exists() )
|
||||
{
|
||||
log( "Downloading " + url );
|
||||
HttpUtils.getFile( url, destinationFile, ignoreErrors, useTimestamp, proxyHost, proxyPort,
|
||||
proxyUserName, proxyPassword, true );
|
||||
if ( dep.getVersion().indexOf( "SNAPSHOT" ) >= 0 )
|
||||
{
|
||||
String name = StringUtils.replace( destinationFile.getName(), version, dep.getVersion() );
|
||||
FileUtils.copyFile( destinationFile, new File( destinationFile.getParentFile(), name ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Artifact was found, continue checking additional remote repos (if any)
|
||||
// in case there is a newer version (i.e. snapshots) in another repo
|
||||
fileFound = true;
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
log( "Artifact not found at [" + url + "]" );
|
||||
// Ignore
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
// If there are additional remote repos, then ignore exception
|
||||
// as artifact may be found in another remote repo. If there
|
||||
// are no more remote repos to check and the artifact wasn't found in
|
||||
// a previous remote repo, then artifactFound is false indicating
|
||||
// that the artifact could not be found in any of the remote repos
|
||||
//
|
||||
// arguably, we need to give the user better control (another command-
|
||||
// line switch perhaps) of what to do in this case? Maven already has
|
||||
// a command-line switch to work in offline mode, but what about when
|
||||
// one of two or more remote repos is unavailable? There may be multiple
|
||||
// remote repos for redundancy, in which case you probably want the build
|
||||
// to continue. There may however be multiple remote repos because some
|
||||
// artifacts are on one, and some are on another. In this case, you may
|
||||
// want the build to break.
|
||||
//
|
||||
// print a warning, in any case, so user catches on to mistyped
|
||||
// hostnames, or other snafus
|
||||
log( "Error retrieving artifact from [" + url + "]: " + e );
|
||||
}
|
||||
}
|
||||
|
||||
return fileFound;
|
||||
}
|
||||
|
||||
private static String getSnapshotMetadataFile( String filename, String s )
|
||||
{
|
||||
int index = filename.lastIndexOf( "SNAPSHOT" );
|
||||
return filename.substring( 0, index ) + s;
|
||||
}
|
||||
|
||||
private void log( String message )
|
||||
{
|
||||
System.out.println( message );
|
||||
}
|
||||
|
||||
public List getRemoteRepositories()
|
||||
{
|
||||
if ( remoteRepositories == null )
|
||||
{
|
||||
remoteRepositories = new ArrayList();
|
||||
}
|
||||
|
||||
if ( remoteRepositories.isEmpty() )
|
||||
{
|
||||
// TODO: use super POM?
|
||||
remoteRepositories.add( new Repository( "central", REPO_URL, Repository.LAYOUT_DEFAULT, false, true ) );
|
||||
// TODO: use maven root POM?
|
||||
remoteRepositories.add( new Repository( "apache.snapshots", "http://cvs.apache.org/maven-snapshot-repository/",
|
||||
Repository.LAYOUT_DEFAULT, true, false ) );
|
||||
}
|
||||
|
||||
return remoteRepositories;
|
||||
}
|
||||
|
||||
public void setRemoteRepositories( List remoteRepositories )
|
||||
{
|
||||
this.remoteRepositories = remoteRepositories;
|
||||
}
|
||||
}
|
@ -1,395 +0,0 @@
|
||||
package org.apache.maven.bootstrap.download;
|
||||
|
||||
/*
|
||||
* 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.util.AbstractReader;
|
||||
import org.apache.maven.bootstrap.util.StringUtils;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* I/O for repository metadata.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RepositoryMetadata
|
||||
{
|
||||
private String snapshotTimestamp;
|
||||
|
||||
private int snapshotBuildNumber;
|
||||
|
||||
private String releaseVersion;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private List versions = new ArrayList();
|
||||
|
||||
private String latestVersion;
|
||||
|
||||
private boolean localCopy;
|
||||
|
||||
private String lastUpdated;
|
||||
|
||||
public String getSnapshotTimestamp()
|
||||
{
|
||||
return snapshotTimestamp;
|
||||
}
|
||||
|
||||
public void setSnapshotTimestamp( String snapshotTimestamp )
|
||||
{
|
||||
this.snapshotTimestamp = snapshotTimestamp;
|
||||
}
|
||||
|
||||
public int getSnapshotBuildNumber()
|
||||
{
|
||||
return snapshotBuildNumber;
|
||||
}
|
||||
|
||||
public void setSnapshotBuildNumber( int snapshotBuildNumber )
|
||||
{
|
||||
this.snapshotBuildNumber = snapshotBuildNumber;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public List getVersions()
|
||||
{
|
||||
return versions;
|
||||
}
|
||||
|
||||
public void setVersions( List versions )
|
||||
{
|
||||
this.versions = versions;
|
||||
}
|
||||
|
||||
public String getReleaseVersion()
|
||||
{
|
||||
return releaseVersion;
|
||||
}
|
||||
|
||||
public void setReleaseVersion( String releaseVersion )
|
||||
{
|
||||
this.releaseVersion = releaseVersion;
|
||||
}
|
||||
|
||||
public String getLatestVersion()
|
||||
{
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
public void setLatestVersion( String latestVersion )
|
||||
{
|
||||
this.latestVersion = latestVersion;
|
||||
}
|
||||
|
||||
public void addVersion( String version )
|
||||
{
|
||||
versions.add( version );
|
||||
}
|
||||
|
||||
public boolean isLocalCopy()
|
||||
{
|
||||
return localCopy;
|
||||
}
|
||||
|
||||
public void setLocalCopy( boolean localCopy )
|
||||
{
|
||||
this.localCopy = localCopy;
|
||||
}
|
||||
|
||||
public static RepositoryMetadata read( File file )
|
||||
throws IOException, ParserConfigurationException, SAXException
|
||||
{
|
||||
return new Reader().parseMetadata( file );
|
||||
}
|
||||
|
||||
public void write( File file )
|
||||
throws IOException
|
||||
{
|
||||
new Writer( this ).write( file );
|
||||
}
|
||||
|
||||
public String constructVersion( String baseVersion )
|
||||
{
|
||||
if ( snapshotTimestamp != null )
|
||||
{
|
||||
baseVersion = StringUtils.replace( baseVersion, "SNAPSHOT", snapshotTimestamp + "-" + snapshotBuildNumber );
|
||||
}
|
||||
return baseVersion;
|
||||
}
|
||||
|
||||
public long getLastUpdatedUtc()
|
||||
{
|
||||
TimeZone timezone = TimeZone.getTimeZone( "UTC" );
|
||||
DateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss" );
|
||||
fmt.setTimeZone( timezone );
|
||||
|
||||
try
|
||||
{
|
||||
return fmt.parse( lastUpdated ).getTime();
|
||||
}
|
||||
catch ( ParseException e )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLastUpdated( String lastUpdated )
|
||||
{
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public String getLastUpdated()
|
||||
{
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
static class Reader
|
||||
extends AbstractReader
|
||||
{
|
||||
private boolean insideVersioning;
|
||||
|
||||
private StringBuffer bodyText = new StringBuffer();
|
||||
|
||||
private boolean insideSnapshot;
|
||||
|
||||
private final RepositoryMetadata metadata = new RepositoryMetadata();
|
||||
|
||||
private boolean insideVersions;
|
||||
|
||||
public RepositoryMetadata parseMetadata( File metadataFile )
|
||||
throws IOException, ParserConfigurationException, SAXException
|
||||
{
|
||||
parse( metadataFile );
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void startElement( String uri, String localName, String rawName, Attributes attributes )
|
||||
{
|
||||
if ( insideVersioning )
|
||||
{
|
||||
if ( "snapshot".equals( rawName ) )
|
||||
{
|
||||
insideSnapshot = true;
|
||||
}
|
||||
else if ( "versions".equals( rawName ) )
|
||||
{
|
||||
insideVersions = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// root element
|
||||
if ( "versioning".equals( rawName ) )
|
||||
{
|
||||
insideVersioning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void characters( char buffer[], int start, int length )
|
||||
{
|
||||
bodyText.append( buffer, start, length );
|
||||
}
|
||||
|
||||
private String getBodyText()
|
||||
{
|
||||
return bodyText.toString().trim();
|
||||
}
|
||||
|
||||
public void endElement( String uri, String localName, String rawName )
|
||||
throws SAXException
|
||||
{
|
||||
if ( insideVersioning )
|
||||
{
|
||||
if ( "versioning".equals( rawName ) )
|
||||
{
|
||||
insideVersioning = false;
|
||||
}
|
||||
else if ( insideSnapshot )
|
||||
{
|
||||
if ( "snapshot".equals( rawName ) )
|
||||
{
|
||||
insideSnapshot = false;
|
||||
}
|
||||
else if ( "buildNumber".equals( rawName ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
metadata.setSnapshotBuildNumber( Integer.valueOf( getBodyText() ).intValue() );
|
||||
}
|
||||
catch ( NumberFormatException e )
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
else if ( "timestamp".equals( rawName ) )
|
||||
{
|
||||
metadata.setSnapshotTimestamp( getBodyText() );
|
||||
}
|
||||
else if ( "localCopy".equals( rawName ) )
|
||||
{
|
||||
metadata.setLocalCopy( Boolean.valueOf( getBodyText() ).booleanValue() );
|
||||
}
|
||||
}
|
||||
else if ( insideVersions )
|
||||
{
|
||||
if ( "versions".equals( rawName ) )
|
||||
{
|
||||
insideVersions = false;
|
||||
}
|
||||
else if ( "version".equals( rawName ) )
|
||||
{
|
||||
metadata.addVersion( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( "latest".equals( rawName ) )
|
||||
{
|
||||
metadata.setLatestVersion( getBodyText() );
|
||||
}
|
||||
else if ( "release".equals( rawName ) )
|
||||
{
|
||||
metadata.setReleaseVersion( getBodyText() );
|
||||
}
|
||||
else if ( "lastUpdated".equals( rawName ) )
|
||||
{
|
||||
metadata.setLastUpdated( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( "groupId".equals( rawName ) )
|
||||
{
|
||||
metadata.setGroupId( getBodyText() );
|
||||
}
|
||||
else if ( "artifactId".equals( rawName ) )
|
||||
{
|
||||
metadata.setArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( "version".equals( rawName ) )
|
||||
{
|
||||
metadata.setVersion( getBodyText() );
|
||||
}
|
||||
bodyText = new StringBuffer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class Writer
|
||||
{
|
||||
private final RepositoryMetadata metadata;
|
||||
|
||||
public Writer( RepositoryMetadata metadata )
|
||||
{
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public void write( File file )
|
||||
throws IOException
|
||||
{
|
||||
PrintWriter w = new PrintWriter( new FileWriter( file ) );
|
||||
|
||||
try
|
||||
{
|
||||
w.println( "<metadata>" );
|
||||
writeLine( w, " ", "groupId", metadata.getGroupId() );
|
||||
writeLine( w, " ", "artifactId", metadata.getArtifactId() );
|
||||
writeLine( w, " ", "version", metadata.getVersion() );
|
||||
w.println( " <versioning>" );
|
||||
writeLine( w, " ", "latest", metadata.getLatestVersion() );
|
||||
writeLine( w, " ", "release", metadata.getReleaseVersion() );
|
||||
writeLine( w, " ", "lastUpdated", metadata.getLastUpdated() );
|
||||
w.println( " <snapshot>" );
|
||||
if ( metadata.isLocalCopy() )
|
||||
{
|
||||
writeLine( w, " ", "localCopy", "true" );
|
||||
}
|
||||
if ( metadata.getSnapshotBuildNumber() > 0 )
|
||||
{
|
||||
writeLine( w, " ", "buildNumber", String.valueOf( metadata.getSnapshotBuildNumber() ) );
|
||||
}
|
||||
writeLine( w, " ", "timestamp", metadata.getSnapshotTimestamp() );
|
||||
w.println( " </snapshot>" );
|
||||
w.println( " <versions>" );
|
||||
for ( Iterator i = metadata.getVersions().iterator(); i.hasNext(); )
|
||||
{
|
||||
writeLine( w, " ", "version", (String) i.next() );
|
||||
}
|
||||
w.println( " </versions>" );
|
||||
w.println( " </versioning>" );
|
||||
w.println( "</metadata>" );
|
||||
}
|
||||
finally
|
||||
{
|
||||
w.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLine( PrintWriter w, String indent, String tag, String content )
|
||||
{
|
||||
if ( content != null )
|
||||
{
|
||||
w.println( indent + ( "<" + tag + ">" + content + "</" + tag + ">" ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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 java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Describes a dependency.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Dependency extends Model
|
||||
{
|
||||
private String id;
|
||||
|
||||
private String url;
|
||||
|
||||
private String jar;
|
||||
|
||||
private String scope = SCOPE_COMPILE;
|
||||
|
||||
private String resolvedVersion;
|
||||
|
||||
private boolean optional;
|
||||
|
||||
public static final String SCOPE_TEST = "test";
|
||||
|
||||
public static final String SCOPE_COMPILE = "compile";
|
||||
|
||||
public static final String SCOPE_RUNTIME = "runtime";
|
||||
|
||||
private Set exclusions = new HashSet();
|
||||
|
||||
public Dependency( List chain )
|
||||
{
|
||||
super(chain);
|
||||
}
|
||||
|
||||
public Dependency( String groupId, String artifactId, String version, String type, List chain )
|
||||
{
|
||||
this( chain );
|
||||
setVersion( version );
|
||||
setArtifactId( artifactId );
|
||||
setGroupId( groupId );
|
||||
setType( type );
|
||||
}
|
||||
|
||||
public void setId( String id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
if ( isValid( getGroupId() ) && isValid( getArtifactId() ) )
|
||||
{
|
||||
return getGroupId() + ":" + getArtifactId();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getArtifactDirectory()
|
||||
{
|
||||
if ( isValid( getGroupId() ) )
|
||||
{
|
||||
return getGroupId();
|
||||
}
|
||||
|
||||
return getId();
|
||||
}
|
||||
|
||||
public String getArtifact()
|
||||
{
|
||||
// If the jar name has been explicty set then use that. This
|
||||
// is when the <jar/> element is explicity used in the POM.
|
||||
if ( jar != null )
|
||||
{
|
||||
return jar;
|
||||
}
|
||||
|
||||
String artifact;
|
||||
|
||||
if ( isValid( getArtifactId() ) )
|
||||
{
|
||||
artifact = getArtifactId() + "-" + getResolvedVersion() + ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
artifact = getId() + "-" + getResolvedVersion() + ".";
|
||||
}
|
||||
|
||||
if ( "jar".equals( getType() ) || "maven-plugin".equals( getType() ) )
|
||||
{
|
||||
artifact += "jar";
|
||||
}
|
||||
else
|
||||
{
|
||||
artifact += getType();
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public void setJar( String jar )
|
||||
{
|
||||
// This is a check we need because of the jelly interpolation
|
||||
// process. If we don't check an empty string will be set and
|
||||
// screw up getArtifact() above.
|
||||
if ( jar.trim().length() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.jar = jar;
|
||||
}
|
||||
|
||||
public String getJar()
|
||||
{
|
||||
return jar;
|
||||
}
|
||||
|
||||
public String getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope( String scope )
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public void setUrl( String url )
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return getPackaging();
|
||||
}
|
||||
|
||||
public void setType( String type )
|
||||
{
|
||||
setPackaging( type );
|
||||
}
|
||||
|
||||
private boolean isValid( String value )
|
||||
{
|
||||
return value != null && !value.trim().equals( "" );
|
||||
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Dependency[" + getId() + ":" + getVersion() + ":" + getType() + "]";
|
||||
}
|
||||
|
||||
|
||||
public String getConflictId()
|
||||
{
|
||||
return getGroupId() + ":" + getArtifactId() + ":" + getType();
|
||||
}
|
||||
|
||||
public String getDependencyConflictId()
|
||||
{
|
||||
return getGroupId() + ":" + getArtifactId() + ":" + getType() + ":" + getVersion();
|
||||
}
|
||||
|
||||
public void setResolvedVersion( String resolvedVersion )
|
||||
{
|
||||
this.resolvedVersion = resolvedVersion;
|
||||
}
|
||||
|
||||
public String getResolvedVersion()
|
||||
{
|
||||
if ( resolvedVersion == null )
|
||||
{
|
||||
resolvedVersion = getVersion();
|
||||
}
|
||||
return resolvedVersion;
|
||||
}
|
||||
|
||||
public void addExclusion( Exclusion currentExclusion )
|
||||
{
|
||||
exclusions.add( currentExclusion.getConflictId() );
|
||||
}
|
||||
|
||||
public Set getExclusions()
|
||||
{
|
||||
return exclusions;
|
||||
}
|
||||
|
||||
public Dependency getPomDependency()
|
||||
{
|
||||
Dependency dep = new Dependency( getGroupId(), getArtifactId(), getVersion(), "pom", getChain() );
|
||||
dep.getRepositories().addAll( getRepositories() );
|
||||
return dep;
|
||||
}
|
||||
|
||||
public void setOptional( boolean optional )
|
||||
{
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
public boolean isOptional()
|
||||
{
|
||||
return optional;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( o instanceof Dependency )
|
||||
{
|
||||
return super.equals( o );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Excluded dependency.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Exclusion
|
||||
{
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getConflictId()
|
||||
{
|
||||
return groupId + ":" + artifactId + ":jar";
|
||||
}
|
||||
}
|
@ -1,290 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a Model.
|
||||
*
|
||||
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
|
||||
*
|
||||
*/
|
||||
public class Model
|
||||
{
|
||||
private Map plugins = new HashMap();
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String parentGroupId;
|
||||
|
||||
private String parentArtifactId;
|
||||
|
||||
private String parentVersion;
|
||||
|
||||
private String packaging = "jar";
|
||||
|
||||
private File pomFile;
|
||||
|
||||
private List modules = new ArrayList();
|
||||
|
||||
private List resources = new ArrayList();
|
||||
|
||||
private Set repositories = new HashSet();
|
||||
|
||||
private Map dependencies = new HashMap();
|
||||
|
||||
private Map parentDependencies = new HashMap();
|
||||
|
||||
private Map transitiveDependencies = new HashMap();
|
||||
|
||||
private Map managedDependencies = new HashMap();
|
||||
|
||||
private Map managedPlugins = new HashMap();
|
||||
|
||||
private List chain;
|
||||
|
||||
public Model()
|
||||
{
|
||||
this.chain = new ArrayList();
|
||||
}
|
||||
|
||||
public Model( List chain )
|
||||
{
|
||||
this.chain = new ArrayList( chain );
|
||||
this.chain.add( this );
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return groupId + ":" + artifactId + ":" + packaging + ":" + version;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getPackaging()
|
||||
{
|
||||
return packaging;
|
||||
}
|
||||
|
||||
public String getParentArtifactId()
|
||||
{
|
||||
return parentArtifactId;
|
||||
}
|
||||
|
||||
public void setParentArtifactId( String artifactId )
|
||||
{
|
||||
this.parentArtifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setPackaging( String packaging )
|
||||
{
|
||||
this.packaging = packaging;
|
||||
}
|
||||
|
||||
public String getParentGroupId()
|
||||
{
|
||||
return parentGroupId;
|
||||
}
|
||||
|
||||
public void setParentGroupId( String groupId )
|
||||
{
|
||||
this.parentGroupId = groupId;
|
||||
}
|
||||
|
||||
public String getParentVersion()
|
||||
{
|
||||
return parentVersion;
|
||||
}
|
||||
|
||||
public void setParentVersion( String version )
|
||||
{
|
||||
this.parentVersion = version;
|
||||
}
|
||||
|
||||
public Map getPlugins()
|
||||
{
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public List getModules()
|
||||
{
|
||||
return modules;
|
||||
}
|
||||
|
||||
public List getResources()
|
||||
{
|
||||
return resources;
|
||||
}
|
||||
|
||||
public File getProjectFile()
|
||||
{
|
||||
return pomFile;
|
||||
}
|
||||
|
||||
public void setPomFile( File file )
|
||||
{
|
||||
this.pomFile = file;
|
||||
}
|
||||
|
||||
public Set getRepositories()
|
||||
{
|
||||
return repositories;
|
||||
}
|
||||
|
||||
public Collection getAllDependencies()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( transitiveDependencies );
|
||||
m.putAll( parentDependencies );
|
||||
m.putAll( dependencies );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
public List getChain()
|
||||
{
|
||||
return chain;
|
||||
}
|
||||
|
||||
public Map getDependencies()
|
||||
{
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public Map getParentDependencies()
|
||||
{
|
||||
return parentDependencies;
|
||||
}
|
||||
|
||||
public Map getTransitiveDependencies()
|
||||
{
|
||||
return transitiveDependencies;
|
||||
}
|
||||
|
||||
public Map getManagedDependencies()
|
||||
{
|
||||
return managedDependencies;
|
||||
}
|
||||
|
||||
public Collection getManagedDependenciesCollection()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( managedDependencies );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
public Map getManagedPlugins()
|
||||
{
|
||||
return managedPlugins;
|
||||
}
|
||||
|
||||
public Collection getManagedPluginsCollection()
|
||||
{
|
||||
Map m = new HashMap();
|
||||
m.putAll( managedPlugins );
|
||||
return m.values();
|
||||
}
|
||||
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Model[" + getId() + "]";
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 17;
|
||||
result = 37 * result + groupId.hashCode();
|
||||
result = 37 * result + artifactId.hashCode();
|
||||
result = 37 * result + packaging.hashCode();
|
||||
result = 37 * result + version.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( o == this )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( o instanceof Model ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Model d = (Model) o;
|
||||
|
||||
if ( !d.getGroupId().equals( groupId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getArtifactId().equals( artifactId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getVersion().equals( version ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getPackaging().equals( packaging ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,477 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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.download.ArtifactResolver;
|
||||
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.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Parse a POM.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ModelReader
|
||||
extends AbstractReader
|
||||
{
|
||||
private int depth = 0;
|
||||
|
||||
private Model model;
|
||||
|
||||
private Dependency currentDependency;
|
||||
|
||||
private Resource currentResource;
|
||||
|
||||
private boolean insideParent;
|
||||
|
||||
private boolean insideDependency;
|
||||
|
||||
private boolean insideResource;
|
||||
|
||||
private boolean insideRepository;
|
||||
|
||||
private StringBuffer bodyText = new StringBuffer();
|
||||
|
||||
private final boolean resolveTransitiveDependencies;
|
||||
|
||||
private Repository currentRepository;
|
||||
|
||||
private final ArtifactResolver resolver;
|
||||
|
||||
private boolean insideDependencyManagement;
|
||||
|
||||
private boolean insideDistributionManagement;
|
||||
|
||||
private boolean insidePluginManagement;
|
||||
|
||||
private boolean insideReleases;
|
||||
|
||||
private boolean insideSnapshots;
|
||||
|
||||
private boolean insideExclusion;
|
||||
|
||||
private Exclusion currentExclusion;
|
||||
|
||||
private final Set excluded;
|
||||
|
||||
private final String inheritedScope;
|
||||
|
||||
private boolean insideConfiguration;
|
||||
|
||||
private boolean insideBuild;
|
||||
|
||||
private Plugin currentPlugin;
|
||||
|
||||
private boolean insidePlugin;
|
||||
|
||||
public ModelReader( ArtifactResolver resolver, boolean resolveTransitiveDependencies )
|
||||
{
|
||||
this( resolver, null, resolveTransitiveDependencies, Collections.EMPTY_SET );
|
||||
}
|
||||
|
||||
public ModelReader( ArtifactResolver resolver, String inheritedScope, boolean resolveTransitiveDependencies,
|
||||
Set excluded )
|
||||
{
|
||||
this.resolver = resolver;
|
||||
|
||||
this.resolveTransitiveDependencies = resolveTransitiveDependencies;
|
||||
|
||||
this.excluded = excluded;
|
||||
|
||||
this.inheritedScope = inheritedScope;
|
||||
}
|
||||
|
||||
public Model parseModel( File file, List chain )
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
this.model = new Model( chain );
|
||||
model.setPomFile( file );
|
||||
|
||||
super.parse( file );
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public void startElement( String uri, String localName, String rawName, Attributes attributes )
|
||||
{
|
||||
if ( rawName.equals( "parent" ) )
|
||||
{
|
||||
insideParent = true;
|
||||
}
|
||||
else if ( rawName.equals( "repository" ) )
|
||||
{
|
||||
currentRepository = new Repository();
|
||||
|
||||
insideRepository = true;
|
||||
}
|
||||
else if ( rawName.equals( "dependency" ) )
|
||||
{
|
||||
currentDependency = new Dependency( model.getChain() );
|
||||
|
||||
insideDependency = true;
|
||||
}
|
||||
else if ( rawName.equals( "build" ) && depth == 1 )
|
||||
{
|
||||
insideBuild = true;
|
||||
}
|
||||
else if ( rawName.equals( "plugin" ) )
|
||||
{
|
||||
currentPlugin = new Plugin();
|
||||
|
||||
insidePlugin = true;
|
||||
}
|
||||
else if ( rawName.equals( "pluginManagement" ) )
|
||||
{
|
||||
insidePluginManagement = true;
|
||||
}
|
||||
|
||||
else if ( rawName.equals( "dependencyManagement" ) )
|
||||
{
|
||||
insideDependencyManagement = true;
|
||||
}
|
||||
else if ( rawName.equals( "distributionManagement" ) )
|
||||
{
|
||||
insideDistributionManagement = true;
|
||||
}
|
||||
else if ( rawName.equals( "resource" ) )
|
||||
{
|
||||
currentResource = new Resource();
|
||||
|
||||
insideResource = true;
|
||||
}
|
||||
else if ( rawName.equals( "testResource" ) )
|
||||
{
|
||||
currentResource = new Resource();
|
||||
|
||||
insideResource = true;
|
||||
}
|
||||
else if ( rawName.equals( "snapshots" ) && insideRepository )
|
||||
{
|
||||
insideSnapshots = true;
|
||||
}
|
||||
else if ( rawName.equals( "releases" ) && insideRepository )
|
||||
{
|
||||
insideReleases = true;
|
||||
}
|
||||
else if ( rawName.equals( "exclusion" ) && insideDependency )
|
||||
{
|
||||
insideExclusion = true;
|
||||
|
||||
currentExclusion = new Exclusion();
|
||||
}
|
||||
else if ( rawName.equals( "configuration" ) && insidePlugin )
|
||||
{
|
||||
insideConfiguration = true;
|
||||
}
|
||||
depth++;
|
||||
}
|
||||
|
||||
public void characters( char buffer[], int start, int length )
|
||||
{
|
||||
bodyText.append( buffer, start, length );
|
||||
}
|
||||
|
||||
private String getBodyText()
|
||||
{
|
||||
return bodyText.toString().trim();
|
||||
}
|
||||
|
||||
public void endElement( String uri, String localName, String rawName )
|
||||
throws SAXException
|
||||
{
|
||||
// support both v3 <extend> and v4 <parent>
|
||||
if ( rawName.equals( "parent" ) )
|
||||
{
|
||||
if ( model.getParentArtifactId() == null || model.getParentArtifactId().trim().length() == 0 )
|
||||
{
|
||||
throw new SAXException( "Missing required element in <parent>: artifactId." );
|
||||
}
|
||||
|
||||
if ( model.getParentGroupId() == null || model.getParentGroupId().trim().length() == 0 )
|
||||
{
|
||||
throw new SAXException( "Missing required element in <parent>: groupId." );
|
||||
}
|
||||
|
||||
if ( model.getParentVersion() == null || model.getParentVersion().trim().length() == 0 )
|
||||
{
|
||||
throw new SAXException( "Missing required element in <parent>: version." );
|
||||
}
|
||||
|
||||
if ( model.getGroupId() == null )
|
||||
{
|
||||
model.setGroupId( model.getParentGroupId() );
|
||||
}
|
||||
|
||||
if ( model.getVersion() == null )
|
||||
{
|
||||
model.setVersion( model.getParentVersion() );
|
||||
}
|
||||
|
||||
Model p = ProjectResolver.retrievePom( resolver, model.getParentGroupId(), model.getParentArtifactId(),
|
||||
model.getParentVersion(), inheritedScope, false, excluded, model.getChain() );
|
||||
|
||||
ProjectResolver.addDependencies( p.getAllDependencies(), model.getParentDependencies(), inheritedScope, excluded );
|
||||
|
||||
ProjectResolver.addDependencies( p.getManagedDependenciesCollection(), model.getManagedDependencies(), inheritedScope, Collections.EMPTY_SET );
|
||||
|
||||
ProjectResolver.addPluginManagement( p.getManagedPluginsCollection(), model.getManagedPlugins() );
|
||||
model.getRepositories().addAll( p.getRepositories() );
|
||||
|
||||
model.getResources().addAll( p.getResources() );
|
||||
|
||||
insideParent = false;
|
||||
}
|
||||
else if ( rawName.equals( "dependency" ) )
|
||||
{
|
||||
insideDependency = false;
|
||||
|
||||
if ( insideDependencyManagement )
|
||||
{
|
||||
model.getManagedDependencies().put( currentDependency.getConflictId(), currentDependency );
|
||||
}
|
||||
else
|
||||
{
|
||||
model.getDependencies().put( currentDependency.getConflictId(), currentDependency );
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "exclusion" ) )
|
||||
{
|
||||
currentDependency.addExclusion( currentExclusion );
|
||||
insideExclusion = false;
|
||||
}
|
||||
else if ( rawName.equals( "dependencyManagement" ) )
|
||||
{
|
||||
insideDependencyManagement = false;
|
||||
}
|
||||
else if ( rawName.equals( "distributionManagement" ) )
|
||||
{
|
||||
insideDistributionManagement = false;
|
||||
}
|
||||
else if ( rawName.equals( "resource" ) )
|
||||
{
|
||||
model.getResources().add( currentResource );
|
||||
|
||||
insideResource = false;
|
||||
}
|
||||
else if ( rawName.equals( "repository" ) )
|
||||
{
|
||||
if ( !insideDistributionManagement )
|
||||
{
|
||||
model.getRepositories().add( currentRepository );
|
||||
}
|
||||
|
||||
insideRepository = false;
|
||||
}
|
||||
else if ( rawName.equals( "plugin" ) )
|
||||
{
|
||||
if (insidePluginManagement)
|
||||
{
|
||||
model.getManagedPlugins().put( currentPlugin.getId(), currentPlugin );
|
||||
}
|
||||
else
|
||||
{
|
||||
model.getPlugins().put( currentPlugin.getId(), currentPlugin );
|
||||
}
|
||||
|
||||
insidePlugin = false;
|
||||
}
|
||||
else if ( rawName.equals( "build" ) )
|
||||
{
|
||||
insideBuild = false;
|
||||
}
|
||||
else if ( rawName.equals( "module" ) )
|
||||
{
|
||||
model.getModules().add( getBodyText() );
|
||||
}
|
||||
else if ( insideParent )
|
||||
{
|
||||
if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
model.setParentGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
model.setParentArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "version" ) )
|
||||
{
|
||||
model.setParentVersion( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( insideDependency )
|
||||
{
|
||||
if ( insideExclusion )
|
||||
{
|
||||
if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
currentExclusion.setGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
currentExclusion.setArtifactId( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "id" ) )
|
||||
{
|
||||
currentDependency.setId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "version" ) )
|
||||
{
|
||||
currentDependency.setVersion( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "jar" ) )
|
||||
{
|
||||
currentDependency.setJar( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "type" ) )
|
||||
{
|
||||
currentDependency.setType( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
currentDependency.setGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
currentDependency.setArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "scope" ) )
|
||||
{
|
||||
currentDependency.setScope( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "optional" ) )
|
||||
{
|
||||
currentDependency.setOptional( Boolean.valueOf( getBodyText() ).booleanValue() );
|
||||
}
|
||||
}
|
||||
else if ( insideBuild && insidePlugin )
|
||||
{
|
||||
if ( insideConfiguration )
|
||||
{
|
||||
if ( rawName.equals( "configuration" ) )
|
||||
{
|
||||
insideConfiguration = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPlugin.getConfiguration().put( rawName, getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
currentPlugin.setGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
currentPlugin.setArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "version" ) )
|
||||
{
|
||||
currentPlugin.setVersion( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( insideResource )
|
||||
{
|
||||
if ( rawName.equals( "directory" ) )
|
||||
{
|
||||
currentResource.setDirectory( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "include" ) )
|
||||
{
|
||||
currentResource.addInclude( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "exclude" ) )
|
||||
{
|
||||
currentResource.addExclude( getBodyText() );
|
||||
}
|
||||
}
|
||||
else if ( insideRepository )
|
||||
{
|
||||
if ( rawName.equals( "id" ) )
|
||||
{
|
||||
currentRepository.setId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "url" ) )
|
||||
{
|
||||
currentRepository.setBasedir( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "layout" ) )
|
||||
{
|
||||
currentRepository.setLayout( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "enabled" ) )
|
||||
{
|
||||
if ( insideSnapshots )
|
||||
{
|
||||
currentRepository.setSnapshots( Boolean.valueOf( getBodyText() ).booleanValue() );
|
||||
}
|
||||
else if ( insideReleases )
|
||||
{
|
||||
currentRepository.setReleases( Boolean.valueOf( getBodyText() ).booleanValue() );
|
||||
}
|
||||
}
|
||||
else if ( rawName.equals( "snapshots" ) )
|
||||
{
|
||||
insideSnapshots = false;
|
||||
}
|
||||
else if ( rawName.equals( "releases" ) )
|
||||
{
|
||||
insideReleases = false;
|
||||
}
|
||||
}
|
||||
else if ( depth == 2 )
|
||||
{
|
||||
if ( rawName.equals( "artifactId" ) )
|
||||
{
|
||||
model.setArtifactId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "version" ) )
|
||||
{
|
||||
model.setVersion( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "groupId" ) )
|
||||
{
|
||||
model.setGroupId( getBodyText() );
|
||||
}
|
||||
else if ( rawName.equals( "packaging" ) )
|
||||
{
|
||||
model.setPackaging( getBodyText() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( depth == 1 ) // model / project
|
||||
{
|
||||
resolver.addBuiltArtifact( model.getGroupId(), model.getArtifactId(), "pom", model.getProjectFile() );
|
||||
|
||||
ProjectResolver.resolveDependencies( resolver, model, resolveTransitiveDependencies, inheritedScope, excluded );
|
||||
}
|
||||
|
||||
bodyText = new StringBuffer();
|
||||
|
||||
depth--;
|
||||
}
|
||||
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Describes a dependency.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Plugin
|
||||
{
|
||||
private String version;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private Map configuration = new HashMap();
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return getGroupId() + ":" + getArtifactId();
|
||||
}
|
||||
|
||||
public void setGroupId( String groupId )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactId( String artifactId )
|
||||
{
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setVersion( String version )
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return getId() + ":" + getVersion();
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 17;
|
||||
result = 37 * result + groupId.hashCode();
|
||||
result = 37 * result + artifactId.hashCode();
|
||||
result = 37 * result + version.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( o == this )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( o instanceof Plugin ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin d = (Plugin) o;
|
||||
|
||||
if ( !d.getGroupId().equals( groupId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getArtifactId().equals( artifactId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( !d.getVersion().equals( version ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Map getConfiguration()
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public Dependency asDependency()
|
||||
{
|
||||
return new Dependency( groupId, artifactId, version, "maven-plugin", Collections.EMPTY_LIST );
|
||||
}
|
||||
|
||||
public Dependency asDependencyPom()
|
||||
{
|
||||
return new Dependency( groupId, artifactId, version, "pom", Collections.EMPTY_LIST );
|
||||
}
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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.download.ArtifactResolver;
|
||||
import org.apache.maven.bootstrap.download.DownloadFailedException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility class for resolving Model dependencies.
|
||||
*
|
||||
*/
|
||||
public final class ProjectResolver
|
||||
{
|
||||
private static Set inProgress = new HashSet();
|
||||
|
||||
private ProjectResolver()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void resolveDependencies( ArtifactResolver resolver, Model model,
|
||||
boolean resolveTransitiveDependencies, String inheritedScope, Set excluded )
|
||||
throws SAXException
|
||||
{
|
||||
for ( Iterator it = model.getDependencies().values().iterator(); it.hasNext(); )
|
||||
{
|
||||
Dependency dependency = (Dependency) it.next();
|
||||
|
||||
if ( !excluded.contains( dependency.getConflictId() ) && !dependency.isOptional() )
|
||||
{
|
||||
if ( !dependency.getScope().equals( Dependency.SCOPE_TEST ) || inheritedScope == null )
|
||||
{
|
||||
if ( dependency.getVersion() == null )
|
||||
{
|
||||
Dependency managedDependency = (Dependency) model.getManagedDependencies().get( dependency
|
||||
.getConflictId() );
|
||||
|
||||
if ( managedDependency == null )
|
||||
{
|
||||
throw new NullPointerException( "[" + model.getId() + "] " + "Dependency "
|
||||
+ dependency.getConflictId()
|
||||
+ " is missing a version, and nothing is found in dependencyManagement. " );
|
||||
}
|
||||
dependency.setVersion( managedDependency.getVersion() );
|
||||
}
|
||||
|
||||
if ( resolveTransitiveDependencies )
|
||||
{
|
||||
Set excluded2 = new HashSet( excluded );
|
||||
excluded2.addAll( dependency.getExclusions() );
|
||||
|
||||
Model p = retrievePom( resolver, dependency.getGroupId(), dependency.getArtifactId(),
|
||||
dependency.getVersion(), dependency.getScope(),
|
||||
resolveTransitiveDependencies, excluded2, dependency.getChain() );
|
||||
|
||||
addDependencies( p.getAllDependencies(), model.getTransitiveDependencies(), dependency.getScope(),
|
||||
excluded2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDependencies( Collection dependencies, Map target, String inheritedScope, Set excluded )
|
||||
{
|
||||
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
||||
// skip test deps
|
||||
if ( !Dependency.SCOPE_TEST.equals( d.getScope() ) )
|
||||
{
|
||||
// Do we care about runtime here?
|
||||
if ( Dependency.SCOPE_TEST.equals( inheritedScope ) )
|
||||
{
|
||||
d.setScope( Dependency.SCOPE_TEST );
|
||||
}
|
||||
|
||||
if ( !hasDependency( d, target ) && !excluded.contains( d.getConflictId() ) && !d.isOptional() )
|
||||
{
|
||||
if ( !"plexus".equals( d.getGroupId() )
|
||||
|| ( !"plexus-utils".equals( d.getArtifactId() ) && !"plexus-container-default".equals( d
|
||||
.getArtifactId() ) ) )
|
||||
{
|
||||
target.put( d.getConflictId(), d );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPluginManagement( Collection plugins, Map target)
|
||||
{
|
||||
Plugin managedPlugin;
|
||||
for (Iterator i = plugins.iterator(); i.hasNext(); )
|
||||
{
|
||||
managedPlugin = (Plugin) i.next();
|
||||
target.put(managedPlugin.getId(),managedPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasDependency( Dependency d, Map dependencies )
|
||||
{
|
||||
String conflictId = d.getConflictId();
|
||||
if ( dependencies.containsKey( conflictId ) )
|
||||
{
|
||||
// We only care about pushing in compile scope dependencies I think
|
||||
// if not, we'll need to be able to get the original and pick the appropriate scope
|
||||
if ( d.getScope().equals( Dependency.SCOPE_COMPILE ) )
|
||||
{
|
||||
dependencies.remove( conflictId );
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Model retrievePom( ArtifactResolver resolver, String groupId, String artifactId, String version,
|
||||
String inheritedScope, boolean resolveTransitiveDependencies, Set excluded,
|
||||
List chain )
|
||||
throws SAXException
|
||||
{
|
||||
String key = groupId + ":" + artifactId + ":" + version;
|
||||
|
||||
if ( inProgress.contains( key ) )
|
||||
{
|
||||
throw new SAXException( "Circular dependency found, looking for " + key + "\nIn progress:" + inProgress );
|
||||
}
|
||||
|
||||
inProgress.add( key );
|
||||
|
||||
ModelReader p = new ModelReader( resolver, inheritedScope, resolveTransitiveDependencies, excluded );
|
||||
|
||||
try
|
||||
{
|
||||
// download the POM
|
||||
Dependency pom = new Dependency( groupId, artifactId, version, "pom", chain );
|
||||
|
||||
resolver.downloadDependencies( Collections.singletonList( pom ) );
|
||||
|
||||
// Parse the POM from the local repository into a model
|
||||
Model model = p.parseModel( resolver.getArtifactFile( pom ), chain );
|
||||
|
||||
inProgress.remove( key );
|
||||
|
||||
return model;
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
catch ( ParserConfigurationException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
catch ( DownloadFailedException e )
|
||||
{
|
||||
throw new SAXException( "Error getting parent POM", e );
|
||||
}
|
||||
}
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Repository path management.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Repository
|
||||
{
|
||||
public static final String LAYOUT_LEGACY = "legacy";
|
||||
|
||||
public static final String LAYOUT_DEFAULT = "default";
|
||||
|
||||
private String basedir;
|
||||
|
||||
private String layout = LAYOUT_DEFAULT;
|
||||
|
||||
private String id;
|
||||
|
||||
private boolean releases = true;
|
||||
|
||||
private boolean snapshots = true;
|
||||
|
||||
public Repository()
|
||||
{
|
||||
}
|
||||
|
||||
public Repository( String id, String basedir, String layout, boolean snapshots, boolean releases )
|
||||
{
|
||||
this.id = id;
|
||||
this.basedir = basedir;
|
||||
this.layout = layout;
|
||||
this.snapshots = snapshots;
|
||||
this.releases = releases;
|
||||
}
|
||||
|
||||
public File getArtifactFile( Dependency dependency )
|
||||
{
|
||||
String repositoryPath = getArtifactPath( dependency );
|
||||
|
||||
return new File( basedir, repositoryPath );
|
||||
}
|
||||
|
||||
public String getArtifactPath( Dependency dependency )
|
||||
{
|
||||
String repositoryPath;
|
||||
if ( LAYOUT_LEGACY.equals( layout ) )
|
||||
{
|
||||
repositoryPath = dependency.getArtifactDirectory() + "/" + dependency.getType() + "s/" +
|
||||
dependency.getArtifact();
|
||||
}
|
||||
else if ( LAYOUT_DEFAULT.equals( layout ) )
|
||||
{
|
||||
repositoryPath = dependency.getGroupId().replace( '.', '/' );
|
||||
repositoryPath = repositoryPath + "/" + dependency.getArtifactId() + "/" + dependency.getVersion();
|
||||
repositoryPath = repositoryPath + "/" + dependency.getArtifact();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException( "Unknown layout: " + layout );
|
||||
}
|
||||
return repositoryPath;
|
||||
}
|
||||
|
||||
public File getMetadataFile( String groupId, String artifactId, String version, String type, String filename )
|
||||
{
|
||||
String repositoryPath = getMetadataPath( groupId, artifactId, version, type, filename );
|
||||
|
||||
return new File( basedir, repositoryPath );
|
||||
}
|
||||
|
||||
public String getMetadataPath( String groupId, String artifactId, String version, String type, String filename )
|
||||
{
|
||||
Dependency dependency = new Dependency( groupId, artifactId, version, type, Collections.EMPTY_LIST );
|
||||
|
||||
String repositoryPath;
|
||||
if ( LAYOUT_LEGACY.equals( layout ) )
|
||||
{
|
||||
repositoryPath = dependency.getArtifactDirectory() + "/poms/" + filename;
|
||||
}
|
||||
else if ( LAYOUT_DEFAULT.equals( layout ) )
|
||||
{
|
||||
repositoryPath = dependency.getGroupId().replace( '.', '/' );
|
||||
repositoryPath = repositoryPath + "/" + dependency.getArtifactId();
|
||||
if ( version != null )
|
||||
{
|
||||
repositoryPath = repositoryPath + "/" + dependency.getVersion();
|
||||
}
|
||||
repositoryPath = repositoryPath + "/" + filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException( "Unknown layout: " + layout );
|
||||
}
|
||||
return repositoryPath;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return basedir;
|
||||
}
|
||||
|
||||
public String getBasedir()
|
||||
{
|
||||
return basedir;
|
||||
}
|
||||
|
||||
public void setBasedir( String basedir )
|
||||
{
|
||||
this.basedir = basedir;
|
||||
}
|
||||
|
||||
public void setLayout( String layout )
|
||||
{
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId( String id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLayout()
|
||||
{
|
||||
return layout;
|
||||
}
|
||||
|
||||
public void setReleases( boolean releases )
|
||||
{
|
||||
this.releases = releases;
|
||||
}
|
||||
|
||||
public void setSnapshots( boolean snapshots )
|
||||
{
|
||||
this.snapshots = snapshots;
|
||||
}
|
||||
|
||||
public boolean isReleases()
|
||||
{
|
||||
return releases;
|
||||
}
|
||||
|
||||
public boolean isSnapshots()
|
||||
{
|
||||
return snapshots;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package org.apache.maven.bootstrap.model;
|
||||
|
||||
/*
|
||||
* 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 java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes a resource.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Resource
|
||||
implements Serializable
|
||||
{
|
||||
private String directory;
|
||||
|
||||
private List includes = new ArrayList();
|
||||
|
||||
private List excludes = new ArrayList();
|
||||
|
||||
public void addInclude( String pattern )
|
||||
{
|
||||
this.includes.add( pattern );
|
||||
}
|
||||
|
||||
public void addExclude( String pattern )
|
||||
{
|
||||
this.excludes.add( pattern );
|
||||
}
|
||||
|
||||
public List getIncludes()
|
||||
{
|
||||
return this.includes;
|
||||
}
|
||||
|
||||
public List getExcludes()
|
||||
{
|
||||
return this.excludes;
|
||||
}
|
||||
|
||||
public void setDirectory( String directory )
|
||||
{
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public String getDirectory()
|
||||
{
|
||||
return this.directory;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package org.apache.maven.bootstrap.settings;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mirror definition.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Mirror
|
||||
{
|
||||
private String id;
|
||||
|
||||
private String mirrorOf;
|
||||
|
||||
private String url;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId( String id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setMirrorOf( String mirrorOf )
|
||||
{
|
||||
this.mirrorOf = mirrorOf;
|
||||
}
|
||||
|
||||
public void setUrl( String url )
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMirrorOf()
|
||||
{
|
||||
return mirrorOf;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package org.apache.maven.bootstrap.settings;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Proxy definition.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Proxy
|
||||
{
|
||||
private boolean active;
|
||||
|
||||
private String host;
|
||||
|
||||
private String port;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String password;
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive( boolean active )
|
||||
{
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public void setHost( String host )
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setPort( String port )
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setUserName( String userName )
|
||||
{
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setPassword( String password )
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
}
|
@ -1,288 +0,0 @@
|
||||
package org.apache.maven.bootstrap.settings;
|
||||
|
||||
/*
|
||||
* 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.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.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Settings definition.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Settings
|
||||
{
|
||||
private String localRepository;
|
||||
|
||||
private List mirrors = new ArrayList();
|
||||
|
||||
private List proxies = new ArrayList();
|
||||
|
||||
private Proxy activeProxy = null;
|
||||
|
||||
public Settings()
|
||||
{
|
||||
localRepository = System.getProperty( "maven.repo.local" );
|
||||
}
|
||||
|
||||
public String getLocalRepository()
|
||||
{
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
public void setLocalRepository( String localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
}
|
||||
|
||||
public void addProxy( Proxy proxy )
|
||||
{
|
||||
proxies.add( proxy );
|
||||
}
|
||||
|
||||
public void addMirror( Mirror mirror )
|
||||
{
|
||||
mirrors.add( mirror );
|
||||
}
|
||||
|
||||
public Proxy getActiveProxy()
|
||||
{
|
||||
if ( activeProxy == null )
|
||||
{
|
||||
for ( Iterator it = proxies.iterator(); it.hasNext() && activeProxy == null; )
|
||||
{
|
||||
Proxy proxy = (Proxy) it.next();
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
activeProxy = proxy;
|
||||
}
|
||||
}
|
||||
}
|
||||
return activeProxy;
|
||||
}
|
||||
|
||||
public static Settings read( String userHome, File file )
|
||||
throws IOException, ParserConfigurationException, SAXException
|
||||
{
|
||||
return new Reader( userHome ).parseSettings( file );
|
||||
}
|
||||
|
||||
public List getMirrors()
|
||||
{
|
||||
return mirrors;
|
||||
}
|
||||
|
||||
private static class Reader
|
||||
extends AbstractReader
|
||||
{
|
||||
private Proxy currentProxy = null;
|
||||
|
||||
private StringBuffer currentBody = new StringBuffer();
|
||||
|
||||
private Mirror currentMirror;
|
||||
|
||||
private final Settings settings = new Settings();
|
||||
|
||||
private final String userHome;
|
||||
|
||||
private Reader( String userHome )
|
||||
{
|
||||
this.userHome = userHome;
|
||||
}
|
||||
|
||||
public void characters( char[] ch, int start, int length )
|
||||
throws SAXException
|
||||
{
|
||||
currentBody.append( ch, start, length );
|
||||
}
|
||||
|
||||
public void endElement( String uri, String localName, String rawName )
|
||||
throws SAXException
|
||||
{
|
||||
if ( "localRepository".equals( rawName ) )
|
||||
{
|
||||
if ( notEmpty( currentBody.toString() ) )
|
||||
{
|
||||
String localRepository = currentBody.toString().trim();
|
||||
if ( settings.getLocalRepository() == null )
|
||||
{
|
||||
settings.setLocalRepository( localRepository );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SAXException(
|
||||
"Invalid profile entry. Missing one or more " + "fields: {localRepository}." );
|
||||
}
|
||||
}
|
||||
else if ( "proxy".equals( rawName ) )
|
||||
{
|
||||
if ( notEmpty( currentProxy.getHost() ) && notEmpty( currentProxy.getPort() ) )
|
||||
{
|
||||
settings.addProxy( currentProxy );
|
||||
currentProxy = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SAXException( "Invalid proxy entry. Missing one or more fields: {host, port}." );
|
||||
}
|
||||
}
|
||||
else if ( currentProxy != null )
|
||||
{
|
||||
if ( "active".equals( rawName ) )
|
||||
{
|
||||
currentProxy.setActive( Boolean.valueOf( currentBody.toString().trim() ).booleanValue() );
|
||||
}
|
||||
else if ( "host".equals( rawName ) )
|
||||
{
|
||||
currentProxy.setHost( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "port".equals( rawName ) )
|
||||
{
|
||||
currentProxy.setPort( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "username".equals( rawName ) )
|
||||
{
|
||||
currentProxy.setUserName( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "password".equals( rawName ) )
|
||||
{
|
||||
currentProxy.setPassword( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "protocol".equals( rawName ) )
|
||||
{
|
||||
}
|
||||
else if ( "nonProxyHosts".equals( rawName ) )
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" );
|
||||
}
|
||||
}
|
||||
else if ( "mirror".equals( rawName ) )
|
||||
{
|
||||
if ( notEmpty( currentMirror.getId() ) && notEmpty( currentMirror.getMirrorOf() ) &&
|
||||
notEmpty( currentMirror.getUrl() ) )
|
||||
{
|
||||
settings.addMirror( currentMirror );
|
||||
currentMirror = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SAXException( "Invalid mirror entry. Missing one or more fields: {id, mirrorOf, url}." );
|
||||
}
|
||||
}
|
||||
else if ( currentMirror != null )
|
||||
{
|
||||
if ( "id".equals( rawName ) )
|
||||
{
|
||||
currentMirror.setId( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "mirrorOf".equals( rawName ) )
|
||||
{
|
||||
currentMirror.setMirrorOf( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "url".equals( rawName ) )
|
||||
{
|
||||
currentMirror.setUrl( currentBody.toString().trim() );
|
||||
}
|
||||
else if ( "name".equals( rawName ) )
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SAXException( "Illegal element inside proxy: \'" + rawName + "\'" );
|
||||
}
|
||||
}
|
||||
|
||||
currentBody = new StringBuffer();
|
||||
}
|
||||
|
||||
private boolean notEmpty( String test )
|
||||
{
|
||||
return test != null && test.trim().length() > 0;
|
||||
}
|
||||
|
||||
public void startElement( String uri, String localName, String rawName, Attributes attributes )
|
||||
throws SAXException
|
||||
{
|
||||
if ( "proxy".equals( rawName ) )
|
||||
{
|
||||
currentProxy = new Proxy();
|
||||
}
|
||||
else if ( "mirror".equals( rawName ) )
|
||||
{
|
||||
currentMirror = new Mirror();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
this.currentBody = null;
|
||||
this.currentMirror = null;
|
||||
}
|
||||
|
||||
public Settings parseSettings( File settingsXml )
|
||||
throws IOException, ParserConfigurationException, SAXException
|
||||
{
|
||||
if ( settingsXml.exists() )
|
||||
{
|
||||
parse( settingsXml );
|
||||
}
|
||||
if ( settings.getLocalRepository() == null )
|
||||
{
|
||||
String m2LocalRepoPath = "/.m2/repository";
|
||||
|
||||
File repoDir = new File( userHome, m2LocalRepoPath );
|
||||
if ( !repoDir.exists() )
|
||||
{
|
||||
repoDir.mkdirs();
|
||||
}
|
||||
|
||||
settings.setLocalRepository( repoDir.getAbsolutePath() );
|
||||
|
||||
System.out.println(
|
||||
"You SHOULD have a ~/.m2/settings.xml file and must contain at least the following information:" );
|
||||
System.out.println();
|
||||
|
||||
System.out.println( "<settings>" );
|
||||
System.out.println( " <localRepository>/path/to/your/repository</localRepository>" );
|
||||
System.out.println( "</settings>" );
|
||||
|
||||
System.out.println();
|
||||
|
||||
System.out.println( "Alternatively, you can specify -Dmaven.repo.local=/path/to/m2/repository" );
|
||||
|
||||
System.out.println();
|
||||
|
||||
System.out.println( "HOWEVER, since you did not specify a repository path, maven will use: " +
|
||||
repoDir.getAbsolutePath() + " to store artifacts locally." );
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
/*
|
||||
* 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.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Parse an XML file.
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractReader
|
||||
extends DefaultHandler
|
||||
{
|
||||
private SAXParserFactory saxFactory;
|
||||
|
||||
public void parse( File file )
|
||||
throws ParserConfigurationException, SAXException, IOException
|
||||
{
|
||||
saxFactory = SAXParserFactory.newInstance();
|
||||
|
||||
SAXParser parser = saxFactory.newSAXParser();
|
||||
|
||||
// Cheap and cheerful. Please add more to skip if the parser chokes (or use the actual
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
IOUtil.copy( new FileInputStream( file ), output );
|
||||
String out = output.toString( "UTF-8" );
|
||||
out = StringUtils.replace( out, "ø", "\u00f8" );
|
||||
|
||||
InputSource is = new InputSource( new ByteArrayInputStream( out.getBytes( "UTF-8" ) ) );
|
||||
|
||||
try
|
||||
{
|
||||
parser.parse( is, this );
|
||||
}
|
||||
catch ( SAXException e )
|
||||
{
|
||||
System.err.println( "Error reading POM: " + file );
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void warning( SAXParseException spe )
|
||||
{
|
||||
printParseError( "Warning", spe );
|
||||
}
|
||||
|
||||
public void error( SAXParseException spe )
|
||||
{
|
||||
printParseError( "Error", spe );
|
||||
}
|
||||
|
||||
public void fatalError( SAXParseException spe )
|
||||
{
|
||||
printParseError( "Fatal Error", spe );
|
||||
}
|
||||
|
||||
private final void printParseError( String type, SAXParseException spe )
|
||||
{
|
||||
System.err.println(
|
||||
type + " [line " + spe.getLineNumber() + ", row " + spe.getColumnNumber() + "]: " + spe.getMessage() );
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,782 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
/*
|
||||
* 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 java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* General IO Stream manipulation.
|
||||
* <p/>
|
||||
* This class provides static utility methods for input/output operations, particularly buffered
|
||||
* copying between sources (<code>InputStream</code>, <code>Reader</code>, <code>String</code> and
|
||||
* <code>byte[]</code>) and destinations (<code>OutputStream</code>, <code>Writer</code>,
|
||||
* <code>String</code> and <code>byte[]</code>).
|
||||
* </p>
|
||||
* <p/>
|
||||
* <p>Unless otherwise noted, these <code>copy</code> methods do <em>not</em> flush or close the
|
||||
* streams. Often, doing so would require making non-portable assumptions about the streams' origin
|
||||
* and further use. This means that both streams' <code>close()</code> methods must be called after
|
||||
* copying. if one omits this step, then the stream resources (sockets, file descriptors) are
|
||||
* released when the associated Stream is garbage-collected. It is not a good idea to rely on this
|
||||
* mechanism. For a good overview of the distinction between "memory management" and "resource
|
||||
* management", see <a href="http://www.unixreview.com/articles/1998/9804/9804ja/ja.htm">this
|
||||
* UnixReview article</a></p>
|
||||
* <p/>
|
||||
* <p>For each <code>copy</code> method, a variant is provided that allows the caller to specify the
|
||||
* buffer size (the default is 4k). As the buffer size can have a fairly large impact on speed, this
|
||||
* may be worth tweaking. Often "large buffer -> faster" does not hold, even for large data
|
||||
* transfers.</p>
|
||||
* <p/>
|
||||
* <p>For byte-to-char methods, a <code>copy</code> variant allows the encoding to be selected
|
||||
* (otherwise the platform default is used).</p>
|
||||
* <p/>
|
||||
* <p>The <code>copy</code> methods use an internal buffer when copying. It is therefore advisable
|
||||
* <em>not</em> to deliberately wrap the stream arguments to the <code>copy</code> methods in
|
||||
* <code>Buffered*</code> streams. For example, don't do the
|
||||
* following:</p>
|
||||
* <p/>
|
||||
* <code>copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) );</code>
|
||||
* <p/>
|
||||
* <p>The rationale is as follows:</p>
|
||||
* <p/>
|
||||
* <p>Imagine that an InputStream's read() is a very expensive operation, which would usually suggest
|
||||
* wrapping in a BufferedInputStream. The BufferedInputStream works by issuing infrequent
|
||||
* {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the underlying InputStream, to
|
||||
* fill an internal buffer, from which further <code>read</code> requests can inexpensively get
|
||||
* their data (until the buffer runs out).</p>
|
||||
* <p>However, the <code>copy</code> methods do the same thing, keeping an internal buffer,
|
||||
* populated by {@link InputStream#read(byte[] b, int off, int len)} requests. Having two buffers
|
||||
* (or three if the destination stream is also buffered) is pointless, and the unnecessary buffer
|
||||
* management hurts performance slightly (about 3%, according to some simple experiments).</p>
|
||||
*
|
||||
* @author <a href="mailto:peter@codehaus.org">Peter Donald</a>
|
||||
* @author <a href="mailto:jefft@codehaus.org">Jeff Turner</a>
|
||||
* @version CVS $Revision$ $Date$
|
||||
* @since 4.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* Behold, intrepid explorers; a map of this class:
|
||||
*
|
||||
* Method Input Output Dependency
|
||||
* ------ ----- ------ -------
|
||||
* 1 copy InputStream OutputStream (primitive)
|
||||
* 2 copy Reader Writer (primitive)
|
||||
*
|
||||
* 3 copy InputStream Writer 2
|
||||
* 4 toString InputStream String 3
|
||||
* 5 toByteArray InputStream byte[] 1
|
||||
*
|
||||
* 6 copy Reader OutputStream 2
|
||||
* 7 toString Reader String 2
|
||||
* 8 toByteArray Reader byte[] 6
|
||||
*
|
||||
* 9 copy String OutputStream 2
|
||||
* 10 copy String Writer (trivial)
|
||||
* 11 toByteArray String byte[] 9
|
||||
*
|
||||
* 12 copy byte[] Writer 3
|
||||
* 13 toString byte[] String 12
|
||||
* 14 copy byte[] OutputStream (trivial)
|
||||
*
|
||||
*
|
||||
* Note that only the first two methods shuffle bytes; the rest use these two, or (if possible) copy
|
||||
* using native Java copy methods. As there are method variants to specify buffer size and encoding,
|
||||
* each row may correspond to up to 4 methods.
|
||||
*
|
||||
*/
|
||||
|
||||
public final class IOUtil
|
||||
{
|
||||
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
||||
|
||||
/**
|
||||
* Private constructor to prevent instantiation.
|
||||
*/
|
||||
private IOUtil()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Core copy methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
|
||||
*/
|
||||
public static void copy( final InputStream input, final OutputStream output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final InputStream input, final OutputStream output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final byte[] buffer = new byte[bufferSize];
|
||||
int n = 0;
|
||||
while ( -1 != ( n = input.read( buffer ) ) )
|
||||
{
|
||||
output.write( buffer, 0, n );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy chars from a <code>Reader</code> to a <code>Writer</code>.
|
||||
*/
|
||||
public static void copy( final Reader input, final Writer output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy chars from a <code>Reader</code> to a <code>Writer</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final Reader input, final Writer output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final char[] buffer = new char[bufferSize];
|
||||
int n = 0;
|
||||
while ( -1 != ( n = input.read( buffer ) ) )
|
||||
{
|
||||
output.write( buffer, 0, n );
|
||||
}
|
||||
output.flush();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Derived copy methods
|
||||
// InputStream -> *
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// InputStream -> Writer
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from an <code>InputStream</code> to chars on a
|
||||
* <code>Writer</code>.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*/
|
||||
public static void copy( final InputStream input, final Writer output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from an <code>InputStream</code> to chars on a
|
||||
* <code>Writer</code>.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final InputStream input, final Writer output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final InputStreamReader in = new InputStreamReader( input );
|
||||
copy( in, output, bufferSize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from an <code>InputStream</code> to chars on a
|
||||
* <code>Writer</code>, using the specified encoding.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
*/
|
||||
public static void copy( final InputStream input, final Writer output, final String encoding )
|
||||
throws IOException
|
||||
{
|
||||
final InputStreamReader in = new InputStreamReader( input, encoding );
|
||||
copy( in, output );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from an <code>InputStream</code> to chars on a
|
||||
* <code>Writer</code>, using the specified encoding.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final InputStream input, final Writer output, final String encoding, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final InputStreamReader in = new InputStreamReader( input, encoding );
|
||||
copy( in, output, bufferSize );
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// InputStream -> String
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a String.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*/
|
||||
public static String toString( final InputStream input )
|
||||
throws IOException
|
||||
{
|
||||
return toString( input, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a String.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static String toString( final InputStream input, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final StringWriter sw = new StringWriter();
|
||||
copy( input, sw, bufferSize );
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a String.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
*/
|
||||
public static String toString( final InputStream input, final String encoding )
|
||||
throws IOException
|
||||
{
|
||||
return toString( input, encoding, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a String.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static String toString( final InputStream input, final String encoding, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final StringWriter sw = new StringWriter();
|
||||
copy( input, sw, encoding, bufferSize );
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// InputStream -> byte[]
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
|
||||
*/
|
||||
public static byte[] toByteArray( final InputStream input )
|
||||
throws IOException
|
||||
{
|
||||
return toByteArray( input, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static byte[] toByteArray( final InputStream input, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
copy( input, output, bufferSize );
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Derived copy methods
|
||||
// Reader -> *
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Reader -> OutputStream
|
||||
/**
|
||||
* Serialize chars from a <code>Reader</code> to bytes on an <code>OutputStream</code>, and
|
||||
* flush the <code>OutputStream</code>.
|
||||
*/
|
||||
public static void copy( final Reader input, final OutputStream output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize chars from a <code>Reader</code> to bytes on an <code>OutputStream</code>, and
|
||||
* flush the <code>OutputStream</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final Reader input, final OutputStream output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final OutputStreamWriter out = new OutputStreamWriter( output );
|
||||
copy( input, out, bufferSize );
|
||||
// NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush
|
||||
// here.
|
||||
out.flush();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Reader -> String
|
||||
/**
|
||||
* Get the contents of a <code>Reader</code> as a String.
|
||||
*/
|
||||
public static String toString( final Reader input )
|
||||
throws IOException
|
||||
{
|
||||
return toString( input, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>Reader</code> as a String.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static String toString( final Reader input, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final StringWriter sw = new StringWriter();
|
||||
copy( input, sw, bufferSize );
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Reader -> byte[]
|
||||
/**
|
||||
* Get the contents of a <code>Reader</code> as a <code>byte[]</code>.
|
||||
*/
|
||||
public static byte[] toByteArray( final Reader input )
|
||||
throws IOException
|
||||
{
|
||||
return toByteArray( input, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>Reader</code> as a <code>byte[]</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static byte[] toByteArray( final Reader input, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
copy( input, output, bufferSize );
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Derived copy methods
|
||||
// String -> *
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// String -> OutputStream
|
||||
|
||||
/**
|
||||
* Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and
|
||||
* flush the <code>OutputStream</code>.
|
||||
*/
|
||||
public static void copy( final String input, final OutputStream output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and
|
||||
* flush the <code>OutputStream</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final String input, final OutputStream output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final StringReader in = new StringReader( input );
|
||||
final OutputStreamWriter out = new OutputStreamWriter( output );
|
||||
copy( in, out, bufferSize );
|
||||
// NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush
|
||||
// here.
|
||||
out.flush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// String -> Writer
|
||||
|
||||
/**
|
||||
* Copy chars from a <code>String</code> to a <code>Writer</code>.
|
||||
*/
|
||||
public static void copy( final String input, final Writer output )
|
||||
throws IOException
|
||||
{
|
||||
output.write( input );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy bytes from an <code>InputStream</code> to an
|
||||
* <code>OutputStream</code>, with buffering.
|
||||
* This is equivalent to passing a
|
||||
* {@link java.io.BufferedInputStream} and
|
||||
* {@link java.io.BufferedOutputStream} to {@link #copy(InputStream, OutputStream)},
|
||||
* and flushing the output stream afterwards. The streams are not closed
|
||||
* after the copy.
|
||||
*
|
||||
* @deprecated Buffering streams is actively harmful! See the class description as to why. Use
|
||||
* {@link #copy(InputStream, OutputStream)} instead.
|
||||
*/
|
||||
public static void bufferedCopy( final InputStream input, final OutputStream output )
|
||||
throws IOException
|
||||
{
|
||||
final BufferedInputStream in = new BufferedInputStream( input );
|
||||
final BufferedOutputStream out = new BufferedOutputStream( output );
|
||||
copy( in, out );
|
||||
out.flush();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// String -> byte[]
|
||||
/**
|
||||
* Get the contents of a <code>String</code> as a <code>byte[]</code>.
|
||||
*/
|
||||
public static byte[] toByteArray( final String input )
|
||||
throws IOException
|
||||
{
|
||||
return toByteArray( input, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>String</code> as a <code>byte[]</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static byte[] toByteArray( final String input, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
copy( input, output, bufferSize );
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Derived copy methods
|
||||
// byte[] -> *
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// byte[] -> Writer
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from a <code>byte[]</code> to chars on a
|
||||
* <code>Writer</code>.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*/
|
||||
public static void copy( final byte[] input, final Writer output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from a <code>byte[]</code> to chars on a
|
||||
* <code>Writer</code>.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final byte[] input, final Writer output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream( input );
|
||||
copy( in, output, bufferSize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from a <code>byte[]</code> to chars on a
|
||||
* <code>Writer</code>, using the specified encoding.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
*/
|
||||
public static void copy( final byte[] input, final Writer output, final String encoding )
|
||||
throws IOException
|
||||
{
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream( input );
|
||||
copy( in, output, encoding );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy and convert bytes from a <code>byte[]</code> to chars on a
|
||||
* <code>Writer</code>, using the specified encoding.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final byte[] input, final Writer output, final String encoding, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream( input );
|
||||
copy( in, output, encoding, bufferSize );
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// byte[] -> String
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>byte[]</code> as a String.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*/
|
||||
public static String toString( final byte[] input )
|
||||
throws IOException
|
||||
{
|
||||
return toString( input, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>byte[]</code> as a String.
|
||||
* The platform's default encoding is used for the byte-to-char conversion.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static String toString( final byte[] input, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final StringWriter sw = new StringWriter();
|
||||
copy( input, sw, bufferSize );
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>byte[]</code> as a String.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
*/
|
||||
public static String toString( final byte[] input, final String encoding )
|
||||
throws IOException
|
||||
{
|
||||
return toString( input, encoding, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>byte[]</code> as a String.
|
||||
*
|
||||
* @param encoding The name of a supported character encoding. See the
|
||||
* <a href="http://www.iana.org/assignments/character-sets">IANA
|
||||
* Charset Registry</a> for a list of valid encoding types.
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static String toString( final byte[] input, final String encoding, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
final StringWriter sw = new StringWriter();
|
||||
copy( input, sw, encoding, bufferSize );
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// byte[] -> OutputStream
|
||||
|
||||
/**
|
||||
* Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
|
||||
*/
|
||||
public static void copy( final byte[] input, final OutputStream output )
|
||||
throws IOException
|
||||
{
|
||||
copy( input, output, DEFAULT_BUFFER_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
|
||||
*
|
||||
* @param bufferSize Size of internal buffer to use.
|
||||
*/
|
||||
public static void copy( final byte[] input, final OutputStream output, final int bufferSize )
|
||||
throws IOException
|
||||
{
|
||||
output.write( input );
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the contents of two Streams to determine if they are equal or not.
|
||||
*
|
||||
* @param input1 the first stream
|
||||
* @param input2 the second stream
|
||||
* @return true if the content of the streams are equal or they both don't exist, false otherwise
|
||||
*/
|
||||
public static boolean contentEquals( final InputStream input1, final InputStream input2 )
|
||||
throws IOException
|
||||
{
|
||||
final InputStream bufferedInput1 = new BufferedInputStream( input1 );
|
||||
final InputStream bufferedInput2 = new BufferedInputStream( input2 );
|
||||
|
||||
int ch = bufferedInput1.read();
|
||||
while ( -1 != ch )
|
||||
{
|
||||
final int ch2 = bufferedInput2.read();
|
||||
if ( ch != ch2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ch = bufferedInput1.read();
|
||||
}
|
||||
|
||||
final int ch2 = bufferedInput2.read();
|
||||
if ( -1 != ch2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// closeXXX()
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Closes the input stream. The input stream can be null and any IOException's will be swallowed.
|
||||
*
|
||||
* @param inputStream The stream to close.
|
||||
*/
|
||||
public static void close( InputStream inputStream )
|
||||
{
|
||||
if ( inputStream == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
inputStream.close();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the output stream. The output stream can be null and any IOException's will be swallowed.
|
||||
*
|
||||
* @param outputStream The stream to close.
|
||||
*/
|
||||
public static void close( OutputStream outputStream )
|
||||
{
|
||||
if ( outputStream == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
outputStream.close();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the reader. The reader can be null and any IOException's will be swallowed.
|
||||
*
|
||||
* @param reader The reader to close.
|
||||
*/
|
||||
public static void close( Reader reader )
|
||||
{
|
||||
if ( reader == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the writer. The writer can be null and any IOException's will be swallowed.
|
||||
*
|
||||
* @param wrtier The writer to close.
|
||||
*/
|
||||
public static void close( Writer writer )
|
||||
{
|
||||
if ( writer == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
writer.close();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
/*
|
||||
* 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 java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class IsolatedClassLoader
|
||||
extends URLClassLoader
|
||||
{
|
||||
private ClassLoader parent;
|
||||
|
||||
public IsolatedClassLoader()
|
||||
{
|
||||
this( ClassLoader.getSystemClassLoader() );
|
||||
}
|
||||
|
||||
public IsolatedClassLoader( ClassLoader parent )
|
||||
{
|
||||
super( new URL[0] );
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void addURL( URL url )
|
||||
{
|
||||
super.addURL( url );
|
||||
}
|
||||
|
||||
public synchronized Class loadClass( String className )
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
Class c = findLoadedClass( className );
|
||||
|
||||
ClassNotFoundException ex = null;
|
||||
|
||||
if ( c == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
c = findClass( className );
|
||||
}
|
||||
catch ( ClassNotFoundException e )
|
||||
{
|
||||
ex = e;
|
||||
|
||||
if ( parent != null )
|
||||
{
|
||||
c = parent.loadClass( className );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( c == null )
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
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
|
||||
{
|
||||
Map includes = new LinkedHashMap();
|
||||
|
||||
addDirectory( includes, "**/**", "**/package.html,**/.svn/**", "", basedir );
|
||||
|
||||
createJar( jarFile, includes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all files in the specified directory to the archive.
|
||||
*
|
||||
* @param includes a map <String, File> of items to be include in the outpur
|
||||
* @param baseDir the directory to add
|
||||
*/
|
||||
protected void addDirectory( Map includes, File baseDir )
|
||||
throws IOException
|
||||
{
|
||||
addDirectory( includes, "", baseDir );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all files in the specified directory to the archive.
|
||||
*
|
||||
* @param includes a map <String, File> 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
|
||||
*/
|
||||
protected void addDirectory( Map includes, String prefix, File baseDir )
|
||||
throws IOException
|
||||
{
|
||||
addDirectory( includes, null, null, prefix, baseDir );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all files in the specified directory to the archive.
|
||||
*
|
||||
* @param includes a map <String, File> 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
|
||||
*/
|
||||
protected void addDirectory( Map includes, String includesPattern, String excludesPattern, String prefix,
|
||||
File baseDir )
|
||||
throws IOException
|
||||
{
|
||||
if ( !baseDir.exists() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DirectoryScanner scanner = new DirectoryScanner();
|
||||
scanner.setBasedir( baseDir );
|
||||
if ( includesPattern != null )
|
||||
{
|
||||
scanner.setIncludes( StringUtils.split( includesPattern, "," ) );
|
||||
}
|
||||
|
||||
if ( excludesPattern != null )
|
||||
{
|
||||
scanner.setExcludes( StringUtils.split( excludesPattern, "," ) );
|
||||
}
|
||||
scanner.scan();
|
||||
String[] files = scanner.getIncludedFiles();
|
||||
for ( int i = 0; i < files.length; i++ )
|
||||
{
|
||||
String file = files[i];
|
||||
file = file.replace( '\\', '/' ); // todo shouldn't the scanner return platform independent names?
|
||||
includes.put( prefix + file, new File( baseDir, file ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a manifest for the jar file
|
||||
*
|
||||
* @return a default manifest; the Manifest-Version and Created-By attributes are initialized
|
||||
*/
|
||||
protected Manifest createManifest()
|
||||
{
|
||||
Manifest mf = new Manifest();
|
||||
Attributes attrs = mf.getMainAttributes();
|
||||
attrs.putValue( Attributes.Name.MANIFEST_VERSION.toString(), "1.0" );
|
||||
attrs.putValue( "Created-By", "Apache Maven Bootstrap Mini" );
|
||||
return mf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the jar file specified and include the listed files.
|
||||
*
|
||||
* @param jarFile the jar file to create
|
||||
* @param includes a Map<String, File>of 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
|
||||
{
|
||||
jarFile.getParentFile().mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream( jarFile );
|
||||
JarOutputStream jos = null;
|
||||
try
|
||||
{
|
||||
if ( includes.containsKey( MF ) )
|
||||
{
|
||||
jos = new JarOutputStream( fos );
|
||||
}
|
||||
else
|
||||
{
|
||||
jos = new JarOutputStream( fos, createManifest() );
|
||||
}
|
||||
addEntries( jos, includes );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( jos );
|
||||
IOUtil.close( fos );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all entries in the supplied Map to the jar
|
||||
*
|
||||
* @param jos a JarOutputStream that can be used to write to the jar
|
||||
* @param includes a Map<String, File> 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
|
||||
{
|
||||
for ( Iterator i = includes.entrySet().iterator(); i.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) i.next();
|
||||
String name = (String) entry.getKey();
|
||||
File file = (File) entry.getValue();
|
||||
addEntry( jos, name, file );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
{
|
||||
FileInputStream fis = new FileInputStream( source );
|
||||
try
|
||||
{
|
||||
jos.putNextEntry( new JarEntry( name ) );
|
||||
int count;
|
||||
while ( ( count = fis.read( buffer ) ) > 0 )
|
||||
{
|
||||
jos.write( buffer, 0, count );
|
||||
}
|
||||
jos.closeEntry();
|
||||
}
|
||||
finally
|
||||
{
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,626 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <p>This is a utility class used by selectors and DirectoryScanner. The
|
||||
* functionality more properly belongs just to selectors, but unfortunately
|
||||
* DirectoryScanner exposed these as protected methods. Thus we have to
|
||||
* support any subclasses of DirectoryScanner that may access these methods.
|
||||
* </p>
|
||||
* <p>This is a Singleton.</p>
|
||||
*
|
||||
* @author Arnout J. Kuiper
|
||||
* <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>
|
||||
* @author Magesh Umasankar
|
||||
* @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
|
||||
* @since 1.5
|
||||
*/
|
||||
public final class SelectorUtils
|
||||
{
|
||||
|
||||
private static SelectorUtils instance = new SelectorUtils();
|
||||
|
||||
/**
|
||||
* Private Constructor
|
||||
*/
|
||||
private SelectorUtils()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the manager of the Singleton.
|
||||
*/
|
||||
public static SelectorUtils getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not a given path matches the start of a given
|
||||
* pattern up to the first "**".
|
||||
* <p/>
|
||||
* This is not a general purpose test and should only be used if you
|
||||
* can live with false positives. For example, <code>pattern=**\a</code>
|
||||
* and <code>str=b</code> will yield <code>true</code>.
|
||||
*
|
||||
* @param pattern The pattern to match against. Must not be
|
||||
* <code>null</code>.
|
||||
* @param str The path to match, as a String. Must not be
|
||||
* <code>null</code>.
|
||||
* @return whether or not a given path matches the start of a given
|
||||
* pattern up to the first "**".
|
||||
*/
|
||||
public static boolean matchPatternStart( String pattern, String str )
|
||||
{
|
||||
return matchPatternStart( pattern, str, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not a given path matches the start of a given
|
||||
* pattern up to the first "**".
|
||||
* <p/>
|
||||
* This is not a general purpose test and should only be used if you
|
||||
* can live with false positives. For example, <code>pattern=**\a</code>
|
||||
* and <code>str=b</code> will yield <code>true</code>.
|
||||
*
|
||||
* @param pattern The pattern to match against. Must not be
|
||||
* <code>null</code>.
|
||||
* @param str The path to match, as a String. Must not be
|
||||
* <code>null</code>.
|
||||
* @param isCaseSensitive Whether or not matching should be performed
|
||||
* case sensitively.
|
||||
* @return whether or not a given path matches the start of a given
|
||||
* pattern up to the first "**".
|
||||
*/
|
||||
public static boolean matchPatternStart( String pattern, String str,
|
||||
boolean isCaseSensitive )
|
||||
{
|
||||
// When str starts with a File.separator, pattern has to start with a
|
||||
// File.separator.
|
||||
// When pattern starts with a File.separator, str has to start with a
|
||||
// File.separator.
|
||||
if ( str.startsWith( File.separator ) !=
|
||||
pattern.startsWith( File.separator ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector patDirs = tokenizePath( pattern );
|
||||
Vector strDirs = tokenizePath( str );
|
||||
|
||||
int patIdxStart = 0;
|
||||
int patIdxEnd = patDirs.size() - 1;
|
||||
int strIdxStart = 0;
|
||||
int strIdxEnd = strDirs.size() - 1;
|
||||
|
||||
// up to first '**'
|
||||
while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
String patDir = (String) patDirs.elementAt( patIdxStart );
|
||||
if ( patDir.equals( "**" ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ( !match( patDir, (String) strDirs.elementAt( strIdxStart ),
|
||||
isCaseSensitive ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
patIdxStart++;
|
||||
strIdxStart++;
|
||||
}
|
||||
|
||||
if ( strIdxStart > strIdxEnd )
|
||||
{
|
||||
// String is exhausted
|
||||
return true;
|
||||
}
|
||||
else if ( patIdxStart > patIdxEnd )
|
||||
{
|
||||
// String not exhausted, but pattern is. Failure.
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pattern now holds ** while string is not exhausted
|
||||
// this will generate false positives but we can live with that.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not a given path matches a given pattern.
|
||||
*
|
||||
* @param pattern The pattern to match against. Must not be
|
||||
* <code>null</code>.
|
||||
* @param str The path to match, as a String. Must not be
|
||||
* <code>null</code>.
|
||||
* @return <code>true</code> if the pattern matches against the string,
|
||||
* or <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean matchPath( String pattern, String str )
|
||||
{
|
||||
return matchPath( pattern, str, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not a given path matches a given pattern.
|
||||
*
|
||||
* @param pattern The pattern to match against. Must not be
|
||||
* <code>null</code>.
|
||||
* @param str The path to match, as a String. Must not be
|
||||
* <code>null</code>.
|
||||
* @param isCaseSensitive Whether or not matching should be performed
|
||||
* case sensitively.
|
||||
* @return <code>true</code> if the pattern matches against the string,
|
||||
* or <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean matchPath( String pattern, String str,
|
||||
boolean isCaseSensitive )
|
||||
{
|
||||
// When str starts with a File.separator, pattern has to start with a
|
||||
// File.separator.
|
||||
// When pattern starts with a File.separator, str has to start with a
|
||||
// File.separator.
|
||||
if ( str.startsWith( File.separator ) !=
|
||||
pattern.startsWith( File.separator ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector patDirs = tokenizePath( pattern );
|
||||
Vector strDirs = tokenizePath( str );
|
||||
|
||||
int patIdxStart = 0;
|
||||
int patIdxEnd = patDirs.size() - 1;
|
||||
int strIdxStart = 0;
|
||||
int strIdxEnd = strDirs.size() - 1;
|
||||
|
||||
// up to first '**'
|
||||
while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
String patDir = (String) patDirs.elementAt( patIdxStart );
|
||||
if ( patDir.equals( "**" ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ( !match( patDir, (String) strDirs.elementAt( strIdxStart ),
|
||||
isCaseSensitive ) )
|
||||
{
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
patIdxStart++;
|
||||
strIdxStart++;
|
||||
}
|
||||
if ( strIdxStart > strIdxEnd )
|
||||
{
|
||||
// String is exhausted
|
||||
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( !patDirs.elementAt( i ).equals( "**" ) )
|
||||
{
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( patIdxStart > patIdxEnd )
|
||||
{
|
||||
// String not exhausted, but pattern is. Failure.
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// up to last '**'
|
||||
while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
String patDir = (String) patDirs.elementAt( patIdxEnd );
|
||||
if ( patDir.equals( "**" ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ( !match( patDir, (String) strDirs.elementAt( strIdxEnd ),
|
||||
isCaseSensitive ) )
|
||||
{
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
patIdxEnd--;
|
||||
strIdxEnd--;
|
||||
}
|
||||
if ( strIdxStart > strIdxEnd )
|
||||
{
|
||||
// String is exhausted
|
||||
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( !patDirs.elementAt( i ).equals( "**" ) )
|
||||
{
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
int patIdxTmp = -1;
|
||||
for ( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( patDirs.elementAt( i ).equals( "**" ) )
|
||||
{
|
||||
patIdxTmp = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( patIdxTmp == patIdxStart + 1 )
|
||||
{
|
||||
// '**/**' situation, so skip one
|
||||
patIdxStart++;
|
||||
continue;
|
||||
}
|
||||
// Find the pattern between padIdxStart & padIdxTmp in str between
|
||||
// strIdxStart & strIdxEnd
|
||||
int patLength = ( patIdxTmp - patIdxStart - 1 );
|
||||
int strLength = ( strIdxEnd - strIdxStart + 1 );
|
||||
int foundIdx = -1;
|
||||
strLoop:
|
||||
for ( int i = 0; i <= strLength - patLength; i++ )
|
||||
{
|
||||
for ( int j = 0; j < patLength; j++ )
|
||||
{
|
||||
String subPat = (String) patDirs.elementAt( patIdxStart + j + 1 );
|
||||
String subStr = (String) strDirs.elementAt( strIdxStart + i + j );
|
||||
if ( !match( subPat, subStr, isCaseSensitive ) )
|
||||
{
|
||||
continue strLoop;
|
||||
}
|
||||
}
|
||||
|
||||
foundIdx = strIdxStart + i;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( foundIdx == -1 )
|
||||
{
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
patIdxStart = patIdxTmp;
|
||||
strIdxStart = foundIdx + patLength;
|
||||
}
|
||||
|
||||
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( !patDirs.elementAt( i ).equals( "**" ) )
|
||||
{
|
||||
patDirs = null;
|
||||
strDirs = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not a string matches against a pattern.
|
||||
* The pattern may contain two special characters:<br>
|
||||
* '*' means zero or more characters<br>
|
||||
* '?' means one and only one character
|
||||
*
|
||||
* @param pattern The pattern to match against.
|
||||
* Must not be <code>null</code>.
|
||||
* @param str The string which must be matched against the pattern.
|
||||
* Must not be <code>null</code>.
|
||||
* @return <code>true</code> if the string matches against the pattern,
|
||||
* or <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean match( String pattern, String str )
|
||||
{
|
||||
return match( pattern, str, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not a string matches against a pattern.
|
||||
* The pattern may contain two special characters:<br>
|
||||
* '*' means zero or more characters<br>
|
||||
* '?' means one and only one character
|
||||
*
|
||||
* @param pattern The pattern to match against.
|
||||
* Must not be <code>null</code>.
|
||||
* @param str The string which must be matched against the pattern.
|
||||
* Must not be <code>null</code>.
|
||||
* @param isCaseSensitive Whether or not matching should be performed
|
||||
* case sensitively.
|
||||
* @return <code>true</code> if the string matches against the pattern,
|
||||
* or <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean match( String pattern, String str,
|
||||
boolean isCaseSensitive )
|
||||
{
|
||||
char[] patArr = pattern.toCharArray();
|
||||
char[] strArr = str.toCharArray();
|
||||
int patIdxStart = 0;
|
||||
int patIdxEnd = patArr.length - 1;
|
||||
int strIdxStart = 0;
|
||||
int strIdxEnd = strArr.length - 1;
|
||||
char ch;
|
||||
|
||||
boolean containsStar = false;
|
||||
for ( int i = 0; i < patArr.length; i++ )
|
||||
{
|
||||
if ( patArr[i] == '*' )
|
||||
{
|
||||
containsStar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !containsStar )
|
||||
{
|
||||
// No '*'s, so we make a shortcut
|
||||
if ( patIdxEnd != strIdxEnd )
|
||||
{
|
||||
return false; // Pattern and string do not have the same size
|
||||
}
|
||||
for ( int i = 0; i <= patIdxEnd; i++ )
|
||||
{
|
||||
ch = patArr[i];
|
||||
if ( ch != '?' )
|
||||
{
|
||||
if ( isCaseSensitive && ch != strArr[i] )
|
||||
{
|
||||
return false;// Character mismatch
|
||||
}
|
||||
if ( !isCaseSensitive && Character.toUpperCase( ch ) !=
|
||||
Character.toUpperCase( strArr[i] ) )
|
||||
{
|
||||
return false; // Character mismatch
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // String matches against pattern
|
||||
}
|
||||
|
||||
if ( patIdxEnd == 0 )
|
||||
{
|
||||
return true; // Pattern contains only '*', which matches anything
|
||||
}
|
||||
|
||||
// Process characters before first star
|
||||
while ( ( ch = patArr[patIdxStart] ) != '*' && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
if ( ch != '?' )
|
||||
{
|
||||
if ( isCaseSensitive && ch != strArr[strIdxStart] )
|
||||
{
|
||||
return false;// Character mismatch
|
||||
}
|
||||
if ( !isCaseSensitive && Character.toUpperCase( ch ) !=
|
||||
Character.toUpperCase( strArr[strIdxStart] ) )
|
||||
{
|
||||
return false;// Character mismatch
|
||||
}
|
||||
}
|
||||
patIdxStart++;
|
||||
strIdxStart++;
|
||||
}
|
||||
if ( strIdxStart > strIdxEnd )
|
||||
{
|
||||
// All characters in the string are used. Check if only '*'s are
|
||||
// left in the pattern. If so, we succeeded. Otherwise failure.
|
||||
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( patArr[i] != '*' )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Process characters after last star
|
||||
while ( ( ch = patArr[patIdxEnd] ) != '*' && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
if ( ch != '?' )
|
||||
{
|
||||
if ( isCaseSensitive && ch != strArr[strIdxEnd] )
|
||||
{
|
||||
return false;// Character mismatch
|
||||
}
|
||||
if ( !isCaseSensitive && Character.toUpperCase( ch ) !=
|
||||
Character.toUpperCase( strArr[strIdxEnd] ) )
|
||||
{
|
||||
return false;// Character mismatch
|
||||
}
|
||||
}
|
||||
patIdxEnd--;
|
||||
strIdxEnd--;
|
||||
}
|
||||
if ( strIdxStart > strIdxEnd )
|
||||
{
|
||||
// All characters in the string are used. Check if only '*'s are
|
||||
// left in the pattern. If so, we succeeded. Otherwise failure.
|
||||
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( patArr[i] != '*' )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// process pattern between stars. padIdxStart and patIdxEnd point
|
||||
// always to a '*'.
|
||||
while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd )
|
||||
{
|
||||
int patIdxTmp = -1;
|
||||
for ( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( patArr[i] == '*' )
|
||||
{
|
||||
patIdxTmp = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( patIdxTmp == patIdxStart + 1 )
|
||||
{
|
||||
// Two stars next to each other, skip the first one.
|
||||
patIdxStart++;
|
||||
continue;
|
||||
}
|
||||
// Find the pattern between padIdxStart & padIdxTmp in str between
|
||||
// strIdxStart & strIdxEnd
|
||||
int patLength = ( patIdxTmp - patIdxStart - 1 );
|
||||
int strLength = ( strIdxEnd - strIdxStart + 1 );
|
||||
int foundIdx = -1;
|
||||
strLoop:
|
||||
for ( int i = 0; i <= strLength - patLength; i++ )
|
||||
{
|
||||
for ( int j = 0; j < patLength; j++ )
|
||||
{
|
||||
ch = patArr[patIdxStart + j + 1];
|
||||
if ( ch != '?' )
|
||||
{
|
||||
if ( isCaseSensitive && ch != strArr[strIdxStart + i + j] )
|
||||
{
|
||||
continue strLoop;
|
||||
}
|
||||
if ( !isCaseSensitive && Character.toUpperCase( ch ) !=
|
||||
Character.toUpperCase( strArr[strIdxStart + i + j] ) )
|
||||
{
|
||||
continue strLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foundIdx = strIdxStart + i;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( foundIdx == -1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
patIdxStart = patIdxTmp;
|
||||
strIdxStart = foundIdx + patLength;
|
||||
}
|
||||
|
||||
// All characters in the string are used. Check if only '*'s are left
|
||||
// in the pattern. If so, we succeeded. Otherwise failure.
|
||||
for ( int i = patIdxStart; i <= patIdxEnd; i++ )
|
||||
{
|
||||
if ( patArr[i] != '*' )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Breaks a path up into a Vector of path elements, tokenizing on
|
||||
* <code>File.separator</code>.
|
||||
*
|
||||
* @param path Path to tokenize. Must not be <code>null</code>.
|
||||
* @return a Vector of path elements from the tokenized path
|
||||
*/
|
||||
public static Vector tokenizePath( String path )
|
||||
{
|
||||
Vector ret = new Vector();
|
||||
StringTokenizer st = new StringTokenizer( path, File.separator );
|
||||
while ( st.hasMoreTokens() )
|
||||
{
|
||||
ret.addElement( st.nextToken() );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns dependency information on these two files. If src has been
|
||||
* modified later than target, it returns true. If target doesn't exist,
|
||||
* it likewise returns true. Otherwise, target is newer than src and
|
||||
* is not out of date, thus the method returns false. It also returns
|
||||
* false if the src file doesn't even exist, since how could the
|
||||
* target then be out of date.
|
||||
*
|
||||
* @param src the original file
|
||||
* @param target the file being compared against
|
||||
* @param granularity the amount in seconds of slack we will give in
|
||||
* determining out of dateness
|
||||
* @return whether the target is out of date
|
||||
*/
|
||||
public static boolean isOutOfDate( File src, File target, int granularity )
|
||||
{
|
||||
if ( !src.exists() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !target.exists() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( ( src.lastModified() - granularity ) > target.lastModified() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* "Flattens" a string by removing all whitespace (space, tab, linefeed,
|
||||
* carriage return, and formfeed). This uses StringTokenizer and the
|
||||
* default set of tokens as documented in the single arguement constructor.
|
||||
*
|
||||
* @param input a String to remove all whitespace.
|
||||
* @return a String that has had all whitespace removed.
|
||||
*/
|
||||
public static String removeWhitespace( String input )
|
||||
{
|
||||
StringBuffer result = new StringBuffer();
|
||||
if ( input != null )
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer( input );
|
||||
while ( st.hasMoreTokens() )
|
||||
{
|
||||
result.append( st.nextToken() );
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
@ -1,232 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Brett Porter
|
||||
*/
|
||||
public class SimpleArgumentParser
|
||||
{
|
||||
private Map arguments = new TreeMap();
|
||||
|
||||
private List parameters = new ArrayList();
|
||||
|
||||
public void parseCommandLineArguments( String[] args )
|
||||
{
|
||||
boolean stillHasArgs = true;
|
||||
for ( int i = 0; i < args.length; i++ )
|
||||
{
|
||||
if ( args[i].equals( "--" ) )
|
||||
{
|
||||
stillHasArgs = false;
|
||||
}
|
||||
else if ( args[i].startsWith( "-" ) && stillHasArgs )
|
||||
{
|
||||
if ( args[i].startsWith( "--" ) )
|
||||
{
|
||||
String name;
|
||||
int index = args[i].indexOf( '=' );
|
||||
if ( index >= 0 )
|
||||
{
|
||||
name = args[i].substring( 0, index ).trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
name = args[i];
|
||||
}
|
||||
|
||||
Argument arg = (Argument) arguments.get( name );
|
||||
if ( arg != null )
|
||||
{
|
||||
if ( arg.isHasValue() )
|
||||
{
|
||||
String value = null;
|
||||
if ( index >= 0 )
|
||||
{
|
||||
value = args[i].substring( index + 1 ).trim();
|
||||
}
|
||||
else if ( i != args.length - 1 && !args[i + 1].startsWith( "-" ) )
|
||||
{
|
||||
value = args[i + 1];
|
||||
i++;
|
||||
}
|
||||
|
||||
arg.setValue( value );
|
||||
}
|
||||
arg.setSet( true );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String name = args[i].substring( 0, 2 );
|
||||
|
||||
Argument arg = (Argument) arguments.get( name );
|
||||
if ( arg != null )
|
||||
{
|
||||
if ( arg.isHasValue() )
|
||||
{
|
||||
String value = null;
|
||||
if ( args[i].length() > 2 )
|
||||
{
|
||||
value = args[i].substring( 2 );
|
||||
}
|
||||
else if ( i != args.length - 1 && !args[i + 1].startsWith( "-" ) )
|
||||
{
|
||||
value = args[i + 1];
|
||||
i++;
|
||||
}
|
||||
|
||||
arg.setValue( value );
|
||||
}
|
||||
arg.setSet( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters.add( args[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getArgumentValue( String argument )
|
||||
{
|
||||
Argument arg = (Argument) arguments.get( argument );
|
||||
String value = null;
|
||||
if ( arg != null )
|
||||
{
|
||||
value = arg.getValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public List getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void addArgument( String argument, String description, String alias )
|
||||
{
|
||||
addArgument( argument, description, alias, false, null );
|
||||
}
|
||||
|
||||
public void addArgument( String argument, String description, String alias, boolean hasValue, String defaultValue )
|
||||
{
|
||||
Argument arg = new Argument( argument, description, alias, hasValue, defaultValue );
|
||||
arguments.put( argument, arg );
|
||||
if ( alias != null )
|
||||
{
|
||||
arguments.put( alias, arg );
|
||||
}
|
||||
}
|
||||
|
||||
public void addArgument( String argument, String description, boolean hasValue, String defaultValue )
|
||||
{
|
||||
addArgument( argument, description, null, hasValue, defaultValue );
|
||||
}
|
||||
|
||||
public void addArgument( String argument, String description )
|
||||
{
|
||||
addArgument( argument, description, null );
|
||||
}
|
||||
|
||||
public void addArgument( String argument, String description, boolean hasValue )
|
||||
{
|
||||
addArgument( argument, description, hasValue, null );
|
||||
}
|
||||
|
||||
public boolean isArgumentSet( String argument )
|
||||
{
|
||||
Argument arg = (Argument) arguments.get( argument );
|
||||
return arg.isSet();
|
||||
}
|
||||
|
||||
private static class Argument
|
||||
{
|
||||
private final String name;
|
||||
|
||||
private final String description;
|
||||
|
||||
private final String alias;
|
||||
|
||||
private String value;
|
||||
|
||||
private final boolean hasValue;
|
||||
|
||||
private final String defaultValue;
|
||||
|
||||
private boolean set;
|
||||
|
||||
public Argument( String name, String description, String alias, boolean hasValue, String defaultValue )
|
||||
{
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.alias = alias;
|
||||
this.hasValue = hasValue;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getAlias()
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
if ( value == null )
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue( String value )
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isHasValue()
|
||||
{
|
||||
return hasValue;
|
||||
}
|
||||
|
||||
public boolean isSet()
|
||||
{
|
||||
return set;
|
||||
}
|
||||
|
||||
public void setSet( boolean set )
|
||||
{
|
||||
this.set = set;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
package org.apache.maven.bootstrap.util;
|
||||
|
||||
/*
|
||||
* 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 java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class StringUtils
|
||||
{
|
||||
public static String[] split( String str )
|
||||
{
|
||||
return split( str, null, -1 );
|
||||
}
|
||||
|
||||
public static String[] split( String text, String separator )
|
||||
{
|
||||
return split( text, separator, -1 );
|
||||
}
|
||||
|
||||
public static String[] split( String str, String separator, int max )
|
||||
{
|
||||
StringTokenizer tok = null;
|
||||
if ( separator == null )
|
||||
{
|
||||
// Null separator means we're using StringTokenizer's default
|
||||
// delimiter, which comprises all whitespace characters.
|
||||
tok = new StringTokenizer( str );
|
||||
}
|
||||
else
|
||||
{
|
||||
tok = new StringTokenizer( str, separator );
|
||||
}
|
||||
|
||||
int listSize = tok.countTokens();
|
||||
if ( max > 0 && listSize > max )
|
||||
{
|
||||
listSize = max;
|
||||
}
|
||||
|
||||
String[] list = new String[listSize];
|
||||
int i = 0;
|
||||
int lastTokenBegin = 0;
|
||||
int lastTokenEnd = 0;
|
||||
while ( tok.hasMoreTokens() )
|
||||
{
|
||||
if ( max > 0 && i == listSize - 1 )
|
||||
{
|
||||
// In the situation where we hit the max yet have
|
||||
// tokens left over in our input, the last list
|
||||
// element gets all remaining text.
|
||||
String endToken = tok.nextToken();
|
||||
lastTokenBegin = str.indexOf( endToken, lastTokenEnd );
|
||||
list[i] = str.substring( lastTokenBegin );
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
list[i] = tok.nextToken();
|
||||
lastTokenBegin = str.indexOf( list[i], lastTokenEnd );
|
||||
lastTokenEnd = lastTokenBegin + list[i].length();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String replaceOnce( String text, String repl, String with )
|
||||
{
|
||||
return replace( text, repl, with, 1 );
|
||||
}
|
||||
|
||||
public static String replace( String text, String repl, String with )
|
||||
{
|
||||
return replace( text, repl, with, -1 );
|
||||
}
|
||||
|
||||
public static String replace( String text, String repl, String with, int max )
|
||||
{
|
||||
if ( text == null || repl == null || with == null || repl.length() == 0 )
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
StringBuffer buf = new StringBuffer( text.length() );
|
||||
int start = 0, end = 0;
|
||||
while ( ( end = text.indexOf( repl, start ) ) != -1 )
|
||||
{
|
||||
buf.append( text.substring( start, end ) ).append( with );
|
||||
start = end + repl.length();
|
||||
|
||||
if ( --max == 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf.append( text.substring( start ) );
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String interpolate( String text, Map namespace )
|
||||
{
|
||||
Iterator keys = namespace.keySet().iterator();
|
||||
|
||||
while ( keys.hasNext() )
|
||||
{
|
||||
String key = keys.next().toString();
|
||||
|
||||
Object obj = namespace.get( key );
|
||||
|
||||
String value = obj.toString();
|
||||
|
||||
text = StringUtils.replace( text, "${" + key + "}", value );
|
||||
|
||||
if ( key.indexOf( " " ) == -1 )
|
||||
{
|
||||
text = StringUtils.replace( text, "$" + key, value );
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: org.apache.maven.bootstrap.Bootstrap
|
Loading…
x
Reference in New Issue
Block a user