r345 - in trunk/lutinvcs: lutinvcs-api/src/main/java/org/codelutin/vcs lutinvcs-api/src/main/java/org/codelutin/vcs/util lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs lutinvcs-provider-cvs/src/test/java/org/codelutin/vcs/impl/cvs lutinvcs-provider-mock/src/main/java/org/codelutin/vcs lutinvcs-provider-svn/src/main/java/org/codelutin/vcs lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn
Author: tchemit Date: 2008-04-04 21:14:37 +0000 (Fri, 04 Apr 2008) New Revision: 345 Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSConnexion.java trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockConnexion.java trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNConnexion.java Removed: trunk/lutinvcs/lutinvcs-provider-cvs/src/test/java/org/codelutin/vcs/impl/cvs/CVSHandlerTest.java trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNHandlerTest.java trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNLogTest.java Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/ConnectionState.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSAction.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionMode.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockHandlerProvider.java trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNHandlerProvider.java Log: begin of refactor : handler are staeless with no config information introduc a VCSConnexion objectto deal with connexion, handler must use now this object to perform action as a method parameter Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/ConnectionState.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/ConnectionState.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/ConnectionState.java 2008-04-04 21:14:37 UTC (rev 345) @@ -24,6 +24,8 @@ * @author chemit */ public enum ConnectionState { + /** lorsque la connexion a �t� initialis�e (valid�e) mais pas ouverte */ + INIT, /** lorsque la connexion n'a pas encore initialis�e */ UNDEFINED, /** lorsque la connexion est ok, mais que l'on est pas connect� */ Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSAction.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSAction.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSAction.java 2008-04-04 21:14:37 UTC (rev 345) @@ -61,12 +61,13 @@ /** libelle of the action */ private final String libelle; - /** flag to say if action should be visible in ui */ + /** flag to say if action should be visible in ui TODO Delete this */ private final boolean visible; - /** flag to say if this action need backup */ + /** flag to say if this action need backup TODO Delete this ? */ private final boolean backup; /** flag to say if this action need write access to repository */ private final boolean write; + /** flag to say if this action need a commit message to be performed */ private boolean commit; VCSAction(String libelle, boolean visible, boolean backup, boolean commit, boolean write) { Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java 2008-04-04 21:14:37 UTC (rev 345) @@ -0,0 +1,96 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 org.codelutin.vcs; + +import java.io.File; +import java.net.URI; +import java.util.Map; + +/** + * Contract to be realized for a connexion to a vcs. + * <p/> + * The method {@link #init(VCSConfig, VCSHandler)} must be invoked before using the connexion. + * + * @author chemit + */ +public interface VCSConnexion { + + /** + * @return the working copy used, can be null if no working copy exists. + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + File getWorkingCopy() throws IllegalStateException; + + /** + * @return the URI used to connect to vcs + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + URI getRemoteURI() throws IllegalStateException; + + /** + * @return the mode of this connexion + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + VCSConnexionMode getMode() throws IllegalStateException; + + /** + * @return options to be used by this connexion + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + Map<String, String> getOptions() throws IllegalStateException; + + /** + * Initialise the connexion. + * <p/> + * If connexion can not be established, then the method {@link #hasFailed()} will always + * return <code>true</code>. + * + * @param config config to be used to initialize the connexion. + * @param handler handler to be used to initialize the connexion. + */ + void init(VCSConfig config, VCSHandler handler); + + /** + * Close connexion. + * + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + void open() throws IllegalStateException; + + /** + * Close connexion. + * + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + void close() throws IllegalStateException; + + /** + * @return <code>true</code> if connexion is opened, <code>false</code> otherwise + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + boolean isOpen() throws IllegalStateException; + + /** + * @return <code>true</code> if connexion is closed, <code>false</code> otherwise + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + boolean isClosed() throws IllegalStateException; + + /** + * @return <code>true</code> if connexion has failed, <code>false</code> otherwise + * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. + */ + boolean hasFailed() throws IllegalStateException; +} Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionMode.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionMode.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionMode.java 2008-04-04 21:14:37 UTC (rev 345) @@ -21,5 +21,6 @@ */ public enum VCSConnexionMode { ANONYMOUS, + PASSWORD, SSH } Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java 2008-04-04 21:14:37 UTC (rev 345) @@ -19,7 +19,7 @@ * * @author chemit */ -public interface VCSHandlerProvider<H extends VCSHandler> { +public interface VCSHandlerProvider<H extends VCSHandler, C extends VCSConnexion> { /** @return the identifier of the vcs provider (eg SVN, CVS, MOCK) */ String getName(); @@ -32,4 +32,11 @@ */ H newInstance(VCSConfig config); + /** + * @param mode the mode required + * @param config the config to be used + * @return the new connexion initializd <b>but not opened</b>. + */ + C newConnection(VCSConnexionMode mode, VCSConfig config); + } Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java 2008-04-04 21:14:37 UTC (rev 345) @@ -0,0 +1,88 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 org.codelutin.vcs.util; + +import org.codelutin.vcs.ConnectionState; +import org.codelutin.vcs.VCSConnexion; +import org.codelutin.vcs.VCSConnexionMode; + +import java.io.File; +import java.net.URI; +import java.util.Map; + +/** @author chemit */ +public abstract class AbstractVCSConnexion implements VCSConnexion { + + public static final String OPTION_LOGIN = "login"; + public static final String OPTION_PASSWORD = "password"; + public static final String OPTION_PASSPHRASE = "passphrase"; + public static final String OPTION_KEY_FILE = "keyfile"; + + protected File localRoot; + protected URI remoteRoot; + protected VCSConnexionMode mode; + protected ConnectionState state; + + protected Map<String, String> options; + + public File getWorkingCopy() throws IllegalStateException { + checkInit(); + return localRoot; + } + + public URI getRemoteURI() throws IllegalStateException { + checkInit(); + return remoteRoot; + } + + public VCSConnexionMode getMode() throws IllegalStateException { + checkInit(); + return mode; + } + + public Map<String, String> getOptions() throws IllegalStateException { + checkInit(); + return options; + } + + public boolean isOpen() throws IllegalStateException { + checkInit(); + return !hasFailed() && state == ConnectionState.ON_LINE; + } + + public boolean isClosed() throws IllegalStateException { + checkInit(); + return !hasFailed() && state != ConnectionState.ON_LINE; + } + + public boolean hasFailed() throws IllegalStateException { + checkInit(); + return state == ConnectionState.ERROR; + } + + protected void checkInit() throws IllegalStateException { + if (state == null) { + throw new IllegalStateException("connexion was not init"); + } + } + + protected void checkOpen() throws IllegalStateException { + checkInit(); + if (!isOpen()) { + throw new IllegalStateException("connexion was not init"); + } + } + +} Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java 2008-04-04 21:14:37 UTC (rev 345) @@ -52,12 +52,13 @@ /** * FilenameFilter to detect all files in a vcs working copy all files and directories that must be handled by vcs * - * @see org.codelutin.vcs.VCSHandler#getVersionnableFilenameFilter() + * @see VCSHandler#getVersionnableFilenameFilter() */ protected final FilenameFilter versionnableFilenameFilter; protected final FileFilter versionnableFileFilter; protected final String confLocalDirName; protected final String confLocalEntriesFilename; + protected final VCSConfig config; protected ListenerSet<VCSHandlerEventListener> listeners = new ListenerSet<VCSHandlerEventListener>(); Added: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSConnexion.java (rev 0) +++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSConnexion.java 2008-04-04 21:14:37 UTC (rev 345) @@ -0,0 +1,34 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 org.codelutin.vcs; + +import org.codelutin.vcs.util.AbstractVCSConnexion; + +/** @author chemit */ +public class CVSConnexion extends AbstractVCSConnexion { + + public void init(VCSConfig config, VCSHandler handler) { + } + + @Override + public void close() throws IllegalStateException { + checkInit(); + } + + @Override + public void open() throws IllegalStateException { + checkInit(); + } +} \ No newline at end of file Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java 2008-04-04 21:14:37 UTC (rev 345) @@ -18,7 +18,7 @@ import org.codelutin.vcs.impl.cvs.CVSHelper; /** @author chemit */ -public class CVSHandlerProvider implements VCSHandlerProvider<CVSHandler> { +public class CVSHandlerProvider implements VCSHandlerProvider<CVSHandler, CVSConnexion> { public String getName() { return "CVS"; @@ -28,4 +28,8 @@ CVSHelper.setConfig(config); return new CVSHandler(config); } + + public CVSConnexion newConnection(VCSConnexionMode mode, VCSConfig config) { + return null; + } } \ No newline at end of file Deleted: trunk/lutinvcs/lutinvcs-provider-cvs/src/test/java/org/codelutin/vcs/impl/cvs/CVSHandlerTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-cvs/src/test/java/org/codelutin/vcs/impl/cvs/CVSHandlerTest.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-provider-cvs/src/test/java/org/codelutin/vcs/impl/cvs/CVSHandlerTest.java 2008-04-04 21:14:37 UTC (rev 345) @@ -1,16 +0,0 @@ -package org.codelutin.vcs.impl.cvs; - -import org.codelutin.vcs.VCSHandlerTest; -import org.codelutin.vcs.VCSType; - -/** Test CVSHandler */ -class CVSHandlerTest extends VCSHandlerTest { - - protected void setUpVars() { - vcsType = VCSType.CVS; - super.setUpVars(); - } - - // if you don't want to execute some incompatible test just override them - -} \ No newline at end of file Added: trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockConnexion.java (rev 0) +++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockConnexion.java 2008-04-04 21:14:37 UTC (rev 345) @@ -0,0 +1,37 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 org.codelutin.vcs; + +import org.codelutin.vcs.util.AbstractVCSConnexion; + +/** @author chemit */ +public class MockConnexion extends AbstractVCSConnexion { + + public void init(VCSConfig config, VCSHandler handler) { + state = ConnectionState.INIT; + } + + @Override + public void close() throws IllegalStateException { + checkInit(); + } + + @Override + public void open() throws IllegalStateException { + checkInit(); + state = ConnectionState.INIT; + } + +} \ No newline at end of file Modified: trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockHandlerProvider.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockHandlerProvider.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockHandlerProvider.java 2008-04-04 21:14:37 UTC (rev 345) @@ -17,7 +17,7 @@ import org.codelutin.vcs.impl.mock.MockVCSHandler; /** @author chemit */ -public class MockHandlerProvider implements VCSHandlerProvider<MockVCSHandler> { +public class MockHandlerProvider implements VCSHandlerProvider<MockVCSHandler, MockConnexion> { public String getName() { return "MOCK"; @@ -26,4 +26,8 @@ public MockVCSHandler newInstance(VCSConfig config) { return new MockVCSHandler(config); } + + public MockConnexion newConnection(VCSConnexionMode mode, VCSConfig config) { + return null; + } } \ No newline at end of file Added: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNConnexion.java (rev 0) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNConnexion.java 2008-04-04 21:14:37 UTC (rev 345) @@ -0,0 +1,38 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 org.codelutin.vcs; + +import org.codelutin.vcs.util.AbstractVCSConnexion; + +/** @author chemit */ +public class SVNConnexion extends AbstractVCSConnexion { + + public void init(VCSConfig config, VCSHandler handler) { + state = null; + } + + @Override + public void close() throws IllegalStateException { + checkInit(); + if (!isOpen()) { + return; + } + } + + @Override + public void open() throws IllegalStateException { + checkInit(); + } +} Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNHandlerProvider.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNHandlerProvider.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNHandlerProvider.java 2008-04-04 21:14:37 UTC (rev 345) @@ -15,9 +15,10 @@ package org.codelutin.vcs; import org.codelutin.vcs.impl.svn.SVNHandler; +import org.codelutin.vcs.util.AbstractVCSConnexion; /** @author chemit */ -public class SVNHandlerProvider implements VCSHandlerProvider<SVNHandler> { +public class SVNHandlerProvider implements VCSHandlerProvider<SVNHandler, AbstractVCSConnexion> { public String getName() { return "SVN"; } @@ -25,4 +26,8 @@ public SVNHandler newInstance(VCSConfig config) { return new SVNHandler(config); } + + public AbstractVCSConnexion newConnection(VCSConnexionMode mode, VCSConfig config) { + return null; + } } Deleted: trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNHandlerTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNHandlerTest.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNHandlerTest.java 2008-04-04 21:14:37 UTC (rev 345) @@ -1,22 +0,0 @@ -package org.codelutin.vcs.impl.svn; - -import org.codelutin.vcs.VCSHandlerTest; -import org.codelutin.vcs.VCSType; - -/** - * Test SVNHandler - * <p/> - * <br/> - * This test use junit_SVN.properties to load vcs configuration - * Please check everything is ok inside it before lanching test. - */ -public class SVNHandlerTest extends VCSHandlerTest { - - protected void setUpVars() { - vcsType = VCSType.SVN; - super.setUpVars(); - } - - // if you don't want to execute some incompatible test just override them - -} \ No newline at end of file Deleted: trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNLogTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNLogTest.java 2008-04-04 20:10:54 UTC (rev 344) +++ trunk/lutinvcs/lutinvcs-provider-svn/src/test/java/org/codelutin/vcs/impl/svn/SVNLogTest.java 2008-04-04 21:14:37 UTC (rev 345) @@ -1,338 +0,0 @@ -package org.codelutin.vcs.impl.svn; - -import junit.framework.Assert; -import org.codelutin.vcs.MethodTest; -import org.codelutin.vcs.VCSException; -import org.codelutin.vcs.VCSLocalData; -import org.codelutin.vcs.VCSLocalDataContext; -import org.codelutin.vcs.VCSRuntimeException; -import org.codelutin.vcs.VCSTest; -import static org.codelutin.vcs.VCSType.SVN; -import org.tmatesoft.svn.core.SVNLogEntry; -import org.tmatesoft.svn.core.wc.SVNRevision; - -import java.io.File; -import java.util.List; - -public class SVNLogTest extends VCSTest { - static protected int start, last; - - static protected int[] interval; - - static protected SVNHandler svnhandler; - - static protected VCSLocalDataContext context; - - protected void setUpVars() { - VCSTest.vcsType = SVN; - VCSTest.resetConfiguration = true; - } - - @Override - protected void initConfig() throws Exception { - super.initConfig(); - - context = new VCSLocalDataContext(getLocalDatabaseFile()); - - // this is specific SVN test - Assert.assertTrue(VCSTest.handler instanceof SVNHandler); - svnhandler = (SVNHandler) VCSTest.handler; - - // init VCS (create remote repo + create working copy) - initVCS(); - - // add 4 files to repository - setCommand(0, 4, "add with commit"); - list = context.create(VCSLocalData.FILE, interval); - - VCSTest.handler.add(list, VCSLocalData.FILE.getCommitMessage("add", this)); - - } - - protected void tearDownVars() throws Exception { - VCSTest.resetConfiguration = null; - VCSTest.vcsType = null; - cleanAfterAll(); - } - - // ///////////////////////////////////////////////////////////////////////// - // / Demarrage du scenario - // ///////////////////////////////////////////////////////////////////////// - - List<File> list; - - @MethodTest - public void testLog() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) left on local and remote - setCommand(0, 3, "log"); - list = context.getFile(VCSLocalData.FILE, interval); - - File f = list.get(0); - - List<SVNLogEntry> logEntries = svnhandler.getLog(SVNRevision.WORKING, - SVNRevision.HEAD, f); - - // we just have one revision on this file - Assert.assertEquals(0, logEntries.size()); - - for (SVNLogEntry logEntry : logEntries) { - System.out.println("logEntry " + logEntry.getAuthor() + " : Rev " - + logEntry.getRevision() + ", Msg '" - + logEntry.getMessage() + "' "); - } - SVNRevision revision1 = svnhandler.getRevision(f); - - System.out.println("==== Revision for file " + f + "(before all) : " - + revision1); - // modify file - modifyFile(f, 20); - - // commit it - VCSTest.handler.commit(this.getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage( - "modif One", this)); - System.out.println("==== Revision for file " + f + "(after commit) : " - + svnhandler.getRevision(f)); - - logEntries = svnhandler - .getLog(SVNRevision.WORKING, SVNRevision.HEAD, f); - - // we just have always no revision for this file since working - // copy is last one - Assert.assertEquals(0, logEntries.size()); - - // go back to first revision - svnhandler.update(f, revision1); - - System.out.println("==== Revision for file " + f + "(" - + svnhandler.getRevision(f) + ") after going back to revision " - + revision1); - - logEntries = svnhandler - .getLog(SVNRevision.WORKING, SVNRevision.HEAD, f); - - // we just have one revision for this file (the last commit) - Assert.assertEquals(1, logEntries.size()); - for (SVNLogEntry logEntry : logEntries) { - System.out.println("logEntry " + logEntry.getAuthor() + " : Rev " - + logEntry.getRevision() + ", Msg '" - + logEntry.getMessage() + "' "); - } - - // a non existing file have no logs of course.... - File file = new File(getLocalDatabaseFile(), "nonExistingFile"); - - logEntries = svnhandler.getLog(SVNRevision.WORKING, SVNRevision.HEAD, - file); - Assert.assertEquals(0, logEntries.size()); - - try { - // now file exists, but still can not have some log entries since - // it is not versionned - file.createNewFile(); - logEntries = svnhandler.getLog(SVNRevision.WORKING, - SVNRevision.HEAD, file); - Assert.assertEquals(0, logEntries.size()); - } finally { - file.delete(); - } - } - - @MethodTest - public void testGetChangeLog() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) left on local and remote - setCommand(0, 3, "changeLog"); - list = context.getFile(VCSLocalData.FILE, interval); - - File f = list.get(0); - SVNRevision revision1 = svnhandler.getRevision(f); - - System.out.println("==== Revision for file " + f + "(" + revision1 - + ") at init "); - - // this file hase two revision and on local we are on first revision - Assert.assertFalse(VCSTest.handler.isUpToDate(f)); - - List<SVNLogEntry> entries = svnhandler.getLog(SVNRevision.WORKING, - SVNRevision.HEAD, f); - - Assert.assertEquals(1, entries.size()); - - for (SVNLogEntry logEntry : entries) { - System.out.println("changeLogEntry " + logEntry.getAuthor() - + " : Rev " + logEntry.getRevision() + ", Msg '" - + logEntry.getMessage() + "' "); - } - - String changeLog; - changeLog = svnhandler.getChangeLog(f); - System.out.println("change log for file " + f + "\n" + changeLog); - - // update to head revision - svnhandler.update(f, SVNRevision.HEAD); - - Assert.assertTrue(VCSTest.handler.isUpToDate(f)); - - SVNRevision newRevision = svnhandler.getRevision(f); - - Assert.assertTrue(revision1.getNumber() < newRevision.getNumber()); - - entries = svnhandler.getLog(SVNRevision.WORKING, SVNRevision.HEAD, f); - - // should have no log entries since we have on local the last version - Assert.assertEquals(0, entries.size()); - - // since there no revision between working revision and remote revision - Assert.assertNull(svnhandler.getChangeLog(f)); - - // add a another revision - modifyFile(f, 40); - - VCSTest.handler.commit(getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage("add a " - + "second revision", this)); - - // go back to first revision - svnhandler.update(f, revision1); - - entries = svnhandler.getLog(SVNRevision.WORKING, SVNRevision.HEAD, f); - - Assert.assertEquals(2, entries.size()); - - changeLog = svnhandler.getChangeLog(f); - System.out.println("change log for file (2 entries) : " + f + "\n" - + changeLog); - Assert.assertTrue(changeLog.contains("add a second revision")); - - // go back to first revision - svnhandler.update(f, revision1); - - // a non existing file have no logs of course.... - File file = new File(getLocalDatabaseFile(), "nonExistingFile"); - - changeLog = svnhandler.getChangeLog(file); - Assert.assertNull(changeLog); - - try { - // now file exists, but still can not have some log entries since - // it is not versionned - file.createNewFile(); - changeLog = svnhandler.getChangeLog(file); - Assert.assertNull(changeLog); - } finally { - file.delete(); - } - } - - @MethodTest - public void testGetDiff() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) - // left on local and remote - setCommand(0, 3, "getDiff"); - list = context.getFile(VCSLocalData.FILE, interval); - - File f = list.get(0); - - // cas limites - try { - VCSTest.handler.getDiff(null); - Assert.fail(); - } catch (VCSRuntimeException e) { - Assert.assertTrue(true); - } - - // a non existing file have no logs of course.... - File file = new File(getLocalDatabaseFile(), "nonExistingFile"); - - try { - VCSTest.handler.getDiff(file); - Assert.fail(); - } catch (VCSException e) { - Assert.assertTrue(true); - } - - try { - // now file exists, but still can not have some log entries - // since it is not versionned - file.createNewFile(); - VCSTest.handler.getDiff(file); - Assert.fail(); - } catch (VCSException e) { - Assert.assertTrue(true); - } finally { - file.delete(); - } - - SVNRevision revision1 = svnhandler.getRevision(f); - - System.out.println("==== Revision for file " + f + "(" + revision1 - + ") at init "); - - String diff = VCSTest.handler.getDiff(f); - - System.out.println(" get diff for file " + f + " result : \n" + diff); - - VCSTest.handler.update(f); - - Object revision2 = VCSTest.handler.getRevision(f); - - // modify file - modifyFile(f, 43, 'b'); - - VCSTest.handler.commit(getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage("second " - + "commit with more as", this)); - - // go back to first revision - VCSTest.handler.update(f, revision1); - - String diff2 = VCSTest.handler.getDiff(f); - - Assert.assertNotSame(diff, diff2); - - // we should have another diff - System.out.println(" get diff for file " + f + " result : \n" + diff2); - - VCSTest.handler.update(f, revision2); - - String diff3 = VCSTest.handler.getDiff(f); - - Assert.assertNotSame(diff3, diff2); - Assert.assertNotSame(diff, diff3); - - // we should have another diff - System.out.println(" get diff for file " + f + " result : \n" + diff3); - } - - // ///////////////////////////////////////////////////////////////////////// - // / methodes utiles - // ///////////////////////////////////////////////////////////////////////// - - public void cleanAfterAll() throws Exception { - - // delete remote directory - VCSTest.handler.deleteRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("deldir remote", - this), ""); - - // delete local working copy - VCSTest.handler.deleteWorkingCopy(); - - // assert local directory does not exists any longer - Assert.assertFalse(getLocalDatabaseFile().exists()); - - } - - protected void setCommand(int start, int last, String command) { - if (!(start == SVNLogTest.start && last == SVNLogTest.last)) { - SVNLogTest.start = start; - SVNLogTest.last = last; - SVNLogTest.interval = context.getIndex(start, last); - } - - VCSTest.log.info("[" + command + "] on interval [" + SVNLogTest.start + "," - + SVNLogTest.last + "]"); - } -}
participants (1)
-
tchemit@users.labs.libre-entreprise.org