use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class GitAddCommand method executeAddCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
GitScmProviderRepository repository = (GitScmProviderRepository) repo;
if (fileSet.getFileList().isEmpty()) {
throw new ScmException("You must provide at least one file/directory to add");
}
AddScmResult result = executeAddFileSet(fileSet);
if (result != null) {
return result;
}
// SCM-709: statusCommand uses repositoryRoot instead of workingDirectory, adjust it with relativeRepositoryPath
Commandline clRevparse = GitStatusCommand.createRevparseShowToplevelCommand(fileSet);
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
URI relativeRepositoryPath = null;
int exitCode;
exitCode = GitCommandLineUtils.execute(clRevparse, stdout, stderr, getLogger());
if (exitCode != 0) {
// git-status returns non-zero if nothing to do
if (getLogger().isInfoEnabled()) {
getLogger().info("Could not resolve toplevel");
}
} else {
relativeRepositoryPath = GitStatusConsumer.resolveURI(stdout.getOutput().trim(), fileSet.getBasedir().toURI());
}
// git-add doesn't show single files, but only summary :/
// so we must run git-status and consume the output
// borrow a few things from the git-status command
Commandline clStatus = GitStatusCommand.createCommandLine(repository, fileSet);
GitStatusConsumer statusConsumer = new GitStatusConsumer(getLogger(), fileSet.getBasedir(), relativeRepositoryPath);
stderr = new CommandLineUtils.StringStreamConsumer();
exitCode = GitCommandLineUtils.execute(clStatus, statusConsumer, stderr, getLogger());
if (exitCode != 0) {
// git-status returns non-zero if nothing to do
if (getLogger().isInfoEnabled()) {
getLogger().info("nothing added to commit but untracked files present (use \"git add\" to track)");
}
}
List<ScmFile> changedFiles = new ArrayList<ScmFile>();
// rewrite all detected files to now have status 'checked_in'
for (ScmFile scmfile : statusConsumer.getChangedFiles()) {
// if a specific fileSet is given, we have to check if the file is really tracked
for (File f : fileSet.getFileList()) {
if (FilenameUtils.separatorsToUnix(f.getPath()).equals(scmfile.getPath())) {
changedFiles.add(scmfile);
}
}
}
Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
return new AddScmResult(cl.toString(), changedFiles);
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class StarteamScmProvider method add.
/**
* {@inheritDoc}
*/
public AddScmResult add(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
fileSet = fixUpScmFileSetAbsoluteFilePath(fileSet);
StarteamAddCommand command = new StarteamAddCommand();
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 StarteamAddCommand method executeAddCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
// work around until maven-scm-api allow this
String issue = System.getProperty("maven.scm.issue");
if (getLogger().isInfoEnabled()) {
getLogger().info("Working directory: " + fileSet.getBasedir().getAbsolutePath());
}
StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
StarteamAddConsumer consumer = new StarteamAddConsumer(getLogger(), fileSet.getBasedir());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
for (File fileToBeAdded : fileSet.getFileList()) {
ScmFileSet scmFile = new ScmFileSet(fileSet.getBasedir(), fileToBeAdded);
Commandline cl = createCommandLine(repository, scmFile, issue);
int exitCode = StarteamCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
if (exitCode != 0) {
return new AddScmResult(cl.toString(), "The starteam command failed.", stderr.getOutput(), false);
}
}
return new AddScmResult(null, consumer.getAddedFiles());
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class SynergyScmProvider method add.
/**
* {@inheritDoc}
*/
public AddScmResult add(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
SynergyAddCommand command = new SynergyAddCommand();
command.setLogger(getLogger());
return (AddScmResult) command.execute(repository, fileSet, parameters);
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-plugins by apache.
the class AbstractScmPublishMojo method addFiles.
/**
* Add files to scm.
*
* @param added files to be added
* @throws MojoFailureException
* @throws MojoExecutionException
*/
protected void addFiles(Collection<File> added) throws MojoFailureException, MojoExecutionException {
List<File> addedList = new ArrayList<File>();
Set<File> createdDirs = new HashSet<File>();
Set<File> dirsToAdd = new TreeSet<File>();
createdDirs.add(relativize(checkoutDirectory, checkoutDirectory));
for (File f : added) {
for (File dir = f.getParentFile(); !dir.equals(checkoutDirectory); dir = dir.getParentFile()) {
File relativized = relativize(checkoutDirectory, dir);
// we do the best we can with the directories
if (createdDirs.add(relativized)) {
dirsToAdd.add(relativized);
} else {
break;
}
}
addedList.add(relativize(checkoutDirectory, f));
}
if (addUniqueDirectory) {
// add one directory at a time
for (File relativized : dirsToAdd) {
try {
ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, relativized);
getLog().info("scm add directory: " + relativized);
AddScmResult addDirResult = scmProvider.add(scmRepository, fileSet, "Adding directory");
if (!addDirResult.isSuccess()) {
getLog().warn(" Error adding directory " + relativized + ": " + addDirResult.getCommandOutput());
}
} catch (ScmException e) {
//
}
}
} else {
// add all directories in one command
try {
List<File> dirs = new ArrayList<File>(dirsToAdd);
ScmFileSet fileSet = new ScmFileSet(checkoutDirectory, dirs);
getLog().info("scm add directories: " + dirs);
AddScmResult addDirResult = scmProvider.add(scmRepository, fileSet, "Adding directories");
if (!addDirResult.isSuccess()) {
getLog().warn(" Error adding directories " + dirs + ": " + addDirResult.getCommandOutput());
}
} catch (ScmException e) {
//
}
}
// remove directories already added !
addedList.removeAll(dirsToAdd);
ScmFileSet addedFileSet = new ScmFileSet(checkoutDirectory, addedList);
getLog().info("scm add files: " + addedList);
try {
CommandParameters commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.MESSAGE, "Adding new site files.");
commandParameters.setString(CommandParameter.FORCE_ADD, Boolean.TRUE.toString());
checkScmResult(scmProvider.add(scmRepository, addedFileSet, commandParameters), "add new files to SCM");
} catch (ScmException e) {
throw new MojoExecutionException("Failed to add new files to SCM", e);
}
}
Aggregations