rmannibucau commented on code in PR #746: URL: https://github.com/apache/creadur-rat/pull/746#discussion_r4252327675
########## apache-rat-core/src/main/java/org/apache/rat/config/exclusion/fileprocessors/GitConfig.java: ########## @@ -0,0 +1,394 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rat.config.exclusion.fileprocessors; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.Set; + +import org.apache.rat.api.EnvVar; + +/** + * Reads the global git configuration files to resolve the file configured + * for {@code core.excludesFile}. + * <p> + * The configuration files are read in git order: {@code $XDG_CONFIG_HOME/git/config} + * first and {@code ~/.gitconfig} second. The last value found for + * {@code core.excludesFile} wins. + * </p> + * <p> + * {@code [include] path} directives are supported and the included files are expanded + * in place, recursively. The relative paths of included files are resolved against the + * directory of the including file, {@code ~/} is expanded to the home directory and a + * depth limit of {@value #MAX_INCLUDE_DEPTH} is enforced like git does. + * </p> + * <p> + * {@code includeIf} directives, the system configuration ({@code /etc/gitconfig}) and the + * repository configuration ({@code .git/config}) are not supported. + * </p> + * <p> + * When {@code core.excludesFile} is not configured the default location next to the XDG + * configuration ({@code $XDG_CONFIG_HOME/git/ignore} or {@code $HOME/.config/git/ignore}) + * is used. + * </p> + */ +public class GitConfig { + /** The name of the 'core' section. */ + private static final String CORE_SECTION = "core"; + /** The name of the 'include' section. */ + private static final String INCLUDE_SECTION = "include"; + /** The key of the core section holding the global ignore file. */ + private static final String EXCLUDES_FILE_KEY = "excludesfile"; + /** The key of the include section holding the file to include. */ + private static final String INCLUDE_PATH_KEY = "path"; + /** The maximum depth of nested includes, matching the git limit. */ + private static final int MAX_INCLUDE_DEPTH = 10; + /** The home directory prefix of a path. */ + private static final String HOME_PREFIX = "~/"; Review Comment: it is `HOME` too, guess you meant to use `USERPROFILE` or whatever var git is using? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
