From d740bc3d313dde5b1e2a95c464eb36a1515fc9f4 Mon Sep 17 00:00:00 2001 From: mguillem Date: Thu, 12 Aug 2021 16:43:51 +0200 Subject: [PATCH] JENKINS-54128 remove call to deprecated Run.getLogFile --- .../linenumbers/LineNumbersAnnotator.java | 29 ++++++++----------- .../LineNumbersAnnotatorFactory.java | 19 ++++++------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotator.java b/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotator.java index a6becb7..9f7c772 100644 --- a/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotator.java +++ b/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotator.java @@ -1,20 +1,18 @@ /* * The MIT License - * - * Copyright (c) 20import hudson.MarkupText; -import hudson.console.ConsoleAnnotator; -import hudson.model.Run; - -import java.text.MessageFormat; -d associated documentation files (the "Software"), to deal + * + * Copyright (c) 2014, Vincent Latombe + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,7 +29,7 @@ d associated documentation files (the "Software"), to deal import java.text.MessageFormat; -public class LineNumbersAnnotator extends ConsoleAnnotator { +public class LineNumbersAnnotator extends ConsoleAnnotator> { private int calls = 0; @@ -44,14 +42,11 @@ public LineNumbersAnnotator(long offset) { } @Override - public ConsoleAnnotator annotate(Object context, MarkupText text) { - if (!(context instanceof Run)) { - return this; - } - Run r = (Run)context; - long start; + public ConsoleAnnotator> annotate(Run r, MarkupText text) { + + final long start; if (offset < 0) { - start = r.getLogFile().length() + offset; + start = r.getLogText().length() + offset; } else { start = offset; } diff --git a/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotatorFactory.java b/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotatorFactory.java index e019d02..87fd00b 100644 --- a/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotatorFactory.java +++ b/src/main/java/org/jenkinsci/plugins/linenumbers/LineNumbersAnnotatorFactory.java @@ -1,18 +1,18 @@ /* * The MIT License - * + * * Copyright (c) 2014, Vincent Latombe - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,20 +26,21 @@ import hudson.Extension; import hudson.console.ConsoleAnnotator; import hudson.console.ConsoleAnnotatorFactory; +import hudson.model.Run; import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.StaplerRequest; /** * Adds line numbers to the console logs as well as bookmarkable anchors - * + * * @author vlatombe - * + * */ @Extension(ordinal = -100) -public class LineNumbersAnnotatorFactory extends ConsoleAnnotatorFactory { +public class LineNumbersAnnotatorFactory extends ConsoleAnnotatorFactory> { @Override - public ConsoleAnnotator newInstance(Object context) { + public ConsoleAnnotator> newInstance(Run context) { long offset = getOffset(Stapler.getCurrentRequest()); return new LineNumbersAnnotator(offset); } @@ -49,7 +50,7 @@ public ConsoleAnnotator newInstance(Object context) { * is from the start of the file, and a negative offset is back from the end * of the file. * Note : Copied from hudson.plugins.timestamper.annotator.TimestampAnnotatorFactory - * + * * @param request * @return the offset in bytes */