Search in sources :

Example 1 with BazaarConsumer

use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer 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 BazaarConsumer

use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer 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 BazaarConsumer

use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer 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)

Example 4 with BazaarConsumer

use of org.apache.maven.scm.provider.bazaar.command.BazaarConsumer in project maven-scm by apache.

the class BazaarUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider can't handle tags.");
    }
    File workingDir = fileSet.getBasedir();
    // Update branch
    String[] updateCmd = new String[] { BazaarConstants.PULL_CMD };
    ScmResult updateResult = BazaarUtils.execute(new BazaarConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = BazaarUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, "" + previousRevision };
    BazaarDiffConsumer diffConsumer = new BazaarDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = BazaarUtils.execute(diffConsumer, getLogger(), workingDir, diffCmd);
    // Now translate between diff and update file status
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    List<CharSequence> changes = new ArrayList<CharSequence>();
    List<ScmFile> diffFiles = diffConsumer.getChangedFiles();
    Map<String, CharSequence> diffChanges = diffConsumer.getDifferences();
    for (Iterator<ScmFile> it = diffFiles.iterator(); it.hasNext(); ) {
        ScmFile file = it.next();
        changes.add(diffChanges.get(file));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : ScmException(org.apache.maven.scm.ScmException) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) BazaarDiffConsumer(org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer) BazaarConsumer(org.apache.maven.scm.provider.bazaar.command.BazaarConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Aggregations

File (java.io.File)4 ScmException (org.apache.maven.scm.ScmException)4 ScmResult (org.apache.maven.scm.ScmResult)4 BazaarConsumer (org.apache.maven.scm.provider.bazaar.command.BazaarConsumer)4 ArrayList (java.util.ArrayList)3 BazaarScmProviderRepository (org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository)3 ScmFile (org.apache.maven.scm.ScmFile)2 IOException (java.io.IOException)1 ChangeSet (org.apache.maven.scm.ChangeSet)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 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)1 UpdateScmResultWithRevision (org.apache.maven.scm.command.update.UpdateScmResultWithRevision)1 BazaarDiffConsumer (org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffConsumer)1 BazaarStatusCommand (org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand)1