[Buix-commits] r333 - in trunk/lutinvcs: lutinvcs-api/src/main/java/org/codelutin/vcs lutinvcs-core/src/main/java/org/codelutin/vcs
Author: tchemit Date: 2008-04-04 19:18:38 +0000 (Fri, 04 Apr 2008) New Revision: 333 Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java Removed: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java Log: move AbstractVCSHandler to api module, in thaht way provider modules only depends on api module :) Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java (from rev 331, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java) =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java 2008-04-04 19:18:38 UTC (rev 333) @@ -0,0 +1,182 @@ +/* *##% +* 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; + +/** + * 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 + "])"); + } +} Modified: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java 2008-04-04 18:14:16 UTC (rev 332) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerProvider.java 2008-04-04 19:18:38 UTC (rev 333) @@ -15,13 +15,13 @@ package org.codelutin.vcs; /** - * Provider de VCSHandler + * The contract to be realized to provide a {@link VCSHandler}. * * @author chemit */ public interface VCSHandlerProvider<H extends VCSHandler> { - /** @return the name defining the vcs provider (eg SVN, CVS) */ + /** @return the identifier of the vcs provider (eg SVN, CVS, MOCK) */ String getName(); /** Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java 2008-04-04 18:14:16 UTC (rev 332) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/AbstractVCSHandler.java 2008-04-04 19:18:38 UTC (rev 333) @@ -1,182 +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; - -/** - * 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 + "])"); - } -}
participants (1)
-
tchemit@users.labs.libre-entreprise.org