r1307 - in trunk/isis-fish/src/java/fr/ifremer/isisfish: . datastore datastore/migration entities simulator ui/widget vcs
Author: bpoussin Date: 2008-08-21 16:21:52 +0000 (Thu, 21 Aug 2008) New Revision: 1307 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/RegionStorage.java trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java trunk/isis-fish/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/widget/Interval.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java Log: - modification de StrategyMonthInfo.[numberOfTrips|minInactivityDays] de int en double - correction du lanceur de simulation pour que les threads de l'executor retrouve bien la simu a faire - amelioration des logs - vcs fonctionnel Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisConfig.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -123,6 +123,7 @@ protected long startingTime = System.nanoTime(); public IsisConfig() { + for (Option o : Option.values()) { setDefaultOption(o.key, o.defaultValue); } @@ -268,10 +269,10 @@ setOption(Option.SIMULATOR_LAUNCHER.key, value); } - public boolean isSimulationShowOnlyQueue() { - Boolean result = getOptionAsBoolean(Option.SIMULATION_SHOW_ONLY_QUEUE.key); - return result; - } +// public boolean isSimulationShowOnlyQueue() { +// Boolean result = getOptionAsBoolean(Option.SIMULATION_SHOW_ONLY_QUEUE.key); +// return result; +// } public boolean isSimulationShowOnlyError() { Boolean result = getOptionAsBoolean(Option.SIMULATION_SHOW_ONLY_ERROR.key); @@ -498,7 +499,7 @@ "password", Option.SIMULATOR_PASSWORD.key, "simulationServer", Option.SIMULATOR_SERVER.key, "simulationShowOnlyError", Option.SIMULATION_SHOW_ONLY_ERROR.key, - "simulationShowOnlyQueue", Option.SIMULATION_SHOW_ONLY_QUEUE.key, + "simulationShowOnlyQueue", null, // Option.SIMULATION_SHOW_ONLY_QUEUE.key, "smtpServer", Option.SMTP_SERVER.key, "userMail", Option.USER_MAIL.key, "userName", Option.USER_NAME.key, @@ -515,8 +516,13 @@ "vcs.typeRepo", null, "vcs.useSshConnexion", null, "vcs.userName", null, + "version", null, + "projectName", null, + "simulationReportMail", null, + }; + log.info("Check configuration change"); for(int i=0; i<keys.length;) { String oldKey = keys[i++]; String newKey = keys[i++]; @@ -524,10 +530,9 @@ String value = getOption(oldKey); if (value != null) { mustSave = true; - if (newKey == null) { - // pas d'equivalent a la cle, on la supprime - homefile.remove(oldKey); - } else { + // quoi qu'il arrive on enleve l'ancienne cle + homefile.remove(oldKey); + if (newKey != null) { setOption(newKey, value); } } @@ -535,7 +540,16 @@ } if (mustSave) { saveForUser(); + log.info("Config file migration done"); + try { + save(new File("/tmp/test.properties"), true); + } catch(Exception eee ){ + eee.printStackTrace(); + } } + if (log.isDebugEnabled()) { + printConfig(); + } } ////////////////////////////////////////////////// @@ -545,7 +559,7 @@ static public enum Option { COMPILATION_DIRECTORY("compilation.directory", _("isisfish.config.main.compileDirectory.description"), getUserHome() + File.separator + "isis-build"), - CONFIG_FILE("config.file", _("isisfish.config.main.configFileName.description"), getUserHome() + File.separator + "." + CONFIG_FILENAME), + CONFIG_FILE(CONFIG_FILE_NAME, _("isisfish.config.main.configFileName.description"), CONFIG_FILENAME), BACKUP_DIRECTORY("backup.directory", _("isisfish.config.main.defaultBackupDirectory.description"), getUserHome() + File.separator + "isis-backup"), DEFAULT_EXPORT_DIRECTORY("default.export.directory", _("isisfish.config.main.defaultExportDirectory.description"), getUserHome() + File.separator + "isis-export"), @@ -568,8 +582,8 @@ LOCALE("locale", _("isisfish.config.main.locale.description"), "fr_FR"), // REGION_MAP("regionMap", _("isisfish.config.main.regionMap.description"), "maps"), // RESULT_EXPORT("resultExport", String.class, 15, n_("isisfish.config.main.resultExport.description"), "resultExports"), - SIMULATION_SHOW_ONLY_ERROR("simulationShowOnlyError", _("isisfish.config.main.simulationShowOnlyError.description"), "true"), - SIMULATION_SHOW_ONLY_QUEUE("simulationShowOnlyQueue", _("isisfish.config.main.simulationShowOnlyQueue.description"), "true"), + SIMULATION_SHOW_ONLY_ERROR("simulationShowOnlyError", _("isisfish.config.main.simulationShowOnlyError.description"), "false"), +// SIMULATION_SHOW_ONLY_QUEUE("simulationShowOnlyQueue", _("isisfish.config.main.simulationShowOnlyQueue.description"), "true"), // if false no graphical interface LAUNCH_UI("launch.ui", _("isisfish.config.main.launchUI.description"), "true"), @@ -582,11 +596,11 @@ // can be None, CVS or SVN. only None or SVN work VCS_TYPE(VCS.VCS_TYPE, _("isisfish.config.vcs.type.description"), VCS.TYPE_SVN), - // depend of VCS_TYPE, for SVN can be http or ssh - VCS_PROTOCOLE(VCS.VCS_PROTOCOLE, _("isisfish.config.vcs.useSshConnexion.description"), "http"), + // depend of VCS_TYPE, for SVN can be svn, svn+ssh, http or file + VCS_PROTOCOLE(VCS.VCS_PROTOCOLE, _("isisfish.config.vcs.useSshConnexion.description"), "svn"), VCS_SSH_KEY_FILE(VCS.VCS_SSH_KEY_FILE, _("isisfish.config.vcs.keyFile.description"), getUserHome() + File.separator + ".ssh" + File.separator + "isis_rsa"), // user login to access vcs - VCS_USER_NAME(VCS.VCS_USER_NAME, _("isisfish.config.vcs.userName.description"), "anonymous"), + VCS_USER_NAME(VCS.VCS_USER_NAME, _("isisfish.config.vcs.userName.description"), ""), VCS_USER_PASSWORD(VCS.VCS_USER_PASSWORD, _("isisfish.config.vcs.userPassword.description"), ""), 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"), Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/IsisFish.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -74,6 +74,7 @@ import org.swixml.ConverterLibrary; import org.codelutin.i18n.I18n; +import org.codelutin.log.UserLog; import org.codelutin.topia.TopiaException; import org.codelutin.util.LocaleConverter; import org.codelutin.util.VersionNumber; @@ -125,7 +126,11 @@ // action after init config.doAction(IsisConfig.Step.AfterInit.ordinal()); - initVCS(); + try { + initVCS(); + } catch (Exception eee) { + log.warn(_("Error during vcs initialisation"), eee); + } log.info(_("isisfish.launching", config.getElapsedTimeAsString())); @@ -187,21 +192,11 @@ } -// public static void initVCS() { -// StringBuilder sb = new StringBuilder(); -// sb.append("connectionState : ").append(vcsConfig.getConnectionState()); -// sb.append("\nhasPreviousConfig : ").append(vcsConfig.hasPreviousConfig()); -// sb.append("\nisTypeChanged : ").append(vcsConfig.isTypeChanged()); -// sb.append("\nneedMigration : ").append(vcsConfig.needMigration()); -// if (vcsConfig.needMigration()) { -// sb.append("\nmigrationType ").append(vcsConfig.getMigrationType()); -// } -// for (String s : sb.toString().split("\n")) { -// log.info(s); -// } -// -// } - + /** + * Veto utilise lors de l'init du vcs pour permettre a l'utilisateur de + * refuser certaine action. S'il refuse les switchs le vcs est passe en + * readonly. + */ static class VCSActionAsker implements VetoableActionListener { public boolean canDoAction(VCS vcs, VCSActionEvent action, File... files) { @@ -233,23 +228,37 @@ } + /** + * Permet de faire une demande a l'utilisateur. S'il repond annuler, on + * quit l'application + * + * @param msg + * @return + */ public static boolean ask(String msg) { boolean result = true; int value = JOptionPane.showConfirmDialog(null, msg); + if (value == JOptionPane.CANCEL_OPTION) { + quit(); + } result = value == JOptionPane.OK_OPTION; return result; } + /** + * Switch le vcs vers VCSNone et le sauvegarde pour le prochain lancement + */ protected static void switchToNoneVCS() { - config.setOption(IsisConfig.Option.VCS_PROTOCOLE.key, "none"); + log.info(_("Switch repository type to none")); + config.setOption(IsisConfig.Option.VCS_TYPE.key, VCS.TYPE_NONE); config.saveForUser(); vcs = VCSFactory.createVCS(config); } /** - * Initialise le VCSNone et check s'il y a des mises a jour pour prevenir + * Initialise le VCS et check s'il y a des mises a jour pour prevenir * l'utilisateur */ - static public void initVCS() throws VCSException { + static public void initVCS() throws VCSException { // init vcs vcs = VCSFactory.createVCS(config); VCSActionAsker asker = new VCSActionAsker(); @@ -257,12 +266,18 @@ // Si le repo local exist mais n'est pas du bon type, on renome ce repertoire File local = config.getDatabaseDirectory(); + log.info(_("Check state of local repository: %s", local)); + if (local.exists()) { if(!vcs.isValidLocalRepository()) { - if (ask(_("Your database repository don't use correct protocol.\nDo you want to make backup of your database and take the correct one ?"))) { + log.info(_("Local repository exists but it's not valide for current vcs: %s", config.getOption(VCS.VCS_TYPE))); + if (ask(_("Your database repository: %s\n don't use correct" + + " protocol.\nDo you want to make backup of your database" + + " and take the correct one ?", local))) { File localBackup = new File(local.getParentFile(), local.getName() + "-" + - new SimpleDateFormat().format(new Date())); + new SimpleDateFormat("yyyy-mm-dd-HH-mm-ss").format(new java.util.Date())); + log.info(_("Rename data directory to %s", localBackup)); if (!local.renameTo(localBackup)) { throw new IsisFishRuntimeException( "Can't rename local repository that don't use svn"); @@ -275,12 +290,12 @@ // Si le repo local n'existe pas on fait un check out complet if (!local.exists()) { - if (vcs instanceof VCSNone) { - JOptionPane.showMessageDialog(null, _( - "No database found and can't get it.\n" + - "You must go to ISIS-Fish web site and download database manualy."), - _("Database needed %s", IsisConfig.getVersion()), - JOptionPane.WARNING_MESSAGE); + log.info(_("Local repository don't exist")); + if (!vcs.isConnected()) { + UserLog.warn(_( + "No database version %s found and can't get it.\n" + + "You must go to ISIS-Fish web site and download database manualy.", + IsisConfig.getDatabaseVersion())); } else { // Si on utilise pas le bon tag on change de tag VersionNumber tag = IsisConfig.getApiVersion(); @@ -316,31 +331,37 @@ throw new IsisFishRuntimeException("Can't find local repository"); } - // check protocol, user, host - vcs.checkProtocol(); + // on s'arrete la si on est pas connecte + if (vcs.isConnected()) { + + // check protocol, user, host + vcs.checkProtocol(); - // Suivant la version du logiciel et les versions de base disponible - // il est possiblement obligatoire de ne plus etre sur le trunk, ou - // de migrer sur un autre tag + // Suivant la version du logiciel et les versions de base disponible + // il est possiblement obligatoire de ne plus etre sur le trunk, ou + // de migrer sur un autre tag - // si on est sur une branche, on est en developpement, on ne fait donc rien - if (!vcs.getTag().startsWith("branches")) { - - // Si on utilise pas le bon tag on change de tag - VersionNumber tag = IsisConfig.getApiVersion(); - if (vcs.isTag(tag)) { - // un tag dispo, on a donc pas la derniere version, on switch - vcs.setTag(tag); + // si on est sur une branche, on est en developpement, on ne fait donc rien + if (vcs.getTag().startsWith("branches")) { + log.info(_("Use branches, switch not needed")); } else { - // pas de tag dispo on retourne sur le trunk - vcs.setTag(null); + // Si on utilise pas le bon tag on change de tag + VersionNumber tag = IsisConfig.getApiVersion(); + if (vcs.isTag(tag)) { + // un tag dispo, on a donc pas la derniere version, on switch + vcs.setTag(tag); + } else { + // pas de tag dispo on retourne sur le trunk + vcs.setTag(null); + } } - } - // check file status - vcs.checkFileStatus(); - + // check file status + vcs.checkFileStatus(); + } + // fin de l'init on supprime le vetoable du vcs + vcs.remoteVetoableActionListener(asker); } /** Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/RegionStorage.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/RegionStorage.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/RegionStorage.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -423,6 +423,8 @@ tx.execute("DELETE " + Result.class.getName()); tx.commitTransaction(); + // FIXME le service topia de migration devrait se mettre en + // route pour les veilles base apres le restore tx.closeContext(); } } Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -109,6 +109,8 @@ "alter table SETOFVESSELS add column TECHNICALEFFICIENCYEQUATION VARCHAR(255);", "alter table STRATEGY add column INACTIVITYEQUATIONUSED BIT default false;", "alter table STRATEGY add column INACTIVITYEQUATION VARCHAR(255);", + "alter table STRATEGYMONTHINFO alter NUMBEROFTRIPS double;", + "alter table STRATEGYMONTHINFO alter MININACTIVITYDAYS double;", }; for (String sql : sqls) { log.info("try " + sql); Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/entities/StrategyMonthInfoImpl.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -145,7 +145,7 @@ * @see fr.ifremer.isisfish.entities.StrategyMonthInfoAbstract#setMinInactivityDays(int) */ @Override - public void setMinInactivityDays(int value) { + public void setMinInactivityDays(double value) { super.setMinInactivityDays(value); computeNumberOfTrips(); } @@ -158,8 +158,8 @@ double inactivity = getStrategy().getInactivityDays(getMonth()); if(tripType != null && tripType.getTripDuration() != null && inactivity >= 0){ int nbDayMonth = getMonth().getNumbersOfDays(); - double result = (int)((nbDayMonth - inactivity) / tripType.getTripDuration().getDay()); - setNumberOfTrips((int)result); + double result = (nbDayMonth - inactivity) / tripType.getTripDuration().getDay(); + setNumberOfTrips(result); } } Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationHelper.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -267,7 +267,11 @@ // } // classpath[classpath.length - 1] = directory.toURL(); // URLClassLoader loader = new URLClassLoader(classpath, null); - URL [] classpath = new URL[]{directory.toURI().toURL()}; + URL [] classpath = new URL[]{directory.toURI().toURL(), + // poussin 20080821 + // il semble ne plus trouve les formules, est-ce mieux avec le compile dir ? + IsisFish.config.getCompileDirectory().toURI().toURL() + }; //URL [] classpath = new URL[]{directory.toURL()}; AspectClassLoader loader = new AspectClassLoader(classpath, ClassLoader.getSystemClassLoader()); //new URLClassLoader(classpath); thread.setContextClassLoader(loader); Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/simulator/SimulationManager.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -114,7 +114,8 @@ // remoteThread.start(); // TODO passer ces valeurs en valeur configurable - int cpus = Runtime.getRuntime().availableProcessors(); + int cpus = 1; // FIXME les logs ne sont pas multi-thread (il se melange a priori) +// int cpus = Runtime.getRuntime().availableProcessors(); int MAX_REMOTE_SIMULATION = 1; log.info(_("Launch Simulation executor with %s cpu(s) for local, and %s" + " process for remote", cpus, MAX_REMOTE_SIMULATION)); @@ -182,6 +183,7 @@ */ public void addSimulation(String id, SimulationParameter param) throws Exception { ExecutorService executor = null; + Runnable job = null; if (param.getLocal()) { executor = localExecutor; log.debug(_("isisfish.message.add.queue", id)); @@ -198,21 +200,22 @@ // c un plan d'analyse, il peut etre independant ou dependant if (!param.isIndependentPlan()) { item = new SimulationItemPlan(id, param); - executor.execute(new SimulationJob(this, item)); + job = new SimulationJob(this, item); } else { // on met dans la queue local le process de generation de toutes // les simus item = new SimulationItemPlanIndependent(id, param); - localExecutor.execute( - new PrepareIndependentSimulationJob(this, executor, item)); + job = new PrepareIndependentSimulationJob(this, executor, item); + executor = localExecutor; // change after job creation, because job need reel executor } } else { // une simulation normal item = new SimulationItem(id, param); log.info("Simulation added to executor: " + executor.isShutdown() + ", " + executor.isTerminated()); - executor.execute(new SimulationJob(this, item)); + job = new SimulationJob(this, item); } fireAddEvent(id, item); // must be before thread notification because thread look in map + executor.execute(job); } /** @@ -359,22 +362,28 @@ * the corresponding simulation */ protected boolean mustShowSimulationDone(String id) { + IsisConfig config = IsisFish.config; - boolean result = true; + boolean result = !config.isSimulationShowOnlyError(); try { - IsisConfig config = IsisFish.config; SimulationItem item = map.get(id); - if (item.hasPlanItem() && !item.getSimulation().getInformation().hasError()) { - // on ne met jamais dans la queue done les simulations de plan - // sauf si elle echoue - result = false; -// FIXME a revoir la condition avec showOnly error et showOnly queue (qui ne sert plus) - } else if (!(config.isSimulationShowOnlyError() && - !(item instanceof SimulationItemPlan) && + + if (result || (!(item instanceof SimulationItemPlan) && item.getSimulation().getInformation().hasError())) { - result = false; + result = true; } + +// if (item.hasPlanItem() && !item.getSimulation().getInformation().hasError()) { +// // on ne met jamais dans la queue done les simulations de plan +// // sauf si elle echoue +// result = false; +//// FIXME a revoir la condition avec showOnly error et showOnly queue (qui ne sert plus) +// } else if (!(config.isSimulationShowOnlyError() && +// !(item instanceof SimulationItemPlan) && +// item.getSimulation().getInformation().hasError())) { +// result = false; +// } } catch (Exception eee) { log.debug("Ne devrait pas arriver", eee); // I don't known how it could appear, but in doubt, show it! @@ -703,6 +712,9 @@ simulationManager.waitAutoLaunch(); try { // si l'simItem exist encore (que l'utilisateur ne la pas retire) + log.info("id: " + simItem.getPlanIdOrId() + " exists ? " + + simulationManager.exists(simItem.getPlanIdOrId()) + + " hasNext ? " + simItem.hasNext()); while (simulationManager.exists(simItem.getPlanIdOrId()) && simItem.hasNext()) { SimulationItem item = simItem.next(); @@ -844,6 +856,12 @@ return planItem; } + /** + * Si renvoi vrai, cela veut dire que cette simulation a ete generee + * par un plan d'experience + * + * @return + */ public boolean hasPlanItem() { boolean result = planItem != null; return result; Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/widget/Interval.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/widget/Interval.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/ui/widget/Interval.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -35,16 +35,13 @@ import java.util.Iterator; import java.util.Observable; -import org.codelutin.xml.XMLable; - /** * Classe permettant de d'ecrire un interval. Cette interval est un peu * particulier car il est circulaire. Par exemple si min=0, max=100, first=75 et * bien last peut etre egal à 25 donc inferieur a first. Dans ce cas si l'on * demande contains 50 il repond faux et contains 99 retourne vrai. */ -public class Interval extends Observable implements Serializable, Cloneable, - XMLable { // Interval +public class Interval extends Observable implements Serializable, Cloneable { // Interval /** * 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-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCS.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -44,7 +44,7 @@ /** * can be http, ssh, pserver, ... */ - public static final String VCS_PROTOCOLE = "vcs.protocole"; + public static final String VCS_PROTOCOLE = "vcs.protocol"; /** * ssh key file */ Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSFactory.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -51,7 +51,7 @@ * @param config * @return usable VCSNone */ - static public VCSNone createVCS(IsisConfig config) { + static public VCS createVCS(IsisConfig config) { Properties aliases = new Properties(); // for empty and TYPE_NONE we used this class aliases.setProperty("", VCSNone.class.getName()); @@ -60,7 +60,7 @@ // FIXME active this line when svn and CVS are implemented // aliases.setProperty(TYPE_CVS, VCSCVS.class.getName()); - VCSNone result = null; + VCS 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); @@ -75,7 +75,7 @@ try { Class clazz = (Class) ConvertUtils.convert(classname, Class.class); - result = (VCSNone) ConstructorUtils.invokeConstructor(clazz, + result = (VCS) ConstructorUtils.invokeConstructor(clazz, new Object[]{dataDir, protocol, host, path, sshKeyFile, login, password}); } catch (Exception eee) { log.error(_("Can't instanciate wanted VCS (%s), use default", Modified: trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java =================================================================== --- trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2008-08-20 13:06:19 UTC (rev 1306) +++ trunk/isis-fish/src/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2008-08-21 16:21:52 UTC (rev 1307) @@ -61,8 +61,13 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(VCSSVN.class); - + + static enum ConnectionState { + NOT_TESTED, OFF_LINE, ON_LINE + } + protected SVNClientManager svnManager = null; + protected ConnectionState connectionState = ConnectionState.NOT_TESTED; public VCSSVN(File localRepository, String protocol, String host, String path, @@ -109,38 +114,66 @@ boolean result = svn.exists(); return result; } - + + public boolean isConnected() { + if (connectionState == ConnectionState.NOT_TESTED) { + try { + SVNURL url = getRemoteURL(); + getSVNManager().getWCClient().doGetProperty(url, "", + SVNRevision.HEAD, + SVNRevision.HEAD, false); + connectionState = ConnectionState.ON_LINE; + log.info(_("Connection to serveur available, switch on line: %s", + getRemoteRepository())); + } catch(SVNException eee) { + log.info(_("Can't connect to serveur, switch to off line: %s", + getRemoteRepository())); + connectionState = ConnectionState.OFF_LINE; + } + } + boolean result = connectionState == ConnectionState.ON_LINE; + return result; + } + @Override public void checkProtocol() throws VCSException { try { File localRoot = getLocalRepository(); - SVNInfo info = getSVNManager().getWCClient().doInfo(localRoot, SVNRevision.WORKING); + SVNInfo info = getSVNManager().getWCClient().doInfo( + localRoot, SVNRevision.WORKING); SVNURL url = info.getURL(); + SVNURL rootUrl = info.getRepositoryRootURL(); + String path = url.toDecodedString().substring(rootUrl.toDecodedString().length()); - // si un des constituants de l'url a change on fait un switch relocate - boolean mustSwitch = false; - if (!url.getProtocol().equals(getProtocol())) { - log.info(_("repository protocol change from %s to %s", - url.getProtocol(), getProtocol())); - mustSwitch = true; - } - if (!url.getUserInfo().equals(getLogin())) { - log.info(_("repository user change from %s to %s", - url.getUserInfo(), getLogin())); - mustSwitch = true; - } - if (!url.getHost().equals(getHost())) { - log.info(_("repository host change from %s to %s", - url.getHost(), getHost())); - mustSwitch = true; - } - - if (mustSwitch) { +// // si un des constituants de l'url a change on fait un switch relocate +// boolean mustSwitch = false; +// if (!url.getProtocol().equals(getProtocol())) { +// log.info(_("repository protocol change from %s to %s", +// url.getProtocol(), getProtocol())); +// mustSwitch = true; +// } +// if (!url.getUserInfo() != null !url.getUserInfo().equals(getLogin())) { +// log.info(_("repository user change from %s to %s", +// url.getUserInfo(), getLogin())); +// mustSwitch = true; +// } +// if (!url.getHost().equals(getHost())) { +// log.info(_("repository host change from %s to %s", +// url.getHost(), getHost())); +// mustSwitch = true; +// } +// +// if (mustSwitch) { + SVNURL newUrl = getRemoteURL(); + newUrl = newUrl.appendPath(path, false); + if (!url.equals(newUrl)) { if (fireAction(VCSActionEvent.SWITCH_PROTOCOL)) { - String path = url.getPath(); - int port = url.getPort(); - SVNURL newUrl = SVNURL.create(getProtocol(), getLogin(), - getHost(), port, path, true); +// String path = url.getPath(); +// int port = url.getPort(); +// SVNURL newUrl = SVNURL.create(getProtocol(), getLogin(), +// getHost(), port, path, true); + log.info(_("Switch repository %s from %s to %s", + localRoot, url, newUrl)); getSVNManager().getUpdateClient().doRelocate(localRoot, url, newUrl, true); } } @@ -158,14 +191,12 @@ * fichiers */ public void checkFileStatus() throws VCSException { - if (isConnected()) { - Map<File, SVNStatus> status = getRemoteStatus(null, true); + Map<File, SVNStatus> status = getRemoteStatus(null, true); // si des fichiers ont ete mis a jour sur le serveur on se synchronise - if (status.size() > 0) { - if (fireAction(VCSActionEvent.UPDATE_REPOSITORY, - status.keySet().toArray(new File[status.size()]))) { - update(null, true); - } + if (status.size() > 0) { + if (fireAction(VCSActionEvent.UPDATE_REPOSITORY, + status.keySet().toArray(new File[status.size()]))) { + update(null, true); } } } @@ -355,7 +386,7 @@ handler); return result; } catch (SVNException eee) { - throw new VCSException("Can't add file", eee); + throw new VCSException("Can't status file", eee); } } @@ -396,7 +427,7 @@ handler); return result; } catch (SVNException eee) { - throw new VCSException("Can't add file", eee); + throw new VCSException("Can't status file", eee); } } @@ -420,10 +451,6 @@ 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."); } @@ -511,7 +538,8 @@ public String getTag() throws VCSException { try { File localRoot = getLocalRepository(); - SVNInfo info = getSVNManager().getWCClient().doInfo(localRoot, SVNRevision.WORKING); + SVNInfo info = getSVNManager().getWCClient().doInfo( + localRoot, SVNRevision.WORKING); String url = info.getURL().toDecodedString(); String result = "/trunk"; if (!url.endsWith("/trunk")) { @@ -545,7 +573,10 @@ SVNURL newUrl = getRemoteURL(); newUrl = newUrl.appendPath(tag, true); - getSVNManager().getUpdateClient().doSwitch(localRoot, newUrl, SVNRevision.HEAD, true); + log.info(_("Switch repository tag from %s to %s", + currantTag, tag)); + getSVNManager().getUpdateClient().doSwitch( + localRoot, newUrl, SVNRevision.HEAD, true); } } } catch (SVNException eee) {
participants (1)
-
bpoussin@users.labs.libre-entreprise.org