
eu.cedarsoft.devtools.modules.AddExternalsDefinition 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.modules;
import com.google.inject.Inject;
import eu.cedarsoft.devtools.Module;
import eu.cedarsoft.devtools.SubversionMessageHandler;
import eu.cedarsoft.devtools.SubversionSupport;
import eu.cedarsoft.utils.CmdLine;
import org.jetbrains.annotations.NotNull;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNProperty;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNPropertyHandler;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNPropertyData;
import org.tmatesoft.svn.core.wc.SVNRevision;
import java.io.File;
/**
* Adds an external definition (SVN)
*/
public class AddExternalsDefinition implements Module {
@NotNull
private final SubversionSupport subversionSupport;
@Inject
public AddExternalsDefinition( @NotNull SubversionSupport subversionSupport ) {
this.subversionSupport = subversionSupport;
}
@NotNull
public String getDescription() {
return SubversionMessageHandler.get( "module.add.external.definition" );
}
public void process( @NotNull final CmdLine cmdLine ) throws Exception {
cmdLine.out( SubversionMessageHandler.get( "module.add.external.definition" ) );
SVNClientManager manager = SVNClientManager.newInstance();
File currentDir = new File( "." );
SVNPropertyData property = manager.getWCClient().doGetProperty( currentDir, SVNProperty.EXTERNALS, SVNRevision.WORKING, SVNRevision.WORKING, false );
String propertyValue;
if ( property != null ) {
propertyValue = property.getValue();
cmdLine.out( SubversionMessageHandler.get( "current.external.definitions" ) );
String[] lines = propertyValue.split( "\n" );
for ( String line : lines ) {
String[] parts = line.split( " " );
if ( parts.length != 2 ) {
continue;
}
cmdLine.out( SubversionMessageHandler.get( "external.definition", parts[0].trim(), parts[1].trim() ) );
}
} else {
cmdLine.out( SubversionMessageHandler.get( "no.current.external.definitions" ) );
propertyValue = "";
}
cmdLine.outNl();
cmdLine.out( SubversionMessageHandler.get( "adding.external.definition" ) );
String directory = cmdLine.read( SubversionMessageHandler.get( "enter.directory" ) );
cmdLine.outNl();
String repository = cmdLine.read( SubversionMessageHandler.get( "enter.svn.url" ), subversionSupport.getRepositoryUrls() );
String path = cmdLine.read( SubversionMessageHandler.get( "enter.path", repository ) );
if ( !path.startsWith( "/" ) ) {
path = "/" + path;
}
String url = repository + path;
cmdLine.outNl();
cmdLine.out( SubversionMessageHandler.get( "will.add.external.definition.directory.url" ), directory, url );
cmdLine.pause( 3 );
String newPropertyValue = propertyValue.trim() + "\n" + directory + " " + url;
manager.getWCClient().doSetProperty( currentDir, SVNProperty.EXTERNALS, newPropertyValue.trim() + "\n", false, false, new ISVNPropertyHandler() {
public void handleProperty( File path, SVNPropertyData property ) throws SVNException {
debug( path.getAbsolutePath(), property.getName(), property.getValue() );
}
public void handleProperty( SVNURL url, SVNPropertyData property ) throws SVNException {
debug( url.getURIEncodedPath(), property.getName(), property.getValue() );
}
public void handleProperty( long revision, SVNPropertyData property ) throws SVNException {
}
public void debug( @NotNull String path, @NotNull String name, @NotNull String value ) {
cmdLine.out( SubversionMessageHandler.get( "setting.property.path", path, name, value ) );
}
} );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy