Title: [40752] trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup: workspace cleanup slicer

Diff

Modified: trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/AbstractWsCleanupSliceSpec.java (40751 => 40752)


--- trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/AbstractWsCleanupSliceSpec.java	2012-10-27 21:40:16 UTC (rev 40751)
+++ trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/AbstractWsCleanupSliceSpec.java	2012-10-28 13:03:30 UTC (rev 40752)
@@ -129,6 +129,30 @@
 		public List<Pattern> patterns = new ArrayList<Pattern>();
 		public boolean appliesToDirectories = false;
 		public boolean skipWhenFailed = false;
+		
+		public boolean equals(Object o) {
+			CleanupInfo that = (CleanupInfo) o;
+			if (this.appliesToDirectories != that.appliesToDirectories) {
+				return false;
+			}
+			if (this.skipWhenFailed != that.skipWhenFailed) {
+				return false;
+			}
+			if (this.patterns.size() != that.patterns.size()) {
+				return false;
+			}
+			for (int i = 0; i < this.patterns.size(); i++) {
+				Pattern thisPattern = this.patterns.get(0);
+				Pattern thatPattern = that.patterns.get(0);
+				if (thisPattern.getType() != thatPattern.getType()) {
+					return false;
+				}
+				if (!thisPattern.getPattern().equals(thatPattern.getPattern())) {
+					return false;
+				}
+			}
+			return true;
+		}
 	}
 
 }

Added: trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupAfterSlicer.java (0 => 40752)


--- trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupAfterSlicer.java	                        (rev 0)
+++ trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupAfterSlicer.java	2012-10-28 13:03:30 UTC (rev 40752)
@@ -0,0 +1,97 @@
+package configurationslicing.wscleanup;
+
+import hudson.Extension;
+import hudson.model.AbstractProject;
+import hudson.model.Descriptor;
+import hudson.model.Hudson;
+import hudson.plugins.ws_cleanup.WsCleanup;
+import hudson.tasks.Publisher;
+import hudson.util.DescribableList;
+
+import java.io.IOException;
+import java.util.List;
+
+import configurationslicing.UnorderedStringSlicer;
+
+@Extension
+public class CleanupAfterSlicer extends UnorderedStringSlicer<AbstractProject<?, ?>> {
+
+	public CleanupAfterSlicer() {
+		super(new CleanupAfterSliceSpec());
+	}
+
+	public static class CleanupAfterSliceSpec extends AbstractWsCleanupSliceSpec {
+
+		public CleanupAfterSliceSpec() {
+			super("wscleanupafter", "Delete workspace when build is done");
+		}
+
+		@Override
+		public CleanupInfo getCleanupInfo(AbstractProject<?, ?> item) {
+			DescribableList<Publisher,Descriptor<Publisher>> publishers = item.getPublishersList();
+			WsCleanup publisher = publishers.get(WsCleanup.class);
+			if (publisher == null) {
+				return null;
+			}
+			
+			CleanupInfo info = new CleanupInfo();
+			info.appliesToDirectories = publisher.getDeleteDirs();
+			info.skipWhenFailed = publisher.getSkipWhenFailed();
+			info.patterns = publisher.getPatterns();
+			
+			return info;
+		}
+
+		@Override
+		public boolean setCleanupInfo(AbstractProject<?, ?> item, CleanupInfo info) {
+			DescribableList<Publisher,Descriptor<Publisher>> publishers = item.getPublishersList();
+			WsCleanup oldPublisher = publishers.get(WsCleanup.class);
+			
+			if (info == null) {
+				if (oldPublisher == null) {
+					return false;
+				} else {
+					try {
+						publishers.remove(oldPublisher);
+						return true;
+					} catch (IOException e) {
+						return false;
+					}
+				}
+			} else {
+				WsCleanup newPublisher = new WsCleanup(info.patterns, info.appliesToDirectories, info.skipWhenFailed);
+				if (oldPublisher == null) {
+					try {
+						publishers.add(newPublisher);
+						return true;
+					} catch (IOException e) {
+						return false;
+					}
+				} else {
+					CleanupInfo oldInfo = getCleanupInfo(item);
+					if (oldInfo.equals(info)) {
+						return false;
+					} else {
+						try {
+							publishers.replace(newPublisher);
+							return true;
+						} catch (IOException e) {
+							return false;
+						}
+					}
+				}
+			}
+		}
+		@Override
+		public boolean isSkipEnabled() {
+			return true;
+		}
+		@SuppressWarnings({ "rawtypes", "unchecked" })
+		@Override
+		public List<AbstractProject<?, ?>> getWorkDomain() {
+            return (List) Hudson.getInstance().getItems(AbstractProject.class);
+		}
+	
+	}
+	
+}
Property changes on: trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupAfterSlicer.java
___________________________________________________________________

