You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2007/02/28 02:29:02 UTC
svn commit: r512550 - in /maven/components/trunk/maven-tools/src:
main/java/org/apache/maven/DefaultMavenTools.java
main/java/org/apache/maven/MavenTools.java
main/resources/META-INF/plexus/components.xml test/
Author: jvanzyl
Date: Tue Feb 27 17:29:02 2007
New Revision: 512550
URL: http://svn.apache.org/viewvc?view=rev&rev=512550
Log:
o got rid of all the settings related code and use the settings builder directly and push the responsibility of
dealing with settings semantics to the client code
Removed:
maven/components/trunk/maven-tools/src/test/
Modified:
maven/components/trunk/maven-tools/src/main/java/org/apache/maven/DefaultMavenTools.java
maven/components/trunk/maven-tools/src/main/java/org/apache/maven/MavenTools.java
maven/components/trunk/maven-tools/src/main/resources/META-INF/plexus/components.xml
Modified: maven/components/trunk/maven-tools/src/main/java/org/apache/maven/DefaultMavenTools.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-tools/src/main/java/org/apache/maven/DefaultMavenTools.java?view=diff&rev=512550&r1=512549&r2=512550
==============================================================================
--- maven/components/trunk/maven-tools/src/main/java/org/apache/maven/DefaultMavenTools.java (original)
+++ maven/components/trunk/maven-tools/src/main/java/org/apache/maven/DefaultMavenTools.java Tue Feb 27 17:29:02 2007
@@ -11,9 +11,7 @@
import org.apache.maven.model.RepositoryBase;
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.settings.MavenSettingsBuilder;
-import org.apache.maven.settings.RuntimeInfo;
import org.apache.maven.settings.Settings;
-import org.apache.maven.settings.SettingsBuilderAdvice;
import org.apache.maven.settings.io.jdom.SettingsJDOMWriter;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.apache.maven.settings.validation.SettingsValidationResult;
@@ -37,33 +35,20 @@
import java.util.Iterator;
import java.util.List;
-/**
- * @author Jason van Zyl
- */
+/** @author Jason van Zyl */
public class DefaultMavenTools
- implements MavenTools,
- Contextualizable
+ implements MavenTools, Contextualizable
{
private ArtifactRepositoryLayout repositoryLayout;
private ArtifactRepositoryFactory artifactRepositoryFactory;
- private MavenSettingsBuilder settingsBuilder;
-
- private SettingsValidator settingsValidator;
-
private PlexusContainer container;
// ----------------------------------------------------------------------------
// ArtifactRepository
// ----------------------------------------------------------------------------
- public ArtifactRepository createDefaultLocalRepository()
- throws SettingsConfigurationException
- {
- return createLocalRepository( new File( getLocalRepositoryPath() ) );
- }
-
public ArtifactRepository createLocalRepository( File directory )
{
String localRepositoryUrl = directory.getAbsolutePath();
@@ -73,11 +58,11 @@
localRepositoryUrl = "file://" + localRepositoryUrl;
}
- return createRepository( "local", localRepositoryUrl);
+ return createRepository( "local", localRepositoryUrl );
}
private ArtifactRepository createRepository( String repositoryId,
- String repositoryUrl)
+ String repositoryUrl )
{
ArtifactRepository localRepository =
new DefaultArtifactRepository( repositoryId, repositoryUrl, repositoryLayout );
@@ -85,89 +70,6 @@
}
// ----------------------------------------------------------------------------
- // Settings
- // ----------------------------------------------------------------------------
-
- public Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean interactive,
- boolean offline,
- boolean usePluginRegistry,
- boolean pluginUpdateOverride )
- throws SettingsConfigurationException
- {
- return buildSettings( userSettingsPath, globalSettingsPath, interactive, offline, usePluginRegistry,
- pluginUpdateOverride, new SettingsBuilderAdvice() );
- }
-
- public Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean interactive,
- boolean offline,
- boolean usePluginRegistry,
- boolean pluginUpdateOverride,
- SettingsBuilderAdvice advice )
- throws SettingsConfigurationException
- {
- Settings settings = buildSettings( userSettingsPath, globalSettingsPath, pluginUpdateOverride, advice );
-
- if ( offline )
- {
- settings.setOffline( true );
- }
-
- settings.setInteractiveMode( interactive );
-
- settings.setUsePluginRegistry( usePluginRegistry );
-
- return settings;
- }
-
- public Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean pluginUpdateOverride )
- throws SettingsConfigurationException
- {
- return buildSettings( userSettingsPath, globalSettingsPath, pluginUpdateOverride, new SettingsBuilderAdvice() );
- }
-
- public Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean pluginUpdateOverride,
- SettingsBuilderAdvice advice )
- throws SettingsConfigurationException
- {
- Settings settings;
-
- if ( advice == null )
- {
- advice = new SettingsBuilderAdvice();
- }
-
- try
- {
- settings = settingsBuilder.buildSettings( userSettingsPath, globalSettingsPath, advice );
- }
- catch ( IOException e )
- {
- throw new SettingsConfigurationException( "Error reading settings file", e );
- }
- catch ( XmlPullParserException e )
- {
- throw new SettingsConfigurationException( e.getMessage(), e.getDetail(), e.getLineNumber(),
- e.getColumnNumber() );
- }
-
- RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
-
- runtimeInfo.setPluginUpdateOverride( Boolean.valueOf( pluginUpdateOverride ) );
-
- settings.setRuntimeInfo( runtimeInfo );
-
- return settings;
- }
-
- // ----------------------------------------------------------------------------
// Code snagged from ProjectUtils: this will have to be moved somewhere else
// but just trying to collect it all in one place right now.
// ----------------------------------------------------------------------------
@@ -237,12 +139,15 @@
public ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy policy )
{
boolean enabled = true;
+
String updatePolicy = null;
+
String checksumPolicy = null;
if ( policy != null )
{
enabled = policy.isEnabled();
+
if ( policy.getUpdatePolicy() != null )
{
updatePolicy = policy.getUpdatePolicy();
@@ -275,105 +180,6 @@
}
// ----------------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------------
-
- /**
- * Retrieve the user settings path using the followiwin search pattern:
- * <p/>
- * 1. System Property
- * 2. Optional path
- * 3. ${user.home}/.m2/settings.xml
- */
- public File getUserSettingsPath( String optionalSettingsPath )
- {
- File userSettingsPath = new File( System.getProperty( ALT_USER_SETTINGS_XML_LOCATION ) + "" );
-
- if ( !userSettingsPath.exists() )
- {
- if ( optionalSettingsPath != null )
- {
- File optionalSettingsPathFile = new File( optionalSettingsPath );
-
- if ( optionalSettingsPathFile.exists() )
- {
- userSettingsPath = optionalSettingsPathFile;
- }
- else
- {
- userSettingsPath = defaultUserSettingsFile;
- }
- }
- else
- {
- userSettingsPath = defaultUserSettingsFile;
- }
- }
-
- return userSettingsPath;
- }
-
- /**
- * Retrieve the global settings path using the followiwin search pattern:
- * <p/>
- * 1. System Property
- * 2. CLI Option
- * 3. ${maven.home}/conf/settings.xml
- */
- public File getGlobalSettingsPath()
- {
- File globalSettingsFile = new File( System.getProperty( ALT_GLOBAL_SETTINGS_XML_LOCATION ) + "" );
-
- if ( !globalSettingsFile.exists() )
- {
- globalSettingsFile = defaultGlobalSettingsFile;
- }
-
- return globalSettingsFile;
- }
-
- /**
- * Retrieve the local repository path using the followiwin search pattern:
- * <p/>
- * 1. System Property
- * 2. localRepository specified in user settings file
- * 3. ${user.home}/.m2/repository
- */
- public String getLocalRepositoryPath( Settings settings )
- {
- String localRepositoryPath = System.getProperty( ALT_LOCAL_REPOSITORY_LOCATION );
-
- if ( localRepositoryPath == null )
- {
- localRepositoryPath = settings.getLocalRepository();
- }
-
- if ( localRepositoryPath == null )
- {
- localRepositoryPath = defaultUserLocalRepository.getAbsolutePath();
- }
-
- return localRepositoryPath;
- }
-
- public String getLocalRepositoryPath()
- throws SettingsConfigurationException
- {
- return getLocalRepositoryPath( buildSettings( getUserSettingsPath( null ),
- getGlobalSettingsPath(),
- false,
- true,
- false,
- false ) );
- }
-
- public ArtifactRepository getLocalRepository()
- throws SettingsConfigurationException
- {
- return createLocalRepository( new File( getLocalRepositoryPath() ) );
- }
-
- // ----------------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------------
@@ -382,51 +188,4 @@
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
-
- public void writeSettings( Settings settings, Writer w )
- throws IOException
- {
- SettingsValidationResult validationResult = settingsValidator.validate( settings );
-
- if ( validationResult.getMessageCount() > 0 )
- {
- throw new IOException( "Failed to validate Settings.\n" + validationResult.render("\n") );
- }
-
- Element root = new Element( "settings" );
-
- Document doc = new Document( root );
-
- SettingsJDOMWriter writer = new SettingsJDOMWriter();
-
- String encoding = settings.getModelEncoding() != null ? settings.getModelEncoding() : "UTF-8";
-
- Format format = Format.getPrettyFormat().setEncoding( encoding );
-
- writer.write( settings, doc, w, format );
- }
-
- public Settings readSettings( Reader r )
- throws IOException, SettingsConfigurationException
- {
- SettingsXpp3Reader reader = new SettingsXpp3Reader();
- try
- {
- Settings settings = reader.read( r );
-
- SettingsValidationResult validationResult = settingsValidator.validate( settings );
-
- if ( validationResult.getMessageCount() > 0 )
- {
- throw new IOException( "Failed to validate Settings.\n" + validationResult.render("\n") );
- }
-
- return settings;
- }
- catch ( XmlPullParserException e )
- {
- throw new SettingsConfigurationException( "Failed to parse settings.", e );
- }
- }
-
}
Modified: maven/components/trunk/maven-tools/src/main/java/org/apache/maven/MavenTools.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-tools/src/main/java/org/apache/maven/MavenTools.java?view=diff&rev=512550&r1=512549&r2=512550
==============================================================================
--- maven/components/trunk/maven-tools/src/main/java/org/apache/maven/MavenTools.java (original)
+++ maven/components/trunk/maven-tools/src/main/java/org/apache/maven/MavenTools.java Tue Feb 27 17:29:02 2007
@@ -4,9 +4,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.Repository;
-import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Settings;
-import org.apache.maven.settings.SettingsBuilderAdvice;
import java.io.File;
import java.io.IOException;
@@ -21,82 +19,6 @@
{
String ROLE = MavenTools.class.getName();
- String userHome = System.getProperty( "user.home" );
-
- File userMavenConfigurationHome = new File( userHome, ".m2" );
-
- String mavenHome = System.getProperty( "maven.home" );
-
- // ----------------------------------------------------------------------
- // Settings
- // ----------------------------------------------------------------------
-
- File defaultUserSettingsFile = MavenSettingsBuilder.DEFAULT_USER_SETTINGS_FILE;
-
- File defaultGlobalSettingsFile = MavenSettingsBuilder.DEFAULT_GLOBAL_SETTINGS_FILE;
-
- String ALT_USER_SETTINGS_XML_LOCATION = "org.apache.maven.user-settings";
-
- String ALT_GLOBAL_SETTINGS_XML_LOCATION = "org.apache.maven.global-settings";
-
- // ----------------------------------------------------------------------
- // Local Repository
- // ----------------------------------------------------------------------
-
- String ALT_LOCAL_REPOSITORY_LOCATION = "maven.repo.local";
-
- File defaultUserLocalRepository = new File( userMavenConfigurationHome, "repository" );
-
- // ----------------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------------
-
- ArtifactRepository createDefaultLocalRepository()
- throws SettingsConfigurationException;
-
- ArtifactRepository createLocalRepository( File localRepositoryPath );
-
- Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean interactive,
- boolean offline,
- boolean usePluginRegistry,
- boolean pluginUpdateOverride,
- SettingsBuilderAdvice advice )
- throws SettingsConfigurationException;
-
- Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean interactive,
- boolean offline,
- boolean usePluginRegistry,
- boolean pluginUpdateOverride )
- throws SettingsConfigurationException;
-
- Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean pluginUpdateOverride,
- SettingsBuilderAdvice advice )
- throws SettingsConfigurationException;
-
- Settings buildSettings( File userSettingsPath,
- File globalSettingsPath,
- boolean pluginUpdateOverride )
- throws SettingsConfigurationException;
-
- // ----------------------------------------------------------------------------
- // Methods taken from CLI
- // ----------------------------------------------------------------------------
-
- File getUserSettingsPath( String optionalSettingsPath );
-
- File getGlobalSettingsPath();
-
- String getLocalRepositoryPath( Settings settings );
-
- String getLocalRepositoryPath()
- throws SettingsConfigurationException;
-
// ----------------------------------------------------------------------------
// Methods taken from ProjectUtils
// ----------------------------------------------------------------------------
@@ -109,11 +31,4 @@
ArtifactRepository buildArtifactRepository( Repository repo )
throws InvalidRepositoryException;
-
- void writeSettings( Settings settings, Writer writer )
- throws IOException;
-
- Settings readSettings( Reader reader )
- throws IOException, SettingsConfigurationException;
-
}
Modified: maven/components/trunk/maven-tools/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-tools/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=512550&r1=512549&r2=512550
==============================================================================
--- maven/components/trunk/maven-tools/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/trunk/maven-tools/src/main/resources/META-INF/plexus/components.xml Tue Feb 27 17:29:02 2007
@@ -11,12 +11,6 @@
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
- <requirement>
- <role>org.apache.maven.settings.MavenSettingsBuilder</role>
- </requirement>
- <requirement>
- <role>org.apache.maven.settings.validation.SettingsValidator</role>
- </requirement>
</requirements>
</component>
</components>