提交 94437f14 编写于 作者: K kohsuke

fixing bugs.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1810 71c3de6d-444a-0410-be80-ed276b4c234a
上级 61a52267
package hudson;
import hudson.model.TaskListener;
import hudson.model.Project;
import hudson.model.TopLevelItem;
import hudson.util.IOException2;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Chmod;
......@@ -24,6 +26,9 @@ import java.util.Map;
import java.util.ResourceBundle;
import java.util.SimpleTimeZone;
import java.util.StringTokenizer;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
......@@ -299,6 +304,18 @@ public class Util {
return s;
}
/**
* Create a sub-list by only picking up instances of the specified type.
*/
public static <T> List<T> createSubList( Collection<?> source, Class<T> type ) {
List<T> r = new ArrayList<T>();
for (Object item : source) {
if(type.isInstance(item))
r.add(type.cast(item));
}
return r;
}
/**
* Escapes non-ASCII characters.
*/
......
......@@ -104,15 +104,6 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
*/
public transient final File root;
/**
* All {@link Job}s keyed by their names.
* Subset of {@link #items}.
*
* @deprecated
* TODO: get rid of this in favor of {@link #items}.
*/
/*package*/ transient final Map<String,Job> jobs = new TreeMap<String,Job>();
/**
* All {@link Item}s keyed by their {@link Item#getName() name}s.
*/
......@@ -372,7 +363,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
* Gets the snapshot of all the jobs.
*/
public synchronized List<Job> getJobs() {
return new ArrayList<Job>(jobs.values());
return Util.createSubList(items.values(),Job.class);
}
public synchronized List<TopLevelItem> getItems() {
......@@ -383,12 +374,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
* Gets the snapshot of all the projects.
*/
public synchronized List<Project> getProjects() {
List<Project> r = new ArrayList<Project>();
for (Job job : jobs.values()) {
if(job instanceof Project)
r.add((Project)job);
}
return r;
return Util.createSubList(items.values(),Project.class);
}
/**
......@@ -396,8 +382,9 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
*/
public synchronized Collection<String> getJobNames() {
List<String> names = new ArrayList<String>();
for (Job j : jobs.values()) {
names.add(j.getName());
for (Item j : items.values()) {
if (j instanceof Job)
names.add(j.getName());
}
return names;
}
......@@ -601,7 +588,11 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
* if such a project doesn't exist.
*/
public synchronized Job getJob(String name) {
return jobs.get(name);
TopLevelItem item = items.get(name);
if(item instanceof Job)
return (Job)item;
else
return null;
}
/**
......@@ -628,7 +619,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
* if the project of the given name already exists.
*/
public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name ) throws IOException {
if(jobs.containsKey(name))
if(items.containsKey(name))
throw new IllegalArgumentException();
TopLevelItem job;
......@@ -650,7 +641,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
for (ItemListener l : viewItemListeners)
l.onDeleted(job);
jobs.remove(job.getName());
items.remove(job.getName());
if(views!=null) {
for (ListView v : views) {
synchronized(v) {
......@@ -665,9 +656,9 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
* Called by {@link Job#renameTo(String)} to update relevant data structure.
* assumed to be synchronized on Hudson by the caller.
*/
/*package*/ void onRenamed(Job job, String oldName, String newName) throws IOException {
jobs.remove(oldName);
jobs.put(newName,job);
/*package*/ void onRenamed(TopLevelItem job, String oldName, String newName) throws IOException {
items.remove(oldName);
items.put(newName,job);
if(views!=null) {
for (ListView v : views) {
......
......@@ -223,10 +223,15 @@ public abstract class Job<JobT extends Job<JobT,RunT>, RunT extends Run<JobT,Run
/**
* Renames a job.
*
* <p>
* This method is defined on {@link Job} but really only applicable
* for {@link Job}s that are top-level items.
*/
public void renameTo(String newName) throws IOException {
// always synchronize from bigger objects first
final Hudson parent = Hudson.getInstance();
assert this instanceof TopLevelItem;
synchronized(parent) {
synchronized(this) {
// sanity check
......@@ -295,7 +300,7 @@ public abstract class Job<JobT extends Job<JobT,RunT>, RunT extends Run<JobT,Run
}
}
parent.onRenamed(this,oldName,newName);
parent.onRenamed((TopLevelItem)this,oldName,newName);
// update BuildTrigger of other projects that point to this object.
// can't we generalize this?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册