All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.cedarsoft.devtools.modules.SwitchToNewUrlModule Maven / Gradle / Ivy

The newest version!
package eu.cedarsoft.devtools.modules;

import com.google.inject.Inject;
import eu.cedarsoft.devtools.Module;
import eu.cedarsoft.devtools.OldUrlNotFoundException;
import eu.cedarsoft.devtools.ProcessWrapper;
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.SVNURL;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCClient;

import java.io.File;

/**
 * Switches to a new url
 */
public class SwitchToNewUrlModule implements Module {
  @NotNull
  private final SubversionSupport subversionSupport;

  @Inject
  public SwitchToNewUrlModule( @NotNull SubversionSupport subversionSupport ) {
    this.subversionSupport = subversionSupport;
  }

  @NotNull
  public String getDescription() {
    return SubversionMessageHandler.get( "module.switch.repository" );
  }

  public void process( @NotNull CmdLine cmdLine ) throws Exception {
    SVNClientManager manager = SVNClientManager.newInstance();
    File current = new File( "." );

    SVNWCClient client = manager.getWCClient();
    SVNInfo info = client.doInfo( current.getCanonicalFile(), SVNRevision.WORKING );
    if ( info == null ) {
      throw new IllegalStateException( "No info found for " + current.getCanonicalPath() );
    }

    SVNURL actualUrl = info.getRepositoryRootURL();

    String newUrl;
    try {
      newUrl = subversionSupport.getCorrespondingNewUrl( actualUrl );
    } catch ( OldUrlNotFoundException ignore ) {
      newUrl = cmdLine.read( SubversionMessageHandler.get( "enter.new.url.for", actualUrl.toString() ), "" );
      subversionSupport.addRepositoryUrl( newUrl );
      subversionSupport.addOldRepositoryUrl( actualUrl.toString(), newUrl );
    }

    cmdLine.out( SubversionMessageHandler.get( "module.switch.relocating", actualUrl, newUrl ) );
    cmdLine.pause( 5 );

    String command = subversionSupport.getSubversionBin() + " switch --relocate " + actualUrl + " " + newUrl;
    cmdLine.out( "---> " + command );
    ProcessWrapper.runCommand( cmdLine, command );
    cmdLine.success( SubversionMessageHandler.get( "module.processed.successfully" ) );
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy