[Buix-commits] r334 - in trunk/lutinvcs: lutinvcs-api/src/main/java/org/codelutin/vcs lutinvcs-api/src/main/resources/i18n lutinvcs-core/src/main/java/org/codelutin/vcs
Author: tchemit Date: 2008-04-04 19:32:29 +0000 (Fri, 04 Apr 2008) New Revision: 334 Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java Removed: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHelper.java Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandler.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: move AbstractVCSHandler to api module, in thaht way provider modules only depends on api module :) Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java 2008-04-04 19:18:38 UTC (rev 333) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java 2008-04-04 19:32:29 UTC (rev 334) @@ -31,6 +31,7 @@ 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. @@ -179,4 +180,28 @@ if (file == null || !file.exists()) throw new VCSRuntimeException(msg + " (file passed : [" + file + "])"); } + + /** + * 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 isConnected() { + return getConfig().isConnected(); + } + + public boolean hasWriteAccess() { + return !getConfig().isReadOnly(); + } } 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-04 19:18:38 UTC (rev 333) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandler.java 2008-04-04 19:32:29 UTC (rev 334) @@ -24,6 +24,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.Collection; +import java.util.EnumSet; import java.util.List; /** @@ -323,4 +324,10 @@ void open(); void close(); + + EnumSet<VCSAction> getAuthorizedActions(); + + public boolean isConnected(); + + public boolean hasWriteAccess(); } \ No newline at end of file Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java (from rev 331, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHelper.java) =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java 2008-04-04 19:32:29 UTC (rev 334) @@ -0,0 +1,191 @@ +/* *##% +* 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 static org.codelutin.i18n.I18n._; + +import java.io.File; + +@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 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-04 19:18:38 UTC (rev 333) +++ trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-en_GB.properties 2008-04-04 19:32:29 UTC (rev 334) @@ -8,6 +8,7 @@ lutinvcs.action.refresh= lutinvcs.action.revert=revert lutinvcs.action.update=update +lutinvcs.error.checkout.dir= lutinvcs.state.missing=missing lutinvcs.state.modified=modified lutinvcs.state.outofdate=out of date 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-04 19:18:38 UTC (rev 333) +++ trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-fr_FR.properties 2008-04-04 19:32:29 UTC (rev 334) @@ -8,6 +8,7 @@ lutinvcs.action.refresh=Rafra\u00EEchir lutinvcs.action.revert=Rollback lutinvcs.action.update=Update +lutinvcs.error.checkout.dir= lutinvcs.state.missing=non pr\u00E9sent lutinvcs.state.modified=modifi\u00E9 lutinvcs.state.outofdate=obsol\u00E8te Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHelper.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHelper.java 2008-04-04 19:18:38 UTC (rev 333) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHelper.java 2008-04-04 19:32:29 UTC (rev 334) @@ -1,216 +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 static org.codelutin.i18n.I18n._; - -import java.io.File; -import java.util.EnumSet; - -@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 = VCSHandlerFactory.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; - } - - - /** - * Obtain the set of permitted vcs actions. - * - * @return the EnumSet of authorized action according to current vcs config - */ - public static 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 static boolean isConnected() { - return VCSHandlerFactory.getConfig().isConnected(); - } - - public static boolean hasWriteAccess() { - return !VCSHandlerFactory.getConfig().isReadOnly(); - } -} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org