mirror of https://github.com/apache/maven.git
MNG-1937, MNG-1665
allow custom configuration of embedder. correct settings location handling for embedder's project reading methods git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@395691 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f698d0acf
commit
0e548f6fc1
|
@ -0,0 +1,31 @@
|
|||
package org.apache.maven.embedder;
|
||||
/*
|
||||
* 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.codehaus.plexus.PlexusContainer;
|
||||
|
||||
/**
|
||||
* Instances of this interface can be user upon start of the embedder to customize
|
||||
* the components in the plexus container.
|
||||
* @author mkleint
|
||||
*/
|
||||
public interface ContainerCustomizer {
|
||||
/**
|
||||
* callback from embedder's start() method that allows to customize the components
|
||||
* in the container.
|
||||
*/
|
||||
void customize(PlexusContainer container);
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package org.apache.maven.embedder;
|
||||
/*
|
||||
* 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.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.maven.settings.Settings;
|
||||
|
||||
/**
|
||||
* Default implementation of MavenEmbedRequest intefrace.
|
||||
* @author mkleint
|
||||
*/
|
||||
public class DefaultMavenEmbedRequest implements MavenEmbedRequest {
|
||||
|
||||
private List inactives;
|
||||
|
||||
private List actives;
|
||||
|
||||
private Settings settings;
|
||||
|
||||
private File userSettings;
|
||||
|
||||
private File globalSettings;
|
||||
|
||||
private ContainerCustomizer customizer;
|
||||
|
||||
/** Creates a new instance of DefaultMavenEmbedRequest */
|
||||
public DefaultMavenEmbedRequest() {
|
||||
}
|
||||
|
||||
public MavenEmbedRequest addActiveProfile(String profile) {
|
||||
getActiveProfiles().add(profile);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenEmbedRequest addInactiveProfile(String profile) {
|
||||
getInactiveProfiles().add(profile);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenEmbedRequest addActiveProfiles(List profiles) {
|
||||
getActiveProfiles().addAll(profiles);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenEmbedRequest 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 MavenEmbedRequest setUserSettingsFile(File user) {
|
||||
userSettings = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenEmbedRequest setGlobalSettingsFile(File global) {
|
||||
globalSettings = global;
|
||||
return this;
|
||||
}
|
||||
|
||||
public File getUserSettingsFile() {
|
||||
return userSettings;
|
||||
}
|
||||
|
||||
public File getGlobalSettingsFile() {
|
||||
return globalSettings;
|
||||
}
|
||||
|
||||
public MavenEmbedRequest setConfigurationCustomizer(ContainerCustomizer customizer) {
|
||||
this.customizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContainerCustomizer getContainerCustomizer() {
|
||||
return customizer;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package org.apache.maven.embedder;
|
||||
/*
|
||||
* 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.net.URL;
|
||||
import java.util.List;
|
||||
import org.apache.maven.settings.Settings;
|
||||
|
||||
/**
|
||||
* Configuration of embedder, used when starting up.
|
||||
* @author mkleint
|
||||
*/
|
||||
public interface MavenEmbedRequest {
|
||||
|
||||
/*
|
||||
* Add profile to activate.
|
||||
*/
|
||||
MavenEmbedRequest addActiveProfile( String profile );
|
||||
|
||||
/*
|
||||
* Add profile to inactivate.
|
||||
*/
|
||||
MavenEmbedRequest addInactiveProfile( String profile );
|
||||
/*
|
||||
* Add a list of String instances with names of profiles to activate.
|
||||
*/
|
||||
MavenEmbedRequest addActiveProfiles( List profiles );
|
||||
/*
|
||||
* Add a list of String instances with names of profiles to inactivate.
|
||||
*/
|
||||
MavenEmbedRequest addInactiveProfiles( List profiles );
|
||||
|
||||
/*
|
||||
* Set location of the user settings file to use for the embedder.
|
||||
*/
|
||||
MavenEmbedRequest setUserSettingsFile(File user);
|
||||
|
||||
/*
|
||||
* Set location of the global settings file to use for the embedder.
|
||||
*/
|
||||
MavenEmbedRequest setGlobalSettingsFile(File global);
|
||||
|
||||
/**
|
||||
* Set a customizer callback implemetation that will be given a chance to modify the plexus container
|
||||
* on startup.
|
||||
*/
|
||||
MavenEmbedRequest setConfigurationCustomizer(ContainerCustomizer customizer);
|
||||
|
||||
List getActiveProfiles();
|
||||
|
||||
List getInactiveProfiles();
|
||||
|
||||
File getUserSettingsFile();
|
||||
|
||||
File getGlobalSettingsFile();
|
||||
|
||||
ContainerCustomizer getContainerCustomizer();
|
||||
|
||||
}
|
|
@ -43,7 +43,6 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.reactor.MavenExecutionException;
|
||||
import org.apache.maven.settings.MavenSettingsBuilder;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.wagon.events.TransferListener;
|
||||
import org.codehaus.classworlds.ClassWorld;
|
||||
|
@ -92,7 +91,6 @@ public class MavenEmbedder
|
|||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private MavenSettingsBuilder settingsBuilder;
|
||||
|
||||
private LifecycleExecutor lifecycleExecutor;
|
||||
|
||||
|
@ -150,6 +148,7 @@ public class MavenEmbedder
|
|||
/**
|
||||
* This option determines whether the embedder is to be aligned to the user
|
||||
* installation.
|
||||
* @deprecated not used
|
||||
*/
|
||||
private boolean alignWithUserInstallation;
|
||||
|
||||
|
@ -157,41 +156,65 @@ public class MavenEmbedder
|
|||
// Accessors
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public void setInteractiveMode( boolean interactiveMode )
|
||||
{
|
||||
this.interactiveMode = interactiveMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public boolean isInteractiveMode()
|
||||
{
|
||||
return interactiveMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public void setOffline( boolean offline )
|
||||
{
|
||||
this.offline = offline;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public boolean isOffline()
|
||||
{
|
||||
return offline;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public void setGlobalChecksumPolicy( String globalChecksumPolicy )
|
||||
{
|
||||
this.globalChecksumPolicy = globalChecksumPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public String getGlobalChecksumPolicy()
|
||||
{
|
||||
return globalChecksumPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public boolean isAlignWithUserInstallation()
|
||||
{
|
||||
return alignWithUserInstallation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used
|
||||
*/
|
||||
public void setAlignWithUserInstallation( boolean alignWithUserInstallation )
|
||||
{
|
||||
this.alignWithUserInstallation = alignWithUserInstallation;
|
||||
|
@ -222,11 +245,17 @@ public class MavenEmbedder
|
|||
return classWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public void setLocalRepositoryDirectory( File localRepositoryDirectory )
|
||||
{
|
||||
this.localRepositoryDirectory = localRepositoryDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated not used.
|
||||
*/
|
||||
public File getLocalRepositoryDirectory()
|
||||
{
|
||||
return localRepositoryDirectory;
|
||||
|
@ -429,7 +458,7 @@ public class MavenEmbedder
|
|||
|
||||
public ArtifactRepository createLocalRepository( Settings settings )
|
||||
{
|
||||
return createLocalRepository( settings.getLocalRepository(), DEFAULT_LOCAL_REPO_ID );
|
||||
return createLocalRepository( mavenTools.getLocalRepositoryPath( settings ), DEFAULT_LOCAL_REPO_ID );
|
||||
}
|
||||
|
||||
public ArtifactRepository createLocalRepository( String url, String repositoryId )
|
||||
|
@ -493,7 +522,13 @@ public class MavenEmbedder
|
|||
public void start()
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
detectUserInstallation();
|
||||
start(new DefaultMavenEmbedRequest());
|
||||
|
||||
}
|
||||
|
||||
public void start(MavenEmbedRequest req)
|
||||
throws MavenEmbedderException
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Set the maven.home system property which is need by components like
|
||||
|
@ -506,7 +541,6 @@ public class MavenEmbedder
|
|||
}
|
||||
|
||||
embedder = new Embedder();
|
||||
|
||||
if ( logger != null )
|
||||
{
|
||||
embedder.setLoggerManager( new MavenEmbedderLoggerManager( new PlexusLoggerAdapter( logger ) ) );
|
||||
|
@ -522,7 +556,12 @@ public class MavenEmbedder
|
|||
}
|
||||
|
||||
embedder.start( classWorld );
|
||||
|
||||
|
||||
if (req.getContainerCustomizer() != null)
|
||||
{
|
||||
req.getContainerCustomizer().customize(embedder.getContainer());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Lookup each of the components we need to provide the desired
|
||||
// client interface.
|
||||
|
@ -539,6 +578,10 @@ public class MavenEmbedder
|
|||
pluginDescriptorBuilder = new PluginDescriptorBuilder();
|
||||
|
||||
profileManager = new DefaultProfileManager( embedder.getContainer() );
|
||||
|
||||
profileManager.explicitlyActivate(req.getActiveProfiles());
|
||||
|
||||
profileManager.explicitlyDeactivate(req.getInactiveProfiles());
|
||||
|
||||
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
|
@ -557,8 +600,15 @@ public class MavenEmbedder
|
|||
lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE );
|
||||
|
||||
wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
|
||||
|
||||
settings = mavenTools.buildSettings( req.getUserSettingsFile(),
|
||||
req.getGlobalSettingsFile(),
|
||||
null );
|
||||
|
||||
profileManager.loadSettingsProfiles( settings );
|
||||
|
||||
localRepository = createLocalRepository( settings );
|
||||
|
||||
}
|
||||
catch ( PlexusContainerException e )
|
||||
{
|
||||
|
@ -571,21 +621,14 @@ public class MavenEmbedder
|
|||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new MavenEmbedderException( "Cannot lookup required component.", e );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private void detectUserInstallation()
|
||||
{
|
||||
if ( new File( userHome, ".m2" ).exists() )
|
||||
}
|
||||
catch (SettingsConfigurationException e )
|
||||
{
|
||||
alignWithUserInstallation = true;
|
||||
throw new MavenEmbedderException( "Cannot create settings configuration", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Lifecycle
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -599,8 +642,6 @@ public class MavenEmbedder
|
|||
|
||||
embedder.release( artifactRepositoryFactory );
|
||||
|
||||
embedder.release( settingsBuilder );
|
||||
|
||||
embedder.release( lifecycleExecutor );
|
||||
}
|
||||
catch ( ComponentLifecycleException e )
|
||||
|
@ -634,6 +675,17 @@ public class MavenEmbedder
|
|||
usePluginRegistry,
|
||||
pluginUpdateOverride );
|
||||
}
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
return mavenTools.buildSettings( userSettingsPath,
|
||||
globalSettingsPath,
|
||||
pluginUpdateOverride );
|
||||
}
|
||||
|
||||
|
||||
public File getUserSettingsPath( String optionalSettingsPath )
|
||||
{
|
||||
|
|
|
@ -101,6 +101,26 @@ public class DefaultMavenTools
|
|||
boolean usePluginRegistry,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
Settings settings = buildSettings(userSettingsPath,
|
||||
globalSettingsPath,
|
||||
pluginUpdateOverride);
|
||||
if ( offline )
|
||||
{
|
||||
settings.setOffline( true );
|
||||
}
|
||||
|
||||
settings.setInteractiveMode( interactive );
|
||||
|
||||
settings.setUsePluginRegistry( usePluginRegistry );
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException
|
||||
{
|
||||
Settings settings;
|
||||
|
||||
|
@ -118,15 +138,6 @@ public class DefaultMavenTools
|
|||
e.getColumnNumber() );
|
||||
}
|
||||
|
||||
if ( offline )
|
||||
{
|
||||
settings.setOffline( true );
|
||||
}
|
||||
|
||||
settings.setInteractiveMode( interactive );
|
||||
|
||||
settings.setUsePluginRegistry( usePluginRegistry );
|
||||
|
||||
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
|
||||
|
||||
runtimeInfo.setPluginUpdateOverride( pluginUpdateOverride );
|
||||
|
|
|
@ -58,6 +58,11 @@ public interface MavenTools
|
|||
boolean usePluginRegistry,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException;
|
||||
|
||||
Settings buildSettings( File userSettingsPath,
|
||||
File globalSettingsPath,
|
||||
Boolean pluginUpdateOverride )
|
||||
throws SettingsConfigurationException;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Methods taken from CLI
|
||||
|
|
Loading…
Reference in New Issue