<commit_before>require "capistrano-maven/version"
require "capistrano"
require "capistrano/configuration/actions/file_transfer_ext"
require "capistrano/configuration/resources/file_resources"
require "uri"

module Capistrano
  module Maven
    def self.extended(configuration)
      configuration.load {
        namespace(:mvn) {
          _cset(:mvn_version, "3.0.5")
          _cset(:mvn_major_version) { mvn_version.split(".").first.to_i }
          _cset(:mvn_archive_url) {
            "http://www.apache.org/dist/maven/maven-#{mvn_major_version}/#{mvn_version}/binaries/apache-maven-#{mvn_version}-bin.tar.gz"
          }
          _cset(:mvn_tools_path) { File.join(shared_path, "tools", "mvn") }
          _cset(:mvn_tools_path_local) { File.expand_path("tools/mvn") }
          _cset(:mvn_archive_path) { mvn_tools_path }
          _cset(:mvn_archive_path_local) { mvn_tools_path_local }
          _cset(:mvn_archive_file) { File.join(mvn_archive_path, File.basename(URI.parse(mvn_archive_url).path)) }
          _cset(:mvn_archive_file_local) { File.join(mvn_archive_path_local, File.basename(URI.parse(mvn_archive_url).path)) }
          _cset(:mvn_path) { File.join(mvn_tools_path, File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz")) }
          _cset(:mvn_path_local) { File.join(mvn_tools_path_local, File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz")) }
          _cset(:mvn_bin) { File.join(mvn_path, "bin", "mvn") }
          _cset(:mvn_bin_local) { File.join(mvn_path_local, "bin", "mvn") }
          _cset(:mvn_cmd) {
            if fetch(:mvn_java_home, nil)
              "env JAVA_HOME=#{mvn_java_home} #{mvn_bin} #{mvn_options.join(' ')}"
            else
              "#{mvn_bin} #{mvn_options.join(' ')}"
            end
          }
          _cset(:mvn_cmd_local) {
            if fetch(:mvn_java_home_local, nil)
              "env JAVA_HOME=#{mvn_java_home_local} #{mvn_bin_local} #{mvn_options_local.join(' ')}"
            else
              "#{mvn_bin_local} #{mvn_options_local.join(' ')}"
            end
          }
          _cset(:mvn_project_path) { release_path }
          _cset(:mvn_project_path_local) { File.expand_path(".") }
          _cset(:mvn_template_path) { File.expand_path("config/templates") }
          _cset(:mvn_goals, %w(clean package))
          _cset(:mvn_common_options) {
            options = []
            options << "-P#{mvn_profiles.join(",")}" unless fetch(:mvn_profiles, []).empty?
            options << "-Dmaven.test.skip=true" if fetch(:mvn_skip_tests, false)
            options << "-U" if fetch(:mvn_update_snapshots, false)
            options << "-B"
            options
          }
          _cset(:mvn_default_options) {
            mvn_common_options + mvn_settings.map { |s| "--settings=#{File.join(mvn_settings_path, s).dump}" }
          }<commit_msg>add :mvn_environment to setup environment variables for Maven<commit_after>require "capistrano-maven/version"
require "capistrano"
require "capistrano/configuration/actions/file_transfer_ext"
require "capistrano/configuration/resources/file_resources"
require "uri"

module Capistrano
  module Maven
    def self.extended(configuration)
      configuration.load {
        namespace(:mvn) {
          _cset(:mvn_version, "3.0.5")
          _cset(:mvn_major_version) { mvn_version.split(".").first.to_i }
          _cset(:mvn_archive_url) {
            "http://www.apache.org/dist/maven/maven-#{mvn_major_version}/#{mvn_version}/binaries/apache-maven-#{mvn_version}-bin.tar.gz"
          }
          _cset(:mvn_tools_path) { File.join(shared_path, "tools", "mvn") }
          _cset(:mvn_tools_path_local) { File.expand_path("tools/mvn") }
          _cset(:mvn_archive_path) { mvn_tools_path }
          _cset(:mvn_archive_path_local) { mvn_tools_path_local }
          _cset(:mvn_archive_file) { File.join(mvn_archive_path, File.basename(URI.parse(mvn_archive_url).path)) }
          _cset(:mvn_archive_file_local) { File.join(mvn_archive_path_local, File.basename(URI.parse(mvn_archive_url).path)) }
          _cset(:mvn_path) { File.join(mvn_tools_path, File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz")) }
          _cset(:mvn_path_local) { File.join(mvn_tools_path_local, File.basename(URI.parse(mvn_archive_url).path, "-bin.tar.gz")) }
          _cset(:mvn_bin_path) { File.join(mvn_path, "bin") }
          _cset(:mvn_bin_path_local) { File.join(mvn_path_local, "bin") }
          _cset(:mvn_bin) { File.join(mvn_bin_path, "mvn") }
          _cset(:mvn_bin_local) { File.join(mvn_bin_path_local, "mvn") }
          _cset(:mvn_project_path) { release_path }
          _cset(:mvn_project_path_local) { File.expand_path(".") }
          _cset(:mvn_template_path) { File.expand_path("config/templates") }

          ## Maven environment
          _cset(:mvn_common_environment, {})
          _cset(:mvn_default_environment) {
            environment = mvn_common_environment.dup
            environment["JAVA_HOME"] = fetch(:mvn_java_home) if exists?(:mvn_java_home)
            environment["MAVEN_OPTS"] = fetch(:mvn_java_options) if exists?(:mvn_java_options)
            environment["PATH"] = [ mvn_bin_path, "$PATH" ].join(":") if mvn_setup_remotely
            environment
          }
          _cset(:mvn_default_environment_local) {
            environment = mvn_common_environment.dup
            environment["JAVA_HOME"] = fetch(:mvn_java_home_local) if exists?(:mvn_java_home_local)
            environment["MAVEN_OPTS"] = fetch(:mvn_java_options_local) if exists?(:mvn_java_options_local)
            environment["PATH"] = [ mvn_bin_path_local, "$PATH" ].join(":") if mvn_setup_locally
            environment
          }
          _cset(:mvn_environment) { mvn_default_environment.merge(fetch(:mvn_extra_environment, {})) }
          _cset(:mvn_environment_local) { mvn_default_environment_local.merge(fetch(:mvn_extra_environment_local, {})) }
          def _command(cmdline, options={})
            environment = options.fetch(:env, {})
            if environment.empty?
              cmdline
            else
              env = (["env"] + environment.map { |k, v| "#{k}=#{v.dump}" }).join(" ")
              "#{env} #{cmdline}"
            end
          end
          def command(cmdline, options={})
            _command(cmdline, :env => mvn_environment.merge(options.fetch(:env, {})))
          end
          def command_local(cmdline, options={})
            _command(cmdline, :env => mvn_environment_local.merge(options.fetch(:env, {})))
          end
          _cset(:mvn_cmd) { command("#{mvn_bin.dump} #{mvn_options.map { |x| x.dump }.join(" ")}") }
          _cset(:mvn_cmd_local) { command_local("#{mvn_bin_local.dump} #{mvn_options_local.map { |x| x.dump }.join(" ")}") }
          _cset(:mvn_goals, %w(clean package))
          _cset(:mvn_common_options) {
            options = []
            options << "-P#{mvn_profiles.join(",")}" unless fetch(:mvn_profiles, []).empty?
            options << "-Dmaven.test.skip=true" if fetch(:mvn_skip_tests, false)
            options << "-U" if fetch(:mvn_update_snapshots, false)
            options << "-B"
            options
          }
          _cset(:mvn_default_options) {
            mvn_common_options + mvn_settings.map { |s| "--settings=#{File.join(mvn_settings_path, s).dump}" }
          }
{'fraction_non_alphanumeric': 0.14338285402753168, 'fraction_numerical': 0.0008177729317159602, 'mean_word_length': 2.892838196286472, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6924135', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2530, 'n_words': 306}