Line data Source code
1 : // Copyright (C) 2020 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server; 16 : 17 : import com.google.gerrit.entities.Project; 18 : import org.eclipse.jgit.errors.ConfigInvalidException; 19 : import org.eclipse.jgit.lib.ObjectId; 20 : 21 : /** Exception that is thrown if an invalid config file causes an error. */ 22 : public class InvalidConfigFileException extends ConfigInvalidException { 23 : private static final long serialVersionUID = 1L; 24 : 25 : private final String fileName; 26 : 27 : public InvalidConfigFileException( 28 : Project.NameKey projectName, 29 : String branchName, 30 : ObjectId revision, 31 : String fileName, 32 : ConfigInvalidException cause) { 33 4 : super(createMessage(projectName, branchName, revision, fileName, cause), cause); 34 4 : this.fileName = fileName; 35 4 : } 36 : 37 : public String getFileName() { 38 1 : return fileName; 39 : } 40 : 41 : private static String createMessage( 42 : Project.NameKey projectName, 43 : String branchName, 44 : ObjectId revision, 45 : String fileName, 46 : ConfigInvalidException cause) { 47 4 : StringBuilder msg = 48 : new StringBuilder("Invalid config file ") 49 4 : .append(fileName) 50 4 : .append(" in project ") 51 4 : .append(projectName.get()) 52 4 : .append(" in branch ") 53 4 : .append(branchName) 54 4 : .append(" in commit ") 55 4 : .append(revision.name()); 56 4 : if (cause != null) { 57 4 : msg.append(": ").append(cause.getMessage()); 58 : } 59 4 : return msg.toString(); 60 : } 61 : }