Skip to content

Commit

Permalink
[FIXED JENKINS-12906] add support for multiple tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Petti committed Mar 7, 2012
1 parent eeae9a5 commit 31a8d65
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
Expand Up @@ -461,6 +461,7 @@ public String getP4Executable(String tool) {
*
* @return the new object which is an instance of PerforceSCM
*/
@SuppressWarnings( "deprecation" )
public Object readResolve() {
if (createWorkspace == null)
{
Expand Down
70 changes: 61 additions & 9 deletions src/main/java/hudson/plugins/perforce/PerforceTagAction.java
Expand Up @@ -14,6 +14,7 @@

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.List;
Expand All @@ -27,8 +28,11 @@
public class PerforceTagAction extends AbstractScmTagAction {
private final int changeNumber;
private Depot depot;
private String tag;
private String desc;
private List<PerforceTag> tags = new ArrayList<PerforceTag>();
@Deprecated
private transient String tag;
@Deprecated
private transient String desc;
private String view;
private String owner;

Expand All @@ -45,6 +49,7 @@ public PerforceTagAction(AbstractBuild build, Depot depot, String label, String
this.depot = depot;
this.changeNumber = -1;
this.tag = label;
this.tags.add(new PerforceTag(label,""));
this.view = views;
this.owner = owner;
}
Expand All @@ -54,6 +59,7 @@ public PerforceTagAction(PerforceTagAction tga) {
this.depot = tga.depot;
this.changeNumber = tga.changeNumber;
this.tag = tga.tag;
this.tags.addAll(tga.getTags());
this.view = tga.view;
this.owner = tga.owner;
}
Expand Down Expand Up @@ -107,11 +113,19 @@ public Depot getDepot() {
return depot;
}

public List<PerforceTag> getTags() {
return tags;
}

public void setTags(List<PerforceTag> tags) {
this.tags = tags;
}

/**
* Returns true if this build has already been tagged at least once.
*/
public boolean isTagged() {
return tag != null;
return tags != null && !tags.isEmpty();
}

/**
Expand Down Expand Up @@ -152,11 +166,9 @@ public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throw
}

public void tagBuild(String tagname, String description) throws IOException {
tag = tagname;
desc = description;
Label label = new Label();
label.setName(tag);
label.setDescription(desc);
label.setName(tagname);
label.setDescription(description);
label.setRevision(new Integer(changeNumber).toString());
if(owner!=null && !owner.equals("")) label.setOwner(owner);

Expand All @@ -174,12 +186,52 @@ public void tagBuild(String tagname, String description) throws IOException {
try {
depot.getLabels().saveLabel(label);
} catch(PerforceException e) {
tag = null;
desc = null;
e.printStackTrace();
throw new IOException("Failed to issue perforce label." + e.getMessage());
}
tags.add(new PerforceTag(tagname,description));
build.save();
}

@SuppressWarnings( "deprecation" )
public Object readResolve() {
if (tags == null)
{
tags = new ArrayList<PerforceTag>();
if (tag != null)
{
tags.add(new PerforceTag(tag,desc));
}
}

return this;
}

public static class PerforceTag {
private String name;
private String desc;

public PerforceTag(String name, String desc) {
this.name = name;
this.desc = desc;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

}
Expand Up @@ -24,48 +24,48 @@

<j:set var="change" value="${it.changeNumber}" />

<j:choose>
<j:when test="${it.isTagged()}">
<p>
This build is labeled: <b>${it.tag}</b>
</p>
<p>
${it.description}
</p>
</j:when>
<j:otherwise>
<p>You may label this build using Perforce's label feature. This will
create a Perforce label with a view matching this project and a revision matching
the change number: ${it.changeNumber}.</p>
<form action="submit" method="get">
<table border="0" width="400">
<tr>
<td nowrap="nowrap"><b>Label Name:</b> </td>
<td><input type="text" name="name"
value="${it.build.project.name}-Build-${it.build.number}" style="width:300px" id="name"
checkUrl="'checkTag?value='+escape(this.value)"/>
</td>
</tr>
<tr>
<td><b>Description:</b> </td>
<td><textarea name="desc" rows="5" cols="50">Changelist: ${it.changeNumber}</textarea></td>
</tr>
<tr>
<td><b>Owner:</b> </td>
<td><input type="text" name="owner"
value="${it.owner}" style="width:300px" id="owner" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Label Build"/></td>
</tr>
</table>
</form>
</j:otherwise>
</j:choose>

<j:if test="${it.isTagged()}">
<p>
This build is labeled:
</p>
<table border="0" width="400"><tr><td><b>Label</b></td><td><b>Description</b></td></tr>
<j:forEach var="entry" items="${it.tags}">
<tr><td>${entry.name}</td><td>${entry.desc}</td></tr>
</j:forEach>
</table>
</j:if>
<p>You may label this build using Perforce's label feature. This will
create a Perforce label with a view matching this project and a revision matching
the change number: ${it.changeNumber}.</p>
<form action="submit" method="get">
<table border="0" width="400">
<tr>
<td nowrap="nowrap"><b>Label Name:</b> </td>
<td><input type="text" name="name"
value="${it.build.project.name}-Build-${it.build.number}" style="width:300px" id="name"
checkUrl="'checkTag?value='+escape(this.value)"/>
</td>
</tr>
<tr>
<td><b>Description:</b> </td>
<td><textarea name="desc" rows="5" cols="50">Changelist: ${it.changeNumber}</textarea></td>
</tr>
<tr>
<td><b>Owner:</b> </td>
<td><input type="text" name="owner"
value="${it.owner}" style="width:300px" id="owner" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Label Build"/></td>
</tr>
</table>
</form>

</l:main-panel>
</l:layout>
</j:jelly>

0 comments on commit 31a8d65

Please sign in to comment.