use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class JazzScmProvider method add.
/**
* {@inheritDoc}
*/
public AddScmResult add(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
getLogger().debug("JazzScmProvider:add()");
JazzAddCommand command = new JazzAddCommand();
command.setLogger(getLogger());
return (AddScmResult) command.execute(repository, fileSet, parameters);
}
use of org.apache.maven.scm.command.add.AddScmResult 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.add.AddScmResult in project maven-scm by apache.
the class JazzCheckInCommand method executeCheckInCommand.
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
// Call the Add command to perform the checkin into the repository workspace.
JazzAddCommand addCommand = new JazzAddCommand();
addCommand.setLogger(getLogger());
AddScmResult addResult = addCommand.executeAddCommand(repo, fileSet);
// Now, if it has a flow target, deliver it.
JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
// Push if we need too
JazzScmCommand deliverCmd = createDeliverCommand((JazzScmProviderRepository) repo, fileSet);
StreamConsumer deliverConsumer = // No need for a dedicated consumer for this
new DebugLoggerConsumer(getLogger());
ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
int status = deliverCmd.execute(deliverConsumer, errConsumer);
if (status != 0) {
return new CheckInScmResult(deliverCmd.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
}
}
// Return what was added.
return new CheckInScmResult(addResult.getCommandLine(), addResult.getAddedFiles());
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class CheckInCommandTckTest method testCheckInCommandPartialFileset.
public void testCheckInCommandPartialFileset() throws Exception {
// Make sure that the correct files was checked out
File fooJava = new File(getWorkingCopy(), "src/main/java/Foo.java");
File barJava = new File(getWorkingCopy(), "src/main/java/Bar.java");
File readmeTxt = new File(getWorkingCopy(), "readme.txt");
assertFalse("check Foo.java doesn't yet exist", fooJava.canRead());
assertFalse("check Bar.java doesn't yet exist", barJava.canRead());
assertTrue("check can read readme.txt", readmeTxt.canRead());
// Change the files
createFooJava(fooJava);
createBarJava(barJava);
changeReadmeTxt(readmeTxt);
AddScmResult addResult = getScmManager().getProviderByUrl(getScmUrl()).add(getScmRepository(), new ScmFileSet(getWorkingCopy(), "src/main/java/Foo.java", null));
assertResultIsSuccess(addResult);
CheckInScmResult result = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy(), "**/Foo.java", null), "Commit message");
assertResultIsSuccess(result);
List<ScmFile> files = result.getCheckedInFiles();
assertNotNull(files);
assertEquals(1, files.size());
ScmFile file1 = files.get(0);
assertEquals(ScmFileStatus.CHECKED_IN, file1.getStatus());
assertPath("/test-repo/check-in/Foo.java", file1.getPath());
CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
assertResultIsSuccess(checkoutResult);
fooJava = new File(getAssertionCopy(), "src/main/java/Foo.java");
barJava = new File(getAssertionCopy(), "src/main/java/Bar.java");
readmeTxt = new File(getAssertionCopy(), "readme.txt");
assertTrue("check can read Foo.java", fooJava.canRead());
assertFalse("check Bar.java doesn't exist", barJava.canRead());
assertTrue("check can read readme.txt", readmeTxt.canRead());
assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class GitAddCommand method executeAddFileSet.
private AddScmResult executeAddFileSet(ScmFileSet fileSet) throws ScmException {
File workingDirectory = fileSet.getBasedir();
List<File> files = fileSet.getFileList();
// command line can be too long for windows so add files individually (see SCM-697)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
for (File file : files) {
AddScmResult result = executeAddFiles(workingDirectory, Collections.singletonList(file));
if (result != null) {
return result;
}
}
} else {
AddScmResult result = executeAddFiles(workingDirectory, files);
if (result != null) {
return result;
}
}
return null;
}
Aggregations