Author: chatellier Date: 2009-10-29 17:48:44 +0000 (Thu, 29 Oct 2009) New Revision: 2718 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java Log: Use uncompress method moved to nuiton-utils. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-10-29 17:10:06 UTC (rev 2717) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-10-29 17:48:44 UTC (rev 2718) @@ -45,6 +45,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.util.FileUtil; import org.nuiton.util.MD5; +import org.nuiton.util.ZipUtil; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; @@ -414,10 +415,10 @@ // FIXME big hacks here, only extract non first simulation // only for AS if (control.getId().startsWith("as_") && !control.getId().endsWith("_0")) { - uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory(), ".*/data/.*"); + ZipUtil.uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory(), ".*/data/.*"); } else { - uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory()); + ZipUtil.uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory()); } if (log.isDebugEnabled()) { @@ -1065,56 +1066,4 @@ return remotePath; } - - /** - * Unzip compressed archive and keep non exluded patterns. - * - * @param file archive file - * @param targetDir destination file - * @param excludes excludes pattern (pattern must match complete entry name including root folder) - * @throws IOException - * - * @deprecated this code may be in lutin util later... - */ - protected void uncompressFiltred(File file, File targetDir, String... excludes) throws IOException { - - ZipFile zipFile = new ZipFile(file); - - Enumeration<? extends ZipEntry> entries = zipFile.entries(); - - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - - String name = entry.getName(); - // add continue to break loop - boolean excludeEntry = false; - if (excludes != null) { - for (String exclude : excludes) { - if (name.matches(exclude)) { - excludeEntry = true; - } - } - } - - if (!excludeEntry) { - File target = new File(targetDir, name); - if (entry.isDirectory()) { - target.mkdirs(); - } else { - // get inputstream only here - InputStream in = zipFile.getInputStream(entry); - target.getParentFile().mkdirs(); - OutputStream out = new BufferedOutputStream(new FileOutputStream(target)); - byte[] buffer = new byte[8 * 1024]; - int len; - - while ((len = in.read(buffer, 0, 8 * 1024)) != -1) { - out.write(buffer, 0, len); - } - out.close(); - in.close(); - } - } - } - } } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-10-29 17:10:06 UTC (rev 2717) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-10-29 17:48:44 UTC (rev 2718) @@ -183,49 +183,4 @@ Assert.assertTrue("Invalid qsub script is used", content .indexOf("!/bin/csh") > 0); } - - /** - * Test la fonction de decompression sans filtres. - * - * @throws IOException - */ - @Test - public void testPartialUncompress() throws IOException { - File archive = new File("src" + File.separator + "test" - + File.separator + "resources" + File.separator + "simulations" - + File.separator + "test-nonregression-20090203.zip"); - File dest = new File(getCurrentDatabaseDirectory(), "testunzip"); - - if (log.isInfoEnabled()) { - log.info("Extracting " + archive + " to " + dest); - } - - SSHSimulatorLauncher launcher = new SSHSimulatorLauncher(); - launcher.uncompressFiltred(archive, dest); - File ruleFile = new File(dest, "test-nonregression-20090203" + File.separator + "scripts" + File.separator + "RuleUtil.java"); - Assert.assertTrue(ruleFile.exists()); - } - - /** - * Test la fonction de decompression avec filtres. - * - * @throws IOException - */ - @Test - public void testPartialUncompressFiltred() throws IOException { - File archive = new File("src" + File.separator + "test" - + File.separator + "resources" + File.separator + "simulations" - + File.separator + "test-nonregression-20090203.zip"); - File dest = new File(getCurrentDatabaseDirectory(), "testunzip2"); - String pattern = ".*/scripts/.*"; - - if (log.isInfoEnabled()) { - log.info("Extracting " + archive + " to " + dest + " without " + pattern); - } - - SSHSimulatorLauncher launcher = new SSHSimulatorLauncher(); - launcher.uncompressFiltred(archive, dest, pattern); - File ruleFile = new File(dest, "test-nonregression-20090203" + File.separator + "scripts" + File.separator + "RuleUtil.java"); - Assert.assertFalse(ruleFile.exists()); - } } \ No newline at end of file