Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinston Prakash2013-07-09 21:41:49 -0400
committerWinston Prakash2013-07-09 21:41:49 -0400
commitcd2dc72f4509707d09722317eb406ca6f9c608c4 (patch)
treed590c1806b40338b7f37c940b20ff5b7f6fb617b
parente66dd0cff2661a0414837142db3b5740c67eba50 (diff)
downloadorg.eclipse.hudson.core-cd2dc72f4509707d09722317eb406ca6f9c608c4.tar.gz
org.eclipse.hudson.core-cd2dc72f4509707d09722317eb406ca6f9c608c4.tar.xz
org.eclipse.hudson.core-cd2dc72f4509707d09722317eb406ca6f9c608c4.zip
Fix: Move job is broken. Now it uses the standard API Job.rename to do the job moving. Also removed the property "teamId" which is no longer needed.
-rw-r--r--hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractItem.java10
-rw-r--r--hudson-core/src/main/java/hudson/model/Hudson.java5
-rw-r--r--hudson-core/src/main/java/hudson/model/Item.java11
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamJobListener.java10
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamManager.java48
-rw-r--r--hudson-core/src/main/resources/org/eclipse/hudson/security/team/TeamManager/teamManager.jelly6
-rw-r--r--hudson-war/src/main/webapp/scripts/team-manager.js14
8 files changed, 49 insertions, 57 deletions
diff --git a/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java b/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java
index ef213f6f..41eb1285 100644
--- a/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java
@@ -64,7 +64,7 @@ public class UpdateJobCommand extends CLICommand {
h.checkPermission(Job.CONFIGURE);
String jobsFolderName = "jobs";
if (teamManager != null){
- jobsFolderName = teamManager.getJobsFolderName(item.getTeamId(), item.getName());
+ jobsFolderName = teamManager.getJobsFolderName(item.getName());
}
File rootDirOfJob = new File(new File(h.getRootDir(), jobsFolderName), name);
// place it as config.xml
diff --git a/hudson-core/src/main/java/hudson/model/AbstractItem.java b/hudson-core/src/main/java/hudson/model/AbstractItem.java
index 3af77080..5627739e 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractItem.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractItem.java
@@ -89,16 +89,6 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
// noop
}
- @Override
- public String getTeamId() {
- return teamId;
- }
-
- @Override
- public void setTeamId(String teamId) {
- this.teamId = teamId;
- }
-
@Exported(visibility = 999)
public String getName() {
return name;
diff --git a/hudson-core/src/main/java/hudson/model/Hudson.java b/hudson-core/src/main/java/hudson/model/Hudson.java
index e8186657..a9afd841 100644
--- a/hudson-core/src/main/java/hudson/model/Hudson.java
+++ b/hudson-core/src/main/java/hudson/model/Hudson.java
@@ -485,9 +485,6 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
private transient final ItemGroupMixIn itemGroupMixIn = new ItemGroupMixIn(this, this) {
@Override
protected void add(TopLevelItem item) {
- if (getTeamManager() != null) {
- item.setTeamId(getTeamManager().getCurrentUserTeamName());
- }
items.put( item.getName(), item);
}
@@ -2178,7 +2175,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
@Override
public File getRootDirFor(TopLevelItem child) {
if (getTeamManager() != null) {
- String jobsFolderName = getTeamManager().getJobsFolderName(child.getTeamId(), child.getName());
+ String jobsFolderName = getTeamManager().getJobsFolderName(child.getName());
return new File(new File(getRootDir(), jobsFolderName), child.getName());
}
return getRootDirFor(child.getName());
diff --git a/hudson-core/src/main/java/hudson/model/Item.java b/hudson-core/src/main/java/hudson/model/Item.java
index 80dc27f4..3507ab51 100644
--- a/hudson-core/src/main/java/hudson/model/Item.java
+++ b/hudson-core/src/main/java/hudson/model/Item.java
@@ -66,17 +66,6 @@ public interface Item extends PersistenceRoot, SearchableModelObject, AccessCont
abstract Collection<? extends Job> getAllJobs();
/**
- * A unique string to identify the team which this item belongs to
- *
- * @return String team ID
- * @since 3.1.0
- */
- public String getTeamId();
-
- public void setTeamId(String id);
-
-
- /**
* Gets the name of the item.
*
* <p> This name is also used for directory name, so it cannot contain any
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamJobListener.java b/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamJobListener.java
index 2aee02f5..23e2b044 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamJobListener.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamJobListener.java
@@ -52,15 +52,7 @@ public class TeamJobListener extends ItemListener {
if (item instanceof Job<?, ?>) {
try {
if (getTeamManager() != null) {
-
- getTeamManager().renameJobInCurrentUserTeam(oldJobName, newJobName);
- Team team;
- try {
- team = getTeamManager().findTeam(item.getTeamId());
- } catch (TeamManager.TeamNotFoundException ex) {
- logger.info(ex.getLocalizedMessage() + " Assuming public team");
- team = getTeamManager().getPublicTeam();
- }
+ Team team = getTeamManager().findJobOwnerTeam(oldJobName);
getTeamManager().renameJob(team, newJobName, newJobName);
}
} catch (IOException ex) {
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamManager.java b/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamManager.java
index 6c536fc0..a6ab0efc 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamManager.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/security/team/TeamManager.java
@@ -36,6 +36,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Level;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
@@ -298,7 +299,7 @@ public final class TeamManager implements Saveable {
return new TeamUtils.ErrorHttpResponse("Team name required.");
}
if ((jobName == null) || "".equals(jobName.trim())) {
- return new TeamUtils.ErrorHttpResponse("Job id required.");
+ return new TeamUtils.ErrorHttpResponse("Job required.");
}
Team newTeam;
try {
@@ -358,20 +359,33 @@ public final class TeamManager implements Saveable {
private void moveJob(Job job, Team oldTeam, Team newTeam) throws IOException {
try {
- File jobRootDir = job.getRootDir();
- File newJobRootDir = new File(getJobsFolder(newTeam), job.getName());
- newJobRootDir.mkdirs();
- Util.moveDirectory(jobRootDir, newJobRootDir);
- oldTeam.removeJob(job.getName());
- String newJobName = getTeamQualifiedJobName(newTeam.getName(), job.getName());
- newTeam.addJob(new TeamJob(newJobName));
- job.setTeamId(newTeam.getName());
- job.save();
- Hudson.getInstance().replaceItemId(job.getName(), newJobName);
+
+ String oldJobName = job.getName();
+ String unqualifiedJobName = getUnqualifiedJobName(job.getName());
+ String qualifiedNewJobName = getTeamQualifiedJobName(newTeam.getName(), unqualifiedJobName);
+
+// File jobRootDir = job.getRootDir();
+// File newJobRootDir = new File(getJobsFolder(newTeam), qualifiedNewJobName);
+// newJobRootDir.mkdirs();
+// Util.moveDirectory(jobRootDir, newJobRootDir);
+
+ newTeam.addJob(new TeamJob(qualifiedNewJobName));
+ job.renameTo(qualifiedNewJobName);
+ oldTeam.removeJob(oldJobName);
+
+ Hudson.getInstance().replaceItemId(job.getName(), qualifiedNewJobName);
} catch (Exception exc) {
throw new IOException(exc);
}
}
+
+ private String getUnqualifiedJobName(String jobName){
+ int index = jobName.indexOf('.');
+ if (jobName.indexOf('.') != -1){
+ jobName = jobName.substring(index + 1);
+ }
+ return jobName;
+ }
/**
* Get the name of the teams as JSON
@@ -587,7 +601,17 @@ public final class TeamManager implements Saveable {
if ((teamName == null) || "".equals(jobName) || Team.PUBLIC_TEAM_NAME.equals(teamName)) {
return jobName;
}
- return teamName + "." + jobName;
+ String qualifiedJobName = teamName + "." + jobName;
+ int postfix = 2;
+ try {
+ while (findTeam(teamName).isJobOwner(qualifiedJobName)){
+ qualifiedJobName += ("_" + postfix);
+ }
+ } catch (TeamNotFoundException ex) {
+ logger.info("getTeamQualifiedJobName: " + ex.getLocalizedMessage());
+ return jobName;
+ }
+ return qualifiedJobName;
}
/**
diff --git a/hudson-core/src/main/resources/org/eclipse/hudson/security/team/TeamManager/teamManager.jelly b/hudson-core/src/main/resources/org/eclipse/hudson/security/team/TeamManager/teamManager.jelly
index 04ed2cac..7f96c063 100644
--- a/hudson-core/src/main/resources/org/eclipse/hudson/security/team/TeamManager/teamManager.jelly
+++ b/hudson-core/src/main/resources/org/eclipse/hudson/security/team/TeamManager/teamManager.jelly
@@ -84,14 +84,14 @@
<j:forEach var="job" items="${app.items}">
<tr>
<td class="column1">
- <input class="move_cb_${job.name}" type="checkbox" value="${job.id}"/>
+ <input class="move_cb_${job.name}" type="checkbox" value="${job.name}"/>
</td>
<td class="column2">
${job.name}
</td>
<td class="column3">
- <span id="job_colum3_span_${job.id}">
- ${it.findJobOwnerTeam(job.id).name}
+ <span id="job_colum3_span_${job.name}">
+ ${it.findJobOwnerTeam(job.name).name}
</span>
</td>
</tr>
diff --git a/hudson-war/src/main/webapp/scripts/team-manager.js b/hudson-war/src/main/webapp/scripts/team-manager.js
index 1552aa74..5f1f4650 100644
--- a/hudson-war/src/main/webapp/scripts/team-manager.js
+++ b/hudson-war/src/main/webapp/scripts/team-manager.js
@@ -459,7 +459,7 @@ function removeTeamMember(teamName, memberName, parent) {
function configureJobVisibilityAction(configureJobItem) {
var trParent = jQuery(configureJobItem).parents("tr:first");
- var jobId = jQuery(trParent).find("input[name='hiddenJobId']").val();
+ var jobName = jQuery(trParent).find("input[name='hiddenJobId']").val();
var teamName = jQuery(trParent).find("input[name='hiddenTeamName']").val();
var teamNames = jQuery(trParent).find("input[name='hiddenVisibilities']").val();
@@ -479,7 +479,7 @@ function configureJobVisibilityAction(configureJobItem) {
teamNames += "public";
}
jQuery(trParent).find("input[name='hiddenVisibilities']").val(teamNames);
- configureJobVisibility(jobId, teamNames);
+ configureJobVisibility(jobName, teamNames);
},
Cancel: function() {
jQuery(this).dialog("close");
@@ -513,12 +513,12 @@ function configureJobVisibilityAction(configureJobItem) {
});
}
-function configureJobVisibility(jobId, teamNames) {
+function configureJobVisibility(jobName, teamNames) {
jQuery.ajax({
type: 'POST',
url: "setJobVisibility",
data: {
- jobId: jobId,
+ jobName: jobName,
teamNames: teamNames
},
success: function() {
@@ -586,17 +586,17 @@ function getJobsToMove() {
return jobs;
}
-function moveJobs(jobId, teamName, img) {
+function moveJobs(jobName, teamName, img) {
jQuery.ajax({
type: 'POST',
url: "moveJob",
data: {
- jobId: jobId,
+ jobName: jobName,
teamName: teamName
},
success: function() {
jQuery(img).attr('src', imageRoot + '/green-check.jpg');
- jQuery("#job_colum3_span_" + jobId).text(teamName);
+ jQuery("#job_colum3_span_" + jobName).text(teamName);
moveCount--;
if (moveCount === 0) {
jQuery('#dialog-move-jobs').dialog("close");

Back to the top