public ScmResult executeTagCommand()

in maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/tag/SvnTagCommand.java [67:163]


    public ScmResult executeTagCommand(
            ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters)
            throws ScmException {
        // NPE free
        if (scmTagParameters == null) {
            logger.debug("SvnTagCommand :: scmTagParameters is null create an empty one");
            scmTagParameters = new ScmTagParameters();
            scmTagParameters.setRemoteTagging(false);
            scmTagParameters.setPinExternals(false);
        } else {
            logger.debug("SvnTagCommand :: scmTagParameters.remoteTagging : " + scmTagParameters.isRemoteTagging());
        }
        if (tag == null || StringUtils.isEmpty(tag.trim())) {
            throw new ScmException("tag must be specified");
        }

        if (!fileSet.getFileList().isEmpty()) {
            throw new ScmException("This provider doesn't support tagging subsets of a directory");
        }

        SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;

        File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);

        try {
            FileUtils.fileWrite(messageFile.getAbsolutePath(), "UTF-8", scmTagParameters.getMessage());
        } catch (IOException ex) {
            return new TagScmResult(
                    null,
                    "Error while making a temporary file for the commit message: " + ex.getMessage(),
                    null,
                    false);
        }

        Commandline cl = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile, scmTagParameters);

        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();

        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

        if (logger.isInfoEnabled()) {
            logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));

            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
            }
        }

        int exitCode;

        try {
            exitCode = SvnCommandLineUtils.execute(cl, stdout, stderr);
        } catch (CommandLineException ex) {
            throw new ScmException("Error while executing command.", ex);
        } finally {
            try {
                FileUtils.forceDelete(messageFile);
            } catch (IOException ex) {
                // ignore
            }
        }

        if (exitCode != 0) {
            // TODO: Improve this error message
            return new TagScmResult(cl.toString(), "The svn tag command failed.", stderr.getOutput(), false);
        }

        List<ScmFile> fileList = new ArrayList<>();

        List<File> files = null;

        try {
            if (StringUtils.isNotEmpty(fileSet.getExcludes())) {
                files = FileUtils.getFiles(
                        fileSet.getBasedir(),
                        (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()),
                        fileSet.getExcludes() + ",**/.svn/**",
                        false);
            } else {
                files = FileUtils.getFiles(
                        fileSet.getBasedir(),
                        (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()),
                        "**/.svn/**",
                        false);
            }
        } catch (IOException e) {
            throw new ScmException("Error while executing command.", e);
        }

        for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
            File f = i.next();

            fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
        }

        return new TagScmResult(cl.toString(), fileList);
    }