r384 - in trunk/lutinvcs/lutinvcs-api/src/main: java/org/codelutin/vcs java/org/codelutin/vcs/util resources/i18n
Author: tchemit Date: 2008-04-06 09:34:44 +0000 (Sun, 06 Apr 2008) New Revision: 384 Modified: 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 trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-en_GB.properties trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-fr_FR.properties Log: improve design : no more shared handler instance in provider each connexion has his own handler handler has a cached connexion 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-06 09:33:56 UTC (rev 383) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSProvider.java 2008-04-06 09:34:44 UTC (rev 384) @@ -30,29 +30,21 @@ /** @return the identifier of the vcs provider (eg SVN, CVS, MOCK) */ String getName(); - /** - * init the provider. (instanciate handler) - * <p/> - * This method MUST be invoked before asking any connexion. - */ - void init(); + /** @return the class of implementation of handler to use for this provider */ + Class<H> getHandlerImpl(); - /** - * return a new VCSHandler instance for given config. - * - * @return the cached instance of handler - * @throws IllegalStateException if provider was not init via {@link #init()} - */ - H getHandler() throws IllegalStateException; + /** @return the imclass of implementation of connexion to use for this provider */ + Class<C> getConnexionImpl(); /** * Instanciate an new connexion for a given config, and init it. + * <p/> + * Note : <b>After this method connexion is init, but not opened.</b> * * @param mode the mode required * @param config the config to be used * @return the new connexion initialized <b>but not opened</b>. - * @throws IllegalStateException if provider was not init via {@link #init()} */ - C newConnection(VCSConnexionMode mode, VCSConnexionConfig config) throws IllegalStateException; + C newConnection(VCSConnexionMode mode, VCSConnexionConfig config); } 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-06 09:33:56 UTC (rev 383) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSConnexion.java 2008-04-06 09:34:44 UTC (rev 384) @@ -16,18 +16,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import static org.codelutin.i18n.I18n._; import org.codelutin.util.ListenerSet; -import org.codelutin.vcs.type.ConnectionState; -import org.codelutin.vcs.type.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.type.VCSConnexionMode; import org.codelutin.vcs.VCSException; import org.codelutin.vcs.VCSHandler; -import org.codelutin.vcs.VCSProvider; +import org.codelutin.vcs.type.ConnectionState; +import org.codelutin.vcs.type.VCSConnexionMode; import org.codelutin.vcs.type.VCSState; import java.io.File; @@ -36,11 +35,10 @@ import java.io.IOException; import java.net.URI; import java.util.Collection; -import java.util.EnumSet; import java.util.List; /** @author chemit */ -public abstract class AbstractVCSConnexion implements VCSConnexion { +public abstract class AbstractVCSConnexion<H extends VCSHandler> implements VCSConnexion<H> { /** to use log facility, just put in your code: log.info(\"...\"); */ static protected final Log log = LogFactory.getLog(AbstractVCSConnexion.class); @@ -49,26 +47,25 @@ protected URI remoteRoot; protected VCSConnexionMode mode; protected ConnectionState state; - protected VCSConnexionConfig config; + protected H handler; - protected VCSProvider<AbstractVCSConnexion, ?> provider; - protected ListenerSet<VCSConnexionEventListener> listeners = new ListenerSet<VCSConnexionEventListener>(); @SuppressWarnings({"unchecked"}) - protected AbstractVCSConnexion(VCSConnexionMode mode, VCSProvider provider) { + protected AbstractVCSConnexion(VCSConnexionMode mode, H handler) { this.mode = mode; - this.provider = provider; + this.handler = handler; + this.handler.setConnexion(this); } - public VCSHandler<AbstractVCSConnexion> getHandler() throws IllegalStateException { - return getProvider().getHandler(); + public H getHandler() throws IllegalStateException { + return handler; } - public VCSProvider<AbstractVCSConnexion, ?> getProvider() { + /*public VCSProvider<AbstractVCSConnexion, ?> getProvider() { return provider; - } + }*/ public File getWorkingCopy() throws IllegalStateException { checkInit(); @@ -112,158 +109,147 @@ listeners.remove(l); } + + 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); + } + + // --------------------------------------------------------------------- + // handler delegate methods + // --------------------------------------------------------------------- + public void initWorkingCopy() throws VCSException { - getHandler().initWorkingCopy(this); + handler.initWorkingCopy(); } public void deleteWorkingCopy() { - getHandler().deleteWorkingCopy(this); + handler.deleteWorkingCopy(); } public FilenameFilter getVersionnableFilenameFilter() { - return getHandler().getVersionnableFilenameFilter(); + return handler.getVersionnableFilenameFilter(); } public FileFilter getVersionnableFileFilter() { - return getHandler().getVersionnableFileFilter(); + return handler.getVersionnableFileFilter(); } public String getConfLocalDirname() { - return getHandler().getConfLocalDirname(); + return handler.getConfLocalDirname(); } public String getConfLocalEntriesFilename() { - return getHandler().getConfLocalEntriesFilename(); + return handler.getConfLocalEntriesFilename(); } public VCSState getState(File fileState, Collection tmp) throws VCSException { - return getHandler().getState(this, fileState, tmp); + return handler.getState(fileState, tmp); } public VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException { - return getHandler().getState(this, file, tmp, noremote); + return handler.getState(file, tmp, noremote); } public boolean isOnRemote(File file) { - return getHandler().isOnRemote(this, file); + return handler.isOnRemote(file); } public boolean isUpToDate(File file) throws VCSException { - return getHandler().isUpToDate(this, file); + return handler.isUpToDate(file); } public boolean isVersionnableFile(File file) { - return getHandler().isVersionnableFile(this, file); + return handler.isVersionnableFile(file); } public void makeRemoteDir(String commitMessage, String... dirNames) throws VCSException { - getHandler().makeRemoteDir(this, commitMessage, dirNames); + handler.makeRemoteDir(commitMessage, dirNames); } public void deleteRemoteDir(String commitMessage, String... dirNames) throws VCSException { - getHandler().deleteRemoteDir(this, commitMessage, dirNames); + handler.deleteRemoteDir(commitMessage, dirNames); } public long add(List<File> files, String msg) throws VCSException { - return getHandler().add(this, files, msg); + return handler.add(files, msg); } public void delete(List<File> files, String msg) throws VCSException { - getHandler().delete(this, files, msg); + handler.delete(files, msg); } public void revert(List<File> files) throws VCSException { - getHandler().revert(this, files); + handler.revert(files); } public long commit(List<File> files, String msg) throws VCSException { - return getHandler().commit(this, files, msg); + return handler.commit(files, msg); } public void update(File file, Object revision) throws VCSException { - getHandler().update(this, file, revision); + handler.update(file, revision); } public void update(File file) throws VCSException { - getHandler().update(this, file); + handler.update(file); } public void checkout(File destDir, String module, boolean recurse) throws VCSException { - getHandler().checkout(this, destDir, module, recurse); + handler.checkout(destDir, module, recurse); } public void checkoutFile(File destDir, String module) throws VCSException { - getHandler().checkoutFile(this, destDir, module); + handler.checkoutFile(destDir, module); } public long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException { - return getHandler().checkoutOnlyTheDirectory(this, root, revision); + return handler.checkoutOnlyTheDirectory(root, revision); } public List<String> getRemoteStorageNames(File directory) throws VCSException { - return getHandler().getRemoteStorageNames(this, directory); + return handler.getRemoteStorageNames(directory); } public List<String> getLocalStorageNames(File directory) { - return getHandler().getLocalStorageNames(this, directory); + return handler.getLocalStorageNames(directory); } public Object getRevision(File f) throws VCSException { - return getHandler().getRevision(this, f); + return handler.getRevision(f); } public List getLog(Object startRevision, Object endRevision, File file) throws VCSException { - return getHandler().getLog(this, startRevision, endRevision, file); + return handler.getLog(startRevision, endRevision, file); } public String getFileContent(File file, Object revision) throws VCSException, IOException { - return getHandler().getFileContent(this, file, revision); + return handler.getFileContent(file, revision); } public String getChangeLog(File file) throws VCSException { - return getHandler().getChangeLog(this, file); + return handler.getChangeLog(file); } public String getDiff(File file) throws VCSException, IOException { - return getHandler().getDiff(this, file); + return handler.getDiff(file); } public String getDiff(File file, Object againstRevision) throws VCSException, IOException { - return getHandler().getDiff(this, file, againstRevision); + return handler.getDiff(file, againstRevision); } public boolean hasProtocoleChanged() throws VCSException { - return getHandler().hasProtocoleChanged(this); + return handler.hasProtocoleChanged(); } - /** - * 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) { @@ -280,14 +266,15 @@ protected void checkInit() throws IllegalStateException { if (state == null) { - throw new IllegalStateException("connexion was not init"); + throw new IllegalStateException(_("lutinvcs.error.connexion.noinit", this)); } } protected void checkOpen() throws IllegalStateException { checkInit(); if (!isOpen()) { - throw new IllegalStateException("connexion was not init"); + throw new IllegalStateException(_("lutinvcs.error.connexion.noopen", this)); + } } 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-06 09:33:56 UTC (rev 383) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java 2008-04-06 09:34:44 UTC (rev 384) @@ -54,6 +54,7 @@ protected final FileFilter versionnableFileFilter; protected final String confLocalDirName; protected final String confLocalEntriesFilename; + protected C connexion; protected AbstractVCSHandler(final String vCSConfLocalDirName, String vCSConfLocalEntriesFilename) { this.confLocalDirName = vCSConfLocalDirName; @@ -70,6 +71,10 @@ }; } + public void setConnexion(C connexion) { + this.connexion = connexion; + } + public FilenameFilter getVersionnableFilenameFilter() { return versionnableFilenameFilter; } @@ -86,19 +91,19 @@ return confLocalEntriesFilename; } - public boolean isVersionnableFile(C connexion, File file) { + public boolean isVersionnableFile(File file) { assertFileExists(file, "file is empty or non existant"); return !confLocalDirName.equalsIgnoreCase(file.getName()); } - public void deleteWorkingCopy(C connexion) { + public void deleteWorkingCopy() { if (connexion.getConfig().getLocalDatabasePath().exists()) { FileUtil.deleteRecursively(connexion.getConfig().getLocalDatabasePath()); connexion.getConfig().getLocalDatabasePath().delete(); } } - public List<String> getLocalStorageNames(C connexion, File directory) { + public List<String> getLocalStorageNames(File directory) { List<String> result = new ArrayList<String>(); if (directory.exists()) { getFiles0(directory, result, ""); @@ -107,11 +112,11 @@ return result; } - public void doCheckoutDir(C connexion, File... dirs) { + public void doCheckoutDir(File... dirs) { for (File dir : dirs) { try { - if (!dir.exists() || !isFileInWorkingCopy(dir, this, connexion, true)) { - checkoutOnlyTheDirectory(connexion, dir, null); + if (!dir.exists() || !isFileInWorkingCopy(dir, true)) { + checkoutOnlyTheDirectory(dir, null); } } catch (Exception eee) { log.warn(_("lutinvcs.error.checkout.dir", dir), eee); @@ -140,40 +145,40 @@ } } - public static boolean isFileInWorkingCopy(File parent, String name, VCSHandler handler, VCSConnexion connexion, boolean underVCS) { + public boolean isFileInWorkingCopy(File parent, String name, 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); + this + "]"); + return isFileInWorkingCopy(new File(parent, name), 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 + "]"); + public boolean isFileInWorkingCopy(File file, boolean underVCS) { + if (file == null) + throw new RuntimeException(AbstractVCSHandler.class.getName() + "#isFileInWorkingCopy can not be invoked with some null parameter but was. [" + file + "," + this + "]"); 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); + return isFileInCheckedDir(realDir); } - 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 + "]"); + public boolean isFileInCheckedDir(File file) { + if (file == null) + throw new RuntimeException(AbstractVCSHandler.class.getName() + "#isFileInCheckedDir can not be invoked with some null parameter but was. [" + file + "," + this + "]"); final File realDir = file.isDirectory() ? file : file.getParentFile(); - return (new File(realDir, handler.getConfLocalDirname()).exists()); + return (new File(realDir, getConfLocalDirname()).exists()); } - public static void assertFileInWC(File file, VCSHandler handler, VCSConnexion connexion) { - if (!isFileInWorkingCopy(file, handler, connexion, false)) + public void assertFileInWC(File file) { + if (!isFileInWorkingCopy(file, 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; + public String getRemoteRelativePath(File f) { + if (!isFileInWorkingCopy(f, false)) return null; //System.out.println("file on vcs working copy : "+f); String rootPath = connexion.getConfig().getLocalDatabasePath().getAbsolutePath(); String localPath = f.getAbsolutePath(); @@ -182,10 +187,10 @@ return convertToRemoteName(localPath); } - public static String getLocalRelativePath(String remoteRelativePath, VCSHandler handler, VCSConnexion connexion) { + public String getLocalRelativePath(String remoteRelativePath) { String localPath = convertToLocalName(remoteRelativePath); final File file = new File(connexion.getConfig().getLocalDatabasePath(), localPath); - if (!isFileInWorkingCopy(file, handler, connexion, false)) return null; + if (!isFileInWorkingCopy(file, false)) return null; return localPath; } 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-06 09:33:56 UTC (rev 383) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSProvider.java 2008-04-06 09:34:44 UTC (rev 384) @@ -22,17 +22,11 @@ import org.codelutin.vcs.type.VCSConnexionMode; /** - * base implementation of provider with a cached common handler for all connexions. + * base implementation of provider. * * @author chemit */ -public abstract class AbstractVCSProvider<C extends VCSConnexion, H extends VCSHandler<C>> implements VCSProvider<C, H> { - /** - * shared cached instance of handler to use for this provider. - * <p/> - * The handler can be used by all connexions for this provider - */ - protected H handler; +public class AbstractVCSProvider<C extends VCSConnexion, H extends VCSHandler<C>> implements VCSProvider<C, H> { /** name of ne provider */ protected final String name; @@ -53,15 +47,26 @@ return name; } - public H getHandler() throws IllegalStateException { - checkHandlerInit(); - return handler; + public Class<C> getConnexionImpl() { + return connexionImpl; } - public C newConnection(VCSConnexionMode mode, VCSConnexionConfig config) throws IllegalStateException { - checkHandlerInit(); + public Class<H> getHandlerImpl() { + return handlerImpl; + } + + public C newConnection(VCSConnexionMode mode, VCSConnexionConfig config) { + + H handler; + C connexion; + try { - C connexion = connexionImpl.getConstructor(VCSConnexionMode.class, getClass()).newInstance(mode, this); + handler = handlerImpl.newInstance(); + } catch (Exception e) { + throw new RuntimeException(_("lutinvcs.error.provider.init.handler", handlerImpl, this, e.getCause())); + } + try { + connexion = connexionImpl.getConstructor(VCSConnexionMode.class, handlerImpl).newInstance(mode, handler); connexion.init(config); return connexion; } catch (Exception e) { @@ -69,20 +74,4 @@ } } - public void init() { - if (handler == null) { - try { - handler = handlerImpl.newInstance(); - } catch (Exception e) { - throw new RuntimeException(_("lutinvcs.error.provider.init.handler", handlerImpl, this, e.getCause())); - } - } - } - - protected void checkHandlerInit() throws IllegalStateException { - if (handler == null) { - throw new IllegalStateException(_("lutinvcs.error.provider.noinit", handler, this)); - } - } - } Modified: trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-en_GB.properties =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-en_GB.properties 2008-04-06 09:33:56 UTC (rev 383) +++ trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-en_GB.properties 2008-04-06 09:34:44 UTC (rev 384) @@ -9,9 +9,10 @@ lutinvcs.action.revert=revert lutinvcs.action.update=update lutinvcs.error.checkout.dir=Can''t checkout dir {0} +lutinvcs.error.connexion.noinit=connexion {0} was not init +lutinvcs.error.connexion.noopen=connexion {0} was not opened lutinvcs.error.provider.init.connexion=could not instanciate connexion {0}, for provider {1}, reason\: {2} lutinvcs.error.provider.init.handler=could not instanciate handler {0}, for provider {1}, reason\: {2} -lutinvcs.error.provider.noinit=handler {0} was not init for provider {1} lutinvcs.location.all=All lutinvcs.location.local=Local lutinvcs.location.remote=Remote Modified: trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-fr_FR.properties =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-fr_FR.properties 2008-04-06 09:33:56 UTC (rev 383) +++ trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-fr_FR.properties 2008-04-06 09:34:44 UTC (rev 384) @@ -9,9 +9,10 @@ lutinvcs.action.revert=Rollback lutinvcs.action.update=Update lutinvcs.error.checkout.dir=Ne peut pas uploader le fichier ''{0}'' +lutinvcs.error.connexion.noinit=La connexion {0} n''a pas \u00E9t\u00E9 initialis\u00E9e +lutinvcs.error.connexion.noopen=La connexion {0} n''a pas \u00E9t\u00E9 ouverte lutinvcs.error.provider.init.connexion=Erreur lors de l''instanciation de la connexion {0}, provider {1}, cause\: {2} lutinvcs.error.provider.init.handler=Erreur lors de l''instanciation du handler {0}, provider {1}, cause\: {2} -lutinvcs.error.provider.noinit=Le handler {0} n''a pas \u00E9t\u00E9 initialis\u00E9 pour le provider {1} lutinvcs.location.all=All lutinvcs.location.local=Local lutinvcs.location.remote=Remote
participants (1)
-
tchemit@users.labs.libre-entreprise.org