Author: chatellier Date: 2009-08-25 13:18:04 +0000 (Tue, 25 Aug 2009) New Revision: 2523 Modified: isis-fish/trunk/changelog.txt isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java Log: Don't extract everything only in AS case. Modified: isis-fish/trunk/changelog.txt =================================================================== --- isis-fish/trunk/changelog.txt 2009-08-25 08:24:53 UTC (rev 2522) +++ isis-fish/trunk/changelog.txt 2009-08-25 13:18:04 UTC (rev 2523) @@ -1,5 +1,6 @@ isis-fish (3.2.0.5) stable; urgency=low + * Don't extract database for sensitivity analysis (excepted first) * Add user script javadoc generation * Move script import/export to Jaxx * Fix nano time problem (not related to real date) 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-08-25 08:24:53 UTC (rev 2522) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-08-25 13:18:04 UTC (rev 2523) @@ -20,10 +20,14 @@ import static org.codelutin.i18n.I18n._; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; import java.rmi.RemoteException; @@ -32,6 +36,8 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.Semaphore; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -385,8 +391,17 @@ // FIXME too slow methods //SimulationStorage.importZip(resultZipFile); //Tbz2Util.uncompress(resultArchiveFile, SimulationStorage.getSimulationDirectory()); - ZipUtil.uncompress(resultArchiveFile, SimulationStorage.getSimulationDirectory()); - + //ZipUtil.uncompress(resultArchiveFile, SimulationStorage.getSimulationDirectory()); + + // 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/.*"); + } + else { + uncompressFiltred(resultArchiveFile, SimulationStorage.getSimulationDirectory()); + } + if (log.isDebugEnabled()) { log.debug("Simulation imported : " + resultArchiveFile.getAbsolutePath()); } @@ -1036,4 +1051,49 @@ return remotePath; } + + /** + * Unzip compressed archive and keep non exluded patterns. + * + * @param file archive file + * @param targetDir destination file + * @param excludes excludes pattern + * @throws IOException + */ + protected void uncompressFiltred(File file, File targetDir, String... excludes) throws IOException { + ZipInputStream in = new ZipInputStream(new FileInputStream(file)); + ZipEntry entry; + while ((entry = in.getNextEntry()) != null) { + + String name = entry.getName(); + + // add continue to break loop + if (excludes != null) { + boolean excludeEntry = false; + for (String exclude : excludes) { + if (name.matches(exclude)) { + excludeEntry = true; + } + } + if (excludeEntry) { + continue; + } + } + + File target = new File(targetDir, name); + if (entry.isDirectory()) { + target.mkdirs(); + } else { + 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/main/resources/i18n/isis-fish-fr_FR.properties =================================================================== --- isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-08-25 08:24:53 UTC (rev 2522) +++ isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-08-25 13:18:04 UTC (rev 2523) @@ -877,7 +877,6 @@ isisfish.script.menu.edit=\u00C9dition isisfish.script.menu.evaluate=Evaluer isisfish.script.menu.file=Fichier -isisfish.script.menu.generatejavadoc=G\u00E9n\u00E9rer la javadoc isisfish.script.menu.javadocgenerate=G\u00E9n\u00E9rer la javadoc isisfish.script.menu.javadocgenerated=Javadoc g\u00E9n\u00E9r\u00E9e dans %s isisfish.script.menu.javadocgenerating=Javadoc en cours de g\u00E9n\u00E9ration dans %s... 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-08-25 08:24:53 UTC (rev 2522) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-08-25 13:18:04 UTC (rev 2523) @@ -18,14 +18,20 @@ package fr.ifremer.isisfish.simulator.launcher; +import java.io.File; import java.io.IOException; import junit.framework.Assert; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; +import com.sun.source.tree.AssertTree; + import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.simulator.SimulationHelperTest; import freemarker.template.TemplateException; /** @@ -40,6 +46,9 @@ */ public class SshSimulatorLauncherTest extends AbstractIsisFishTest { + /** Commons logging log. */ + private static Log log = LogFactory.getLog(SshSimulatorLauncherTest.class); + /** * Test l'instantiation du script qsub (caparmor). * @@ -65,15 +74,16 @@ SIMULATIONZIP, SIMULATIONRESULTZIP, SIMULATIONPRESCRIPT); // simulation parameters - Assert.assertTrue("String \"" + SIMULATIONID + Assert + .assertTrue("String \"" + SIMULATIONID + "\" not found in template", content .indexOf(SIMULATIONID) > 0); Assert.assertTrue("String \"" + SIMULATIONZIP + "\" not found in template", content.indexOf(SIMULATIONZIP) > 0); Assert.assertTrue("String \"" + SIMULATIONRESULTZIP - + "\" not found in template", - content.indexOf(SIMULATIONRESULTZIP) > 0); + + "\" not found in template", content + .indexOf(SIMULATIONRESULTZIP) > 0); Assert.assertTrue("String \"" + SIMULATIONPRESCRIPT + "\" not found in template", content .indexOf(SIMULATIONPRESCRIPT) > 0); @@ -113,17 +123,18 @@ SIMULATIONZIP, SIMULATIONRESULTZIP, SIMULATIONPRESCRIPT); // simulation parameters - Assert.assertTrue("String \"" + SIMULATIONID + Assert + .assertTrue("String \"" + SIMULATIONID + "\" not found in template", content .indexOf(SIMULATIONID) > 0); Assert.assertTrue("String \"" + SIMULATIONZIP + "\" not found in template", content.indexOf(SIMULATIONZIP) > 0); Assert.assertTrue("String \"" + SIMULATIONRESULTZIP - + "\" not found in template", - content.indexOf(SIMULATIONRESULTZIP) > 0); - Assert.assertTrue("Action --simulateRemotelly not on script", - content.indexOf(" --simulateRemotelly ") > 0); + + "\" not found in template", content + .indexOf(SIMULATIONRESULTZIP) > 0); + Assert.assertTrue("Action --simulateRemotelly not on script", content + .indexOf(" --simulateRemotelly ") > 0); // isis location Assert.assertTrue("String \"" + ISISHOME + "\" not found in template", @@ -141,11 +152,55 @@ public void testValidQsubScript() throws IOException { SSHSimulatorLauncher launcher = new SSHSimulatorLauncher(); String content = launcher.getSimulationScriptLaunchContent( - SSHSimulatorLauncher.QSUB_SCRIPT_TEMPLATE, "", - "", "", ""); + SSHSimulatorLauncher.QSUB_SCRIPT_TEMPLATE, "", "", "", ""); // simulation parameters Assert.assertTrue("Invalid qsub script is used", content - .indexOf("!/bin/csh") > 0); + .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(), "testunzip"); + 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
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org