Search in sources :

Example 1 with CategorisedElements

use of org.apache.maven.scm.provider.accurev.CategorisedElements in project maven-scm by apache.

the class AccuRevStatusCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    File basedir = fileSet.getBasedir();
    List<File> elements = fileSet.getFileList();
    List<File> defunctElements = accuRev.stat(basedir, elements, AccuRevStat.DEFUNCT);
    if (defunctElements == null) {
        return error(accuRev, "Failed retrieving defunct elements");
    }
    List<File> keptElements = accuRev.stat(basedir, elements, AccuRevStat.KEPT);
    // Defunct elements are also listed as kept (AccuRev 4.7.1), exclude those here.
    if (keptElements == null) {
        return error(accuRev, "Failed retrieving kept elements");
    }
    List<File> modOrAddedElements = new ArrayList<File>();
    for (File file : keptElements) {
        if (!defunctElements.contains(file)) {
            modOrAddedElements.add(file);
        }
    }
    List<File> modifiedElements = accuRev.stat(basedir, elements, AccuRevStat.MODIFIED);
    if (modifiedElements == null) {
        return error(accuRev, "Failed retrieving modified elements");
    }
    modOrAddedElements.addAll(modifiedElements);
    CategorisedElements catElems = accuRev.statBackingStream(basedir, modOrAddedElements);
    if (catElems == null) {
        return error(accuRev, "Failed stat backing stream to split modified and added elements");
    }
    modifiedElements = catElems.getMemberElements();
    List<File> addedElements;
    if (AccuRevCapability.STAT_ADDED_NOT_PROMOTED_BUG.isSupported(accuRev.getClientVersion())) {
        modOrAddedElements.removeAll(modifiedElements);
        addedElements = modOrAddedElements;
    } else {
        addedElements = catElems.getNonMemberElements();
    }
    List<File> missingElements = accuRev.stat(basedir, elements, AccuRevStat.MISSING);
    if (missingElements == null) {
        return error(accuRev, "Failed retrieving missing elements");
    }
    List<File> externalElements = accuRev.stat(basedir, elements, AccuRevStat.EXTERNAL);
    if (externalElements == null) {
        return error(accuRev, "Failed retrieving external elements");
    }
    List<ScmFile> resultFiles = getScmFiles(defunctElements, ScmFileStatus.DELETED);
    resultFiles.addAll(getScmFiles(modifiedElements, ScmFileStatus.MODIFIED));
    resultFiles.addAll(getScmFiles(addedElements, ScmFileStatus.ADDED));
    resultFiles.addAll(getScmFiles(missingElements, ScmFileStatus.MISSING));
    resultFiles.addAll(getScmFiles(externalElements, ScmFileStatus.UNKNOWN));
    return new StatusScmResult(accuRev.getCommandLines(), resultFiles);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) ArrayList(java.util.ArrayList) CategorisedElements(org.apache.maven.scm.provider.accurev.CategorisedElements) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with CategorisedElements

use of org.apache.maven.scm.provider.accurev.CategorisedElements in project maven-scm by apache.

the class AccuRevCommandLine method statBackingStream.

public CategorisedElements statBackingStream(File basedir, Collection<File> elements) throws AccuRevException {
    CategorisedElements catElems = new CategorisedElements();
    if (elements.isEmpty()) {
        return catElems;
    }
    String[] args = { "stat", "-b", "-ffr" };
    boolean ret = executeCommandLine(basedir, args, elements, new StatBackingConsumer(catElems.getMemberElements(), catElems.getNonMemberElements()));
    return ret ? catElems : null;
}
Also used : CategorisedElements(org.apache.maven.scm.provider.accurev.CategorisedElements)

Example 3 with CategorisedElements

use of org.apache.maven.scm.provider.accurev.CategorisedElements in project maven-scm by apache.

the class AccuRevStatusCommandTest method testStatus.

