diff options
-rw-r--r-- | BKUWebStart/pom.xml | 7 | ||||
-rw-r--r-- | BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java | 107 | ||||
-rw-r--r-- | JettyTempCleaner/pom.xml | 173 | ||||
-rw-r--r-- | JettyTempCleaner/src/main/java/JettyTempCleaner.java | 57 | ||||
-rw-r--r-- | JettyTempCleaner/src/site/apt/index.apt | 12 | ||||
-rw-r--r-- | JettyTempCleaner/src/site/site.xml | 42 | ||||
-rw-r--r-- | pom.xml | 1 |
7 files changed, 71 insertions, 328 deletions
diff --git a/BKUWebStart/pom.xml b/BKUWebStart/pom.xml index e58e0177..313afb82 100644 --- a/BKUWebStart/pom.xml +++ b/BKUWebStart/pom.xml @@ -29,7 +29,7 @@ <goal>copy-dependencies</goal> </goals> <configuration> - <includeArtifactIds>BKULocal,JettyTempCleaner</includeArtifactIds> + <includeArtifactIds>BKULocal</includeArtifactIds> <includeGroupIds>at.gv.egiz</includeGroupIds> <outputDirectory>${project.build.directory}/classes</outputDirectory> <stripVersion>true</stripVersion> @@ -344,11 +344,6 @@ <artifactId>BKUCertificates</artifactId> </dependency> <dependency> - <groupId>at.gv.egiz</groupId> - <artifactId>JettyTempCleaner</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>iaik</groupId> <artifactId>iaik_jce_full_signed</artifactId> <scope>compile</scope> diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java index ab3d9a42..f4bd14b6 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java @@ -37,10 +37,9 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintWriter; import java.security.KeyStore; import java.security.cert.Certificate; -import java.util.ArrayList; -import java.util.List; import java.util.Locale; import org.mortbay.jetty.Connector; @@ -57,7 +56,7 @@ public class Container { public static final String HTTP_PORT_PROPERTY = "mocca.http.port"; public static final String HTTPS_PORT_PROPERTY = "mocca.https.port"; - private static final String JETTY_TEMP_CLEANER_JAR = "JettyTempCleaner.jar"; + private static final String JETTY_TEMP_STORE = ".jettytemp"; private static Logger log = LoggerFactory.getLogger(Container.class); @@ -85,6 +84,7 @@ public class Container { public void init() throws IOException { // System.setProperty("DEBUG", "true"); + deleteJettyTemp(); server = new Server(); QueuedThreadPool qtp = new QueuedThreadPool(); qtp.setMaxThreads(5); @@ -175,40 +175,76 @@ public class Container { return webapp.getPath(); } - private void copyCleaner(File dir) throws IOException { - File cleanerJar = new File(dir, JETTY_TEMP_CLEANER_JAR); - log.debug("copying JettyTempCleaner to " + cleanerJar); - InputStream is = getClass().getClassLoader().getResourceAsStream(JETTY_TEMP_CLEANER_JAR); - OutputStream os; - os = new BufferedOutputStream(new FileOutputStream(cleanerJar)); - new StreamCopier(is, os).copyStream(); - os.close(); + 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) { + log.debug("Trying to remove " + tmpDir); + if (deleteRecursive(tmpDir)) { + log.debug("Successfully removed temporary directory"); + } } - private void cleanupJettyTemp() { + private void storeJettyTemp() { String os = System.getProperty("os.name"); - if (os.toLowerCase().contains("windows")) { - try { - File userDir = new File(System.getProperty("user.home") + "/" + Configurator.BKU_USER_DIR); - if (!userDir.exists()) - { - log.error("User directory " + userDir + " not found"); - return; - } - copyCleaner(userDir); - List<String> args = new ArrayList<String>(); - args.add("java"); - args.add("-jar"); - args.add(JETTY_TEMP_CLEANER_JAR); - args.add(tempDir.getAbsolutePath()); - ProcessBuilder pb = new ProcessBuilder(args); - pb.directory(userDir); - log.debug("Starting " + JETTY_TEMP_CLEANER_JAR + " to remove " + tempDir.getAbsolutePath()); - pb.start(); - } catch (IOException e) { - log.error("Failed to copy jetty temp cleaner", e); - e.printStackTrace(); + if (!os.toLowerCase().contains("windows")) + return; + try { + File userDir = new File(System.getProperty("user.home") + "/" + Configurator.BKU_USER_DIR); + if (!userDir.exists()) + { + log.error("User directory " + userDir + " not found"); + return; } + File jettytempstore = new File(userDir, JETTY_TEMP_STORE); + PrintWriter w = new PrintWriter(jettytempstore, "UTF-8"); + w.println(tempDir.getAbsolutePath()); + w.close(); + log.debug("Stored jetty temp dir " + tempDir.getAbsolutePath() + " for removal on next start"); + } catch (IOException e) { + log.error("Failed to copy jetty temp cleaner", e); + e.printStackTrace(); + } + } + + private void deleteJettyTemp() { + String os = System.getProperty("os.name"); + if (!os.toLowerCase().contains("windows")) + return; + try { + File userDir = new File(System.getProperty("user.home") + "/" + Configurator.BKU_USER_DIR); + if (!userDir.exists()) + { + log.error("User directory " + userDir + " not found"); + return; + } + File jettytempstore = new File(userDir, JETTY_TEMP_STORE); + if (!jettytempstore.exists()) + { + log.debug("No Jetty temp store file found"); + return; + } + BufferedReader r = new BufferedReader(new FileReader(jettytempstore)); + File oldTemp = new File(r.readLine()); + if (oldTemp.exists()) { + log.info("Deleting old jetty temp dir " + oldTemp); + clean(oldTemp); + } else { + log.debug("Old jetty temp dir " + oldTemp + " doesn't exist anymore"); + } + r.close(); + jettytempstore.delete(); + } catch (IOException e) { + log.error("Failed to copy jetty temp cleaner", e); + e.printStackTrace(); } } @@ -246,14 +282,11 @@ public class Container { public void stop() throws Exception { server.stop(); - - cleanupJettyTemp(); + storeJettyTemp(); } public void destroy() { server.destroy(); - - cleanupJettyTemp(); } public void join() throws InterruptedException { diff --git a/JettyTempCleaner/pom.xml b/JettyTempCleaner/pom.xml deleted file mode 100644 index 5d23bc47..00000000 --- a/JettyTempCleaner/pom.xml +++ /dev/null @@ -1,173 +0,0 @@ -<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.23-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 deleted file mode 100644 index 67854ecb..00000000 --- a/JettyTempCleaner/src/main/java/JettyTempCleaner.java +++ /dev/null @@ -1,57 +0,0 @@ -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(); - } -} diff --git a/JettyTempCleaner/src/site/apt/index.apt b/JettyTempCleaner/src/site/apt/index.apt deleted file mode 100644 index d60219dc..00000000 --- a/JettyTempCleaner/src/site/apt/index.apt +++ /dev/null @@ -1,12 +0,0 @@ - --- - About - --- - EGIZ - --- - 2015 - --- - -Jetty Temp Cleaner - - This module is used to remove temporary files used by jetty after the execution of MOCCA ended - under Microsoft Windows, as those files can't be deleted at runtime. diff --git a/JettyTempCleaner/src/site/site.xml b/JettyTempCleaner/src/site/site.xml deleted file mode 100644 index a1191b25..00000000 --- a/JettyTempCleaner/src/site/site.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - Copyright 2015 by Graz University of Technology, Austria - MOCCA has been developed by the E-Government Innovation Center EGIZ, a joint - initiative of the Federal Chancellery Austria and Graz University of Technology. - - Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - the European Commission - subsequent versions of the EUPL (the "Licence"); - You may not use this work except in compliance with the Licence. - You may obtain a copy of the Licence at: - http://www.osor.eu/eupl/ - - Unless required by applicable law or agreed to in writing, software - distributed under the Licence is distributed on an "AS IS" basis, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the Licence for the specific language governing permissions and - limitations under the Licence. - - This product combines work with different licenses. See the "NOTICE" text - file for details on the various modules and licenses. - The "NOTICE" text file is part of the distribution. Any derivative works - that you distribute must include a readable copy of the "NOTICE" text file. ---> - -<project name="MOCCA"> - <publishDate position="right"/> - <bannerLeft> - <name>MOCCA</name> - <src>../images/mocca2-t_s.png</src> - <href>http://joinup.ec.europa.eu/site/mocca/</href> - </bannerLeft> - - <body> - - <menu ref="parent"/> - - <menu ref="reports"/> - - </body> - -</project> @@ -33,7 +33,6 @@ <module>BKUGuiExt</module> <module>smccSTALExt</module> <module>BKUFonts</module> - <module>JettyTempCleaner</module> </modules> <inceptionYear>2007</inceptionYear> <developers> |