r3615 - in trunk/src/main/java/fr/ifremer/isisfish: . datastore ui/script util
Author: echatellier Date: 2012-02-24 17:46:43 +0100 (Fri, 24 Feb 2012) New Revision: 3615 Url: http://forge.codelutin.com/repositories/revision/isis-fish/3615 Log: #846 : Scripts comming from community repository often do not work Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/JavaSourceStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityAnalysisStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationPlanStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -33,6 +33,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; +import java.io.FileFilter; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; @@ -46,6 +47,7 @@ import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.I18n; @@ -57,14 +59,14 @@ import org.nuiton.widget.SwingSession; import fr.ifremer.isisfish.cron.CronService; -import fr.ifremer.isisfish.datastore.SimulationPlanStorage; import fr.ifremer.isisfish.datastore.ExportStorage; import fr.ifremer.isisfish.datastore.FormuleStorage; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.datastore.ScriptStorage; +import fr.ifremer.isisfish.datastore.SensitivityAnalysisStorage; import fr.ifremer.isisfish.datastore.SensitivityExportStorage; -import fr.ifremer.isisfish.datastore.SensitivityAnalysisStorage; +import fr.ifremer.isisfish.datastore.SimulationPlanStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; import fr.ifremer.isisfish.simulator.launcher.SimulationService; @@ -140,6 +142,7 @@ try { initVCS(); initCommunityVCS(); + checkDuplicatedFiles(); } catch (Exception eee) { log.warn(_("Error during vcs initialisation"), eee); } @@ -530,6 +533,34 @@ } /** + * Look for duplicated file name in official repository and community + * repository and rename duplicated in community repository. + */ + protected static void checkDuplicatedFiles() { + + // get official file list + List<File> offFiles = FileUtil.getFilteredElements(IsisFish.config.getDatabaseDirectory(), new FileFilter() { + @Override + public boolean accept(File pathname) { + return pathname.getName().endsWith(".java"); + } + }, true); + + // compare it with community repo + for (File offFile : offFiles) { + File comFile = new File(IsisFish.config.getCommunityDatabaseDirectory() + + StringUtils.removeStart(offFile.getAbsolutePath(), IsisFish.config.getDatabaseDirectory().getAbsolutePath())); + if (comFile.isFile()) { + if (log.isWarnEnabled()) { + log.warn("Found file collision for " + comFile.getAbsolutePath()); + } + File newFile = new File(comFile.getParentFile(), "Duplicated_" + comFile.getName()); + comFile.renameTo(newFile); + } + } + } + + /** * Display dialog with files list, and specifique label. * * @param dialogTitle dialog title Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -27,11 +27,14 @@ import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.Iterator; import java.util.List; import org.nuiton.util.FileUtil; +import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishRuntimeException; /** @@ -42,6 +45,7 @@ * {@link fr.ifremer.isisfish.datastore.ExportStorage}, * {@link fr.ifremer.isisfish.datastore.SimulationPlanStorage}, * {@link fr.ifremer.isisfish.datastore.SensitivityAnalysisStorage} + * {@link fr.ifremer.isisfish.datastore.SensitivityExportStorage} * * Created: 21 janv. 2006 15:20:24 * @@ -54,6 +58,49 @@ public abstract class CodeSourceStorage extends VersionStorage { /** + * Location enum to look for script in official repository or + * community directory. + * + * Implements iterable to be used in JavaFileManager. + */ + public static enum Location implements Iterable<File> { + OFFICIAL(IsisFish.config.getDatabaseDirectory()), + COMMUNITY(IsisFish.config.getCommunityDatabaseDirectory()), + ALL(IsisFish.config.getDatabaseDirectory(), IsisFish.config.getCommunityDatabaseDirectory()); + + protected File[] directory; + private Location(File... directory) { + this.directory = directory; + } + + public File[] getDirectories() { + return directory; + } + + /* + * @see java.lang.Iterable#iterator() + */ + @Override + public Iterator<File> iterator() { + List<File> files = Arrays.asList(directory); + return files.iterator(); + } + } + + /** + * Get non empty location. + * + * @param location current location (if empty, return {@link Location#All}. + */ + protected static Location[] nonEmptyLocation(Location... location) { + Location[] locs = location; + if (locs == null || locs.length == 0) { + locs = Location.values(); + } + return locs; + } + + /** * Le nom de la classe sans le package. */ protected String name = null; Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ExportStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -37,6 +37,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.export.Export; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.util.Docable; @@ -65,7 +66,7 @@ public static final String EXPORT_TEMPLATE = "templates/script/export.ftl"; @SuppressWarnings("unchecked") - private static Map<String, ExportStorage> scriptsCache = (Map<String, ExportStorage>) new ReferenceMap(); + private static Map<String, ExportStorage> exportCache = (Map<String, ExportStorage>) new ReferenceMap(); /** * Constructeur. @@ -115,34 +116,38 @@ * Retourne le storage pour l'export demandée * * @param name le nom de l'export souhaitée + * @param location location to open storage file * @return Le storage pour l'export */ - public static ExportStorage getExport(String name) { - String cacheName = getContextDatabaseCacheKey(name); - ExportStorage result = scriptsCache.get(cacheName); + public static ExportStorage getExport(String name, Location... location) { + ExportStorage result = exportCache.get(name); if (result == null) { - result = new ExportStorage(getContextDatabaseDirectory(), - getExportDirectory(), name); - scriptsCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + ExportStorage storage = new ExportStorage(dir, new File(dir, EXPORT_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + exportCache.put(name, result); + } + } + } } return result; } - + /** - * Retourne le storage pour l'export demandée - * - * @param name le nom de l'export souhaitée - * @return Le storage pour l'export + * Create new export. + * + * @param name new export to create + * @param location location to create storage file + * @return new export storage */ - public static ExportStorage getCommunityExport(String name) { - String cacheName = getCommunityDatabaseCacheKey(name); - ExportStorage result = scriptsCache.get(cacheName); - if (result == null) { - result = new ExportStorage(getCommunityDatabaseDirectory(), - getCommunityExportDirectory(), name); - scriptsCache.put(cacheName, result); - } - return result; + public static ExportStorage createExport(String name, Location location) { + File dir = location.getDirectories()[0]; + ExportStorage storage = new ExportStorage(dir, new File(dir, EXPORT_PATH), name); + return storage; } /** Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/JavaSourceStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/JavaSourceStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/JavaSourceStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/RegionStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -163,18 +163,16 @@ @Override public void rename(String toName) throws StorageException { try { - String cacheName = getContextDatabaseCacheKey(getName()); - regions.remove(cacheName); + regions.remove(getName()); super.rename(toName); TopiaContext tx = getStorage().beginTransaction(); FisheryRegion region = getFisheryRegion(tx); region.setName(toName); tx.commitTransaction(); tx.closeContext(); - - cacheName = getContextDatabaseCacheKey(toName); - regions.put(cacheName, this); + regions.put(toName, this); + // add storage modification event fireDataChanged(new StorageChangeEvent(this)); @@ -222,8 +220,7 @@ * est retourné */ static public RegionStorage getRegion(String name) { - String cacheName = getContextDatabaseCacheKey(name); - RegionStorage result = regions.get(cacheName); + RegionStorage result = regions.get(name); if (result == null) { // recherche du repertoire de la region en fonction de la config File directory = null; @@ -243,7 +240,7 @@ if (directory.exists()) { result = new RegionStorage(directory, name); - regions.put(cacheName, result); + regions.put(name, result); } } return result; @@ -291,8 +288,7 @@ throw new StorageException("Can't create new Region", eee); } - String cacheName = getContextDatabaseCacheKey(name); - regions.put(cacheName, result); + regions.put(name, result); // add storage modification event fireDataChanged(new StorageChangeEvent(result)); @@ -310,8 +306,7 @@ // add storage modification event fireDataChanged(new StorageChangeEvent(this)); - String cacheName = getContextDatabaseCacheKey(getName()); - regions.remove(cacheName); + regions.remove(getName()); } /** Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -37,6 +37,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.rule.Rule; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.util.Docable; @@ -121,34 +122,38 @@ * Retourne le storage pour la regle demandée * * @param name le nom de la regle souhaitée + * @param location location to open storage file * @return Le storage pour la regle */ - static public RuleStorage getRule(String name) { - String cacheName = getContextDatabaseCacheKey(name); - RuleStorage result = rulesCache.get(cacheName); + static public RuleStorage getRule(String name, Location... location) { + RuleStorage result = rulesCache.get(name); if (result == null) { - result = new RuleStorage(getContextDatabaseDirectory(), - getRuleDirectory(), name); - rulesCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + RuleStorage storage = new RuleStorage(dir, new File(dir, RULE_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + rulesCache.put(name, result); + } + } + } } return result; } /** - * Retourne le storage pour la regle demandée - * - * @param name le nom de la regle souhaitée - * @return Le storage pour la regle + * Create new rule. + * + * @param name new rule to create + * @param location location to rule storage file + * @return new rule storage */ - static public RuleStorage getCommunityRule(String name) { - String cacheName = getCommunityDatabaseCacheKey(name); - RuleStorage result = rulesCache.get(cacheName); - if (result == null) { - result = new RuleStorage(getCommunityDatabaseDirectory(), - getCommunityRuleDirectory(), name); - rulesCache.put(cacheName, result); - } - return result; + public static RuleStorage createRule(String name, Location location) { + File dir = location.getDirectories()[0]; + RuleStorage storage = new RuleStorage(dir, new File(dir, RULE_PATH), name); + return storage; } /** Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -33,6 +33,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.vcs.VCSException; /** @@ -105,34 +106,38 @@ * Retourne le storage pour la regle demandée * * @param name le nom de la regle souhaitée + * @param location location to open storage file * @return Le storage pour la regle */ - static public ScriptStorage getScript(String name) { - String cacheName = getContextDatabaseCacheKey(name); - ScriptStorage result = scriptsCache.get(cacheName); + static public ScriptStorage getScript(String name, Location... location) { + ScriptStorage result = scriptsCache.get(name); if (result == null) { - result = new ScriptStorage(getContextDatabaseDirectory(), - getScriptDirectory(), name); - scriptsCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + ScriptStorage storage = new ScriptStorage(dir, new File(dir, SCRIPT_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + scriptsCache.put(name, result); + } + } + } } return result; } - + /** - * Retourne le storage pour la regle demandée + * Create new script. * - * @param name le nom de la regle souhaitée - * @return Le storage pour la regle + * @param name new script to create + * @param location location to script storage file + * @return new rule script */ - static public ScriptStorage getCommunityScript(String name) { - String cacheName = getCommunityDatabaseCacheKey(name); - ScriptStorage result = scriptsCache.get(cacheName); - if (result == null) { - result = new ScriptStorage(getCommunityDatabaseDirectory(), - getCommunityScriptDirectory(), name); - scriptsCache.put(cacheName, result); - } - return result; + public static ScriptStorage createScript(String name, Location location) { + File dir = location.getDirectories()[0]; + ScriptStorage storage = new ScriptStorage(dir, new File(dir, SCRIPT_PATH), name); + return storage; } static public void checkout() throws VCSException { Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityAnalysisStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityAnalysisStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityAnalysisStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric + * Copyright (C) 2009 - 2012 Ifremer, CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -37,6 +37,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.simulator.sensitivity.SensitivityAnalysis; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.util.Docable; @@ -117,32 +118,38 @@ * Retourne le storage pour le calculateur demandé. * * @param name le nom du calculateur souhaité + * @param location location to open storage file * @return Le {@link SensitivityAnalysisStorage} pour le calculateur */ - public static SensitivityAnalysisStorage getSensitivityAnalysis(String name) { - String cacheName = getContextDatabaseCacheKey(name); - SensitivityAnalysisStorage result = sensitivityCache.get(cacheName); + static public SensitivityAnalysisStorage getSensitivityAnalysis(String name, Location... location) { + SensitivityAnalysisStorage result = sensitivityCache.get(name); if (result == null) { - result = new SensitivityAnalysisStorage(getContextDatabaseDirectory(), getSensitivityAnalysisDirectory(), name); - sensitivityCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + SensitivityAnalysisStorage storage = new SensitivityAnalysisStorage(dir, new File(dir, SENSITIVITY_ANALYSIS_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + sensitivityCache.put(name, result); + } + } + } } return result; } - + /** - * Retourne le storage pour le calculateur demandé. - * - * @param name le nom du calculateur souhaité - * @return Le {@link SensitivityAnalysisStorage} pour le calculateur + * Create new sensitivity analysis. + * + * @param name new sensitivity analysis to create + * @param location location to sensitivity analysis storage file + * @return new sensitivity analysis storage */ - public static SensitivityAnalysisStorage getCommunitySensitivityAnalysis(String name) { - String cacheName = getCommunityDatabaseCacheKey(name); - SensitivityAnalysisStorage result = sensitivityCache.get(cacheName); - if (result == null) { - result = new SensitivityAnalysisStorage(getCommunityDatabaseDirectory(), getCommunitySensitivityAnalysisDirectory(), name); - sensitivityCache.put(cacheName, result); - } - return result; + public static SensitivityAnalysisStorage createSensitivityAnalysis(String name, Location location) { + File dir = location.getDirectories()[0]; + SensitivityAnalysisStorage storage = new SensitivityAnalysisStorage(dir, new File(dir, SENSITIVITY_ANALYSIS_PATH), name); + return storage; } /** Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityExportStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -33,6 +33,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.export.SensitivityExport; import fr.ifremer.isisfish.util.Docable; import fr.ifremer.isisfish.vcs.VCSException; @@ -107,34 +108,38 @@ * Retourne le storage pour l'export demandé. * * @param name le nom de la export souhaitée + * @param location location to open storage file * @return Le storage pour l'export */ - public static SensitivityExportStorage getSensitivityExport(String name) { - String cacheName = getContextDatabaseCacheKey(name); - SensitivityExportStorage result = sensitivityExportsCache.get(cacheName); + public static SensitivityExportStorage getSensitivityExport(String name, Location... location) { + SensitivityExportStorage result = sensitivityExportsCache.get(name); if (result == null) { - result = new SensitivityExportStorage(getContextDatabaseDirectory(), - getSensitivityExportDirectory(), name); - sensitivityExportsCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + SensitivityExportStorage storage = new SensitivityExportStorage(dir, new File(dir, SENSITIVITY_EXPORT_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + sensitivityExportsCache.put(name, result); + } + } + } } return result; } /** - * Retourne le storage pour l'export demandé. - * - * @param name le nom de l'export souhaitée - * @return Le storage pour l'export + * Create new sensitivity export. + * + * @param name new sensitivity export to create + * @param location location to sensitivity export storage file + * @return new sensitivity export storage */ - public static SensitivityExportStorage getCommunitySensitivityExport(String name) { - String cacheName = getCommunityDatabaseCacheKey(name); - SensitivityExportStorage result = sensitivityExportsCache.get(cacheName); - if (result == null) { - result = new SensitivityExportStorage(getCommunityDatabaseDirectory(), - getCommunitySensitivityExportDirectory(), name); - sensitivityExportsCache.put(cacheName, result); - } - return result; + public static SensitivityExportStorage createSensitivityExport(String name, Location location) { + File dir = location.getDirectories()[0]; + SensitivityExportStorage storage = new SensitivityExportStorage(dir, new File(dir, SENSITIVITY_EXPORT_PATH), name); + return storage; } /** Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationPlanStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationPlanStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationPlanStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -37,6 +37,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.simulator.SimulationPlan; import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.util.Docable; @@ -118,34 +119,38 @@ * Retourne le storage pour le plan demandé. * * @param name le nom du plan souhaité + * @param location location to open storage file * @return Le storage pour le plan */ - static public SimulationPlanStorage getSimulationPlan(String name) { - String cacheName = getContextDatabaseCacheKey(name); - SimulationPlanStorage result = plansCache.get(cacheName); + static public SimulationPlanStorage getSimulationPlan(String name, Location... location) { + SimulationPlanStorage result = plansCache.get(name); if (result == null) { - result = new SimulationPlanStorage(getContextDatabaseDirectory(), - getSimulationPlanDirectory(), name); - plansCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + SimulationPlanStorage storage = new SimulationPlanStorage(dir, new File(dir, SIMULATION_PLAN_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + plansCache.put(name, result); + } + } + } } return result; } - + /** - * Retourne le storage pour le plan demandé. - * - * @param name le nom du plan souhaité - * @return Le storage pour le plan + * Create new simulation plan. + * + * @param name new simulation plan to create + * @param location location to simulation plan storage file + * @return new simulation plan storage */ - static public SimulationPlanStorage getCommunitySimulationPlan(String name) { - String cacheName = getCommunityDatabaseCacheKey(name); - SimulationPlanStorage result = plansCache.get(cacheName); - if (result == null) { - result = new SimulationPlanStorage(getCommunityDatabaseDirectory(), - getCommunitySimulationPlanDirectory(), name); - plansCache.put(cacheName, result); - } - return result; + public static SimulationPlanStorage createSimulationPlan(String name, Location location) { + File dir = location.getDirectories()[0]; + SimulationPlanStorage storage = new SimulationPlanStorage(dir, new File(dir, SIMULATION_PLAN_PATH), name); + return storage; } /** Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulatorStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2005 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -33,6 +33,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.simulator.Simulator; import fr.ifremer.isisfish.vcs.VCSException; @@ -105,36 +106,38 @@ * {@link SimulatorStorage} is cached by name. * * @param name le nom de la regle souhaitée + * @param location location to open storage file * @return Le storage pour la regle */ - static public SimulatorStorage getSimulator(String name) { - String cacheName = getContextDatabaseCacheKey(name); - SimulatorStorage result = simulatorsCache.get(cacheName); + static public SimulatorStorage getSimulator(String name, Location... location) { + SimulatorStorage result = simulatorsCache.get(name); if (result == null) { - result = new SimulatorStorage(getContextDatabaseDirectory(), - getSimulatorDirectory(), name); - simulatorsCache.put(cacheName, result); + Location[] locs = nonEmptyLocation(location); + for (int i = 0; i < locs.length && result == null; i++) { + Location loc = locs[i]; + for (File dir : loc.getDirectories()) { + SimulatorStorage storage = new SimulatorStorage(dir, new File(dir, SIMULATOR_PATH), name); + if (storage.getFile().isFile()) { + result = storage; + simulatorsCache.put(name, result); + } + } + } } return result; } - + /** - * Retourne le storage pour le simulateur demandée. + * Create new simulation plan. * - * {@link SimulatorStorage} is cached by name. - * - * @param name le nom de la regle souhaitée - * @return Le storage pour la regle + * @param name new simulation plan to create + * @param location location to simulation plan storage file + * @return new simulation plan storage */ - static public SimulatorStorage getCommunitySimulator(String name) { - String cacheName = getContextDatabaseCacheKey(name); - SimulatorStorage result = simulatorsCache.get(cacheName); - if (result == null) { - result = new SimulatorStorage(getCommunityDatabaseDirectory(), - getCommunitySimulatorDirectory(), name); - simulatorsCache.put(cacheName, result); - } - return result; + public static SimulatorStorage createSimulator(String name, Location location) { + File dir = location.getDirectories()[0]; + SimulatorStorage storage = new SimulatorStorage(dir, new File(dir, SIMULATOR_PATH), name); + return storage; } static public void checkout() throws VCSException { Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -106,30 +106,6 @@ } /** - * Get cache storage key to use depending on context storage used. - * - * Two simulation must have their own cache. - * - * @return context cache key - */ - protected static String getContextDatabaseCacheKey(String key) { - String result = getContextDatabaseDirectory().getAbsolutePath() + key; - return result; - } - - /** - * Get cache storage key to use depending on context storage used. - * - * Two simulation must have their own cache and community scripts too. - * - * @return context cache key - */ - protected static String getCommunityDatabaseCacheKey(String key) { - String result = getCommunityDatabaseDirectory().getAbsolutePath() + key; - return result; - } - - /** * Get VCS instance for storage file. * * @return vcs instance Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -66,6 +66,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.CodeSourceStorage; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.datastore.ExportStorage; import fr.ifremer.isisfish.datastore.FormuleStorage; import fr.ifremer.isisfish.datastore.JavaSourceStorage; @@ -291,26 +292,26 @@ Language.JAVA); break; case CommunitySimulationPlan: - script = SimulationPlanStorage.getCommunitySimulationPlan(fileName); + script = SimulationPlanStorage.getSimulationPlan(fileName, Location.COMMUNITY); break; case CommunityExport: - script = ExportStorage.getCommunityExport(fileName); + script = ExportStorage.createExport(fileName, Location.COMMUNITY); break; case CommunityRule: - script = RuleStorage.getCommunityRule(fileName); + script = RuleStorage.createRule(fileName, Location.COMMUNITY); break; case CommunityScript: - script = ScriptStorage.getCommunityScript(fileName); + script = ScriptStorage.createScript(fileName, Location.COMMUNITY); break; case CommunitySimulator: - script = SimulatorStorage.getCommunitySimulator(fileName); + script = SimulatorStorage.createSimulator(fileName, Location.COMMUNITY); break; case CommunitySensitivity: - script = SensitivityAnalysisStorage.getCommunitySensitivityAnalysis(fileName); + script = SensitivityAnalysisStorage.createSensitivityAnalysis(fileName, Location.COMMUNITY); break; case CommunitySensitivityExport: script = SensitivityExportStorage - .getCommunitySensitivityExport(fileName); + .createSensitivityExport(fileName, Location.COMMUNITY); break; default: if (log.isErrorEnabled()) { @@ -435,46 +436,46 @@ } break; case Rule: - script = RuleStorage.getRule(file.getName()); + script = RuleStorage.getRule(file.getName(), Location.OFFICIAL); break; case SimulationPlan: - script = SimulationPlanStorage.getSimulationPlan(file.getName()); + script = SimulationPlanStorage.getSimulationPlan(file.getName(), Location.OFFICIAL); break; case Export: - script = ExportStorage.getExport(file.getName()); + script = ExportStorage.getExport(file.getName(), Location.OFFICIAL); break; case Script: - script = ScriptStorage.getScript(file.getName()); + script = ScriptStorage.getScript(file.getName(), Location.OFFICIAL); break; case Simulator: - script = SimulatorStorage.getSimulator(file.getName()); + script = SimulatorStorage.getSimulator(file.getName(), Location.OFFICIAL); break; case Sensitivity: - script = SensitivityAnalysisStorage.getSensitivityAnalysis(file.getName()); + script = SensitivityAnalysisStorage.getSensitivityAnalysis(file.getName(), Location.OFFICIAL); break; case SensitivityExport: - script = SensitivityExportStorage.getSensitivityExport(file.getName()); + script = SensitivityExportStorage.getSensitivityExport(file.getName(), Location.OFFICIAL); break; case CommunityRule: - script = RuleStorage.getCommunityRule(file.getName()); + script = RuleStorage.getRule(file.getName(), Location.COMMUNITY); break; case CommunitySimulationPlan: - script = SimulationPlanStorage.getCommunitySimulationPlan(file.getName()); + script = SimulationPlanStorage.getSimulationPlan(file.getName(), Location.COMMUNITY); break; case CommunityExport: - script = ExportStorage.getCommunityExport(file.getName()); + script = ExportStorage.getExport(file.getName(), Location.COMMUNITY); break; case CommunityScript: - script = ScriptStorage.getCommunityScript(file.getName()); + script = ScriptStorage.getScript(file.getName(), Location.COMMUNITY); break; case CommunitySimulator: - script = SimulatorStorage.getCommunitySimulator(file.getName()); + script = SimulatorStorage.getSimulator(file.getName(), Location.COMMUNITY); break; case CommunitySensitivity: - script = SensitivityAnalysisStorage.getCommunitySensitivityAnalysis(file.getName()); + script = SensitivityAnalysisStorage.getSensitivityAnalysis(file.getName(), Location.COMMUNITY); break; case CommunitySensitivityExport: - script = SensitivityExportStorage.getCommunitySensitivityExport(file.getName()); + script = SensitivityExportStorage.getSensitivityExport(file.getName(), Location.COMMUNITY); break; default: log.fatal("ScriptType unknown: " + file.getName()); Modified: trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2012-02-20 12:12:45 UTC (rev 3614) +++ trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2012-02-24 16:46:43 UTC (rev 3615) @@ -40,6 +40,7 @@ import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; import javax.tools.ToolProvider; import org.apache.commons.lang3.StringUtils; @@ -50,6 +51,7 @@ import com.sun.tools.javac.api.JavacTool; import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location; import fr.ifremer.isisfish.datastore.JavaSourceStorage; /** @@ -188,12 +190,6 @@ List<File> classpath = new ArrayList<File>(); classpath.add(rootSrc.getAbsoluteFile()); - // FIXME echatellier 20110617 : hack depuis qu'il y a un - // nouveau dossier de sources de script "communauté", mais - // qui peu dépendre de sources du dossier "officiel" - if (rootSrc.equals(IsisFish.config.getCommunityDatabaseDirectory())) { - classpath.add(IsisFish.config.getDatabaseDirectory()); - } result = compile(classpath, src, dest, out); } catch (Exception eee) { @@ -227,6 +223,7 @@ // JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = compiler .getStandardFileManager(null, null, null); + fileManager.setLocation(StandardLocation.SOURCE_PATH, Location.ALL); Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromFiles(src);
participants (1)
-
echatellier@users.forge.codelutin.com