1 package org.apache.rat.config; 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 import java.util.ArrayList; 22 import java.util.List; 23 24 public enum SourceCodeManagementSystems { 25 SUBVERSION(".svn", null), // 26 GIT(".git", ".gitignore"), // 27 BAZAAR(".bzr", ".bzrignore"), // 28 MERCURIAL(".hg", ".hgignore"), // 29 CVS("CVS", ".cvsignore") 30 // 31 ; 32 33 /** 34 * Technical directory of that SCM which contains SCM internals. 35 */ 36 private final String directory; 37 /** 38 * If there is a external way to configure files to be ignored: name of this 39 * file, <code>null</code> otherwise. 40 */ 41 private final String ignoreFile; 42 43 SourceCodeManagementSystems(String directory, String ignoreFile) { 44 this.directory = directory; 45 this.ignoreFile = ignoreFile; 46 } 47 48 /** 49 * If an ignore file exists it's added as 50 * 51 * <pre> 52 * *⁄.scm⁄* 53 * </pre> 54 * 55 * . Otherwise the technical directory of the SCM is added as 56 * 57 * <pre> 58 * **⁄.scmignore 59 * </pre> 60 * 61 * to be used as exclusion during RAT runs. 62 * 63 * @return list of excludes if the current SCM is used. 64 */ 65 public List<String> getExclusions() { 66 List<String> excludes = new ArrayList<>(2); 67 68 if (hasIgnoreFile()) { 69 excludes.add("**/" + ignoreFile); 70 } 71 excludes.add("*/" + directory + "/*"); 72 73 return excludes; 74 } 75 76 public boolean hasIgnoreFile() { 77 return ignoreFile != null && !ignoreFile.isEmpty(); 78 } 79 80 /** 81 * Calls {@link #getExclusions()} on each SCM to generate a global list of 82 * exclusions to be used during RAT runs. 83 * 84 * @return the global list of exclusions usable for all known SCM. 85 */ 86 public static List<String> getPluginExclusions() { 87 List<String> pluginExclusions = new ArrayList<>(); 88 89 for (SourceCodeManagementSystems scm : values()) { 90 pluginExclusions.addAll(scm.getExclusions()); 91 } 92 93 return pluginExclusions; 94 } 95 96 /** 97 * Maybe <code>null</code>, check before with 98 * @see #hasIgnoreFile() 99 * 100 * @return the ignore file of the SCM. 101 */ 102 public String getIgnoreFile() { 103 return ignoreFile; 104 } 105 }