@Test
public void testStatus() throws Exception {
    final ScmFileSet testFileSet = getScmFileSet();
    File keptFile = new File("kept/file");
    File keptAdded = new File("kept/added");
    // this is the special one, it is returned by both the kept and defunct stat calls, so the command
    // needs to filter it out.
    File keptDefunct = new File("kept/defunct");
    File modifiedFile = new File("modified/file");
    File modifiedAdded = new File("modified/added");
    File missingFile = new File("missing/file");
    File externalFile = new File("external/file");
    when(accurev.stat(eq(basedir), anyListOf(File.class), eq(AccuRevStat.DEFUNCT))).thenReturn(Arrays.asList(keptDefunct));
    when(accurev.stat(eq(basedir), anyListOf(File.class), eq(AccuRevStat.MODIFIED))).thenReturn(Arrays.asList(modifiedFile, modifiedAdded));
    when(accurev.stat(eq(basedir), anyListOf(File.class), eq(AccuRevStat.KEPT))).thenReturn(Arrays.asList(keptDefunct, keptFile, keptAdded));
    when(accurev.stat(eq(basedir), anyListOf(File.class), eq(AccuRevStat.MISSING))).thenReturn(Arrays.asList(missingFile));
    when(accurev.stat(eq(basedir), anyListOf(File.class), eq(AccuRevStat.EXTERNAL))).thenReturn(Arrays.asList(externalFile));
    CategorisedElements catElems = new CategorisedElements();
    catElems.getMemberElements().addAll(Arrays.asList(modifiedFile, keptFile));
    catElems.getNonMemberElements().addAll(Arrays.asList(modifiedAdded, keptAdded));
    when(accurev.statBackingStream(eq(basedir), (Collection<File>) argThat(hasItems(modifiedFile, modifiedAdded, keptFile, keptAdded)))).thenReturn(catElems);
    AccuRevStatusCommand command = new AccuRevStatusCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    StatusScmResult result = command.status(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.getChangedFiles().size(), is(7));
    assertThat((List<ScmFile>) result.getChangedFiles(), not(Matchers.<ScmFile>hasItem(scmFile("kept/defunct", ScmFileStatus.MODIFIED))));
    assertHasScmFile(result.getChangedFiles(), "kept/file", ScmFileStatus.MODIFIED);
    assertHasScmFile(result.getChangedFiles(), "kept/added", ScmFileStatus.ADDED);
    assertHasScmFile(result.getChangedFiles(), "kept/defunct", ScmFileStatus.DELETED);
    assertHasScmFile(result.getChangedFiles(), "modified/file", ScmFileStatus.MODIFIED);
    assertHasScmFile(result.getChangedFiles(), "modified/added", ScmFileStatus.ADDED);
    assertHasScmFile(result.getChangedFiles(), "missing/file", ScmFileStatus.MISSING);
    assertHasScmFile(result.getChangedFiles(), "external/file", ScmFileStatus.UNKNOWN);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmFileSet(org.apache.maven.scm.ScmFileSet) CategorisedElements(org.apache.maven.scm.provider.accurev.CategorisedElements) CommandParameters(org.apache.maven.scm.CommandParameters) ScmFile(org.apache.maven.scm.ScmFile) ScmFileMatcher.scmFile(org.apache.maven.scm.ScmFileMatcher.scmFile) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile) ScmFileMatcher.assertHasScmFile(org.apache.maven.scm.ScmFileMatcher.assertHasScmFile) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Aggregations

CategorisedElements (org.apache.maven.scm.provider.accurev.CategorisedElements)3 File (java.io.File)2 ScmFile (org.apache.maven.scm.ScmFile)2 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)2 ArrayList (java.util.ArrayList)1 CommandParameters (org.apache.maven.scm.CommandParameters)1 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)1 ScmFileMatcher.scmFile (org.apache.maven.scm.ScmFileMatcher.scmFile)1 ScmFileSet (org.apache.maven.scm.ScmFileSet)1 AccuRev (org.apache.maven.scm.provider.accurev.AccuRev)1 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)1 Test (org.junit.Test)1