o adding a way to set the local repository in the configuration

o adding a configuration validator so that clients can tell what state the settings are in before firing up the embedder


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@512540 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-02-28 01:11:43 +00:00
parent f4b3eedc8a
commit 513e42d79d
4 changed files with 425 additions and 0 deletions

View File

@ -0,0 +1,123 @@
package org.apache.maven.embedder.configuration;
/*
* 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.embedder.ContainerCustomizer;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.codehaus.plexus.classworlds.ClassWorld;
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.Properties;
/**
* Configuration of embedder, used when starting up.
*
* @author mkleint
* @author Jason van Zyl
*/
public interface Configuration
{
// ----------------------------------------------------------------------------
// Settings
// ----------------------------------------------------------------------------
/** Set location of the userSettingsFile settings file to use for the embedder. */
Configuration setUserSettingsFile( File userSettingsFile );
File getUserSettingsFile();
/** Set location of the globalSettingsFiles settings file to use for the embedder. */
Configuration setGlobalSettingsFile( File globalSettingsFiles );
File getGlobalSettingsFile();
// ----------------------------------------------------------------------------
// Local Repository
// ----------------------------------------------------------------------------
/**
* This overrides anything set in a settings file.
*/
Configuration setLocalRepository( File localRepository );
File getLocalRepository();
// ----------------------------------------------------------------------------
// Logger
// ----------------------------------------------------------------------------
Configuration setMavenEmbedderLogger( MavenEmbedderLogger logger );
MavenEmbedderLogger getMavenEmbedderLogger();
// ----------------------------------------------------------------------------
// ClassWorld/ClassLoader
// ----------------------------------------------------------------------------
ClassWorld getClassWorld();
Configuration setClassWorld( ClassWorld classWorld );
Configuration setClassLoader( ClassLoader loader );
// ----------------------------------------------------------------------------
// Profiles
// ----------------------------------------------------------------------------
/** Add profile to activate. */
Configuration addActiveProfile( String profile );
/** Add profile to inactivate. */
Configuration addInactiveProfile( String profile );
/** Add a list of String instances with names of profiles to activate. */
Configuration addActiveProfiles( List profiles );
/** Add a list of String instances with names of profiles to inactivate. */
Configuration addInactiveProfiles( List profiles );
/** Set a customizer callback implemetation that will be given a chance to modify the plexus container on startup. */
Configuration setConfigurationCustomizer( ContainerCustomizer customizer );
/** set the system properties to be used during the lifecycle of the embedder. Excluding the time when executing the project, then the properties from MavenExecutionRequestare used. */
Configuration setSystemProperties( Properties properties );
List getActiveProfiles();
List getInactiveProfiles();
// ----------------------------------------------------------------------------
// Container Customizer
// ----------------------------------------------------------------------------
ContainerCustomizer getContainerCustomizer();
// ----------------------------------------------------------------------------
// System Properties
// ----------------------------------------------------------------------------
Properties getSystemProperties();
// ----------------------------------------------------------------------------
// Extensions
// ----------------------------------------------------------------------------
void addExtension( URL url );
List getExtensions();
}

View File

@ -0,0 +1,25 @@
package org.apache.maven.embedder.configuration;
/** @author Jason van Zyl */
public interface ConfigurationValidationResult
{
boolean isValid();
boolean isUserSettingsFilePresent();
void setUserSettingsFilePresent( boolean userSettingsFilePresent );
boolean isUserSettingsFileParses();
void setUserSettingsFileParses( boolean userSettingsFileParses );
boolean isGlobalSettingsFilePresent();
void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent );
boolean isGlobalSettingsFileParses();
void setGlobalSettingsFileParses( boolean globalSettingsFileParses );
void display();
}

View File

