Search in sources :

Example 41 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class ClearCaseCheckOutCommand method executeCheckOutCommand.

// ----------------------------------------------------------------------
// AbstractCheckOutCommand Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing checkout command...");
    }
    ClearCaseScmProviderRepository repo = (ClearCaseScmProviderRepository) repository;
    File workingDirectory = fileSet.getBasedir();
    if (version != null && getLogger().isDebugEnabled()) {
        getLogger().debug(version.getType() + ": " + version.getName());
    }
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Running with CLEARCASE " + settings.getClearcaseType());
    }
    ClearCaseCheckOutConsumer consumer = new ClearCaseCheckOutConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    Commandline cl;
    String projectDirectory = "";
    try {
        // Since clearcase only wants to checkout to a non-existent directory, first delete the working dir
        // if it already exists
        FileUtils.deleteDirectory(workingDirectory);
        // First create the view
        String viewName = getUniqueViewName(repo, workingDirectory.getAbsolutePath());
        String streamIdentifier = getStreamIdentifier(repo.getStreamName(), repo.getVobName());
        cl = createCreateViewCommandLine(workingDirectory, viewName, streamIdentifier);
        if (getLogger().isInfoEnabled()) {
            getLogger().info("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
        }
        exitCode = CommandLineUtils.executeCommandLine(cl, new CommandLineUtils.StringStreamConsumer(), stderr);
        if (exitCode == 0) {
            File configSpecLocation;
            if (!repo.isAutoConfigSpec()) {
                configSpecLocation = repo.getConfigSpec();
                if (version != null && StringUtils.isNotEmpty(version.getName())) {
                    // 
                    throw new UnsupportedOperationException("Building on a label not supported with user-specified config specs");
                }
            } else {
                // write config spec to temp file
                String configSpec;
                if (!repo.hasElements()) {
                    configSpec = createConfigSpec(repo.getLoadDirectory(), version);
                } else {
                    configSpec = createConfigSpec(repo.getLoadDirectory(), repo.getElementName(), version);
                }
                if (getLogger().isInfoEnabled()) {
                    getLogger().info("Created config spec for view '" + viewName + "':\n" + configSpec);
                }
                configSpecLocation = writeTemporaryConfigSpecFile(configSpec, viewName);
                // When checking out from ClearCase, the directory structure of the
                // SCM system is repeated within the checkout directory. E.g. if you check out the
                // project "my/project" to "/some/dir", the project sources are actually checked out
                // to "my/project/some/dir".
                projectDirectory = repo.getLoadDirectory();
                // strip off leading / to make the path relative
                if (projectDirectory.startsWith("/")) {
                    projectDirectory = projectDirectory.substring(1);
                }
            }
            cl = createUpdateConfigSpecCommandLine(workingDirectory, configSpecLocation, viewName);
            if (getLogger().isInfoEnabled()) {
                getLogger().info("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
            }
            exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
        }
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing clearcase command.", ex);
    } catch (IOException ex) {
        throw new ScmException("Error while deleting working directory.", ex);
    }
    if (exitCode != 0) {
        return new CheckOutScmResult(cl.toString(), "The cleartool command failed.", stderr.getOutput(), false);
    }
    return new CheckOutScmResult(cl.toString(), consumer.getCheckedOutFiles(), projectDirectory);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) ClearCaseScmProviderRepository(org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository)

Example 42 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class IntegrityScmProvider method checkout.

/**
 * Maps to si createsandbox and/or si resync
 */
@Override
protected CheckOutScmResult checkout(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    IntegrityCheckOutCommand command = new IntegrityCheckOutCommand();
    command.setLogger(getLogger());
    return (CheckOutScmResult) command.execute(repository, fileSet, params);
}
Also used : IntegrityCheckOutCommand(org.apache.maven.scm.provider.integrity.command.checkout.IntegrityCheckOutCommand) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 43 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class CvsExeCheckOutCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsCheckOutConsumer consumer = new CvsCheckOutConsumer(getLogger());
    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);
    }
    if (exitCode != 0) {
        return new CheckOutScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new CheckOutScmResult(cl.toString(), consumer.getCheckedOutFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) CvsCheckOutConsumer(org.apache.maven.scm.provider.cvslib.command.checkout.CvsCheckOutConsumer) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 44 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class CvsCheckoutCommandTest method testCheckOutWithoutTag.

/**
 * @todo move this test to the TCK.
 */
public void testCheckOutWithoutTag() throws Exception {
    if (!isSystemCmd(CvsScmTestUtils.CVS_COMMAND_LINE)) {
        System.err.println("'" + CvsScmTestUtils.CVS_COMMAND_LINE + "' is not a system command. Ignored " + getName() + ".");
        return;
    }
    ScmManager scmManager = getScmManager();
    CheckOutScmResult result = scmManager.checkOut(getScmRepository(), getScmFileSet());
    if (!result.isSuccess()) {
        fail(result.getProviderMessage() + "\n" + result.getCommandOutput() + "\n" + result.getCommandLine());
    }
    List<ScmFile> files = result.getCheckedOutFiles();
    assertNotNull(files);
    assertEquals(3, files.size());
    assertCheckedOutFile(files, 0, "/Foo.java", ScmFileStatus.UPDATED);
    assertCheckedOutFile(files, 1, "/Readme.txt", ScmFileStatus.UPDATED);
    assertCheckedOutFile(files, 2, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED);
}
Also used : ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile)

Example 45 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class CvsJavaCheckOutCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsLogListener logListener = new CvsLogListener();
    CvsCheckOutConsumer consumer = new CvsCheckOutConsumer(getLogger());
    try {
        boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
        if (!isSuccess) {
            return new CheckOutScmResult(cl.toString(), "The cvs command failed.", logListener.getStderr().toString(), false);
        }
        BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
        String line;
        while ((line = stream.readLine()) != null) {
            consumer.consumeLine(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new CheckOutScmResult(cl.toString(), "The cvs command failed.", logListener.getStdout().toString(), false);
    }
    return new CheckOutScmResult(cl.toString(), consumer.getCheckedOutFiles());
}
Also used : CvsLogListener(org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) CvsCheckOutConsumer(org.apache.maven.scm.provider.cvslib.command.checkout.CvsCheckOutConsumer) BufferedReader(java.io.BufferedReader) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmException(org.apache.maven.scm.ScmException)

Aggregations

CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)57 File (java.io.File)24 ScmFileSet (org.apache.maven.scm.ScmFileSet)20 ScmFile (org.apache.maven.scm.ScmFile)14 ScmException (org.apache.maven.scm.ScmException)11 ScmTag (org.apache.maven.scm.ScmTag)9 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)9 Commandline (org.codehaus.plexus.util.cli.Commandline)8 Test (org.junit.Test)8 CommandParameters (org.apache.maven.scm.CommandParameters)7 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)7 IOException (java.io.IOException)6 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 ScmManager (org.apache.maven.scm.manager.ScmManager)5 ScmRepository (org.apache.maven.scm.repository.ScmRepository)5 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)5 ArrayList (java.util.ArrayList)4 ScmResult (org.apache.maven.scm.ScmResult)4 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)3