Author: bpoussin Date: 2008-08-14 14:55:00 +0000 (Thu, 14 Aug 2008) New Revision: 1298 Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ExportAction.java trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ImportAction.java trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/OtherAction.java trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/SimulationAction.java trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/VCSAction.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/AbstractVCS.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSNone.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/Welcome.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/package.html Log: refactoring du vcs en cours Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-13 18:24:19 UTC (rev 1297) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -27,7 +27,7 @@ import fr.ifremer.isisfish.actions.SimulationAction; import fr.ifremer.isisfish.actions.VCSAction; import fr.ifremer.isisfish.simulator.SimulationContext; -import fr.ifremer.isisfish.vcs.VCS; +import fr.ifremer.isisfish.vcs.VCSNone; import java.io.File; import java.net.MalformedURLException; import java.net.URL; @@ -186,7 +186,7 @@ // public boolean isUseVCS() { // String value = getOption(Option.VCS_TYPE.key); -// boolean result = !VCS.TYPE_NONE.equals(value); +// boolean result = !VCSNone.TYPE_NONE.equals(value); // return result; // } @@ -439,14 +439,14 @@ SSH_PASSPHRASE("ssh.passphrase", _("isisfish.config.vcs.passphrase.description"), ""), // can be None, CVS or SVN. only None or SVN work - VCS_TYPE(VCS.VCS_TYPE, _("isisfish.config.vcs.type.description"), VCS.TYPE_SVN), + VCS_TYPE(VCSNone.VCS_TYPE, _("isisfish.config.vcs.type.description"), VCSNone.TYPE_SVN), // depend of VCS_TYPE, for SVN can be http or ssh - VCS_CONNECTION(VCS.VCS_CONNECTION, _("isisfish.config.vcs.useSshConnexion.description"), "http"), + VCS_CONNECTION(VCSNone.VCS_CONNECTION, _("isisfish.config.vcs.useSshConnexion.description"), "http"), // user login to access vcs - VCS_USER_NAME(VCS.VCS_USER_NAME, _("isisfish.config.vcs.userName.description"), "anonymous"), - VCS_HOST_NAME(VCS.VCS_HOST_NAME, _("isisfish.config.vcs.hostName.description"), "labs.libre-entreprise.org"), - VCS_PATH(VCS.VCS_PATH, _("isisfish.config.vcs.remotePath.description"), "svnroot/isis-fish-data"), - VCS_TAG(VCS.VCS_TAG, _("isisfish.config.vcs.remoteDatabase.description"), "tag/" + VERSION_DATABASE), + VCS_USER_NAME(VCSNone.VCS_USER_NAME, _("isisfish.config.vcs.userName.description"), "anonymous"), + VCS_HOST_NAME(VCSNone.VCS_HOST_NAME, _("isisfish.config.vcs.hostName.description"), "labs.libre-entreprise.org"), + VCS_PATH(VCSNone.VCS_PATH, _("isisfish.config.vcs.remotePath.description"), "svnroot/isis-fish-data"), + VCS_TAG(VCSNone.VCS_TAG, _("isisfish.config.vcs.remoteDatabase.description"), "tag/" + VERSION_DATABASE), // TYPE_REPO_PROPERTY_KEY = newConfigPropertyKey("typeRepo", VCSTypeRepo.class, 9, n_("isisfish.config.vcs.typeRepo.description"), "TAG"), // PROJECT_NAME_PROPERTY_KEY = newConfigPropertyKey("projectName", String.class, 11, n_("isisfish.config.main.projectName.description"), "Isis-Fish"), Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java 2008-08-13 18:24:19 UTC (rev 1297) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -49,7 +49,7 @@ import fr.ifremer.isisfish.util.RangeOfValuesConverter; import fr.ifremer.isisfish.util.StringConverter; import fr.ifremer.isisfish.util.TimeUnitConverter; -import fr.ifremer.isisfish.vcs.VCS; +import fr.ifremer.isisfish.vcs.VCSNone; import java.io.File; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.logging.LogFactory; @@ -92,7 +92,7 @@ static public IsisConfig config = null; static public int step = 0; // action step - static public VCS vcs = null; + static public VCSNone vcs = null; static public Context uiContext = null; static protected boolean quit = false; @@ -250,12 +250,12 @@ } /** - * Initialise le VCS et check s'il y a des mises a jour pour prevenir + * Initialise le VCSNone et check s'il y a des mises a jour pour prevenir * l'utilisateur */ static public void initVCS() { // init vcs - vcs = VCS.createVCS(config); + vcs = VCSNone.createVCS(config); // check connection status vcs.checkConnection(); Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ExportAction.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ExportAction.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ExportAction.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,248 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.actions; + +import fr.ifremer.isisfish.IsisConfig; +import fr.ifremer.isisfish.datastore.AnalysePlanStorage; +import fr.ifremer.isisfish.datastore.DataStorage; +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.SimulationStorage; +import fr.ifremer.isisfish.datastore.SimulatorStorage; +import fr.ifremer.isisfish.ui.ScriptActionHelper; +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Pattern; +import static org.codelutin.i18n.I18nf._; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.FileUtil; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ExportAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ExportAction.class); + + protected IsisConfig config = null; + + public ExportAction(IsisConfig config) { + this.config = config; + } + + public void applyFilter(String filter, List<String> names) { + if (filter != null && !"*".equals(filter)) { + Pattern p = Pattern.compile(filter); + // apply filter on names found + for (Iterator<String> i=names.iterator(); i.hasNext();) { + String name = i.next(); + if (!p.matcher(name).matches()) { + i.remove(); + } + } + } + } + + public void display(String filter, List<String> names) { + StringBuilder sb = new StringBuilder(); + sb.append(" found ").append(names.size()); + sb.append(" with filter ").append(filter); + sb.append(" in IsisFish"); + for (String name : names) { + sb.append("\n").append(name); + } + System.out.println(sb.toString()); + } + + public void listAnalysePlan(String filter) throws Exception { + List<String> names = AnalysePlanStorage.getAnalysePlanNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listExport(String filter) throws Exception { + List<String> names = ExportStorage.getExportNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listRule(String filter) throws Exception { + List<String> names = RuleStorage.getRuleNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listScript(String filter) throws Exception { + List<String> names = ScriptStorage.getScriptNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listRegion(String filter) throws Exception { + List<String> names = RegionStorage.getRegionNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listSimulation(String filter) throws Exception { + List<String> names = SimulationStorage.getSimulationNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listSimulator(String filter) throws Exception { + List<String> names = SimulatorStorage.getSimulatorNames(); + applyFilter(filter, names); + display(filter, names); + } + + public void listFormula(String filter) throws Exception { + List<String> names = new ArrayList<String>(); + for (String name : FormuleStorage.getCategories()) { + names.addAll(FormuleStorage.getFormuleNames(name)); + } + applyFilter(filter, names); + display(filter, names); + } + + ////////////////////////////////////////////////////////////////////////// + // + // E X P O R T + // + ////////////////////////////////////////////////////////////////////////// + + public void exportRegion(File file, String name, boolean force) throws Exception { + log.info("file:" + file + ", name:" + name); + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + + if (!RegionStorage.exists(name)) { + // fatal error + throw new IllegalArgumentException(_("could not found region %s", name)); + } + DataStorage data = RegionStorage.getRegion(name); + if (data != null) { + data.createZip(file); + } + } + + public void exportSimulation(File file, String name, boolean force) throws Exception { + log.info("file:" + file + ", name:" + name); + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + + if (!SimulationStorage.exists(name)) { + // fatal error + throw new IllegalArgumentException(_("could not found simulation %s", name)); + } + DataStorage data = SimulationStorage.getSimulation(name); + if (data != null) { + data.createZip(file); + } + } + + public void exportAnalysePlan(File file, String name, boolean force) throws Exception { + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + AnalysePlanStorage storage = AnalysePlanStorage.getAnalysePlan(name); + if (!storage.exists()) { + throw new IllegalArgumentException(_("could not found %s", name)); + } + String content = storage.getContent(); + FileUtil.writeString(file, content); + } + + public void exportRule(File file, String name, boolean force) throws Exception { + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + RuleStorage storage = RuleStorage.getRule(name); + if (!storage.exists()) { + throw new IllegalArgumentException(_("could not found %s", name)); + } + String content = storage.getContent(); + FileUtil.writeString(file, content); + } + + public void exportScript(File file, String name, boolean force) throws Exception { + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + ScriptStorage storage = ScriptStorage.getScript(name); + if (!storage.exists()) { + throw new IllegalArgumentException(_("could not found %s", name)); + } + String content = storage.getContent(); + FileUtil.writeString(file, content); + } + + public void exportExport(File file, String name, boolean force) throws Exception { + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + ExportStorage storage = ExportStorage.getExport(name); + if (!storage.exists()) { + throw new IllegalArgumentException(_("could not found %s", name)); + } + String content = storage.getContent(); + FileUtil.writeString(file, content); + } + + public void exportSimulator(File file, String name, boolean force) throws Exception { + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + SimulatorStorage storage = SimulatorStorage.getSimulator(name); + if (!storage.exists()) { + throw new IllegalArgumentException(_("could not found %s", name)); + } + String content = storage.getContent(); + FileUtil.writeString(file, content); + } + + public void exportFormula(File file, String category, String name, boolean force) throws Exception { + if (!force && file.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use 'force' argument to force overwrite", file)); + } + FormuleStorage storage = FormuleStorage.getFormule(category, name); + if (!storage.exists()) { + throw new IllegalArgumentException(_("could not found %s", name)); + } + String content = storage.getContent(); + FileUtil.writeString(file, content); + } + +} Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ImportAction.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ImportAction.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/ImportAction.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,169 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.actions; + +import static org.codelutin.i18n.I18nf._; + +import fr.ifremer.isisfish.IsisConfig; +import fr.ifremer.isisfish.datastore.AnalysePlanStorage; +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.SimulationStorage; +import fr.ifremer.isisfish.datastore.SimulatorStorage; +import fr.ifremer.isisfish.ui.ScriptActionHelper; +import java.io.File; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.FileUtil; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class ImportAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(ImportAction.class); + + protected IsisConfig config = null; + + public ImportAction(IsisConfig config) { + this.config = config; + } + + public void importAnalysePlan(boolean force, File file) throws Exception { + String name = file.getName(); + AnalysePlanStorage storage = AnalysePlanStorage.getAnalysePlan(name); + if(!force && storage.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use \'force\' argument to force overwrite", storage.getFile())); + } + String content = FileUtil.readAsString(file); + storage.setContent(content); + } + + public void importExport(boolean force, File file) throws Exception { + String name = file.getName(); + ExportStorage storage = ExportStorage.getExport(name); + if(!force && storage.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use \'force\' argument to force overwrite", storage.getFile())); + } + String content = FileUtil.readAsString(file); + storage.setContent(content); + } + + public void importRule(boolean force, File file) throws Exception { + String name = file.getName(); + RuleStorage storage = RuleStorage.getRule(name); + if(!force && storage.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use \'force\' argument to force overwrite", storage.getFile())); + } + String content = FileUtil.readAsString(file); + storage.setContent(content); + } + + public void importScript(boolean force, File file) throws Exception { + String name = file.getName(); + ScriptStorage storage = ScriptStorage.getScript(name); + if(!force && storage.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use \'force\' argument to force overwrite", storage.getFile())); + } + String content = FileUtil.readAsString(file); + storage.setContent(content); + } + + public void importSimulator(boolean force, File file) throws Exception { + String name = file.getName(); + SimulatorStorage storage = SimulatorStorage.getSimulator(name); + if(!force && storage.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use \'force\' argument to force overwrite", storage.getFile())); + } + String content = FileUtil.readAsString(file); + storage.setContent(content); + } + + public void importFormula(boolean force, String formulaType, File file) throws Exception { + if (!FormuleStorage.getCategories().contains(formulaType)) { + throw new IllegalArgumentException(_("Could not found formule type %s autorised type are %s", formulaType, FormuleStorage.getCategories())); + } + String name = file.getName(); + FormuleStorage storage = FormuleStorage.getFormule(formulaType, name); + if(!force && storage.exists()) { + throw new IllegalArgumentException(_("destination already exists %s use \'force\' argument to force overwrite", storage.getFile())); + } + String content = FileUtil.readAsString(file); + storage.setContent(content); + } + + /** + * + * @param file zip file containing data + * @param force + * @throws java.lang.Exception + */ + public void importRegion(boolean force, File file) throws Exception { + //TODO test if region exists + RegionStorage.importZip(file); + } + + /** + * + * @param file zip file containing data + * @param name new region name + * @param force + * @throws java.lang.Exception + */ + public void importRegionAndRename(boolean force, File file, String name) throws Exception { + if (RegionStorage.exists(name) && !force) { + // fatal error + throw new IllegalArgumentException(_("region already exists %s use 'force' argument to force overwrite", name)); + } + RegionStorage.importAndRenameZip(file, name); + } + + /** + * + * @param file zip file containing data + * @param force + * @throws java.lang.Exception + */ + public void importSimulation(boolean force, File file) throws Exception { + //TODO test if simulation exists + SimulationStorage.importZip(file); + } + + /** + * Import zipped file containing all directory structure + * + * @param file zip file containing data + * @param force + * @throws java.lang.Exception + */ + public void importScriptModule(boolean force, File file) throws Exception { + ScriptActionHelper.importScript(file, force, false, null); + } + +} Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/OtherAction.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/OtherAction.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/OtherAction.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,62 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.actions; + +import static org.codelutin.i18n.I18nf._; + +import fr.ifremer.isisfish.IsisConfig; +import fr.ifremer.isisfish.vcs.VCSNone; +import java.io.File; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class OtherAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(OtherAction.class); + + protected IsisConfig config = null; + + public OtherAction(IsisConfig config) { + this.config = config; + } + + static public void help() { + System.out.println("Usage: isis-fish [-h]"); + } + + public void chekoutMavenFile() throws Exception { + VCSNone vcs = config.getVCS(); + File dest = config.getDatabaseDirectory(); + File file = new File(dest, "pom.xml"); + log.info(_("Checkout pom.xml to %s", file)); + vcs.update(file); + } + + +} Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/SimulationAction.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/SimulationAction.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/SimulationAction.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,112 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.actions; + +import static org.codelutin.i18n.I18nf._; + +import fr.ifremer.isisfish.IsisConfig; +import fr.ifremer.isisfish.datastore.RegionStorage; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.SimulationHelper; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import java.io.File; +import java.io.FileInputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class SimulationAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(SimulationAction.class); + + protected IsisConfig config = null; + + public SimulationAction(IsisConfig config) { + this.config = config; + } + + public static void simulateWithRegion(String simulId, File parameterFile, File region) throws Exception { + Properties props = new Properties(); + FileInputStream inStream = new FileInputStream(parameterFile); + props.load(inStream); + inStream.close(); + + SimulationParameter params = new SimulationParameter(); + params.fromProperties(props); + + // try to import region if needed + String regionName = params.getRegionName(); + if (region != null) { + if (!RegionStorage.exists(regionName)) { + RegionStorage.importAndRenameZip(region, regionName); + } else { + log.warn(_("Region %s allready exist in repository. Cant import", regionName)); + } + } + + SimulationHelper.simulate(simulId, params, false); + } + + /** + * + * @param simulId id de simulation + * @param zip Zip de la simulation + * @param parameterFile parametre optionnel pour la simulation + */ + public static void simulateWithSimulation(String simulId, File parameterFile, File simulationZip) throws Exception { + SimulationParameter params = null; + if (parameterFile != null && parameterFile.exists()) { + Properties props = new Properties(); + FileInputStream inStream = new FileInputStream(parameterFile); + props.load(inStream); + inStream.close(); + + params = new SimulationParameter(); + params.fromProperties(props); + } + log.info("id:" + simulId + ", zip:" + simulationZip + (params!=null?" with parameters":"")); + + // import de cette simulation + String name = simulId + " " + new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date()); + + // import de la simulation avec un autre nom + SimulationStorage sim = SimulationStorage.importAndRenameZip(simulationZip, name); + if (params != null) { + sim.setParameter(params); + } + // lancement de la simulation + SimulationHelper.simulate(null, sim); + + sim.getStorage().closeContext(); + + } + +} Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/VCSAction.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/VCSAction.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/actions/VCSAction.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,97 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.actions; + + +import com.sshtools.j2ssh.transport.publickey.OpenSSHPublicKeyFormat; +import com.sshtools.j2ssh.transport.publickey.SshKeyGenerator; +import fr.ifremer.isisfish.IsisConfig; +import fr.ifremer.isisfish.ui.Welcome; +import java.io.File; +import java.util.Arrays; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.FileUtil; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class VCSAction { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(VCSAction.class); + + protected IsisConfig config = null; + + public VCSAction(IsisConfig config) { + this.config = config; + } + + public void sshCreateKey(boolean force) throws Exception { + File f = config.getOptionAsFile(IsisConfig.Option.SSH_KEY_FILE.key); + + if (f.exists() && !force) { + log.error("the private key already exist " + f + ", use option [force] to overwrite"); + return; + } + File publicKeyFile = new File(f.getAbsolutePath() + ".pub"); + + log.info("Generate ssh key to " + f); + SshKeyGenerator.main(new String[]{"-b", "1024", "-t", "rsa", f.getAbsolutePath()}); + + log.info("public key before OpenSsh : " + FileUtil.readAsString(publicKeyFile)); + String openSshPublicKey = + SshKeyGenerator.convertPublicKeyFile(publicKeyFile, + new OpenSSHPublicKeyFormat( + config.getOption(IsisConfig.Option.USER_NAME.key) + + "@forIsisFish 1024-bit rsa")); + + log.info("public key OpenSsh : " + openSshPublicKey); + FileUtil.writeString(new File(publicKeyFile.getAbsolutePath()), openSshPublicKey); + } + + public void vcsUpdate() throws Exception { + // ATTENTION: il est inutil de d'accepter cette option au premier + // lancement! car on a effectue soit un checkout, soit + // une migration // !IsisContext.get().isFirstLaunch() + Welcome.updateVCS(null); + } + + public void vcsAdd(File ... file) throws Exception { + log.info("file*:" + Arrays.toString(file)); + throw new UnsupportedOperationException("to be done..."); + } + + public void vcsRemove(File ... file) throws Exception { + log.info("file*:" + Arrays.toString(file)); + throw new UnsupportedOperationException("to be done..."); + } + + public void vcsCommit(File ... file) throws Exception { + log.info("file*:" + Arrays.toString(file)); + throw new UnsupportedOperationException("to be done..."); + } + +} Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2008-08-13 18:24:19 UTC (rev 1297) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/VersionStorage.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -33,7 +33,7 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.vcs.VCSException; -import fr.ifremer.isisfish.vcs.VCS; +import fr.ifremer.isisfish.vcs.VCSNone; import static org.codelutin.i18n.I18n._; import org.codelutin.util.FileUtil; @@ -56,7 +56,7 @@ /** Logger for this class */ private static final Log log = LogFactory.getLog(VersionStorage.class); - static protected VCS getVCS() { + static protected VCSNone getVCS() { return IsisFish.vcs; } @@ -68,7 +68,7 @@ * Par exemple si on a /home/poussin/isis-database comme root * il faut que file soit un fichier ou un sous fichiers dans root * - * @param root le repertoire racine de mise en VCS (HOME VCS) + * @param root le repertoire racine de mise en VCSNone (HOME VCSNone) * @param file le fichier a gérer. */ protected VersionStorage(File root, File file) { @@ -78,7 +78,7 @@ /** * Permet de demander la preparation des fichiers pour etre envoyé - * vers le VCS + * vers le VCSNone * */ abstract protected void prepare(); @@ -100,9 +100,9 @@ /** * Indique s'il a deja ete ajouté au cvs. Si file est un repertoire * (ex pour Region) alors vrai meme si tous les fichiers du repertoire - * ne sont pas sur le VCS + * ne sont pas sur le VCSNone * - * @return vrai si deja dans le VCS + * @return vrai si deja dans le VCSNone */ public boolean isOnRemote() throws VCSException { return getVCS().isOnRemote(getFile()); @@ -110,7 +110,7 @@ /** * Permet de savoir si un fichier doit etre géré par le vcs ou non. - * L'implantation par defaut exclus les répertoires VCS, il faut + * L'implantation par defaut exclus les répertoires VCSNone, il faut * toujours appeler le super si on surcharge la methode. * * @param file le fichier a tester @@ -121,7 +121,7 @@ } /** - * Donne la liste de tous les fichiers que le VCS doit gérer. + * Donne la liste de tous les fichiers que le VCSNone doit gérer. * Par defaut parcours tous les repertoires et ajouter tous les fichiers * et repertoire trouvé. Il est possible d'exclure des fichiers et/ou * repertoire en surchargeant {@link #isVersionnableAbleFile(File)} @@ -144,9 +144,9 @@ } /** - * Donne la liste de tous les fichiers à gérer par le VCS. + * Donne la liste de tous les fichiers à gérer par le VCSNone. * Ceci inclu la liste des répertoires pour aller de ce storage - * jusqu'a la racine VCS si withParent est vrai + * jusqu'a la racine VCSNone si withParent est vrai * * @param withParent si vrai inclu les parents * @return la liste des fichiers trouvés @@ -167,7 +167,7 @@ } /** - * Permet d'ajouter ce storage dans le VCS. Cela prend effet immediatement + * Permet d'ajouter ce storage dans le VCSNone. Cela prend effet immediatement * (un commit est fait). * * @param msg le message indiquant le but du fichier @@ -209,7 +209,7 @@ } /** - * Permet d'envoyer des modifications faite en local sur le VCS + * Permet d'envoyer des modifications faite en local sur le VCSNone * * @param msg le message indiquant le type des modifications * @throws VCSException si pb pendant l'op @@ -217,13 +217,13 @@ */ public void commit(String msg) throws VCSException { // on appelle en fait add, car il y a peut-etre des nouveaux fichiers - // a ajouter au VCS et ca doit etre fait automatiquement + // a ajouter au VCSNone et ca doit etre fait automatiquement add(msg); } /** * Permet de mettre a jour le fichier local en fonction de ce qu'il y - * a sur le VCS + * a sur le VCSNone * * @throws VCSException si pb pendant l'op * @@ -239,7 +239,7 @@ } /** - * Permet de ramener tout un répertoire du VCS. Utile seulement pour le + * Permet de ramener tout un répertoire du VCSNone. Utile seulement pour le * premier lancement pour scipts et exports. * * @param destDir le repertoire parent @@ -275,12 +275,12 @@ /** * Retourne la liste des noms de tous les storages disponibles sur le - * serveur VCS + * serveur VCSNone * - * @param directory le répertoire sur le VCS ou doivent se trouver + * @param directory le répertoire sur le VCSNone ou doivent se trouver * les storages (regions, simulations) * @return la liste des noms de tous les storages disponibles sur le - * serveur VCS. Si le serveur n'est pas disponible la liste retournée + * serveur VCSNone. Si le serveur n'est pas disponible la liste retournée * est vide. */ static public List<String> getRemoteStorageNames(File directory) { Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/Welcome.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/Welcome.java 2008-08-13 18:24:19 UTC (rev 1297) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/Welcome.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -49,7 +49,7 @@ import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.datastore.ScriptStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; -import fr.ifremer.isisfish.vcs.VCS; +import fr.ifremer.isisfish.vcs.VCSNone; import org.swixat.framework.AbstractFrame; import org.swixat.framework.OutputView; import org.swixat.model.GenericContext; @@ -74,7 +74,7 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(Welcome.class); - static protected VCS getVCS() { + static protected VCSNone getVCS() { return IsisFish.config.getVCS(); } Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/AbstractVCS.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/AbstractVCS.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/AbstractVCS.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,56 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.vcs; + + +import java.io.File; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.ApplicationConfig; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public abstract class AbstractVCS implements VCS { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(AbstractVCS.class); + + protected ApplicationConfig config; + + public AbstractVCS(ApplicationConfig config) { + this.config = config; + } + + public boolean accept(File pathname) { + return isVersionnableAbleFile(pathname); + } + + public boolean isVersionnableAbleFile(File file) { + String filename = file.getName(); + return !".svn".equals(filename) && !"CVS".equals(filename) && !filename.endsWith("~"); + } + +} Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java 2008-08-13 18:24:19 UTC (rev 1297) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -1,4 +1,4 @@ -/* *##% +/* * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -15,149 +15,188 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. - *##%*/ + */ package fr.ifremer.isisfish.vcs; import java.io.File; import java.io.FileFilter; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import static org.codelutin.i18n.I18nf._; +import org.codelutin.util.VersionNumber; -import org.apache.commons.beanutils.ConstructorUtils; -import org.apache.commons.beanutils.ConvertUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.util.ApplicationConfig; - /** - * VCS (svn or vcs) must extends this class. This class can be used as dummy - * VCS if not valid VCS found. - * + * * @author poussin * @version $Revision$ * * Last update: $Date$ * by : $Author$ */ -public class VCS implements FileFilter { +public interface VCS extends FileFilter { + public static final String TYPE_CVS = "cvs"; + public static final String TYPE_NONE = "none"; + public static final String TYPE_SVN = "svn"; + /** + * can be http, ssh, pserver, ... + */ + public static final String VCS_PROTOCOLE = "vcs.protocole"; + /** + * remote server adresse (ip or serveur name) ex: labs.libre-entreprise.org + */ + public static final String VCS_HOST_NAME = "vcs.hostName"; + /** + * remote repository path ex: /svnroot/isis-fish-data + */ + public static final String VCS_PATH = "vcs.path"; + /** + * repository tag to used ex: "3.2" or "" for no tag + */ + public static final String VCS_TAG = "vcs.tag"; + /** + * can be None, CVS or SVN. only None or SVN work + */ + public static final String VCS_TYPE = "vcs.type"; + /** + * user login to access vcs ex: bpoussin + */ + public static final String VCS_USER_NAME = "vcs.username"; + /** + * user passwd or passphrase to access vcs ex: xxxxxxxx + */ + public static final String VCS_USER_PASSWORD = "vcs.password"; - static final public String TYPE_NONE = "none"; - static final public String TYPE_SVN = "svn"; - static final public String TYPE_CVS = "cvs"; - - // can be None, CVS or SVN. only None or SVN work - static final public String VCS_TYPE = "vcs.type"; - static final public String VCS_CONNECTION = "vcs.connection"; - // user login to access vcs - static final public String VCS_USER_NAME = "vcs.username"; - static final public String VCS_HOST_NAME = "vcs.hostName"; - static final public String VCS_PATH = "vcs.path"; - static final public String VCS_TAG = "vcs.tag"; - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(VCS.class); + /** + * Usefull to permit to use VCSNone as filter + * @param pathname + * @return + */ + public boolean accept(File pathname); - protected ApplicationConfig config; + /** + * Add and commit file in server repository + * @param files list of file to add + * @param msg message for commit + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void add(List<File> files, String msg) throws VCSException; + + /** + * get repository module on server and put it in destDir + * @param destDir destination directory + * @param module module name + * @param b // FIXME + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void checkout(File destDir, String module, boolean b) throws VCSException; + + /** + * Change repository tag, used when we use some tag and we want to go to + * trunk. + * @param version version to go, if null trunk is used, otherwize + * tags/version is used + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void switchTag(VersionNumber version) throws VCSException; /** - * VCS factory, looking for vcs.type key in config to find vcs class to used - * If no vcs.type found or is not valid class, use {@link VCS}. - * @param config - * @return usable VCS + * switch to new protocole, can be used to switch between anonymous and + * authenticate protocole + * @param protocoleType + * @throws fr.ifremer.isisfish.vcs.VCSException */ - static public VCS createVCS(ApplicationConfig config) { - Properties aliases = new Properties(); - aliases.setProperty("", VCS.class.getName()); - aliases.setProperty(TYPE_NONE, VCS.class.getName()); -// aliases.setProperty(TYPE_SVN, VCSSVN.class.getName()); -// aliases.setProperty(TYPE_CVS, VCSCVS.class.getName()); - - VCS result = null; - String type = config.getOption(VCS_TYPE); - // try to convert if type is not class name but an alias - String classname = aliases.getProperty(type, type); - try { - Class clazz = (Class)ConvertUtils.convert(classname, Class.class); - result = (VCS) ConstructorUtils.invokeConstructor(clazz, config); - } catch (Exception eee) { - log.error(_("Can't instanciate wanted VCS (%s), use default", - config.getOption(VCS_TYPE)), eee); - result = new VCS(config); - } - return result; - } + public void switchProtocole(String protocoleType) throws VCSException; - protected VCS(ApplicationConfig config) { - this.config = config; - } + /** + * Delete and commit files in server repository + * @param files file to delete + * @param msg message for commit + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void delete(List<File> files, String msg) throws VCSException; - public void add(List<File> files, String msg) throws VCSException { - throw new VCSException("Can't add file with dummy VCS"); - } + /** + * Return all changelog between local file version and remote repository + * file version + * @param files + * @return changelog for each file + */ + public Map<File, String> getChanglog(List<File> files); - public void checkout(File destDir, String module, boolean b) throws VCSException { - throw new VCSException("Can't checkout with dummy VCS"); - } + /** + * show diff between local file and repository file + * @param file + * @return + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public String getDiff(File file) throws VCSException; - public void delete(List<File> files, String msg) throws VCSException { - // do nothing - } - - public String getDiff(File file) throws VCSException { - throw new VCSException("Can't diff with dummy VCS"); - } - /** * Return list of all file on directory on remote server * @param directory * @return */ - public List<String> getFileList(File directory) throws VCSException { - List<String> result = new ArrayList<String>(); - return result; - } + public List<String> getFileList(File directory) throws VCSException; - public boolean isConnected() { - return false; - } - - public boolean isOnRemote(File file) throws VCSException { - return false; - } + /** + * get list of new or modified files on server + * @return list of modified or new files + */ + public List<File> getUpdatedFile(); - public boolean isUpToDate(File file) throws VCSException { - return true; - } + /** + * Ask if there are some new or modified files on server + * @return true if new file available + */ + public boolean haveUpdate(); /** + * Get connection state. + * @return true if server is connectable + */ + public boolean isConnected(); + + /** + * Check if file is available on server + * @param file file to check + * @return true if file available + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public boolean isOnRemote(File file) throws VCSException; + + /** + * look on server if version is tag repository + * @param version version number like 3.2 + * @return true if tag found with this name + */ + public boolean isTag(VersionNumber version); + + /** + * Check if file is uptodate + * @param file file to check + * @return true if file is in last version + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public boolean isUpToDate(File file) throws VCSException; + + /** * Must be overwriten, this default implementation return true. * Check if file can be put in vcs repository, for example when you used * CVS, you must not put CVS file. - * + * <p> + * default refused .svn, CVS and ~ filename + * * @param file * @return */ - public boolean isVersionnableAbleFile(File file) { - return true; - } + public boolean isVersionnableAbleFile(File file); - public void update(File file) throws VCSException { - throw new VCSException("Can't update file with dummy VCS"); - } - /** - * Usefull to permit to use VCS as filter - * @param pathname - * @return + * Update file + * @param file file to update + * @return true if there are some merging conflict, false otherwize + * @throws fr.ifremer.isisfish.vcs.VCSException */ - public boolean accept(File pathname) { - return isVersionnableAbleFile(pathname); - } + public boolean update(File file) throws VCSException; - } Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,76 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.vcs; + +import static org.codelutin.i18n.I18nf._; + +import java.util.Properties; +import org.apache.commons.beanutils.ConstructorUtils; +import org.apache.commons.beanutils.ConvertUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.ApplicationConfig; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class VCSFactory { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(VCSFactory.class); + + private VCSFactory() {} + + /** + * VCSNone factory, looking for vcs.type key in config to find vcs class to used + * If no vcs.type found or is not valid class, use {@link VCSNone}. + * @param config + * @return usable VCSNone + */ + static public VCSNone createVCS(ApplicationConfig config) { + Properties aliases = new Properties(); + // for empty and TYPE_NONE we used this class + aliases.setProperty("", VCSNone.class.getName()); + aliases.setProperty(VCS.TYPE_NONE, VCSNone.class.getName()); + aliases.setProperty(VCS.TYPE_SVN, VCSSVN.class.getName()); + // FIXME active this line when svn and CVS are implemented +// aliases.setProperty(TYPE_CVS, VCSCVS.class.getName()); + + VCSNone result = null; + String type = config.getOption(VCS.VCS_TYPE); + // try to convert if type is not class name but an alias + String classname = aliases.getProperty(type, type); + try { + Class clazz = (Class)ConvertUtils.convert(classname, Class.class); + result = (VCSNone) ConstructorUtils.invokeConstructor(clazz, config); + } catch (Exception eee) { + log.error(_("Can't instanciate wanted VCS (%s), use default", + config.getOption(VCS.VCS_TYPE)), eee); + result = new VCSNone(config); + } + return result; + } + +} Copied: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSNone.java (from rev 1283, trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java) =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSNone.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSNone.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,186 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.vcs; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static org.codelutin.i18n.I18nf._; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.ApplicationConfig; +import org.codelutin.util.VersionNumber; + +/** + * VCSNone (svn or vcs) must extends this class. This class can be used as dummy + * VCSNone if not valid VCSNone found. + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class VCSNone extends AbstractVCS { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(VCSNone.class); + + public VCSNone(ApplicationConfig config) { + super(config); + } + + /** + * look on server if version is tag repository + * @param version version number like 3.2 + * @return true if tag found with this name + */ + public boolean isTag(VersionNumber version) { + return false; + } + + /** + * Ask if there are some new or modified files on server + * @return true if new file available + */ + public boolean haveUpdate() { + return false; + } + + /** + * get list of new or modified files on server + * @return list of modified or new files + */ + public List<File> getUpdatedFile() { + return new ArrayList<File>(); + } + + /** + * Return all changelog between local file version and remote repository + * file version + * @param files + * @return changelog for each file + */ + public Map<File, String> getChanglog(List<File> files) { + return new HashMap<File, String>(); + } + + /** + * Add and commit file in server repository + * @param files list of file to add + * @param msg message for commit + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void add(List<File> files, String msg) throws VCSException { + throw new VCSException("Can't add file with dummy VCS"); + } + + /** + * get repository module on server and put it in destDir + * @param destDir destination directory + * @param module module name + * @param b // FIXME + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void checkout(File destDir, String module, boolean b) throws VCSException { + throw new VCSException("Can't checkout with dummy VCS"); + } + + /** + * Delete and commit files in server repository + * @param files file to delete + * @param msg message for commit + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public void delete(List<File> files, String msg) throws VCSException { + // do nothing + } + + /** + * show diff between local file and repository file + * @param file + * @return + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public String getDiff(File file) throws VCSException { + throw new VCSException("Can't diff with dummy VCS"); + } + + /** + * Return list of all file on directory on remote server + * @param directory + * @return + */ + public List<String> getFileList(File directory) throws VCSException { + List<String> result = new ArrayList<String>(); + return result; + } + + /** + * Get connection state. + * @return true if server is connectable + */ + public boolean isConnected() { + return false; + } + + /** + * Check if file is available on server + * @param file file to check + * @return true if file available + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public boolean isOnRemote(File file) throws VCSException { + return false; + } + + /** + * Check if file is uptodate + * @param file file to check + * @return true if file is in last version + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public boolean isUpToDate(File file) throws VCSException { + return true; + } + + /** + * Update file + * @param file file to update + * @return true if there are some merging conflict, false otherwize + * @throws fr.ifremer.isisfish.vcs.VCSException + */ + public boolean update(File file) throws VCSException { + throw new VCSException("Can't update file with dummy VCS"); + } + + public void switchTag(VersionNumber version) throws VCSException { + // do nothing + } + + public void switchProtocole(String protocoleType) throws VCSException { + // do nothing + } + + +} Added: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java (rev 0) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2008-08-14 14:55:00 UTC (rev 1298) @@ -0,0 +1,109 @@ +/* *##% + * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##%*/ + +package fr.ifremer.isisfish.vcs; + + +import java.io.File; +import java.util.List; +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.ApplicationConfig; +import org.codelutin.util.VersionNumber; + +/** + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class VCSSVN extends AbstractVCS { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(VCSSVN.class); + + public VCSSVN(ApplicationConfig config) { + super(config); + } + + public void add(List<File> files, String msg) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void checkout(File destDir, String module, boolean b) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void delete(List<File> files, String msg) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Map<File, String> getChanglog(List<File> files) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public String getDiff(File file) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public List<String> getFileList(File directory) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public List<File> getUpdatedFile() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean haveUpdate() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isConnected() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isOnRemote(File file) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isTag(VersionNumber version) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean isUpToDate(File file) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean update(File file) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void switchTag(VersionNumber version) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void switchProtocole(String protocoleType) throws VCSException { + throw new UnsupportedOperationException("Not supported yet."); + } + + +} Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/package.html =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/package.html 2008-08-13 18:24:19 UTC (rev 1297) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/package.html 2008-08-14 14:55:00 UTC (rev 1298) @@ -1,4 +1,4 @@ -Try to keep this class agnostic about IsisFish specific objet. This permit +Try to keep this classes agnostic about IsisFish specific objects. This permit library creation in near futur. <h1>Politique d'utilisation du VCS pour les datas</h1> @@ -29,9 +29,9 @@ <ul> <li>Sur le trunk en ecriture</li> <li>Sur le trunk en lecture (anonymous)</li> - <li>Sur le trunk en lecture (car release obsolete)</li> + <li>Sur le trunk en lecture (car release obsolete, sans mise a jour))</li> <li>Sur un tag car ancienne release</li> <li>Sur une branch (en developpement)</li> <li>En lecture (trunk, tag, branch) car reseau indisponible</li> </ul> -</p> \ No newline at end of file +</p>