From 7136b01f88479496048637ef7f9eb59943edf3f8 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Thu, 7 Dec 2006 20:53:33 +0000 Subject: [PATCH] o merging in my changes from the refactored embedder branch milos, this has some stuff that we worked on so i've tried to unify everythign in trunk now git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@483655 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/cli/MavenCli.java | 8 +- .../java/org/apache/maven/DefaultMaven.java | 45 +-- .../src/main/java/org/apache/maven/Maven.java | 5 +- .../DefaultMavenExecutionRequest.java | 216 +++++++----- .../DefaultMavenExecutionResult.java | 33 ++ .../execution/MavenExecutionRequest.java | 176 ++++++---- .../maven/execution/MavenExecutionResult.java | 20 ++ .../DefaultMavenEmbedderConfiguration.java | 139 ++++++++ .../apache/maven/embedder/MavenEmbedder.java | 45 +++ .../embedder/MavenEmbedderConfiguration.java | 83 +++++ .../maven/embedder/user/SettingsAdapter.java | 72 ++++ maven.ipr | 324 ++++++++++++++++++ maven.iws | 226 ++++++------ 13 files changed, 1108 insertions(+), 284 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java create mode 100644 maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java create mode 100644 maven-embedder/src/main/java/org/apache/maven/embedder/DefaultMavenEmbedderConfiguration.java create mode 100644 maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConfiguration.java create mode 100644 maven-embedder/src/main/java/org/apache/maven/embedder/user/SettingsAdapter.java create mode 100644 maven.ipr diff --git a/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java index 62075d4371..ee11a7c6ca 100644 --- a/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java @@ -375,16 +375,16 @@ else if ( quiet ) .setGoals( goals ) .setLocalRepositoryPath( localRepositoryPath ) .setProperties( executionProperties ) - .setFailureBehavior( reactorFailureBehaviour ) + .setReactorFailureBehavior( reactorFailureBehaviour ) .setRecursive( recursive ) - .setReactorActive( reactorActive ) + //.setReactorActive( reactorActive ) .setPomFile( alternatePomFile ) .setShowErrors( showErrors ) - .setInteractive( interactive ) + .setInteractiveMode( interactive ) .addActiveProfiles( activeProfiles ) .addInactiveProfiles( inactiveProfiles ) .setLoggingLevel( loggingLevel ) - .activateDefaultEventMonitor() + //.activateDefaultEventMonitor() .setSettings( settings ) .setTransferListener( transferListener ) .setOffline( offline ) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index fffa50ae9c..5b9192f763 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -28,9 +28,10 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; import org.apache.maven.execution.RuntimeInformation; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutor; -import org.apache.maven.model.Profile; import org.apache.maven.monitor.event.DefaultEventDispatcher; import org.apache.maven.monitor.event.DefaultEventMonitor; import org.apache.maven.monitor.event.EventDispatcher; @@ -48,7 +49,6 @@ import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; -import org.apache.maven.settings.SettingsUtils; import org.apache.maven.usability.SystemWarnings; import org.apache.maven.usability.diagnostics.ErrorDiagnostics; import org.codehaus.plexus.PlexusConstants; @@ -58,7 +58,6 @@ import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.logging.AbstractLogger; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; @@ -120,7 +119,7 @@ public class DefaultMaven // Project execution // ---------------------------------------------------------------------- - public void execute( MavenExecutionRequest request ) + public MavenExecutionResult execute( MavenExecutionRequest request ) throws MavenExecutionException { boolean snapshotPolicySet = false; @@ -142,28 +141,18 @@ public void execute( MavenExecutionRequest request ) request.setLocalRepository( mavenTools.createLocalRepository( request.getLocalRepositoryPath() ) ); } - // FIXME: This will not touch the core maven logger, since it's already been initialized for - // this component. + Logger logger = loggerManager.getLoggerForComponent( Mojo.ROLE ); + + if ( request.getEventMonitors() == null ) + { + request.addEventMonitor( new DefaultEventMonitor( logger ) ); + } + loggerManager.setThreshold( request.getLoggingLevel() ); - - Logger myLogger = getLogger(); - - // TODO: When the above problem is fixed, remove this. - if ( myLogger instanceof AbstractLogger ) - { - ((AbstractLogger) myLogger).setThreshold( request.getLoggingLevel() ); - } - - Logger mojoLogger = loggerManager.getLoggerForComponent( Mojo.ROLE ); - - if ( request.isDefaultEventMonitorActive() ) - { - request.addEventMonitor( new DefaultEventMonitor( mojoLogger ) ); - } request.setStartTime( new Date() ); - wagonManager.setInteractive( request.isInteractive() ); + wagonManager.setInteractive( request.isInteractiveMode() ); wagonManager.setDownloadMonitor( request.getTransferListener() ); @@ -253,7 +242,9 @@ public void execute( MavenExecutionRequest request ) line(); - dispatcher.dispatchEnd( event, request.getBaseDirectory() ); + dispatcher.dispatchEnd( event, request.getBaseDirectory() ); + + return new DefaultMavenExecutionResult( rm.getTopLevelProject(), null ); } private void logErrors( ReactorManager rm, boolean showErrors ) @@ -358,7 +349,7 @@ private ReactorManager doExecute( MavenExecutionRequest request, EventDispatcher { rm = new ReactorManager( projects ); - String requestFailureBehavior = request.getFailureBehavior(); + String requestFailureBehavior = request.getReactorFailureBehavior(); if ( requestFailureBehavior != null ) { @@ -425,7 +416,7 @@ private List getProjects( MavenExecutionRequest request, ProfileManager globalPr request.isRecursive(), request.getSettings(), globalProfileManager, - !request.isReactorActive() ); + !request.useReactor() ); } catch ( IOException e ) @@ -617,8 +608,6 @@ protected MavenSession createSession( MavenExecutionRequest request, ReactorMana * them in. It doesn't feel quite right. * @todo [JC] we should at least provide a mapping of protocol-to-proxy for * the wagons, shouldn't we? - * @todo [mkleint] as part of fix MNG-1884, I've copied this code into - * MavenEmbedder. if rewritten, needs to be rewritten there too */ private void resolveParameters( Settings settings ) throws ComponentLookupException, ComponentLifecycleException, SettingsConfigurationException @@ -891,7 +880,7 @@ private List getProjectFiles( MavenExecutionRequest request ) List files = Collections.EMPTY_LIST; File userDir = new File( System.getProperty( "user.dir" ) ); - if ( request.isReactorActive() ) + if ( request.useReactor() ) { // TODO: should we now include the pom.xml in the current directory? // String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 ); diff --git a/maven-core/src/main/java/org/apache/maven/Maven.java b/maven-core/src/main/java/org/apache/maven/Maven.java index d40e249455..6cf30caae1 100644 --- a/maven-core/src/main/java/org/apache/maven/Maven.java +++ b/maven-core/src/main/java/org/apache/maven/Maven.java @@ -17,6 +17,7 @@ */ import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.reactor.MavenExecutionException; /** @@ -47,8 +48,6 @@ public interface Maven static final int LOGGING_LEVEL_DISABLE = 5; - - - void execute( MavenExecutionRequest request ) + MavenExecutionResult execute( MavenExecutionRequest request ) throws MavenExecutionException; } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index f418093ad4..3502d3ad8c 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -34,34 +34,51 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest { - private File basedir; + // ---------------------------------------------------------------------------- + // Settings equivalents + // ---------------------------------------------------------------------------- - /** - * @todo [BP] is this required? This hands off to MavenSession, but could be passed through the handler.handle function (+ createSession). - */ private ArtifactRepository localRepository; - + private File localRepositoryPath; - private List goals; + private boolean offline; - protected MavenSession session; + private boolean interactiveMode; - private Settings settings; + private List proxies; - private boolean recursive = true; + private List servers; - private boolean reactorActive; + private List mirrors; - private String pomFilename; + private List profiles; - private String failureBehavior; + private List pluginGroups; - private Properties properties; + private boolean usePluginRegistry; - private Date startTime; + // ---------------------------------------------------------------------------- + // Request + // ---------------------------------------------------------------------------- - private boolean showErrors; + private File basedir; + + private List goals; + + private Settings settings; + + private boolean useReactor; + + private String pomFile; + + private String reactorFailureBehavior; + + private Properties properties; + + private Date startTime; + + private boolean showErrors; private List eventMonitors; @@ -69,20 +86,16 @@ public class DefaultMavenExecutionRequest private List inactiveProfiles; - private boolean interactive; - private TransferListener transferListener; private int loggingLevel; - private boolean activateDefaultEventMonitor; - - private boolean offline; - private boolean updateSnapshots; private String globalChecksumPolicy; + private boolean recursive; + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -97,11 +110,6 @@ public Settings getSettings() return settings; } - public boolean isRecursive() - { - return recursive; - } - public ArtifactRepository getLocalRepository() { return localRepository; @@ -122,19 +130,14 @@ public Properties getProperties() return properties; } - public MavenSession getSession() - { - return session; - } - public String getPomFile() { - return pomFilename; + return pomFile; } - public String getFailureBehavior() + public String getReactorFailureBehavior() { - return failureBehavior; + return reactorFailureBehavior; } public Date getStartTime() @@ -147,9 +150,9 @@ public boolean isShowErrors() return showErrors; } - public boolean isInteractive() + public boolean isInteractiveMode() { - return interactive; + return interactiveMode; } public List getEventMonitors() @@ -180,21 +183,11 @@ public TransferListener getTransferListener() return transferListener; } - public boolean isDefaultEventMonitorActivated() - { - return activateDefaultEventMonitor; - } - public int getLoggingLevel() { return loggingLevel; } - public boolean isDefaultEventMonitorActive() - { - return activateDefaultEventMonitor; - } - public boolean isOffline() { return offline; @@ -210,6 +203,11 @@ public String getGlobalChecksumPolicy() return globalChecksumPolicy; } + public boolean isRecursive() + { + return recursive; + } + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -223,7 +221,7 @@ public MavenExecutionRequest setBasedir( File basedir ) public MavenExecutionRequest setStartTime( Date startTime ) { - this.startTime= startTime; + this.startTime = startTime; return this; } @@ -277,16 +275,9 @@ public MavenExecutionRequest setProperties( Properties properties ) return this; } - public MavenExecutionRequest setFailureBehavior( String failureBehavior ) + public MavenExecutionRequest setReactorFailureBehavior( String failureBehavior ) { - this.failureBehavior = failureBehavior; - - return this; - } - - public MavenExecutionRequest setSession( MavenSession session ) - { - this.session = session; + this.reactorFailureBehavior = failureBehavior; return this; } @@ -319,7 +310,6 @@ public MavenExecutionRequest addInactiveProfiles( List profiles ) return this; } - public MavenExecutionRequest addEventMonitor( EventMonitor monitor ) { if ( eventMonitors == null ) @@ -332,42 +322,28 @@ public MavenExecutionRequest addEventMonitor( EventMonitor monitor ) return this; } - public MavenExecutionRequest activateDefaultEventMonitor() + public MavenExecutionRequest setUseReactor( boolean reactorActive ) { - activateDefaultEventMonitor = true; + this.useReactor = reactorActive; return this; } - public MavenExecutionRequest setReactorActive( boolean reactorActive ) + public boolean useReactor() { - this.reactorActive = reactorActive; - - return this; - } - - public boolean isReactorActive() - { - return reactorActive; + return useReactor; } public MavenExecutionRequest setPomFile( String pomFilename ) { - this.pomFilename = pomFilename; + this.pomFile = pomFilename; return this; } - public MavenExecutionRequest setRecursive( boolean recursive ) + public MavenExecutionRequest setInteractiveMode( boolean interactive ) { - this.recursive = recursive; - - return this; - } - - public MavenExecutionRequest setInteractive( boolean interactive ) - { - this.interactive = interactive; + this.interactiveMode = interactive; return this; } @@ -406,4 +382,88 @@ public MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolic return this; } + + // ---------------------------------------------------------------------------- + // Settings equivalents + // ---------------------------------------------------------------------------- + + public List getProxies() + { + return proxies; + } + + public MavenExecutionRequest setProxies( List proxies ) + { + this.proxies = proxies; + + return this; + } + + public List getServers() + { + return servers; + } + + public MavenExecutionRequest setServers( List servers ) + { + this.servers = servers; + + return this; + } + + public List getMirrors() + { + return mirrors; + } + + public MavenExecutionRequest setMirrors( List mirrors ) + { + this.mirrors = mirrors; + + return this; + } + + public List getProfiles() + { + return profiles; + } + + public MavenExecutionRequest setProfiles( List profiles ) + { + this.profiles = profiles; + + return this; + } + + public List getPluginGroups() + { + return pluginGroups; + } + + public MavenExecutionRequest setPluginGroups( List pluginGroups ) + { + this.pluginGroups = pluginGroups; + + return this; + } + + public boolean isUsePluginRegistry() + { + return usePluginRegistry; + } + + public MavenExecutionRequest setUsePluginRegistry( boolean usePluginRegistry ) + { + this.usePluginRegistry = usePluginRegistry; + + return this; + } + + public MavenExecutionRequest setRecursive( boolean recursive ) + { + this.recursive = recursive; + + return this; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java new file mode 100644 index 0000000000..50713227d6 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java @@ -0,0 +1,33 @@ +package org.apache.maven.execution; + +import org.apache.maven.project.MavenProject; + +import java.util.List; + +/** + * @author Jason van Zyl + */ +public class DefaultMavenExecutionResult + implements MavenExecutionResult +{ + private MavenProject mavenProject; + + private List exceptions; + + public DefaultMavenExecutionResult( MavenProject project, + List exceptions ) + { + this.mavenProject = project; + this.exceptions = exceptions; + } + + public MavenProject getMavenProject() + { + return mavenProject; + } + + public List getExceptions() + { + return exceptions; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index 2f662f2817..b4a9a7fe1b 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -31,53 +31,10 @@ /** * @author Jason van Zyl * @version $Id$ + * @todo merge Settings,RuntimeInfo,MavenSession into this. make adapters for everything */ public interface MavenExecutionRequest { - File getLocalRepositoryPath(); - - ArtifactRepository getLocalRepository(); - - List getGoals(); - - Settings getSettings(); - - String getBaseDirectory(); - - boolean isRecursive(); - - boolean isInteractive(); - - boolean isReactorActive(); - - String getPomFile(); - - String getFailureBehavior(); - - Properties getProperties(); - - Date getStartTime(); - - boolean isShowErrors(); - - List getEventMonitors(); - - List getActiveProfiles(); - - List getInactiveProfiles(); - - TransferListener getTransferListener(); - - int getLoggingLevel(); - - boolean isDefaultEventMonitorActive(); - - boolean isOffline(); - - boolean isUpdateSnapshots(); - - String getGlobalChecksumPolicy(); - // ---------------------------------------------------------------------- // Logging // ---------------------------------------------------------------------- @@ -107,7 +64,7 @@ public interface MavenExecutionRequest // ---------------------------------------------------------------------- // Artifactr repository policies // ---------------------------------------------------------------------- - + static final String CHECKSUM_POLICY_FAIL = ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL; static final String CHECKSUM_POLICY_WARN = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; @@ -116,55 +73,146 @@ public interface MavenExecutionRequest // // ---------------------------------------------------------------------- + // Base directory + MavenExecutionRequest setBasedir( File basedir ); + String getBaseDirectory(); + + // Settings MavenExecutionRequest setSettings( Settings settings ); + Settings getSettings(); + + // Timing (remove this) MavenExecutionRequest setStartTime( Date start ); + Date getStartTime(); + + // Goals MavenExecutionRequest setGoals( List goals ); - MavenExecutionRequest setLocalRepository( ArtifactRepository localRepository ); + List getGoals(); + + // Properties + MavenExecutionRequest setProperties( Properties properties ); + + Properties getProperties(); + + // Reactor + MavenExecutionRequest setReactorFailureBehavior( String failureBehavior ); + + String getReactorFailureBehavior(); + + MavenExecutionRequest setUseReactor( boolean useReactor ); + + boolean useReactor(); + + // Recursive (really to just process the top-level POM) + MavenExecutionRequest setRecursive( boolean recursive ); + + boolean isRecursive(); + + // Event monitors + MavenExecutionRequest addEventMonitor( EventMonitor monitor ); + + List getEventMonitors(); + + // Pom + MavenExecutionRequest setPomFile( String pomFilename ); + + String getPomFile(); + + // Errors + MavenExecutionRequest setShowErrors( boolean showErrors ); + + boolean isShowErrors(); + + // Transfer listeners + MavenExecutionRequest setTransferListener( TransferListener transferListener ); + + TransferListener getTransferListener(); + + // Logging + MavenExecutionRequest setLoggingLevel( int loggingLevel ); + + int getLoggingLevel(); + + // Update snapshots + MavenExecutionRequest setUpdateSnapshots( boolean updateSnapshots ); + + boolean isUpdateSnapshots(); + + // Checksum policy + MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolicy ); + + String getGlobalChecksumPolicy(); + + // ---------------------------------------------------------------------------- + // Settings equivalents + // ---------------------------------------------------------------------------- + + // Local repository MavenExecutionRequest setLocalRepositoryPath( String localRepository ); MavenExecutionRequest setLocalRepositoryPath( File localRepository ); - MavenExecutionRequest setProperties( Properties properties ); + File getLocalRepositoryPath(); - MavenExecutionRequest setFailureBehavior( String failureBehavior ); + MavenExecutionRequest setLocalRepository( ArtifactRepository repository ); - MavenExecutionRequest setSession( MavenSession session ); + ArtifactRepository getLocalRepository(); + + // Interactive + MavenExecutionRequest setInteractiveMode( boolean interactive ); + + boolean isInteractiveMode(); + + // Offline + MavenExecutionRequest setOffline( boolean offline ); + + boolean isOffline(); + + // Profiles + List getProfiles(); + + MavenExecutionRequest setProfiles( List profiles ); MavenExecutionRequest addActiveProfile( String profile ); - MavenExecutionRequest addInactiveProfile( String profile ); - MavenExecutionRequest addActiveProfiles( List profiles ); + List getActiveProfiles(); + + MavenExecutionRequest addInactiveProfile( String profile ); + MavenExecutionRequest addInactiveProfiles( List profiles ); - MavenExecutionRequest addEventMonitor( EventMonitor monitor ); + List getInactiveProfiles(); - MavenExecutionRequest setReactorActive( boolean reactorActive ); + // Proxies + List getProxies(); - MavenExecutionRequest setPomFile( String pomFilename ); + MavenExecutionRequest setProxies( List proxies ); - MavenExecutionRequest setRecursive( boolean recursive ); + // Servers + List getServers(); - MavenExecutionRequest setShowErrors( boolean showErrors ); + MavenExecutionRequest setServers( List servers ); - MavenExecutionRequest setInteractive( boolean interactive ); + // Mirrors + List getMirrors(); - MavenExecutionRequest setTransferListener( TransferListener transferListener ); + MavenExecutionRequest setMirrors( List mirrors ); - MavenExecutionRequest setLoggingLevel( int loggingLevel ); + // Plugin groups + List getPluginGroups(); - MavenExecutionRequest activateDefaultEventMonitor(); + MavenExecutionRequest setPluginGroups( List pluginGroups ); - MavenExecutionRequest setOffline( boolean offline ); + // Plugin registry + boolean isUsePluginRegistry(); - MavenExecutionRequest setUpdateSnapshots( boolean updateSnapshots ); - - MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolicy ); + MavenExecutionRequest setUsePluginRegistry( boolean usePluginRegistry ); } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java new file mode 100644 index 0000000000..741dd97bbb --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java @@ -0,0 +1,20 @@ +package org.apache.maven.execution; + +import org.apache.maven.project.MavenProject; + +import java.util.List; + +/** + * @author Jason van Zyl + */ +public interface MavenExecutionResult +{ + MavenProject getMavenProject(); + + // for each exception + // - knowing what artifacts are missing + // - project building exception + // - invalid project model exception: list of markers + // - xmlpull parser exception + List getExceptions(); +} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultMavenEmbedderConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultMavenEmbedderConfiguration.java new file mode 100644 index 0000000000..383c25d717 --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultMavenEmbedderConfiguration.java @@ -0,0 +1,139 @@ +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.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.settings.Settings; + +/** + * Default implementation of MavenEmbedderConfiguration intefrace. + * + * @author mkleint + */ +public class DefaultMavenEmbedderConfiguration + implements MavenEmbedderConfiguration +{ + private List inactives; + + private List actives; + + private Settings settings; + + private File userSettings; + + private File globalSettings; + + private ContainerCustomizer customizer; + + private Properties systemProperties; + + /** + * Creates a new instance of DefaultMavenEmbedderConfiguration + */ + public DefaultMavenEmbedderConfiguration() + { + } + + public MavenEmbedderConfiguration addActiveProfile( String profile ) + { + getActiveProfiles().add( profile ); + return this; + } + + public MavenEmbedderConfiguration addInactiveProfile( String profile ) + { + getInactiveProfiles().add( profile ); + return this; + } + + public MavenEmbedderConfiguration addActiveProfiles( List profiles ) + { + getActiveProfiles().addAll( profiles ); + return this; + } + + public MavenEmbedderConfiguration 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 MavenEmbedderConfiguration setUserSettingsFile( File user ) + { + userSettings = user; + return this; + } + + public MavenEmbedderConfiguration setGlobalSettingsFile( File global ) + { + globalSettings = global; + return this; + } + + public File getUserSettingsFile() + { + return userSettings; + } + + public File getGlobalSettingsFile() + { + return globalSettings; + } + + public MavenEmbedderConfiguration setConfigurationCustomizer( ContainerCustomizer customizer ) + { + this.customizer = customizer; + return this; + } + + public ContainerCustomizer getContainerCustomizer() + { + return customizer; + } + + public MavenEmbedderConfiguration setSystemProperties( Properties properties ) + { + systemProperties = properties; + return this; + } + + public Properties getSystemProperties() + { + return systemProperties != null ? systemProperties : System.getProperties(); + } +} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 5ddf644d13..1512f3ad2c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -30,6 +30,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; @@ -72,6 +74,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Collections; /** * Class intended to be used by clients who wish to embed Maven into their applications @@ -341,6 +344,48 @@ public MavenProject readProjectWithDependencies( File mavenProject ) return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager ); } + /** + * This method is used to grab the list of dependencies that belong to a project so that a UI + * can be populated. For example, a list of libraries that are used by an Eclipse, Netbeans, or + * IntelliJ project. + */ + // Not well formed exceptions to point people at errors + // line number in the originating POM so that errors can be shown + // Need to walk down the tree of dependencies and find all the errors and report in the result + // validate the request + // for dependency errors: identifier, path + // unable to see why you can't get a resource from the repository + // short message or error id + // completely obey the same settings used by the CLI, should work exactly the same as the + // command line. right now they are very different + public MavenExecutionResult readProjectWithDependencies( MavenExecutionRequest request ) + { + MavenProject project = null; + + // How can we get rid of the profile manager from the request + + try + { + project = mavenProjectBuilder.buildWithDependencies( new File( request.getPomFile() ), + request.getLocalRepository(), profileManager, + request.getTransferListener() ); + } + catch ( ProjectBuildingException e ) + { + return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) ); + } + catch ( ArtifactResolutionException e ) + { + return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) ); + } + catch ( ArtifactNotFoundException e ) + { + return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) ); + } + + return new DefaultMavenExecutionResult( project, Collections.EMPTY_LIST ); + } + public List collectProjects( File basedir, String[] includes, String[] excludes ) throws MojoExecutionException { diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConfiguration.java new file mode 100644 index 0000000000..30ed506d5a --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConfiguration.java @@ -0,0 +1,83 @@ +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.util.List; +import java.util.Properties; + +/** + * Configuration of embedder, used when starting up. + * + * @author mkleint + */ +public interface MavenEmbedderConfiguration +{ + /* + * Add profile to activate. + */ + MavenEmbedderConfiguration addActiveProfile( String profile ); + + /* + * Add profile to inactivate. + */ + MavenEmbedderConfiguration addInactiveProfile( String profile ); + + /* + * Add a list of String instances with names of profiles to activate. + */ + MavenEmbedderConfiguration addActiveProfiles( List profiles ); + + /* + * Add a list of String instances with names of profiles to inactivate. + */ + MavenEmbedderConfiguration addInactiveProfiles( List profiles ); + + /* + * Set location of the user settings file to use for the embedder. + */ + MavenEmbedderConfiguration setUserSettingsFile( File user ); + + /* + * Set location of the global settings file to use for the embedder. + */ + MavenEmbedderConfiguration setGlobalSettingsFile( File global ); + + /** + * Set a customizer callback implemetation that will be given a chance to modify the plexus container + * on startup. + */ + MavenEmbedderConfiguration 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. + */ + MavenEmbedderConfiguration setSystemProperties( Properties properties ); + + List getActiveProfiles(); + + List getInactiveProfiles(); + + File getUserSettingsFile(); + + File getGlobalSettingsFile(); + + ContainerCustomizer getContainerCustomizer(); + + Properties getSystemProperties(); + + +} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/user/SettingsAdapter.java b/maven-embedder/src/main/java/org/apache/maven/embedder/user/SettingsAdapter.java new file mode 100644 index 0000000000..75ea42c4bb --- /dev/null +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/user/SettingsAdapter.java @@ -0,0 +1,72 @@ +package org.apache.maven.embedder.user; + +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.settings.Settings; + +import java.util.List; + +/** + * Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core. + * + * @author Jason van Zyl + */ +public class SettingsAdapter + extends Settings +{ + private MavenExecutionRequest request; + + public SettingsAdapter( MavenExecutionRequest request ) + { + this.request = request; + } + + public String getLocalRepository() + { + return request.getLocalRepositoryPath().getAbsolutePath(); + } + + public boolean isInteractiveMode() + { + return request.isInteractiveMode(); + } + + public boolean isUsePluginRegistry() + { + return request.isUsePluginRegistry(); + } + + public boolean isOffline() + { + return request.isOffline(); + } + + public List getProxies() + { + return request.getProxies(); + } + + public List getServers() + { + return request.getServers(); + } + + public List getMirrors() + { + return request.getMirrors(); + } + + public List getProfiles() + { + return request.getProfiles(); + } + + public List getActiveProfiles() + { + return request.getActiveProfiles(); + } + + public List getPluginGroups() + { + return request.getPluginGroups(); + } +} diff --git a/maven.ipr b/maven.ipr new file mode 100644 index 0000000000..88cdf066c6 --- /dev/null +++ b/maven.ipr @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven.iws b/maven.iws index 49fdcb8ea4..9f033a6115 100644 --- a/maven.iws +++ b/maven.iws @@ -19,13 +19,20 @@ - - - - - + + - + + + + + + + + + + + @@ -234,38 +241,31 @@ - - + + - + - - + + - + - - + + - - - - - - - - - - - + + + + @@ -311,7 +311,16 @@ - + + + + + + + +