Search in sources :

Example 1 with ScmException

use of org.apache.maven.scm.ScmException in project wagon-git by synergian.

the class GitBackend method run.

private synchronized boolean run(String command, String[] args) throws GitException {
    try {
        Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(workDir, command);
        if (args != null) {
            for (int i = 0; i < args.length; i++) cl.createArgument().setValue(args[i]);
        }
        StringBuffer sb = new StringBuffer();
        sb.append("git ").append(command);
        if (args != null) {
            for (int i = 0; i < args.length; i++) sb.append(" ").append(args[i]);
        }
        int exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, log);
        log.debug("RAN: " + sb.toString() + " / $? = " + exitCode);
        return exitCode == 0;
    } catch (ScmException e) {
        throw new GitException("Couldn't run command " + command + ": " + e.getMessage(), e);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 2 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class AbstractScmPublishMojo method checkinFiles.

/**
     * Check-in content from scm checkout.
     *
     * @throws MojoExecutionException
     */
protected void checkinFiles() throws MojoExecutionException {
    if (skipCheckin) {
        return;
    }
    ScmFileSet updatedFileSet = new ScmFileSet(checkoutDirectory);
    try {
        long start = System.currentTimeMillis();
        CheckInScmResult checkinResult = checkScmResult(scmProvider.checkIn(scmRepository, updatedFileSet, new ScmBranch(scmBranch), checkinComment), "check-in files to SCM");
        logInfo("Checked in %d file(s) to revision %s in %s", checkinResult.getCheckedInFiles().size(), checkinResult.getScmRevision(), DurationFormatUtils.formatPeriod(start, System.currentTimeMillis(), "H' h 'm' m 's' s'"));
    } catch (ScmException e) {
        throw new MojoExecutionException("Failed to perform SCM checkin", e);
    }
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 3 with ScmException

use of org.apache.maven.scm.ScmException 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)

Example 4 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class ChangeLogReport method getRevisionForTag.

/**
     * Resolves the given tag to the revision number.
     *
     * @param tag
     * @param repository
     * @param provider
     * @return
     * @throws ScmException
     */
private String getRevisionForTag(final String tag, final ScmRepository repository, final ScmProvider provider) throws ScmException {
    if (repository.getProvider().equals("svn")) {
        if (tag == null) {
            return "HEAD";
        }
        SvnInfoCommandExpanded infoCommand = new SvnInfoCommandExpanded();
        infoCommand.setLogger(new DefaultLog());
        InfoScmResult infoScmResult = infoCommand.executeInfoTagCommand((SvnScmProviderRepository) repository.getProviderRepository(), new ScmFileSet(basedir), tag, null, false, null);
        if (infoScmResult.getInfoItems().size() == 0) {
            throw new ScmException("There is no tag named '" + tag + "' in the Subversion repository.");
        }
        InfoItem infoItem = infoScmResult.getInfoItems().get(0);
        String revision = infoItem.getLastChangedRevision();
        getLog().info(String.format("Resolved tag '%s' to revision '%s'", tag, revision));
        return revision;
    }
    return tag;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) InfoItem(org.apache.maven.scm.command.info.InfoItem) ScmException(org.apache.maven.scm.ScmException) DefaultLog(org.apache.maven.scm.log.DefaultLog) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) SvnInfoCommandExpanded(org.apache.maven.scm.provider.svn.svnexe.command.info.SvnInfoCommandExpanded)

Example 5 with ScmException

use of org.apache.maven.scm.ScmException in project maven-plugins by apache.

the class ChangeLogReport method getScmRepository.

public ScmRepository getScmRepository() throws ScmException {
    ScmRepository repository;
    try {
        repository = manager.makeScmRepository(getConnection());
        ScmProviderRepository providerRepo = repository.getProviderRepository();
        if (!StringUtils.isEmpty(username)) {
            providerRepo.setUser(username);
        }
        if (!StringUtils.isEmpty(password)) {
            providerRepo.setPassword(password);
        }
        if (repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost) {
            ScmProviderRepositoryWithHost repo = (ScmProviderRepositoryWithHost) repository.getProviderRepository();
            loadInfosFromSettings(repo);
            if (!StringUtils.isEmpty(username)) {
                repo.setUser(username);
            }
            if (!StringUtils.isEmpty(password)) {
                repo.setPassword(password);
            }
            if (!StringUtils.isEmpty(privateKey)) {
                repo.setPrivateKey(privateKey);
            }
            if (!StringUtils.isEmpty(passphrase)) {
                repo.setPassphrase(passphrase);
            }
        }
        if (!StringUtils.isEmpty(tagBase) && repository.getProvider().equals("svn")) {
            SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository();
            svnRepo.setTagBase(tagBase);
        }
    } catch (Exception e) {
        throw new ScmException("Can't load the scm provider.", e);
    }
    return repository;
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) ScmProviderRepositoryWithHost(org.apache.maven.scm.provider.ScmProviderRepositoryWithHost) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ScmProviderRepository(org.apache.maven.scm.provider.ScmProviderRepository) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) ScmException(org.apache.maven.scm.ScmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MavenReportException(org.apache.maven.reporting.MavenReportException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

ScmException (org.apache.maven.scm.ScmException)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ScmFileSet (org.apache.maven.scm.ScmFileSet)7 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ScmBranch (org.apache.maven.scm.ScmBranch)3 MavenReportException (org.apache.maven.reporting.MavenReportException)2 CommandParameters (org.apache.maven.scm.CommandParameters)2 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 InfoScmResult (org.apache.maven.scm.command.info.InfoScmResult)2 AbstractSvnScmProvider (org.apache.maven.scm.provider.svn.AbstractSvnScmProvider)2 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)2 ScmRepository (org.apache.maven.scm.repository.ScmRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1