View Javadoc
1   package org.apache.rat.mp.util;
2   
3   import org.apache.maven.plugin.logging.Log;
4   import org.apache.rat.config.SourceCodeManagementSystems;
5   import org.codehaus.plexus.util.DirectoryScanner;
6   
7   import java.util.Arrays;
8   import java.util.Collections;
9   import java.util.List;
10  import java.util.Set;
11  
12  /*
13   * Licensed to the Apache Software Foundation (ASF) under one
14   * or more contributor license agreements.  See the NOTICE file
15   * distributed with this work for additional information
16   * regarding copyright ownership.  The ASF licenses this file
17   * to you under the Apache License, Version 2.0 (the
18   * "License"); you may not use this file except in compliance
19   * with the License.  You may obtain a copy of the License at
20   *
21   *   http://www.apache.org/licenses/LICENSE-2.0
22   *
23   * Unless required by applicable law or agreed to in writing,
24   * software distributed under the License is distributed on an
25   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26   * KIND, either express or implied.  See the License for the
27   * specific language governing permissions and limitations
28   * under the License.
29   */
30  
31  /**
32   * This class encapsulates the file/directory exclusion handling of RAT.
33   * Visibility is to allow testing and usage in the maven plugin itself.
34   */
35  public final class ExclusionHelper {
36      /**
37       * The Maven specific default excludes.
38       */
39      static final List<String> MAVEN_DEFAULT_EXCLUDES = Collections
40              .unmodifiableList(Arrays.asList(//
41                      "target/**/*", //
42                      "cobertura.ser", //
43                      "release.properties", //
44                      ".repository", // Used by Jenkins when a Maven job uses a private repository that is "Local to the workspace"
45                      "build.log", // RAT-160: until now maven-invoker-plugin runs create a build.log that is not part of a release
46                      ".mvn", // Project configuration since Maven 3.3.1 which contains maven.config, jvm.config, extensions.xml
47                      "pom.xml.releaseBackup"));
48  
49      /**
50       * The Eclipse specific default excludes.
51       */
52      static final List<String> ECLIPSE_DEFAULT_EXCLUDES = Collections
53              .unmodifiableList(Arrays.asList(".classpath",//
54                      ".project", //
55                      ".settings/**/*"));
56  
57      /**
58       * The IDEA specific default excludes.
59       */
60      static final List<String> IDEA_DEFAULT_EXCLUDES = Collections
61              .unmodifiableList(Arrays.asList(//
62                      "*.iml", //
63                      "*.ipr", //
64                      "*.iws", //
65                      ".idea/**/*"));
66  
67      public static void addPlexusAndScmDefaults(Log log, final boolean useDefaultExcludes,
68                                                 final Set<String> excludeList1) {
69          if (useDefaultExcludes) {
70              log.debug("Adding plexus default exclusions...");
71              Collections.addAll(excludeList1, DirectoryScanner.DEFAULTEXCLUDES);
72              log.debug("Adding SCM default exclusions...");
73              excludeList1.addAll(//
74                      SourceCodeManagementSystems.getPluginExclusions());
75          } else {
76              log.debug("rat.useDefaultExcludes set to false. "
77                      + "Plexus and SCM default exclusions will not be added");
78          }
79      }
80  
81      public static void addMavenDefaults(Log log, boolean useMavenDefaultExcludes,
82                                          final Set<String> excludeList) {
83          if (useMavenDefaultExcludes) {
84              log.debug("Adding exclusions often needed by Maven projects...");
85              excludeList.addAll(MAVEN_DEFAULT_EXCLUDES);
86          } else {
87              log.debug("rat.useMavenDefaultExcludes set to false. "
88                      + "Exclusions often needed by Maven projects will not be added.");
89          }
90      }
91  
92      public static void addEclipseDefaults(Log log, boolean useEclipseDefaultExcludes,
93                                            final Set<String> excludeList) {
94          if (useEclipseDefaultExcludes) {
95              log.debug("Adding exclusions often needed by projects "
96                      + "developed in Eclipse...");
97              excludeList.addAll(ECLIPSE_DEFAULT_EXCLUDES);
98          } else {
99              log.debug("rat.useEclipseDefaultExcludes set to false. "
100                     + "Exclusions often needed by projects developed in "
101                     + "Eclipse will not be added.");
102         }
103     }
104 
105     public static void addIdeaDefaults(Log log, boolean useIdeaDefaultExcludes,
106                                        final Set<String> excludeList) {
107         if (useIdeaDefaultExcludes) {
108             log.debug("Adding exclusions often needed by projects "
109                     + "developed in IDEA...");
110             excludeList.addAll(IDEA_DEFAULT_EXCLUDES);
111         } else {
112             log.debug("rat.useIdeaDefaultExcludes set to false. "
113                     + "Exclusions often needed by projects developed in "
114                     + "IDEA will not be added.");
115         }
116     }
117 
118 }