mirror of https://github.com/apache/maven.git
MNG-3649: making sure that the request parameters which are populated from the CLI are honored in plugins like the release plugin which consume CLI options from the user
settings object. ug. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@701216 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6779e62e80
commit
cc5827fa72
|
@ -1,22 +1,18 @@
|
|||
package org.apache.maven.cli;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||
* copyright ownership. The ASF licenses this file to you 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.commons.cli.CommandLine;
|
||||
|
@ -90,83 +86,36 @@ public class CLIManager
|
|||
|
||||
private Options options;
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public CLIManager()
|
||||
{
|
||||
options = new Options();
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription(
|
||||
"Force the use of an alternate POM file." ).create( ALTERNATE_POM_FILE ) );
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create(
|
||||
SET_SYSTEM_PROPERTY ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( OFFLINE ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create(
|
||||
VERSION ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create(
|
||||
QUIET ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create(
|
||||
DEBUG ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create(
|
||||
ERRORS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription(
|
||||
"Execute goals for project found in the reactor" ).create( REACTOR ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription(
|
||||
"Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "update-snapshots" ).withDescription(
|
||||
"Forces a check for updated releases and snapshots on remote repositories" ).create( UPDATE_SNAPSHOTS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription(
|
||||
"Comma-delimited list of profiles to activate" ).hasArg().create( ACTIVATE_PROFILES ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription(
|
||||
"Run in non-interactive (batch) mode" ).create( BATCH_MODE ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "check-plugin-updates" ).withDescription(
|
||||
"Force upToDate check for any relevant registered plugins" ).create( FORCE_PLUGIN_UPDATES ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "update-plugins" ).withDescription(
|
||||
"Synonym for " + FORCE_PLUGIN_UPDATES ).create( FORCE_PLUGIN_UPDATES2 ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription(
|
||||
"Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) );
|
||||
|
||||
options.addOption(OptionBuilder.withLongOpt("no-snapshot-updates")
|
||||
.withDescription("Supress SNAPSHOT updates")
|
||||
.create(SUPRESS_SNAPSHOT_UPDATES));
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription(
|
||||
"Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription(
|
||||
"Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create(
|
||||
CHECKSUM_WARNING_POLICY ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "settings" )
|
||||
.withDescription( "Alternate path for the user settings file" ).hasArg()
|
||||
.create( ALTERNATE_USER_SETTINGS ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription(
|
||||
"Stop at first failure in reactorized builds" ).create( FAIL_FAST ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-at-end" ).withDescription(
|
||||
"Only fail the build afterwards; allow all non-impacted builds to continue" ).create( FAIL_AT_END ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription(
|
||||
"NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );
|
||||
|
||||
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription(
|
||||
"Log file to where all build output will go." ).create( LOG_FILE ) );
|
||||
|
||||
options.addOption(
|
||||
OptionBuilder.withLongOpt( "show-version" ).withDescription( "Display version information WITHOUT stopping build" ).create(
|
||||
SHOW_VERSION ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription( "Force the use of an alternate POM file." ).create( ALTERNATE_POM_FILE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( OFFLINE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create( VERSION ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create( QUIET ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create( DEBUG ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create( ERRORS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "reactor" ).withDescription( "Execute goals for project found in the reactor" ).create( REACTOR ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription( "Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "update-snapshots" ).withDescription( "Forces a check for updated releases and snapshots on remote repositories" ).create( UPDATE_SNAPSHOTS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription( "Comma-delimited list of profiles to activate" ).hasArg().create( ACTIVATE_PROFILES ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription( "Run in non-interactive (batch) mode" ).create( BATCH_MODE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "check-plugin-updates" ).withDescription( "Force upToDate check for any relevant registered plugins" ).create( FORCE_PLUGIN_UPDATES ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "update-plugins" ).withDescription( "Synonym for " + FORCE_PLUGIN_UPDATES ).create( FORCE_PLUGIN_UPDATES2 ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription( "Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-snapshot-updates" ).withDescription( "Supress SNAPSHOT updates" ).create( SUPRESS_SNAPSHOT_UPDATES ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription( "Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription( "Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create( CHECKSUM_WARNING_POLICY ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "settings" ).withDescription( "Alternate path for the user settings file" ).hasArg().create( ALTERNATE_USER_SETTINGS ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription( "Stop at first failure in reactorized builds" ).create( FAIL_FAST ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-at-end" ).withDescription( "Only fail the build afterwards; allow all non-impacted builds to continue" ).create( FAIL_AT_END ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription( "NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription( "Log file to where all build output will go." ).create( LOG_FILE ) );
|
||||
options.addOption( OptionBuilder.withLongOpt( "show-version" ).withDescription( "Display version information WITHOUT stopping build" ).create( SHOW_VERSION ) );
|
||||
}
|
||||
|
||||
public CommandLine parse( String[] args )
|
||||
|
@ -276,7 +225,6 @@ public class CLIManager
|
|||
return cleanArgs;
|
||||
}
|
||||
|
||||
|
||||
public void displayHelp()
|
||||
{
|
||||
System.out.println();
|
||||
|
|
|
@ -232,7 +232,7 @@ public final class CLIRequestUtils
|
|||
.setRecursive( recursive ) // default: true
|
||||
.setUseReactor( useReactor ) // default: false
|
||||
.setShowErrors( showErrors ) // default: false
|
||||
.setInteractiveMode( interactive ) // default: false
|
||||
.setInteractiveMode( interactive ) // default: true
|
||||
.setOffline( offline ) // default: false
|
||||
.setUsePluginUpdateOverride( pluginUpdateOverride )
|
||||
.addActiveProfiles( activeProfiles ) // optional
|
||||
|
|
|
@ -19,6 +19,16 @@ package org.apache.maven.embedder;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.Maven;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
|
@ -33,7 +43,13 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
|
|||
import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
|
||||
import org.apache.maven.errors.CoreErrorReporter;
|
||||
import org.apache.maven.errors.CoreReporterManager;
|
||||
import org.apache.maven.execution.*;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||
import org.apache.maven.execution.DuplicateProjectException;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.MavenExecutionResult;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ReactorManager;
|
||||
import org.apache.maven.lifecycle.LifecycleException;
|
||||
import org.apache.maven.lifecycle.LifecycleUtils;
|
||||
import org.apache.maven.lifecycle.plan.BuildPlan;
|
||||
|
@ -50,10 +66,8 @@ import org.apache.maven.plugin.MavenPluginDiscoverer;
|
|||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.PluginManagerException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
|
||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
import org.apache.maven.execution.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.MavenProjectBuildingResult;
|
||||
|
@ -88,16 +102,6 @@ import org.codehaus.plexus.util.WriterFactory;
|
|||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class intended to be used by clients who wish to embed Maven into their applications
|
||||
*
|
||||
|
@ -137,18 +141,10 @@ public class MavenEmbedder
|
|||
|
||||
private MavenXpp3Writer modelWriter;
|
||||
|
||||
private SettingsXpp3Writer settingsWriter;
|
||||
|
||||
private PluginDescriptorBuilder pluginDescriptorBuilder;
|
||||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
private ArtifactResolver artifactResolver;
|
||||
|
||||
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
|
||||
|
||||
private ArtifactHandlerManager artifactHandlerManager;
|
||||
|
||||
private Maven maven;
|
||||
|
@ -392,6 +388,7 @@ public class MavenEmbedder
|
|||
// registered as an artifact and is not added to the classpath elements.
|
||||
|
||||
readProject( request.getPom(), request );
|
||||
|
||||
}
|
||||
catch ( MavenEmbedderException e )
|
||||
{
|
||||
|
@ -649,29 +646,19 @@ public class MavenEmbedder
|
|||
|
||||
modelWriter = new MavenXpp3Writer();
|
||||
|
||||
settingsWriter = new SettingsXpp3Writer();
|
||||
|
||||
maven = (Maven) container.lookup( Maven.ROLE );
|
||||
|
||||
pluginDescriptorBuilder = new PluginDescriptorBuilder();
|
||||
|
||||
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Artifact related components
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
artifactRepositoryFactory = (ArtifactRepositoryFactory) container.lookup( ArtifactRepositoryFactory.ROLE );
|
||||
|
||||
artifactFactory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE );
|
||||
|
||||
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE, "default" );
|
||||
|
||||
defaultArtifactRepositoryLayout =
|
||||
(ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, "default" );
|
||||
|
||||
populator = (MavenExecutionRequestPopulator) container.lookup(
|
||||
MavenExecutionRequestPopulator.ROLE );
|
||||
populator = (MavenExecutionRequestPopulator) container.lookup( MavenExecutionRequestPopulator.ROLE );
|
||||
|
||||
buildPlanner = (BuildPlanner) container.lookup( BuildPlanner.class );
|
||||
|
||||
|
|
|
@ -113,9 +113,6 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
|
||||
snapshotPolicy( request, configuration );
|
||||
|
||||
// TODO: Can we remove this second call?
|
||||
// localRepository( request, configuration );
|
||||
|
||||
checksumPolicy( request, configuration );
|
||||
|
||||
artifactTransferMechanism( request, configuration );
|
||||
|
@ -334,12 +331,13 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
|
||||
try
|
||||
{
|
||||
request.setSettings(
|
||||
settingsBuilder.buildSettings( request ) );
|
||||
Settings settings = settingsBuilder.buildSettings( request );
|
||||
|
||||
request.setSettings( new SettingsAdapter( request, settings ) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
request.setSettings( new Settings() );
|
||||
request.setSettings( new SettingsAdapter( request, new Settings() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.apache.maven.embedder.user;
|
||||
package org.apache.maven.embedder.execution;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
|
@ -26,6 +26,9 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core.
|
||||
* We want to make sure that what is ask for in the execution request overrides what is in the settings.
|
||||
* The CLI feeds into an execution request so if a particular value is present in the execution request
|
||||
* then we will take that over the value coming from the user settings.
|
||||
*
|
||||
* @author Jason van Zyl
|
||||
*/
|
||||
|
@ -33,20 +36,27 @@ public class SettingsAdapter
|
|||
extends Settings
|
||||
{
|
||||
private MavenExecutionRequest request;
|
||||
private Settings settings;
|
||||
|
||||
public SettingsAdapter( MavenExecutionRequest request )
|
||||
public SettingsAdapter( MavenExecutionRequest request, Settings settings )
|
||||
{
|
||||
this.request = request;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public String getLocalRepository()
|
||||
{
|
||||
return request.getLocalRepositoryPath().getAbsolutePath();
|
||||
if ( request.getLocalRepositoryPath() != null )
|
||||
{
|
||||
return request.getLocalRepositoryPath().getAbsolutePath();
|
||||
}
|
||||
|
||||
return settings.getLocalRepository();
|
||||
}
|
||||
|
||||
public boolean isInteractiveMode()
|
||||
{
|
||||
return request.isInteractiveMode();
|
||||
{
|
||||
return request.isInteractiveMode();
|
||||
}
|
||||
|
||||
public boolean isOffline()
|
||||
|
@ -54,33 +64,35 @@ public class SettingsAdapter
|
|||
return request.isOffline();
|
||||
}
|
||||
|
||||
// These we are not setting in the execution request currently
|
||||
|
||||
public List getProxies()
|
||||
{
|
||||
return request.getProxies();
|
||||
return settings.getProxies();
|
||||
}
|
||||
|
||||
public List getServers()
|
||||
{
|
||||
return request.getServers();
|
||||
return settings.getServers();
|
||||
}
|
||||
|
||||
public List getMirrors()
|
||||
{
|
||||
return request.getMirrors();
|
||||
return settings.getMirrors();
|
||||
}
|
||||
|
||||
public List getProfiles()
|
||||
{
|
||||
return request.getProfiles();
|
||||
return settings.getProfiles();
|
||||
}
|
||||
|
||||
public List getActiveProfiles()
|
||||
{
|
||||
return request.getActiveProfiles();
|
||||
return settings.getActiveProfiles();
|
||||
}
|
||||
|
||||
public List getPluginGroups()
|
||||
{
|
||||
return request.getPluginGroups();
|
||||
return settings.getPluginGroups();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue