public ScmResult executeTagCommand()

in maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/tag/GitTagCommand.java [54:124]


    public ScmResult executeTagCommand(
            ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters)
            throws ScmException {
        if (tag == null || tag.trim().isEmpty()) {
            throw new ScmException("tag name must be specified");
        }

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

        GitScmProviderRepository repository = (GitScmProviderRepository) 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);
        }

        try {
            CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
            CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

            int exitCode;

            boolean sign = scmTagParameters.isSign();

            Commandline clTag = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile, sign);

            exitCode = GitCommandLineUtils.execute(clTag, stdout, stderr);
            if (exitCode != 0) {
                return new TagScmResult(clTag.toString(), "The git-tag command failed.", stderr.getOutput(), false);
            }

            if (repo.isPushChanges()) {
                // and now push the tag to the configured upstream repository
                Commandline clPush = createPushCommandLine(repository, fileSet, tag);

                exitCode = GitCommandLineUtils.execute(clPush, stdout, stderr);
                if (exitCode != 0) {
                    return new TagScmResult(
                            clPush.toString(), "The git-push command failed.", stderr.getOutput(), false);
                }
            }

            // plus search for the tagged files
            GitListConsumer listConsumer = new GitListConsumer(fileSet.getBasedir(), ScmFileStatus.TAGGED);

            Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());

            exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr);
            if (exitCode != 0) {
                return new CheckOutScmResult(
                        clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
            }

            return new TagScmResult(clTag.toString(), listConsumer.getListedFiles());
        } finally {
            try {
                FileUtils.forceDelete(messageFile);
            } catch (IOException ex) {
                // ignore
            }
        }
    }