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
April 2008
- 1 participants
- 373 discussions
r343 - in trunk/lutinvcs: lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/impl/mock lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn
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 20:10:40 +0000 (Fri, 04 Apr 2008)
New Revision: 343
Modified:
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java
trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/impl/mock/MockVCSHandler.java
trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java
trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java
Log:
move to util package all helper classes and abstract implementations
Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java 2008-04-04 20:10:16 UTC (rev 342)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHandler.java 2008-04-04 20:10:40 UTC (rev 343)
@@ -2,7 +2,7 @@
import static org.codelutin.i18n.I18n._;
import org.codelutin.util.FileUtil;
-import org.codelutin.vcs.AbstractVCSHandler;
+import org.codelutin.vcs.util.AbstractVCSHandler;
import org.codelutin.vcs.VCSConfig;
import org.codelutin.vcs.VCSException;
import org.codelutin.vcs.VCSState;
Modified: trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/impl/mock/MockVCSHandler.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/impl/mock/MockVCSHandler.java 2008-04-04 20:10:16 UTC (rev 342)
+++ trunk/lutinvcs/lutinvcs-provider-mock/src/main/java/org/codelutin/vcs/impl/mock/MockVCSHandler.java 2008-04-04 20:10:40 UTC (rev 343)
@@ -14,7 +14,7 @@
*/
package org.codelutin.vcs.impl.mock;
-import org.codelutin.vcs.AbstractVCSHandler;
+import org.codelutin.vcs.util.AbstractVCSHandler;
import org.codelutin.vcs.VCSConfig;
import org.codelutin.vcs.VCSException;
import org.codelutin.vcs.VCSState;
Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java 2008-04-04 20:10:16 UTC (rev 342)
+++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHandler.java 2008-04-04 20:10:40 UTC (rev 343)
@@ -20,11 +20,11 @@
package org.codelutin.vcs.impl.svn;
import static org.codelutin.i18n.I18n._;
-import org.codelutin.vcs.AbstractVCSHandler;
+import org.codelutin.vcs.util.AbstractVCSHandler;
import org.codelutin.vcs.VCSConfig;
import org.codelutin.vcs.VCSException;
-import org.codelutin.vcs.VCSHelper;
-import static org.codelutin.vcs.VCSHelper.isFileInCheckedDir;
+import org.codelutin.vcs.util.VCSHelper;
+import static org.codelutin.vcs.util.VCSHelper.isFileInCheckedDir;
import org.codelutin.vcs.VCSRuntimeException;
import org.codelutin.vcs.VCSState;
import static org.codelutin.vcs.VCSState.OUT_OF_DATE;
Modified: trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java 2008-04-04 20:10:16 UTC (rev 342)
+++ trunk/lutinvcs/lutinvcs-provider-svn/src/main/java/org/codelutin/vcs/impl/svn/SVNHelper.java 2008-04-04 20:10:40 UTC (rev 343)
@@ -22,7 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.vcs.VCSException;
-import org.codelutin.vcs.VCSHelper;
+import org.codelutin.vcs.util.VCSHelper;
import org.codelutin.vcs.VCSRuntimeException;
import org.codelutin.vcs.VCSTypeRepo;
import org.tmatesoft.svn.core.SVNCancelException;
1
0
r342 - in trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs: . util
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 20:10:16 +0000 (Fri, 04 Apr 2008)
New Revision: 342
Added:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java
Removed:
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java
trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java
Log:
move to util package all helper classes and abstract implementations
Deleted: 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:37:59 UTC (rev 341)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java 2008-04-04 20:10:16 UTC (rev 342)
@@ -1,207 +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 org.codelutin.util.FileUtil;
-import org.codelutin.util.ListenerSet;
-import org.codelutin.vcs.VCSHandlerEvent.Type;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FilenameFilter;
-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 {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static protected final Log log = LogFactory.getLog(AbstractVCSHandler.class);
-
- /**
- * FilenameFilter to detect all files in a vcs working copy all files and directories that must be handled by vcs
- *
- * @see org.codelutin.vcs.VCSHandler#getVersionnableFilenameFilter()
- */
- protected final FilenameFilter versionnableFilenameFilter;
- protected final FileFilter versionnableFileFilter;
- protected final String confLocalDirName;
- protected final String confLocalEntriesFilename;
- protected final VCSConfig config;
-
- protected ListenerSet<VCSHandlerEventListener> listeners = new ListenerSet<VCSHandlerEventListener>();
-
- protected AbstractVCSHandler(VCSConfig config, final String vCSConfLocalDirName, String vCSConfLocalEntriesFilename) {
- this.config = config;
- this.confLocalDirName = vCSConfLocalDirName;
- this.confLocalEntriesFilename = vCSConfLocalEntriesFilename;
- this.versionnableFilenameFilter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return !vCSConfLocalDirName.equals(name) && !"CVS".equals(name);
- }
- };
- this.versionnableFileFilter = new FileFilter() {
- public boolean accept(File dir) {
- 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;
- }
-
- public FileFilter getVersionnableFileFilter() {
- return versionnableFileFilter;
- }
-
- public String getConfLocalDirname() {
- return confLocalDirName;
- }
-
- public String getConfLocalEntriesFilename() {
- return confLocalEntriesFilename;
- }
-
- public boolean isVersionnableFile(File file) {
- assertFileExists(file, "file is empty or non existant");
- return !confLocalDirName.equalsIgnoreCase(file.getName());
- }
-
- public List<String> getLocalStorageNames(File directory) {
- List<String> result = new ArrayList<String>();
- if (directory.exists()) {
- getFiles0(directory, result, "");
- }
- Collections.sort(result);
- 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);
- }
- }
-
- protected void fireOpen() {
- VCSHandlerEvent e = new VCSHandlerEvent(this, Type.OPEN);
- for (VCSHandlerEventListener l : listeners) {
- l.open(e);
- }
- }
-
- 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;
- final String[] strings = directory.list(versionnableFilenameFilter);
- boolean first = prefix.equals("");
- final String newPrefix = (first ? "" : prefix + File.separator);
-
- for (String filename : strings) {
- final File dir = new File(directory, filename);
- if (dir.isDirectory())
- getFiles0(dir, result, newPrefix + dir.getName());
- else result.add(newPrefix + dir.getName());
- }
- }
-
- protected void assertFileExists(File file, String msg) {
- 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();
- }
-}
Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java 2008-04-04 19:37:59 UTC (rev 341)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java 2008-04-04 20:10:16 UTC (rev 342)
@@ -1,191 +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;
-
-(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
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java (from rev 334, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/AbstractVCSHandler.java 2008-04-04 20:10:16 UTC (rev 342)
@@ -0,0 +1,213 @@
+/* *##%
+* 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 org.codelutin.util.FileUtil;
+import org.codelutin.util.ListenerSet;
+import org.codelutin.vcs.VCSHandlerEvent.Type;
+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 java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+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 {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static protected final Log log = LogFactory.getLog(AbstractVCSHandler.class);
+
+ /**
+ * FilenameFilter to detect all files in a vcs working copy all files and directories that must be handled by vcs
+ *
+ * @see org.codelutin.vcs.VCSHandler#getVersionnableFilenameFilter()
+ */
+ protected final FilenameFilter versionnableFilenameFilter;
+ protected final FileFilter versionnableFileFilter;
+ protected final String confLocalDirName;
+ protected final String confLocalEntriesFilename;
+ protected final VCSConfig config;
+
+ protected ListenerSet<VCSHandlerEventListener> listeners = new ListenerSet<VCSHandlerEventListener>();
+
+ protected AbstractVCSHandler(VCSConfig config, final String vCSConfLocalDirName, String vCSConfLocalEntriesFilename) {
+ this.config = config;
+ this.confLocalDirName = vCSConfLocalDirName;
+ this.confLocalEntriesFilename = vCSConfLocalEntriesFilename;
+ this.versionnableFilenameFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return !vCSConfLocalDirName.equals(name) && !"CVS".equals(name);
+ }
+ };
+ this.versionnableFileFilter = new FileFilter() {
+ public boolean accept(File dir) {
+ 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;
+ }
+
+ public FileFilter getVersionnableFileFilter() {
+ return versionnableFileFilter;
+ }
+
+ public String getConfLocalDirname() {
+ return confLocalDirName;
+ }
+
+ public String getConfLocalEntriesFilename() {
+ return confLocalEntriesFilename;
+ }
+
+ public boolean isVersionnableFile(File file) {
+ assertFileExists(file, "file is empty or non existant");
+ return !confLocalDirName.equalsIgnoreCase(file.getName());
+ }
+
+ public List<String> getLocalStorageNames(File directory) {
+ List<String> result = new ArrayList<String>();
+ if (directory.exists()) {
+ getFiles0(directory, result, "");
+ }
+ Collections.sort(result);
+ 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);
+ }
+ }
+
+ protected void fireOpen() {
+ VCSHandlerEvent e = new VCSHandlerEvent(this, Type.OPEN);
+ for (VCSHandlerEventListener l : listeners) {
+ l.open(e);
+ }
+ }
+
+ 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;
+ final String[] strings = directory.list(versionnableFilenameFilter);
+ boolean first = prefix.equals("");
+ final String newPrefix = (first ? "" : prefix + File.separator);
+
+ for (String filename : strings) {
+ final File dir = new File(directory, filename);
+ if (dir.isDirectory())
+ getFiles0(dir, result, newPrefix + dir.getName());
+ else result.add(newPrefix + dir.getName());
+ }
+ }
+
+ protected void assertFileExists(File file, String msg) {
+ 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();
+ }
+}
Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java (from rev 334, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHelper.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java 2008-04-04 20:10:16 UTC (rev 342)
@@ -0,0 +1,194 @@
+/* *##%
+* 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
r341 - trunk/lutinvcs/lutinvcs-ui-jaxx/src/main/uimodel/org/codelutin/vcs/ui
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 19:37:59 +0000 (Fri, 04 Apr 2008)
New Revision: 341
Modified:
trunk/lutinvcs/lutinvcs-ui-jaxx/src/main/uimodel/org/codelutin/vcs/ui/JConfirmUI.jaxx
Log:
used fixed size + only used table as spacor :)
Modified: trunk/lutinvcs/lutinvcs-ui-jaxx/src/main/uimodel/org/codelutin/vcs/ui/JConfirmUI.jaxx
===================================================================
--- trunk/lutinvcs/lutinvcs-ui-jaxx/src/main/uimodel/org/codelutin/vcs/ui/JConfirmUI.jaxx 2008-04-04 19:37:36 UTC (rev 340)
+++ trunk/lutinvcs/lutinvcs-ui-jaxx/src/main/uimodel/org/codelutin/vcs/ui/JConfirmUI.jaxx 2008-04-04 19:37:59 UTC (rev 341)
@@ -1,4 +1,5 @@
-<org.codelutin.vcs.ui.AbstractUI title='lutinvcs.confirm.title' defaultCloseOperation='DISPOSE_ON_CLOSE' modal='true'>
+<org.codelutin.vcs.ui.AbstractUI title='lutinvcs.confirm.title' defaultCloseOperation='DISPOSE_ON_CLOSE' modal='true'
+ resizable='false' height='300' width='400'>
<style source="common.css"/>
<script>
import org.codelutin.vcs.VCSAction;
@@ -29,7 +30,6 @@
}
</script>
-
<Table>
<row fill='both'>
<cell fill='both'>
@@ -42,28 +42,21 @@
<row>
<cell>
<JToolBar id='tool'>
+ <JLabel id="actionCommitLabel" text="lutinvcs.commit.message"/>
<Table fill='both' insets='0,0,0,0'>
<row>
- <cell fill='both'>
- <JLabel id="actionCommitLabel" text="lutinvcs.commit.message"/>
- </cell>
- <cell fill='both' weightx="1">
- <JLabel/>
- </cell>
- <cell anchor='east'>
- <JButton id='lastMessages'
- toolTipText="lutinvcs.action.tooltip.lastMessages"
- icon='{createImageIcon("recent_msgs.png")}'
- onActionPerformed='showLastMessages()'/>
- </cell>
+ <cell fill='both'/>
</row>
</Table>
-
+ <JButton id='lastMessages'
+ toolTipText="lutinvcs.action.tooltip.lastMessages"
+ icon='{createImageIcon("recent_msgs.png")}'
+ onActionPerformed='showLastMessages()'/>
</JToolBar>
</cell>
</row>
<row fill='both'>
- <cell fill='both' columns='3' weightx='1' weighty='1'>
+ <cell fill='both' columns='3' weightx='1'>
<JScrollPane id="commitScroll" height='90' verticalScrollBarPolicy="20"
columnHeaderView="{tool}">
<JTextArea id="commitMessage" constructorParams="4,50"/>
@@ -73,7 +66,6 @@
</Table>
</cell>
</row>
-
<row>
<cell fill='both' weightx='1' weighty='1'>
<JScrollPane id='content' styleClass='confirmScroll'>
1
0
r340 - trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui
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 19:37:36 +0000 (Fri, 04 Apr 2008)
New Revision: 340
Modified:
trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java
Log:
more files generated
Modified: trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java
===================================================================
--- trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java 2008-04-04 19:36:20 UTC (rev 339)
+++ trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java 2008-04-04 19:37:36 UTC (rev 340)
@@ -39,7 +39,7 @@
VCSHandler handler = initVCS(root);
- List<VCSFileState> datas = generateListFileStates(handler, 20, "trunk", "local/", "remote/");
+ List<VCSFileState> datas = generateListFileStates(handler, 50, "trunk", "local/", "remote/");
JSynchUI synchUI = VCSUIFactory.newSynchUI(handler, datas);
1
0
r339 - in trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs: . impl/cvs
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 19:36:20 +0000 (Fri, 04 Apr 2008)
New Revision: 339
Modified:
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java
trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java
Log:
init Config in CVSHelper from CVSHandlerProvider
Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java 2008-04-04 19:35:35 UTC (rev 338)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/CVSHandlerProvider.java 2008-04-04 19:36:20 UTC (rev 339)
@@ -15,6 +15,7 @@
package org.codelutin.vcs;
import org.codelutin.vcs.impl.cvs.CVSHandler;
+import org.codelutin.vcs.impl.cvs.CVSHelper;
/** @author chemit */
public class CVSHandlerProvider implements VCSHandlerProvider<CVSHandler> {
@@ -24,6 +25,7 @@
}
public CVSHandler newInstance(VCSConfig config) {
+ CVSHelper.setConfig(config);
return new CVSHandler(config);
}
}
\ No newline at end of file
Modified: trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java 2008-04-04 19:35:35 UTC (rev 338)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/src/main/java/org/codelutin/vcs/impl/cvs/CVSHelper.java 2008-04-04 19:36:20 UTC (rev 339)
@@ -36,7 +36,6 @@
import static org.codelutin.i18n.I18n._;
import org.codelutin.vcs.VCSConfig;
import org.codelutin.vcs.VCSException;
-import org.codelutin.vcs.VCSHandlerFactory;
import org.codelutin.vcs.VCSRuntimeException;
import org.codelutin.vcs.VCSType;
import org.netbeans.lib.cvsclient.CVSRoot;
@@ -94,7 +93,7 @@
String hostName = getConfig().getHostName();
// R�pertoire distant du CVS
- String repository = config.getRemotePath();
+ String repository = getConfig().getRemotePath();
String userName = getConfig().getUserName();
@@ -142,8 +141,9 @@
}
private static VCSConfig getConfig() {
- if (config == null)
- config = VCSHandlerFactory.getConfig();
+ if (config == null) {
+ throw new IllegalStateException("config is null, should use provider to init config, or setConfig method");
+ }
if (config.getType() != VCSType.CVS) {
throw new VCSRuntimeException("can not execute CVS command with " +
"a [" + config.getType() + "] handler");
@@ -524,6 +524,10 @@
return listener.getResult();
}
+ public static void setConfig(VCSConfig config) {
+ CVSHelper.config = config;
+ }
+
static protected class LogCVSListener implements CVSListener {
protected CVSCommandResult result = new CVSCommandResult();
1
0
r338 - in trunk/lutinvcs: lutinvcs-provider-cvs lutinvcs-provider-mock lutinvcs-provider-svn
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 19:35:35 +0000 (Fri, 04 Apr 2008)
New Revision: 338
Modified:
trunk/lutinvcs/lutinvcs-provider-cvs/pom.xml
trunk/lutinvcs/lutinvcs-provider-mock/pom.xml
trunk/lutinvcs/lutinvcs-provider-svn/pom.xml
Log:
move AbstractVCSHandler to api module, in thaht way provider modules only depends on api module :)
Modified: trunk/lutinvcs/lutinvcs-provider-cvs/pom.xml
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-cvs/pom.xml 2008-04-04 19:35:20 UTC (rev 337)
+++ trunk/lutinvcs/lutinvcs-provider-cvs/pom.xml 2008-04-04 19:35:35 UTC (rev 338)
@@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>lutinlib.vcs</groupId>
- <artifactId>lutinvcs-core</artifactId>
+ <artifactId>lutinvcs-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
Modified: trunk/lutinvcs/lutinvcs-provider-mock/pom.xml
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-mock/pom.xml 2008-04-04 19:35:20 UTC (rev 337)
+++ trunk/lutinvcs/lutinvcs-provider-mock/pom.xml 2008-04-04 19:35:35 UTC (rev 338)
@@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>lutinlib.vcs</groupId>
- <artifactId>lutinvcs-core</artifactId>
+ <artifactId>lutinvcs-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
Modified: trunk/lutinvcs/lutinvcs-provider-svn/pom.xml
===================================================================
--- trunk/lutinvcs/lutinvcs-provider-svn/pom.xml 2008-04-04 19:35:20 UTC (rev 337)
+++ trunk/lutinvcs/lutinvcs-provider-svn/pom.xml 2008-04-04 19:35:35 UTC (rev 338)
@@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>lutinlib.vcs</groupId>
- <artifactId>lutinvcs-core</artifactId>
+ <artifactId>lutinvcs-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
1
0
r337 - in trunk/lutinvcs: lutinvcs-api/src/main/resources/i18n lutinvcs-core/src/main/resources/i18n
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 19:35:20 +0000 (Fri, 04 Apr 2008)
New Revision: 337
Modified:
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
trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-en_GB.properties
trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-fr_FR.properties
Log:
use only ServiceLoader once and save list of detected providers once for all :)
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:33:29 UTC (rev 336)
+++ trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-en_GB.properties 2008-04-04 19:35:20 UTC (rev 337)
@@ -8,7 +8,7 @@
lutinvcs.action.refresh=
lutinvcs.action.revert=revert
lutinvcs.action.update=update
-lutinvcs.error.checkout.dir=
+lutinvcs.error.checkout.dir=Can''t checkout dir {0}
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:33:29 UTC (rev 336)
+++ trunk/lutinvcs/lutinvcs-api/src/main/resources/i18n/lutinvcs-api-fr_FR.properties 2008-04-04 19:35:20 UTC (rev 337)
@@ -8,7 +8,7 @@
lutinvcs.action.refresh=Rafra\u00EEchir
lutinvcs.action.revert=Rollback
lutinvcs.action.update=Update
-lutinvcs.error.checkout.dir=
+lutinvcs.error.checkout.dir=Ne peut pas uploader le fichier ''{0}''
lutinvcs.state.missing=non pr\u00E9sent
lutinvcs.state.modified=modifi\u00E9
lutinvcs.state.outofdate=obsol\u00E8te
Modified: trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-en_GB.properties
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-en_GB.properties 2008-04-04 19:33:29 UTC (rev 336)
+++ trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-en_GB.properties 2008-04-04 19:35:20 UTC (rev 337)
@@ -1,4 +1,3 @@
-lutinvcs.error.checkout.dir=Can''t checkout dir {0}
lutinvcs.error.init.config=config is not init, you should invoke on the config validate(true) method to validate it and finish his init {0}
lutinvcs.error.init.no.config=should invoke {0}\#init(VCSType,Properties) before required instance.
lutinvcs.error.thread.action=
Modified: trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-fr_FR.properties
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-fr_FR.properties 2008-04-04 19:33:29 UTC (rev 336)
+++ trunk/lutinvcs/lutinvcs-core/src/main/resources/i18n/lutinvcs-core-fr_FR.properties 2008-04-04 19:35:20 UTC (rev 337)
@@ -1,4 +1,3 @@
-lutinvcs.error.checkout.dir=Can''t checkout dir {0}
lutinvcs.error.init.config=config is not init, you should invoke on the config validate(true) method to validate it and finish his init {0}
lutinvcs.error.init.no.config=should invoke {0}\#init(VCSType,Properties) before required instance.
lutinvcs.error.thread.action=
1
0
r336 - trunk/lutinvcs/lutinvcs-core/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 19:33:29 +0000 (Fri, 04 Apr 2008)
New Revision: 336
Modified:
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java
Log:
use only ServiceLoader once and save list of detected providers once for all :)
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 19:32:54 UTC (rev 335)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java 2008-04-04 19:33:29 UTC (rev 336)
@@ -24,6 +24,8 @@
import static org.codelutin.i18n.I18n._;
import org.codelutin.util.StringUtil;
+import java.util.ArrayList;
+import java.util.List;
import java.util.ServiceLoader;
/**
@@ -47,8 +49,9 @@
private VCSHandler handler;
/** providers availables */
- private ServiceLoader<VCSHandlerProvider> providers;
+ private List<VCSHandlerProvider> providers;
+
public static VCSHandlerFactory getInstance() {
if (instance == null) {
instance = new VCSHandlerFactory();
@@ -58,7 +61,7 @@
public static VCSConfig getConfig() {
VCSHandlerFactory factory = getInstance();
- factory.assertConfigIsNotNull(factory.config);
+ assertConfigIsNotNull(factory.config);
return factory.config;
}
@@ -87,8 +90,8 @@
public static VCSHandler newHandler(VCSConfig config) {
VCSHandlerFactory factory = getInstance();
- factory.assertConfigIsInit(config);
- VCSHandlerProvider<?> provider = factory.getProvider(config);
+ assertConfigIsInit(config);
+ VCSHandlerProvider<?> provider = factory.getProvider(config.getType().name().toUpperCase());
if (provider == null) {
throw new IllegalArgumentException("could not find a provider for type " + config.getType());
}
@@ -97,39 +100,35 @@
private VCSHandlerFactory() {
long t0 = System.nanoTime();
- providers = ServiceLoader.load(VCSHandlerProvider.class);
- int nb = 0;
- for (VCSHandlerProvider provider : providers) {
+ providers = new ArrayList<VCSHandlerProvider>();
+ for (VCSHandlerProvider provider : ServiceLoader.load(VCSHandlerProvider.class)) {
+ providers.add(provider);
if (log.isDebugEnabled()) {
log.debug("find " + provider);
}
- nb++;
}
- log.info("found " + nb + " provider(s) " + providers.toString() + " in " + StringUtil.convertTime(t0, System.nanoTime()));
+ log.info("found " + providers.size() + " provider(s) " + providers.toString() + " in " + StringUtil.convertTime(t0, System.nanoTime()));
for (VCSHandlerProvider provider : providers) {
log.info(provider.getName() + " [" + provider + ']');
}
}
- private VCSHandlerProvider getProvider(VCSConfig config) {
-
- String type = config.getType().name();
-
+ private VCSHandlerProvider getProvider(String type) {
for (VCSHandlerProvider provider : providers) {
- if (type.equals(provider.getName())) {
+ if (type.equals(provider.getName().toUpperCase())) {
return provider;
}
}
- return null;
+ throw new IllegalArgumentException("could not found a provier for " + config);
}
- private void assertConfigIsNotNull(VCSConfig vcsConfig) {
+ private static void assertConfigIsNotNull(VCSConfig vcsConfig) {
if (vcsConfig == null) {
throw new VCSRuntimeException(_("lutinvcs.error.init.no.config", VCSHandlerFactory.class.getName()));
}
}
- private void assertConfigIsInit(VCSConfig config) {
+ private static void assertConfigIsInit(VCSConfig config) {
assertConfigIsNotNull(config);
if (!config.isInit()) {
throw new VCSRuntimeException(_("lutinvcs.error.init.config", config));
1
0
r335 - in trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs: . runner ui/handler
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 19:32:54 +0000 (Fri, 04 Apr 2008)
New Revision: 335
Added:
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java
Removed:
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java
Modified:
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java
Log:
add runner package
Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java 2008-04-04 19:32:29 UTC (rev 334)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java 2008-04-04 19:32:54 UTC (rev 335)
@@ -1,157 +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.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import static org.codelutin.i18n.I18n._;
-
-import java.util.Date;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.PriorityBlockingQueue;
-
-/**
- * Manager used to fired vcs actions
- * <p/>
- * use a {@link org.codelutin.vcs.VCSActionManager.VCSActionThread}.
- *
- * @author chemit
- */
-public class VCSActionManager {
-
- /** vcs actions runner thread */
- protected VCSActionThread thread;
-
- /** queue */
- protected PriorityBlockingQueue<QueueItem> queue;
-
- public boolean add(VCSAction action, VCSFileState[] states) {
- QueueItem queueItem = new QueueItem(action, states);
- return queue.add(queueItem);
- }
-
- public VCSActionManager(VCSHandler handler) {
- queue = new PriorityBlockingQueue<QueueItem>(1024);
- thread = new VCSActionThread(handler, queue);
- thread.start();
- }
-
-
- /** @author chemit */
- public static class VCSActionThread extends Thread implements VCSHandlerEventListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(VCSActionThread.class);
-
- /** queue */
- protected BlockingQueue<QueueItem> queue;
-
- /** handler to use for vcs operations */
- protected VCSHandler handler;
-
- public VCSActionThread(VCSHandler handler, BlockingQueue<QueueItem> queue) {
- super("VCSAction Thread [" + handler + "]");
- this.handler = handler;
- this.queue = queue;
- this.handler.addVCSHandlerEventListener(this);
- }
-
- @Override
- public void run() {
- log.info("Start " + getName() + " at " + new Date());
- boolean run = true;
- QueueItem item = null;
- try {
- while (run) {
- // item qui sert a faire la simulation courante
-
- log.info("waiting for action...");
- item = queue.take();
- if (item.getAction() == null) {
- // this is a special case to stop thread
- run = false;
- continue;
- }
- log.info("Just take " + item);
- }
- }
- catch (Throwable eee) {
- if (log.isWarnEnabled()) {
- log.warn(_("lutinvcs.error.thread.action", item), eee);
- }
- }
- log.info("Stop " + getName() + " at " + new Date());
- }
-
-
- public void init(VCSHandlerEvent event) {
- }
-
- public void open(VCSHandlerEvent event) {
- }
-
- public void close(VCSHandlerEvent event) {
-
- handler.removeVCSHandlerEventListener(this);
- if (!queue.isEmpty()) {
- queue.clear();
- }
- queue.add(new QueueItem(null, new VCSFileState[0]));
- }
- }
-
- public static class QueueItem implements Comparable<QueueItem> {
-
- protected long time;
- protected VCSFileState[] states;
- protected VCSAction action;
-
-
- public QueueItem(VCSAction action, VCSFileState[] states) {
- this.time = System.nanoTime();
- this.states = states;
- this.action = action;
- }
-
- public VCSAction getAction() {
- return action;
- }
-
- public VCSFileState[] getStates() {
- return states;
- }
-
- @Override
- public boolean equals(Object o) {
- return this == o || o instanceof QueueItem && time == ((QueueItem) o).time;
- }
-
- @Override
- public int hashCode() {
- return (int) (time ^ (time >>> 32));
- }
-
- @Override
- public String toString() {
- return super.toString() + ", time:" + time + ", action:" + action + ", size:" + (states == null ? 0 : states.length);
- }
-
- public int compareTo(QueueItem o) {
- return time == o.time ? 0 : time > o.time ? 1 : -1;
- }
- }
-
-
-}
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java (from rev 331, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSActionManager.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java 2008-04-04 19:32:54 UTC (rev 335)
@@ -0,0 +1,110 @@
+/**
+ * # #% 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.runner;
+
+import org.codelutin.vcs.VCSAction;
+import org.codelutin.vcs.VCSFileState;
+import org.codelutin.vcs.VCSHandler;
+import org.codelutin.vcs.VCSHandlerEvent;
+import org.codelutin.vcs.VCSHandlerEventListener;
+
+import java.util.concurrent.PriorityBlockingQueue;
+
+/**
+ * Manager used to fired vcs actions
+ * <p/>
+ * use a {@link org.codelutin.vcs.runner.VCSActionThread}.
+ *
+ * @author chemit
+ */
+public class VCSActionManager implements VCSHandlerEventListener {
+
+ /** special item to add in queue to stop the thread */
+ protected static final QueueItem STOP_ITEM = new QueueItem(null, new VCSFileState[0]);
+
+ /** vcs actions runner thread */
+ protected VCSActionThread thread;
+
+ /** queue */
+ protected PriorityBlockingQueue<QueueItem> queue;
+
+ public VCSActionManager(VCSHandler handler) {
+ queue = new PriorityBlockingQueue<QueueItem>(1024);
+ thread = new VCSActionThread(handler, queue);
+ handler.addVCSHandlerEventListener(this);
+ }
+
+ public boolean add(VCSAction action, VCSFileState[] states) {
+ QueueItem queueItem = new QueueItem(action, states);
+ return queue.add(queueItem);
+ }
+
+ public void init(VCSHandlerEvent event) {
+ }
+
+ public void open(VCSHandlerEvent event) {
+ thread.start();
+ }
+
+ public void close(VCSHandlerEvent event) {
+ thread.handler.removeVCSHandlerEventListener(this);
+ if (!queue.isEmpty()) {
+ queue.clear();
+ }
+ queue.add(VCSActionManager.STOP_ITEM);
+ }
+
+ /** @author chemit */
+ public static class QueueItem implements Comparable<QueueItem> {
+
+ protected long time;
+ protected VCSFileState[] states;
+ protected VCSAction action;
+
+
+ public QueueItem(VCSAction action, VCSFileState[] states) {
+ this.time = System.nanoTime();
+ this.states = states;
+ this.action = action;
+ }
+
+ public VCSAction getAction() {
+ return action;
+ }
+
+ public VCSFileState[] getStates() {
+ return states;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return this == o || o instanceof QueueItem && time == ((QueueItem) o).time;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) (time ^ (time >>> 32));
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + ", time:" + time + ", action:" + action + ", size:" + (states == null ? 0 : states.length);
+ }
+
+ public int compareTo(QueueItem o) {
+ return time == o.time ? 0 : time > o.time ? 1 : -1;
+ }
+ }
+}
Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java 2008-04-04 19:32:54 UTC (rev 335)
@@ -0,0 +1,97 @@
+/**
+ * # #% 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.runner;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.vcs.VCSHandler;
+
+import java.util.Date;
+import java.util.concurrent.BlockingQueue;
+
+/** @author chemit */
+public class VCSActionThread extends Thread {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(VCSActionThread.class);
+
+ /** queue */
+ protected BlockingQueue<VCSActionManager.QueueItem> queue;
+
+ /** handler to use for vcs operations */
+ protected VCSHandler handler;
+
+ public VCSActionThread(VCSHandler handler, BlockingQueue<VCSActionManager.QueueItem> queue) {
+ super("VCSAction Thread [" + handler + "]");
+ this.handler = handler;
+ this.queue = queue;
+ }
+
+ @Override
+ public void run() {
+ log.info("Start " + getName() + " at " + new Date());
+ boolean run = true;
+ VCSActionManager.QueueItem item = null;
+ try {
+ while (run) {
+ // item qui sert a faire la simulation courante
+
+ log.info("waiting for action...");
+ item = queue.take();
+ if (item.getAction() == null) {
+ // this is a special case to stop thread
+ run = false;
+ continue;
+ }
+ doAction(item);
+ }
+ }
+ catch (Throwable eee) {
+ if (log.isWarnEnabled()) {
+ log.warn(_("lutinvcs.error.thread.action", item), eee);
+ }
+ }
+ log.info("Stop " + getName() + " at " + new Date());
+ }
+
+ protected void doAction(VCSActionManager.QueueItem item) {
+ log.info("Just take " + item);
+ switch (item.getAction()) {
+ case ADD:
+ break;
+ case CHANGELOG:
+ break;
+ case CHECKOUT:
+ break;
+ case COMMIT:
+ break;
+ case DELETE:
+ break;
+ case DIFF:
+ break;
+ case OVERWRITE_AND_UPDATE:
+ break;
+ case REFRESH:
+ break;
+ case REVERT:
+ break;
+ case UPDATE:
+ break;
+ }
+ }
+
+
+}
Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java 2008-04-04 19:32:29 UTC (rev 334)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java 2008-04-04 19:32:54 UTC (rev 335)
@@ -15,7 +15,7 @@
package org.codelutin.vcs.ui.handler;
import org.codelutin.vcs.VCSAction;
-import org.codelutin.vcs.VCSActionManager;
+import org.codelutin.vcs.runner.VCSActionManager;
import org.codelutin.vcs.VCSFileState;
import org.codelutin.vcs.VCSHandler;
import org.codelutin.vcs.ui.VCSUIConstants;
1
0
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
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 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;
+
+(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
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;
-
-(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 = 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
1
0