Search in sources :

Example 1 with BazaarScmProviderRepository

use of org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository in project maven-scm by apache.

the class BazaarCheckInCommand method executeCheckInCommand.

/**
 * {@inheritDoc}
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider can't handle tags.");
    }
    // Get files that will be committed (if not specified in fileSet)
    List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
    List<File> files = fileSet.getFileList();
    if (files.isEmpty()) {
        // Either commit all changes
        BazaarStatusCommand statusCmd = new BazaarStatusCommand();
        statusCmd.setLogger(getLogger());
        StatusScmResult status = statusCmd.executeStatusCommand(repo, fileSet);
        List<ScmFile> statusFiles = status.getChangedFiles();
        for (ScmFile file : statusFiles) {
            if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
                commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
            }
        }
    } else {
        // Or commit spesific files
        for (File file : files) {
            commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
        }
    }
    // Commit to local branch
    String[] commitCmd = new String[] { BazaarConstants.COMMIT_CMD, BazaarConstants.MESSAGE_OPTION, message };
    commitCmd = BazaarUtils.expandCommandLine(commitCmd, fileSet);
    ScmResult result = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), commitCmd);
    // Push to parent branch if any
    BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
    if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath()) && repo.isPushChanges()) {
        String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, BazaarConstants.NO_STRICT_OPTION, repository.getURI() };
        result = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
    }
    return new CheckInScmResult(commitedFiles, result);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ArrayList(java.util.ArrayList) BazaarStatusCommand(org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile) BazaarScmProviderRepository(org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 2 with BazaarScmProviderRepository

use of org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository in project maven-scm by apache.

the class BazaarTagCommand method executeTagCommand.

protected ScmResult executeTagCommand(ScmProviderRepository repository, ScmFileSet fileSet, String tagName, ScmTagParameters scmTagParameters) throws ScmException {
    if (tagName == null || StringUtils.isEmpty(tagName.trim())) {
        throw new ScmException("tag name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("tagging specific files is not allowed");
    }
    // Perform the tagging operation
    File bazaarRoot = fileSet.getBasedir();
    BazaarConsumer consumer = new BazaarConsumer(getLogger());
    String[] tagCmd = new String[] { BazaarConstants.TAG_CMD, tagName };
    ScmResult tagResult = BazaarUtils.execute(consumer, getLogger(), bazaarRoot, tagCmd);
    if (!tagResult.isSuccess()) {
        return new TagScmResult(null, tagResult);
    }
    // Do "bzr ls -R -r tag:tagName" to get a list of the tagged files
    BazaarLsConsumer lsConsumer = new BazaarLsConsumer(getLogger(), bazaarRoot, ScmFileStatus.TAGGED);
    String[] lsCmd = new String[] { BazaarConstants.LS_CMD, BazaarConstants.RECURSIVE_OPTION, BazaarConstants.REVISION_OPTION, "tag:" + tagName };
    ScmResult lsResult = BazaarUtils.execute(lsConsumer, getLogger(), bazaarRoot, lsCmd);
    if (!lsResult.isSuccess()) {
        return new TagScmResult(null, lsResult);
    }
    // Push new tags to parent branch if any
    BazaarScmProviderRepository bazaarRepository = (BazaarScmProviderRepository) repository;
    if (!bazaarRepository.getURI().equals(fileSet.getBasedir().getAbsolutePath()) && repository.isPushChanges()) {
        String[] pushCmd = new String[] { BazaarConstants.PUSH_CMD, bazaarRepository.getURI() };
        ScmResult pushResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
        if (!pushResult.isSuccess()) {
            return new TagScmResult(null, pushResult);
        }
    }
    return new TagScmResult(lsConsumer.getListedFiles(), tagResult);
}
Also used : ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) BazaarScmProviderRepository(org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) File(java.io.File)

Example 3 with BazaarScmProviderRepository

use of org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository in project maven-scm by apache.

the class BazaarCheckOutCommand method executeCheckOutCommand.

/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
    BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
    String url = repository.getURI();
    File checkoutDir = fileSet.getBasedir();
    try {
        if (getLogger().isInfoEnabled()) {
            getLogger().info("Removing " + checkoutDir);
        }
        FileUtils.deleteDirectory(checkoutDir);
    } catch (IOException e) {
        throw new ScmException("Cannot remove " + checkoutDir);
    }
    // Do the actual checkout
    List<String> checkoutCmd = new ArrayList<String>();
    checkoutCmd.add(BazaarConstants.BRANCH_CMD);
    checkoutCmd.add(url);
    checkoutCmd.add(checkoutDir.getAbsolutePath());
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        checkoutCmd.add(BazaarConstants.REVISION_OPTION);
        checkoutCmd.add("tag:" + version.getName());
    }
    BazaarConsumer checkoutConsumer = new BazaarConsumer(getLogger());
    BazaarUtils.execute(checkoutConsumer, getLogger(), checkoutDir.getParentFile(), (String[]) checkoutCmd.toArray(new String[0]));
    // Do inventory to find list of checkedout files
    String[] inventoryCmd = new String[] { BazaarConstants.INVENTORY_CMD };
    BazaarCheckOutConsumer consumer = new BazaarCheckOutConsumer(getLogger(), checkoutDir);
    ScmResult result = BazaarUtils.execute(consumer, getLogger(), checkoutDir, inventoryCmd);
    if (!result.isSuccess()) {
        throw new ScmException(result.getProviderMessage());
    }
    return new CheckOutScmResult(consumer.getCheckedOutFiles(), result);
}
Also used : ScmException(org.apache.maven.scm.ScmException) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmResult(org.apache.maven.scm.ScmResult) BazaarScmProviderRepository(org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository) ArrayList(java.util.ArrayList) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)3 ScmException (org.apache.maven.scm.ScmException)3 ScmResult (org.apache.maven.scm.ScmResult)3 BazaarConsumer (org.apache.maven.scm.provider.bazaar.command.BazaarConsumer)3 BazaarScmProviderRepository (org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 ScmFile (org.apache.maven.scm.ScmFile)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)1 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)1 TagScmResult (org.apache.maven.scm.command.tag.TagScmResult)1 BazaarStatusCommand (org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand)1