Search in sources :

Example 11 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class JazzScmProvider method add.

/**
 * {@inheritDoc}
 */
public AddScmResult add(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    getLogger().debug("JazzScmProvider:add()");
    JazzAddCommand command = new JazzAddCommand();
    command.setLogger(getLogger());
    return (AddScmResult) command.execute(repository, fileSet, parameters);
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) JazzAddCommand(org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand)

Example 12 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class JazzAddCommand method executeAddCommand.

public AddScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    // NOTE: THIS IS ALSO CALLED DIRECTLY FROM THE CHECKIN COMMAND.
    // 
    // The "checkin" command does not produce consumable output as to which individual files were checked in. (in
    // 2.0.0.2 at least). Since only "locally modified" changes get checked in, we call a "status" command to
    // generate a list of these files.
    File baseDir = fileSet.getBasedir();
    File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
    List<ScmFile> changedScmFiles = new ArrayList<ScmFile>();
    List<File> changedFiles = new ArrayList<File>();
    List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
    JazzStatusCommand statusCmd = new JazzStatusCommand();
    statusCmd.setLogger(getLogger());
    StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
    List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
    for (ScmFile file : statusScmFiles) {
        getLogger().debug("Iterating over statusScmFiles: " + file);
        if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
            changedScmFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
            changedFiles.add(new File(parentFolder, file.getPath()));
        }
    }
    List<File> files = fileSet.getFileList();
    if (files.size() == 0) {
        // Either commit all local changes
        commitedFiles = changedScmFiles;
    } else {
        // Or commit specific files
        for (File file : files) {
            if (fileExistsInFileList(file, changedFiles)) {
                commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
            }
        }
    }
    // Now that we have a list of files to process, we can "add" (scm checkin) them.
    JazzAddConsumer addConsumer = new JazzAddConsumer(repo, getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand command = createAddCommand(repo, fileSet);
    int status = command.execute(addConsumer, errConsumer);
    if (status != 0) {
        return new AddScmResult(command.getCommandString(), "Error code for Jazz SCM add (checkin) command - " + status, errConsumer.getOutput(), false);
    }
    return new AddScmResult(command.getCommandString(), addConsumer.getFiles());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 13 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class JazzCheckInCommand method executeCheckInCommand.

protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    // Call the Add command to perform the checkin into the repository workspace.
    JazzAddCommand addCommand = new JazzAddCommand();
    addCommand.setLogger(getLogger());
    AddScmResult addResult = addCommand.executeAddCommand(repo, fileSet);
    // Now, if it has a flow target, deliver it.
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
        // Push if we need too
        JazzScmCommand deliverCmd = createDeliverCommand((JazzScmProviderRepository) repo, fileSet);
        StreamConsumer deliverConsumer = // No need for a dedicated consumer for this
        new DebugLoggerConsumer(getLogger());
        ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
        int status = deliverCmd.execute(deliverConsumer, errConsumer);
        if (status != 0) {
            return new CheckInScmResult(deliverCmd.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
        }
    }
    // Return what was added.
    return new CheckInScmResult(addResult.getCommandLine(), addResult.getAddedFiles());
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) JazzAddCommand(org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 14 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class CheckInCommandTckTest method testCheckInCommandPartialFileset.

public void testCheckInCommandPartialFileset() throws Exception {
    // Make sure that the correct files was checked out
    File fooJava = new File(getWorkingCopy(), "src/main/java/Foo.java");
    File barJava = new File(getWorkingCopy(), "src/main/java/Bar.java");
    File readmeTxt = new File(getWorkingCopy(), "readme.txt");
    assertFalse("check Foo.java doesn't yet exist", fooJava.canRead());
    assertFalse("check Bar.java doesn't yet exist", barJava.canRead());
    assertTrue("check can read readme.txt", readmeTxt.canRead());
    // Change the files
    createFooJava(fooJava);
    createBarJava(barJava);
    changeReadmeTxt(readmeTxt);
    AddScmResult addResult = getScmManager().getProviderByUrl(getScmUrl()).add(getScmRepository(), new ScmFileSet(getWorkingCopy(), "src/main/java/Foo.java", null));
    assertResultIsSuccess(addResult);
    CheckInScmResult result = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy(), "**/Foo.java", null), "Commit message");
    assertResultIsSuccess(result);
    List<ScmFile> files = result.getCheckedInFiles();
    assertNotNull(files);
    assertEquals(1, files.size());
    ScmFile file1 = files.get(0);
    assertEquals(ScmFileStatus.CHECKED_IN, file1.getStatus());
    assertPath("/test-repo/check-in/Foo.java", file1.getPath());
    CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
    assertResultIsSuccess(checkoutResult);
    fooJava = new File(getAssertionCopy(), "src/main/java/Foo.java");
    barJava = new File(getAssertionCopy(), "src/main/java/Bar.java");
    readmeTxt = new File(getAssertionCopy(), "readme.txt");
    assertTrue("check can read Foo.java", fooJava.canRead());
    assertFalse("check Bar.java doesn't exist", barJava.canRead());
    assertTrue("check can read readme.txt", readmeTxt.canRead());
    assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 15 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class GitAddCommand method executeAddFileSet.

private AddScmResult executeAddFileSet(ScmFileSet fileSet) throws ScmException {
    File workingDirectory = fileSet.getBasedir();
    List<File> files = fileSet.getFileList();
    // command line can be too long for windows so add files individually (see SCM-697)
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        for (File file : files) {
            AddScmResult result = executeAddFiles(workingDirectory, Collections.singletonList(file));
            if (result != null) {
                return result;
            }
        }
    } else {
        AddScmResult result = executeAddFiles(workingDirectory, files);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Aggregations

AddScmResult (org.apache.maven.scm.command.add.AddScmResult)39 File (java.io.File)18 ScmFile (org.apache.maven.scm.ScmFile)12 ScmFileSet (org.apache.maven.scm.ScmFileSet)9 ScmException (org.apache.maven.scm.ScmException)8 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 ArrayList (java.util.ArrayList)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 Commandline (org.codehaus.plexus.util.cli.Commandline)6 CommandParameters (org.apache.maven.scm.CommandParameters)4 ScmRepository (org.apache.maven.scm.repository.ScmRepository)4 ScmResult (org.apache.maven.scm.ScmResult)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)2 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)2