use of org.apache.maven.scm.command.status.StatusScmResult 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);
}
use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.
the class VssStatusCommand method executeStatusCommand.
/**
* {@inheritDoc}
*/
protected StatusScmResult executeStatusCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("executing status command...");
}
VssScmProviderRepository repo = (VssScmProviderRepository) repository;
Commandline cl = buildCmdLine(repo, fileSet);
VssStatusConsumer consumer = new VssStatusConsumer(repo, getLogger(), fileSet);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
if (getLogger().isDebugEnabled()) {
getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
}
exitCode = VssCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
if (exitCode != 0) {
String error = stderr.getOutput();
if (getLogger().isDebugEnabled()) {
getLogger().debug("VSS returns error: [" + error + "] return code: [" + exitCode + "]");
}
return new StatusScmResult(cl.toString(), "The vss command failed.", error, false);
}
return new StatusScmResult(cl.toString(), consumer.getUpdatedFiles());
}
use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.
the class JazzAddCommand method executeAddCommand.
public AddScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
// NOTE: THIS IS ALSO CALLED DIRECTLY FROM THE CHECKIN COMMAND.
//
// The "checkin" command does not produce consumable output as to which individual files were checked in. (in
// 2.0.0.2 at least). Since only "locally modified" changes get checked in, we call a "status" command to
// generate a list of these files.
File baseDir = fileSet.getBasedir();
File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
List<ScmFile> changedScmFiles = new ArrayList<ScmFile>();
List<File> changedFiles = new ArrayList<File>();
List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
JazzStatusCommand statusCmd = new JazzStatusCommand();
statusCmd.setLogger(getLogger());
StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
for (ScmFile file : statusScmFiles) {
getLogger().debug("Iterating over statusScmFiles: " + file);
if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
changedScmFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
changedFiles.add(new File(parentFolder, file.getPath()));
}
}
List<File> files = fileSet.getFileList();
if (files.size() == 0) {
// Either commit all local changes
commitedFiles = changedScmFiles;
} else {
// Or commit specific files
for (File file : files) {
if (fileExistsInFileList(file, changedFiles)) {
commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
}
}
}
// Now that we have a list of files to process, we can "add" (scm checkin) them.
JazzAddConsumer addConsumer = new JazzAddConsumer(repo, getLogger());
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
JazzScmCommand command = createAddCommand(repo, fileSet);
int status = command.execute(addConsumer, errConsumer);
if (status != 0) {
return new AddScmResult(command.getCommandString(), "Error code for Jazz SCM add (checkin) command - " + status, errConsumer.getOutput(), false);
}
return new AddScmResult(command.getCommandString(), addConsumer.getFiles());
}
use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.
the class IntegrityStatusCommand method executeStatusCommand.
/**
* {@inheritDoc}
*/
@Override
public StatusScmResult executeStatusCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
StatusScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
getLogger().info("Status of files changed in sandbox " + fileSet.getBasedir().getAbsolutePath());
try {
// Initialize the list of ScmFile objects for the StatusScmResult
List<ScmFile> scmFileList = new ArrayList<ScmFile>();
// Get a listing for all the changes in the sandbox
Sandbox siSandbox = iRepo.getSandbox();
// Get the excludes and includes list from the configuration
String excludes = Sandbox.formatFilePatterns(fileSet.getExcludes());
String includes = Sandbox.formatFilePatterns(fileSet.getIncludes());
// Get the new members found in the sandbox
List<ScmFile> newMemberList = siSandbox.getNewMembers(excludes, includes);
// Update the scmFileList with our updates
scmFileList.addAll(newMemberList);
// Get the changed/dropped members from the sandbox
List<WorkItem> changeList = siSandbox.getChangeList();
for (Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); ) {
WorkItem wi = wit.next();
File memberFile = new File(wi.getField("name").getValueAsString());
// Separate the changes into files that have been updated and deleted files
if (siSandbox.hasWorkingFile((Item) wi.getField("wfdelta").getValue())) {
scmFileList.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.UPDATED));
} else {
scmFileList.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.DELETED));
}
}
if (scmFileList.size() == 0) {
getLogger().info("No local changes found!");
}
result = new StatusScmResult(scmFileList, new ScmResult("si viewsandbox", "", "", true));
} catch (APIException aex) {
ExceptionHandler eh = new ExceptionHandler(aex);
getLogger().error("MKS API Exception: " + eh.getMessage());
getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
result = new StatusScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.
the class JazzDiffCommand method executeDiffCommand.
/**
* {@inheritDoc}
*/
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Executing diff command...");
}
File baseDir = fileSet.getBasedir();
File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
// First execute the status command to get the list of changed files.
JazzStatusCommand statusCmd = new JazzStatusCommand();
statusCmd.setLogger(getLogger());
StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
// In this case, we also use it across multiple calls to "scm diff" so that we
// sum all output into on.
JazzScmCommand diffCmd = null;
StringBuilder patch = new StringBuilder();
Map<String, CharSequence> differences = new HashMap<String, CharSequence>();
// Now lets iterate through them
for (ScmFile file : statusScmFiles) {
if (file.getStatus() == ScmFileStatus.MODIFIED) {
// The "scm status" command returns files relative to the sandbox root.
// Whereas the "scm diff" command needs them relative to the working directory.
File fullPath = new File(parentFolder, file.getPath());
String relativePath = fullPath.toString().substring(baseDir.toString().length());
getLogger().debug("Full Path : '" + fullPath + "'");
getLogger().debug("Relative Path : '" + relativePath + "'");
// Now call "scm diff on it"
// In this case, we use the DebugLoggerConsumer's ability to store captured output
DebugLoggerConsumer diffConsumer = new DebugLoggerConsumer(getLogger());
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
diffCmd = createDiffCommand(repo, fileSet, relativePath);
int status = diffCmd.execute(diffConsumer, errConsumer);
if (status != 0) {
// Return a false result (not the usual SCMResult)
return new DiffScmResult(diffCmd.toString(), "The scm diff command failed.", errConsumer.getOutput(), false);
}
// Append to patch (all combined)
patch.append(diffConsumer.getOutput());
// Set the differences map <File, <CharSequence>
differences.put(relativePath, diffConsumer.getOutput());
}
}
return new DiffScmResult(diffCmd.toString(), statusCmdResult.getChangedFiles(), differences, patch.toString());
}
Aggregations