[Buix-commits] r355 - in trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs: . util
Author: tchemit Date: 2008-04-05 20:32:29 +0000 (Sat, 05 Apr 2008) New Revision: 355 Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java Removed: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java Log: introduce VCSEntry, VCSEntries, VCSConnexion and VCSConnexionConfig introduc default implementations delete VCSHelper Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java 2008-04-05 20:31:28 UTC (rev 354) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java 2008-04-05 20:32:29 UTC (rev 355) @@ -1,96 +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.net.URI; -import java.util.Map; - -/** - * Contract to be realized for a connexion to a vcs. - * <p/> - * The method {@link #init(VCSConfig, VCSHandler)} must be invoked before using the connexion. - * - * @author chemit - */ -public interface VCSConnexion { - - /** - * @return the working copy used, can be null if no working copy exists. - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - File getWorkingCopy() throws IllegalStateException; - - /** - * @return the URI used to connect to vcs - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - URI getRemoteURI() throws IllegalStateException; - - /** - * @return the mode of this connexion - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - VCSConnexionMode getMode() throws IllegalStateException; - - /** - * @return options to be used by this connexion - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - Map<String, String> getOptions() throws IllegalStateException; - - /** - * Initialise the connexion. - * <p/> - * If connexion can not be established, then the method {@link #hasFailed()} will always - * return <code>true</code>. - * - * @param config config to be used to initialize the connexion. - * @param handler handler to be used to initialize the connexion. - */ - void init(VCSConfig config, VCSHandler handler); - - /** - * Close connexion. - * - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - void open() throws IllegalStateException; - - /** - * Close connexion. - * - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - void close() throws IllegalStateException; - - /** - * @return <code>true</code> if connexion is opened, <code>false</code> otherwise - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - boolean isOpen() throws IllegalStateException; - - /** - * @return <code>true</code> if connexion is closed, <code>false</code> otherwise - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - boolean isClosed() throws IllegalStateException; - - /** - * @return <code>true</code> if connexion has failed, <code>false</code> otherwise - * @throws IllegalStateException if {@link #init(VCSConfig, VCSHandler)} was not invoked before. - */ - boolean hasFailed() throws IllegalStateException; -} Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexion.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,384 @@ +/** + * # #% 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.FileFilter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.URI; +import java.util.Collection; +import java.util.List; + +/** + * Contract to be realized for a connexion to a vcs. + * <p/> + * The method {@link #init(VCSConnexionConfig)} must be invoked before using the connexion. + * <p/> + * Note: you should not instanciate directly this class but use + * {@link org.codelutin.vcs.VCSProvider#newConnection(org.codelutin.vcs.VCSConnexionMode , VCSConnexionConfig)} instead. + * + * @author chemit + */ +public interface VCSConnexion { + + VCSProvider getProvider(); + + /** + * @return the working copy used, can be null if no working copy exists. + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + File getWorkingCopy() throws IllegalStateException; + + /** + * @return the URI used to connect to vcs + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + URI getRemoteURI() throws IllegalStateException; + + /** + * @return the mode of this connexion + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + VCSConnexionMode getMode() throws IllegalStateException; + + /** + * Initialize the connexion. + * <p/> + * If connexion can not be established, then the method {@link #hasFailed()} will always + * return <code>true</code>. + * + * @param config config to be used to initialize the connexion. + */ + void init(VCSConnexionConfig config); + + /** + * @return the config of the connexion + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + VCSConnexionConfig getConfig() throws IllegalStateException; + + /** + * test if connection is ok + * + * @throws VCSException if any problem + */ + void testConnection() throws VCSException; + + /** + * Close connexion. + * + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + void open() throws IllegalStateException; + + /** + * Close connexion. + * + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + void close() throws IllegalStateException; + + /** + * @return <code>true</code> if connexion is opened, <code>false</code> otherwise + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + boolean isOpen() throws IllegalStateException; + + /** + * @return <code>true</code> if connexion is closed, <code>false</code> otherwise + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + boolean isClosed() throws IllegalStateException; + + /** + * @return <code>true</code> if connexion has failed, <code>false</code> otherwise + * @throws IllegalStateException if {@link #init(VCSConnexionConfig)} was not invoked before. + */ + boolean hasFailed() throws IllegalStateException; + + /** @param l the listener to add */ + void addVCSConnexionEventListener(VCSConnexionEventListener l); + + /** @param l the listener to remove */ + void removeVCSConnexionEventListener(VCSConnexionEventListener l); + + /** + * init working copy, says if it is the first we use it it, we will checkout + * the databaseDirectory directory + * + * @throws VCSException if any exception while init + */ + void initWorkingCopy() throws VCSException; + + /** delete the local working copy with all his files */ + void deleteWorkingCopy(); + + /** + * @return a <code>FilenameFilter<code> to detect all files and directories in a vcs working copy that + * must be handled by vcs + */ + FilenameFilter getVersionnableFilenameFilter(); + + /** + * @return a <code>FileFilter<code> to detect all files and directories in a vcs working copy that + * must be handled by vcs + */ + FileFilter getVersionnableFileFilter(); + + /** + * @return name of directory used by vcs to store in working copy, a data's + * directory configuration (e.g CVS for cvs and .svn for svn) + */ + String getConfLocalDirname(); + + /** + * @return name of the file used by vcs to store in working copy + * configuration directory entries of data's directory (e.g Entries + * for cvs and entries for svn) + */ + String getConfLocalEntriesFilename(); + + VCSState getState(File fileState, Collection tmp) throws VCSException; + + VCSState getState(File file, Collection tmp, boolean noremote) throws VCSException; + + /** + * @param file file to test + * @return <code>true</code> if <code>file</code> is on remote + * repository, <code>false</code> otherwise. + */ + boolean isOnRemote(File file); + + /** + * @param file file to test + * @return <code>true</code> if file is uptodate,<code>false</code> + * otherwise. + * @throws VCSException if any exception while operation + */ + boolean isUpToDate(File file) throws VCSException; + + /** + * @param file file to test + * @return <code>true</code> if file is handled by VCS,<code>false</code> + * otherwise. + */ + boolean isVersionnableFile(File file); + + /** + * add on remote repository somes directories + * + * @param commitMessage commit message + * @param dirNames names of the directories to create on remote repository (could + * used multi-level directories) + * @throws VCSException if any exception while operation + */ + void makeRemoteDir(String commitMessage, String... dirNames) + throws VCSException; + + /** + * delete on remote repository somes directories + * + * @param commitMessage commit message + * @param dirNames names of the directories to delete on remote repository (could + * used multi-level directories) + * @throws VCSException if any exception while operation + */ + void deleteRemoteDir(String commitMessage, String... dirNames) + throws VCSException; + + /** + * add a list of files into repository + * + * @param files files to add + * @param msg message for VCS commit, if <code>null</code> then no commit + * is performed + * @return revision of the operation + * @throws VCSException if any exception while operation + */ + long add(List<File> files, String msg) throws VCSException; + + // void add(File file, String msg) throws VCSException; + + /** + * delete a list of files from repository + * + * @param files files to delete + * @param msg message for VCS commit, if <code>null</code> then no commit + * is performed + * @throws VCSException if any exception while operation + */ + void delete(List<File> files, String msg) throws VCSException; + + /** + * revert a list of files from repository + * + * @param files files to revert + * @throws VCSException if any exception while operation + */ + void revert(List<File> files) throws VCSException; + + /** + * commit a list of files into repository + * + * @param files files to commit + * @param msg message for VCS commit + * @return revision of the operation + * @throws VCSException if any exception while operation + */ + long commit(List<File> files, String msg) throws VCSException; + + /** + * update a file to repository to a certain revision + * + * @param file file to update + * @param revision object representing a revision for the current VCS + * @throws VCSException if any exception while operation + */ + void update(File file, Object revision) throws VCSException; + + /** + * update a file to repository + * + * @param file file to update + * @throws VCSException if any exception while operation + */ + void update(File file) throws VCSException; + + /** + * checkout a module from repository to a local file + * + * @param destDir local file where to checkout + * @param module module's name to checkout + * @param recurse flag to say to recurse checkout or not. + * @throws VCSException if any exception while operation + */ + void checkout(File destDir, String module, boolean recurse) throws VCSException; + + void checkoutFile(File destDir, String module) throws VCSException; + + long checkoutOnlyTheDirectory(File root, Object revision) throws VCSException; + + /** + * TODO This is not the good place : VCS != Storage + * + * @param directory directory to treate + * @return TODO + * @throws VCSException TODO + */ + List<String> getRemoteStorageNames(File directory) throws VCSException; + + /** + * TODO This is not the good place : VCS != Storage + * + * @param directory directory to treate + * @return TODO + */ + List<String> getLocalStorageNames(File directory); + + /** + * @param f local file to treate + * @return current local revision of a file + * @throws VCSException TODO + */ + Object getRevision(File f) throws VCSException; + + /** + * Obtain the list of log entries for the file + * + * @param startRevision TODO + * @param endRevision TODO + * @param file file to treate + * @return list of log entries for this file between two revisions + * @throws VCSException if any exception while grabbing infos + */ + List getLog(Object startRevision, Object endRevision, File file) + throws VCSException; + + /** + * obtain the content of a file for a specific revision + * + * @param file file to obtain + * @param revision revision treated + * @return the content of the file on repository for the specific revision + * passed as arguement. + * @throws VCSException if any exception while operation + * @throws java.io.IOException TODO + */ + String getFileContent(File file, Object revision) throws VCSException, IOException; + + /** + * Build the changelog for <code>file</code> from current revision of this + * local file against head repository head version. For each revision + * between current revision and head revision of this file, we give the + * following informations : + * <ul> + * <li>revision number</li> + * <li>author</li> + * <li>date</li> + * <li>commit message</li> + * </ul> + * + * @param file file to treate + * @return a string representation of change log for the local file to the + * head ? + * @throws VCSException if any exception while building changelog + */ + String getChangeLog(File file) throws VCSException; + + /** + * Generate in the ouputstream the diff between the current revision of the + * local file against headest revision on repository. <br> + * If file is uptodate, then does nothing. + * + * @param file the file to treate + * @return the diff + * @throws VCSException inf any exception while building diff, such as : + * <ul> + * <li>unversionned file</li> + * <li>unexistant file locally</li> + * <li>locally modified file ?</li> + * <li>...</li> + * </ul> + * @throws java.io.IOException if io problem with streams + */ + String getDiff(File file) throws VCSException, IOException; + + /** + * Generate in the ouputstream the diff between the current revision of the + * local file against another revision (<code>againstRevision</code>) on + * repository. <br> + * If file is uptodate, then does nothing. + * + * @param file the file to treate + * @param againstRevision the against revision to use + * @return the diff + * @throws VCSException inf any exception while building diff, such as : + * <ul> + * <li>unversionned file</li> + * <li>unexistant file locally</li> + * <li>locally modified file ?</li> + * <li>...</li> + * </ul> + * @throws java.io.IOException if problem with streams + */ + String getDiff(File file, Object againstRevision) throws VCSException, IOException; + + /** + * @return <code>true</code> if protocol has changed between config and working copy + * @throws VCSException if any pb + */ + boolean hasProtocoleChanged() throws VCSException; +} Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConfig.java) =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionConfig.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,67 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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; + +/** + * Contract to be realized by a VCSConnexion configuration. + * <p/> + * This class has no logic, ans is a <code>POJO</code>. + * + * @author chemit + */ +public interface VCSConnexionConfig { + + /** @return the type of vcs used */ + VCSType getType(); + + /** @return <code>true</code> if ssh connexion is used */ + boolean isUseSshConnexion(); + + /** @return the url of hostname */ + String getHostName(); + + /** @return location of the private ssh2 key file */ + File getKeyFile(); + + /** @return the user connexion login */ + String getUserName(); + + /** @return <code>true</code> if user ssh2 pair keys use a passphrase */ + boolean isNoPassPhrase(); + + String getPassphrase(); + + /** @return the full location path of the remote container of module */ + String getRemotePath(); + + /** @return the name of remote module */ + String getRemoteDatabase(); + + /** @return the full url path to the remote repository (with module name include) */ + String getRemoteDatabasePath(); + + File getLocalDatabasePath(); + + /** @return the type of reposotory used (head,tags,branches,...) */ + VCSTypeRepo getTypeRepo(); + + void setUseSshConnexion(boolean newValue); +} \ No newline at end of file Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEvent.java) =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEvent.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,56 @@ +/** + * # #% 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.util.EventObject; + +/** + * Events to be used while {@link org.codelutin.vcs.VCSHandler} life cycle. + * + * @author chemit + * @see org.codelutin.vcs.VCSHandlerEventListener + * @see org.codelutin.vcs.VCSHandler + */ +public class VCSConnexionEvent extends EventObject { + + private static final long serialVersionUID = 1L; + + protected Type state; + + public enum Type { + OPEN, CLOSE + } + + /** + * Constructs a prototypical Event. + * + * @param source The object on which the Event initially occurred. + * @param type type of event + * @throws IllegalArgumentException if source is null. + */ + public VCSConnexionEvent(VCSConnexion source, Type type) { + super(source); + this.state = type; + } + + @Override + public VCSConnexion getSource() { + return (VCSConnexion) super.getSource(); + } + + public Type getState() { + return state; + } +} \ No newline at end of file Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSHandlerEventListener.java) =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSConnexionEventListener.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,38 @@ +/** + * # #% 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; + +/** + * A listener on {@link VCSConnexion} life cycle + * + * @author chemit + */ +public interface VCSConnexionEventListener extends java.util.EventListener { + + /** + * call when vcs connexion was successfull open + * + * @param event current event + */ + public void open(VCSConnexionEvent event); + + /** + * call when vcs connexion was closed + * + * @param event current event + */ + public void close(VCSConnexionEvent event); + +} \ No newline at end of file Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntries.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,121 @@ +/** + * # #% 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 javax.swing.ListSelectionModel; +import java.util.List; + +/** @author chemit */ +public interface VCSEntries { + + /** + * Discover and Populate with all local and remote entries. + * + * @param timestamp gloabal timestamp to apply + * @param connexion connexion used to populate + * @throws VCSException if any pb with vcs io + */ + void populate(VCSConnexion connexion, long timestamp) throws VCSException; + + /** + * Populate with no discovering for a given list of local relative paths for a given location type. + * <p/> + * Note : <b>We always used the filesystem path separator to encode paths.</b> + * + * @param relativeLocalPaths list of local relative path to populate + * @param location location to be used + * @param timestamp gloabal timestamp to apply + * @param connexion connexion used tro refresh + * @throws VCSException if any pb with vcs io + */ + void populate(VCSConnexion connexion, List<String> relativeLocalPaths, VCSEntryLocation location, long timestamp) throws VCSException; + + /** + * Populate from pre-computed entries. No discovering is done, nor vcs io operations. + * + * @param location given location to use + * @param states pre-computed states to populate + */ + void populate(VCSEntryLocation location, VCSEntry[] states); + + /** + * refresh state of the entry. + * + * @param entries entries to refresh + * @param timestamp global timestamp to apply + * @throws IllegalStateException if entry was never populated + */ + void refresh(List<VCSEntry> entries, long timestamp) throws IllegalStateException; + + /** + * obtain the list of all entries. + * + * @return list of all entries + * @throws IllegalStateException if entry was never populated + */ + List<VCSEntry> getEntries() throws IllegalStateException; + + /** + * obtain the list of all entries for a given connexion + * + * @param connexion filter connexion + * @param entries entries to filter + * @return list of all entries for a given connexion + */ + List<VCSEntry> filter(VCSConnexion connexion, List<VCSEntry> entries); + + /** + * obtain the list of all entries for a given location + * + * @param location filter location + * @param entries entries to filter + * @return list of all entries for a given connexion + */ + List<VCSEntry> filter(VCSEntryLocation location, List<VCSEntry> entries); + + /** + * obtain the list of all entries for a given state + * + * @param state filter state + * @param entries entries to filter + * @return list of all entries for a given connexion + */ + List<VCSEntry> filter(VCSState state, List<VCSEntry> entries); + + /** + * obtain the list of all entries for a given selection model + * + * @param selectionModel filter from selection model + * @param entries entries to filter + * @return list of all entries for a given connexion + */ + List<VCSEntry> filter(ListSelectionModel selectionModel, List<VCSEntry> entries); + + /** + * obtain the list of all entries for a given action + * + * @param action filter state + * @param entries entries to filter + * @return list of all entries for a given connexion + */ + List<VCSEntry> filter(VCSAction action, List<VCSEntry> entries); + + VCSAction[] getActions(List<VCSEntry> entries); + + VCSState[] getStates(List<VCSEntry> entries); + + /** clear the list of entries. */ + void clear(); +} Copied: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java (from rev 345, trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSFileState.java) =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/VCSEntry.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,121 @@ +/** + * # #% 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.BufferedReader; +import java.io.File; +import java.io.Serializable; + +/** @author chemit */ +public interface VCSEntry extends Serializable { + + /** + * Populate the state of the entry, this method calls {@link #refresh(long)} method. + * + * @param timestamp gloabal timestamp to apply + * @throws VCSException if anypb with vcs io + */ + void populate(long timestamp) throws VCSException; + + /** + * refresh state of the entry. + * + * @param timestamp global timestamp to apply + * @throws IllegalStateException if entry was never populated + * @throws VCSException if anypb with vcs io + */ + void refresh(long timestamp) throws IllegalStateException, VCSException; + + /** + * Obtain the relative path from root repository to the entry. + * <p/> + * Note: <b>We use the filesystem path separator, could not be the same on remote</b> + * + * @return the relativePath from local root repository to the entry + */ + String getRelativeLocalPath(); + + /** + * Obtain the relative path from root repository to the entry. + * <p/> + * Note: <b>We use the '/' as path separator, could not be the same on local</b> + * + * @return the relativePath from remote root repository to the entry + */ + String getRelativeRemotePath(); + + /** + * Obtain the projected entry on local working copy. + * <p/> + * Note : <b> the file could not exists. + * + * @return the local file represented by this entry + */ + File getFile(); + + /** @return connexion used */ + VCSConnexion getConnexion(); + + /** + * @return the location of entry + * @throws IllegalStateException if entry was never populated + * @see VCSEntryLocation + */ + VCSEntryLocation getLocation() throws IllegalStateException; + + /** + * @return the last state found for the entry + * @throws IllegalStateException if entry was never populated + */ + VCSState getState() throws IllegalStateException; + + /** + * @return the timestamp of the last state synchronization for the entry + * @throws IllegalStateException if entry was never populated + */ + long getTimestamp() throws IllegalStateException; + + /** + * @return the rev of entry + * @throws IllegalStateException if entry was never populated + */ + String getRev() throws IllegalStateException; + + /** + * @return the changelog of entry from local aginst remote + * @throws IllegalStateException if entry was never populated + */ + BufferedReader getChangeLog() throws IllegalStateException; + + /** + * @return the diff of entry from local aginst remote + * @throws IllegalStateException if entry was never populated + */ + BufferedReader getDiff() throws IllegalStateException; + + /** + * @return the local entry content + * @throws IllegalStateException if entry was never populated, or entry is a directory + */ + BufferedReader getLocalContent() throws IllegalStateException; + + /** + * @return the remote entry content + * @throws IllegalStateException if entry was never populated, or entry is a directory + */ + BufferedReader getRemoteContent() throws IllegalStateException; + + void setState(VCSState state); +} \ No newline at end of file Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSConnexionConfigImpl.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,130 @@ +/** + * # #% 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.util; + +import org.codelutin.vcs.VCSConnexionConfig; +import org.codelutin.vcs.VCSType; +import org.codelutin.vcs.VCSTypeRepo; + +import java.io.File; + +/** @author chemit */ +public class VCSConnexionConfigImpl implements VCSConnexionConfig { + + private VCSType type; + private boolean useSshConnexion; + private String hostName; + private File keyFile; + private String userName; + private boolean noPassPhrase; + private String passPhrase; + private String remotePath; + private String remoteDatabase; + private VCSTypeRepo typeRepo; + private File localDatabasePath; + + + public VCSType getType() { + return type; + } + + public boolean isUseSshConnexion() { + return useSshConnexion; + } + + public String getHostName() { + return hostName; + } + + public File getKeyFile() { + return keyFile; + } + + public String getUserName() { + return userName; + } + + public boolean isNoPassPhrase() { + return noPassPhrase; + } + + public String getPassphrase() { + return passPhrase; + } + + public String getRemotePath() { + return remotePath; + } + + public String getRemoteDatabase() { + return remoteDatabase; + } + + public String getRemoteDatabasePath() { + return remotePath + '/' + remoteDatabase; + } + + public File getLocalDatabasePath() { + return localDatabasePath; + } + + public VCSTypeRepo getTypeRepo() { + return typeRepo; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + public void setKeyFile(File keyFile) { + this.keyFile = keyFile; + } + + public void setLocalDatabasePath(File localDatabasePath) { + this.localDatabasePath = localDatabasePath; + } + + public void setNoPassPhrase(boolean noPassPhrase) { + this.noPassPhrase = noPassPhrase; + } + + public void setPassPhrase(String passPhrase) { + this.passPhrase = passPhrase; + } + + public void setRemoteDatabase(String remoteDatabase) { + this.remoteDatabase = remoteDatabase; + } + + public void setRemotePath(String remotePath) { + this.remotePath = remotePath; + } + + public void setType(VCSType type) { + this.type = type; + } + + public void setTypeRepo(VCSTypeRepo typeRepo) { + this.typeRepo = typeRepo; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public void setUseSshConnexion(boolean useSshConnexion) { + this.useSshConnexion = useSshConnexion; + } +} Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntriesImpl.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,201 @@ +/** + * # #% 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.util; + +import org.codelutin.vcs.VCSAction; +import org.codelutin.vcs.VCSConnexion; +import org.codelutin.vcs.VCSEntries; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; +import org.codelutin.vcs.VCSException; +import org.codelutin.vcs.VCSState; + +import javax.swing.ListSelectionModel; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Collections; +import java.util.Arrays; + +/** @author chemit */ +public class VCSEntriesImpl implements VCSEntries { + + protected List<VCSEntry> entries; + + public void populate(VCSConnexion connexion, long timestamp) throws VCSException { + + List<String> localFiles = connexion.getLocalStorageNames(connexion.getWorkingCopy()); + + List<String> remoteFiles = transformToLocal(connexion.getRemoteStorageNames(connexion.getWorkingCopy())); + + List<String> allFiles = new ArrayList<String>(); + + // detect location all from remote files + for (Iterator<String> it = remoteFiles.iterator(); it.hasNext();) { + String relativePath = it.next(); + if (localFiles.contains(relativePath)) { + allFiles.add(relativePath); + it.remove(); + localFiles.remove(relativePath); + } + } + + // detect location all from local files + for (Iterator<String> it = localFiles.iterator(); it.hasNext();) { + String relativePath = it.next(); + if (remoteFiles.contains(relativePath)) { + allFiles.add(relativePath); + it.remove(); + remoteFiles.remove(relativePath); + } + } + + populate(connexion, localFiles, VCSEntryLocation.LOCAL, timestamp); + populate(connexion, remoteFiles, VCSEntryLocation.REMOTE, timestamp); + populate(connexion, allFiles, VCSEntryLocation.ALL, timestamp); + + } + + public void populate(VCSConnexion connexion, List<String> relativeLocalPaths, VCSEntryLocation location, long timestamp) throws VCSException { + if (entries == null) { + entries = new ArrayList<VCSEntry>(); + } + for (String relativeLocalPath : relativeLocalPaths) { + VCSEntry entry = new VCSEntryImpl(connexion, relativeLocalPath); + entry.populate(timestamp); + entries.add(entry); + } + } + + public void populate(VCSEntryLocation location, VCSEntry[] entries) { + if (this.entries == null) { + this.entries = new ArrayList<VCSEntry>(); + } + this.entries.addAll(Arrays.asList(entries)); + } + + public void refresh(List<VCSEntry> entries, long timestamp) throws IllegalStateException { + checkPopulated(); + } + + public List<VCSEntry> getEntries() throws IllegalStateException { + checkPopulated(); + // always return a copy of the list, to be safe... + return new ArrayList<VCSEntry>(entries); + } + + public List<VCSEntry> filter(VCSConnexion connexion, List<VCSEntry> entries) { + List<VCSEntry> result = new ArrayList<VCSEntry>(); + for (VCSEntry entry : entries) { + if (connexion.equals(entry.getConnexion())) { + result.add(entry); + } + } + return result; + } + + public List<VCSEntry> filter(VCSEntryLocation location, List<VCSEntry> entries) { + if (location == VCSEntryLocation.ALL) { + return new ArrayList<VCSEntry>(entries); + } + List<VCSEntry> result = new ArrayList<VCSEntry>(); + for (VCSEntry entry : entries) { + VCSEntryLocation vcsEntryLocation = entry.getLocation(); + if (vcsEntryLocation == VCSEntryLocation.ALL || location.equals(vcsEntryLocation)) { + result.add(entry); + } + } + return result; + } + + public List<VCSEntry> filter(VCSState state, List<VCSEntry> entries) { + List<VCSEntry> result = new ArrayList<VCSEntry>(); + for (VCSEntry entry : entries) { + if (state.equals(entry.getState())) { + result.add(entry); + } + } + return result; + } + + public List<VCSEntry> filter(ListSelectionModel selectionModel, List<VCSEntry> entries) { + if (entries.isEmpty() || selectionModel.isSelectionEmpty()) { + return Collections.emptyList(); + } + List<VCSEntry> list = new ArrayList<VCSEntry>(); + for (int i = 0, max = entries.size(); i < max; i++) { + if (selectionModel.isSelectedIndex(i)) { + list.add(entries.get(i)); + } + } + return list; + } + + public List<VCSEntry> filter(VCSAction action, List<VCSEntry> entries) { + List<VCSEntry> result = new ArrayList<VCSEntry>(); + for (VCSEntry entry : entries) { + if (entry.getState().getActions().contains(action)) { + result.add(entry); + } + } + return result; + } + + public void clear() { + //checkPopulated(); + if (entries != null) { + entries.clear(); + } + } + + + public VCSAction[] getActions(List<VCSEntry> entries) { + 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 VCSState[] getStates(List<VCSEntry> entries) { + 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()]); + } + + protected List<String> transformToLocal(List<String> relativeRemotePath) { + List<String> result = new ArrayList<String>(relativeRemotePath.size()); + for (String s : relativeRemotePath) { + result.add(AbstractVCSHandler.convertToLocalName(s)); + } + return result; + } + + protected void checkPopulated() throws IllegalStateException { + if (entries == null) { + throw new IllegalStateException(this + " was not populated..."); + } + } +} Added: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java (rev 0) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSEntryImpl.java 2008-04-05 20:32:29 UTC (rev 355) @@ -0,0 +1,127 @@ +/** + * # #% 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.util; + +import org.codelutin.vcs.VCSConnexion; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; +import org.codelutin.vcs.VCSState; +import org.codelutin.vcs.VCSException; + +import java.io.BufferedReader; +import java.io.File; + +/** @author chemit */ +public class VCSEntryImpl implements VCSEntry { + + protected transient final VCSConnexion connexion; + + protected final String relativeLocalPath; + + protected final String relativeRemotePath; + + protected final File localFile; + + protected VCSState state; + + protected long timestamp; + + protected String rev; + private static final long serialVersionUID = -6628119456256629555L; + + public VCSEntryImpl(VCSConnexion connexion, String relativeLocalPath) { + this.connexion = connexion; + this.relativeLocalPath = relativeLocalPath; + this.relativeRemotePath = AbstractVCSHandler.convertToRemoteName(relativeLocalPath); + this.localFile = new File(connexion.getWorkingCopy(), relativeLocalPath); + } + + public void populate(long timestamp) throws VCSException { + this.timestamp = timestamp; + this.state = connexion.getState(new File(connexion.getWorkingCopy(), relativeLocalPath), null); + } + + public void refresh(long timestamp) throws IllegalStateException, VCSException { + checkPopulated(); + populate(timestamp); + } + + public String getRelativeLocalPath() { + return relativeLocalPath; + } + + public String getRelativeRemotePath() { + return relativeRemotePath; + } + + public File getFile() { + return localFile; + } + + public VCSConnexion getConnexion() { + return connexion; + } + + public VCSEntryLocation getLocation() throws IllegalStateException { + checkPopulated(); + return state.getLocation(); + } + + public VCSState getState() throws IllegalStateException { + checkPopulated(); + return state; + } + + public long getTimestamp() throws IllegalStateException { + checkPopulated(); + return timestamp; + } + + public String getRev() throws IllegalStateException { + checkPopulated(); + return rev; + } + + public BufferedReader getChangeLog() throws IllegalStateException { + checkPopulated(); + return null; + } + + public BufferedReader getDiff() throws IllegalStateException { + checkPopulated(); + return null; + } + + public BufferedReader getLocalContent() throws IllegalStateException { + checkPopulated(); + return null; + } + + public BufferedReader getRemoteContent() throws IllegalStateException { + checkPopulated(); + return null; + } + + public void setState(VCSState state) { + this.state = state; + } + + protected void checkPopulated() throws IllegalStateException { + if (timestamp == -1) { + throw new IllegalStateException(this + " was not populated"); + } + } + +} Deleted: trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java =================================================================== --- trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java 2008-04-05 20:31:28 UTC (rev 354) +++ trunk/lutinvcs/lutinvcs-api/src/main/java/org/codelutin/vcs/util/VCSHelper.java 2008-04-05 20:32:29 UTC (rev 355) @@ -1,194 +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.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; - -@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
participants (1)
-
tchemit@users.labs.libre-entreprise.org