Skip to content

Commit

Permalink
jenkinsci#185 Allow identifying ColorizedAction with a String which c…
Browse files Browse the repository at this point in the history
…an be used more broadly and is backwards serializable
  • Loading branch information
tszmytka committed Jul 27, 2020
1 parent a634a55 commit 15be927
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/main/java/hudson/plugins/ansicolor/action/ColorizedAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ColorizedAction extends InvisibleAction {
static final ColorizedAction CONTINUE = new ColorizedAction("", Command.CONTINUE);
static final ColorizedAction IGNORE = new ColorizedAction("", Command.IGNORE);

private final UUID id;
private final String id;

private final String colorMapName;

Expand All @@ -55,12 +55,18 @@ public enum Command {
}

public ColorizedAction(String colorMapName, Command command) {
id = UUID.randomUUID();
id = UUID.randomUUID().toString();
this.colorMapName = colorMapName == null || colorMapName.isEmpty() ? AnsiColorMap.DefaultName : colorMapName;
this.command = command;
}

public UUID getId() {
public ColorizedAction(String id, ColorizedAction other) {
this.id = id;
colorMapName = other.colorMapName;
command = other.command;
}

public String getId() {
return id;
}

Expand All @@ -79,8 +85,12 @@ public static ColorizedAction parseAction(MarkupText text, Run<?, ?> run) {
final int from = actionIdOffset + TAG_ACTION_BEGIN.length() + 1;
final int to = line.indexOf("\"", from);
final String id = line.substring(from, to);
return run.getActions(ColorizedAction.class).stream().filter(a -> id.equals(a.getId().toString())).findAny().orElse(CONTINUE);
return run.getActions(ColorizedAction.class).stream().filter(a -> id.equals(a.getId())).findAny().orElse(CONTINUE);
}
return line.contains(TAG_PIPELINE_INTERNAL) ? IGNORE : CONTINUE;
}

public static ColorizedAction parseAction(String lineContent, long lineNo, Run<?, ?> run, LineIdentifier lineIdentifier) {
return run.getActions(ColorizedAction.class).stream().filter(a -> lineIdentifier.isEqual(lineContent, lineNo, a.id)).findAny().orElse(CONTINUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ActionNoteTest {

@Before
public void setUp() throws Exception {
when(colorizedAction.getId()).thenReturn(UUID);
when(colorizedAction.getId()).thenReturn(UUID.toString());
actionNote = new ActionNote(colorizedAction);
}

Expand Down

0 comments on commit 15be927

Please sign in to comment.