diff --git a/src/main/java/org/codehaus/plexus/build/BuildContext.java b/src/main/java/org/codehaus/plexus/build/BuildContext.java index e13b37d..2036ac2 100644 --- a/src/main/java/org/codehaus/plexus/build/BuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/BuildContext.java @@ -24,10 +24,18 @@ *
BuildContext interface.
*/ public interface BuildContext { - /** ConstantSEVERITY_WARNING=1 */
+ /**
+ * Constant SEVERITY_WARNING=1
+ * @deprecated Use {@link Severity#WARNING} instead
+ */
+ @Deprecated
int SEVERITY_WARNING = 1;
- /** Constant SEVERITY_ERROR=2 */
+ /**
+ * Constant SEVERITY_ERROR=2
+ * @deprecated Use {@link Severity#ERROR} instead
+ */
+ @Deprecated
int SEVERITY_ERROR = 2;
// TODO should we add File getBasedir()?
@@ -201,6 +209,20 @@ public interface BuildContext {
*/
void addError(File file, int line, int column, String message, Throwable cause);
+ /**
+ * Adds a message to the build context. The message is associated with a file and a location inside that file.
+ *
+ * @param file The file or folder with which the message is associated. Should not be null and it is recommended to be
+ * an absolute path.
+ * @param line The line number inside the file. Use 1 (not 0) for the first line. Use 0 for unknown/unspecified.
+ * @param column The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified.
+ * @param severity The severity of the message.
+ * @param cause A Throwable object associated with the message. Can be null.
+ * @since 1.2.1
+ * @param message a {@link java.lang.String} object.
+ */
+ void addMessage(File file, int line, int column, String message, Severity severity, Throwable cause);
+
/**
* Adds a message to the build context. The message is associated with a file and a location inside that file.
*
@@ -210,9 +232,11 @@ public interface BuildContext {
* @param column The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified.
* @param severity The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR.
* @param cause A Throwable object associated with the message. Can be null.
+ * @deprecated Use {@link #addMessage(File, int, int, String, Severity, Throwable)} instead
* @since 0.0.7
* @param message a {@link java.lang.String} object.
*/
+ @Deprecated
void addMessage(File file, int line, int column, String message, int severity, Throwable cause);
/**
diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java
index 2b34e71..b743ae5 100644
--- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java
+++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java
@@ -163,12 +163,12 @@ public void setValue(String key, Object value) {
/** {@inheritDoc} */
public void addError(File file, int line, int column, String message, Throwable cause) {
- addMessage(file, line, column, message, SEVERITY_ERROR, cause);
+ addMessage(file, line, column, message, Severity.ERROR, cause);
}
/** {@inheritDoc} */
public void addWarning(File file, int line, int column, String message, Throwable cause) {
- addMessage(file, line, column, message, SEVERITY_WARNING, cause);
+ addMessage(file, line, column, message, Severity.WARNING, cause);
}
private String getMessage(File file, int line, int column, String message) {
@@ -176,13 +176,14 @@ private String getMessage(File file, int line, int column, String message) {
}
/** {@inheritDoc} */
- public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {
+ @Override
+ public void addMessage(File file, int line, int column, String message, Severity severity, Throwable cause) {
if (isDefaultImplementation()) {
switch (severity) {
- case BuildContext.SEVERITY_ERROR:
+ case ERROR:
logger.error(getMessage(file, line, column, message), cause);
return;
- case BuildContext.SEVERITY_WARNING:
+ case WARNING:
logger.warn(getMessage(file, line, column, message), cause);
return;
default:
@@ -190,7 +191,14 @@ public void addMessage(File file, int line, int column, String message, int seve
return;
}
}
- legacy.addMessage(file, line, column, message, severity, cause);
+ legacy.addMessage(file, line, column, message, severity.getValue(), cause);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Deprecated
+ public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {
+ addMessage(file, line, column, message, Severity.fromValue(severity), cause);
}
/** {@inheritDoc} */
diff --git a/src/main/java/org/codehaus/plexus/build/Severity.java b/src/main/java/org/codehaus/plexus/build/Severity.java
new file mode 100644
index 0000000..7ba55f8
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/build/Severity.java
@@ -0,0 +1,62 @@
+/*
+Copyright (c) 2008 Sonatype, Inc. All rights reserved.
+
+This program is licensed to you under the Apache License Version 2.0,
+and you may not use this file except in compliance with the Apache License Version 2.0.
+You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the Apache License Version 2.0 is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
+*/
+package org.codehaus.plexus.build;
+
+/**
+ * Severity levels for build messages.
+ *
+ * @since 1.2.1
+ */
+public enum Severity {
+ /**
+ * Warning severity level.
+ */
+ WARNING(1),
+
+ /**
+ * Error severity level.
+ */
+ ERROR(2);
+
+ private final int value;
+
+ Severity(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the legacy integer value for this severity level.
+ * This is provided for backward compatibility.
+ *
+ * @return the integer value
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Converts a legacy integer severity value to a Severity enum.
+ *
+ * @param value the integer severity value
+ * @return the corresponding Severity enum value
+ * @throws IllegalArgumentException if the value doesn't correspond to a known severity
+ */
+ public static Severity fromValue(int value) {
+ for (Severity severity : values()) {
+ if (severity.value == value) {
+ return severity;
+ }
+ }
+ throw new IllegalArgumentException("Unknown severity value: " + value);
+ }
+}