Skip to content

Commit 99115dd

Browse files
Copilotlaeubi
andcommitted
Address review feedback: shorter method names, package-private constructor, copyright removal, create(String message)
Co-authored-by: laeubi <[email protected]>
1 parent 738c950 commit 99115dd

File tree

7 files changed

+23
-43
lines changed

7 files changed

+23
-43
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ private Messages messages;
5252

5353
public void execute() {
5454
// Create an error message
55-
messages.buildError(Paths.get("/path/to/file.java"))
55+
messages.error(Paths.get("/path/to/file.java"))
5656
.line(42)
5757
.column(10)
58-
.message("Syntax error")
5958
.cause(exception)
60-
.create();
59+
.create("Syntax error");
6160

6261
// Create a warning message
63-
messages.buildWarning(Paths.get("/path/to/file.java"))
62+
messages.warning(Paths.get("/path/to/file.java"))
6463
.line(15)
65-
.message("Deprecated method used")
66-
.create();
64+
.create("Deprecated method used");
6765

6866
// Clear messages for a specific file
6967
messages.clear(Paths.get("/path/to/file.java"));

src/main/java/org/codehaus/plexus/build/BuildContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public interface BuildContext {
209209
* @param cause A Throwable object associated with the message. Can be null.
210210
* @since 0.0.7
211211
* @param message a {@link java.lang.String} object.
212+
* @deprecated Use {@link org.codehaus.plexus.build.messages.Messages} API instead
212213
*/
213214
void addMessage(File file, int line, int column, String message, int severity, Throwable cause);
214215

@@ -218,6 +219,7 @@ public interface BuildContext {
218219
*
219220
* @since 0.0.7
220221
* @param file a {@link java.io.File} object.
222+
* @deprecated Use {@link org.codehaus.plexus.build.messages.Messages#clear(java.nio.file.Path)} instead
221223
*/
222224
void removeMessages(File file);
223225

src/main/java/org/codehaus/plexus/build/messages/DefaultMessages.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3-
42
This program is licensed to you under the Apache License Version 2.0,
53
and you may not use this file except in compliance with the Apache License Version 2.0.
64
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
@@ -62,17 +60,17 @@ public void clear(Path path) {
6260
}
6361

6462
@Override
65-
public MessageBuilder buildError(Path path) {
63+
public MessageBuilder error(Path path) {
6664
return build(MessageType.ERROR, path);
6765
}
6866

6967
@Override
70-
public MessageBuilder buildWarning(Path path) {
68+
public MessageBuilder warning(Path path) {
7169
return build(MessageType.WARNING, path);
7270
}
7371

7472
@Override
75-
public MessageBuilder buildInfo(Path path) {
73+
public MessageBuilder info(Path path) {
7674
return build(MessageType.INFO, path);
7775
}
7876

@@ -167,10 +165,8 @@ private int mapTypeToSeverity(MessageType type) {
167165
return BuildContext.SEVERITY_WARNING;
168166
case INFO:
169167
default:
170-
// There's no INFO severity in BuildContext (only WARNING and ERROR),
171-
// so we map INFO messages to WARNING to ensure they are still visible in the IDE.
172-
// Custom implementations may provide different mappings.
173-
return BuildContext.SEVERITY_WARNING;
168+
// BuildContext supports 0 as an info severity level (undocumented)
169+
return 0;
174170
}
175171
}
176172
}

src/main/java/org/codehaus/plexus/build/messages/Message.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3-
42
This program is licensed to you under the Apache License Version 2.0,
53
and you may not use this file except in compliance with the Apache License Version 2.0.
64
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
@@ -36,7 +34,7 @@ public class Message {
3634
* @param message the message text
3735
* @param cause the exception cause, can be null
3836
*/
39-
public Message(MessageType type, Path path, int line, int column, String message, Throwable cause) {
37+
Message(MessageType type, Path path, int line, int column, String message, Throwable cause) {
4038
this.type = type;
4139
this.path = path;
4240
this.line = line;

src/main/java/org/codehaus/plexus/build/messages/MessageBuilder.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3-
42
This program is licensed to you under the Apache License Version 2.0,
53
and you may not use this file except in compliance with the Apache License Version 2.0.
64
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
@@ -30,7 +28,6 @@ public class MessageBuilder {
3028

3129
private int line = 0;
3230
private int column = 0;
33-
private String message;
3431
private Throwable cause;
3532

3633
/**
@@ -72,17 +69,6 @@ public MessageBuilder column(int column) {
7269
return this;
7370
}
7471

75-
/**
76-
* Sets the message text.
77-
*
78-
* @param message the message text
79-
* @return this builder for method chaining
80-
*/
81-
public MessageBuilder message(String message) {
82-
this.message = message;
83-
return this;
84-
}
85-
8672
/**
8773
* Sets the exception cause for the message.
8874
*
@@ -97,8 +83,13 @@ public MessageBuilder cause(Throwable cause) {
9783
/**
9884
* Creates the message object with all collected parameters and informs the consumer.
9985
* This method finalizes the builder and creates the message.
86+
*
87+
* @param message the message text (must not be null or blank)
10088
*/
101-
public void create() {
89+
public void create(String message) {
90+
if (message == null || message.trim().isEmpty()) {
91+
throw new IllegalArgumentException("Message text must not be null or blank");
92+
}
10293
Message msg = new Message(type, path, line, column, message, cause);
10394
consumer.accept(msg);
10495
}

src/main/java/org/codehaus/plexus/build/messages/MessageType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3-
42
This program is licensed to you under the Apache License Version 2.0,
53
and you may not use this file except in compliance with the Apache License Version 2.0.
64
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.

src/main/java/org/codehaus/plexus/build/messages/Messages.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3-
42
This program is licensed to you under the Apache License Version 2.0,
53
and you may not use this file except in compliance with the Apache License Version 2.0.
64
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
@@ -26,11 +24,10 @@
2624
* Example usage:
2725
* </p>
2826
* <pre>
29-
* messages.buildError(Paths.get("/path/to/file.java"))
27+
* messages.error(Paths.get("/path/to/file.java"))
3028
* .line(42)
3129
* .column(10)
32-
* .message("Syntax error")
33-
* .create();
30+
* .create("Syntax error");
3431
* </pre>
3532
*/
3633
public interface Messages {
@@ -54,23 +51,23 @@ public interface Messages {
5451
* @param path the file path for which the error message should be created
5552
* @return a MessageBuilder for constructing the error message
5653
*/
57-
MessageBuilder buildError(Path path);
54+
MessageBuilder error(Path path);
5855

5956
/**
6057
* Creates a builder for a warning message.
6158
*
6259
* @param path the file path for which the warning message should be created
6360
* @return a MessageBuilder for constructing the warning message
6461
*/
65-
MessageBuilder buildWarning(Path path);
62+
MessageBuilder warning(Path path);
6663

6764
/**
6865
* Creates a builder for an informational message.
6966
*
7067
* @param path the file path for which the info message should be created
7168
* @return a MessageBuilder for constructing the info message
7269
*/
73-
MessageBuilder buildInfo(Path path);
70+
MessageBuilder info(Path path);
7471

7572
/**
7673
* Creates a builder for a message of a specific type.

0 commit comments

Comments
 (0)