Search in sources :

Example 26 with AddScmResult

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

the class CvsExeAddCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected AddScmResult executeCvsCommand(Commandline cl, List<ScmFile> addedFiles) throws ScmException {
    CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    // TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses?
    if (exitCode != 0) {
        return new AddScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new AddScmResult(cl.toString(), addedFiles);
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 27 with AddScmResult

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

the class CheckInCommandTckTest method testCheckInCommandTest.

public void testCheckInCommandTest() 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().add(getScmRepository(), new ScmFileSet(getWorkingCopy(), "src/main/java/Foo.java", null));
    assertResultIsSuccess(addResult);
    CheckInScmResult result = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), "Commit message");
    assertResultIsSuccess(result);
    List<ScmFile> files = result.getCheckedInFiles();
    assertNotNull(files);
    assertEquals(2, files.size());
    Map<String, ScmFile> fileMap = mapFilesByPath(files);
    ScmFile file1 = fileMap.get("src/main/java/Foo.java");
    assertNotNull(file1);
    assertEquals(ScmFileStatus.CHECKED_IN, file1.getStatus());
    ScmFile file2 = fileMap.get("readme.txt");
    assertNotNull(file2);
    assertEquals(ScmFileStatus.CHECKED_IN, file2.getStatus());
    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", "changed file", 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 28 with AddScmResult

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

the class HgScmProvider method add.

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

Example 29 with AddScmResult

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

the class HgAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    // String[] addCmd = new String[] { ADD_CMD, NO_RECURSE_OPTION };
    String[] addCmd = new String[] { HgCommandConstants.ADD_CMD, HgCommandConstants.VERBOSE_OPTION };
    addCmd = HgUtils.expandCommandLine(addCmd, fileSet);
    File workingDir = fileSet.getBasedir();
    HgAddConsumer consumer = new HgAddConsumer(getLogger(), workingDir);
    ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir, addCmd);
    AddScmResult addScmResult = new AddScmResult(consumer.getAddedFiles(), result);
    // framework seems to think that this is the way we should behave.  it's pretty hacky. -rwd
    for (File workingFile : fileSet.getFileList()) {
        File file = new File(workingDir + "/" + workingFile.getPath());
        if (file.isDirectory() && file.listFiles().length == 0) {
            addScmResult.getAddedFiles().add(new ScmFile(workingFile.getPath(), ScmFileStatus.ADDED));
        }
    }
    return addScmResult;
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ScmResult(org.apache.maven.scm.ScmResult) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 30 with AddScmResult

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

the class IntegrityAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
@Override
public AddScmResult executeAddCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    getLogger().info("Attempting to add new files from directory " + fileSet.getBasedir().getAbsolutePath());
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    Sandbox siSandbox = iRepo.getSandbox();
    String excludes = Sandbox.formatFilePatterns(fileSet.getExcludes());
    String includes = Sandbox.formatFilePatterns(fileSet.getIncludes());
    String msg = ((null == message || message.length() == 0) ? System.getProperty("message") : message);
    List<ScmFile> addedFiles = siSandbox.addNonMembers(excludes, includes, msg);
    if (siSandbox.getOverallAddSuccess()) {
        return new AddScmResult("si add", addedFiles);
    } else {
        return new AddScmResult(addedFiles, new ScmResult("si add", "There was a problem adding files to the repository", "", false));
    }
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ScmResult(org.apache.maven.scm.ScmResult) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox) ScmFile(org.apache.maven.scm.ScmFile)

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