SettingsParserException.java
/*
* 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.maven.api.spi;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.services.MavenException;
/**
* A syntax error in a settings source, with optional one-based line and column numbers.
* If no message is supplied, the cause's message is used when available, otherwise a
* default message is used. Messages, including those from causes, should not contain
* credentials from the input.
*
* @since 4.1.0
*/
@Experimental
public class SettingsParserException extends MavenException {
/**
* The one-based index of the line containing the error.
*/
private final int lineNumber;
/**
* The one-based index of the column containing the error.
*/
private final int columnNumber;
public SettingsParserException() {
this(null, null);
}
public SettingsParserException(String message) {
this(message, null);
}
public SettingsParserException(String message, Throwable cause) {
this(message, -1, -1, cause);
}
public SettingsParserException(String message, int lineNumber, int columnNumber, Throwable cause) {
super(messageOrDefault(message, cause), cause);
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
}
public SettingsParserException(Throwable cause) {
this(null, cause);
}
private static String messageOrDefault(String message, Throwable cause) {
if (message != null) {
return message;
}
if (cause != null && cause.getMessage() != null) {
return cause.getMessage();
}
return "Unknown settings parsing error";
}
public int getLineNumber() {
return lineNumber;
}
public int getColumnNumber() {
return columnNumber;
}
}