Skip to content

Commit

Permalink
Merge pull request #57 from willi1s/JENKINS-59923_manifest_action
Browse files Browse the repository at this point in the history
[JENKINS-59923] Replaced TagAction with new ManifestAction
  • Loading branch information
rsandell authored Jan 31, 2020
2 parents b06f6f2 + e3bf4fd commit 9714366
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 25 deletions.
108 changes: 108 additions & 0 deletions src/main/java/hudson/plugins/repo/ManifestAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* The MIT License
*
* Copyright (c) 2010, Brad Larson
*
* 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.repo;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.kohsuke.stapler.export.ExportedBean;

import hudson.model.BuildBadgeAction;
import hudson.model.Run;
import jenkins.model.RunAction2;

/**
* A Manifest Action displays the static manifest information needed
* to recreate the exact state of the repository when the build was run.
*/
@ExportedBean(defaultVisibility = 999)
public class ManifestAction implements RunAction2, BuildBadgeAction {

private static Logger debug = Logger
.getLogger("hudson.plugins.repo.ManifestAction");

private transient Run<?, ?> run;

/**
* Constructs the manifest action object.
* @param run Build whose manifest we wish to display.
*/
ManifestAction(final Run<?, ?> run) {
this.run = run;
}

@Override
public void onAttached(final Run<?, ?> r) {
this.run = r;
}

@Override
public void onLoad(final Run<?, ?> r) {
this.run = r;
}

/**
* Getter for the run property.
*/
public Run<?, ?> getRun() {
return run;
}

/**
* Returns the filename to use as the badge.
*/
public String getIconFileName() {
return "star.gif";
}

/**
* Returns the display name to use for the action.
*/
public String getDisplayName() {
return "Repo Manifest";
}

/**
* Returns the name of the Url to use for the action.
*/
public final String getUrlName() {
return "repo-manifest";
}

/**
* Gets a String representation of the static manifest for this repo snapshot.
*/
public String getManifest() {
String result = "";
try {
final RevisionState revisionState = run.getAction(RevisionState.class);
if (revisionState != null) {
result = revisionState.getManifest();
}
} catch (Exception e) {
debug.log(Level.WARNING, "Error getting revision state {0}", e.getMessage());
}
return result;
}
}
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/repo/RepoScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public void checkout(
repoDir,
showAllChanges);
}
build.addAction(new TagAction(build));
build.addAction(new ManifestAction(build));
}

private int doSync(final Launcher launcher, @Nonnull final FilePath workspace,
Expand Down
39 changes: 30 additions & 9 deletions src/main/java/hudson/plugins/repo/TagAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,28 @@
*/
package hudson.plugins.repo;

import java.io.ObjectStreamException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import hudson.model.Run;
import hudson.scm.AbstractScmTagAction;

import org.kohsuke.stapler.export.ExportedBean;

/**
/**
* A Tag Action allows a user to tag a build. Repo doesn't support a solid tag
* method, so right now we just display the static manifest information needed
* to recreate the exact state of the repository when the build was ran.
* @deprecated replaced by {@link ManifestAction} JENKINS-59923
*/
@ExportedBean(defaultVisibility = 999)
@Deprecated
@Restricted(NoExternalUse.class)
public class TagAction extends AbstractScmTagAction {

private static Logger debug = Logger.getLogger("hudson.plugins.repo.TagAction");

/**
* Constructs the tag action object. Just call the superclass.
*
Expand All @@ -54,7 +63,7 @@ public String getIconFileName() {
// TODO: return null if we don't want to show a link (no permissions?)
// TODO: if we later support actual tagging, we can use star-gold.gif
// for already tagged builds
return "star.gif";
return null;
}

/**
Expand All @@ -63,7 +72,7 @@ public String getIconFileName() {
*/
public String getDisplayName() {
// TODO: adjust name based on build state (tagged already or not)?
return "Repo Manifest";
return null;
}

@Override
Expand All @@ -83,8 +92,20 @@ public boolean isTagged() {
* snapshot.
*/
public String getManifest() {
final RevisionState revisionState =
getRun().getAction(RevisionState.class);
return revisionState.getManifest();
return null;
}

@Override
public void onAttached(final Run<?, ?> r) {
debug.log(Level.SEVERE, "Unexpected attach of TagAction class");
}

/**
* Migrate to a new ManifestAction.
* @return
* @throws ObjectStreamException if there is an issue
*/
Object readResolve() throws ObjectStreamException {
return new ManifestAction(build);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?jelly escape-by-default='true'?>

<a href="${rootURL}/${it.run.url}${it.urlName}">
<img width="16" height="16"
tooltip="${it.displayName}"
alt="[manifest]"
src="${imagesURL}/16x16/${it.iconFileName}"/>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
xmlns:f="/lib/form">

<l:layout title="Repo">
<st:include it="${it.run}" page="sidepanel.jelly" />
<l:side-panel>
<st:include page="sidepanel.jelly" it="${it.run}" optional="true" />
</l:side-panel>
<l:main-panel>
<h1>Repo Manifest - Build #${it.build.number}</h1>
<h1>Repo Manifest - Build #${it.run.number}</h1>
To recreate this build, copy the below manifest and past it to .repo/manifest.xml, then run 'repo sync'.
When done, be sure to undo changes to the .repo/manifest.xml file and repo sync again.

Manifest File:<br /><br />
<br/><br/>
Manifest File:<br/><br/>
<textarea rows="15" cols="140">${it.manifest}</textarea>
</l:main-panel>
</l:layout>
Expand Down
11 changes: 0 additions & 11 deletions src/main/resources/hudson/plugins/repo/TagAction/badge.jelly

This file was deleted.

0 comments on commit 9714366

Please sign in to comment.