diff options
Diffstat (limited to 'JettyTempCleaner')
-rw-r--r-- | JettyTempCleaner/pom.xml | 173 | ||||
-rw-r--r-- | JettyTempCleaner/src/main/java/JettyTempCleaner.java | 57 |
2 files changed, 230 insertions, 0 deletions
diff --git a/JettyTempCleaner/pom.xml b/JettyTempCleaner/pom.xml new file mode 100644 index 00000000..8924fb0d --- /dev/null +++ b/JettyTempCleaner/pom.xml @@ -0,0 +1,173 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>at.gv.egiz</groupId> + <artifactId>mocca</artifactId> + <version>1.3.21-SNAPSHOT</version> + </parent> + <artifactId>JettyTempCleaner</artifactId> + <name>Jetty Temp Cleaner</name> + <url>http://joinup.ec.europa.eu/site/mocca/</url> + <description>Clean Jetty temp dir under windows after MOCCA webstart finishes</description> + <build> + <plugins> + <plugin> + <artifactId>buildnumber-maven-plugin</artifactId> + <groupId>org.codehaus.mojo</groupId> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>create</goal> + </goals> + </execution> + </executions> + <configuration> + <doCheck>false</doCheck> + <doUpdate>false</doUpdate> + <revisionOnScmFailure>SvnRevMissing</revisionOnScmFailure> + </configuration> + </plugin> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <executions> + <execution> + <goals> + <goal>sign</goal> + </goals> + <!--configuration> + <jarPath>${project.build.directory}/${project.build.finalName}-single.${project.packaging}</jarPath> + </configuration--> + </execution> + </executions> + <configuration> + <archive> + <addMavenDescriptor>false</addMavenDescriptor> + <index>false</index> + <manifest> + <addClasspath>false</addClasspath> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <mainClass>JettyTempCleaner</mainClass> + </manifest> + <manifestEntries> + <Application-Name>JettyTempCleaner</Application-Name> + <Implementation-Build>${project.version}-r${buildNumber}</Implementation-Build> + <Permissions>all-permissions</Permissions> + <Codebase>*</Codebase> + <Caller-Allowable-Codebase>*</Caller-Allowable-Codebase> + <Trusted-Library>true</Trusted-Library> + </manifestEntries> + </archive> + <alias>test-applet signer</alias> + <keystore>../BKUApplet/keystore.ks</keystore> + <storepass>storepass</storepass> + <keypass>keypass</keypass> + <verify>true</verify> + </configuration> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>pkcs11-sign</id> + <build> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <version>2.2-mocca</version> + <configuration> + <keystore>NONE</keystore> + <type>PKCS11</type> + <providerClass>iaik.pkcs.pkcs11.provider.IAIKPkcs11</providerClass> + <alias>a-sit-2</alias> + <storepass>${pkcs11-pass}</storepass> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>ks-sign</id> + <build> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <version>2.2-mocca</version> + <configuration> + <keystore>${ks-file}</keystore> + <alias>a-sit-3</alias> + <storepass>${ks-pass}</storepass> + <keypass>${ks-pass}</keypass> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <!-- + This profile is here for triggering when another scm than svn is + used (for example git). Get the git commit hash. + --> + <id>buildnumber-git</id> + <activation> + <file> + <missing>.svn</missing> + </file> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.groovy.maven</groupId> + <artifactId>gmaven-plugin</artifactId> + <version>1.0</version> + <executions> + <execution> + <phase>generate-resources</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source> + def shell = "sh" + def param = "-c" + if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) { + shell = "cmd" + param = "/c" + } + def gitSvnProc = [shell, param, "git rev-parse --short HEAD"].execute() + gitSvnProc.waitFor() + def svnref = gitSvnProc.in.text.trim() + project.properties['gitSvnRev'] = svnref + </source> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>buildnumber-maven-plugin</artifactId> + <executions> + <execution> + <phase>generate-resources</phase> + <goals> + <goal>create</goal> + </goals> + </execution> + </executions> + <configuration> + <doCheck>false</doCheck> + <doUpdate>false</doUpdate> + <format>{0}</format> + <items> + <item>${gitSvnRev}</item> + </items> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> 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(); + } +} |