summaryrefslogtreecommitdiff
path: root/JettyTempCleaner/src/main
diff options
context:
space:
mode:
authorTobias Kellner <tobias.kellner@iaik.tugraz.at>2015-10-20 17:26:18 +0200
committerTobias Kellner <tobias.kellner@iaik.tugraz.at>2015-10-20 18:04:11 +0200
commitc2b94e353bc398d847e25c28ff2210cbc59b6cbe (patch)
tree1feb05a6fec3caefc1e0d3561c6e994caef19e30 /JettyTempCleaner/src/main
parent300c3452d7e93cd42c0626310790a6df7c81b846 (diff)
downloadmocca-c2b94e353bc398d847e25c28ff2210cbc59b6cbe.tar.gz
mocca-c2b94e353bc398d847e25c28ff2210cbc59b6cbe.tar.bz2
mocca-c2b94e353bc398d847e25c28ff2210cbc59b6cbe.zip
Move JettyTempCleaner to own module, create signed jar
Diffstat (limited to 'JettyTempCleaner/src/main')
-rw-r--r--JettyTempCleaner/src/main/java/JettyTempCleaner.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/JettyTempCleaner/src/main/java/JettyTempCleaner.java b/JettyTempCleaner/src/main/java/JettyTempCleaner.java
new file mode 100644
index 00000000..67854ecb
--- /dev/null
+++ b/JettyTempCleaner/src/main/java/JettyTempCleaner.java
@@ -0,0 +1,57 @@
+import java.io.File;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class JettyTempCleaner extends TimerTask {
+
+ private static final long CLEAN_INTERVAL = 60000; // 1 minute
+
+ private File tmpDir;
+
+ public JettyTempCleaner(File tmpDir) {
+ this.tmpDir = tmpDir;
+ }
+
+ private static boolean deleteRecursive(File f) {
+ if (f.isDirectory()) {
+ String[] children = f.list();
+ for (String child : children) {
+ if (!deleteRecursive(new File(f, child)))
+ return false;
+ }
+ }
+ return f.delete();
+ }
+
+ private static void clean(File tmpDir) {
+ System.out.println("Trying to remove " + tmpDir);
+ if (deleteRecursive(tmpDir)) {
+ System.out.println("Successfully removed temporary directory");
+ System.exit(0);
+ }
+ }
+
+ private void schedule() {
+ System.out.println("Scheduling cleaner for directory " + tmpDir);
+ Timer t = new Timer();
+ t.scheduleAtFixedRate(this, 1000, CLEAN_INTERVAL);
+ }
+
+ @Override
+ public void run() {
+ clean(tmpDir);
+ }
+
+ public static void main(String[] args) {
+ if (args.length != 1)
+ System.exit(1);
+ File tmpDir = new File(args[0]);
+ if (!tmpDir.exists())
+ {
+ System.err.println("Directory " + args[0] + " doesn't exist");
+ System.exit(2);
+ }
+ JettyTempCleaner cleaner = new JettyTempCleaner(tmpDir);
+ cleaner.schedule();
+ }
+}