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