[Buix-commits] r357 - in trunk/lutinvcs: lutinvcs-api/src/main/java/org/codelutin/vcs lutinvcs-core/src/main/java/org/codelutin/vcs lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model
Author: tchemit Date: 2008-04-05 20:35:25 +0000 (Sat, 05 Apr 2008) New Revision: 357 Removed: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java Log: delete old code Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java 2008-04-05 20:33:02 UTC (rev 356) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java 2008-04-05 20:35:25 UTC (rev 357) @@ -1,60 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * # #% - */ -package org.codelutin.vcs; - -import java.io.File; -import java.io.Serializable; - -/** @author chemit */ -public interface VCSFileState extends Serializable { - - boolean existLocally(); - - String getLocalPath(); - - String getModuleName(); - - String getModuleRelativeFileName(); - - String[] getFileNamePath(); - - String getRemotePath(); - - VCSState getState(); - - long getTimestamp(); - - File getFile(); - - String getChangeLog(); - - Long getRev(); - - VCSAction getAction(); - - void resetState(); - - boolean wasSynch(); - - boolean isLocallySynch(); - - void doSynch(VCSHandler handler, long timestamp); - - void doSynch(VCSHandler handler, long timestamp, boolean ifFileChanged); - - void setChangeLog(String changeLog); - - void setAction(VCSAction action); -} Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java 2008-04-05 20:33:02 UTC (rev 356) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSUIAction.java 2008-04-05 20:35:25 UTC (rev 357) @@ -1,23 +0,0 @@ -package org.codelutin.vcs; - -import javax.swing.JDialog; -import java.util.List; - -/** - * a VCSUIAction represents an action to realize on a file in working copy - * or on remote repository with an possible ui interaction. - * <p/> - * This is the highest api level for vcs using - * <p/> - * The method {@link #doAction(JDialog, org.codelutin.vcs.VCSHandler , List)} fired the action - * on a list of states - */ -public interface VCSUIAction { - /** - * @param dialog the dialog where action was asked - * @param handler vcshandler to use - * @param states list of VCSFileState to treate - * @throws VCSException if any exception while operation - */ - void doAction(JDialog dialog, VCSHandler handler, List<VCSFileState> states) throws VCSException; -} Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java 2008-04-05 20:33:02 UTC (rev 356) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateImpl.java 2008-04-05 20:35:25 UTC (rev 357) @@ -1,268 +0,0 @@ -package org.codelutin.vcs; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.vcs.util.VCSHelper; - -import java.io.File; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; - -/** - * This class represents the vcs state of a file in a working copy or on remote - * repository. - * <br/> - * For a defined file in a working copy, we only use a instance of the - * class, {@link VCSFileStateManager} is responsible of instanciate thoses - * objects and store them in a cache. - * <br/> - * use method {@link #doSynch(VCSHandler,long)} to doSynch whatever - * local file state. - * use method {@link #doSynch(VCSHandler,long,boolean)} to doSynch only - * if local file state changed (with true value) - * - * @see VCSState - * @see VCSFileStateManager - */ -public class VCSFileStateImpl implements VCSFileState, Serializable { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static protected final Log log = LogFactory.getLog(VCSFileStateImpl.class); - - /** - * working copy file to deal with (could not exists in file only exists - * on remote repository) - */ - protected File file; - /** a optional module name (if defined, will change getModuleRelativeFileName behavior) */ - protected String moduleName; - /** - * relative path on local file system (use File.separator) to root of local - * working copy - */ - protected String localPath; - /** - * relative path on remote repository (use '/' (should be Remote.separator) - * to root of this repository - */ - protected String remotePath; - /** timestamp of last doSynch or -1 if no doSynch was previously done */ - protected long timestamp; - /** state of the file */ - protected VCSState state; - /** - * index used to identify uniquely each instance (hashcode of - * file.getAbsolutePath()) - */ - protected int key; - /** revision of this file, or null if unversionned */ - protected Long rev; - /** changeLog of the file */ - protected String changeLog; - /** diff of the file */ - protected String diff; - /** action to be programmed for this state */ - protected VCSAction action; - - private static final long serialVersionUID = -815443990862836772L; - - /** - * protected access restriction : you should not instanciate directly - * this class, but use {@link VCSFileStateManager} to do it. - * - * @param handler the vcs handler used with this working copy - * @param file file to be handled - */ - public VCSFileStateImpl(VCSHandler handler, File file) { - this.file = file; - this.key = file.getAbsolutePath().hashCode(); - String path = file.getAbsolutePath(); - String rootPath = handler.getLocalDatabasePath().getAbsolutePath(); - - if (!path.startsWith(rootPath)) { - throw new VCSRuntimeException("could not create a VCSFileState " + - "for a file not in the root working copy registered in " + - "vcsHandler, but was : [" + file + " ::" + - handler.getLocalDatabasePath() + " ]"); - } - if (file.equals(handler.getConfig().getLocalDatabasePath())) { - this.localPath = ""; - } else { - - this.localPath = path.substring(rootPath.length() + 1); - } - // by default moduleName is the first dir of localpath (if any) - int index = this.localPath.indexOf(File.separator); - if (index == -1) { - // this is a module directory - this.moduleName = this.localPath; - this.localPath = ""; - } else { - this.moduleName = this.localPath.substring(0, index); - } - - resetState(); - } - - public boolean existLocally() { - return file.exists(); - } - - public String getLocalPath() { - return localPath; - } - - public String getModuleName() { - return moduleName; - } - - public String getModuleRelativeFileName() { - return "".equals(moduleName) ? getLocalPath() : - "".equals(localPath) ? "" : localPath.substring(moduleName.length() + 1); - } - - public String[] getFileNamePath() { - // TODO Should use File.separator - return getModuleRelativeFileName().split(File.separator); - } - - public String getRemotePath() { - if (remotePath == null) - remotePath = VCSHelper.convertToRemoteName(localPath); - return remotePath; - } - - public VCSState getState() { - return state; - } - - public long getTimestamp() { - return timestamp; - } - - public File getFile() { - return file; - } - - public String getChangeLog() { - return changeLog; - } - - public Long getRev() { - return rev; - } - - public VCSAction getAction() { - return action; - } - - /** - * reset synch for this instance : after this invocation, - * the method {@link #wasSynch()} will return <code>true</code> to means - * that no synch info are available. - */ - public void resetState() { - state = null; - timestamp = -1; - } - - /** - * @return <code>true</code> if there at least one invocation of - * {@link #doSynch(VCSHandler,long)} or - * {@link #doSynch(VCSHandler,long,boolean)} - * was made and no invocation of {@link #resetState()} - * was made after. - */ - public boolean wasSynch() { - return state != null && timestamp != -1; - } - - /** - * @return <code>true</code> if this instance <code>wasSynch</code> and - * the file was not modified since last synch. - */ - public boolean isLocallySynch() { - return wasSynch() && timestamp <= file.lastModified(); - } - - /** - * doSynch this instance with remote repository and put a new timestamp - * the one passed as parameter. - * - * @param handler vcs handler to use - * @param timestamp the new synch timestamp - */ - public void doSynch(VCSHandler handler, long timestamp) { - doSynch(handler, timestamp, false); - } - - /** - * doSynch this instance with remote repository and put a new timestamp - * the one passed as parameter. - * Do not doSynch if <code>ifFileChanged</code> is <code>true</code> - * and file was not modify since last synch. - * - * @param handler vcs handler to use - * @param timestamp the new synch timestamp - * @param ifFileChanged if <code>true</code> will doSynch only if file - * was locally modified after last doSynch - */ - public void doSynch(VCSHandler handler, long timestamp, - boolean ifFileChanged) { - //TODO should deal with possibility of file existed but no more... - boolean needSynch = !wasSynch() || - !ifFileChanged || timestamp <= file.lastModified(); - - try { - if (needSynch) { - this.timestamp = timestamp; - Collection tmp = new ArrayList(); - this.state = handler.getState(file, tmp); - if (!tmp.isEmpty()) this.rev = (Long) tmp.iterator().next(); - log.info(" new synch " + this); - } - } catch (VCSException e) { - log.warn("could not acquire state for " + this + " : " + e.getMessage()); - resetState(); - } - } - - @Override - public boolean equals(Object o) { - return this == o || !(o == null || getClass() != o.getClass()) && - localPath.equals(((VCSFileStateImpl) o).localPath); - } - - @Override - public int hashCode() { - return localPath.hashCode(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(localPath).append('(').append(key).append(')'). - append('|').append(state).append('|').append(timestamp); - return sb.toString(); - } - - @Override - public VCSFileStateImpl clone() throws CloneNotSupportedException { - return (VCSFileStateImpl) super.clone(); - } - - - public void setChangeLog(String changeLog) { - this.changeLog = changeLog; - } - - public void setAction(VCSAction action) { - this.action = action; - } - - public void setState(VCSState state) { - this.state = state; - } -} - Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java 2008-04-05 20:33:02 UTC (rev 356) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFileStateManager.java 2008-04-05 20:35:25 UTC (rev 357) @@ -1,276 +0,0 @@ -/* ##% -* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Benjamin Poussin, Tony Chemit -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%*/ -package org.codelutin.vcs; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.TreeMap; - -/** - * Classe responsable de la gestion des {@link VCSFileStateImpl}. - * <p/> - * Elle permet leur instanciation, et g�re un cache de ces objets, la politique - * �tant de n'instancier qu'une seule fois et ensuite d'utiliser les methodes de - * synchronisations. - * <br/> - * TODO Doc - * {@link #doSynch()} - * {@link #getState(long,File)} ()} - * {@link #doAdd(VCSHandler,File)} - * {@link #doDelete(File)} - * {@link #doClear()} - * {@link #doReset()} - * - * @author chemit - */ -public class VCSFileStateManager { - - protected static VCSHandler getVCSHanler() { - return VCSHandlerFactory.getHandler(); - } - - static public List<VCSFileState> doScan(VCSHandler handler, File root, boolean changeLog, - VCSState... states) throws VCSException { - // TODO on devrait changer l'algorithme, pour ne recuperer - // TODO que ce qui est reellement est necessaire - - // recupereration des fichier locaux - List<String> localFileNames = handler.getLocalStorageNames(root); - - // recuperation des fichiers distants - List<String> remoteFileNames = handler.getRemoteStorageNames(root); - - // recuperation des fichiers uniquement presents sur le repository distant - List<String> newRemoteName = new ArrayList<String>(remoteFileNames); - newRemoteName.removeAll(localFileNames); - - List<VCSFileState> vcsstates = new ArrayList<VCSFileState>(); - - long timestamp = System.nanoTime(); - - for (String filePath : localFileNames) { - File f = new File(root, filePath); - vcsstates.add(getState(timestamp, f)); - } - - for (String filePath : newRemoteName) { - File f = new File(root, filePath); - vcsstates.add(getState(timestamp, f)); - } - - final List<VCSFileState> result = filter(vcsstates, states); - if (changeLog) { - // compute all change log for selected files - for (VCSFileState vcsFileState : result) - vcsFileState.setChangeLog(handler.getChangeLog(vcsFileState.getFile())); - } - return result; - } - - // ///////////////////////////////////////////////////////////////////////// - // / methodes getState(XXX) pour obtenir des etats du cache (avec creation - // / si besoin est) - // ///////////////////////////////////////////////////////////////////////// - - static public VCSFileState getState(long timestamp, File f) { - return getState(getVCSHanler(), timestamp, f); - } - - static public VCSFileState getState(boolean synch, File f) { - return getState(getVCSHanler(), synch, f); - } - - static public VCSFileState getState(VCSHandler handler, boolean synch, - File f) { - VCSFileState result; - synchronized (cache) { - final int key = getKey(f); - result = cache.get(key); - if (result == null) { - result = doAdd(handler, f); - } - if (synch) { - result.doSynch(handler, System.nanoTime()); - } - } - return result; - } - - static public VCSFileState getState(VCSHandler handler, long timestamp, File f) { - VCSFileState result; - synchronized (cache) { - final int key = getKey(f); - result = cache.get(key); - if (result == null) { - result = doAdd(handler, f); - } - result.doSynch(handler, timestamp); - } - return result; - } - - static public VCSFileState[] getState(VCSHandler handler, boolean synch, - Collection<File> f) { - VCSFileState[] result = new VCSFileState[f.size()]; - - int index = 0; - for (File file : f) { - result[index] = getState(handler, synch, file); - index++; - } - return result; - } - - // ///////////////////////////////////////////////////////////////////////// - // / methodes doSynch(XXX) pour synchroniser les �tats du cache - // ///////////////////////////////////////////////////////////////////////// - - static public void doSynch() { - doSynch(getVCSHanler(), false, System.nanoTime()); - } - - static public void doSynch(VCSHandler handler, boolean ifFileChanged, - long timestamp) { - synchronized (cache) { - for (Integer hashcode : cache.keySet()) { - cache.get(hashcode).doSynch(handler, timestamp, ifFileChanged); - } - } - } - - static public void doSynch(VCSHandler handler, Collection<File> files) { - doSynch(handler, false, System.nanoTime(), files); - } - - static public void doSynch(VCSHandler handler, boolean ifFileChanged, - long timestamp, Collection<File> files) { - synchronized (cache) { - for (File file : files) { - VCSFileState vcsFileState = cache.get(getKey(file)); - if (vcsFileState == null) - vcsFileState = doAdd(getVCSHanler(), file); - vcsFileState.doSynch(handler, timestamp, ifFileChanged); - } - } - } - - // ///////////////////////////////////////////////////////////////////////// - // methodes protected doAdd(XXX) pour ajouter directement des etats au cache - // ///////////////////////////////////////////////////////////////////////// - - static protected VCSFileState doAdd(VCSHandler handler, File f) { - VCSFileState result; - synchronized (cache) { - final int key = getKey(f); - cache.put(key, result = new VCSFileStateImpl(handler, f)); - log.debug("[cache size:" + cache.size() + "] : " + result); - } - return result; - } - - // //////////////////////////////////////////////////////////////////////// - // methodes doDelete(XXX) pour supprimer des etats du cache - // //////////////////////////////////////////////////////////////////////// - - static public void doDelete(File file) { - synchronized (cache) { - cache.remove(getKey(file)); - } - } - - // ///////////////////////////////////////////////////////////////////////// - // / clean cache methods - // ///////////////////////////////////////////////////////////////////////// - - static public void doReset() { - synchronized (cache) { - for (Integer hashcode : cache.keySet()) { - cache.get(hashcode).resetState(); - } - } - } - - static public void doClear() { - synchronized (cache) { - cache.clear(); - } - } - - protected VCSFileStateManager() { - } - - static private int getKey(File file) { - return file.getAbsolutePath().hashCode(); - } - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static protected final Log log = LogFactory - .getLog(VCSFileStateManager.class); - - /** cache of VCSFileState, keys are relativePath.hashCode of each entry */ - static final protected java.util.Map<Integer, VCSFileState> cache = new TreeMap<Integer, VCSFileState>(); - - // ///////////////////////////////////////////////////////////////////////// - // / utils methods (filter and explode from VCSAction and VCSState) - // ///////////////////////////////////////////////////////////////////////// - @SuppressWarnings({"unchecked"}) - static public List<VCSFileState>[] explode(List<VCSFileState> source, - VCSState... wanted) { - if (wanted.length == 0) - wanted = VCSState.values(); - int nbState = wanted.length; - List<VCSFileState>[] result = new List[nbState]; - for (int i = 0; i < nbState; i++) { - result[i] = new ArrayList<VCSFileState>(); - } - List<VCSState> states = java.util.Arrays.asList(wanted); - VCSState state; - int index; - for (VCSFileState fileState : source) { - state = fileState.getState(); - if ((index = states.indexOf(state)) > -1) { - result[index].add(fileState); - } - } - return result; - } - - static public List<VCSFileState> filter(List<VCSFileState> source, - VCSState... wanted) { - List<VCSFileState> result = new ArrayList<VCSFileState>(); - List<VCSState> states = java.util.Arrays.asList(wanted); - - if (wanted.length == 0) { - return result; - } - for (VCSFileState fileState : source) { - VCSState currentState = fileState.getState(); - if (states.contains(currentState)) { - result.add(fileState); - } - } - return result; - } -} Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java 2008-04-05 20:33:02 UTC (rev 356) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSFileStatesModel.java 2008-04-05 20:35:25 UTC (rev 357) @@ -1,49 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * # #% - */ -package org.codelutin.vcs.ui.model; - -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSState; -import org.codelutin.vcs.ui.VCSUIConstants; - -/** @author chemit */ -public class SimpleVCSFileStatesModel extends AbstractVCSFileStatesModel { - - private static final long serialVersionUID = -7592705623128585146L; - - public SimpleVCSFileStatesModel(String name) { - super(name, VCSUIConstants.SIMPLE_COLUMNS_NAMES); - } - - public Object getValueAt(int rowIndex, int columnIndex) { - if (isEmpty()) return null; - VCSFileState item = data.get(rowIndex); - Object result = null; - if (columnIndex == 0) { - // get module - result = item.getModuleName(); - } else if (columnIndex == 1) { - // get file - result = item.getModuleRelativeFileName(); - } else if (columnIndex == 2) { - // get status - VCSState state = item.getState(); - result = state == null ? null : state.libelle(); - } - return result; - } - - -} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org