Search in sources :

Example 16 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class PerforceRemoveConsumerTest method testParse.

public void testParse() throws Exception {
    File testFile = getTestFile("src/test/resources/perforce/removelog.txt");
    PerforceRemoveConsumer consumer = new PerforceRemoveConsumer();
    FileInputStream fis = new FileInputStream(testFile);
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    String s = in.readLine();
    while (s != null) {
        consumer.consumeLine(s);
        s = in.readLine();
    }
    List<ScmFile> removes = consumer.getRemovals();
    assertEquals("Wrong number of entries returned", 2, removes.size());
    String entry = removes.get(0).getPath();
    assertTrue(entry.startsWith("//"));
    assertTrue(entry.endsWith("foo.xml"));
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ScmFile(org.apache.maven.scm.ScmFile)

Example 17 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class PerforceAddConsumerTest method testParse.

public void testParse() throws Exception {
    File testFile = getTestFile("src/test/resources/perforce/addlog.txt");
    PerforceAddConsumer consumer = new PerforceAddConsumer();
    FileInputStream fis = new FileInputStream(testFile);
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    String s = in.readLine();
    while (s != null) {
        consumer.consumeLine(s);
        s = in.readLine();
    }
    List<ScmFile> adds = consumer.getAdditions();
    assertEquals("Wrong number of entries returned", 3, adds.size());
    String entry = adds.get(0).getPath();
    assertTrue(entry.startsWith("//"));
    assertTrue(entry.endsWith("foo.xml"));
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ScmFile(org.apache.maven.scm.ScmFile)

Example 18 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class LocalUpdateCommand method update.

private List<ScmFile> update(File source, File baseDestination, List<File> files) throws ScmException, IOException {
    String sourcePath = source.getAbsolutePath();
    List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
    for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
        File repositoryFile = i.next();
        File repositoryDirectory = repositoryFile.getParentFile();
        // TODO: Add more excludes here
        if (repositoryDirectory != null && repositoryDirectory.getName().equals("CVS")) {
            continue;
        }
        String dest = repositoryFile.getAbsolutePath().substring(sourcePath.length() + 1);
        File destinationFile = new File(baseDestination, dest);
        String repositoryFileContents = FileUtils.fileRead(repositoryFile);
        if (destinationFile.exists()) {
            String destionationFileContents = FileUtils.fileRead(destinationFile);
            if (repositoryFileContents.equals(destionationFileContents)) {
                continue;
            }
        }
        File destinationDirectory = destinationFile.getParentFile();
        if (!destinationDirectory.exists() && !destinationDirectory.mkdirs()) {
            throw new ScmException("Could not create destination directory '" + destinationDirectory.getAbsolutePath() + "'.");
        }
        ScmFileStatus status;
        if (destinationFile.exists()) {
            status = ScmFileStatus.UPDATED;
        } else {
            status = ScmFileStatus.ADDED;
        }
        FileUtils.copyFileToDirectory(repositoryFile, destinationDirectory);
        int chop = baseDestination.getAbsolutePath().length();
        String fileName = "/" + destinationFile.getAbsolutePath().substring(chop + 1);
        updatedFiles.add(new ScmFile(fileName, status));
    }
    return updatedFiles;
}
Also used : ScmFileStatus(org.apache.maven.scm.ScmFileStatus) ScmException(org.apache.maven.scm.ScmException) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 19 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class HgUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion tag) throws ScmException {
    File workingDir = fileSet.getBasedir();
    String[] updateCmd;
    // Update branch
    if (repo.isPushChanges()) {
        updateCmd = new String[] { HgCommandConstants.PULL_CMD, HgCommandConstants.REVISION_OPTION, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip" };
    } else {
        updateCmd = new String[] { HgCommandConstants.UPDATE_CMD, tag != null && !StringUtils.isEmpty(tag.getName()) ? tag.getName() : "tip", HgCommandConstants.CLEAN_OPTION };
    }
    ScmResult updateResult = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, updateCmd);
    if (!updateResult.isSuccess()) {
        return new UpdateScmResult(null, null, updateResult);
    }
    // Find changes from last revision
    int currentRevision = HgUtils.getCurrentRevisionNumber(getLogger(), workingDir);
    int previousRevision = currentRevision - 1;
    String[] diffCmd = new String[] { HgCommandConstants.DIFF_CMD, HgCommandConstants.REVISION_OPTION, "" + previousRevision };
    HgDiffConsumer diffConsumer = new HgDiffConsumer(getLogger(), workingDir);
    ScmResult diffResult = HgUtils.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 (ScmFile file : diffFiles) {
        changes.add(diffChanges.get(file.getPath()));
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            updatedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.PATCHED));
        } else {
            updatedFiles.add(file);
        }
    }
    if (repo.isPushChanges()) {
        String[] hgUpdateCmd = new String[] { HgCommandConstants.UPDATE_CMD };
        HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, hgUpdateCmd);
    }
    return new UpdateScmResultWithRevision(updatedFiles, new ArrayList<ChangeSet>(0), String.valueOf(currentRevision), diffResult);
}
Also used : UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmResult(org.apache.maven.scm.ScmResult) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) HgDiffConsumer(org.apache.maven.scm.provider.hg.command.diff.HgDiffConsumer) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 20 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class HgBranchCommand method executeBranchCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeBranchCommand(ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters) throws ScmException {
    if (StringUtils.isBlank(branch)) {
        throw new ScmException("branch must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branchging subsets of a directory");
    }
    File workingDir = fileSet.getBasedir();
    // build the command
    String[] branchCmd = new String[] { HgCommandConstants.BRANCH_CMD, branch };
    // keep the command about in string form for reporting
    HgConsumer branchConsumer = new HgConsumer(getLogger()) {

        public void doConsume(ScmFileStatus status, String trimmedLine) {
        // noop
        }
    };
    ScmResult result = HgUtils.execute(branchConsumer, getLogger(), workingDir, branchCmd);
    HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
    if (!result.isSuccess()) {
        throw new ScmException("Error while executing command " + joinCmd(branchCmd));
    }
    // First commit.
    String[] commitCmd = new String[] { HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, scmBranchParameters.getMessage() };
    result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), workingDir, commitCmd);
    if (!result.isSuccess()) {
        throw new ScmException("Error while executing command " + joinCmd(commitCmd));
    }
    if (repository.isPushChanges()) {
        if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
            String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, HgCommandConstants.NEW_BRANCH_OPTION, repository.getURI() };
            result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
            if (!result.isSuccess()) {
                throw new ScmException("Error while executing command " + joinCmd(pushCmd));
            }
        }
    }
    // do an inventory to return the files branched (all of them)
    String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
    HgListConsumer listconsumer = new HgListConsumer(getLogger());
    result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
    if (!result.isSuccess()) {
        throw new ScmException("Error while executing command " + joinCmd(listCmd));
    }
    List<ScmFile> files = listconsumer.getFiles();
    List<ScmFile> fileList = new ArrayList<ScmFile>();
    for (ScmFile f : files) {
        fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
    }
    return new BranchScmResult(fileList, result);
}
Also used : ScmException(org.apache.maven.scm.ScmException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmResult(org.apache.maven.scm.ScmResult) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) ArrayList(java.util.ArrayList) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) ScmFile(org.apache.maven.scm.ScmFile) ScmFileStatus(org.apache.maven.scm.ScmFileStatus) HgListConsumer(org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) HgScmProviderRepository(org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository)

Aggregations

ScmFile (org.apache.maven.scm.ScmFile)198 File (java.io.File)102 ArrayList (java.util.ArrayList)51 ScmException (org.apache.maven.scm.ScmException)34 BufferedReader (java.io.BufferedReader)21 DefaultLog (org.apache.maven.scm.log.DefaultLog)20 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)19 ScmFileSet (org.apache.maven.scm.ScmFileSet)17 InputStreamReader (java.io.InputStreamReader)16 ScmResult (org.apache.maven.scm.ScmResult)15 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)15 IOException (java.io.IOException)14 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)13 Matcher (java.util.regex.Matcher)11 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)11 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)10 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)10 Commandline (org.codehaus.plexus.util.cli.Commandline)10 SynergyScmProviderRepository (org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository)9 FileInputStream (java.io.FileInputStream)8