[Buix-commits] r523 - in trunk/lutinvcs/core/src/main/java/org/codelutin/vcs: . event runner util
Author: tchemit Date: 2008-04-15 08:48:00 +0000 (Tue, 15 Apr 2008) New Revision: 523 Added: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEvent.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEventListener.java Removed: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEvent.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEventListener.java Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntries.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntry.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java Log: mise en place listener sur action du thread (et non plus sur chaque entr?\195?\169e ?\195?\160 traiter). Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java 2008-04-15 08:48:00 UTC (rev 523) @@ -18,6 +18,7 @@ * ##% */ package org.codelutin.vcs; +import org.codelutin.vcs.type.VCSConnexionMode; import org.codelutin.vcs.type.VCSTypeRepo; import java.io.File; @@ -34,6 +35,8 @@ /** @return the type of vcs used */ String getType(); + VCSConnexionMode getMode(); + /** @return <code>true</code> if ssh connexion is used */ boolean isUseSshConnexion(); @@ -87,4 +90,6 @@ void setUserName(String userName); void setUseSshConnexion(boolean newValue); + + void setConnexionMode(VCSConnexionMode mode); } \ No newline at end of file Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntries.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntries.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntries.java 2008-04-15 08:48:00 UTC (rev 523) @@ -75,10 +75,21 @@ * @param timestamp global timestamp to apply * @param entries entries to refresh * @throws IllegalStateException if entry was never populated + * @throws VCSException if vcs io pb */ - void refresh(long timestamp, List<VCSEntry> entries) throws IllegalStateException; + void refresh(long timestamp, List<VCSEntry> entries) throws IllegalStateException, VCSException; /** + * refresh state of the entry. + * + * @param timestamp global timestamp to apply + * @param entries entries to refresh + * @throws IllegalStateException if entry was never populated + * @throws VCSException if vcs io pb + */ + void refresh(long timestamp, VCSEntry entries) throws IllegalStateException, VCSException; + + /** * //TODO update javadoc, use efficient algo * obtain the array of all {@link VCSAction} found in the given entries * @@ -141,4 +152,9 @@ * @return list of all entries for a given connexion */ List<VCSEntry> filter(VCSAction action, List<VCSEntry> entries); + + void addEntry(VCSEntry entry); + + void removeEntry(VCSEntry entry); + } Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntry.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntry.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/VCSEntry.java 2008-04-15 08:48:00 UTC (rev 523) @@ -14,7 +14,6 @@ */ package org.codelutin.vcs; -import org.codelutin.vcs.event.VCSEntryStateChangedEventListener; import org.codelutin.vcs.type.VCSEntryLocation; import org.codelutin.vcs.type.VCSState; @@ -59,7 +58,7 @@ * * @throws VCSException if any pb with vcs io * @throws IllegalStateException if entry was never populated - * @throws IOException if io pb + * @throws IOException if io pb */ void populateDiff() throws IllegalStateException, VCSException, IOException; @@ -139,15 +138,15 @@ /** * @return the changelog of entry from local against remote (compute it if necessary) * @throws IllegalStateException if entry was never populated - * @throws VCSException if vcs io pb while computing changelog + * @throws VCSException if vcs io pb while computing changelog */ BufferedReader getChangeLog() throws IllegalStateException, VCSException; /** * @return the diff of entry from local against remote (compute it if necessary) * @throws IllegalStateException if entry was never populated - * @throws VCSException if vcs io pb while computing diff - * @throws IOException if io pb while computing diff + * @throws VCSException if vcs io pb while computing diff + * @throws IOException if io pb while computing diff */ BufferedReader getDiff() throws IllegalStateException, IOException, VCSException; @@ -163,10 +162,4 @@ */ BufferedReader getRemoteContent() throws IllegalStateException; - /** @param l the listener to add */ - void addVCSEntryStateChangedEventListener(VCSEntryStateChangedEventListener l); - - /** @param l the listener to remove */ - void removeVCSEntryStateChangedEventListener(VCSEntryStateChangedEventListener l); - } \ No newline at end of file Copied: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEvent.java (from rev 511, trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEvent.java) =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEvent.java (rev 0) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEvent.java 2008-04-15 08:48:00 UTC (rev 523) @@ -0,0 +1,58 @@ +/** + * ##% 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.event; + +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.type.VCSAction; + +import java.util.EventObject; + +/** + * Events to be used by {@link org.codelutin.vcs.runner.VCSActionThread} + * + * @author chemit + */ +public class VCSActionThreadEvent extends EventObject { + + private static final long serialVersionUID = 1L; + + protected VCSAction action; + + /** + * Constructs a prototypical Event. + * + * @param source The object on which the Event initially occurred. + * @param action action to be performed + * @throws IllegalArgumentException if source is null. + */ + public VCSActionThreadEvent(VCSEntry[] source, VCSAction action) { + super(source); + this.action = action; + } + + @Override + public VCSEntry[] getSource() { + return (VCSEntry[]) super.getSource(); + } + + public VCSAction getAction() { + return action; + } + + @Override + public String toString() { + return super.toString() + " " + action + " , " + (getSource() == null ? 0 : getSource().length); + } +} \ No newline at end of file Copied: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEventListener.java (from rev 511, trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSConnexionEventListener.java) =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEventListener.java (rev 0) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSActionThreadEventListener.java 2008-04-15 08:48:00 UTC (rev 523) @@ -0,0 +1,39 @@ +/** + * ##% 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.event; + +/** + * A listener on {@link org.codelutin.vcs.runner.VCSActionThread} life cycle. + * + * @author chemit + */ +public interface VCSActionThreadEventListener extends java.util.EventListener { + + /** + * call when one action start on thread + * + * @param event current event + */ + public void onActionStarted(VCSActionThreadEvent event); + + /** + * call when one action is done by thread + * + * @param event current event + */ + public void onActionDone(VCSActionThreadEvent event); + + +} \ No newline at end of file Deleted: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEvent.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEvent.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEvent.java 2008-04-15 08:48:00 UTC (rev 523) @@ -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.event; - -import org.codelutin.vcs.VCSEntry; -import org.codelutin.vcs.type.VCSState; - -import java.util.EventObject; - -/** - * Events to be used when the state of a {@link org.codelutin.vcs.VCSEntry} has changed. - * - * @author chemit - */ -public class VCSEntryStateChangedEvent extends EventObject { - - private static final long serialVersionUID = 1L; - - protected VCSState oldState; - protected VCSState newState; - - /** - * Constructs a prototypical Event. - * - * @param source The object on which the Event initially occurred. - * @param oldState old state of the entry - * @param newState new state of event - * @throws IllegalArgumentException if source is null. - */ - public VCSEntryStateChangedEvent(VCSEntry source, VCSState oldState, VCSState newState) { - super(source); - this.oldState = oldState; - this.newState = newState; - } - - @Override - public VCSEntry getSource() { - return (VCSEntry) super.getSource(); - } - - public VCSState getOldState() { - return oldState; - } - - public VCSState getNewState() { - return newState; - } -} \ No newline at end of file Deleted: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEventListener.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEventListener.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/event/VCSEntryStateChangedEventListener.java 2008-04-15 08:48:00 UTC (rev 523) @@ -1,77 +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.event; - -import org.codelutin.vcs.type.VCSState; - -/** - * A listener on state of a {@link org.codelutin.vcs.VCSEntry}. - * <p/> - * This listener reacts on every change of state of a {@link org.codelutin.vcs.VCSEntry}, locally and remotely. - * <p/> - * This listener can be used on UIs to update the render of an entry from his state. - * - * @author chemit - */ -public interface VCSEntryStateChangedEventListener extends java.util.EventListener { - - /** - * call when entry's state becomes {@link VCSState#UNVERSIONNED} : - * <p/> - * entry was added on local repository, or removed from remote repository. - * - * @param event current event - */ - public void onAdded(VCSEntryStateChangedEvent event); - - /** - * call when entry's state becomes {@link VCSState#MODIFIED} : - * <p/> - * entry was localy modified. - * - * @param event current event - */ - public void onModified(VCSEntryStateChangedEvent event); - - /** - * call when entry's state becomes {@link VCSState#OUT_OF_DATE_AND_MODIFIED} or {@link VCSState#OUT_OF_DATE} : - * <p/> - * entry is obsolete on local. - * <p/> - * Note: <b>if entry was locally modified, and just has a new version of remote, this method will also be invoked.</b> - * - * @param event current event - */ - public void onObsoleted(VCSEntryStateChangedEvent event); - - /** - * call when entry's state becomes {@link VCSState#MISSING} : - * <p/> - * entry was remotely deleted. - * - * @param event current event - */ - public void onDeleted(VCSEntryStateChangedEvent event); - - /** - * call when entry's state becomes {@link VCSState#UP_TO_DATE} : - * <p/> - * entry was just updated, or rollbacked, or checkouted... - * - * @param event current event - */ - public void onUpdated(VCSEntryStateChangedEvent event); - -} \ No newline at end of file Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionManager.java 2008-04-15 08:48:00 UTC (rev 523) @@ -16,6 +16,7 @@ import org.codelutin.vcs.VCSConnexion; import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.event.VCSActionThreadEventListener; import org.codelutin.vcs.type.VCSAction; import java.util.concurrent.PriorityBlockingQueue; @@ -52,10 +53,7 @@ } public void open() { - if (thread != null) { - // thread is already opend - throw new IllegalStateException("thread is already opened"); - } + checkThreadNotInit(); (thread = new VCSActionThread(queue)).start(); } @@ -73,4 +71,30 @@ } } + public void addVCSActionThreadEventListener(VCSActionThreadEventListener l) { + checkThreadInit(); + thread.addVCSActionThreadEventListener(l); + } + + public void removeVCSActionThreadEventListener(VCSActionThreadEventListener l) { + if (thread!=null) { + thread.removeVCSActionThreadEventListener(l); + } + } + + protected void checkThreadInit() throws IllegalStateException { + if (thread == null) { + // thread is already opend + throw new IllegalStateException("thread is not opened"); + } + } + + protected void checkThreadNotInit() throws IllegalStateException { + if (thread != null) { + // thread is already opend + throw new IllegalStateException("thread is already opened"); + } + } + + } Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/runner/VCSActionThread.java 2008-04-15 08:48:00 UTC (rev 523) @@ -17,18 +17,21 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import static org.codelutin.i18n.I18n._; +import org.codelutin.util.ListenerSet; import org.codelutin.vcs.VCSConnexion; import org.codelutin.vcs.VCSEntry; import org.codelutin.vcs.VCSException; +import org.codelutin.vcs.event.VCSActionThreadEvent; +import org.codelutin.vcs.event.VCSActionThreadEventListener; import org.codelutin.vcs.type.VCSAction; import org.codelutin.vcs.type.VCSState; -import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Date; +import java.util.EnumMap; import java.util.List; import java.util.Map.Entry; import java.util.concurrent.BlockingQueue; @@ -36,9 +39,6 @@ /** @author chemit */ public class VCSActionThread extends Thread { - /** to notify when thread is busy or not */ - static public final String BUSY_STATE_PROPERTY_CHANGED = "thread.busy"; - /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(VCSActionThread.class); @@ -48,6 +48,8 @@ /** support for change properties support */ protected PropertyChangeSupport changeSupport; + protected transient ListenerSet<VCSActionThreadEventListener> listeners = new ListenerSet<VCSActionThreadEventListener>(); + public VCSActionThread(BlockingQueue<VCSActionQueueItem> queue) { super("VCSActionThread"); this.queue = queue; @@ -63,7 +65,7 @@ log.info("waiting for action..."); item = queue.take(); // acquire a first item, thread becomes busy TODO should synchronize thread - firePropertyChange(BUSY_STATE_PROPERTY_CHANGED, false, true); + fireStateBusy(false, true); do { if (item.getAction() == null) { // this is a special case to stop thread @@ -75,7 +77,7 @@ item = !queue.isEmpty() ? queue.take() : null; } while (run && item != null); // queue is empty, thread is no more busy - firePropertyChange(BUSY_STATE_PROPERTY_CHANGED, true, false); + fireStateBusy(true, false); } } catch (Throwable eee) { @@ -85,7 +87,7 @@ } } finally { // notify queue is dead - firePropertyChange(BUSY_STATE_PROPERTY_CHANGED, null, false); + fireStateBusy(null, false); log.info("Stop " + getName() + " at " + new Date()); } } @@ -94,8 +96,12 @@ for (Entry<VCSConnexion, VCSEntry[]> entry : item.getEntriesByConnexion().entrySet()) { VCSConnexion connexion = entry.getKey(); if (connexion.isOpen()) { - // only works on opened connexion + // after each 'atomic operation', notify listener operation is done + fireAction("onActionStarted", item.getAction(), entry); + // only works on opened connexion doAction0(item.getAction(), connexion, entry.getValue(), item.getMessage()); + // after each 'atomic operation', notify listener operation is done + fireAction("onActionDone", item.getAction(), entry); } } } @@ -118,14 +124,15 @@ for (VCSEntry entry : entries) { connexion.checkoutFile(entry.getFile().getParentFile(), entry.getFile().getName()); } - //updateState(VCSState.UP_TO_DATE, entries); + updateState(VCSState.UP_TO_DATE, entries); break; case COMMIT: - //updateState(VCSState.UP_TO_DATE, entries); + connexion.commit(files, message); + updateState(VCSState.UP_TO_DATE, entries); break; case DELETE: - - //updateState(VCSState.UP_TO_DATE, entries); + connexion.delete(files, message); + updateState(VCSState.UP_TO_DATE, entries); break; case DIFF: for (VCSEntry entry : entries) { @@ -133,84 +140,85 @@ } break; case OVERWRITE_AND_UPDATE: - - //updateState(VCSState.UP_TO_DATE, entries); + connexion.revert(files); + for (File file : files) { + connexion.update(file); + } + updateState(VCSState.UP_TO_DATE, entries); break; case REFRESH: break; case REVERT: - //updateState(VCSState.UP_TO_DATE, entries); + connexion.revert(files); + updateState(VCSState.UP_TO_DATE, getRevertMapper(), entries); break; case UPDATE: - - //updateState(VCSState.UP_TO_DATE, entries); + for (File file : files) { + connexion.update(file); + } + updateState(VCSState.UP_TO_DATE, entries); break; } } - protected void updateState(VCSState state, VCSEntry[] entries) { - for (VCSEntry entry : entries) { - entry.setState(state); + protected EnumMap<VCSState, VCSState> revertMapper; + + protected EnumMap<VCSState, VCSState> getRevertMapper() { + if (revertMapper == null) { + revertMapper = new EnumMap<VCSState, VCSState>(VCSState.class); + revertMapper.put(VCSState.OUT_OF_DATE_AND_MODIFIED, VCSState.OUT_OF_DATE); } + return revertMapper; } - protected List<File> getFiles(VCSEntry[] entries) { - List<File> result = new ArrayList<File>(); - for (VCSEntry entry : entries) { - result.add(entry.getFile()); + protected void fireAction(String actionName, VCSAction action, Entry<VCSConnexion, VCSEntry[]> entry) { + VCSActionThreadEvent event = new VCSActionThreadEvent(entry.getValue(), action); + try { + listeners.fire(actionName, event); + } catch (Exception e) { + log.error(e); } - return result; } - public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - if (listener == null) { - return; - } - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(propertyName, listener); + protected void fireStateBusy(Boolean oldState, Boolean newState) { + log.info("old state : " + oldState + ", new state : " + newState); } - public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { - if (listener == null) { - return; + protected void updateState(VCSState state, VCSEntry[] entries) { + for (VCSEntry entry : entries) { + entry.setState(state); } - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(listener); } - public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { - if (listener == null || changeSupport == null) { - return; + protected void updateState(VCSState state, EnumMap<VCSState, VCSState> mapper, VCSEntry[] entries) { + + for (VCSEntry entry : entries) { + if (mapper.containsKey(entry.getState())) { + entry.setState(mapper.get(entry.getState())); + } else { + entry.setState(state); + } } - changeSupport.removePropertyChangeListener(listener); } - public synchronized void removePropertyChangeListeners() { - if (changeSupport == null) { - return; + protected List<File> getFiles(VCSEntry[] entries) { + List<File> result = new ArrayList<File>(); + for (VCSEntry entry : entries) { + result.add(entry.getFile()); } - for (PropertyChangeListener listener : getPropertyChangeListeners()) { - changeSupport.removePropertyChangeListener(listener); - } + return result; } - public synchronized PropertyChangeListener[] getPropertyChangeListeners() { - if (changeSupport == null) { - return new PropertyChangeListener[0]; - } - return changeSupport.getPropertyChangeListeners(); + /** @param l the listener to add */ + public void addVCSActionThreadEventListener(VCSActionThreadEventListener l) { + listeners.add(l); + log.info("added listener on thread : " + listeners.size() + " : " + l); } - public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - if (changeSupport == null || (oldValue == null && newValue == null) || - (oldValue != null && oldValue.equals(newValue))) { - return; - } - changeSupport.firePropertyChange(propertyName, oldValue, newValue); + /** @param l the listener to remove */ + public void removeVCSActionThreadEventListener(VCSActionThreadEventListener l) { + listeners.remove(l); + log.info("removed listener on thread : " + listeners.size() + " : " + l); } } Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java 2008-04-15 08:48:00 UTC (rev 523) @@ -16,6 +16,7 @@ import org.codelutin.vcs.VCSConnexionConfig; import org.codelutin.vcs.type.VCSTypeRepo; +import org.codelutin.vcs.type.VCSConnexionMode; import java.io.File; @@ -33,6 +34,7 @@ protected String remoteDatabase; protected VCSTypeRepo typeRepo; protected File localDatabasePath; + protected VCSConnexionMode mode; public String getType() { return type; @@ -54,11 +56,18 @@ return userName; } + public VCSConnexionMode getMode() { + return mode; + } + public boolean isNoPassPhrase() { return noPassPhrase; } public String getPassphrase() { + if (passPhrase==null) { + passPhrase=""; + } return passPhrase; } @@ -125,4 +134,8 @@ public void setUseSshConnexion(boolean useSshConnexion) { this.useSshConnexion = useSshConnexion; } + + public void setConnexionMode(VCSConnexionMode mode) { + this.mode=mode; + } } Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java 2008-04-15 08:48:00 UTC (rev 523) @@ -24,7 +24,6 @@ import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.EnumMap; import java.util.EnumSet; import java.util.List; @@ -74,7 +73,7 @@ for (String relativeLocalPath : relativeLocalPaths) { VCSEntry entry = new VCSEntryImpl(connexion, relativeLocalPath); entry.populateState(timestamp); - entries.add(entry); + addEntry(entry); } } @@ -82,13 +81,31 @@ if (this.entries == null) { this.entries = new ArrayList<VCSEntry>(); } - this.entries.addAll(Arrays.asList(entries)); + for (VCSEntry entry : entries) { + addEntry(entry); + } } - public void refresh(long timestamp, List<VCSEntry> entries) throws IllegalStateException { + public void refresh(long timestamp, List<VCSEntry> entries) throws IllegalStateException, VCSException { checkPopulated(); + for (VCSEntry entry : entries) { + entry.populateState(timestamp); + /*if (entry.getState() == VCSState.UP_TO_DATE) { + removeEntry(entry); + } + it.remove();*/ + } } + public void refresh(long timestamp, VCSEntry entry) throws IllegalStateException, VCSException { + checkPopulated(); + entry.populateState(timestamp); + /*if (entry.getState() == VCSState.UP_TO_DATE) { + System.out.println("refresh: remove up to date entry " + entry); + this.entries.remove(entry); + }*/ + } + public List<VCSEntry> getEntries() throws IllegalStateException { checkPopulated(); // always return a copy of the list, to be safe... @@ -146,7 +163,6 @@ } } - public EnumMap<VCSAction, Integer> countActions(List<VCSEntry> entries) { EnumSet<VCSAction> set = EnumSet.allOf(VCSAction.class); EnumMap<VCSAction, Integer> map = new EnumMap<VCSAction, Integer>(VCSAction.class); @@ -163,18 +179,9 @@ map.put(vcsAction, tmp[index]); } return map; - /*List<VCSAction> result = new ArrayList<VCSAction>(); - for (VCSState vcsFileState : getStates(entries)) { - List<VCSAction> action = vcsFileState.getActions(); - for (VCSAction vcsAction : action) { - if (vcsAction != null && !result.contains(vcsAction)) { - result.add(vcsAction); - } - } - } - return result.toArray(new VCSAction[result.size()]);*/ } + public EnumMap<VCSState, Integer> countStates(List<VCSEntry> entries) { EnumSet<VCSState> set = EnumSet.allOf(VCSState.class); EnumMap<VCSState, Integer> map = new EnumMap<VCSState, Integer>(VCSState.class); @@ -190,18 +197,16 @@ map.put(state, tmp[index]); } return map; - /* - List<VCSState> result = new ArrayList<VCSState>(); - for (VCSEntry entry : entries) { - VCSState state = entry.getState(); - if (state != null && !result.contains(state)) { - result.add(state); - } - } - return result.toArray(new VCSState[result.size()]); - */ } + public void addEntry(VCSEntry entry) { + entries.add(entry); + } + + public void removeEntry(VCSEntry entry) { + entries.remove(entry); + } + protected List<String> transformToLocal(List<String> relativeRemotePath) { List<String> result = new ArrayList<String>(relativeRemotePath.size()); for (String s : relativeRemotePath) { @@ -215,4 +220,5 @@ throw new IllegalStateException(this + " was not populated..."); } } + } Modified: trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java =================================================================== --- trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java 2008-04-15 08:47:01 UTC (rev 522) +++ trunk/lutinvcs/core/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java 2008-04-15 08:48:00 UTC (rev 523) @@ -14,12 +14,9 @@ */ package org.codelutin.vcs.util; -import org.codelutin.util.ListenerSet; import org.codelutin.vcs.VCSConnexion; import org.codelutin.vcs.VCSEntry; import org.codelutin.vcs.VCSException; -import org.codelutin.vcs.event.VCSEntryStateChangedEvent; -import org.codelutin.vcs.event.VCSEntryStateChangedEventListener; import org.codelutin.vcs.type.VCSEntryLocation; import org.codelutin.vcs.type.VCSState; @@ -49,8 +46,6 @@ protected String diff; - protected transient ListenerSet<VCSEntryStateChangedEventListener> listeners = new ListenerSet<VCSEntryStateChangedEventListener>(); - private static final long serialVersionUID = 1L; public VCSEntryImpl(VCSConnexion connexion, String relativeLocalPath) { @@ -80,8 +75,7 @@ public void populateState(long timestamp) throws VCSException { this.timestamp = timestamp; - VCSState newState = connexion.getState(getFile(), null); - setState(newState); + this.state = connexion.getState(getFile(), null); } public void populateChangeLog() throws IllegalStateException, VCSException { @@ -100,11 +94,9 @@ } public void setState(VCSState state) { - VCSState oldState = this.state; - this.state = state; // mark new timestamp this.timestamp = System.nanoTime(); - fireStateChanged(oldState); + this.state = state; } public VCSEntryLocation getLocation() throws IllegalStateException { @@ -137,7 +129,7 @@ public BufferedReader getDiff() throws IllegalStateException, IOException, VCSException { checkPopulated(); - if (diff== null) { + if (diff == null) { populateDiff(); } return new BufferedReader(new StringReader(diff)); @@ -153,14 +145,6 @@ return null; } - public void addVCSEntryStateChangedEventListener(VCSEntryStateChangedEventListener l) { - listeners.add(l); - } - - public void removeVCSEntryStateChangedEventListener(VCSEntryStateChangedEventListener l) { - listeners.remove(l); - } - @Override public String toString() { return super.toString() + " " + localFile + " : " + state; @@ -172,52 +156,4 @@ } } - protected void fireStateChanged(VCSState oldState) { - if (oldState != null && oldState == state) { - // nothing to do - return; - } - // state has changed, must reset changelog and diff to be safe - diff = changelog = null; - - String methodName = null; - - switch (state) { - case MISSING: - methodName = "onDeleted"; - break; - case MODIFIED: - methodName = "onModified"; - break; - case OUT_OF_DATE: - methodName = "onObsoleted"; - break; - case OUT_OF_DATE_AND_MODIFIED: - methodName = oldState == VCSState.OUT_OF_DATE ? "onModified" : "onObsoleted"; - break; - case REMOVED: - methodName = "onDeleted"; - break; - case UNKNOWN: - return; - case UNVERSIONNED: - case UNVERSIONNED_OR_MISSING: - methodName = "onAdded"; - break; - case UP_TO_DATE: - methodName = "onUpdated"; - break; - } - - if (methodName == null) { - throw new IllegalStateException("could not find a disptacher property for state: " + state); - } - try { - VCSEntryStateChangedEvent event = new VCSEntryStateChangedEvent(this, oldState, state); - listeners.fire(methodName, event); - } catch (Exception e) { - //TODO - } - } - }
participants (1)
-
tchemit@users.labs.libre-entreprise.org