Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/main/java/org/codehaus/plexus/build/BuildContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@
* <p>BuildContext interface.</p>
*/
public interface BuildContext {
/** Constant <code>SEVERITY_WARNING=1</code> */
/**
* Constant <code>SEVERITY_WARNING=1</code>
* @deprecated Use {@link Severity#WARNING} instead
*/
@Deprecated
int SEVERITY_WARNING = 1;

/** Constant <code>SEVERITY_ERROR=2</code> */
/**
* Constant <code>SEVERITY_ERROR=2</code>
* @deprecated Use {@link Severity#ERROR} instead
*/
@Deprecated
int SEVERITY_ERROR = 2;

// TODO should we add File getBasedir()?
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);

/**
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,34 +163,42 @@ 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) {
return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + 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:
logger.debug(getMessage(file, line, column, message), cause);
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} */
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/org/codehaus/plexus/build/Severity.java
Original file line number Diff line number Diff line change
@@ -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);
}
}