
eu.cedarsoft.devtools.SubversionSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of subversion Show documentation
Show all versions of subversion Show documentation
Subversion modules for DevTools
The newest version!
package eu.cedarsoft.devtools;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Subversion Support class
*/
@Singleton
public class SubversionSupport {
static {
SVNRepositoryFactoryImpl.setup();
DAVRepositoryFactory.setup();
FSRepositoryFactory.setup();
}
@NonNls
public static final String PROPERTY_SUBVERSION_BIN = "subversionBin";
@NonNls
public static final String PROPERTY_REPOSITORY_URLS = "repositoryUrls";
@NonNls
public static final String PROPERTY_OLD_REPOSITORY_URLS = "oldRepositoryUrls";
private final PropertyChangeSupport pcs = new PropertyChangeSupport( this );
@NotNull
private final List repositoryUrls = new ArrayList();
@NotNull
@NonNls
private final String subversionBin;
@NotNull
private final DirectorySupport directorySupport;
@NotNull
private final Map oldRepositoryUrls = new HashMap();
@Inject
public SubversionSupport( @NotNull DirectorySupport directorySupport, @SubversionBin @NotNull String subversionBin ) {
this.directorySupport = directorySupport;
this.subversionBin = subversionBin;
}
@NotNull
public ISVNAuthenticationManager getAuthenticationManager() {
return new DefaultSVNAuthenticationManager( null, true, null, null );
}
@NotNull
@NonNls
public String getSubversionBin() {
return subversionBin;
}
@NotNull
@NonNls
public List getRepositoryUrls() {
return Collections.unmodifiableList( repositoryUrls );
}
public void setRepositoryUrls( @NonNls @NotNull List repositoryUrls ) {
List old = new ArrayList( repositoryUrls );
this.repositoryUrls.clear();
this.repositoryUrls.addAll( repositoryUrls );
pcs.firePropertyChange( PROPERTY_REPOSITORY_URLS, old, repositoryUrls );
}
public void addRepositoryUrl( @NotNull @NonNls String repositoryUrl ) {
if ( repositoryUrls.contains( repositoryUrl ) ) {
return;
}
List old = new ArrayList( repositoryUrls );
this.repositoryUrls.add( repositoryUrl );
pcs.firePropertyChange( PROPERTY_REPOSITORY_URLS, old, repositoryUrls );
}
public void setOldRepositoryUrls( @NotNull Map oldRepositoryUrls ) {
Map old = new HashMap( this.oldRepositoryUrls );
this.oldRepositoryUrls.clear();
this.oldRepositoryUrls.putAll( oldRepositoryUrls );
pcs.firePropertyChange( PROPERTY_OLD_REPOSITORY_URLS, old, this.oldRepositoryUrls );
}
public void addOldRepositoryUrl( @NotNull @NonNls String oldUrl, @NotNull @NonNls String newUrl ) {
if ( !repositoryUrls.contains( newUrl ) ) {
throw new IllegalArgumentException( "Invalid newUrl \"" + newUrl + "\"" );
}
Map old = new HashMap( oldRepositoryUrls );
oldRepositoryUrls.put( oldUrl, newUrl );
pcs.firePropertyChange( PROPERTY_OLD_REPOSITORY_URLS, old, oldRepositoryUrls );
}
@NotNull
public Map getOldRepositoryUrls() {
return Collections.unmodifiableMap( oldRepositoryUrls );
}
/**
* Returns the correpsonding new url for the given old url
*
* @param oldUrl the old url
* @return the new url
*/
@NotNull
@NonNls
public String getCorrespondingNewUrl( @NotNull @NonNls String oldUrl ) throws OldUrlNotFoundException {
String newUrl = oldRepositoryUrls.get( oldUrl );
if ( newUrl == null ) {
throw new OldUrlNotFoundException( "No new URL found for " + oldUrl );
}
return newUrl;
}
@NotNull
public String getCorrespondingNewUrl( @NotNull SVNURL actualUrl ) throws OldUrlNotFoundException {
return getCorrespondingNewUrl( actualUrl.toString() );
}
@NotNull
public String guessImportName( @NotNull File dirToImport ) throws IOException {
if ( !dirToImport.exists() ) {
throw new IllegalArgumentException( "File does not exist: " + dirToImport.getCanonicalPath() );
}
if ( !dirToImport.isDirectory() ) {
throw new IllegalArgumentException( "File ist not a directory " + dirToImport.getCanonicalPath() );
}
if ( directorySupport.isInProjectRoot( dirToImport ) ) {
String path = directorySupport.getProjectSubPath( dirToImport );
return path.replaceAll( "/", "." );
}
return dirToImport.getCanonicalFile().getName();
}
public void addPropertyChangeListener( PropertyChangeListener listener ) {
pcs.addPropertyChangeListener( listener );
}
public void removePropertyChangeListener( PropertyChangeListener listener ) {
pcs.removePropertyChangeListener( listener );
}
public void addPropertyChangeListener( String propertyName, PropertyChangeListener listener ) {
pcs.addPropertyChangeListener( propertyName, listener );
}
public void removePropertyChangeListener( String propertyName, PropertyChangeListener listener ) {
pcs.removePropertyChangeListener( propertyName, listener );
}
@NotNull
public DirectorySupport getDirectorySupport() {
return directorySupport;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy