View Javadoc
1   package org.apache.maven.plugins.assembly.functions;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.ArtifactUtils;
24  import org.apache.maven.project.MavenProject;
25  import org.slf4j.Logger;
26  
27  import java.util.List;
28  import java.util.Set;
29  
30  /**
31   *
32   */
33  public class MavenProjects
34  {
35      public static void without( Iterable<MavenProject> source, String packagingType, MavenProjectConsumer consumer )
36      {
37          for ( MavenProject project : source )
38          {
39              if ( !packagingType.equals( project.getPackaging() ) )
40              {
41                  consumer.accept( project );
42              }
43          }
44      }
45  
46      public static void select( Iterable<MavenProject> source, String packagingType, MavenProjectConsumer consumer )
47      {
48          for ( MavenProject project : source )
49          {
50              if ( packagingType.equals( project.getPackaging() ) )
51              {
52                  consumer.accept( project );
53              }
54          }
55      }
56  
57      public static void select( Iterable<MavenProject> source, String packagingType, MavenProjectConsumer include,
58                                 MavenProjectConsumer excluded )
59      {
60          for ( MavenProject project : source )
61          {
62              if ( packagingType.equals( project.getPackaging() ) )
63              {
64                  include.accept( project );
65              }
66              else
67              {
68                  excluded.accept( project );
69              }
70          }
71      }
72  
73      public static Artifact findArtifactByClassifier( MavenProject mavenProject, String classifier )
74      {
75          final List<Artifact> attachments = mavenProject.getAttachedArtifacts();
76          if ( ( attachments != null ) && !attachments.isEmpty() )
77          {
78              for ( final Artifact attachment : attachments )
79              {
80                  if ( classifier.equals( attachment.getClassifier() ) )
81                  {
82                      return attachment;
83                  }
84              }
85          }
86          return null;
87      }
88  
89  
90      public static MavenProjectConsumer log( final Logger logger )
91      {
92          return new MavenProjectConsumer()
93          {
94              @Override
95              public void accept( MavenProject project )
96              {
97                  final String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
98  
99                  logger.debug( "Excluding POM-packaging module: " + projectId );
100             }
101         };
102     }
103 
104     public static MavenProjectConsumer addTo( final Set<MavenProject> set )
105     {
106         return new MavenProjectConsumer()
107         {
108             @Override
109             public void accept( MavenProject project )
110             {
111                 set.add( project );
112             }
113         };
114     }
115 
116 }