Search in sources :

Example 1 with JazzScmProviderRepository

use of org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository in project maven-scm by apache.

the class JazzCheckInCommandTest method testCreateCreateChangesetCommand.

public void testCreateCreateChangesetCommand() throws Exception {
    JazzScmProviderRepository repo = getScmProviderRepository();
    Commandline cmd = new JazzCheckInCommand().createCreateChangesetCommand(repo, getScmFileSet(), "This is my comment.").getCommandline();
    String expected = "scm create changeset --username myUserName --password myPassword \"This is my comment.\"";
    assertCommandLine(expected, getWorkingDirectory(), cmd);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 2 with JazzScmProviderRepository

use of org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository in project maven-scm by apache.

the class JazzCheckInCommandTest method testCreateCheckInCommandCheckingInLocalChanges.

public void testCreateCheckInCommandCheckingInLocalChanges() throws Exception {
    JazzScmProviderRepository repo = getScmProviderRepository();
    Commandline cmd = new JazzCheckInCommand().createCheckInCommand(repo, new ScmFileSet(getWorkingDirectory())).getCommandline();
    String expected = "scm checkin --username myUserName --password myPassword .";
    assertCommandLine(expected, getWorkingDirectory(), cmd);
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) Commandline(org.codehaus.plexus.util.cli.Commandline) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 3 with JazzScmProviderRepository

use of org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository in project maven-scm by apache.

the class JazzCheckInCommandTest method testCreateChangesetAssociateCommand.

public void testCreateChangesetAssociateCommand() throws Exception {
    JazzScmProviderRepository repo = getScmProviderRepository();
    // Populate the values that are normally parsed and set by the StatusConsumer.
    repo.setWorkItem("215762");
    Commandline cmd = new JazzCheckInCommand().createChangesetAssociateCommand(repo, new Integer(1234)).getCommandline();
    // Because we do not use a ScmFileSet, the working dir is not set, so the test fails.
    cmd.setWorkingDirectory(getWorkingDirectory());
    String expected = "scm changeset associate --username myUserName --password myPassword 1234 215762";
    assertCommandLine(expected, getWorkingDirectory(), cmd);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 4 with JazzScmProviderRepository

use of org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository in project maven-scm by apache.

the class JazzScmProvider method makeProviderScmRepository.

/**
 * This method parses the scm URL and returns a SCM provider repository.
 * At this point, the scmUrl is the part after scm:provider_name: in your SCM URL.
 * <p/>
 * The basic url parsing approach is to be as loose as possible.
 * If you specify as per the docs you'll get what you expect.
 * If you do something else the result is undefined.
 * Don't use "/" "\" or "@" as the delimiter.
 * <p/>
 * Parse the scmUrl, which will be of the form:
 * [username[;password]@]http[s]://server_name[:port]/contextRoot:repositoryWorkspace
 * eg:
 * Deb;Deb@https://rtc:9444/jazz:BogusRepositoryWorkspace
 * {@inheritDoc}
 */
public ScmProviderRepository makeProviderScmRepository(String scmUrl, char delimiter) throws ScmRepositoryException {
    // Called from:
    // AbstractScmProvider.makeScmRepository()
    // AbstractScmProvider.validateScmUrl()
    getLogger().debug("JazzScmProvider:makeProviderScmRepository()");
    getLogger().debug("Provided scm url   - " + scmUrl);
    getLogger().debug("Provided delimiter - '" + delimiter + "'");
    String jazzUrlAndWorkspace = null;
    String usernameAndPassword = null;
    // Look for the Jazz URL after any '@' delimiter used to pass
    // username/password etc (which may not have been specified)
    int lastAtPosition = scmUrl.lastIndexOf('@');
    if (lastAtPosition == -1) {
        // The username;password@ was not supplied.
        jazzUrlAndWorkspace = scmUrl;
    } else {
        // The username@ or username;password@ was supplied.
        jazzUrlAndWorkspace = (lastAtPosition < 0) ? scmUrl : scmUrl.substring(lastAtPosition + 1);
        usernameAndPassword = (lastAtPosition < 0) ? null : scmUrl.substring(0, lastAtPosition);
    }
    // jazzUrlAndWorkspace should be: http[s]://server_name:port/contextRoot:repositoryWorkspace
    // usernameAndPassword should be: username;password or null
    // username and password may not be supplied, and so may remain null.
    String username = null;
    String password = null;
    if (usernameAndPassword != null) {
        // Can be:
        // username
        // username;password
        int delimPosition = usernameAndPassword.indexOf(';');
        username = delimPosition >= 0 ? usernameAndPassword.substring(0, delimPosition) : usernameAndPassword;
        password = delimPosition >= 0 ? usernameAndPassword.substring(delimPosition + 1) : null;
    }
    // We will now validate the jazzUrlAndWorkspace for right number of colons.
    // This has been observed in the wild, where the contextRoot:repositoryWorkspace was not properly formed
    // and this resulted in very strange results in the way in which things were parsed.
    int colonsCounted = 0;
    int colonIndex = 0;
    while (colonIndex != -1) {
        colonIndex = jazzUrlAndWorkspace.indexOf(":", colonIndex + 1);
        if (colonIndex != -1) {
            colonsCounted++;
        }
    }
    // havePort may also be true when port is supplied, but otherwise have a malformed URL.
    boolean havePort = colonsCounted == 3;
    // Look for workspace after the end of the Jazz URL
    int repositoryWorkspacePosition = jazzUrlAndWorkspace.lastIndexOf(delimiter);
    String repositoryWorkspace = jazzUrlAndWorkspace.substring(repositoryWorkspacePosition + 1);
    String jazzUrl = jazzUrlAndWorkspace.substring(0, repositoryWorkspacePosition);
    // Validate the protocols.
    try {
        // Determine if it is a valid URI.
        URI jazzUri = URI.create(jazzUrl);
        String scheme = jazzUri.getScheme();
        getLogger().debug("Scheme - " + scheme);
        if (scheme == null || !(scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) {
            throw new ScmRepositoryException("Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT);
        }
    } catch (IllegalArgumentException e) {
        throw new ScmRepositoryException("Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT);
    }
    // At this point, jazzUrl is guaranteed to start with either http:// or https://
    // Further process the jazzUrl to extract the server name and port.
    String hostname = null;
    int port = 0;
    if (havePort) {
        // jazzUrlAndWorkspace should be: http[s]://server_name:port/contextRoot:repositoryWorkspace
        // jazzUrl should be            : http[s]://server_name:port/contextRoot
        // The +3 accounts for the "://"
        int protocolIndex = jazzUrl.indexOf(":") + 3;
        int portIndex = jazzUrl.indexOf(":", protocolIndex + 1);
        hostname = jazzUrl.substring(protocolIndex, portIndex);
        int pathIndex = jazzUrl.indexOf("/", portIndex + 1);
        String portNo = jazzUrl.substring(portIndex + 1, pathIndex);
        try {
            port = Integer.parseInt(portNo);
        } catch (NumberFormatException nfe) {
            throw new ScmRepositoryException("Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT);
        }
    } else {
        // jazzUrlAndWorkspace should be: http[s]://server_name/contextRoot:repositoryWorkspace
        // jazzUrl should be            : http[s]://server_name/contextRoot
        // So we will set port to zero.
        // The +3 accounts for the "://"
        int protocolIndex = jazzUrl.indexOf(":") + 3;
        int pathIndex = jazzUrl.indexOf("/", protocolIndex + 1);
        if ((protocolIndex != -1) && (pathIndex != -1)) {
            hostname = jazzUrl.substring(protocolIndex, pathIndex);
        } else {
            throw new ScmRepositoryException("Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT);
        }
    }
    getLogger().debug("Creating JazzScmProviderRepository with the following values:");
    getLogger().debug("jazzUrl             - " + jazzUrl);
    getLogger().debug("username            - " + username);
    getLogger().debug("password            - " + password);
    getLogger().debug("hostname            - " + hostname);
    getLogger().debug("port                - " + port);
    getLogger().debug("repositoryWorkspace - " + repositoryWorkspace);
    return new JazzScmProviderRepository(jazzUrl, username, password, hostname, port, repositoryWorkspace);
}
Also used : ScmRepositoryException(org.apache.maven.scm.repository.ScmRepositoryException) URI(java.net.URI) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 5 with JazzScmProviderRepository

use of org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository in project maven-scm by apache.

the class JazzChangeLogCommand method createListChangesetCommand.

protected JazzScmCommand createListChangesetCommand(ScmProviderRepository repo, ScmFileSet fileSet, List<ChangeSet> changeSets) {
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    JazzScmCommand command = new JazzScmCommand(JazzConstants.CMD_LIST, JazzConstants.CMD_SUB_CHANGESETS, repo, fileSet, getLogger());
    command.addArgument(JazzConstants.ARG_WORKSPACE);
    command.addArgument(jazzRepo.getWorkspace());
    for (int i = 0; i < changeSets.size(); i++) {
        command.addArgument(changeSets.get(i).getRevision());
    }
    return command;
}
Also used : JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Aggregations

JazzScmProviderRepository (org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)17 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)7 ErrorConsumer (org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer)6 DebugLoggerConsumer (org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer)4 Commandline (org.codehaus.plexus.util.cli.Commandline)4 Matcher (java.util.regex.Matcher)3 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)3 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 File (java.io.File)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ScmException (org.apache.maven.scm.ScmException)1 ScmFile (org.apache.maven.scm.ScmFile)1 ScmFileSet (org.apache.maven.scm.ScmFileSet)1 ScmResult (org.apache.maven.scm.ScmResult)1 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)1 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)1 ListScmResult (org.apache.maven.scm.command.list.ListScmResult)1 TagScmResult (org.apache.maven.scm.command.tag.TagScmResult)1 JazzAddCommand (org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand)1