Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.plugins.help;
  
  /*
   * 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 java.util.Date;
 import java.util.List;
 import java.util.Map;
 
Displays a list of the profiles which are currently active for this build.

Version:
$Id: ActiveProfilesMojo.java 1446806 2013-02-15 23:07:28Z rfscholte $
Since:
2.0
 
 @Mojo( name = "active-profiles", aggregator = true )
 public class ActiveProfilesMojo
     extends AbstractHelpMojo
 {
     // ----------------------------------------------------------------------
     // Mojo parameters
     // ----------------------------------------------------------------------
 
    
This is the list of projects currently slated to be built by Maven.
 
     @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
     private List<MavenProjectprojects;
 
     // ----------------------------------------------------------------------
     // Public methods
     // ----------------------------------------------------------------------
 
    
 
     public void execute()
         throws MojoExecutionException
     {
         StringBuilder message = new StringBuilder();
 
         for ( MavenProject project :  )
         {
             getActiveProfileStatementprojectmessage );
 
             message.append"\n\n" );
         }
 
         if (  != null )
         {
             StringBuilder sb = new StringBuilder();
             sb.append"Created by: " + getClass().getName() ).append"\n" );
             sb.append"Created on: " + new Date() ).append"\n" ).append"\n" );
             sb.appendmessage.toString() );
 
             try
             {
                 writeFilesb );
             }
             catch ( IOException e )
             {
                 throw new MojoExecutionException"Cannot write active profiles to output: " + e );
             }
 
             if ( getLog().isInfoEnabled() )
             {
                 getLog().info"Active profile report written to: " +  );
             }
         }
         else
         {
             if ( getLog().isInfoEnabled() )
             {
                 getLog().infomessage );
            }
        }
    }
    // ----------------------------------------------------------------------
    // Private methods
    // ----------------------------------------------------------------------

    
Method to get the active profiles for the project

Parameters:
project the current project
message the object where the information will be appended to
    private void getActiveProfileStatementMavenProject projectStringBuilder message )
    {
        Map<StringList<String>> activeProfileIds = new LinkedHashMap<StringList<String>>();
        try 
        {
            activeProfileIds.putAllgetInjectedProfileIdsproject ) );
        }
        catch ( UnsupportedOperationException uoe )
        {
            // Fall back to M2 approach
            @SuppressWarnings"unchecked" )
            List<Profileprofiles = new ArrayList<Profile>( project.getActiveProfiles() );
            
            for ( Profile profile : profiles )
            {
                List<StringprofileIds = activeProfileIds.getprofile.getSource() );
                if ( profileIds == null )
                {
                    profileIds = new ArrayList<String>();
                    activeProfileIds.putprofile.getSource(), profileIds );
                }
                profileIds.addprofile.getId() );
            }
        }
        
        message.append"\n" );
        message.append"Active Profiles for Project \'" + project.getId() + "\': \n\n" );
        if ( activeProfileIds.isEmpty() )
        {
            message.append"There are no active profiles." );
        }
        else
        {
            message.append"The following profiles are active:\n" );
            for ( Map.Entry<StringList<String>> entry : activeProfileIds.entrySet() )
            {
                for ( String profileId : entry.getValue() )
                {
                    message.append"\n - " ).appendprofileId );
                    message.append" (source: " ).appendentry.getKey() ).append")" );
                }
            }
        }
        message.append"\n" );
    }
    @SuppressWarnings"unchecked" )
    {
        try
        {
            // This method was introduced with M3
            Method getInjectedProfileIdsMethod = MavenProject.class.getMethod"getInjectedProfileIds" );
            return (Map<StringList<String>>) getInjectedProfileIdsMethod.invokeproject );
        }
        catch ( SecurityException e )
        {
            throw new UnsupportedOperationExceptione.getMessage(), e );
        }
        catch ( NoSuchMethodException e )
        {
            throw new UnsupportedOperationExceptione.getMessage(), e );
        }
        catch ( IllegalArgumentException e )
        {
            throw new UnsupportedOperationExceptione.getMessage(), e );
        }
        catch ( IllegalAccessException e )
        {
            throw new UnsupportedOperationExceptione.getMessage(), e );
        }
        catch ( InvocationTargetException e )
        {
            throw new UnsupportedOperationExceptione.getMessage(), e );
        }
    }
New to GrepCode? Check out our FAQ X