Search in sources :

Example 16 with AddScmResult

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);
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) URI(java.net.URI) ScmFile(org.apache.maven.scm.ScmFile) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) GitStatusConsumer(org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 17 with AddScmResult

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);
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) StarteamAddCommand(org.apache.maven.scm.provider.starteam.command.add.StarteamAddCommand)

Example 18 with AddScmResult

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());
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) Commandline(org.codehaus.plexus.util.cli.Commandline) StarteamScmProviderRepository(org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository) StarteamCommandLineUtils(org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) File(java.io.File)

Example 19 with AddScmResult

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);
}
Also used : AddScmResult(org.apache.maven.scm.command.add.AddScmResult) SynergyAddCommand(org.apache.maven.scm.provider.synergy.command.add.SynergyAddCommand)

Example 20 with AddScmResult

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);
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeSet(java.util.TreeSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

AddScmResult (org.apache.maven.scm.command.add.AddScmResult)39 File (java.io.File)18 ScmFile (org.apache.maven.scm.ScmFile)12 ScmFileSet (org.apache.maven.scm.ScmFileSet)9 ScmException (org.apache.maven.scm.ScmException)8 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 ArrayList (java.util.ArrayList)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 Commandline (org.codehaus.plexus.util.cli.Commandline)6 CommandParameters (org.apache.maven.scm.CommandParameters)4 ScmRepository (org.apache.maven.scm.repository.ScmRepository)4 ScmResult (org.apache.maven.scm.ScmResult)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)2 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)2