You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2013/02/04 23:28:53 UTC
svn commit: r1442405 - in /maven/plugins/trunk/maven-help-plugin/src:
it/active-profiles_multimodule/ it/active-profiles_multimodule/module/
main/java/org/apache/maven/plugins/help/
Author: rfscholte
Date: Mon Feb 4 22:28:52 2013
New Revision: 1442405
URL: http://svn.apache.org/viewvc?rev=1442405&view=rev
Log:
[MPH-79] help:active-profiles does not list active inherited profiles
Added:
maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/
maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/invoker.properties
maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/module/
maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/module/pom.xml
maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/pom.xml
maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/verify.groovy
Modified:
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
Added: maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/invoker.properties?rev=1442405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/invoker.properties (added)
+++ maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/invoker.properties Mon Feb 4 22:28:52 2013
@@ -0,0 +1,2 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:active-profiles
+invoker.maven.version=3.0+
Added: maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/module/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/module/pom.xml?rev=1442405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/module/pom.xml (added)
+++ maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/module/pom.xml Mon Feb 4 22:28:52 2013
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- 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. -->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.its.help</groupId>
+ <artifactId>active-profiles_multimodule</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>active-profiles_multimodule-module</artifactId>
+
+</project>
Added: maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/pom.xml?rev=1442405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/pom.xml (added)
+++ maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/pom.xml Mon Feb 4 22:28:52 2013
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- 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. -->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.help</groupId>
+ <artifactId>active-profiles_multimodule</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>module</module>
+ </modules>
+
+ <profiles>
+ <profile>
+ <id>mph79</id>
+ <activation>
+ <file>
+ <exists>pom.xml</exists>
+ </file>
+ </activation>
+ </profile>
+ </profiles>
+</project>
Added: maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/verify.groovy?rev=1442405&view=auto
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/verify.groovy (added)
+++ maven/plugins/trunk/maven-help-plugin/src/it/active-profiles_multimodule/verify.groovy Mon Feb 4 22:28:52 2013
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+def buildLog = new File( basedir, 'build.log' );
+assert buildLog.exists()
+
+assert 2 == buildLog.text.count( ' - mph79 (source: org.apache.maven.its.help:active-profiles_multimodule:1.0-SNAPSHOT)' )
Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java?rev=1442405&r1=1442404&r2=1442405&view=diff
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java (original)
+++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java Mon Feb 4 22:28:52 2013
@@ -19,17 +19,21 @@ package org.apache.maven.plugins.help;
* under the License.
*/
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.maven.model.Profile;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
/**
* Displays a list of the profiles which are currently active for this build.
*
@@ -109,16 +113,35 @@ public class ActiveProfilesMojo
*/
private void getActiveProfileStatement( MavenProject project, StringBuilder message )
{
- // Get active profiles into our own list,
- // since we'll be modifying it, further below
- @SuppressWarnings( "unchecked" )
- List<Profile> profiles = new ArrayList<Profile>( project.getActiveProfiles() );
+ Map<String, List<String>> activeProfileIds = new LinkedHashMap<String, List<String>>();
+ try
+ {
+ activeProfileIds.putAll( getInjectedProfileIds( project ) );
+ }
+ catch ( UnsupportedOperationException uoe )
+ {
+ // Fall back to M2 approach
+ @SuppressWarnings( "unchecked" )
+ List<Profile> profiles = new ArrayList<Profile>( project.getActiveProfiles() );
+
+ for( Profile profile : profiles )
+ {
+ List<String> profileIds = activeProfileIds.get( profile.getSource() );
+ if( profileIds == null )
+ {
+ profileIds = new ArrayList<String>();
+ activeProfileIds.put( profile.getSource(), profileIds );
+ }
+ profileIds.add( profile.getId() );
+ }
+ }
+
message.append( "\n" );
message.append( "Active Profiles for Project \'" + project.getId() + "\': \n\n" );
- if ( profiles == null || profiles.isEmpty() )
+ if ( activeProfileIds.isEmpty() )
{
message.append( "There are no active profiles." );
}
@@ -126,14 +149,47 @@ public class ActiveProfilesMojo
{
message.append( "The following profiles are active:\n" );
- for ( Profile profile : profiles )
+ for ( Map.Entry<String, List<String>> entry : activeProfileIds.entrySet() )
{
- message.append( "\n - " ).append( profile.getId() );
- message.append( " (source: " ).append( profile.getSource() ).append( ")" );
+ for ( String profileId : entry.getValue() )
+ {
+ message.append( "\n - " ).append( profileId );
+ message.append( " (source: " ).append( entry.getKey() ).append( ")" );
+ }
}
-
}
message.append( "\n" );
}
+
+ @SuppressWarnings( "unchecked" )
+ private Map<String, List<String>> getInjectedProfileIds( MavenProject project ) throws UnsupportedOperationException
+ {
+ try
+ {
+ // This method was introduced with M3
+ Method getInjectedProfileIdsMethod = MavenProject.class.getMethod( "getInjectedProfileIds" );
+ return (Map<String, List<String>>) getInjectedProfileIdsMethod.invoke( project );
+ }
+ catch ( SecurityException e )
+ {
+ throw new UnsupportedOperationException( e.getMessage(), e );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ throw new UnsupportedOperationException( e.getMessage(), e );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ throw new UnsupportedOperationException( e.getMessage(), e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new UnsupportedOperationException( e.getMessage(), e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new UnsupportedOperationException( e.getMessage(), e );
+ }
+ }
}