Added: svn:mime-type

Modified: trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupBeforeSlicer.java (40751 => 40752)


--- trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupBeforeSlicer.java	2012-10-27 21:40:16 UTC (rev 40751)
+++ trunk/hudson/plugins/configurationslicing/src/main/java/configurationslicing/wscleanup/CleanupBeforeSlicer.java	2012-10-28 13:03:30 UTC (rev 40752)
@@ -9,6 +9,7 @@
 import hudson.tasks.BuildWrapper;
 import hudson.util.DescribableList;
 
+import java.io.IOException;
 import java.util.List;
 
 import configurationslicing.UnorderedStringSlicer;
@@ -28,30 +29,70 @@
 
 		@Override
 		public CleanupInfo getCleanupInfo(AbstractProject<?, ?> item) {
-			CleanupInfo info = new CleanupInfo();
-			
 			BuildableItemWithBuildWrappers bi = (BuildableItemWithBuildWrappers) item;
 			DescribableList<BuildWrapper,Descriptor<BuildWrapper>> wrappers = bi.getBuildWrappersList();
-			boolean changed = false;
 			PreBuildCleanup wrapper = wrappers.get(PreBuildCleanup.class);
-			
-			if (changed) {
-				
+
+			if (wrapper == null) {
+				return null;
 			}
 			
+			CleanupInfo info = new CleanupInfo();
+			info.appliesToDirectories = wrapper.getDeleteDirs();
+			info.skipWhenFailed = false; // is N/A
+			info.patterns = wrapper.getPatterns();
+			
 			return info;
 		}
 
 		@Override
 		public boolean setCleanupInfo(AbstractProject<?, ?> item, CleanupInfo info) {
-			return false;
+			BuildableItemWithBuildWrappers bi = (BuildableItemWithBuildWrappers) item;
+			DescribableList<BuildWrapper,Descriptor<BuildWrapper>> wrappers = bi.getBuildWrappersList();
+			PreBuildCleanup oldWrapper = wrappers.get(PreBuildCleanup.class);
+			
+			if (info == null) {
+				if (oldWrapper == null) {
+					return false;
+				} else {
+					try {
+						wrappers.remove(oldWrapper);
+						return true;
+					} catch (IOException e) {
+						return false;
+					}
+				}
+			} else {
+				PreBuildCleanup newWrapper = new PreBuildCleanup(info.patterns, info.appliesToDirectories);
+				if (oldWrapper == null) {
+					try {
+						wrappers.add(newWrapper);
+						return true;
+					} catch (IOException e) {
+						return false;
+					}
+				} else {
+					CleanupInfo oldInfo = getCleanupInfo(item);
+					if (oldInfo.equals(info)) {
+						return false;
+					} else {
+						try {
+							wrappers.replace(newWrapper);
+							return true;
+						} catch (IOException e) {
+							return false;
+						}
+					}
+				}
+			}
 		}
+		
 		@Override
 		public boolean isSkipEnabled() {
 			// we do not allow skip on fail in the cleanup before
 			return false;
 		}
-		@SuppressWarnings("unchecked")
+		@SuppressWarnings({ "rawtypes", "unchecked" })
 		@Override
 		public List<AbstractProject<?, ?>> getWorkDomain() {
             return (List) Hudson.getInstance().getItems(BuildableItemWithBuildWrappers.class);

Reply via email to