Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-37369] Expose the last computation for computed folders
- Loading branch information
Showing
6 changed files
with
274 additions
and
2 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
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
151 changes: 151 additions & 0 deletions
151
src/main/java/com/cloudbees/hudson/plugins/folder/computed/PseudoRun.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,151 @@ | ||
package com.cloudbees.hudson.plugins.folder.computed; | ||
|
||
import hudson.Functions; | ||
import hudson.Util; | ||
import hudson.model.Actionable; | ||
import hudson.model.Result; | ||
import hudson.model.Run; | ||
import hudson.model.TopLevelItem; | ||
import java.io.File; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.List; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import jenkins.model.Jenkins; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.Ancestor; | ||
import org.kohsuke.stapler.HttpResponse; | ||
import org.kohsuke.stapler.HttpResponses; | ||
import org.kohsuke.stapler.StaplerFallback; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
/** | ||
* A fake {@link Run} used to render last build information via Stapler and Jelly | ||
*/ | ||
@Restricted(NoExternalUse.class) // used by stapler / jelly only | ||
public class PseudoRun<I extends TopLevelItem> extends Actionable implements StaplerFallback { | ||
private final FolderComputation<I> computation; | ||
|
||
PseudoRun(FolderComputation<I> computation) { | ||
this.computation = computation; | ||
} | ||
|
||
public String getDisplayName() { | ||
return "log"; | ||
} | ||
|
||
public RunUrl decompose(StaplerRequest req) { | ||
List<Ancestor> ancestors = req.getAncestors(); | ||
|
||
// find the first and last Run instances | ||
Ancestor f = null, l = null; | ||
for (Ancestor anc : ancestors) { | ||
if (anc.getObject() instanceof PseudoRun) { | ||
if (f == null) f = anc; | ||
l = anc; | ||
} | ||
} | ||
if (l == null) return null; // there was no Run object | ||
|
||
String base = l.getUrl(); | ||
|
||
return new RunUrl(base); | ||
|
||
} | ||
|
||
/** | ||
* Gets the string that says how long since this build has started. | ||
* | ||
* @return string like "3 minutes" "1 day" etc. | ||
*/ | ||
@Nonnull | ||
public String getTimestampString() { | ||
long duration = new GregorianCalendar().getTimeInMillis() - computation.getTimestamp().getTimeInMillis(); | ||
return Util.getPastTimeString(duration); | ||
} | ||
|
||
/** | ||
* Returns the timestamp formatted in xs:dateTime. | ||
* | ||
* @return the timestamp formatted in xs:dateTime. | ||
*/ | ||
@Nonnull | ||
public String getTimestampString2() { | ||
return Util.XS_DATETIME_FORMATTER.format(computation.getTimestamp()); | ||
} | ||
|
||
@CheckForNull | ||
public Result getResult() { | ||
return computation.getResult(); | ||
} | ||
|
||
@Nonnull | ||
public Calendar getTimestamp() { | ||
return computation.getTimestamp(); | ||
} | ||
|
||
@Nonnull | ||
public String getDurationString() { | ||
return computation.getDurationString(); | ||
} | ||
|
||
@Override | ||
public String getSearchUrl() { | ||
return computation.getSearchUrl(); | ||
} | ||
|
||
@Nonnull | ||
public File getLogFile() { | ||
return computation.getLogFile(); | ||
} | ||
|
||
@Override | ||
public Object getStaplerFallback() { | ||
return computation; | ||
} | ||
|
||
public HttpResponse doIndex(StaplerRequest request) { | ||
return HttpResponses.redirectTo(Jenkins.getActiveInstance().getRootUrlFromRequest() + computation.getUrl() ); | ||
} | ||
|
||
public HttpResponse doConsole(StaplerRequest request) { | ||
return HttpResponses.redirectTo(Jenkins.getActiveInstance().getRootUrlFromRequest() + computation.getUrl() + "console"); | ||
} | ||
|
||
public HttpResponse doConsoleText(StaplerRequest request) { | ||
return HttpResponses.redirectTo(Jenkins.getActiveInstance().getRootUrlFromRequest() + computation.getUrl() + "consoleText"); | ||
} | ||
|
||
@Restricted(NoExternalUse.class) | ||
public static final class RunUrl { | ||
private final String base; | ||
|
||
|
||
public RunUrl(String base) { | ||
this.base = base; | ||
} | ||
|
||
public String getBaseUrl() { | ||
return base; | ||
} | ||
|
||
/** | ||
* Returns the same page in the next build. | ||
*/ | ||
public String getNextBuildUrl() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the same page in the previous build. | ||
*/ | ||
public String getPreviousBuildUrl() { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
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
3 changes: 2 additions & 1 deletion
3
src/main/resources/com/cloudbees/hudson/plugins/folder/computed/Messages.properties
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ComputedFolder.already_computing=Already computing | ||
FolderComputation.DisplayName=Folder Computation | ||
ThrottleComputationQueueTaskDispatcher.MaxConcurrentIndexing=At maximum indexing capacity | ||
PeriodicFolderTrigger.DisplayName=Periodically if not otherwise run | ||
PeriodicFolderTrigger.DisplayName=Periodically if not otherwise run | ||
PseudoRun.DisplayName=log |
37 changes: 37 additions & 0 deletions
37
src/main/resources/com/cloudbees/hudson/plugins/folder/computed/PseudoRun/sidepanel.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,37 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2017 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. | ||
--> | ||
|
||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project"> | ||
<l:header/> | ||
<l:side-panel> | ||
<l:tasks> | ||
<j:set var="buildUrl" value="${it.decompose(request)}"/> | ||
<p:console-link/> | ||
<st:include page="actions.jelly"/> | ||
<t:actions actions="${it.transientActions}"/> | ||
</l:tasks> | ||
</l:side-panel> | ||
</j:jelly> |