Skip to content
Permalink
Browse files

Merge pull request #11 from ninian/master

 FIXED JENKINS-18455 - remove extra maven modules from all slicing
FIXED JENKINS-20082
FIXED JENKINS-21556
FIXED JENKINS-23766
  • Loading branch information...
ninian committed Nov 9, 2014
2 parents 9434d1d + 2051b49 commit f78127ed04eebe1af465af0fd71831269526b4a5
@@ -0,0 +1,40 @@
package configurationslicing;

import hudson.model.TopLevelItem;
import hudson.model.AbstractProject;
import hudson.model.Hudson;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
/**
* Helper class to provide all top level items configured in Jenkins, excluding other items
* held in folders, such as maven modules
*
*/
public class TopLevelItemSelector {

// private constructor since we don't expect this class to be instantiated
private TopLevelItemSelector() {

}

/**
* Provide all top level items configured in Jenkins
* @param clazz the type to search the ItemGroup for
* @return all items in the Jenkins ItemGroup tree which are of type TopLevelItem
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static List<AbstractProject<?,?>> getAllTopLevelItems(Class clazz) {
List<AbstractProject<?,?>> list = (List)Hudson.getInstance().getAllItems(clazz);
CollectionUtils.filter(list, new Predicate() {
public boolean evaluate(Object object) {
// exclude MatrixConfiguration, MavenModule, etc
return object instanceof TopLevelItem;
}
});
return list;
}

}
@@ -1,12 +1,13 @@
package configurationslicing.blockbuild;

import hudson.Extension;
import hudson.model.AbstractProject;

import java.io.IOException;
import java.util.List;

import configurationslicing.BooleanSlicer;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import configurationslicing.TopLevelItemSelector;

@Extension
public class BlockBuildWhenDownstreamBuildingBoolSlicer extends BooleanSlicer<AbstractProject<?,?>> {
@@ -33,7 +34,7 @@ public boolean getValue(AbstractProject<?,?> item) {
}

public List<AbstractProject<?,?>> getWorkDomain() {
return (List)Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValue(AbstractProject<?,?> item, boolean value) {
@@ -1,12 +1,13 @@
package configurationslicing.blockbuild;

import hudson.Extension;
import hudson.model.AbstractProject;

import java.io.IOException;
import java.util.List;

import configurationslicing.BooleanSlicer;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import configurationslicing.TopLevelItemSelector;

@Extension
public class BlockBuildWhenUpstreamBuildingBoolSlicer extends BooleanSlicer<AbstractProject<?,?>> {
@@ -33,7 +34,7 @@ public boolean getValue(AbstractProject<?,?> item) {
}

public List<AbstractProject<?,?>> getWorkDomain() {
return (List)Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValue(AbstractProject<?,?> item, boolean value) {
@@ -4,7 +4,6 @@
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.plugins.build_timeout.BuildTimeoutWrapper;
import hudson.tasks.BuildWrapper;
import hudson.util.DescribableList;
@@ -17,6 +16,7 @@

import org.apache.commons.lang.StringUtils;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

@Extension
@@ -53,10 +53,9 @@ public String getUrl() {
return "buildtimeout";
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(BuildableItemWithBuildWrappers.class);
return TopLevelItemSelector.getAllTopLevelItems(BuildableItemWithBuildWrappers.class);
}

@Override
@@ -4,7 +4,6 @@
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.plugins.build_timeout.BuildTimeoutWrapper;
import hudson.tasks.BuildWrapper;
import hudson.util.DescribableList;
@@ -19,6 +18,7 @@

import configurationslicing.ParametersStringSliceSpec;
import configurationslicing.ParametersStringSlicer;
import configurationslicing.TopLevelItemSelector;

@Extension
public class BuildTimeoutSlicer2 extends ParametersStringSlicer<AbstractProject<?,?>>{
@@ -53,10 +53,9 @@ public String getUrl() {
return "buildtimeout2";
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(BuildableItemWithBuildWrappers.class);
return TopLevelItemSelector.getAllTopLevelItems(BuildableItemWithBuildWrappers.class);
}

@Override
@@ -3,7 +3,6 @@
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.plugins.claim.ClaimPublisher;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
@@ -12,6 +11,7 @@
import java.util.List;

import configurationslicing.BooleanSlicer;
import configurationslicing.TopLevelItemSelector;

@Extension
public class ClaimSlicer extends BooleanSlicer<AbstractProject<?,?>> {
@@ -49,9 +49,8 @@ public boolean getValue(AbstractProject<?,?> item) {
return claimPublisher != null;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
public List<AbstractProject<?,?>> getWorkDomain() {
return (List)Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValue(AbstractProject<?,?> item, boolean value) {
@@ -1,7 +1,6 @@
package configurationslicing.email;

import hudson.model.AbstractProject;
import hudson.model.Hudson;

import java.io.IOException;
import java.util.ArrayList;
@@ -11,9 +10,9 @@

import org.apache.commons.lang.StringUtils;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer.UnorderedStringSlicerSpec;

@SuppressWarnings("unchecked")
public abstract class AbstractEmailSliceSpec extends UnorderedStringSlicerSpec<AbstractProject<?, ?>> {

public static final String DISABLED = "(Disabled)";
@@ -108,10 +107,10 @@ public String join(Collection<String> set) {
return value;
}
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

protected abstract ProjectHandler getProjectHandler(AbstractProject project);
protected abstract ProjectHandler getProjectHandler(AbstractProject<?, ?> project);

public String getDefaultValueString() {
return DISABLED;
@@ -12,6 +12,7 @@
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

@Extension
@@ -47,9 +48,8 @@ public String getUrl() {
return ret;
}

@SuppressWarnings("unchecked")
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValues(AbstractProject<?, ?> item, List<String> set) {
@@ -1,12 +1,13 @@
package configurationslicing.jobdisabled;

import hudson.Extension;
import hudson.model.AbstractProject;

import java.io.IOException;
import java.util.List;

import configurationslicing.BooleanSlicer;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import configurationslicing.TopLevelItemSelector;

@Extension
public class JobDisabledBoolSlicer extends BooleanSlicer<AbstractProject<?,?>> {
@@ -32,7 +33,7 @@ public boolean getValue(AbstractProject<?,?> item) {
}

public List<AbstractProject<?,?>> getWorkDomain() {
return (List)Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValue(AbstractProject<?,?> item, boolean value) {
@@ -2,12 +2,12 @@

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

/**
@@ -56,9 +56,9 @@ public boolean isBlankNeededForValues() {
return values;
}

@SuppressWarnings({ "unchecked" })

public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValues(AbstractProject<?, ?> job, List<String> set) {
@@ -9,6 +9,7 @@
import java.util.Collections;
import java.util.List;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

@Extension
@@ -42,9 +43,8 @@ public String getUrl() {
return Collections.singletonList(labelName);
}

@SuppressWarnings("unchecked")
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValues(AbstractProject<?, ?> item, List<String> set) {
@@ -4,7 +4,6 @@
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.plugins.logfilesizechecker.LogfilesizecheckerWrapper;
import hudson.tasks.BuildWrapper;
import hudson.util.DescribableList;
@@ -15,6 +14,8 @@
import java.util.List;

import org.apache.commons.lang.StringUtils;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

/**
@@ -52,10 +53,9 @@ public String getUrl() {
return "logfilesize";
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getItems(BuildableItemWithBuildWrappers.class);
return TopLevelItemSelector.getAllTopLevelItems(BuildableItemWithBuildWrappers.class);
}

@Override
@@ -2,13 +2,13 @@

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.tasks.LogRotator;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

public abstract class LogRotationSlicer extends UnorderedStringSlicer<AbstractProject<?,?>> {
@@ -82,9 +82,8 @@ public String getName(AbstractProject<?, ?> item) {
}
abstract protected String getValue(LogRotator rotator);

@SuppressWarnings("unchecked")
public List<AbstractProject<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(AbstractProject.class);
return TopLevelItemSelector.getAllTopLevelItems(AbstractProject.class);
}

public boolean setValues(AbstractProject<?, ?> item, List<String> set) {
@@ -120,8 +119,8 @@ public boolean setValues(AbstractProject<?, ?> item, List<String> set) {
LogRotator newlogrotator = new LogRotator(days, builds, artifactDaysToKeep, artifactNumToKeep);

if (!LogRotationSlicer.equals(newlogrotator, logrotator)) {
item.setLogRotator(newlogrotator);
try {
try {
item.setLogRotator(newlogrotator);
item.save();
} catch (IOException e) {
e.printStackTrace();
@@ -1,14 +1,14 @@
package configurationslicing.prioritysorter;

import hudson.model.JobProperty;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.queueSorter.PrioritySorterJobProperty;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import configurationslicing.TopLevelItemSelector;
import configurationslicing.UnorderedStringSlicer;

/**
@@ -58,9 +58,9 @@ public String getUrl() {
return values;
}

@SuppressWarnings({ "unchecked" })
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Job<?, ?>> getWorkDomain() {
return (List) Hudson.getInstance().getAllItems(Job.class);
return (List) TopLevelItemSelector.getAllTopLevelItems(Job.class);
}

@SuppressWarnings("unchecked")
Oops, something went wrong.

0 comments on commit f78127e

Please sign in to comment.
You can’t perform that action at this time.