You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2016/09/24 15:13:58 UTC
[37/40] maven git commit: First step to implement --fail-level warn,
--fail-level error
First step to implement --fail-level warn, --fail-level error
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/3b4e13fb
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/3b4e13fb
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/3b4e13fb
Branch: refs/heads/MNG-6012-Missing-Profile-At-End
Commit: 3b4e13fb9ae6e93e895f4beebd7d49d45c70d590
Parents: 31a6647
Author: khmarbaise <kh...@apache.org>
Authored: Mon Aug 29 08:23:23 2016 +0200
Committer: khmarbaise <kh...@apache.org>
Committed: Mon Aug 29 09:47:54 2016 +0200
----------------------------------------------------------------------
apache-maven/pom.xml | 11 +++++
.../java/org/apache/maven/DefaultMaven.java | 51 ++++++++++----------
.../execution/DefaultMavenExecutionRequest.java | 35 ++++++++++----
.../maven/execution/MavenExecutionRequest.java | 31 ++++++++++--
.../java/org/apache/maven/cli/CLIManager.java | 4 +-
.../java/org/apache/maven/cli/MavenCli.java | 25 ++++++++--
6 files changed, 109 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/3b4e13fb/apache-maven/pom.xml
----------------------------------------------------------------------
diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml
index ec11cc2..ac3ce52 100644
--- a/apache-maven/pom.xml
+++ b/apache-maven/pom.xml
@@ -122,6 +122,17 @@ under the License.
</plugins>
</pluginManagement>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>process-resource-bundles</id>
+ <phase>U</phase>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
http://git-wip-us.apache.org/repos/asf/maven/blob/3b4e13fb/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
----------------------------------------------------------------------
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 7051737..a38cae8 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -113,7 +113,7 @@ public class DefaultMaven
}
catch ( RuntimeException e )
{
- //TODO Hack to make the cycle detection the same for the new graph builder
+ // TODO Hack to make the cycle detection the same for the new graph builder
if ( e.getCause() instanceof ProjectCycleException )
{
result = addExceptionToResult( new DefaultMavenExecutionResult(), e.getCause() );
@@ -121,7 +121,7 @@ public class DefaultMaven
else
{
result = addExceptionToResult( new DefaultMavenExecutionResult(),
- new InternalErrorException( "Internal error: " + e, e ) );
+ new InternalErrorException( "Internal error: " + e, e ) );
}
}
finally
@@ -162,7 +162,7 @@ public class DefaultMaven
//
@SuppressWarnings( "checkstyle:methodlength" )
private MavenExecutionResult doExecute( MavenExecutionRequest request )
- {
+ {
request.setStartTime( new Date() );
MavenExecutionResult result = new DefaultMavenExecutionResult();
@@ -205,8 +205,8 @@ public class DefaultMaven
{
try
{
- for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections
- .<MavenProject>emptyList() ) )
+ for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants(
+ Collections.<MavenProject>emptyList() ) )
{
listener.afterSessionStart( session );
}
@@ -219,12 +219,11 @@ public class DefaultMaven
eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );
Result<? extends ProjectDependencyGraph> graphResult = buildGraph( session, result );
-
+
if ( graphResult.hasErrors() )
{
return addExceptionToResult( result,
- Iterables.toArray( graphResult.getProblems(), ModelProblem.class )[0]
- .getException() );
+ Iterables.toArray( graphResult.getProblems(), ModelProblem.class )[0].getException() );
}
try
@@ -253,8 +252,8 @@ public class DefaultMaven
// Workspace
// User Local Repository
//
- repoSession.setWorkspaceReader( ChainedWorkspaceReader.newInstance( reactorWorkspace,
- repoSession.getWorkspaceReader() ) );
+ repoSession.setWorkspaceReader(
+ ChainedWorkspaceReader.newInstance( reactorWorkspace, repoSession.getWorkspaceReader() ) );
repoSession.setReadOnly();
@@ -285,14 +284,13 @@ public class DefaultMaven
// Note that participants may affect the topological order of the projects but it is
// not expected that a participant will add or remove projects from the session.
//
-
+
graphResult = buildGraph( session, result );
-
+
if ( graphResult.hasErrors() )
{
return addExceptionToResult( result,
- Iterables.toArray( graphResult.getProblems(), ModelProblem.class )[0]
- .getException() );
+ Iterables.toArray( graphResult.getProblems(), ModelProblem.class )[0].getException() );
}
try
@@ -308,10 +306,11 @@ public class DefaultMaven
// Give the user a hint about not existing profiles at the beginning and fail
// the build if he request to do so.
- List<String> profilesWhichDoNotExist = identifyProfilesWhichDoNotExist( session.getProjects(), request.getActiveProfiles() );
+ List<String> profilesWhichDoNotExist =
+ identifyProfilesWhichDoNotExist( session.getProjects(), request.getActiveProfiles() );
if ( !profilesWhichDoNotExist.isEmpty() )
{
- if ( request.isFailOnMissingProfiles() )
+ if ( request.isFailLevelWARN() )
{
logWarnOrError( profilesWhichDoNotExist, true );
@@ -388,7 +387,7 @@ public class DefaultMaven
Thread.currentThread().setContextClassLoader( originalClassLoader );
}
}
-
+
public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
return repositorySessionFactory.newRepositorySession( request );
@@ -411,8 +410,7 @@ public class DefaultMaven
private Collection<AbstractMavenLifecycleParticipant> getLifecycleParticipants( Collection<MavenProject> projects )
{
- Collection<AbstractMavenLifecycleParticipant> lifecycleListeners =
- new LinkedHashSet<>();
+ Collection<AbstractMavenLifecycleParticipant> lifecycleListeners = new LinkedHashSet<>();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try
@@ -470,7 +468,7 @@ public class DefaultMaven
private List<String> identifyProfilesWhichDoNotExist( List<MavenProject> projects, List<String> activeProfileIds )
{
List<String> result = new LinkedList<>();
-
+
Collection<String> notActivatedProfileIds = new LinkedHashSet<>( activeProfileIds );
for ( MavenProject project : projects )
@@ -481,7 +479,8 @@ public class DefaultMaven
}
}
- if ( !notActivatedProfileIds.isEmpty() ) {
+ if ( !notActivatedProfileIds.isEmpty() )
+ {
result.addAll( notActivatedProfileIds );
}
@@ -530,7 +529,7 @@ public class DefaultMaven
return index;
}
- private Result<? extends ProjectDependencyGraph> buildGraph( MavenSession session, MavenExecutionResult result )
+ private Result<? extends ProjectDependencyGraph> buildGraph( MavenSession session, MavenExecutionResult result )
{
Result<? extends ProjectDependencyGraph> graphResult = graphBuilder.build( session );
for ( ModelProblem problem : graphResult.getProblems() )
@@ -550,12 +549,12 @@ public class DefaultMaven
ProjectDependencyGraph projectDependencyGraph = graphResult.get();
session.setProjects( projectDependencyGraph.getSortedProjects() );
session.setAllProjects( projectDependencyGraph.getSortedProjects() );
- session.setProjectDependencyGraph( projectDependencyGraph );
+ session.setProjectDependencyGraph( projectDependencyGraph );
}
-
- return graphResult;
+
+ return graphResult;
}
-
+
@Deprecated
// 5 January 2014
protected Logger getLogger()
http://git-wip-us.apache.org/repos/asf/maven/blob/3b4e13fb/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
----------------------------------------------------------------------
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 a95a7f2..686850d 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
@@ -163,11 +163,12 @@ public class DefaultMavenExecutionRequest
private boolean useLegacyLocalRepositoryManager = false;
private Map<String, Object> data;
-
- private boolean failOnMissingProfiles;
+
+ private FailLevel failLevel;
public DefaultMavenExecutionRequest()
{
+ this.failLevel = FailLevel.ERROR;
}
public static MavenExecutionRequest copy( MavenExecutionRequest original )
@@ -189,8 +190,8 @@ public class DefaultMavenExecutionRequest
copy.setGlobalSettingsFile( original.getGlobalSettingsFile() );
copy.setUserToolchainsFile( original.getUserToolchainsFile() );
copy.setGlobalToolchainsFile( original.getGlobalToolchainsFile() );
- copy.setBaseDirectory( ( original.getBaseDirectory() != null ) ? new File( original.getBaseDirectory() )
- : null );
+ copy.setBaseDirectory(
+ ( original.getBaseDirectory() != null ) ? new File( original.getBaseDirectory() ) : null );
copy.setGoals( original.getGoals() );
copy.setRecursive( original.isRecursive() );
copy.setPom( original.getPom() );
@@ -674,7 +675,9 @@ public class DefaultMavenExecutionRequest
return useReactor;
}
- /** @deprecated use {@link #setPom(File)} */
+ /**
+ * @deprecated use {@link #setPom(File)}
+ */
@Deprecated
public MavenExecutionRequest setPomFile( String pomFilename )
{
@@ -1289,15 +1292,27 @@ public class DefaultMavenExecutionRequest
}
@Override
- public boolean isFailOnMissingProfiles()
+ public boolean isFailLevelWARN()
+ {
+ return this.failLevel.equals( FailLevel.WARN );
+ }
+
+ @Override
+ public boolean isFailLevelERROR()
+ {
+ return this.failLevel.equals( FailLevel.ERROR );
+ }
+
+ @Override
+ public FailLevel getFailLevel()
{
- return failOnMissingProfiles;
+ return this.failLevel;
}
-
+
@Override
- public MavenExecutionRequest setFailOnMissingProfiles( boolean failOnMissingProfiles )
+ public MavenExecutionRequest setFailLevel( FailLevel failLevel )
{
- this.failOnMissingProfiles = failOnMissingProfiles;
+ this.failLevel = failLevel;
return this;
}
}
http://git-wip-us.apache.org/repos/asf/maven/blob/3b4e13fb/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
----------------------------------------------------------------------
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 335cc61..6af9c75 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
@@ -92,6 +92,16 @@ public interface MavenExecutionRequest
String CHECKSUM_POLICY_WARN = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
+ public enum FailLevel {
+ /**
+ * The default level on which Maven will fail the build.
+ */
+ ERROR,
+ /**
+ * In case of warnings fail the build.
+ */
+ WARN
+ }
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@@ -444,17 +454,28 @@ public interface MavenExecutionRequest
Map<String, Object> getData();
/**
- * @return {@code true} if we should fail on missing profiles {@code false} otherwise.
+ * @return the current {@link FailLevel}
* @since 3.4.0
*/
- boolean isFailOnMissingProfiles();
+ FailLevel getFailLevel();
/**
- * {@code true} to fail the build on missing profiles {@code false} otherwise.
- * @param failOnMissingProfiles true/false.
+ * Set the fail level to one of {@link FailLevel}.
+ * @param The FailLevel.
* @return {@link MavenExecutionRequest}
* @since 3.4.0
*/
- MavenExecutionRequest setFailOnMissingProfiles( boolean failOnMissingProfiles );
+ MavenExecutionRequest setFailLevel( FailLevel failLevel );
+ /**
+ * check if FailLevel is {@code WARN}.
+ * @return true if {@link FailLevel} is {@code WARN}.
+ */
+ boolean isFailLevelWARN();
+ /**
+ * check if FailLevel is {@code ERROR}.
+ * @return true if {@link FailLevel} is {@code ERROR}.
+ */
+ boolean isFailLevelERROR();
+
}
http://git-wip-us.apache.org/repos/asf/maven/blob/3b4e13fb/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
index 0fdbefb..d96ebd4 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
@@ -81,7 +81,7 @@ public class CLIManager
public static final String FAIL_NEVER = "fn";
- public static final String FAIL_ON_MISSING_PROFILES = "fomp";
+ public static final String FAIL_LEVEL = "fl";
public static final String RESUME_FROM = "rf";
@@ -142,7 +142,7 @@ public class CLIManager
options.addOption( OptionBuilder.withLongOpt( "threads" ).hasArg().withDescription( "Thread count, for instance 2.0C where C is core multiplied" ).create( THREADS ) );
options.addOption( OptionBuilder.withLongOpt( "legacy-local-repository" ).withDescription( "Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also be activated by using -Dmaven.legacyLocalRepo=true" ).create( LEGACY_LOCAL_REPOSITORY ) );
options.addOption( OptionBuilder.withLongOpt( "builder" ).hasArg().withDescription( "The id of the build strategy to use" ).create( BUILDER ) );
- options.addOption( OptionBuilder.withLongOpt( "fail-on-missing-profiles" ).withDescription( "The build will fail if you are trying to use one or more profiles which do not exist." ).create( FAIL_ON_MISSING_PROFILES ) );
+ options.addOption( OptionBuilder.withLongOpt( "fail-level" ).hasArg().withDescription( "Fail the build if XXXX" ).create( FAIL_LEVEL ) );
// Adding this back in for compatibility with the verifier that hard codes this option.
options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription( "Ineffective, only kept for backward compatibility" ).create( "npr" ) );
http://git-wip-us.apache.org/repos/asf/maven/blob/3b4e13fb/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 0b070b7..17f1061 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -41,6 +41,7 @@ import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.UnrecognizedOptionException;
@@ -74,6 +75,7 @@ import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.ExecutionListener;
import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest.FailLevel;
import org.apache.maven.execution.MavenExecutionRequestPopulationException;
import org.apache.maven.execution.MavenExecutionRequestPopulator;
import org.apache.maven.execution.MavenExecutionResult;
@@ -109,9 +111,6 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import com.google.common.base.Charsets;
-import com.google.common.io.Files;
-import com.google.inject.AbstractModule;
import org.eclipse.aether.transfer.TransferListener;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
@@ -122,6 +121,10 @@ import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import org.sonatype.plexus.components.sec.dispatcher.SecUtil;
import org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity;
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+import com.google.inject.AbstractModule;
+
// TODO: push all common bits back to plexus cli and prepare for transition to Guice. We don't need 50 ways to make CLIs
/**
@@ -1616,9 +1619,21 @@ public class MavenCli
}
}
- if ( commandLine.hasOption( CLIManager.FAIL_ON_MISSING_PROFILES ) )
+ if ( commandLine.hasOption( CLIManager.FAIL_LEVEL ) )
{
- request.setFailOnMissingProfiles( true );
+ String failLevelString = commandLine.getOptionValue( CLIManager.FAIL_LEVEL );
+
+ FailLevel valueOf;
+ try
+ {
+ valueOf = MavenExecutionRequest.FailLevel.valueOf( failLevelString.toUpperCase() );
+ }
+ catch ( Exception e )
+ {
+ throw new IllegalArgumentException("The given value for --fail-level is not allowed. Only WARN or ERROR is allowed.");
+ }
+
+ request.setFailLevel( valueOf );
}
//