Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-49237] - Fix escaping of StatisticSummary
- Loading branch information
1 parent
4f43d8d
commit 8309ec9
Showing
10 changed files
with
273 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/hudson/plugins/cppncss/parser/FormattedStatisticSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018 CloudBees, Inc. | ||
* | ||
* 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 | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.cppncss.parser; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* @author Oleg Nenashev | ||
* @since TODO | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public final class FormattedStatisticSummary extends StatisticSummary { | ||
|
||
private final long wasFunctions; | ||
private final long wasNcss; | ||
private final long wasCcn; | ||
private final long functions; | ||
private final long ncss; | ||
private final long ccn; | ||
|
||
public FormattedStatisticSummary(long wasCcn, long wasFunctions, long wasNcss, long ccn, long functions, long ncss) { | ||
this.wasFunctions = wasFunctions; | ||
this.wasNcss = wasNcss; | ||
this.wasCcn = wasCcn; | ||
this.functions = functions; | ||
this.ncss = ncss; | ||
this.ccn = ccn; | ||
} | ||
|
||
public FormattedStatisticSummary(long ccn, long functions, long ncss) { | ||
this(0,0,0, ccn, functions, ncss); | ||
} | ||
|
||
public FormattedStatisticSummary(@Nonnull Statistic was, @Nonnull Statistic now) { | ||
this(was.getCcn(), was.getFunctions(), was.getNcss(), now.getCcn(), now.getFunctions(), now.getNcss()); | ||
} | ||
|
||
public long getCcn() { | ||
return ccn; | ||
} | ||
|
||
public long getFunctions() { | ||
return functions; | ||
} | ||
|
||
public long getNcss() { | ||
return ncss; | ||
} | ||
|
||
private static String diff(long a, long b, String name) { | ||
if (a == b) { | ||
return ""; | ||
} else if (a < b) { | ||
return "<li>" + name + " (+" + (b - a) + ")</li>"; | ||
} else { // if (a < b) | ||
return "<li>" + name + " (-" + (a - b) + ")</li>"; | ||
} | ||
} | ||
|
||
/** | ||
* Converts object to the HTML string | ||
*/ | ||
@Override | ||
public String getHtmlSummary() { | ||
return "<ul>" | ||
+ diff(wasCcn, ccn, "ccn") | ||
+ diff(wasFunctions, functions, "functions") | ||
+ diff(wasCcn, ncss, "ncss") | ||
+ "</ul>"; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("cnn: %s, functions: %s, ncss: %s. Was: %s/%s/%s", ccn, functions, ncss, wasCcn, wasFunctions, wasNcss); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/hudson/plugins/cppncss/parser/StatisticSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018 CloudBees, Inc. | ||
* | ||
* 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 | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.cppncss.parser; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Summary for {@link Statistic}. | ||
* Implementations must have the {@code summary.jelly} file defined. | ||
* | ||
* @since TODO | ||
*/ | ||
public abstract class StatisticSummary { | ||
|
||
/** | ||
* Gets raw HTML summary string | ||
* @return Summary String | ||
*/ | ||
@Nonnull | ||
public abstract String getHtmlSummary(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/hudson/plugins/cppncss/parser/StringStatisticSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018 CloudBees, Inc. | ||
* | ||
* 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 | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.plugins.cppncss.parser; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* @since TODO | ||
* @deprecated Compatibility layer for external class usages. | ||
*/ | ||
@Deprecated | ||
@Restricted(NoExternalUse.class) | ||
public class StringStatisticSummary extends StatisticSummary { | ||
|
||
private final String summary; | ||
|
||
public StringStatisticSummary(String summary) { | ||
this.summary = summary; | ||
} | ||
|
||
public String getSummary() { | ||
return summary; | ||
} | ||
|
||
@Override | ||
public String getHtmlSummary() { | ||
return summary; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/resources/hudson/plugins/cppncss/parser/FormattedStatisticSummary/summary.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"> | ||
<!-- The class is final, so we trust the implementation --> | ||
<j:out value="${it.htmlSummary}"/> | ||
</j:jelly> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/hudson/plugins/cppncss/parser/StringStatisticSummary/summary.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"> | ||
<!-- Legacy mode, strings may be escaped --> | ||
${it.summary} | ||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters