11/*
22 * The MIT License
3- *
3+ *
44 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5- *
5+ *
66 * Permission is hereby granted, free of charge, to any person obtaining a copy
77 * of this software and associated documentation files (the "Software"), to deal
88 * in the Software without restriction, including without limitation the rights
99 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010 * copies of the Software, and to permit persons to whom the Software is
1111 * furnished to do so, subject to the following conditions:
12- *
12+ *
1313 * The above copyright notice and this permission notice shall be included in
1414 * all copies or substantial portions of the Software.
15- *
15+ *
1616 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2323 */
2424package hudson .tasks .test ;
2525
26+ import java .io .IOException ;
27+ import java .util .List ;
28+ import javax .servlet .ServletException ;
29+ import javax .servlet .http .Cookie ;
30+ import javax .servlet .http .HttpServletResponse ;
31+
2632import edu .hm .hafner .echarts .ChartModelConfiguration ;
2733import edu .hm .hafner .echarts .JacksonFacade ;
2834import edu .hm .hafner .echarts .LinesChartModel ;
2935import edu .umd .cs .findbugs .annotations .CheckForNull ;
36+
37+ import org .kohsuke .stapler .Ancestor ;
38+ import org .kohsuke .stapler .StaplerRequest ;
39+ import org .kohsuke .stapler .StaplerResponse ;
40+ import org .kohsuke .stapler .bind .JavaScriptMethod ;
3041import hudson .model .AbstractProject ;
3142import hudson .model .Action ;
3243import hudson .model .Job ;
3344import hudson .model .Run ;
3445import hudson .tasks .junit .JUnitResultArchiver ;
46+
47+ import io .jenkins .plugins .echarts .AsyncConfigurableTrendChart ;
48+ import io .jenkins .plugins .echarts .AsyncTrendChart ;
3549import io .jenkins .plugins .junit .storage .FileJunitTestResultStorage ;
36- import io .jenkins .plugins .junit .storage .TestResultImpl ;
3750import io .jenkins .plugins .junit .storage .JunitTestResultStorage ;
38- import io .jenkins .plugins .echarts .AsyncTrendChart ;
39- import org .kohsuke .stapler .Ancestor ;
40- import org .kohsuke .stapler .StaplerRequest ;
41- import org .kohsuke .stapler .StaplerResponse ;
42-
43- import javax .servlet .ServletException ;
44- import javax .servlet .http .Cookie ;
45- import javax .servlet .http .HttpServletResponse ;
46- import java .io .IOException ;
47- import java .util .List ;
48- import org .kohsuke .stapler .bind .JavaScriptMethod ;
51+ import io .jenkins .plugins .junit .storage .TestResultImpl ;
4952
5053/**
5154 * Project action object from test reporter, such as {@link JUnitResultArchiver},
5659 *
5760 * @author Kohsuke Kawaguchi
5861 */
59- public class TestResultProjectAction implements Action , AsyncTrendChart {
62+ public class TestResultProjectAction implements Action , AsyncTrendChart , AsyncConfigurableTrendChart {
6063 /**
6164 * Project that owns this action.
6265 * @since 1.2-beta-1
@@ -69,13 +72,13 @@ public class TestResultProjectAction implements Action, AsyncTrendChart {
6972 /**
7073 * @since 1.2-beta-1
7174 */
72- public TestResultProjectAction (Job <?,?> job ) {
75+ public TestResultProjectAction (final Job <?,?> job ) {
7376 this .job = job ;
7477 project = job instanceof AbstractProject ? (AbstractProject ) job : null ;
7578 }
7679
7780 @ Deprecated
78- public TestResultProjectAction (AbstractProject <?,?> project ) {
81+ public TestResultProjectAction (final AbstractProject <?,?> project ) {
7982 this ((Job ) project );
8083 }
8184
@@ -114,7 +117,12 @@ public AbstractTestResultAction getLastTestResultAction() {
114117 return null ;
115118 }
116119
120+ @ Deprecated
117121 protected LinesChartModel createChartModel () {
122+ return createChartModel (new ChartModelConfiguration ());
123+ }
124+
125+ private LinesChartModel createChartModel (final ChartModelConfiguration configuration ) {
118126 Run <?, ?> lastCompletedBuild = job .getLastCompletedBuild ();
119127
120128 JunitTestResultStorage storage = JunitTestResultStorage .find ();
@@ -127,11 +135,11 @@ protected LinesChartModel createChartModel() {
127135 if (buildHistory == null ) {
128136 return new LinesChartModel ();
129137 }
130- return new TestResultTrendChart ().create (buildHistory , new ChartModelConfiguration () );
138+ return new TestResultTrendChart ().create (buildHistory , configuration );
131139 }
132140
133141 @ CheckForNull
134- private TestResultActionIterable createBuildHistory (Run <?, ?> lastCompletedBuild ) {
142+ private TestResultActionIterable createBuildHistory (final Run <?, ?> lastCompletedBuild ) {
135143 // some plugins that depend on junit seem to attach the action even though there's no run
136144 // e.g. xUnit and cucumber
137145 if (lastCompletedBuild == null ) {
@@ -153,11 +161,11 @@ private TestResultActionIterable createBuildHistory(Run<?, ?> lastCompletedBuild
153161
154162 /**
155163 * Display the test result trend.
156- *
164+ *
157165 * @deprecated Replaced by echarts in TODO
158166 */
159167 @ Deprecated
160- public void doTrend ( StaplerRequest req , StaplerResponse rsp ) throws IOException , ServletException {
168+ public void doTrend ( final StaplerRequest req , final StaplerResponse rsp ) throws IOException , ServletException {
161169 AbstractTestResultAction a = getLastTestResultAction ();
162170 if (a !=null )
163171 a .doGraph (req ,rsp );
@@ -171,7 +179,7 @@ public void doTrend( StaplerRequest req, StaplerResponse rsp ) throws IOExceptio
171179 * @deprecated Replaced by echarts in TODO
172180 */
173181 @ Deprecated
174- public void doTrendMap ( StaplerRequest req , StaplerResponse rsp ) throws IOException , ServletException {
182+ public void doTrendMap ( final StaplerRequest req , final StaplerResponse rsp ) throws IOException , ServletException {
175183 AbstractTestResultAction a = getLastTestResultAction ();
176184 if (a !=null )
177185 a .doGraphMap (req ,rsp );
@@ -182,7 +190,7 @@ public void doTrendMap( StaplerRequest req, StaplerResponse rsp ) throws IOExcep
182190 /**
183191 * Changes the test result report display mode.
184192 */
185- public void doFlipTrend ( StaplerRequest req , StaplerResponse rsp ) throws IOException , ServletException {
193+ public void doFlipTrend ( final StaplerRequest req , final StaplerResponse rsp ) throws IOException , ServletException {
186194 boolean failureOnly = false ;
187195
188196 // check the current preference value
@@ -200,7 +208,7 @@ public void doFlipTrend( StaplerRequest req, StaplerResponse rsp ) throws IOExce
200208 // set the updated value
201209 Cookie cookie = new Cookie (FAILURE_ONLY_COOKIE ,String .valueOf (failureOnly ));
202210 List <Ancestor > anc = req .getAncestors ();
203- Ancestor a = ( Ancestor ) anc .get (anc .size ()-2 );
211+ Ancestor a = anc .get (anc .size ()-2 );
204212 cookie .setPath (a .getUrl ()); // just for this project
205213 cookie .setMaxAge (60 *60 *24 *365 ); // 1 year
206214 rsp .addCookie (cookie );
@@ -211,12 +219,17 @@ public void doFlipTrend( StaplerRequest req, StaplerResponse rsp ) throws IOExce
211219
212220 private static final String FAILURE_ONLY_COOKIE = "TestResultAction_failureOnly" ;
213221
214- @ JavaScriptMethod
215- @ Override
222+ @ Override @ Deprecated
216223 public String getBuildTrendModel () {
217224 return new JacksonFacade ().toJson (createChartModel ());
218225 }
219226
227+ @ JavaScriptMethod
228+ @ Override
229+ public String getConfigurableBuildTrendModel (final String configuration ) {
230+ return new JacksonFacade ().toJson (createChartModel (ChartModelConfiguration .fromJson (configuration )));
231+ }
232+
220233 @ Override
221234 public boolean isTrendVisible () {
222235 return true ;
0 commit comments