diff --git a/pom.xml b/pom.xml
index 1dd5808..0fd74b5 100755
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
org.jenkins-ci.plugins
diskcheck
- 0.27
+ 0.28
hpi
diff --git a/src/main/java/org/jenkinsci/plugin/Diskcheck.java b/src/main/java/org/jenkinsci/plugin/Diskcheck.java
index 0de2de4..7b04c0e 100644
--- a/src/main/java/org/jenkinsci/plugin/Diskcheck.java
+++ b/src/main/java/org/jenkinsci/plugin/Diskcheck.java
@@ -21,8 +21,6 @@
import java.io.IOException;
import java.io.PrintStream;
-
-
/**
* Class to allow any build step to be performed before the SCM checkout occurs.
*
@@ -30,17 +28,15 @@
*
*/
-
public class Diskcheck extends BuildWrapper {
-
public final boolean failOnError;
/**
* Constructor taking a list of buildsteps to use.
*
* @param buildstep
- * list of but steps configured in the UI
+ * list of build steps configured in the UI
*/
@DataBoundConstructor
public Diskcheck(boolean failOnError) {
@@ -62,6 +58,11 @@ public Environment setUp(AbstractBuild build, Launcher launcher,
return new NoopEnv();
}
+ @Override
+ public Descriptor getDescriptor() {
+ return (Descriptor) super.getDescriptor();
+ }
+
/**
* Overridden precheckout step, this is where wedo all the work.
*
@@ -75,19 +76,12 @@ public Environment setUp(AbstractBuild build, Launcher launcher,
* @param listener
*/
- @Override
- public Descriptor getDescriptor() {
- return (Descriptor) super.getDescriptor();
- }
@Override
- public void preCheckout(AbstractBuild build, Launcher launcher,
- BuildListener listener) throws IOException, InterruptedException {
+ public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
PrintStream log = listener.getLogger();
// Default value of disk space check is 1Gb
- int SpaceThreshold;
- SpaceThreshold = PluginImpl.getInstance().getSpacecheck();
+ final int SpaceThreshold = PluginImpl.getInstance().getSpacecheck();
-
log.println("Disk space threshold is set to :" + SpaceThreshold + "Gb");
log.println("Checking disk space Now ");
@@ -96,85 +90,61 @@ public void preCheckout(AbstractBuild build, Launcher launcher,
build.getWorkspace().mkdirs();
}
- Node node1 = build.getBuiltOn();
- Computer Comp = node1.toComputer();
- String NodeName = build.getBuiltOnStr();
- /* if (Comp.getChannel()==null)
- {
- log.println("Can not get slave infomration wait for 10 sec \n");
- Thread.sleep(10000);
- if (Comp.getChannel()==null)
- {
- log.println("Waited long enough to get slave information exiting discheck for now \n");
- System.exit(0);
- }
-
- }
- */
-
- if ( DiskSpaceMonitor.DESCRIPTOR.get(Comp)== null )
- { log.println("No Slave Data available trying to get data from slave");
- Thread.sleep(10000);
- if ( DiskSpaceMonitor.DESCRIPTOR.get(Comp)== null )
-
- log.println(" Could not get Slave Information , Exiting Disk check for this slave");
- System.exit(0);
+ final Computer Comp = build.getBuiltOn().toComputer();
+ final String NodeName = build.getBuiltOnStr() == "" ? "master" : build.getBuiltOnStr();
+
+ if ( DiskSpaceMonitor.DESCRIPTOR.get(Comp) == null ) {
+ log.println("No Slave Data available trying to get data from slave");
+ Thread.sleep(10000); // ???
+
+ if ( DiskSpaceMonitor.DESCRIPTOR.get(Comp) == null ) {
+ log.println(" Could not get Slave Information, Exiting Disk check for this slave");
+ System.exit(0);
+ }
}
- long size=0;
- try
- {
- size = DiskSpaceMonitor.DESCRIPTOR.get(Comp).size;
+ int roundedSize = 0;
+ try {
+ long size = DiskSpaceMonitor.DESCRIPTOR.get(Comp).size;
+ roundedSize = (int) (size / (1024 * 1024 * 1024));
}
- catch(NullPointerException e ){
- log.println("Could not get Slave Information , Exiting Disk check for this slave");
- System.exit(0);
- }
- int roundedSize = (int) (size / (1024 * 1024 * 1024));
- log.println("Total Disk Space Available is: " + roundedSize + "Gb");
-
- if (build.getBuiltOnStr() == "") {
- NodeName = "master";
+ catch (NullPointerException e) {
+ log.println("Could not get Slave disk size Information: " + e + ".\nExiting Disk check for this slave.");
+ System.exit(0);
}
- log.println(" Node Name: " + NodeName);
+ log.println("Total Disk Space Available is: " + roundedSize + "Gb");
+ log.println("Node Name: " + NodeName);
- if (PluginImpl.getInstance().isDiskrecyclerenabled()) {
- if (roundedSize < SpaceThreshold) {
+ if (roundedSize < SpaceThreshold) {
+ if (PluginImpl.getInstance().isDiskrecyclerenabled()) {
log.println("Disk Recycler is Enabled so I am going to wipe off the workspace Directory Now ");
- String mycommand = "echo $WORKSPACE; rm -rf $WORKSPACE/../; df -k .";
- String mywincommand = "echo Deleting file from %WORKSPACE% && Del /R %WORKSPACE%";
-
- /**
- * This method will return the command intercepter as per the
- * node OS
- *
- * @param launcher
- * @param script
- * @return CommandInterpreter
- */
+
CommandInterpreter runscript;
- if (launcher.isUnix())
- runscript = new Shell(mycommand);
- else
- runscript = new BatchFile(mywincommand);
+ if (launcher.isUnix()) {
+ String cmd = "echo Deleting directory $WORKSPACE && rm -rf $WORKSPACE";
+
+ runscript = new Shell(cmd);
+ }
+ else {
+ /*
+ rmdir syntax
+ /S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree.
+ /Q Quiet mode, do not ask if ok to remove a directory tree with /S.
+ */
+ String cmd = "echo Deleting directory %WORKSPACE% && rmdir /S /Q %WORKSPACE%";
+
+ runscript = new BatchFile(cmd);
+ }
- Result result = runscript.perform(build, launcher, listener) ? Result.SUCCESS
- : Result.FAILURE;
+ Result result = runscript.perform(build, launcher, listener) ? Result.SUCCESS : Result.FAILURE;
if (result.toString() == "FAILURE") {
- throw new AbortException(
- "Something went wrong while deleting Files , Please check the error message above");
+ throw new AbortException("Something went wrong while deleting workspace. Please check the error message above");
}
}
- }
-
- log.println("Running Prebuild steps");
- if (roundedSize < SpaceThreshold
- && !(PluginImpl.getInstance().isDiskrecyclerenabled())) {
- throw new AbortException(
- "Disk Space is too low please look into it before starting a build");
-
+ } else {
+ throw new AbortException("Disk Space is too low please look into it before starting a build");
}
}
@@ -186,19 +156,14 @@ public static final class DescriptorImpl extends Descriptor {
* This human readable name is used in the configuration screen.
*/
public String getDisplayName() {
- return "Check Disk Space";
- }
-
-
+ return "Check Disk Space";
+ }
public DescriptorImpl() {
load();
}
-
-
}
-
class NoopEnv extends Environment {
}
}
diff --git a/src/main/java/org/jenkinsci/plugin/PluginImpl.java b/src/main/java/org/jenkinsci/plugin/PluginImpl.java
old mode 100755
new mode 100644
index f8c44cd..6ec92c8
--- a/src/main/java/org/jenkinsci/plugin/PluginImpl.java
+++ b/src/main/java/org/jenkinsci/plugin/PluginImpl.java
@@ -42,32 +42,26 @@ public void stop() throws Exception {
}
@Override
- public void configure(StaplerRequest req, JSONObject formData)
- throws IOException, ServletException, FormException {
- formData=formData.getJSONObject("disk-check");
- spacecheck=formData.getInt("spacecheck");
- diskrecyclerenabled=formData.getBoolean("diskrecyclerenabled");
+ public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, FormException {
+ formData = formData.getJSONObject("disk-check");
+ spacecheck = formData.getInt("spacecheck");
+ diskrecyclerenabled = formData.getBoolean("diskrecyclerenabled");
save();
super.configure(req, formData);
-
}
-
-
public void setDiskrecyclerenabled(boolean diskrecyclerenabled) {
- this.diskrecyclerenabled = diskrecyclerenabled;
-}
+ this.diskrecyclerenabled = diskrecyclerenabled;
+ }
- public int getSpacecheck()
- {
+ public int getSpacecheck() {
return spacecheck;
}
- public void setSpacecheck(int spaceheck)
- {
- this.spacecheck = spacecheck;
-}
+ public void setSpacecheck(int spaceheck) {
+ this.spacecheck = spacecheck;
+ }
public boolean isDiskrecyclerenabled() {
return diskrecyclerenabled;