Buix-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- 1440 discussions
r359 - in trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs: . util
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
05 Apr '08
Author: tchemit
Date: 2008-04-05 20:36:34 +0000 (Sat, 05 Apr 2008)
New Revision: 359
Modified:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandler.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java
Log:
refactor PRovider, Handler and Connexion
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandler.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandler.java 2008-04-05 20:36:07 UTC (rev 358)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandler.java 2008-04-05 20:36:34 UTC (rev 359)
@@ -24,7 +24,6 @@
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Collection;
-import java.util.EnumSet;
import java.util.List;
/**
@@ -33,38 +32,32 @@
* @author chemit
*/
-public interface VCSHandler {
+public interface VCSHandler<C extends VCSConnexion> {
- /** @return the location to local working copy */
- File getLocalDatabasePath();
-
/**
* init working copy, says if it is the first we use it it, we will checkout
* the databaseDirectory directory
*
+ * @param connexion vcs connexion to use
* @throws VCSException if any exception while init
*/
- void initWorkingCopy() throws VCSException;
+ void initWorkingCopy(C connexion) throws VCSException;
- /** delete the local working copy with all his files */
- void deleteWorkingCopy();
+ /**
+ * delete the local working copy with all his files
+ *
+ * @param connexion vcs connexion to use
+ */
+ void deleteWorkingCopy(C connexion);
- /** @return the complete remote url to acces repository */
- String getRemoteUrl();
-
- /** @return the config used by this handler */
- VCSConfig getConfig();
-
/**
- * @return a
- * <code>FilenameFilter<code> to detect all files and directories in a vcs working copy that
+ * @return a <code>FilenameFilter<code> to detect all files and directories in a vcs working copy that
* must be handled by vcs
*/
FilenameFilter getVersionnableFilenameFilter();
/**
- * @return a
- * <code>FileFilter<code> to detect all files and directories in a vcs working copy that
+ * @return a <code>FileFilter<code> to detect all files and directories in a vcs working copy that
* must be handled by vcs
*/
FileFilter getVersionnableFileFilter();
@@ -82,174 +75,190 @@
*/
String getConfLocalEntriesFilename();
- VCSState getState(File fileState, Collection tmp) throws VCSException;
+ VCSState getState(C connexion, File file, Collection tmp) throws VCSException;
- VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException;
+ VCSState getState(C connexion, File file, Collection tmp, boolean noremote) throws VCSException;
/**
- * @param file file to test
+ * @param connexion vcs connexion to use
+ * @param file file to test
* @return <code>true</code> if <code>file</code> is on remote
* repository, <code>false</code> otherwise.
*/
- boolean isOnRemote(File file);
+ boolean isOnRemote(C connexion, File file);
/**
- * @param file file to test
+ * @param connexion vcs connexion to use
+ * @param file file to test
* @return <code>true</code> if file is uptodate,<code>false</code>
* otherwise.
* @throws VCSException if any exception while operation
*/
- boolean isUpToDate(File file) throws VCSException;
+ boolean isUpToDate(C connexion, File file) throws VCSException;
/**
- * @param file file to test
+ * @param connexion vcs connexion to use
+ * @param file file to test
* @return <code>true</code> if file is handled by VCS,<code>false</code>
* otherwise.
*/
- boolean isVersionnableFile(File file);
+ boolean isVersionnableFile(C connexion, File file);
/**
* add on remote repository somes directories
*
+ * @param connexion vcs connexion to use
* @param commitMessage commit message
* @param dirNames names of the directories to create on remote repository (could
* used multi-level directories)
* @throws VCSException if any exception while operation
*/
- void makeRemoteDir(String commitMessage, String... dirNames)
+ void makeRemoteDir(C connexion, String commitMessage, String... dirNames)
throws VCSException;
/**
* delete on remote repository somes directories
*
+ * @param connexion vcs connexion to use
* @param commitMessage commit message
* @param dirNames names of the directories to delete on remote repository (could
* used multi-level directories)
* @throws VCSException if any exception while operation
*/
- void deleteRemoteDir(String commitMessage, String... dirNames)
+ void deleteRemoteDir(C connexion, String commitMessage, String... dirNames)
throws VCSException;
/**
* add a list of files into repository
*
- * @param files files to add
- * @param msg message for VCS commit, if <code>null</code> then no commit
- * is performed
+ * @param connexion vcs connexion to use
+ * @param files files to add
+ * @param msg message for VCS commit, if <code>null</code> then no commit
+ * is performed
* @return revision of the operation
* @throws VCSException if any exception while operation
*/
- long add(List<File> files, String msg) throws VCSException;
+ long add(C connexion, List<File> files, String msg) throws VCSException;
// void add(File file, String msg) throws VCSException;
/**
* delete a list of files from repository
*
- * @param files files to delete
- * @param msg message for VCS commit, if <code>null</code> then no commit
- * is performed
+ * @param connexion vcs connexion to use
+ * @param files files to delete
+ * @param msg message for VCS commit, if <code>null</code> then no commit
+ * is performed
* @throws VCSException if any exception while operation
*/
- void delete(List<File> files, String msg) throws VCSException;
+ void delete(C connexion, List<File> files, String msg) throws VCSException;
/**
* revert a list of files from repository
*
- * @param files files to revert
+ * @param connexion vcs connexion to use
+ * @param files files to revert
* @throws VCSException if any exception while operation
*/
- void revert(List<File> files) throws VCSException;
+ void revert(C connexion, List<File> files) throws VCSException;
/**
* commit a list of files into repository
*
- * @param files files to commit
- * @param msg message for VCS commit
+ * @param connexion vcs connexion to use
+ * @param files files to commit
+ * @param msg message for VCS commit
* @return revision of the operation
* @throws VCSException if any exception while operation
*/
- long commit(List<File> files, String msg) throws VCSException;
+ long commit(C connexion, List<File> files, String msg) throws VCSException;
/**
* update a file to repository to a certain revision
*
- * @param file file to update
- * @param revision object representing a revision for the current VCS
+ * @param connexion vcs connexion to use
+ * @param file file to update
+ * @param revision object representing a revision for the current VCS
* @throws VCSException if any exception while operation
*/
- void update(File file, Object revision) throws VCSException;
+ void update(C connexion, File file, Object revision) throws VCSException;
/**
* update a file to repository
*
- * @param file file to update
+ * @param connexion vcs connexion to use
+ * @param file file to update
* @throws VCSException if any exception while operation
*/
- void update(File file) throws VCSException;
+ void update(C connexion, File file) throws VCSException;
/**
* checkout a module from repository to a local file
*
- * @param destDir local file where to checkout
- * @param module module's name to checkout
- * @param recurse flag to say to recurse checkout or not.
+ * @param connexion vcs connexion to use
+ * @param destDir local file where to checkout
+ * @param module module's name to checkout
+ * @param recurse flag to say to recurse checkout or not.
* @throws VCSException if any exception while operation
*/
- void checkout(File destDir, String module, boolean recurse)
- throws VCSException;
+ void checkout(C connexion, File destDir, String module, boolean recurse) throws VCSException;
- void checkoutFile(File destDir, String module) throws VCSException;
+ void checkoutFile(C connexion, File destDir, String module) throws VCSException;
- long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException;
+ long checkoutOnlyTheDirectory(C connexion, File root, Object revision) throws VCSException;
/**
* TODO This is not the good place : VCS != Storage
*
+ * @param connexion vcs connexion to use
* @param directory directory to treate
* @return TODO
* @throws VCSException TODO
*/
- List<String> getRemoteStorageNames(File directory) throws VCSException;
+ List<String> getRemoteStorageNames(C connexion, File directory) throws VCSException;
/**
* TODO This is not the good place : VCS != Storage
*
+ * @param connexion vcs connexion to use
* @param directory directory to treate
* @return TODO
*/
- List<String> getLocalStorageNames(File directory);
+ List<String> getLocalStorageNames(C connexion, File directory);
/**
- * @param f local file to treate
+ * @param connexion vcs connexion to use
+ * @param f local file to treate
* @return current local revision of a file
* @throws VCSException TODO
*/
- Object getRevision(File f) throws VCSException;
+ Object getRevision(C connexion, File f) throws VCSException;
/**
* Obtain the list of log entries for the file
*
+ * @param connexion vcs connexion to use
* @param startRevision TODO
* @param endRevision TODO
* @param file file to treate
* @return list of log entries for this file between two revisions
* @throws VCSException if any exception while grabbing infos
*/
- List getLog(Object startRevision, Object endRevision, File file)
+ List getLog(C connexion, Object startRevision, Object endRevision, File file)
throws VCSException;
/**
* obtain the content of a file for a specific revision
*
- * @param file file to obtain
- * @param revision revision treated
+ * @param connexion vcs connexion to use
+ * @param file file to obtain
+ * @param revision revision treated
* @return the content of the file on repository for the specific revision
* passed as arguement.
* @throws VCSException if any exception while operation
* @throws java.io.IOException TODO
*/
- String getFileContent(File file, Object revision) throws VCSException, IOException;
+ String getFileContent(C connexion, File file, Object revision) throws VCSException, IOException;
/**
* Build the changelog for <code>file</code> from current revision of this
@@ -263,19 +272,21 @@
* <li>commit message</li>
* </ul>
*
- * @param file file to treate
+ * @param connexion vcs connexion to use
+ * @param file file to treate
* @return a string representation of change log for the local file to the
* head ?
* @throws VCSException if any exception while building changelog
*/
- String getChangeLog(File file) throws VCSException;
+ String getChangeLog(C connexion, File file) throws VCSException;
/**
* Generate in the ouputstream the diff between the current revision of the
* local file against headest revision on repository. <br>
* If file is uptodate, then does nothing.
*
- * @param file the file to treate
+ * @param connexion vcs connexion to use
+ * @param file the file to treate
* @return the diff
* @throws VCSException inf any exception while building diff, such as :
* <ul>
@@ -286,7 +297,7 @@
* </ul>
* @throws java.io.IOException if io problem with streams
*/
- String getDiff(File file) throws VCSException, IOException;
+ String getDiff(C connexion, File file) throws VCSException, IOException;
/**
* Generate in the ouputstream the diff between the current revision of the
@@ -294,6 +305,7 @@
* repository. <br>
* If file is uptodate, then does nothing.
*
+ * @param connexion vcs connexion to use
* @param file the file to treate
* @param againstRevision the against revision to use
* @return the diff
@@ -306,28 +318,9 @@
* </ul>
* @throws java.io.IOException if problem with streams
*/
- String getDiff(File file, Object againstRevision) throws VCSException, IOException;
+ String getDiff(C connexion, File file, Object againstRevision) throws VCSException, IOException;
- /**
- * test if connection is ok
- *
- * @throws VCSException if any problem
- */
- void testConnection() throws VCSException;
- boolean hasProtocoleChanged() throws VCSException;
+ boolean hasProtocoleChanged(C connexion) throws VCSException;
- void addVCSHandlerEventListener(VCSHandlerEventListener l);
-
- void removeVCSHandlerEventListener(VCSHandlerEventListener l);
-
- void open();
-
- void close();
-
- EnumSet<VCSAction> getAuthorizedActions();
-
- public boolean isConnected();
-
- public boolean hasWriteAccess();
}
\ No newline at end of file
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-05 20:36:07 UTC (rev 358)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-05 20:36:34 UTC (rev 359)
@@ -14,8 +14,6 @@
*/
package org.codelutin.vcs;
-import java.util.List;
-
/**
* The contract to be realized to provide vcs communication.
* <p/>
@@ -25,36 +23,30 @@
* @see VCSHandler
* @see VCSConnexion
*/
-public interface VCSProvider<H extends VCSHandler, C extends VCSConnexion> {
+public interface VCSProvider<C extends VCSConnexion, H extends VCSHandler<C>> {
/** @return the identifier of the vcs provider (eg SVN, CVS, MOCK) */
String getName();
- /** @return list of known connexions. */
- List<C> getConnexions();
-
/**
* return a new VCSHandler instance for given config.
*
* @return the cached instance of handler
- * @throws IllegalStateException if handler was not init via {@link #newInstance(VCSConfig)}
+ * @throws IllegalStateException if provider was not init via {@link #init()}
*/
H getHandler() throws IllegalStateException;
- /**
- * return a new VCSHandler instance for given config.
- *
- * @param config svn handler config
- * @return the new instance
- * @throws IllegalStateException if any pb while init handler
- */
- H newInstance(VCSConfig config) throws IllegalStateException;
+ /** init the provider */
+ void init();
/**
+ * Instanciate an new connexion for a given config, and init it.
+ *
* @param mode the mode required
* @param config the config to be used
* @return the new connexion initializd <b>but not opened</b>.
+ * @throws IllegalStateException if provider was not init via {@link #init()}
*/
- C newConnection(VCSConnexionMode mode, VCSConfig config);
+ C newConnection(VCSConnexionMode mode, VCSConnexionConfig config) throws IllegalStateException;
}
Modified: 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 2008-04-05 20:36:07 UTC (rev 358)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java 2008-04-05 20:36:34 UTC (rev 359)
@@ -14,29 +14,62 @@
*/
package org.codelutin.vcs.util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.util.ListenerSet;
import org.codelutin.vcs.ConnectionState;
+import org.codelutin.vcs.VCSAction;
import org.codelutin.vcs.VCSConnexion;
+import org.codelutin.vcs.VCSConnexionConfig;
+import org.codelutin.vcs.VCSConnexionEvent;
+import org.codelutin.vcs.VCSConnexionEvent.Type;
+import org.codelutin.vcs.VCSConnexionEventListener;
import org.codelutin.vcs.VCSConnexionMode;
+import org.codelutin.vcs.VCSException;
+import org.codelutin.vcs.VCSHandler;
+import org.codelutin.vcs.VCSProvider;
+import org.codelutin.vcs.VCSState;
import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
import java.net.URI;
-import java.util.Map;
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.List;
/** @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";
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static protected final Log log = LogFactory.getLog(AbstractVCSConnexion.class);
protected File localRoot;
protected URI remoteRoot;
protected VCSConnexionMode mode;
protected ConnectionState state;
- protected Map<String, String> options;
+ protected VCSConnexionConfig config;
+ protected VCSProvider<AbstractVCSConnexion, ?> provider;
+
+ protected ListenerSet<VCSConnexionEventListener> listeners = new ListenerSet<VCSConnexionEventListener>();
+
+ @SuppressWarnings({"unchecked"})
+ protected AbstractVCSConnexion(VCSConnexionMode mode, VCSProvider provider) {
+ this.mode = mode;
+ this.provider = provider;
+ }
+
+ public VCSHandler<AbstractVCSConnexion> getHandler() throws IllegalStateException {
+ return getProvider().getHandler();
+ }
+
+ public VCSProvider<AbstractVCSConnexion, ?> getProvider() {
+ return provider;
+ }
+
public File getWorkingCopy() throws IllegalStateException {
checkInit();
return localRoot;
@@ -52,9 +85,8 @@
return mode;
}
- public Map<String, String> getOptions() throws IllegalStateException {
- checkInit();
- return options;
+ public VCSConnexionConfig getConfig() throws IllegalStateException {
+ return config;
}
public boolean isOpen() throws IllegalStateException {
@@ -72,6 +104,180 @@
return state == ConnectionState.ERROR;
}
+ public void addVCSConnexionEventListener(VCSConnexionEventListener l) {
+ listeners.add(l);
+ }
+
+ public void removeVCSConnexionEventListener(VCSConnexionEventListener l) {
+ listeners.remove(l);
+ }
+
+ public void initWorkingCopy() throws VCSException {
+ getHandler().initWorkingCopy(this);
+ }
+
+ public void deleteWorkingCopy() {
+ getHandler().deleteWorkingCopy(this);
+ }
+
+ public FilenameFilter getVersionnableFilenameFilter() {
+ return getHandler().getVersionnableFilenameFilter();
+ }
+
+ public FileFilter getVersionnableFileFilter() {
+ return getHandler().getVersionnableFileFilter();
+ }
+
+ public String getConfLocalDirname() {
+ return getHandler().getConfLocalDirname();
+ }
+
+ public String getConfLocalEntriesFilename() {
+ return getHandler().getConfLocalEntriesFilename();
+ }
+
+ public VCSState getState(File fileState, Collection tmp) throws VCSException {
+ return getHandler().getState(this, fileState, tmp);
+ }
+
+ public VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException {
+ return getHandler().getState(this, file, tmp, noremote);
+ }
+
+ public boolean isOnRemote(File file) {
+ return getHandler().isOnRemote(this, file);
+ }
+
+ public boolean isUpToDate(File file) throws VCSException {
+ return getHandler().isUpToDate(this, file);
+ }
+
+ public boolean isVersionnableFile(File file) {
+ return getHandler().isVersionnableFile(this, file);
+ }
+
+ public void makeRemoteDir(String commitMessage, String... dirNames) throws VCSException {
+ getHandler().makeRemoteDir(this, commitMessage, dirNames);
+ }
+
+ public void deleteRemoteDir(String commitMessage, String... dirNames) throws VCSException {
+ getHandler().deleteRemoteDir(this, commitMessage, dirNames);
+ }
+
+ public long add(List<File> files, String msg) throws VCSException {
+ return getHandler().add(this, files, msg);
+ }
+
+ public void delete(List<File> files, String msg) throws VCSException {
+ getHandler().delete(this, files, msg);
+ }
+
+ public void revert(List<File> files) throws VCSException {
+ getHandler().revert(this, files);
+ }
+
+ public long commit(List<File> files, String msg) throws VCSException {
+ return getHandler().commit(this, files, msg);
+ }
+
+ public void update(File file, Object revision) throws VCSException {
+ getHandler().update(this, file, revision);
+ }
+
+ public void update(File file) throws VCSException {
+ getHandler().update(this, file);
+ }
+
+ public void checkout(File destDir, String module, boolean recurse) throws VCSException {
+ getHandler().checkout(this, destDir, module, recurse);
+ }
+
+ public void checkoutFile(File destDir, String module) throws VCSException {
+ getHandler().checkoutFile(this, destDir, module);
+ }
+
+ public long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException {
+ return getHandler().checkoutOnlyTheDirectory(this, root, revision);
+ }
+
+ public List<String> getRemoteStorageNames(File directory) throws VCSException {
+ return getHandler().getRemoteStorageNames(this, directory);
+ }
+
+ public List<String> getLocalStorageNames(File directory) {
+ return getHandler().getLocalStorageNames(this, directory);
+ }
+
+ public Object getRevision(File f) throws VCSException {
+ return getHandler().getRevision(this, f);
+ }
+
+ public List getLog(Object startRevision, Object endRevision, File file) throws VCSException {
+ return getHandler().getLog(this, startRevision, endRevision, file);
+ }
+
+ public String getFileContent(File file, Object revision) throws VCSException, IOException {
+ return getHandler().getFileContent(this, file, revision);
+ }
+
+ public String getChangeLog(File file) throws VCSException {
+ return getHandler().getChangeLog(this, file);
+ }
+
+ public String getDiff(File file) throws VCSException, IOException {
+ return getHandler().getDiff(this, file);
+ }
+
+ public String getDiff(File file, Object againstRevision) throws VCSException, IOException {
+ return getHandler().getDiff(this, file, againstRevision);
+ }
+
+ public boolean hasProtocoleChanged() throws VCSException {
+ return getHandler().hasProtocoleChanged(this);
+ }
+
+ /**
+ * Obtain the set of permitted vcs actions.
+ *
+ * @return the EnumSet of authorized action according to current vcs config
+ */
+ public EnumSet<VCSAction> getAuthorizedActions() {
+ boolean canWrite = hasWriteAccess();
+ EnumSet<VCSAction> result = EnumSet.noneOf(VCSAction.class);
+ for (VCSAction vcsAction : VCSAction.values()) {
+ if (!vcsAction.isWrite() || canWrite) {
+ result.add(vcsAction);
+ }
+ }
+ return result;
+ }
+
+ public boolean hasWriteAccess() {
+ return !getConfig().isUseSshConnexion() && getMode() != VCSConnexionMode.ANONYMOUS;
+ }
+
+ public void addVCSHandlerEventListener(VCSConnexionEventListener l) {
+ listeners.add(l);
+ }
+
+ public void removeVCSHandlerEventListener(VCSConnexionEventListener l) {
+ listeners.remove(l);
+ }
+
+ protected void fireOpen() {
+ VCSConnexionEvent e = new VCSConnexionEvent(this, Type.OPEN);
+ for (VCSConnexionEventListener l : listeners) {
+ l.open(e);
+ }
+ }
+
+ protected void fireClose() {
+ VCSConnexionEvent e = new VCSConnexionEvent(this, Type.CLOSE);
+ for (VCSConnexionEventListener l : listeners) {
+ l.close(e);
+ }
+ }
+
protected void checkInit() throws IllegalStateException {
if (state == null) {
throw new IllegalStateException("connexion was not init");
@@ -85,4 +291,5 @@
}
}
+
}
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-05 20:36:07 UTC (rev 358)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java 2008-04-05 20:36:34 UTC (rev 359)
@@ -21,15 +21,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import static org.codelutin.i18n.I18n._;
import org.codelutin.util.FileUtil;
-import org.codelutin.util.ListenerSet;
-import org.codelutin.vcs.VCSHandlerEvent.Type;
+import org.codelutin.vcs.VCSConnexion;
import org.codelutin.vcs.VCSHandler;
-import org.codelutin.vcs.VCSConfig;
-import org.codelutin.vcs.VCSHandlerEventListener;
-import org.codelutin.vcs.VCSHandlerEvent;
import org.codelutin.vcs.VCSRuntimeException;
-import org.codelutin.vcs.VCSAction;
+import org.codelutin.vcs.VCSTypeRepo;
import java.io.File;
import java.io.FileFilter;
@@ -37,14 +34,13 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.EnumSet;
/**
* abstract VCSHandler base with usefull methods that does not need vcs specific code.
*
* @author chemit
*/
-public abstract class AbstractVCSHandler implements VCSHandler {
+public abstract class AbstractVCSHandler<C extends VCSConnexion> implements VCSHandler<C> {
/** to use log facility, just put in your code: log.info(\"...\"); */
static protected final Log log = LogFactory.getLog(AbstractVCSHandler.class);
@@ -58,13 +54,13 @@
protected final FileFilter versionnableFileFilter;
protected final String confLocalDirName;
protected final String confLocalEntriesFilename;
+ public static final String LOCAL_SEP = File.separator;
+ public static final String LOCAL_SEP_PATTERN = "\\".equals(LOCAL_SEP) ?
+ LOCAL_SEP + LOCAL_SEP : LOCAL_SEP;
+ public static final String REMOTE_SEP = "/";
+ public static final String REMOTE_SEP_PATTERN = "/";
- protected final VCSConfig config;
-
- protected ListenerSet<VCSHandlerEventListener> listeners = new ListenerSet<VCSHandlerEventListener>();
-
- protected AbstractVCSHandler(VCSConfig config, final String vCSConfLocalDirName, String vCSConfLocalEntriesFilename) {
- this.config = config;
+ protected AbstractVCSHandler(final String vCSConfLocalDirName, String vCSConfLocalEntriesFilename) {
this.confLocalDirName = vCSConfLocalDirName;
this.confLocalEntriesFilename = vCSConfLocalEntriesFilename;
this.versionnableFilenameFilter = new FilenameFilter() {
@@ -77,24 +73,8 @@
return dir.isFile() || (!vCSConfLocalDirName.equals(dir.getName()) && !"CVS".equals(dir.getName()));
}
};
- fireInit();
}
- public VCSConfig getConfig() {
- return config;
- }
-
- public File getLocalDatabasePath() {
- return config.getLocalDatabasePath();
- }
-
- public void deleteWorkingCopy() {
- if (getLocalDatabasePath().exists()) {
- FileUtil.deleteRecursively(getLocalDatabasePath());
- getLocalDatabasePath().delete();
- }
- }
-
public FilenameFilter getVersionnableFilenameFilter() {
return versionnableFilenameFilter;
}
@@ -111,12 +91,19 @@
return confLocalEntriesFilename;
}
- public boolean isVersionnableFile(File file) {
+ public boolean isVersionnableFile(C connexion, File file) {
assertFileExists(file, "file is empty or non existant");
return !confLocalDirName.equalsIgnoreCase(file.getName());
}
- public List<String> getLocalStorageNames(File directory) {
+ public void deleteWorkingCopy(C connexion) {
+ if (connexion.getConfig().getLocalDatabasePath().exists()) {
+ FileUtil.deleteRecursively(connexion.getConfig().getLocalDatabasePath());
+ connexion.getConfig().getLocalDatabasePath().delete();
+ }
+ }
+
+ public List<String> getLocalStorageNames(C connexion, File directory) {
List<String> result = new ArrayList<String>();
if (directory.exists()) {
getFiles0(directory, result, "");
@@ -125,49 +112,24 @@
return result;
}
- public void addVCSHandlerEventListener(VCSHandlerEventListener l) {
- listeners.add(l);
- }
-
- public void removeVCSHandlerEventListener(VCSHandlerEventListener l) {
- listeners.remove(l);
- }
-
- public void open() {
- fireOpen();
- }
-
- public void close() {
- fireClose();
- }
-
- protected void fireInit() {
- VCSHandlerEvent e = new VCSHandlerEvent(this, Type.INIT);
- for (VCSHandlerEventListener l : listeners) {
- l.init(e);
+ public void doCheckoutDir(C connexion, File... dirs) {
+ for (File dir : dirs) {
+ try {
+ if (!dir.exists() || !isFileInWorkingCopy(dir, this, connexion, true)) {
+ checkoutOnlyTheDirectory(connexion, dir, null);
+ }
+ } catch (Exception eee) {
+ log.warn(_("lutinvcs.error.checkout.dir", dir), eee);
+ break;
+ }
}
}
- protected void fireOpen() {
- VCSHandlerEvent e = new VCSHandlerEvent(this, Type.OPEN);
- for (VCSHandlerEventListener l : listeners) {
- l.open(e);
- }
+ protected void assertFileExists(File file, String msg) {
+ if (file == null || !file.exists())
+ throw new VCSRuntimeException(msg + " (file passed : [" + file + "])");
}
- protected void fireClose() {
- VCSHandlerEvent e = new VCSHandlerEvent(this, Type.CLOSE);
- for (VCSHandlerEventListener l : listeners) {
- l.close(e);
- }
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- close();
- }
-
protected void getFiles0(File directory, List<String> result, String prefix) {
//TODO put the hardcored value in a property!!!
if (directory.getName().equals("data")) return;
@@ -183,32 +145,132 @@
}
}
- protected void assertFileExists(File file, String msg) {
- if (file == null || !file.exists())
- throw new VCSRuntimeException(msg + " (file passed : [" + file + "])");
+ public static boolean isFileInWorkingCopy(File parent, String name, VCSHandler handler, VCSConnexion connexion, boolean underVCS) {
+ if (parent == null || name == null)
+ throw new RuntimeException(AbstractVCSHandler.class.getName() + "#isFileInWorkingCopy can not be invoked with some null parameter but was. [" + parent + "," + name + "," +
+ handler + "]");
+ return isFileInWorkingCopy(new File(parent, name), handler, connexion, underVCS);
}
+ public static boolean isFileInWorkingCopy(File file, VCSHandler handler, VCSConnexion connexion, boolean underVCS) {
+ if (file == null || handler == null)
+ throw new RuntimeException(AbstractVCSHandler.class.getName() + "#isFileInWorkingCopy can not be invoked with some null parameter but was. [" + file + "," + handler + "]");
+ String rootPath = connexion.getConfig().getLocalDatabasePath().getAbsolutePath();
+ String localPath = file.getAbsolutePath();
+ if (localPath.startsWith(rootPath) && !underVCS) {
+ return true;
+ }
+ final File realDir = file.isDirectory() ? file : file.getParentFile();
+ return isFileInCheckedDir(realDir, handler);
+ }
+
+ public static boolean isFileInCheckedDir(File file, VCSHandler handler) {
+ if (file == null || handler == null)
+ throw new RuntimeException(AbstractVCSHandler.class.getName() + "#isFileInCheckedDir can not be invoked with some null parameter but was. [" + file + "," + handler + "]");
+ final File realDir = file.isDirectory() ? file : file.getParentFile();
+ return (new File(realDir, handler.getConfLocalDirname()).exists());
+
+ }
+
+ public static void assertFileInWC(File file, VCSHandler handler, VCSConnexion connexion) {
+ if (!isFileInWorkingCopy(file, handler, connexion, false))
+ throw new VCSRuntimeException("the file [" + file + "] is not in the working copy [" + connexion.getConfig().getLocalDatabasePath() + "]");
+ }
+
+ public static String getRemoteRelativePath(File f, VCSHandler handler, VCSConnexion connexion) {
+ if (!isFileInWorkingCopy(f, handler, connexion, false)) return null;
+ //System.out.println("file on vcs working copy : "+f);
+ String rootPath = connexion.getConfig().getLocalDatabasePath().getAbsolutePath();
+ String localPath = f.getAbsolutePath();
+ if (!localPath.startsWith(rootPath)) return null;
+ localPath = localPath.substring(rootPath.length() + 1);
+ return convertToRemoteName(localPath);
+ }
+
+ public static String getLocalRelativePath(String remoteRelativePath, VCSHandler handler, VCSConnexion connexion) {
+ String localPath = convertToLocalName(remoteRelativePath);
+ final File file = new File(connexion.getConfig().getLocalDatabasePath(), localPath);
+ if (!isFileInWorkingCopy(file, handler, connexion, false)) return null;
+ return localPath;
+ }
+
+ public static String convertToRemoteName(String txt) {
+ return txt.replaceAll(LOCAL_SEP_PATTERN, REMOTE_SEP);
+ }
+
+ public static String convertToLocalName(String txt) {
+ return txt.replaceAll(REMOTE_SEP_PATTERN, LOCAL_SEP);
+ }
+
/**
- * Obtain the set of permitted vcs actions.
- *
- * @return the EnumSet of authorized action according to current vcs config
+ * @param typeRepo the type of repo to used
+ * @param remotePath the unclean remote path to use
+ * @return the remote path from the old one according to given type repo
*/
- public EnumSet<VCSAction> getAuthorizedActions() {
- boolean canWrite = hasWriteAccess();
- EnumSet<VCSAction> result = EnumSet.noneOf(VCSAction.class);
- for (VCSAction vcsAction : VCSAction.values()) {
- if (!vcsAction.isWrite() || canWrite) {
- result.add(vcsAction);
- }
+ public static String getRemotePath(VCSTypeRepo typeRepo, String remotePath) {
+ String result = cleanRemotePath(remotePath);
+ switch (typeRepo) {
+ case BRANCH:
+ case TAG:
+ result = remotePath + '/' + typeRepo.getPath();
+ break;
+ case HEAD:
+ result = remotePath;
+ break;
}
return result;
}
- public boolean isConnected() {
- return getConfig().isConnected();
+ /**
+ * @param typeRepo the type of repo to use
+ * @param version the version to use
+ * @return the remoteDatabase according to type of repo and version
+ */
+ public static String getRemoteDatabase(VCSTypeRepo typeRepo, String version) {
+ String result = null;
+ switch (typeRepo) {
+ case BRANCH:
+ case TAG:
+ result = version;
+ break;
+ case HEAD:
+ result = VCSTypeRepo.HEAD.getPath();
+ break;
+ }
+ return result;
}
- public boolean hasWriteAccess() {
- return !getConfig().isReadOnly();
+ /**
+ * to clean a remote path from typeRepo suffix.
+ * <p/>
+ * For example, having a url svn://XXX/trunk then remove /trunk.
+ * <p/>
+ * Or if having svn://XXX/branches/YYY then remove /branches/YYY
+ * Or if having svn://XXX/tags/YYY then remove /tags/YYY
+ *
+ * @param remotePath the remote path to clean
+ * @return the cleaned remote path
+ */
+ public static String cleanRemotePath(String remotePath) {
+ int pos = remotePath.indexOf(VCSTypeRepo.BRANCH.getPath());
+ if (pos > -1) {
+ // found a branch
+ remotePath = remotePath.substring(0, pos - 1);
+ } else {
+ pos = remotePath.indexOf(VCSTypeRepo.HEAD.getPath());
+ if (pos > -1) {
+ // found a branch
+ remotePath = remotePath.substring(0, pos - 1);
+ } else {
+ pos = remotePath.indexOf(VCSTypeRepo.TAG.getPath());
+ if (pos > -1) {
+ // found a tag
+ remotePath = remotePath.substring(0, pos - 1);
+ } else {
+ // remote path was clean
+ }
+ }
+ }
+ return remotePath;
}
}
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java 2008-04-05 20:36:07 UTC (rev 358)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java 2008-04-05 20:36:34 UTC (rev 359)
@@ -14,70 +14,76 @@
*/
package org.codelutin.vcs.util;
-import org.codelutin.vcs.VCSConfig;
import org.codelutin.vcs.VCSConnexion;
+import org.codelutin.vcs.VCSConnexionConfig;
+import org.codelutin.vcs.VCSConnexionMode;
import org.codelutin.vcs.VCSHandler;
import org.codelutin.vcs.VCSProvider;
import java.lang.reflect.InvocationTargetException;
-import java.util.List;
/**
* base implementation of provider with a cached handler and list of connexions
*
* @author chemit
*/
-public abstract class AbstractVCSProvider<H extends VCSHandler, C extends VCSConnexion> implements VCSProvider<H, C> {
+public abstract class AbstractVCSProvider<C extends VCSConnexion, H extends VCSHandler<C>> implements VCSProvider<C, H> {
protected H handler;
- protected List<C> connexions;
-
protected final String name;
private final Class<H> handlerImpl;
+ private final Class<C> connexionImpl;
- protected AbstractVCSProvider(String name, Class<H> handlerImpl) {
+ protected AbstractVCSProvider(String name, Class<H> handlerImpl, Class<C> connexionImpl) {
this.name = name;
this.handlerImpl = handlerImpl;
+ this.connexionImpl = connexionImpl;
}
public final String getName() {
return name;
}
- public List<C> getConnexions() {
- if (connexions == null) {
- connexions = new java.util.ArrayList<C>();
- }
- return connexions;
- }
-
public H getHandler() throws IllegalStateException {
checkHandlerInit();
return handler;
}
- public H newInstance(VCSConfig config) throws IllegalStateException {
- if (handler != null) {
- return handler;
- }
+ public C newConnection(VCSConnexionMode mode, VCSConnexionConfig config) throws IllegalStateException {
+ checkHandlerInit();
try {
- return handlerImpl.getConstructor(VCSConfig.class).newInstance(config);
+ C connexion = connexionImpl.getConstructor(VCSConnexionMode.class, getClass()).newInstance(mode, this);
+ connexion.init(config);
+ return connexion;
} catch (InstantiationException e) {
- throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ throw new RuntimeException("could not instanciate connexion " + connexionImpl + " for reason " + e.getMessage());
} catch (IllegalAccessException e) {
- throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ throw new RuntimeException("could not instanciate connexion " + connexionImpl + " for reason " + e.getMessage());
} catch (InvocationTargetException e) {
- throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ throw new RuntimeException("could not instanciate connexion " + connexionImpl + " for reason " + e.getMessage());
} catch (NoSuchMethodException e) {
- throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ throw new RuntimeException("could not instanciate connexion " + connexionImpl + " for reason " + e.getMessage());
}
}
+ public void init() {
+ if (handler == null) {
+ try {
+ handler = handlerImpl.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ }
+ }
+ }
+
protected void checkHandlerInit() throws IllegalStateException {
if (handler == null) {
throw new IllegalStateException("handler was not init in " + this);
}
}
+
}
1
0
r358 - trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
05 Apr '08
Author: tchemit
Date: 2008-04-05 20:36:07 +0000 (Sat, 05 Apr 2008)
New Revision: 358
Modified:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSState.java
Log:
use VCSEntryLocation as property to VCSState
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSState.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSState.java 2008-04-05 20:35:25 UTC (rev 357)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSState.java 2008-04-05 20:36:07 UTC (rev 358)
@@ -30,7 +30,7 @@
* <br/>
* The only action for this state is to delete the file, nothing else.
*/
- UP_TO_DATE("uptodate", n_("lutinvcs.state.uptodate"), false, false, DELETE),
+ UP_TO_DATE("uptodate", n_("lutinvcs.state.uptodate"), VCSEntryLocation.ALL, DELETE),
/**
* when a local file matches a remote copy but not the latest one.
@@ -42,8 +42,7 @@
* <li>{@link VCSAction#CHANGELOG}</li>
* </ul>
*/
- OUT_OF_DATE("outofdate", n_("lutinvcs.state.outofdate"), false, true,
- UPDATE, DIFF, CHANGELOG),
+ OUT_OF_DATE("outofdate", n_("lutinvcs.state.outofdate"), VCSEntryLocation.REMOTE, UPDATE, DIFF, CHANGELOG),
/**
* when a local file does not matches his remote latest copy, but is based
@@ -56,8 +55,7 @@
* <li>{@link VCSAction#DIFF}</li>
* </ul>
*/
- MODIFIED("modified", n_("lutinvcs.state.modified"), true, false,
- COMMIT, OVERWRITE_AND_UPDATE, REVERT, DIFF),
+ MODIFIED("modified", n_("lutinvcs.state.modified"), VCSEntryLocation.LOCAL, COMMIT, OVERWRITE_AND_UPDATE, REVERT, DIFF),
/**
* when a local file does not match the working version remote copy and
@@ -71,9 +69,7 @@
* <li>{@link VCSAction#CHANGELOG}</li>
* </ul>
*/
- OUT_OF_DATE_AND_MODIFIED("outofdateAndModified",
- n_("lutinvcs.state.outofdateAndModified"), true, true,
- OVERWRITE_AND_UPDATE, REVERT, DIFF, CHANGELOG),
+ OUT_OF_DATE_AND_MODIFIED("outofdateAndModified", n_("lutinvcs.state.outofdateAndModified"), VCSEntryLocation.ALL, OVERWRITE_AND_UPDATE, REVERT, DIFF, CHANGELOG),
/**
* when a local file does not exist on remote repository.
@@ -82,7 +78,7 @@
* <li>{@link VCSAction#ADD}</li>
* </ul>
*/
- UNVERSIONNED("unversionned", n_("lutinvcs.state.unversionned"), true, false, ADD, REVERT),
+ UNVERSIONNED("unversionned", n_("lutinvcs.state.unversionned"), VCSEntryLocation.LOCAL, ADD, REVERT),
/**
* when a file exists on remote repository but not locally.
@@ -91,7 +87,7 @@
* <li>{@link VCSAction#UPDATE}</li>
* </ul>
*/
- MISSING("missing", n_("lutinvcs.state.missing"), false, true, UPDATE),
+ MISSING("missing", n_("lutinvcs.state.missing"), VCSEntryLocation.REMOTE, UPDATE),
/**
* when a file is unversionned or missing : this special and durty state
@@ -107,35 +103,34 @@
* <p/>
* </ul>
*/
- UNVERSIONNED_OR_MISSING("unversionnedOrMissing",
- n_("lutinvcs.state.unversionnedOrMissing"), true, true, ADD, UPDATE),
+ UNVERSIONNED_OR_MISSING("unversionnedOrMissing", n_("lutinvcs.state.unversionnedOrMissing"), VCSEntryLocation.LOCAL, ADD, UPDATE),
- REMOVED("removed", n_("lutinvcs.state.removed"), true, false, DELETE, REVERT),
+ REMOVED("removed", n_("lutinvcs.state.removed"), VCSEntryLocation.LOCAL, DELETE, REVERT),
/** to deal with other cases (...) */
- UNKNOWN("unknown", n_("lutinvcs.state.unknown"), true, false);
+ UNKNOWN("unknown", n_("lutinvcs.state.unknown"), null);
/** libelle to be used */
private final String libelle;
/** key of the state */
private final String key;
- /** flag to indicate if state is on a local file */
- private final boolean local;
- /** flag to indicate if state is on a remote file */
- private final boolean remote;
+
/** VCSAction associated with this state */
private final List<VCSAction> actions;
- VCSState(String key, String libelle, boolean local, boolean remote, VCSAction... actions) {
+ /** location of the state */
+ private VCSEntryLocation location;
+
+ VCSState(String key, String libelle, VCSEntryLocation location, VCSAction... actions) {
+ this.location = location;
this.libelle = libelle;
List<VCSAction> actions1 = new ArrayList<VCSAction>(Arrays.asList(actions));
// refresh action is enabled for all states
actions1.add(VCSAction.REFRESH);
this.actions = Collections.unmodifiableList(actions1);
this.key = key;
- this.local = local;
- this.remote = remote;
+
}
public String libelle() {
@@ -150,12 +145,16 @@
return key;
}
+ public VCSEntryLocation getLocation() {
+ return location;
+ }
+
public boolean isLocal() {
- return local;
+ return location != VCSEntryLocation.REMOTE;
}
public boolean isRemote() {
- return remote;
+ return location != VCSEntryLocation.LOCAL;
}
public boolean authorizeAction(VCSAction... actions) {
1
0
r357 - in trunk/lutinvcs: lutinvcs-api/src/main/java/org/codelutin/vcs lutinvcs-core/src/main/java/org/codelutin/vcs lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
05 Apr '08
Author: tchemit
Date: 2008-04-05 20:35:25 +0000 (Sat, 05 Apr 2008)
New Revision: 357
Removed:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java
Log:
delete old code
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java 2008-04-05 20:33:02 UTC (rev 356)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java 2008-04-05 20:35:25 UTC (rev 357)
@@ -1,60 +0,0 @@
-/**
- * # #% 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.io.Serializable;
-
-/** @author chemit */
-public interface VCSFileState extends Serializable {
-
- boolean existLocally();
-
- String getLocalPath();
-
- String getModuleName();
-
- String getModuleRelativeFileName();
-
- String[] getFileNamePath();
-
- String getRemotePath();
-
- VCSState getState();
-
- long getTimestamp();
-
- File getFile();
-
- String getChangeLog();
-
- Long getRev();
-
- VCSAction getAction();
-
- void resetState();
-
- boolean wasSynch();
-
- boolean isLocallySynch();
-
- void doSynch(VCSHandler handler, long timestamp);
-
- void doSynch(VCSHandler handler, long timestamp, boolean ifFileChanged);
-
- void setChangeLog(String changeLog);
-
- void setAction(VCSAction action);
-}
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java 2008-04-05 20:33:02 UTC (rev 356)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java 2008-04-05 20:35:25 UTC (rev 357)
@@ -1,23 +0,0 @@
-package org.codelutin.vcs;
-
-import javax.swing.JDialog;
-import java.util.List;
-
-/**
- * a VCSUIAction represents an action to realize on a file in working copy
- * or on remote repository with an possible ui interaction.
- * <p/>
- * This is the highest api level for vcs using
- * <p/>
- * The method {@link #doAction(JDialog, org.codelutin.vcs.VCSHandler , List)} fired the action
- * on a list of states
- */
-public interface VCSUIAction {
- /**
- * @param dialog the dialog where action was asked
- * @param handler vcshandler to use
- * @param states list of VCSFileState to treate
- * @throws VCSException if any exception while operation
- */
- void doAction(JDialog dialog, VCSHandler handler, List<VCSFileState> states) throws VCSException;
-}
Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java 2008-04-05 20:33:02 UTC (rev 356)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java 2008-04-05 20:35:25 UTC (rev 357)
@@ -1,268 +0,0 @@
-package org.codelutin.vcs;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.vcs.util.VCSHelper;
-
-import java.io.File;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * This class represents the vcs state of a file in a working copy or on remote
- * repository.
- * <br/>
- * For a defined file in a working copy, we only use a instance of the
- * class, {@link VCSFileStateManager} is responsible of instanciate thoses
- * objects and store them in a cache.
- * <br/>
- * use method {@link #doSynch(VCSHandler,long)} to doSynch whatever
- * local file state.
- * use method {@link #doSynch(VCSHandler,long,boolean)} to doSynch only
- * if local file state changed (with true value)
- *
- * @see VCSState
- * @see VCSFileStateManager
- */
-public class VCSFileStateImpl implements VCSFileState, Serializable {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static protected final Log log = LogFactory.getLog(VCSFileStateImpl.class);
-
- /**
- * working copy file to deal with (could not exists in file only exists
- * on remote repository)
- */
- protected File file;
- /** a optional module name (if defined, will change getModuleRelativeFileName behavior) */
- protected String moduleName;
- /**
- * relative path on local file system (use File.separator) to root of local
- * working copy
- */
- protected String localPath;
- /**
- * relative path on remote repository (use '/' (should be Remote.separator)
- * to root of this repository
- */
- protected String remotePath;
- /** timestamp of last doSynch or -1 if no doSynch was previously done */
- protected long timestamp;
- /** state of the file */
- protected VCSState state;
- /**
- * index used to identify uniquely each instance (hashcode of
- * file.getAbsolutePath())
- */
- protected int key;
- /** revision of this file, or null if unversionned */
- protected Long rev;
- /** changeLog of the file */
- protected String changeLog;
- /** diff of the file */
- protected String diff;
- /** action to be programmed for this state */
- protected VCSAction action;
-
- private static final long serialVersionUID = -815443990862836772L;
-
- /**
- * protected access restriction : you should not instanciate directly
- * this class, but use {@link VCSFileStateManager} to do it.
- *
- * @param handler the vcs handler used with this working copy
- * @param file file to be handled
- */
- public VCSFileStateImpl(VCSHandler handler, File file) {
- this.file = file;
- this.key = file.getAbsolutePath().hashCode();
- String path = file.getAbsolutePath();
- String rootPath = handler.getLocalDatabasePath().getAbsolutePath();
-
- if (!path.startsWith(rootPath)) {
- throw new VCSRuntimeException("could not create a VCSFileState " +
- "for a file not in the root working copy registered in " +
- "vcsHandler, but was : [" + file + " ::" +
- handler.getLocalDatabasePath() + " ]");
- }
- if (file.equals(handler.getConfig().getLocalDatabasePath())) {
- this.localPath = "";
- } else {
-
- this.localPath = path.substring(rootPath.length() + 1);
- }
- // by default moduleName is the first dir of localpath (if any)
- int index = this.localPath.indexOf(File.separator);
- if (index == -1) {
- // this is a module directory
- this.moduleName = this.localPath;
- this.localPath = "";
- } else {
- this.moduleName = this.localPath.substring(0, index);
- }
-
- resetState();
- }
-
- public boolean existLocally() {
- return file.exists();
- }
-
- public String getLocalPath() {
- return localPath;
- }
-
- public String getModuleName() {
- return moduleName;
- }
-
- public String getModuleRelativeFileName() {
- return "".equals(moduleName) ? getLocalPath() :
- "".equals(localPath) ? "" : localPath.substring(moduleName.length() + 1);
- }
-
- public String[] getFileNamePath() {
- // TODO Should use File.separator
- return getModuleRelativeFileName().split(File.separator);
- }
-
- public String getRemotePath() {
- if (remotePath == null)
- remotePath = VCSHelper.convertToRemoteName(localPath);
- return remotePath;
- }
-
- public VCSState getState() {
- return state;
- }
-
- public long getTimestamp() {
- return timestamp;
- }
-
- public File getFile() {
- return file;
- }
-
- public String getChangeLog() {
- return changeLog;
- }
-
- public Long getRev() {
- return rev;
- }
-
- public VCSAction getAction() {
- return action;
- }
-
- /**
- * reset synch for this instance : after this invocation,
- * the method {@link #wasSynch()} will return <code>true</code> to means
- * that no synch info are available.
- */
- public void resetState() {
- state = null;
- timestamp = -1;
- }
-
- /**
- * @return <code>true</code> if there at least one invocation of
- * {@link #doSynch(VCSHandler,long)} or
- * {@link #doSynch(VCSHandler,long,boolean)}
- * was made and no invocation of {@link #resetState()}
- * was made after.
- */
- public boolean wasSynch() {
- return state != null && timestamp != -1;
- }
-
- /**
- * @return <code>true</code> if this instance <code>wasSynch</code> and
- * the file was not modified since last synch.
- */
- public boolean isLocallySynch() {
- return wasSynch() && timestamp <= file.lastModified();
- }
-
- /**
- * doSynch this instance with remote repository and put a new timestamp
- * the one passed as parameter.
- *
- * @param handler vcs handler to use
- * @param timestamp the new synch timestamp
- */
- public void doSynch(VCSHandler handler, long timestamp) {
- doSynch(handler, timestamp, false);
- }
-
- /**
- * doSynch this instance with remote repository and put a new timestamp
- * the one passed as parameter.
- * Do not doSynch if <code>ifFileChanged</code> is <code>true</code>
- * and file was not modify since last synch.
- *
- * @param handler vcs handler to use
- * @param timestamp the new synch timestamp
- * @param ifFileChanged if <code>true</code> will doSynch only if file
- * was locally modified after last doSynch
- */
- public void doSynch(VCSHandler handler, long timestamp,
- boolean ifFileChanged) {
- //TODO should deal with possibility of file existed but no more...
- boolean needSynch = !wasSynch() ||
- !ifFileChanged || timestamp <= file.lastModified();
-
- try {
- if (needSynch) {
- this.timestamp = timestamp;
- Collection tmp = new ArrayList();
- this.state = handler.getState(file, tmp);
- if (!tmp.isEmpty()) this.rev = (Long) tmp.iterator().next();
- log.info(" new synch " + this);
- }
- } catch (VCSException e) {
- log.warn("could not acquire state for " + this + " : " + e.getMessage());
- resetState();
- }
- }
-
- @Override
- public boolean equals(Object o) {
- return this == o || !(o == null || getClass() != o.getClass()) &&
- localPath.equals(((VCSFileStateImpl) o).localPath);
- }
-
- @Override
- public int hashCode() {
- return localPath.hashCode();
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(localPath).append('(').append(key).append(')').
- append('|').append(state).append('|').append(timestamp);
- return sb.toString();
- }
-
- @Override
- public VCSFileStateImpl clone() throws CloneNotSupportedException {
- return (VCSFileStateImpl) super.clone();
- }
-
-
- public void setChangeLog(String changeLog) {
- this.changeLog = changeLog;
- }
-
- public void setAction(VCSAction action) {
- this.action = action;
- }
-
- public void setState(VCSState state) {
- this.state = state;
- }
-}
-
Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java 2008-04-05 20:33:02 UTC (rev 356)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java 2008-04-05 20:35:25 UTC (rev 357)
@@ -1,276 +0,0 @@
-/* ##%
-* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin,
-* Benjamin Poussin, 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.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.TreeMap;
-
-/**
- * Classe responsable de la gestion des {@link VCSFileStateImpl}.
- * <p/>
- * Elle permet leur instanciation, et g�re un cache de ces objets, la politique
- * �tant de n'instancier qu'une seule fois et ensuite d'utiliser les methodes de
- * synchronisations.
- * <br/>
- * TODO Doc
- * {@link #doSynch()}
- * {@link #getState(long,File)} ()}
- * {@link #doAdd(VCSHandler,File)}
- * {@link #doDelete(File)}
- * {@link #doClear()}
- * {@link #doReset()}
- *
- * @author chemit
- */
-public class VCSFileStateManager {
-
- protected static VCSHandler getVCSHanler() {
- return VCSHandlerFactory.getHandler();
- }
-
- static public List<VCSFileState> doScan(VCSHandler handler, File root, boolean changeLog,
- VCSState... states) throws VCSException {
- // TODO on devrait changer l'algorithme, pour ne recuperer
- // TODO que ce qui est reellement est necessaire
-
- // recupereration des fichier locaux
- List<String> localFileNames = handler.getLocalStorageNames(root);
-
- // recuperation des fichiers distants
- List<String> remoteFileNames = handler.getRemoteStorageNames(root);
-
- // recuperation des fichiers uniquement presents sur le repository distant
- List<String> newRemoteName = new ArrayList<String>(remoteFileNames);
- newRemoteName.removeAll(localFileNames);
-
- List<VCSFileState> vcsstates = new ArrayList<VCSFileState>();
-
- long timestamp = System.nanoTime();
-
- for (String filePath : localFileNames) {
- File f = new File(root, filePath);
- vcsstates.add(getState(timestamp, f));
- }
-
- for (String filePath : newRemoteName) {
- File f = new File(root, filePath);
- vcsstates.add(getState(timestamp, f));
- }
-
- final List<VCSFileState> result = filter(vcsstates, states);
- if (changeLog) {
- // compute all change log for selected files
- for (VCSFileState vcsFileState : result)
- vcsFileState.setChangeLog(handler.getChangeLog(vcsFileState.getFile()));
- }
- return result;
- }
-
- // /////////////////////////////////////////////////////////////////////////
- // / methodes getState(XXX) pour obtenir des etats du cache (avec creation
- // / si besoin est)
- // /////////////////////////////////////////////////////////////////////////
-
- static public VCSFileState getState(long timestamp, File f) {
- return getState(getVCSHanler(), timestamp, f);
- }
-
- static public VCSFileState getState(boolean synch, File f) {
- return getState(getVCSHanler(), synch, f);
- }
-
- static public VCSFileState getState(VCSHandler handler, boolean synch,
- File f) {
- VCSFileState result;
- synchronized (cache) {
- final int key = getKey(f);
- result = cache.get(key);
- if (result == null) {
- result = doAdd(handler, f);
- }
- if (synch) {
- result.doSynch(handler, System.nanoTime());
- }
- }
- return result;
- }
-
- static public VCSFileState getState(VCSHandler handler, long timestamp, File f) {
- VCSFileState result;
- synchronized (cache) {
- final int key = getKey(f);
- result = cache.get(key);
- if (result == null) {
- result = doAdd(handler, f);
- }
- result.doSynch(handler, timestamp);
- }
- return result;
- }
-
- static public VCSFileState[] getState(VCSHandler handler, boolean synch,
- Collection<File> f) {
- VCSFileState[] result = new VCSFileState[f.size()];
-
- int index = 0;
- for (File file : f) {
- result[index] = getState(handler, synch, file);
- index++;
- }
- return result;
- }
-
- // /////////////////////////////////////////////////////////////////////////
- // / methodes doSynch(XXX) pour synchroniser les �tats du cache
- // /////////////////////////////////////////////////////////////////////////
-
- static public void doSynch() {
- doSynch(getVCSHanler(), false, System.nanoTime());
- }
-
- static public void doSynch(VCSHandler handler, boolean ifFileChanged,
- long timestamp) {
- synchronized (cache) {
- for (Integer hashcode : cache.keySet()) {
- cache.get(hashcode).doSynch(handler, timestamp, ifFileChanged);
- }
- }
- }
-
- static public void doSynch(VCSHandler handler, Collection<File> files) {
- doSynch(handler, false, System.nanoTime(), files);
- }
-
- static public void doSynch(VCSHandler handler, boolean ifFileChanged,
- long timestamp, Collection<File> files) {
- synchronized (cache) {
- for (File file : files) {
- VCSFileState vcsFileState = cache.get(getKey(file));
- if (vcsFileState == null)
- vcsFileState = doAdd(getVCSHanler(), file);
- vcsFileState.doSynch(handler, timestamp, ifFileChanged);
- }
- }
- }
-
- // /////////////////////////////////////////////////////////////////////////
- // methodes protected doAdd(XXX) pour ajouter directement des etats au cache
- // /////////////////////////////////////////////////////////////////////////
-
- static protected VCSFileState doAdd(VCSHandler handler, File f) {
- VCSFileState result;
- synchronized (cache) {
- final int key = getKey(f);
- cache.put(key, result = new VCSFileStateImpl(handler, f));
- log.debug("[cache size:" + cache.size() + "] : " + result);
- }
- return result;
- }
-
- // ////////////////////////////////////////////////////////////////////////
- // methodes doDelete(XXX) pour supprimer des etats du cache
- // ////////////////////////////////////////////////////////////////////////
-
- static public void doDelete(File file) {
- synchronized (cache) {
- cache.remove(getKey(file));
- }
- }
-
- // /////////////////////////////////////////////////////////////////////////
- // / clean cache methods
- // /////////////////////////////////////////////////////////////////////////
-
- static public void doReset() {
- synchronized (cache) {
- for (Integer hashcode : cache.keySet()) {
- cache.get(hashcode).resetState();
- }
- }
- }
-
- static public void doClear() {
- synchronized (cache) {
- cache.clear();
- }
- }
-
- protected VCSFileStateManager() {
- }
-
- static private int getKey(File file) {
- return file.getAbsolutePath().hashCode();
- }
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static protected final Log log = LogFactory
- .getLog(VCSFileStateManager.class);
-
- /** cache of VCSFileState, keys are relativePath.hashCode of each entry */
- static final protected java.util.Map<Integer, VCSFileState> cache = new TreeMap<Integer, VCSFileState>();
-
- // /////////////////////////////////////////////////////////////////////////
- // / utils methods (filter and explode from VCSAction and VCSState)
- // /////////////////////////////////////////////////////////////////////////
- @SuppressWarnings({"unchecked"})
- static public List<VCSFileState>[] explode(List<VCSFileState> source,
- VCSState... wanted) {
- if (wanted.length == 0)
- wanted = VCSState.values();
- int nbState = wanted.length;
- List<VCSFileState>[] result = new List[nbState];
- for (int i = 0; i < nbState; i++) {
- result[i] = new ArrayList<VCSFileState>();
- }
- List<VCSState> states = java.util.Arrays.asList(wanted);
- VCSState state;
- int index;
- for (VCSFileState fileState : source) {
- state = fileState.getState();
- if ((index = states.indexOf(state)) > -1) {
- result[index].add(fileState);
- }
- }
- return result;
- }
-
- static public List<VCSFileState> filter(List<VCSFileState> source,
- VCSState... wanted) {
- List<VCSFileState> result = new ArrayList<VCSFileState>();
- List<VCSState> states = java.util.Arrays.asList(wanted);
-
- if (wanted.length == 0) {
- return result;
- }
- for (VCSFileState fileState : source) {
- VCSState currentState = fileState.getState();
- if (states.contains(currentState)) {
- result.add(fileState);
- }
- }
- return result;
- }
-}
Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java 2008-04-05 20:33:02 UTC (rev 356)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java 2008-04-05 20:35:25 UTC (rev 357)
@@ -1,49 +0,0 @@
-/**
- * # #% 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.ui.model;
-
-import org.codelutin.vcs.VCSFileState;
-import org.codelutin.vcs.VCSState;
-import org.codelutin.vcs.ui.VCSUIConstants;
-
-/** @author chemit */
-public class SimpleVCSFileStatesModel extends AbstractVCSFileStatesModel {
-
- private static final long serialVersionUID = -7592705623128585146L;
-
- public SimpleVCSFileStatesModel(String name) {
- super(name, VCSUIConstants.SIMPLE_COLUMNS_NAMES);
- }
-
- public Object getValueAt(int rowIndex, int columnIndex) {
- if (isEmpty()) return null;
- VCSFileState item = data.get(rowIndex);
- Object result = null;
- if (columnIndex == 0) {
- // get module
- result = item.getModuleName();
- } else if (columnIndex == 1) {
- // get file
- result = item.getModuleRelativeFileName();
- } else if (columnIndex == 2) {
- // get status
- VCSState state = item.getState();
- result = state == null ? null : state.libelle();
- }
- return result;
- }
-
-
-}
\ No newline at end of file
1
0
r356 - trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
05 Apr '08
Author: tchemit
Date: 2008-04-05 20:33:02 +0000 (Sat, 05 Apr 2008)
New Revision: 356
Removed:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConfig.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEvent.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEventListener.java
Log:
deletec VCSConfig and VCSHandlerEvents
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConfig.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConfig.java 2008-04-05 20:32:29 UTC (rev 355)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConfig.java 2008-04-05 20:33:02 UTC (rev 356)
@@ -1,97 +0,0 @@
-/*
-* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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;
-
-/**
- * Contract to be realised by a VCS config used in VCSHandler
- *
- * @author chemit
- */
-public interface VCSConfig {
-
- /**
- * find out if a connection to remote vcs servsder can be etablished.
- * <p/>
- * Note : The method is safe and will not throw any exception.
- *
- * @return <code>true</code> if connection to remote vcs server can be
- * etablished.
- */
- boolean canConnect();
-
- /** @return <code>true</code> if handler is connected to remote vcs server */
- boolean isConnected();
-
- /** @return the current connexion state */
- ConnectionState getConnectionState();
-
- /** @return the type of vcs used */
- VCSType getType();
-
- /** @return <code>true</code> if ssh connexion is used */
- boolean isUseSshConnexion();
-
- /** @return the url of hostname */
- String getHostName();
-
- /** @return location of the private ssh2 key file */
- File getKeyFile();
-
- /** @return the user connexion login */
- String getUserName();
-
- /** @return <code>true</code> if user ssh2 pair keys use a passphrase */
- boolean isNoPassPhrase();
-
- String getPassphrase();
-
- /** @return the full location path of the remote container of module */
- String getRemotePath();
-
- /** @return the name of remote module */
- String getRemoteDatabase();
-
- /** @return the full url path to the remote repository (with module name include) */
- String getRemoteDatabasePath();
-
- File getLocalDatabasePath();
-
- /** @return the type of reposotory used (head,tags,branches,...) */
- VCSTypeRepo getTypeRepo();
-
- /** @return <code>true</code> if no connexion is etablish at current time */
- boolean isOffline();
-
- /** @return <code>true</code> if remote repository is read-only */
-
- boolean isReadOnly();
-
- /** @return <code>true</code> if vcs handler is finely init */
-
- boolean isInit();
-
- /** method to validate vcs configuration. */
- void validate();
-
- void setUseSshConnexion(boolean useSshConnexion);
-
- File getSource();
-}
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEvent.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEvent.java 2008-04-05 20:32:29 UTC (rev 355)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEvent.java 2008-04-05 20:33:02 UTC (rev 356)
@@ -1,51 +0,0 @@
-/**
- * # #% 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.util.EventObject;
-
-/**
- * Events to be used while {@link VCSHandler} life cycle.
- *
- * @author chemit
- * @see VCSHandlerEventListener
- * @see VCSHandler
- */
-public class VCSHandlerEvent extends EventObject {
-
- private static final long serialVersionUID = 1L;
-
- protected Type type;
-
- public enum Type {
- INIT, OPEN, CLOSE
- }
-
- /**
- * Constructs a prototypical Event.
- *
- * @param source The object on which the Event initially occurred.
- * @param type type of event
- * @throws IllegalArgumentException if source is null.
- */
- public VCSHandlerEvent(Object source, Type type) {
- super(source);
- this.type = type;
- }
-
- public Type getType() {
- return type;
- }
-}
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEventListener.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEventListener.java 2008-04-05 20:32:29 UTC (rev 355)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEventListener.java 2008-04-05 20:33:02 UTC (rev 356)
@@ -1,47 +0,0 @@
-/**
- * # #% 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.util.EventListener;
-
-/**
- * A listener on {@link org.codelutin.vcs.VCSHandler}
- *
- * @author chemit
- */
-public interface VCSHandlerEventListener extends EventListener {
-
- /**
- * call when vcs handler was successfull init
- *
- * @param event current event
- */
- public void init(VCSHandlerEvent event);
-
- /**
- * call when vcs handler was successfull open
- *
- * @param event current event
- */
- public void open(VCSHandlerEvent event);
-
- /**
- * call when vcs handler was closed
- *
- * @param event current event
- */
- public void close(VCSHandlerEvent event);
-
-}
\ No newline at end of file
1
0
r355 - in trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs: . util
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
05 Apr '08
Author: tchemit
Date: 2008-04-05 20:32:29 +0000 (Sat, 05 Apr 2008)
New Revision: 355
Added:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java
Removed:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java
Log:
introduce VCSEntry, VCSEntries, VCSConnexion and VCSConnexionConfig
introduc default implementations
delete VCSHelper
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java 2008-04-05 20:31:28 UTC (rev 354)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -1,96 +0,0 @@
-/**
- * # #% 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;
-}
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-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,384 @@
+/**
+ * # #% 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.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Contract to be realized for a connexion to a vcs.
+ * <p/>
+ * The method {@link #init(VCSConnexionConfig)} must be invoked before using the connexion.
+ * <p/>
+ * Note: you should not instanciate directly this class but use
+ * {@link org.codelutin.vcs.VCSProvider#newConnection(org.codelutin.vcs.VCSConnexionMode , VCSConnexionConfig)} instead.
+ *
+ * @author chemit
+ */
+public interface VCSConnexion {
+
+ VCSProvider getProvider();
+
+ /**
+ * @return the working copy used, can be null if no working copy exists.
+ * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before.
+ */
+ File getWorkingCopy() throws IllegalStateException;
+
+ /**
+ * @return the URI used to connect to vcs
+ * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before.
+ */
+ URI getRemoteURI() throws IllegalStateException;
+
+ /**
+ * @return the mode of this connexion
+ * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before.
+ */
+ VCSConnexionMode getMode() throws IllegalStateException;
+
+ /**
+ * Initialize 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.
+ */
+ void init(VCSConnexionConfig config);
+
+ /**
+ * @return the config of the connexion
+ * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before.
+ */
+ VCSConnexionConfig getConfig() throws IllegalStateException;
+
+ /**
+ * test if connection is ok
+ *
+ * @throws VCSException if any problem
+ */
+ void testConnection() throws VCSException;
+
+ /**
+ * Close connexion.
+ *
+ * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before.
+ */
+ void open() throws IllegalStateException;
+
+ /**
+ * Close connexion.
+ *
+ * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} 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(VCSConnexionConfig)} 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(VCSConnexionConfig)} 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(VCSConnexionConfig)} was not invoked before.
+ */
+ boolean hasFailed() throws IllegalStateException;
+
+ /** @param l the listener to add */
+ void addVCSConnexionEventListener(VCSConnexionEventListener l);
+
+ /** @param l the listener to remove */
+ void removeVCSConnexionEventListener(VCSConnexionEventListener l);
+
+ /**
+ * init working copy, says if it is the first we use it it, we will checkout
+ * the databaseDirectory directory
+ *
+ * @throws VCSException if any exception while init
+ */
+ void initWorkingCopy() throws VCSException;
+
+ /** delete the local working copy with all his files */
+ void deleteWorkingCopy();
+
+ /**
+ * @return a <code>FilenameFilter<code> to detect all files and directories in a vcs working copy that
+ * must be handled by vcs
+ */
+ FilenameFilter getVersionnableFilenameFilter();
+
+ /**
+ * @return a <code>FileFilter<code> to detect all files and directories in a vcs working copy that
+ * must be handled by vcs
+ */
+ FileFilter getVersionnableFileFilter();
+
+ /**
+ * @return name of directory used by vcs to store in working copy, a data's
+ * directory configuration (e.g CVS for cvs and .svn for svn)
+ */
+ String getConfLocalDirname();
+
+ /**
+ * @return name of the file used by vcs to store in working copy
+ * configuration directory entries of data's directory (e.g Entries
+ * for cvs and entries for svn)
+ */
+ String getConfLocalEntriesFilename();
+
+ VCSState getState(File fileState, Collection tmp) throws VCSException;
+
+ VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException;
+
+ /**
+ * @param file file to test
+ * @return <code>true</code> if <code>file</code> is on remote
+ * repository, <code>false</code> otherwise.
+ */
+ boolean isOnRemote(File file);
+
+ /**
+ * @param file file to test
+ * @return <code>true</code> if file is uptodate,<code>false</code>
+ * otherwise.
+ * @throws VCSException if any exception while operation
+ */
+ boolean isUpToDate(File file) throws VCSException;
+
+ /**
+ * @param file file to test
+ * @return <code>true</code> if file is handled by VCS,<code>false</code>
+ * otherwise.
+ */
+ boolean isVersionnableFile(File file);
+
+ /**
+ * add on remote repository somes directories
+ *
+ * @param commitMessage commit message
+ * @param dirNames names of the directories to create on remote repository (could
+ * used multi-level directories)
+ * @throws VCSException if any exception while operation
+ */
+ void makeRemoteDir(String commitMessage, String... dirNames)
+ throws VCSException;
+
+ /**
+ * delete on remote repository somes directories
+ *
+ * @param commitMessage commit message
+ * @param dirNames names of the directories to delete on remote repository (could
+ * used multi-level directories)
+ * @throws VCSException if any exception while operation
+ */
+ void deleteRemoteDir(String commitMessage, String... dirNames)
+ throws VCSException;
+
+ /**
+ * add a list of files into repository
+ *
+ * @param files files to add
+ * @param msg message for VCS commit, if <code>null</code> then no commit
+ * is performed
+ * @return revision of the operation
+ * @throws VCSException if any exception while operation
+ */
+ long add(List<File> files, String msg) throws VCSException;
+
+ // void add(File file, String msg) throws VCSException;
+
+ /**
+ * delete a list of files from repository
+ *
+ * @param files files to delete
+ * @param msg message for VCS commit, if <code>null</code> then no commit
+ * is performed
+ * @throws VCSException if any exception while operation
+ */
+ void delete(List<File> files, String msg) throws VCSException;
+
+ /**
+ * revert a list of files from repository
+ *
+ * @param files files to revert
+ * @throws VCSException if any exception while operation
+ */
+ void revert(List<File> files) throws VCSException;
+
+ /**
+ * commit a list of files into repository
+ *
+ * @param files files to commit
+ * @param msg message for VCS commit
+ * @return revision of the operation
+ * @throws VCSException if any exception while operation
+ */
+ long commit(List<File> files, String msg) throws VCSException;
+
+ /**
+ * update a file to repository to a certain revision
+ *
+ * @param file file to update
+ * @param revision object representing a revision for the current VCS
+ * @throws VCSException if any exception while operation
+ */
+ void update(File file, Object revision) throws VCSException;
+
+ /**
+ * update a file to repository
+ *
+ * @param file file to update
+ * @throws VCSException if any exception while operation
+ */
+ void update(File file) throws VCSException;
+
+ /**
+ * checkout a module from repository to a local file
+ *
+ * @param destDir local file where to checkout
+ * @param module module's name to checkout
+ * @param recurse flag to say to recurse checkout or not.
+ * @throws VCSException if any exception while operation
+ */
+ void checkout(File destDir, String module, boolean recurse) throws VCSException;
+
+ void checkoutFile(File destDir, String module) throws VCSException;
+
+ long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException;
+
+ /**
+ * TODO This is not the good place : VCS != Storage
+ *
+ * @param directory directory to treate
+ * @return TODO
+ * @throws VCSException TODO
+ */
+ List<String> getRemoteStorageNames(File directory) throws VCSException;
+
+ /**
+ * TODO This is not the good place : VCS != Storage
+ *
+ * @param directory directory to treate
+ * @return TODO
+ */
+ List<String> getLocalStorageNames(File directory);
+
+ /**
+ * @param f local file to treate
+ * @return current local revision of a file
+ * @throws VCSException TODO
+ */
+ Object getRevision(File f) throws VCSException;
+
+ /**
+ * Obtain the list of log entries for the file
+ *
+ * @param startRevision TODO
+ * @param endRevision TODO
+ * @param file file to treate
+ * @return list of log entries for this file between two revisions
+ * @throws VCSException if any exception while grabbing infos
+ */
+ List getLog(Object startRevision, Object endRevision, File file)
+ throws VCSException;
+
+ /**
+ * obtain the content of a file for a specific revision
+ *
+ * @param file file to obtain
+ * @param revision revision treated
+ * @return the content of the file on repository for the specific revision
+ * passed as arguement.
+ * @throws VCSException if any exception while operation
+ * @throws java.io.IOException TODO
+ */
+ String getFileContent(File file, Object revision) throws VCSException, IOException;
+
+ /**
+ * Build the changelog for <code>file</code> from current revision of this
+ * local file against head repository head version. For each revision
+ * between current revision and head revision of this file, we give the
+ * following informations :
+ * <ul>
+ * <li>revision number</li>
+ * <li>author</li>
+ * <li>date</li>
+ * <li>commit message</li>
+ * </ul>
+ *
+ * @param file file to treate
+ * @return a string representation of change log for the local file to the
+ * head ?
+ * @throws VCSException if any exception while building changelog
+ */
+ String getChangeLog(File file) throws VCSException;
+
+ /**
+ * Generate in the ouputstream the diff between the current revision of the
+ * local file against headest revision on repository. <br>
+ * If file is uptodate, then does nothing.
+ *
+ * @param file the file to treate
+ * @return the diff
+ * @throws VCSException inf any exception while building diff, such as :
+ * <ul>
+ * <li>unversionned file</li>
+ * <li>unexistant file locally</li>
+ * <li>locally modified file ?</li>
+ * <li>...</li>
+ * </ul>
+ * @throws java.io.IOException if io problem with streams
+ */
+ String getDiff(File file) throws VCSException, IOException;
+
+ /**
+ * Generate in the ouputstream the diff between the current revision of the
+ * local file against another revision (<code>againstRevision</code>) on
+ * repository. <br>
+ * If file is uptodate, then does nothing.
+ *
+ * @param file the file to treate
+ * @param againstRevision the against revision to use
+ * @return the diff
+ * @throws VCSException inf any exception while building diff, such as :
+ * <ul>
+ * <li>unversionned file</li>
+ * <li>unexistant file locally</li>
+ * <li>locally modified file ?</li>
+ * <li>...</li>
+ * </ul>
+ * @throws java.io.IOException if problem with streams
+ */
+ String getDiff(File file, Object againstRevision) throws VCSException, IOException;
+
+ /**
+ * @return <code>true</code> if protocol has changed between config and working copy
+ * @throws VCSException if any pb
+ */
+ boolean hasProtocoleChanged() throws VCSException;
+}
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConfig.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,67 @@
+/*
+* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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;
+
+/**
+ * Contract to be realized by a VCSConnexion configuration.
+ * <p/>
+ * This class has no logic, ans is a <code>POJO</code>.
+ *
+ * @author chemit
+ */
+public interface VCSConnexionConfig {
+
+ /** @return the type of vcs used */
+ VCSType getType();
+
+ /** @return <code>true</code> if ssh connexion is used */
+ boolean isUseSshConnexion();
+
+ /** @return the url of hostname */
+ String getHostName();
+
+ /** @return location of the private ssh2 key file */
+ File getKeyFile();
+
+ /** @return the user connexion login */
+ String getUserName();
+
+ /** @return <code>true</code> if user ssh2 pair keys use a passphrase */
+ boolean isNoPassPhrase();
+
+ String getPassphrase();
+
+ /** @return the full location path of the remote container of module */
+ String getRemotePath();
+
+ /** @return the name of remote module */
+ String getRemoteDatabase();
+
+ /** @return the full url path to the remote repository (with module name include) */
+ String getRemoteDatabasePath();
+
+ File getLocalDatabasePath();
+
+ /** @return the type of reposotory used (head,tags,branches,...) */
+ VCSTypeRepo getTypeRepo();
+
+ void setUseSshConnexion(boolean newValue);
+}
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEvent.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,56 @@
+/**
+ * # #% 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.util.EventObject;
+
+/**
+ * Events to be used while {@link org.codelutin.vcs.VCSHandler} life cycle.
+ *
+ * @author chemit
+ * @see org.codelutin.vcs.VCSHandlerEventListener
+ * @see org.codelutin.vcs.VCSHandler
+ */
+public class VCSConnexionEvent extends EventObject {
+
+ private static final long serialVersionUID = 1L;
+
+ protected Type state;
+
+ public enum Type {
+ OPEN, CLOSE
+ }
+
+ /**
+ * Constructs a prototypical Event.
+ *
+ * @param source The object on which the Event initially occurred.
+ * @param type type of event
+ * @throws IllegalArgumentException if source is null.
+ */
+ public VCSConnexionEvent(VCSConnexion source, Type type) {
+ super(source);
+ this.state = type;
+ }
+
+ @Override
+ public VCSConnexion getSource() {
+ return (VCSConnexion) super.getSource();
+ }
+
+ public Type getState() {
+ return state;
+ }
+}
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEventListener.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -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;
+
+/**
+ * A listener on {@link VCSConnexion} life cycle
+ *
+ * @author chemit
+ */
+public interface VCSConnexionEventListener extends java.util.EventListener {
+
+ /**
+ * call when vcs connexion was successfull open
+ *
+ * @param event current event
+ */
+ public void open(VCSConnexionEvent event);
+
+ /**
+ * call when vcs connexion was closed
+ *
+ * @param event current event
+ */
+ public void close(VCSConnexionEvent event);
+
+}
\ No newline at end of file
Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,121 @@
+/**
+ * # #% 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 javax.swing.ListSelectionModel;
+import java.util.List;
+
+/** @author chemit */
+public interface VCSEntries {
+
+ /**
+ * Discover and Populate with all local and remote entries.
+ *
+ * @param timestamp gloabal timestamp to apply
+ * @param connexion connexion used to populate
+ * @throws VCSException if any pb with vcs io
+ */
+ void populate(VCSConnexion connexion, long timestamp) throws VCSException;
+
+ /**
+ * Populate with no discovering for a given list of local relative paths for a given location type.
+ * <p/>
+ * Note : <b>We always used the filesystem path separator to encode paths.</b>
+ *
+ * @param relativeLocalPaths list of local relative path to populate
+ * @param location location to be used
+ * @param timestamp gloabal timestamp to apply
+ * @param connexion connexion used tro refresh
+ * @throws VCSException if any pb with vcs io
+ */
+ void populate(VCSConnexion connexion, List<String> relativeLocalPaths, VCSEntryLocation location, long timestamp) throws VCSException;
+
+ /**
+ * Populate from pre-computed entries. No discovering is done, nor vcs io operations.
+ *
+ * @param location given location to use
+ * @param states pre-computed states to populate
+ */
+ void populate(VCSEntryLocation location, VCSEntry[] states);
+
+ /**
+ * refresh state of the entry.
+ *
+ * @param entries entries to refresh
+ * @param timestamp global timestamp to apply
+ * @throws IllegalStateException if entry was never populated
+ */
+ void refresh(List<VCSEntry> entries, long timestamp) throws IllegalStateException;
+
+ /**
+ * obtain the list of all entries.
+ *
+ * @return list of all entries
+ * @throws IllegalStateException if entry was never populated
+ */
+ List<VCSEntry> getEntries() throws IllegalStateException;
+
+ /**
+ * obtain the list of all entries for a given connexion
+ *
+ * @param connexion filter connexion
+ * @param entries entries to filter
+ * @return list of all entries for a given connexion
+ */
+ List<VCSEntry> filter(VCSConnexion connexion, List<VCSEntry> entries);
+
+ /**
+ * obtain the list of all entries for a given location
+ *
+ * @param location filter location
+ * @param entries entries to filter
+ * @return list of all entries for a given connexion
+ */
+ List<VCSEntry> filter(VCSEntryLocation location, List<VCSEntry> entries);
+
+ /**
+ * obtain the list of all entries for a given state
+ *
+ * @param state filter state
+ * @param entries entries to filter
+ * @return list of all entries for a given connexion
+ */
+ List<VCSEntry> filter(VCSState state, List<VCSEntry> entries);
+
+ /**
+ * obtain the list of all entries for a given selection model
+ *
+ * @param selectionModel filter from selection model
+ * @param entries entries to filter
+ * @return list of all entries for a given connexion
+ */
+ List<VCSEntry> filter(ListSelectionModel selectionModel, List<VCSEntry> entries);
+
+ /**
+ * obtain the list of all entries for a given action
+ *
+ * @param action filter state
+ * @param entries entries to filter
+ * @return list of all entries for a given connexion
+ */
+ List<VCSEntry> filter(VCSAction action, List<VCSEntry> entries);
+
+ VCSAction[] getActions(List<VCSEntry> entries);
+
+ VCSState[] getStates(List<VCSEntry> entries);
+
+ /** clear the list of entries. */
+ void clear();
+}
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,121 @@
+/**
+ * # #% 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.BufferedReader;
+import java.io.File;
+import java.io.Serializable;
+
+/** @author chemit */
+public interface VCSEntry extends Serializable {
+
+ /**
+ * Populate the state of the entry, this method calls {@link #refresh(long)} method.
+ *
+ * @param timestamp gloabal timestamp to apply
+ * @throws VCSException if anypb with vcs io
+ */
+ void populate(long timestamp) throws VCSException;
+
+ /**
+ * refresh state of the entry.
+ *
+ * @param timestamp global timestamp to apply
+ * @throws IllegalStateException if entry was never populated
+ * @throws VCSException if anypb with vcs io
+ */
+ void refresh(long timestamp) throws IllegalStateException, VCSException;
+
+ /**
+ * Obtain the relative path from root repository to the entry.
+ * <p/>
+ * Note: <b>We use the filesystem path separator, could not be the same on remote</b>
+ *
+ * @return the relativePath from local root repository to the entry
+ */
+ String getRelativeLocalPath();
+
+ /**
+ * Obtain the relative path from root repository to the entry.
+ * <p/>
+ * Note: <b>We use the '/' as path separator, could not be the same on local</b>
+ *
+ * @return the relativePath from remote root repository to the entry
+ */
+ String getRelativeRemotePath();
+
+ /**
+ * Obtain the projected entry on local working copy.
+ * <p/>
+ * Note : <b> the file could not exists.
+ *
+ * @return the local file represented by this entry
+ */
+ File getFile();
+
+ /** @return connexion used */
+ VCSConnexion getConnexion();
+
+ /**
+ * @return the location of entry
+ * @throws IllegalStateException if entry was never populated
+ * @see VCSEntryLocation
+ */
+ VCSEntryLocation getLocation() throws IllegalStateException;
+
+ /**
+ * @return the last state found for the entry
+ * @throws IllegalStateException if entry was never populated
+ */
+ VCSState getState() throws IllegalStateException;
+
+ /**
+ * @return the timestamp of the last state synchronization for the entry
+ * @throws IllegalStateException if entry was never populated
+ */
+ long getTimestamp() throws IllegalStateException;
+
+ /**
+ * @return the rev of entry
+ * @throws IllegalStateException if entry was never populated
+ */
+ String getRev() throws IllegalStateException;
+
+ /**
+ * @return the changelog of entry from local aginst remote
+ * @throws IllegalStateException if entry was never populated
+ */
+ BufferedReader getChangeLog() throws IllegalStateException;
+
+ /**
+ * @return the diff of entry from local aginst remote
+ * @throws IllegalStateException if entry was never populated
+ */
+ BufferedReader getDiff() throws IllegalStateException;
+
+ /**
+ * @return the local entry content
+ * @throws IllegalStateException if entry was never populated, or entry is a directory
+ */
+ BufferedReader getLocalContent() throws IllegalStateException;
+
+ /**
+ * @return the remote entry content
+ * @throws IllegalStateException if entry was never populated, or entry is a directory
+ */
+ BufferedReader getRemoteContent() throws IllegalStateException;
+
+ void setState(VCSState state);
+}
\ No newline at end of file
Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,130 @@
+/**
+ * # #% 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.VCSConnexionConfig;
+import org.codelutin.vcs.VCSType;
+import org.codelutin.vcs.VCSTypeRepo;
+
+import java.io.File;
+
+/** @author chemit */
+public class VCSConnexionConfigImpl implements VCSConnexionConfig {
+
+ private VCSType type;
+ private boolean useSshConnexion;
+ private String hostName;
+ private File keyFile;
+ private String userName;
+ private boolean noPassPhrase;
+ private String passPhrase;
+ private String remotePath;
+ private String remoteDatabase;
+ private VCSTypeRepo typeRepo;
+ private File localDatabasePath;
+
+
+ public VCSType getType() {
+ return type;
+ }
+
+ public boolean isUseSshConnexion() {
+ return useSshConnexion;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public File getKeyFile() {
+ return keyFile;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public boolean isNoPassPhrase() {
+ return noPassPhrase;
+ }
+
+ public String getPassphrase() {
+ return passPhrase;
+ }
+
+ public String getRemotePath() {
+ return remotePath;
+ }
+
+ public String getRemoteDatabase() {
+ return remoteDatabase;
+ }
+
+ public String getRemoteDatabasePath() {
+ return remotePath + '/' + remoteDatabase;
+ }
+
+ public File getLocalDatabasePath() {
+ return localDatabasePath;
+ }
+
+ public VCSTypeRepo getTypeRepo() {
+ return typeRepo;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public void setKeyFile(File keyFile) {
+ this.keyFile = keyFile;
+ }
+
+ public void setLocalDatabasePath(File localDatabasePath) {
+ this.localDatabasePath = localDatabasePath;
+ }
+
+ public void setNoPassPhrase(boolean noPassPhrase) {
+ this.noPassPhrase = noPassPhrase;
+ }
+
+ public void setPassPhrase(String passPhrase) {
+ this.passPhrase = passPhrase;
+ }
+
+ public void setRemoteDatabase(String remoteDatabase) {
+ this.remoteDatabase = remoteDatabase;
+ }
+
+ public void setRemotePath(String remotePath) {
+ this.remotePath = remotePath;
+ }
+
+ public void setType(VCSType type) {
+ this.type = type;
+ }
+
+ public void setTypeRepo(VCSTypeRepo typeRepo) {
+ this.typeRepo = typeRepo;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public void setUseSshConnexion(boolean useSshConnexion) {
+ this.useSshConnexion = useSshConnexion;
+ }
+}
Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,201 @@
+/**
+ * # #% 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.VCSAction;
+import org.codelutin.vcs.VCSConnexion;
+import org.codelutin.vcs.VCSEntries;
+import org.codelutin.vcs.VCSEntry;
+import org.codelutin.vcs.VCSEntryLocation;
+import org.codelutin.vcs.VCSException;
+import org.codelutin.vcs.VCSState;
+
+import javax.swing.ListSelectionModel;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Collections;
+import java.util.Arrays;
+
+/** @author chemit */
+public class VCSEntriesImpl implements VCSEntries {
+
+ protected List<VCSEntry> entries;
+
+ public void populate(VCSConnexion connexion, long timestamp) throws VCSException {
+
+ List<String> localFiles = connexion.getLocalStorageNames(connexion.getWorkingCopy());
+
+ List<String> remoteFiles = transformToLocal(connexion.getRemoteStorageNames(connexion.getWorkingCopy()));
+
+ List<String> allFiles = new ArrayList<String>();
+
+ // detect location all from remote files
+ for (Iterator<String> it = remoteFiles.iterator(); it.hasNext();) {
+ String relativePath = it.next();
+ if (localFiles.contains(relativePath)) {
+ allFiles.add(relativePath);
+ it.remove();
+ localFiles.remove(relativePath);
+ }
+ }
+
+ // detect location all from local files
+ for (Iterator<String> it = localFiles.iterator(); it.hasNext();) {
+ String relativePath = it.next();
+ if (remoteFiles.contains(relativePath)) {
+ allFiles.add(relativePath);
+ it.remove();
+ remoteFiles.remove(relativePath);
+ }
+ }
+
+ populate(connexion, localFiles, VCSEntryLocation.LOCAL, timestamp);
+ populate(connexion, remoteFiles, VCSEntryLocation.REMOTE, timestamp);
+ populate(connexion, allFiles, VCSEntryLocation.ALL, timestamp);
+
+ }
+
+ public void populate(VCSConnexion connexion, List<String> relativeLocalPaths, VCSEntryLocation location, long timestamp) throws VCSException {
+ if (entries == null) {
+ entries = new ArrayList<VCSEntry>();
+ }
+ for (String relativeLocalPath : relativeLocalPaths) {
+ VCSEntry entry = new VCSEntryImpl(connexion, relativeLocalPath);
+ entry.populate(timestamp);
+ entries.add(entry);
+ }
+ }
+
+ public void populate(VCSEntryLocation location, VCSEntry[] entries) {
+ if (this.entries == null) {
+ this.entries = new ArrayList<VCSEntry>();
+ }
+ this.entries.addAll(Arrays.asList(entries));
+ }
+
+ public void refresh(List<VCSEntry> entries, long timestamp) throws IllegalStateException {
+ checkPopulated();
+ }
+
+ public List<VCSEntry> getEntries() throws IllegalStateException {
+ checkPopulated();
+ // always return a copy of the list, to be safe...
+ return new ArrayList<VCSEntry>(entries);
+ }
+
+ public List<VCSEntry> filter(VCSConnexion connexion, List<VCSEntry> entries) {
+ List<VCSEntry> result = new ArrayList<VCSEntry>();
+ for (VCSEntry entry : entries) {
+ if (connexion.equals(entry.getConnexion())) {
+ result.add(entry);
+ }
+ }
+ return result;
+ }
+
+ public List<VCSEntry> filter(VCSEntryLocation location, List<VCSEntry> entries) {
+ if (location == VCSEntryLocation.ALL) {
+ return new ArrayList<VCSEntry>(entries);
+ }
+ List<VCSEntry> result = new ArrayList<VCSEntry>();
+ for (VCSEntry entry : entries) {
+ VCSEntryLocation vcsEntryLocation = entry.getLocation();
+ if (vcsEntryLocation == VCSEntryLocation.ALL || location.equals(vcsEntryLocation)) {
+ result.add(entry);
+ }
+ }
+ return result;
+ }
+
+ public List<VCSEntry> filter(VCSState state, List<VCSEntry> entries) {
+ List<VCSEntry> result = new ArrayList<VCSEntry>();
+ for (VCSEntry entry : entries) {
+ if (state.equals(entry.getState())) {
+ result.add(entry);
+ }
+ }
+ return result;
+ }
+
+ public List<VCSEntry> filter(ListSelectionModel selectionModel, List<VCSEntry> entries) {
+ if (entries.isEmpty() || selectionModel.isSelectionEmpty()) {
+ return Collections.emptyList();
+ }
+ List<VCSEntry> list = new ArrayList<VCSEntry>();
+ for (int i = 0, max = entries.size(); i < max; i++) {
+ if (selectionModel.isSelectedIndex(i)) {
+ list.add(entries.get(i));
+ }
+ }
+ return list;
+ }
+
+ public List<VCSEntry> filter(VCSAction action, List<VCSEntry> entries) {
+ List<VCSEntry> result = new ArrayList<VCSEntry>();
+ for (VCSEntry entry : entries) {
+ if (entry.getState().getActions().contains(action)) {
+ result.add(entry);
+ }
+ }
+ return result;
+ }
+
+ public void clear() {
+ //checkPopulated();
+ if (entries != null) {
+ entries.clear();
+ }
+ }
+
+
+ public VCSAction[] getActions(List<VCSEntry> entries) {
+ List<VCSAction> result = new ArrayList<VCSAction>();
+ for (VCSState vcsFileState : getStates(entries)) {
+ List<VCSAction> action = vcsFileState.getActions();
+ for (VCSAction vcsAction : action) {
+ if (vcsAction != null && !result.contains(vcsAction)) {
+ result.add(vcsAction);
+ }
+ }
+ }
+ return result.toArray(new VCSAction[result.size()]);
+ }
+
+ public VCSState[] getStates(List<VCSEntry> entries) {
+ List<VCSState> result = new ArrayList<VCSState>();
+ for (VCSEntry entry : entries) {
+ VCSState state = entry.getState();
+ if (state != null && !result.contains(state)) {
+ result.add(state);
+ }
+ }
+ return result.toArray(new VCSState[result.size()]);
+ }
+
+ protected List<String> transformToLocal(List<String> relativeRemotePath) {
+ List<String> result = new ArrayList<String>(relativeRemotePath.size());
+ for (String s : relativeRemotePath) {
+ result.add(AbstractVCSHandler.convertToLocalName(s));
+ }
+ return result;
+ }
+
+ protected void checkPopulated() throws IllegalStateException {
+ if (entries == null) {
+ throw new IllegalStateException(this + " was not populated...");
+ }
+ }
+}
Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -0,0 +1,127 @@
+/**
+ * # #% 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.VCSConnexion;
+import org.codelutin.vcs.VCSEntry;
+import org.codelutin.vcs.VCSEntryLocation;
+import org.codelutin.vcs.VCSState;
+import org.codelutin.vcs.VCSException;
+
+import java.io.BufferedReader;
+import java.io.File;
+
+/** @author chemit */
+public class VCSEntryImpl implements VCSEntry {
+
+ protected transient final VCSConnexion connexion;
+
+ protected final String relativeLocalPath;
+
+ protected final String relativeRemotePath;
+
+ protected final File localFile;
+
+ protected VCSState state;
+
+ protected long timestamp;
+
+ protected String rev;
+ private static final long serialVersionUID = -6628119456256629555L;
+
+ public VCSEntryImpl(VCSConnexion connexion, String relativeLocalPath) {
+ this.connexion = connexion;
+ this.relativeLocalPath = relativeLocalPath;
+ this.relativeRemotePath = AbstractVCSHandler.convertToRemoteName(relativeLocalPath);
+ this.localFile = new File(connexion.getWorkingCopy(), relativeLocalPath);
+ }
+
+ public void populate(long timestamp) throws VCSException {
+ this.timestamp = timestamp;
+ this.state = connexion.getState(new File(connexion.getWorkingCopy(), relativeLocalPath), null);
+ }
+
+ public void refresh(long timestamp) throws IllegalStateException, VCSException {
+ checkPopulated();
+ populate(timestamp);
+ }
+
+ public String getRelativeLocalPath() {
+ return relativeLocalPath;
+ }
+
+ public String getRelativeRemotePath() {
+ return relativeRemotePath;
+ }
+
+ public File getFile() {
+ return localFile;
+ }
+
+ public VCSConnexion getConnexion() {
+ return connexion;
+ }
+
+ public VCSEntryLocation getLocation() throws IllegalStateException {
+ checkPopulated();
+ return state.getLocation();
+ }
+
+ public VCSState getState() throws IllegalStateException {
+ checkPopulated();
+ return state;
+ }
+
+ public long getTimestamp() throws IllegalStateException {
+ checkPopulated();
+ return timestamp;
+ }
+
+ public String getRev() throws IllegalStateException {
+ checkPopulated();
+ return rev;
+ }
+
+ public BufferedReader getChangeLog() throws IllegalStateException {
+ checkPopulated();
+ return null;
+ }
+
+ public BufferedReader getDiff() throws IllegalStateException {
+ checkPopulated();
+ return null;
+ }
+
+ public BufferedReader getLocalContent() throws IllegalStateException {
+ checkPopulated();
+ return null;
+ }
+
+ public BufferedReader getRemoteContent() throws IllegalStateException {
+ checkPopulated();
+ return null;
+ }
+
+ public void setState(VCSState state) {
+ this.state = state;
+ }
+
+ protected void checkPopulated() throws IllegalStateException {
+ if (timestamp == -1) {
+ throw new IllegalStateException(this + " was not populated");
+ }
+ }
+
+}
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java 2008-04-05 20:31:28 UTC (rev 354)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java 2008-04-05 20:32:29 UTC (rev 355)
@@ -1,194 +0,0 @@
-/* *##%
-* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin,
-* Benjamin Poussin, 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.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import static org.codelutin.i18n.I18n._;
-import org.codelutin.vcs.VCSHandler;
-import org.codelutin.vcs.VCSRuntimeException;
-import org.codelutin.vcs.VCSTypeRepo;
-
-import java.io.File;
-
-(a)org.codelutin.i18n.I18nable
-public class VCSHelper {
-
- private static final String LOCAL_SEP = File.separator;
- private static final String LOCAL_SEP_PATTERN = "\\".equals(LOCAL_SEP) ?
- LOCAL_SEP + LOCAL_SEP : LOCAL_SEP;
- private static final String REMOTE_SEP = "/";
- private static final String REMOTE_SEP_PATTERN = "/";
-
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(VCSHelper.class);
-
- public static boolean isFileInWorkingCopy(File parent, String name, VCSHandler handler, boolean underVCS) {
- if (parent == null || name == null)
- throw new RuntimeException(VCSHelper.class.getName() +
- "#isFileInWorkingCopy can not be invoked with some " +
- "null parameter but was. [" + parent + "," + name + "," +
- handler + "]");
- return isFileInWorkingCopy(new File(parent, name), handler, underVCS);
- }
-
- public static boolean isFileInWorkingCopy(File file, VCSHandler handler, boolean underVCS) {
- if (file == null || handler == null)
- throw new RuntimeException(VCSHelper.class.getName() +
- "#isFileInWorkingCopy can not be invoked with some " +
- "null parameter but was. [" + file + "," + handler + "]");
- String rootPath = handler.getConfig().getLocalDatabasePath().getAbsolutePath();
- String localPath = file.getAbsolutePath();
- if (localPath.startsWith(rootPath) && !underVCS) {
- return true;
- }
- final File realDir = file.isDirectory() ? file : file.getParentFile();
- return isFileInCheckedDir(realDir, handler);
- }
-
- public static boolean isFileInCheckedDir(File file, VCSHandler handler) {
- if (file == null || handler == null)
- throw new RuntimeException(VCSHelper.class.getName() +
- "#isFileInCheckedDir can not be invoked with some " +
- "null parameter but was. [" + file + "," + handler + "]");
- final File realDir = file.isDirectory() ? file : file.getParentFile();
- return (new File(realDir, handler.getConfLocalDirname()).exists());
-
- }
-
- public static void assertFileInWC(File file, VCSHandler handler) {
- if (!isFileInWorkingCopy(file, handler, false))
- throw new VCSRuntimeException("the file [" + file +
- "] is not in the working copy [" +
- handler.getLocalDatabasePath() + "]");
- }
-
- public static String getRemoteRelativePath(File f, VCSHandler handler) {
- if (!isFileInWorkingCopy(f, handler, false)) return null;
- //System.out.println("file on vcs working copy : "+f);
- String rootPath = handler.getConfig().getLocalDatabasePath().getAbsolutePath();
- String localPath = f.getAbsolutePath();
- if (!localPath.startsWith(rootPath)) return null;
- localPath = localPath.substring(rootPath.length() + 1);
- return convertToRemoteName(localPath);
- }
-
- public static String getLocalRelativePath(String remoteRelativePath, VCSHandler handler) {
- String localPath = convertToLocalName(remoteRelativePath);
- final File file = new File(handler.getConfig().getLocalDatabasePath(), localPath);
- if (!isFileInWorkingCopy(file, handler, false)) return null;
- return localPath;
- }
-
- public static String convertToRemoteName(String txt) {
- return txt.replaceAll(LOCAL_SEP_PATTERN, REMOTE_SEP);
- }
-
- public static String convertToLocalName(String txt) {
- return txt.replaceAll(REMOTE_SEP_PATTERN, LOCAL_SEP);
- }
-
- public static void doCheckoutDir(VCSHandler handler, File... dirs) {
- for (File dir : dirs) {
- try {
- if (!dir.exists() || !isFileInWorkingCopy(dir, handler, true)) {
- handler.checkoutOnlyTheDirectory(dir, null);
- }
- } catch (Exception eee) {
- log.warn(_("lutinvcs.error.checkout.dir", dir), eee);
- break;
- }
- }
- }
-
- /**
- * @param typeRepo the type of repo to used
- * @param remotePath the unclean remote path to use
- * @return the remote path from the old one according to given type repo
- */
- public static String getRemotePath(VCSTypeRepo typeRepo, String remotePath) {
- String result = cleanRemotePath(remotePath);
- switch (typeRepo) {
- case BRANCH:
- case TAG:
- result = remotePath + '/' + typeRepo.getPath();
- break;
- case HEAD:
- result = remotePath;
- break;
- }
- return result;
- }
-
- /**
- * @param typeRepo the type of repo to use
- * @param version the version to use
- * @return the remoteDatabase according to type of repo and version
- */
- public static String getRemoteDatabase(VCSTypeRepo typeRepo, String version) {
- String result = null;
- switch (typeRepo) {
- case BRANCH:
- case TAG:
- result = version;
- break;
- case HEAD:
- result = VCSTypeRepo.HEAD.getPath();
- break;
- }
- return result;
- }
-
- /**
- * to clean a remote path from typeRepo suffix.
- * <p/>
- * For example, having a url svn://XXX/trunk then remove /trunk.
- * <p/>
- * Or if having svn://XXX/branches/YYY then remove /branches/YYY
- * Or if having svn://XXX/tags/YYY then remove /tags/YYY
- *
- * @param remotePath the remote path to clean
- * @return the cleaned remote path
- */
- public static String cleanRemotePath(String remotePath) {
- int pos = remotePath.indexOf(VCSTypeRepo.BRANCH.getPath());
- if (pos > -1) {
- // found a branch
- remotePath = remotePath.substring(0, pos - 1);
- } else {
- pos = remotePath.indexOf(VCSTypeRepo.HEAD.getPath());
- if (pos > -1) {
- // found a branch
- remotePath = remotePath.substring(0, pos - 1);
- } else {
- pos = remotePath.indexOf(VCSTypeRepo.TAG.getPath());
- if (pos > -1) {
- // found a tag
- remotePath = remotePath.substring(0, pos - 1);
- } else {
- // remote path was clean
- }
- }
- }
- return remotePath;
- }
-
-}
\ No newline at end of file
1
0
r354 - trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
by tchemit@users.labs.libre-entreprise.org 05 Apr '08
05 Apr '08
Author: tchemit
Date: 2008-04-05 20:31:28 +0000 (Sat, 05 Apr 2008)
New Revision: 354
Added:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntryLocation.java
Log:
introduce VCSEntryLocation
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntryLocation.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSAction.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntryLocation.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntryLocation.java 2008-04-05 20:31:28 UTC (rev 354)
@@ -0,0 +1,65 @@
+/* ##%
+* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin,
+* Benjamin Poussin, 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 static org.codelutin.i18n.I18n._;
+import static org.codelutin.i18n.I18n.n_;
+
+/**
+ * a VCSEntryLocation represents where a {@link VCSEntry} was found, should be :
+ * <p/>
+ * <ul>
+ * <li>{@link #ALL} : if entry is both on local and on remote</li>
+ * <li>{@link #LOCAL} : if entry is only on local </li>
+ * <li>{@link #REMOTE} : if entryis only on remote</li>
+ * <p/>
+ * </ul>
+ * VCSAction represents an action that can be realized on a file in working
+ * copy or on remote repository.
+ * <p/>
+ * Each <code>VCSAction</code> has 4 properties :
+ * <ul>
+ * <li>libelle : i18n to be used for this action</li>
+ * <li>visible : flag to say if action should be visible in ui</li>
+ * <li>backup : flag to say if this action need backup</li>
+ * <li>write : flag to say if this action need write access to repository</li>
+ * </ul>
+ *
+ * @author chemit
+ */
+(a)org.codelutin.i18n.I18nable
+public enum VCSEntryLocation {
+ ALL(n_("lutinvcs.location.all")),
+ LOCAL(n_("lutinvcs.location.local")),
+ REMOTE(n_("lutinvcs.location.remote")),
+ UNKNOW(n_("lutinvcs.location.unknown"));
+
+ /** libelle of location */
+ private final String libelle;
+
+
+ public String getLibelle() {
+ return _(libelle);
+ }
+
+ VCSEntryLocation(String libelle) {
+ this.libelle = libelle;
+ }
+}
\ No newline at end of file
1
0
r353 - in trunk/lutinvcs: lutinvcs-core/src/main/java/org/codelutin/vcs lutinvcs-provider-cvs/src/main/resources/META-INF/services lutinvcs-provider-mock/src/main/resources/META-INF/services lutinvcs-provider-svn/src/main/resources/META-INF/services
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
04 Apr '08
Author: tchemit
Date: 2008-04-04 21:54:55 +0000 (Fri, 04 Apr 2008)
New Revision: 353
Added:
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider
trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider
trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider
Removed:
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider
trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider
trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider
Modified:
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java
Log:
refactor provider to act as handler and connexion factory
Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java 2008-04-04 21:48:53 UTC (rev 352)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java 2008-04-04 21:54:55 UTC (rev 353)
@@ -91,7 +91,7 @@
VCSHandlerFactory factory = getInstance();
assertConfigIsInit(config);
- VCSProvider<?> provider = factory.getProvider(config.getType().name().toUpperCase());
+ VCSProvider<?, ?> provider = factory.getProvider(config.getType().name().toUpperCase());
if (provider == null) {
throw new IllegalArgumentException("could not find a provider for type " + config.getType());
}
Deleted: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider 2008-04-04 21:48:53 UTC (rev 352)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider 2008-04-04 21:54:55 UTC (rev 353)
@@ -1 +0,0 @@
-org.codelutin.vcs.CVSProvider
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider (from rev 347, trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider)
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider (rev 0)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider 2008-04-04 21:54:55 UTC (rev 353)
@@ -0,0 +1 @@
+org.codelutin.vcs.CVSProvider
\ No newline at end of file
Deleted: trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider 2008-04-04 21:48:53 UTC (rev 352)
+++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider 2008-04-04 21:54:55 UTC (rev 353)
@@ -1 +0,0 @@
-org.codelutin.vcs.MockProvider
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider (from rev 348, trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider)
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider (rev 0)
+++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider 2008-04-04 21:54:55 UTC (rev 353)
@@ -0,0 +1 @@
+org.codelutin.vcs.MockProvider
\ No newline at end of file
Deleted: trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider 2008-04-04 21:48:53 UTC (rev 352)
+++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider 2008-04-04 21:54:55 UTC (rev 353)
@@ -1 +0,0 @@
-org.codelutin.vcs.SVNProvider
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider (from rev 348, trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSHandlerProvider)
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider (rev 0)
+++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/resources/META-INF/services/org.codelutin.vcs.VCSProvider 2008-04-04 21:54:55 UTC (rev 353)
@@ -0,0 +1 @@
+org.codelutin.vcs.SVNProvider
\ No newline at end of file
1
0
r352 - 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-mock/src/main/java/org/codelutin/vcs lutinvcs-provider-svn/src/main/java/org/codelutin/vcs
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
04 Apr '08
Author: tchemit
Date: 2008-04-04 21:48:53 +0000 (Fri, 04 Apr 2008)
New Revision: 352
Modified:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java
trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java
trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java
Log:
refactor provider to act as handler and connexion factory
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-04 21:43:01 UTC (rev 351)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-04 21:48:53 UTC (rev 352)
@@ -19,7 +19,7 @@
/**
* The contract to be realized to provide vcs communication.
* <p/>
- * Atcs as a handler and connexion factory.
+ * Acts as a handler and connexion factory and manage a single handler instance
*
* @author chemit
* @see VCSHandler
@@ -36,6 +36,14 @@
/**
* return a new VCSHandler instance for given config.
*
+ * @return the cached instance of handler
+ * @throws IllegalStateException if handler was not init via {@link #newInstance(VCSConfig)}
+ */
+ H getHandler() throws IllegalStateException;
+
+ /**
+ * return a new VCSHandler instance for given config.
+ *
* @param config svn handler config
* @return the new instance
* @throws IllegalStateException if any pb while init handler
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java 2008-04-04 21:43:01 UTC (rev 351)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java 2008-04-04 21:48:53 UTC (rev 352)
@@ -16,12 +16,10 @@
import org.codelutin.vcs.VCSConfig;
import org.codelutin.vcs.VCSConnexion;
-import org.codelutin.vcs.VCSConnexionMode;
import org.codelutin.vcs.VCSHandler;
import org.codelutin.vcs.VCSProvider;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -50,11 +48,16 @@
public List<C> getConnexions() {
if (connexions == null) {
- connexions = new ArrayList<C>();
+ connexions = new java.util.ArrayList<C>();
}
return connexions;
}
+ public H getHandler() throws IllegalStateException {
+ checkHandlerInit();
+ return handler;
+ }
+
public H newInstance(VCSConfig config) throws IllegalStateException {
if (handler != null) {
return handler;
@@ -72,7 +75,9 @@
}
}
- public C newConnection(VCSConnexionMode mode, VCSConfig config) {
- return null;
+ protected void checkHandlerInit() throws IllegalStateException {
+ if (handler == null) {
+ throw new IllegalStateException("handler was not init in " + this);
+ }
}
}
Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java 2008-04-04 21:43:01 UTC (rev 351)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java 2008-04-04 21:48:53 UTC (rev 352)
@@ -26,12 +26,14 @@
super("CVS", CVSHandler.class);
}
+ @Override
public CVSHandler newInstance(VCSConfig config) {
CVSHelper.setConfig(config);
return super.newInstance(config);
}
public CVSConnexion newConnection(VCSConnexionMode mode, VCSConfig config) {
+ checkHandlerInit();
return null;
}
}
\ No newline at end of file
Modified: trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java 2008-04-04 21:43:01 UTC (rev 351)
+++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java 2008-04-04 21:48:53 UTC (rev 352)
@@ -26,6 +26,7 @@
}
public MockConnexion newConnection(VCSConnexionMode mode, VCSConfig config) {
+ checkHandlerInit();
return null;
}
}
\ No newline at end of file
Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java 2008-04-04 21:43:01 UTC (rev 351)
+++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java 2008-04-04 21:48:53 UTC (rev 352)
@@ -26,6 +26,7 @@
}
public AbstractVCSConnexion newConnection(VCSConnexionMode mode, VCSConfig config) {
+ checkHandlerInit();
return null;
}
}
1
0
r351 - 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-mock/src/main/java/org/codelutin/vcs lutinvcs-provider-svn/src/main/java/org/codelutin/vcs
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
04 Apr '08
Author: tchemit
Date: 2008-04-04 21:43:01 +0000 (Fri, 04 Apr 2008)
New Revision: 351
Added:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java
Modified:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java
trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java
trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java
Log:
refactor provider to act as handler and connexion factory
Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-04 21:26:19 UTC (rev 350)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-04 21:43:01 UTC (rev 351)
@@ -14,6 +14,8 @@
*/
package org.codelutin.vcs;
+import java.util.List;
+
/**
* The contract to be realized to provide vcs communication.
* <p/>
@@ -28,13 +30,17 @@
/** @return the identifier of the vcs provider (eg SVN, CVS, MOCK) */
String getName();
+ /** @return list of known connexions. */
+ List<C> getConnexions();
+
/**
* return a new VCSHandler instance for given config.
*
* @param config svn handler config
* @return the new instance
+ * @throws IllegalStateException if any pb while init handler
*/
- H newInstance(VCSConfig config);
+ H newInstance(VCSConfig config) throws IllegalStateException;
/**
* @param mode the mode required
Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java 2008-04-04 21:43:01 UTC (rev 351)
@@ -0,0 +1,78 @@
+/**
+ * # #% 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.VCSConfig;
+import org.codelutin.vcs.VCSConnexion;
+import org.codelutin.vcs.VCSConnexionMode;
+import org.codelutin.vcs.VCSHandler;
+import org.codelutin.vcs.VCSProvider;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * base implementation of provider with a cached handler and list of connexions
+ *
+ * @author chemit
+ */
+public abstract class AbstractVCSProvider<H extends VCSHandler, C extends VCSConnexion> implements VCSProvider<H, C> {
+
+ protected H handler;
+
+ protected List<C> connexions;
+
+ protected final String name;
+
+ private final Class<H> handlerImpl;
+
+ protected AbstractVCSProvider(String name, Class<H> handlerImpl) {
+ this.name = name;
+ this.handlerImpl = handlerImpl;
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ public List<C> getConnexions() {
+ if (connexions == null) {
+ connexions = new ArrayList<C>();
+ }
+ return connexions;
+ }
+
+ public H newInstance(VCSConfig config) throws IllegalStateException {
+ if (handler != null) {
+ return handler;
+ }
+ try {
+ return handlerImpl.getConstructor(VCSConfig.class).newInstance(config);
+ } catch (InstantiationException e) {
+ throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ } catch (InvocationTargetException e) {
+ throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("could not instanciate the handler " + handlerImpl + " for reason " + e.getMessage());
+ }
+ }
+
+ public C newConnection(VCSConnexionMode mode, VCSConfig config) {
+ return null;
+ }
+}
Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java 2008-04-04 21:26:19 UTC (rev 350)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSProvider.java 2008-04-04 21:43:01 UTC (rev 351)
@@ -14,20 +14,21 @@
*/
package org.codelutin.vcs;
+import org.codelutin.vcs.impl.cvs.CVSConnexion;
import org.codelutin.vcs.impl.cvs.CVSHandler;
import org.codelutin.vcs.impl.cvs.CVSHelper;
-import org.codelutin.vcs.impl.cvs.CVSConnexion;
+import org.codelutin.vcs.util.AbstractVCSProvider;
/** @author chemit */
-public class CVSProvider implements VCSProvider<CVSHandler, CVSConnexion> {
+public class CVSProvider extends AbstractVCSProvider<CVSHandler, CVSConnexion> {
- public String getName() {
- return "CVS";
+ public CVSProvider() {
+ super("CVS", CVSHandler.class);
}
public CVSHandler newInstance(VCSConfig config) {
CVSHelper.setConfig(config);
- return new CVSHandler(config);
+ return super.newInstance(config);
}
public CVSConnexion newConnection(VCSConnexionMode mode, VCSConfig config) {
Modified: trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java 2008-04-04 21:26:19 UTC (rev 350)
+++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockProvider.java 2008-04-04 21:43:01 UTC (rev 351)
@@ -14,20 +14,17 @@
*/
package org.codelutin.vcs;
-import org.codelutin.vcs.impl.mock.MockVCSHandler;
import org.codelutin.vcs.impl.mock.MockConnexion;
+import org.codelutin.vcs.impl.mock.MockVCSHandler;
+import org.codelutin.vcs.util.AbstractVCSProvider;
/** @author chemit */
-public class MockProvider implements VCSProvider<MockVCSHandler, MockConnexion> {
+public class MockProvider extends AbstractVCSProvider<MockVCSHandler, MockConnexion> {
- public String getName() {
- return "MOCK";
+ public MockProvider() {
+ super("MOCK", MockVCSHandler.class);
}
- public MockVCSHandler newInstance(VCSConfig config) {
- return new MockVCSHandler(config);
- }
-
public MockConnexion newConnection(VCSConnexionMode mode, VCSConfig config) {
return null;
}
Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java 2008-04-04 21:26:19 UTC (rev 350)
+++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/SVNProvider.java 2008-04-04 21:43:01 UTC (rev 351)
@@ -16,15 +16,13 @@
import org.codelutin.vcs.impl.svn.SVNHandler;
import org.codelutin.vcs.util.AbstractVCSConnexion;
+import org.codelutin.vcs.util.AbstractVCSProvider;
/** @author chemit */
-public class SVNProvider implements VCSProvider<SVNHandler, AbstractVCSConnexion> {
- public String getName() {
- return "SVN";
- }
+public class SVNProvider extends AbstractVCSProvider<SVNHandler, AbstractVCSConnexion> {
- public SVNHandler newInstance(VCSConfig config) {
- return new SVNHandler(config);
+ public SVNProvider() {
+ super("SVN", SVNHandler.class);
}
public AbstractVCSConnexion newConnection(VCSConnexionMode mode, VCSConfig config) {
1
0
r350 - in trunk/lutinvcs: lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs lutinvcs-provider-mock/src/main/java/org/codelutin/vcs
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
by tchemit@users.labs.libre-entreprise.org 04 Apr '08
04 Apr '08
Author: tchemit
Date: 2008-04-04 21:26:19 +0000 (Fri, 04 Apr 2008)
New Revision: 350
Removed:
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
Log:
refactor provider to act as handler and connexion factory
Deleted: 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 2008-04-04 21:26:10 UTC (rev 349)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSConnexion.java 2008-04-04 21:26:19 UTC (rev 350)
@@ -1,34 +0,0 @@
-/**
- * # #% 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
Deleted: 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 2008-04-04 21:26:10 UTC (rev 349)
+++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/MockConnexion.java 2008-04-04 21:26:19 UTC (rev 350)
@@ -1,37 +0,0 @@
-/**
- * # #% 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
1
0