Author: chatellier
Date: 2009-06-24 13:02:42 +0000 (Wed, 24 Jun 2009)
New Revision: 2425
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCS.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSNone.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java
isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties
isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java
Log:
Affichage des conflits lors des mises ?\195?\160 jour svn (la premi?\195?\168re fois)
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2009-06-24 13:02:42 UTC (rev 2425)
@@ -279,18 +279,6 @@
result = value == JOptionPane.OK_OPTION;
return result;
}
-
- /**
- * Permet d'afficher un message d'avertissement
- * à l'utilisateur.
- *
- * @param msg msg to show
- */
- protected static void warn(String msg) {
- JOptionPane.showMessageDialog(null, msg,
- _("isisfish.error.warning.title"),
- JOptionPane.WARNING_MESSAGE);
- }
/**
* Switch le vcs vers VCSNone et le sauvegarde pour le prochain lancement
@@ -311,27 +299,33 @@
static public void initVCS() throws VCSException {
if (config.isLaunchUI()) {
+
// init vcs
- // even if UI in not launched
+ // in graphical mode, real VCS
vcs = VCSFactory.createVCS(config);
-
- // FIXME ajouter une option vcs.init
VCSActionAsker asker = new VCSActionAsker();
vcs.addVetoableActionListener(asker);
// 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 (log.isInfoEnabled()) {
+ log.info(_("Check state of local repository: %s", local));
+ }
if (local.exists()) {
if (!vcs.isValidLocalRepository()) {
- log.info(_("Local repository exists but it's not valide for current vcs: %s", config.getOption(VCS.VCS_TYPE)));
+ if (log.isInfoEnabled()) {
+ log.info(_("Local repository exists but it's not valide for current vcs: %s",
+ config.getOption(VCS.VCS_TYPE)));
+ }
if (ask(_("isisfish.vcs.init.wrongprotocol", local))) {
File localBackup = new File(local.getParentFile(),
local.getName() + "-" +
new SimpleDateFormat("yyyy-mm-dd-HH-mm-ss").format(new java.util.Date()));
- log.info(_("Rename data directory to %s", localBackup));
+ if (log.isInfoEnabled()) {
+ 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");
@@ -344,7 +338,9 @@
// Si le repo local n'existe pas on fait un check out complet
if (!local.exists()) {
- log.info(_("Local repository don't exist"));
+ if (log.isInfoEnabled()) {
+ log.info(_("Local repository don't exist"));
+ }
if (!vcs.isConnected()) {
UserLog.warn(_(
"isisfish.vcs.init.notfoundcantdownload",
@@ -398,14 +394,15 @@
// il est possiblement obligatoire de ne plus etre sur le trunk, ou
// de migrer sur un autre tag
+ List<File> filesInClonflict = null;
+
// 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 {
// Si on utilise pas le bon tag on change de tag
VersionNumber tag = IsisConfig.getApiVersion();
-
- List<File> filesInClonflict = null;
+
if (vcs.isTag(tag)) {
// un tag dispo, on a donc pas la derniere version, on switch
filesInClonflict = vcs.setTag(tag);
@@ -418,22 +415,19 @@
// display a beautiful frame to manage each case
// for now, display a simple warning message
// si refus de l'utilisateur, c'est null aussi
- if(filesInClonflict != null && !filesInClonflict.isEmpty()) {
-
- // construit une chaine plutot qu'un Arrays.toString() qui
- // est illisible
- String conflictFiles = "";
- for(File file : filesInClonflict) {
- conflictFiles += " - " + file.toString() + "\n";
- }
-
- warn(_("isisfish.vcs.switchtag.warningconflict", conflictFiles));
+ if (filesInClonflict != null && !filesInClonflict.isEmpty()) {
+ warnFileListDialog(_("isisfish.error.warning.title"), _("isisfish.vcs.switchtag.warningconflict"), filesInClonflict);
}
}
// check file status
- vcs.checkFileStatus();
+ // WARNING : this do the real svn update
+ filesInClonflict = vcs.checkFileStatus();
+ if (filesInClonflict != null && !filesInClonflict.isEmpty()) {
+ warnFileListDialog(_("isisfish.error.warning.title"), _("isisfish.vcs.update.warningconflict"), filesInClonflict);
+ }
}
+
// fin de l'init on supprime le vetoable du vcs
vcs.remoteVetoableActionListener(asker);
}
@@ -446,6 +440,35 @@
}
/**
+ * Display dialog with files list, and specifique label.
+ *
+ * @param dialogTitle dialog title
+ * @param labelTitle labelTitle
+ * @param conflictFiles conflict files
+ */
+ protected static void warnFileListDialog(String dialogTitle, String labelTitle, List<File> conflictFiles) {
+ // construit une chaine plutot qu'un Arrays.toString() qui
+ // est illisible
+ String conflictFilesString = "";
+ String separator = "";
+ for(File file : conflictFiles) {
+ conflictFilesString += separator + file.toString();
+ separator = "\n";
+ }
+
+ JLabel labelModifiedFiles = new JLabel();
+ JTextArea areaModifiedFiles = new JTextArea(conflictFilesString);
+ areaModifiedFiles.setEditable(false);
+ areaModifiedFiles.setAutoscrolls(true);
+ JScrollPane sp = new JScrollPane(areaModifiedFiles);
+ sp.setPreferredSize(new Dimension(500, 100)); // don't remove popup is huge
+
+ JOptionPane.showMessageDialog(null, new Component[] { labelModifiedFiles, sp},
+ dialogTitle,
+ JOptionPane.WARNING_MESSAGE);
+ }
+
+ /**
* initialise et lance l'interface graphique si elle est demandee
*/
public static void launchUI() {
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCS.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCS.java 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCS.java 2009-06-24 13:02:42 UTC (rev 2425)
@@ -285,9 +285,11 @@
* les fichiers, avec la possibilite de voir les changements sur les
* fichiers
*
+ * @return list of file with unresolved conflict
+ *
* @throws VCSException
*/
- void checkFileStatus() throws VCSException;
+ List<File> checkFileStatus() throws VCSException;
/**
* Get host.
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSNone.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSNone.java 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSNone.java 2009-06-24 13:02:42 UTC (rev 2425)
@@ -193,8 +193,9 @@
// nothing to do
}
- public void checkFileStatus() throws VCSException {
+ public List<File> checkFileStatus() throws VCSException {
// nothing to do
+ return null;
}
public boolean isWriteable() throws VCSException {
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2009-06-24 13:02:42 UTC (rev 2425)
@@ -291,18 +291,23 @@
* les fichiers, avec la possibilite de voir les changements sur les
* fichiers
*
+ * @return list of file with unresolved conflict
* @throws VCSException
*/
@Override
- public void checkFileStatus() throws VCSException {
+ public List<File> checkFileStatus() throws VCSException {
+ List<File> fileInConflict = null;
+
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);
+ fileInConflict = update(null, true);
}
}
+
+ return fileInConflict;
}
/**
@@ -589,7 +594,7 @@
ISVNStatusHandler handler = new ISVNStatusHandler() {
public void handleStatus(SVNStatus status) throws SVNException {
- if ((acceptedStatusType.size() == 0
+ if ((acceptedStatusType.isEmpty()
&& status.getContentsStatus() != SVNStatusType.STATUS_NONE && status
.getContentsStatus() != SVNStatusType.STATUS_NORMAL)
|| acceptedStatusType.contains(status
@@ -1202,7 +1207,7 @@
// recherche de tous les fichiers locaux en conflit apres le switch
Map<File, SVNStatus> status = getLocalStatus(localRoot,
true, SVNStatusType.STATUS_CONFLICTED);
- if (status.size() > 0) {
+ if (!status.isEmpty()) {
filesInConflict = new ArrayList<File>();
filesInConflict.addAll(status.keySet());
// on supprime les conflits pour pouvoir commiter convenablement
@@ -1210,10 +1215,10 @@
//getSVNManager().getWCClient().doResolve(localFile, recurse);
// FIXME use conflit resolution choice ?
- //SVNWCClient wcClient = getSVNManager().getWCClient();
- //wcClient.doResolve(localFile, // File file
- // recurse ? SVNDepth.INFINITY : SVNDepth.FILES, // depth
- // SVNConflictChoice.MERGED); // ConflictChoice
+ SVNWCClient wcClient = getSVNManager().getWCClient();
+ wcClient.doResolve(localRoot, // File file
+ SVNDepth.INFINITY, // depth
+ SVNConflictChoice.MERGED); // ConflictChoice
}
}
}
Modified: isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties
===================================================================
--- isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-06-24 13:02:42 UTC (rev 2425)
@@ -986,7 +986,7 @@
isisfish.vcs.init.notfoundcantdownload=No database version %s found and can't get it.\nYou must go to ISIS-Fish web site and download database manually.
isisfish.vcs.init.wrongprotocol=Your database repository\: %s\n don't use correct protocol.\nDo you want to make backup of your database and take the correct one ?
isisfish.vcs.switchprotocol.confirm=Protocol to access repository script has changed.\nDo you want to switch your repository ?
-isisfish.vcs.switchtag.warningconflict=Your repository is now up-to-date, but following files are conflicted, you may check them \:\n%s
+isisfish.vcs.switchtag.warningconflict=Your repository is now up-to-date, but following files are conflicted, you may check them \:\n
isisfish.vcs.switchversion.confirm=You don't use correct repository script for your application version %s.\nDo you want to switch your repository ?
isisfish.vcs.update=vcs.update
isisfish.vcs.update.cancel=cancel
@@ -1007,6 +1007,7 @@
isisfish.vcs.update.tooltip.checkAll=checkAll
isisfish.vcs.update.tooltip.local=
isisfish.vcs.update.tooltip.remote=
+isisfish.vcs.update.warningconflict=Your repository is now up-to-date, but following files are conflicted, you may check them \:\n
isisfish.vcs.updateconfirm=updateconfirm
isisfish.vcs.updateconfirm.cancel=cancel
isisfish.vcs.updateconfirm.checkAll=checkAll
Modified: isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties
===================================================================
--- isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-06-24 13:02:42 UTC (rev 2425)
@@ -986,7 +986,7 @@
isisfish.vcs.init.notfoundcantdownload=La base de donn\u00E9es pour la version %s n'a ni pu \u00EAtre trouv\u00E9e, ni t\u00E9l\u00E9charg\u00E9e.\nVous devez la t\u00E9l\u00E9charger manullement \u00E0 partir du site d'Isis-Fish.
isisfish.vcs.init.wrongprotocol=Votre base de donn\u00E9es locale \: %s n'utilise pas un protocole correct.\nVoulez-vous faire une sauvegarde de cette base et r\u00E9cup\u00E9rer une meilleure version ?
isisfish.vcs.switchprotocol.confirm=Le protocole d'acc\u00E8s au d\u00E9p\u00F4t des scripts a chang\u00E9.\nVoulez-vous changer vers le nouveau d\u00E9p\u00F4t ?
-isisfish.vcs.switchtag.warningconflict=Votre base de donn\u00E9es a \u00E9t\u00E9 mise \u00E0 jour\nmais les fichiers suivants sont en conflit, merci de les v\u00E9rifier \:\n%s
+isisfish.vcs.switchtag.warningconflict=Votre base de donn\u00E9es a \u00E9t\u00E9 mise \u00E0 jour\nmais les fichiers suivants sont en conflit, merci de les v\u00E9rifier \:\n
isisfish.vcs.switchversion.confirm=Vous n'utilisez pas le d\u00E9p\u00F4t correct pour votre version d'Isis-Fish \: %s.\nVoulez-vous changer de d\u00E9p\u00F4t ?
isisfish.vcs.update=R\u00E9sultats de la synchronisation avec le serveur
isisfish.vcs.update.cancel=annuler
@@ -1007,6 +1007,7 @@
isisfish.vcs.update.tooltip.checkAll=(D\u00E9-)S\u00E9lectionner tous les fichiers (\u00E0 action unique) que vous voulez traiter
isisfish.vcs.update.tooltip.local=vcs.update.tooltip.local
isisfish.vcs.update.tooltip.remote=vcs.update.tooltip.remote
+isisfish.vcs.update.warningconflict=Votre base de donn\u00E9es a \u00E9t\u00E9 mise \u00E0 jour\nmais les fichiers suivants sont en conflit, merci de les v\u00E9rifier \:\n
isisfish.vcs.updateconfirm=Confirmation des ope\u00E9rations de synchronisation avec le serveur
isisfish.vcs.updateconfirm.cancel=annuler
isisfish.vcs.updateconfirm.checkAll=(de)-select tout
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-06-24 12:47:18 UTC (rev 2424)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-06-24 13:02:42 UTC (rev 2425)
@@ -882,14 +882,10 @@
}
VersionNumber version = new VersionNumber(3, 1, 0);
- boolean expResult = true;
- boolean result = vcs.isTag(version);
- Assert.assertEquals(expResult, result);
+ Assert.assertTrue(vcs.isTag(version));
version = new VersionNumber(3, 2, 0);
- expResult = false;
- result = vcs.isTag(version);
- Assert.assertEquals(expResult, result);
+ Assert.assertFalse(vcs.isTag(version));
}
/**
@@ -1050,4 +1046,199 @@
Assert.assertTrue("No file should be in conflit", filesInConflict
.isEmpty());
}
+
+ /**
+ * Test an update with file in conflict.
+ *
+ * - Checkout
+ * - commit modification
+ * - update at revision -1
+ * - modify one file
+ * - update at head
+ *
+ * @throws VCSException
+ * @throws SVNException
+ * @throws IOException
+ */
+ @Test
+ public void testUpdateWithConflict() throws VCSException, SVNException,
+ IOException {
+
+ // log
+ if (log.isInfoEnabled()) {
+ log.info("testUpdateWithConflict()");
+ }
+
+ // chechout
+ vcs.checkout(null, false);
+
+ // modif on remote repo
+ File file = new File(vcs.getLocalRepository(), "scripts"
+ + File.separator + "version.txt");
+ FileUtil.writeString(file, "aaaaaz");
+ SVNClientManager svnManager = SVNClientManager.newInstance();
+ SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
+ new File[] { file },// File[] paths,
+ false, //boolean keepLocks,
+ "modify version", //String commitMessage,
+ null, //SVNProperties revisionProperties,
+ null,// String[] changelists,
+ false, //boolean keepChangelist,
+ false, //boolean force,
+ SVNDepth.INFINITY); //SVNDepth depth);
+
+ // display : At revision 4
+ log.debug("Commited, new revision is " + rev.getNewRevision());
+
+ // do a new checkout at revision n-1
+ SVNRevision revision = SVNRevision.create(rev.getNewRevision() - 1);
+ SVNClientManager svnManagerLocal = vcs.getSVNManager();
+ SVNUpdateClient updateClient = svnManagerLocal.getUpdateClient();
+ long newRevision = updateClient.doUpdate(vcs.getLocalRepository(), // File file
+ revision, // SVNRevision revision
+ SVNDepth.INFINITY, // SVNDepth depth
+ false, // boolean allowUnversionedObstructions
+ false); // boolean depthIsSticky
+ log.debug("Updated at revision " + newRevision);
+
+ // modify one file
+ File file2 = new File(vcs.getLocalRepository(), "scripts"
+ + File.separator + "version.txt");
+ FileUtil.writeString(file2, "oooooo");
+
+ // try to update...
+ List<File> filesInConflict = vcs.update(null, true);
+ Assert.assertNotNull(filesInConflict);
+ Assert.assertEquals(1, filesInConflict.size());
+ log.debug("Conflicts are : " + filesInConflict);
+ }
+
+ /**
+ * Test a trunk-to-trunk switch with file in conflict.
+ *
+ * - Checkout tag
+ * - commit modification
+ * - swith to trunk
+ * - modify same file
+ * - switch to tag
+ *
+ * @throws VCSException
+ * @throws SVNException
+ * @throws IOException
+ */
+ @Test
+ public void testSwitchWithConflict() throws VCSException, SVNException,
+ IOException {
+
+ // log
+ if (log.isInfoEnabled()) {
+ log.info("testSwitchWithConflict()");
+ }
+
+ // chechout tags
+ vcs.checkout(new VersionNumber(3, 1, 0), false);
+
+ // modif on remote repo on tag :)
+ File file = new File(vcs.getLocalRepository(), "scripts"
+ + File.separator + "version.txt");
+ FileUtil.writeString(file, "aaaaaz");
+ SVNClientManager svnManager = SVNClientManager.newInstance();
+ SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
+ new File[] { file },// File[] paths,
+ false, //boolean keepLocks,
+ "modify version", //String commitMessage,
+ null, //SVNProperties revisionProperties,
+ null,// String[] changelists,
+ false, //boolean keepChangelist,
+ false, //boolean force,
+ SVNDepth.INFINITY); //SVNDepth depth);
+
+ // display : At revision 4
+ log.debug("Commited, new revision is " + rev.getNewRevision());
+
+ // switch to trunk
+ vcs.setTag(null);
+
+ // modify one file
+ File file2 = new File(vcs.getLocalRepository(), "scripts"
+ + File.separator + "version.txt");
+ FileUtil.writeString(file2, "oooooo");
+
+ // try to update...
+ List<File> filesInConflict = vcs.setTag(new VersionNumber(3, 1, 0));
+ Assert.assertNotNull(filesInConflict);
+ Assert.assertEquals(1, filesInConflict.size());
+ log.debug("Conflicts are : " + filesInConflict);
+ }
+
+ /**
+ * Test a checkFileStatus (witch is doing an update)
+ *
+ * - Checkout
+ * - commit modification
+ * - update at revision -1
+ * - modify one file
+ * - update at head
+ *
+ * @throws VCSException
+ * @throws SVNException
+ * @throws IOException
+ */
+ @Test
+ public void testCheckFileStatusWithConflict() throws VCSException, SVNException,
+ IOException {
+
+ // log
+ if (log.isInfoEnabled()) {
+ log.info("testCheckFileStatusWithConflict()");
+ }
+
+ // chechout
+ vcs.checkout(null, false);
+
+ // modif on remote repo
+ File file = new File(vcs.getLocalRepository(), "scripts"
+ + File.separator + "version.txt");
+ FileUtil.writeString(file, "aaaaaz");
+ SVNClientManager svnManager = SVNClientManager.newInstance();
+ SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
+ new File[] { file },// File[] paths,
+ false, //boolean keepLocks,
+ "modify version", //String commitMessage,
+ null, //SVNProperties revisionProperties,
+ null,// String[] changelists,
+ false, //boolean keepChangelist,
+ false, //boolean force,
+ SVNDepth.INFINITY); //SVNDepth depth);
+
+ // display : At revision 4
+ log.debug("Commited, new revision is " + rev.getNewRevision());
+
+ // do a new checkout at revision n-1
+ SVNRevision revision = SVNRevision.create(rev.getNewRevision() - 1);
+ SVNClientManager svnManagerLocal = vcs.getSVNManager();
+ SVNUpdateClient updateClient = svnManagerLocal.getUpdateClient();
+ long newRevision = updateClient.doUpdate(vcs.getLocalRepository(), // File file
+ revision, // SVNRevision revision
+ SVNDepth.INFINITY, // SVNDepth depth
+ false, // boolean allowUnversionedObstructions
+ false); // boolean depthIsSticky
+ log.debug("Updated at revision " + newRevision);
+
+ // modify one file
+ File file2 = new File(vcs.getLocalRepository(), "scripts"
+ + File.separator + "version.txt");
+ FileUtil.writeString(file2, "oooooo");
+
+ // try to update...
+ List<File> filesInConflict = vcs.checkFileStatus();
+ Assert.assertNotNull(filesInConflict);
+ Assert.assertEquals(1, filesInConflict.size());
+ log.debug("Conflicts are : " + filesInConflict);
+
+ // do it twice doesn't return results
+ // checkFileStatus is doing a merge
+ filesInConflict = vcs.checkFileStatus();
+ Assert.assertNull(filesInConflict);
+ }
}
\ No newline at end of file