Search in sources :

Example 1 with AddScmResult

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

the class AccuRevAddCommandTest method testAdd.

@Test
public void testAdd() throws Exception {
    final ScmFileSet testFileSet = new ScmFileSet(basedir, new File("src/main/java/Foo.java"));
    final List<File> files = testFileSet.getFileList();
    when(accurev.add(basedir, files, "A new file")).thenReturn(Collections.singletonList(new File("added/file")));
    AccuRevAddCommand command = new AccuRevAddCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.MESSAGE, "A new file");
    AddScmResult result = command.add(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.getAddedFiles().size(), is(1));
    assertHasScmFile(result.getAddedFiles(), "added/file", ScmFileStatus.ADDED);
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 2 with AddScmResult

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

the class JGitCheckInCommandCommitterAuthorTckTest method createAndCommitFile.

private void createAndCommitFile(File file, String username) throws Exception, ScmException, IOException {
    createFooJava(file);
    ScmRepository scmRepository = getScmRepository();
    scmRepository.getProviderRepository().setUser(username);
    AddScmResult addResult = getScmManager().add(scmRepository, new ScmFileSet(getWorkingCopy(), "**/*.java"));
    assertResultIsSuccess(addResult);
    CheckInScmResult result = getScmManager().checkIn(scmRepository, new ScmFileSet(getWorkingCopy(), "**/Foo.java"), "Commit message");
    assertResultIsSuccess(result);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 3 with AddScmResult

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

the class SvnAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    // TODO: could do this with propset?
    if (binary) {
        throw new ScmException("This provider does not yet support binary files");
    }
    if (fileSet.getFileList().isEmpty()) {
        throw new ScmException("You must provide at least one file/directory to add");
    }
    Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
    SvnAddConsumer consumer = new SvnAddConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new AddScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new AddScmResult(cl.toString(), consumer.getAddedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 4 with AddScmResult

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

the class ScmTckTestCase method addToWorkingTree.

/**
 * Convenience method to add a file to the working tree at the working directory
 */
protected void addToWorkingTree(File workingDirectory, File file, ScmRepository repository) throws Exception {
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.FORCE_ADD, Boolean.TRUE.toString());
    AddScmResult result = provider.add(repository, new ScmFileSet(workingDirectory, file), commandParameters);
    assertTrue("Check result was successful, output: " + result.getCommandOutput(), result.isSuccess());
    List<ScmFile> addedFiles = result.getAddedFiles();
    if (new File(workingDirectory, file.getPath()).isFile()) {
        // Don't check directory add because some SCM tools ignore it
        assertEquals("Expected 1 file in the added files list " + addedFiles, 1, addedFiles.size());
    }
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) File(java.io.File)

Example 5 with AddScmResult

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

the class PerforceScmProvider method add.

public AddScmResult add(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    PerforceAddCommand command = new PerforceAddCommand();
    command.setLogger(getLogger());
    return (AddScmResult) command.execute(repository, fileSet, params);
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) PerforceAddCommand(org.apache.maven.scm.provider.perforce.command.add.PerforceAddCommand)

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