code: @SuppressWarnings( "unchecked" )
      private List<String> findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle )
          throws LifecycleExecutionException, PluginNotFoundException
      {
          String packaging = project.getPackaging();
          List<String> optionalMojos = null;
  
          LifecycleMapping m =
              (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(),
                                                session.getLocalRepository() );
  
          if ( m != null )
          {
              optionalMojos = m.getOptionalMojos( lifecycle.getId() );
          }
  
          if ( optionalMojos == null )
          {
              try
              {
                  m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
                  optionalMojos = m.getOptionalMojos( lifecycle.getId() );
              }
              catch ( ComponentLookupException e )
              {
                  log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: "
                      + lifecycle.getId() + ". Error: " + e.getMessage(), e );
              }
          }
  
          if ( optionalMojos == null )
          {
              optionalMojos = Collections.emptyList();
          }
  
          return optionalMojos;
      }
docs: Find optional mojos for lifecycle.
  
  @param project the project
  @param lifecycle the lifecycle
  @return the list
  @throws LifecycleExecutionException the lifecycle execution exception
  @throws PluginNotFoundException the plugin not found exception