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(".checkstyle",
54                      ".classpath",//
55                      ".project", //
56                      ".settings/**/*"));
57  
58      /**
59       * The IDEA specific default excludes.
60       */
61      static final List<String> IDEA_DEFAULT_EXCLUDES = Collections
62              .unmodifiableList(Arrays.asList(//
63                      "*.iml", //
64                      "*.ipr", //
65                      "*.iws", //
66                      ".idea/**/*"));
67  
68      public static void addPlexusAndScmDefaults(Log log, final boolean useDefaultExcludes,
69                                                 final Set<String> excludeList1) {
70          if (useDefaultExcludes) {
71              log.debug("Adding plexus default exclusions...");
72              Collections.addAll(excludeList1, DirectoryScanner.DEFAULTEXCLUDES);
73              log.debug("Adding SCM default exclusions...");
74              excludeList1.addAll(//
75                      SourceCodeManagementSystems.getPluginExclusions());
76          } else {
77              log.debug("rat.useDefaultExcludes set to false. "
78                      + "Plexus and SCM default exclusions will not be added");
79          }
80      }
81  
82      public static void addMavenDefaults(Log log, boolean useMavenDefaultExcludes,
83                                          final Set<String> excludeList) {
84          if (useMavenDefaultExcludes) {
85              log.debug("Adding exclusions often needed by Maven projects...");
86              excludeList.addAll(MAVEN_DEFAULT_EXCLUDES);
87          } else {
88              log.debug("rat.useMavenDefaultExcludes set to false. "
89                      + "Exclusions often needed by Maven projects will not be added.");
90          }
91      }
92  
93      public static void addEclipseDefaults(Log log, boolean useEclipseDefaultExcludes,
94                                            final Set<String> excludeList) {
95          if (useEclipseDefaultExcludes) {
96              log.debug("Adding exclusions often needed by projects "
97                      + "developed in Eclipse...");
98              excludeList.addAll(ECLIPSE_DEFAULT_EXCLUDES);
99          } else {
100             log.debug("rat.useEclipseDefaultExcludes set to false. "
101                     + "Exclusions often needed by projects developed in "
102                     + "Eclipse will not be added.");
103         }
104     }
105 
106     public static void addIdeaDefaults(Log log, boolean useIdeaDefaultExcludes,
107                                        final Set<String> excludeList) {
108         if (useIdeaDefaultExcludes) {
109             log.debug("Adding exclusions often needed by projects "
110                     + "developed in IDEA...");
111             excludeList.addAll(IDEA_DEFAULT_EXCLUDES);
112         } else {
113             log.debug("rat.useIdeaDefaultExcludes set to false. "
114                     + "Exclusions often needed by projects developed in "
115                     + "IDEA will not be added.");
116         }
117     }
118 
119 }