@ -0,0 +1,209 @@
package org.apache.maven.embedder.configuration;
/*
* 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.embedder.ContainerCustomizer;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.classworlds.ClassWorld;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* Default implementation of Configuration intefrace.
*
* @author mkleint
*/
public class DefaultConfiguration
implements Configuration
{
private List inactives;
private List actives;
private File userSettings;
private File globalSettings;
private ContainerCustomizer customizer;
private Properties systemProperties;
/** List<URL>. */
private List extensions = new ArrayList();
private MavenEmbedderLogger logger;
private ClassWorld classWorld;
private File localRepository;
/** Creates a new instance of DefaultConfiguration */
public DefaultConfiguration()
{
}
public Configuration addActiveProfile( String profile )
{
getActiveProfiles().add( profile );
return this;
}
public Configuration addInactiveProfile( String profile )
{
getInactiveProfiles().add( profile );
return this;
}
public Configuration addActiveProfiles( List profiles )
{
getActiveProfiles().addAll( profiles );
return this;
}
public Configuration addInactiveProfiles( List profiles )
{
getInactiveProfiles().addAll( profiles );
return this;
}
public List getActiveProfiles()
{
if ( actives == null )
{
actives = new ArrayList();
}
return actives;
}
public List getInactiveProfiles()
{
if ( inactives == null )
{
inactives = new ArrayList();
}
return inactives;
}
public Configuration setUserSettingsFile( File user )
{
userSettings = user;
return this;
}
public Configuration setGlobalSettingsFile( File global )
{
globalSettings = global;
return this;
}
public File getUserSettingsFile()
{
return userSettings;
}
public File getGlobalSettingsFile()
{
return globalSettings;
}
public Configuration setConfigurationCustomizer( ContainerCustomizer customizer )
{
this.customizer = customizer;
return this;
}
public ContainerCustomizer getContainerCustomizer()
{
return customizer;
}
public Configuration setSystemProperties( Properties properties )
{
systemProperties = properties;
return this;
}
public Properties getSystemProperties()
{
return systemProperties != null ? systemProperties : System.getProperties();
}
public void addExtension( URL url )
{
extensions.add( url );
}
public List getExtensions()
{
return extensions;
}
public Configuration setMavenEmbedderLogger( MavenEmbedderLogger logger )
{
this.logger = logger;
return this;
}
public MavenEmbedderLogger getMavenEmbedderLogger()
{
return logger;
}
public ClassWorld getClassWorld()
{
return classWorld;
}
public Configuration setClassWorld( ClassWorld classWorld )
{
this.classWorld = classWorld;
return this;
}
public Configuration setClassLoader( ClassLoader loader )
{
this.classWorld = new ClassWorld( "plexus.core", loader );
return this;
}
// ----------------------------------------------------------------------------
// Local Repository
// ----------------------------------------------------------------------------
public Configuration setLocalRepository( File localRepository )
{
this.localRepository = localRepository;
return this;
}
public File getLocalRepository()
{
return localRepository;
}
}

View File

@ -0,0 +1,68 @@
package org.apache.maven.embedder.configuration;
/** @author Jason van Zyl */
public class DefaultConfigurationValidationResult
implements ConfigurationValidationResult
{
private boolean userSettingsFilePresent = true;
private boolean userSettingsFileParses = true;
private boolean globalSettingsFilePresent = true;
private boolean globalSettingsFileParses = true;
public boolean isValid()
{
return userSettingsFilePresent && userSettingsFileParses && globalSettingsFilePresent &&
globalSettingsFileParses;
}
public boolean isUserSettingsFilePresent()
{
return userSettingsFilePresent;
}
public void setUserSettingsFilePresent( boolean userSettingsFilePresent )
{
this.userSettingsFilePresent = userSettingsFilePresent;
}
public boolean isUserSettingsFileParses()
{
return userSettingsFileParses;
}
public void setUserSettingsFileParses( boolean userSettingsFileParses )
{
this.userSettingsFileParses = userSettingsFileParses;
}
public boolean isGlobalSettingsFilePresent()
{
return globalSettingsFilePresent;
}
public void setGlobalSettingsFilePresent( boolean globalSettingsFilePresent )
{
this.globalSettingsFilePresent = globalSettingsFilePresent;
}
public boolean isGlobalSettingsFileParses()
{
return globalSettingsFileParses;
}
public void setGlobalSettingsFileParses( boolean globalSettingsFileParses )
{
this.globalSettingsFileParses = globalSettingsFileParses;
}
public void display()
{
System.out.println( "userSettingsFilePresent = " + userSettingsFilePresent );
System.out.println( "globalSettingsFileParses = " + globalSettingsFileParses );
System.out.println( "globalSettingsFilePresent = " + globalSettingsFilePresent );
System.out.println( "globalSettingsFileParses = " + globalSettingsFileParses );
}
}