Search in sources :

Example 36 with ScmFile

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

the class CvsCheckoutCommandTest method assertCheckedOutFile.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
private File assertCheckedOutFile(List<ScmFile> files, int i, String fileName, ScmFileStatus status) throws Exception {
    File file = new File(getWorkingDirectory(), fileName);
    assertTrue(file.getAbsolutePath() + " file doesn't exist.", file.exists());
    ScmFile coFile = files.get(i);
    assertSame(status, coFile.getStatus());
    assertPath(fileName, coFile.getPath());
    return file;
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 37 with ScmFile

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

the class CvsCheckoutCommandTest method testCheckOutWithTag.

/**
 * @todo move this test to the TCK - checkout with "revision", then have one for tag as well.
 */
public void testCheckOutWithTag() 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();
    @SuppressWarnings("deprecation") CheckOutScmResult result = scmManager.getProviderByRepository(getScmRepository()).checkOut(getScmRepository(), getScmFileSet(), "MAVEN_1_0");
    if (!result.isSuccess()) {
        fail(result.getProviderMessage() + "\n" + result.getCommandOutput());
    }
    List<ScmFile> files = result.getCheckedOutFiles();
    assertNotNull(files);
    assertEquals(1, files.size());
    File mavenUtils = assertCheckedOutFile(files, 0, "/src/java/org/apache/maven/MavenUtils.java", ScmFileStatus.UPDATED);
    assertBetween(38403, 39511, mavenUtils.length());
}
Also used : ScmManager(org.apache.maven.scm.manager.ScmManager) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 38 with ScmFile

use of org.apache.maven.scm.ScmFile 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 39 with ScmFile

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

the class AccuRevScmProvider method update.

@Override
protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    AccuRevScmProviderRepository accurevRepo = (AccuRevScmProviderRepository) repository;
    AccuRevUpdateCommand command = new AccuRevUpdateCommand(getLogger());
    UpdateScmResult result = command.update(repository, fileSet, parameters);
    if (result.isSuccess() && parameters.getBoolean(CommandParameter.RUN_CHANGELOG_WITH_UPDATE)) {
        AccuRevUpdateScmResult accuRevResult = (AccuRevUpdateScmResult) result;
        ScmRevision fromRevision = new ScmRevision(accuRevResult.getFromRevision());
        ScmRevision toRevision = new ScmRevision(accuRevResult.getToRevision());
        parameters.setScmVersion(CommandParameter.START_SCM_VERSION, fromRevision);
        parameters.setScmVersion(CommandParameter.END_SCM_VERSION, toRevision);
        AccuRevVersion startVersion = accurevRepo.getAccuRevVersion(fromRevision);
        AccuRevVersion endVersion = accurevRepo.getAccuRevVersion(toRevision);
        if (startVersion.getBasisStream().equals(endVersion.getBasisStream())) {
            ChangeLogScmResult changeLogResult = changelog(repository, fileSet, parameters);
            if (changeLogResult.isSuccess()) {
                result.setChanges(changeLogResult.getChangeLog().getChangeSets());
            } else {
                getLogger().warn("Changelog from " + fromRevision + " to " + toRevision + " failed");
            }
        } else {
            String comment = "Cross stream update result from " + startVersion + " to " + endVersion;
            String author = "";
            List<ScmFile> files = result.getUpdatedFiles();
            List<ChangeFile> changeFiles = new ArrayList<ChangeFile>(files.size());
            for (ScmFile scmFile : files) {
                changeFiles.add(new ChangeFile(scmFile.getPath()));
            }
            ChangeSet dummyChangeSet = new ChangeSet(new Date(), comment, author, changeFiles);
            // different streams invalidates the change log, insert a dummy change instead.
            List<ChangeSet> changeSets = Collections.singletonList(dummyChangeSet);
            result.setChanges(changeSets);
        }
    }
    return result;
}
Also used : AccuRevUpdateScmResult(org.apache.maven.scm.provider.accurev.command.update.AccuRevUpdateScmResult) ScmRevision(org.apache.maven.scm.ScmRevision) AccuRevUpdateScmResult(org.apache.maven.scm.provider.accurev.command.update.AccuRevUpdateScmResult) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ArrayList(java.util.ArrayList) Date(java.util.Date) ScmFile(org.apache.maven.scm.ScmFile) AccuRevUpdateCommand(org.apache.maven.scm.provider.accurev.command.update.AccuRevUpdateCommand) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 40 with ScmFile

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

the class AbstractAccuRevExtractSourceCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    ScmVersion scmVersion = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
    File basedir = fileSet.getBasedir();
    String outputDirectory = parameters.getString(CommandParameter.OUTPUT_DIRECTORY, null);
    if (outputDirectory != null) {
        basedir = new File(outputDirectory);
    }
    if (!basedir.exists()) {
        basedir.mkdirs();
    }
    if (!basedir.isDirectory() || basedir.list().length != 0) {
        throw new ScmException("Checkout directory " + basedir.getAbsolutePath() + " not empty");
    }
    AccuRevVersion accuRevVersion = repository.getAccuRevVersion(scmVersion);
    List<File> checkedOutFiles = extractSource(repository, basedir, accuRevVersion);
    List<ScmFile> scmFiles = checkedOutFiles == null ? null : getScmFiles(checkedOutFiles, ScmFileStatus.CHECKED_OUT);
    return getScmResult(repository, scmFiles, scmVersion);
}
Also used : ScmException(org.apache.maven.scm.ScmException) AccuRevVersion(org.apache.maven.scm.provider.accurev.AccuRevVersion) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmVersion(org.apache.maven.scm.ScmVersion) ScmFile(org.apache.maven.scm.ScmFile)

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