<commit_before>(ns leiningen.pom
  "Write a pom.xml file to disk for Maven interop."
  (:require [lancet])
  (:use [clojure.contrib.duck-streams :only [writer]]
        [clojure.contrib.java-utils :only [file]])
  (:import [org.apache.maven.model Model Parent Dependency Repository]
           [org.apache.maven.project MavenProject]
           [org.apache.maven.artifact.ant Pom]))

(def #^{:doc "A notice to place at the bottom of generated files."} disclaimer
     "\n<!-- This file was autogenerated by the Leiningen build tool.
  Please do not edit it directly; instead edit project.clj and regenerate it.
  It should not be considered canonical data. For more information see
  http://github.com/technomancy/leiningen -->\n")

(defn make-dependency [[dep version]]
  (doto (Dependency.)
    (.setGroupId (or (namespace dep) (name dep)))
    (.setArtifactId (name dep))
    (.setVersion version)))

(defn make-repository [[id url]]
  (doto (Repository.)
    (.setId id)
    (.setUrl url)))

(def default-repos {"central" "http://repo1.maven.org/maven2"
                    "clojure-snapshots" "http://build.clojure.org/snapshots"
                    "clojars" "http://clojars.org/repo/"})

(defn make-model [project]
  (let [model (doto (Model.)
                (.setModelVersion "4.0.0")
                (.setArtifactId (:name project))
                (.setName (:name project))
                (.setVersion (:version project))
                (.setGroupId (:group project))
                (.setDescription (:description project)))]<commit_msg>Populate the scm tag in the pom with git data if available.<commit_after>(ns leiningen.pom
  "Write a pom.xml file to disk for Maven interop."
  (:require [lancet])
  (:use [clojure.contrib.duck-streams :only [reader writer]]
        [clojure.contrib.java-utils :only [file]])
  (:import [org.apache.maven.model Model Parent Dependency Repository Scm]
           [org.apache.maven.project MavenProject]
           [org.apache.maven.artifact.ant Pom]))

(def #^{:doc "A notice to place at the bottom of generated files."} disclaimer
     "\n<!-- This file was autogenerated by the Leiningen build tool.
  Please do not edit it directly; instead edit project.clj and regenerate it.
  It should not be considered canonical data. For more information see
  http://github.com/technomancy/leiningen -->\n")

(defn read-git-ref
  "Reads the commit SHA1 for a git ref path."
  [git-dir ref-path]
  (.trim (slurp (str (file git-dir ref-path)))))

(defn read-git-head
  "Reads the value of HEAD and returns a commit SHA1."
  [git-dir]
  (let [head (.trim (slurp (str (file git-dir "HEAD"))))]
    (if-let [ref-path (second (re-find #"ref: (\S+)" head))]
      (read-git-ref git-dir ref-path)
      head)))

(defn read-git-origin
  "Reads the URL for the remote origin repository."
  [git-dir]
  (with-open [rdr (reader (file git-dir "config"))]
    (->> (map #(.trim %) (line-seq rdr))
         (drop-while #(not= "[remote \"origin\"]" %))
         (next)
         (take-while #(not (.startsWith % "[")))
         (map #(re-matches #"url\s*=\s*(\S*)\s*" %))
         (filter identity)
         (first)
         (second))))

(defn parse-github-url
  "Parses a GitHub URL returning a [username repo] pair."
  [url]
  (when url
    (next
     (or
      (re-matches #"(?:git@)?github.com:([^/]+)/([^/]+).git" url)
      (re-matches #"[^:]+://(?:git@)?github.com/([^/]+)/([^/]+).git" url)))))

(defn github-urls [url]
  (when-let [[user repo] (parse-github-url url)]
    {:public-clone (str "git://github.com/" user "/" repo ".git")
     :dev-clone (str "ssh://git@github.com/" user "/" repo ".git")
     :browse (str "http://github.com/" user "/" repo)}))

(defn make-git-scm [git-dir]
  (try
   (let [origin (read-git-origin git-dir)
         head (read-git-head git-dir)
         urls (github-urls origin)
         scm (Scm.)]
     (.setUrl scm (:browse urls))
     (.setTag scm head)
     (when (:public-clone urls)
       (.setConnection scm (str "scm:git:" (:public-clone urls))))
     (when (:dev-clone urls)
       (.setDeveloperConnection scm (str "scm:git:" (:dev-clone urls))))
     scm)
   (catch java.io.FileNotFoundException e
     nil)))

(defn make-dependency [[dep version]]
  (doto (Dependency.)
    (.setGroupId (or (namespace dep) (name dep)))
    (.setArtifactId (name dep))
    (.setVersion version)))

(defn make-repository [[id url]]
  (doto (Repository.)
    (.setId id)
    (.setUrl url)))

(def default-repos {"central" "http://repo1.maven.org/maven2"
                    "clojure-snapshots" "http://build.clojure.org/snapshots"
                    "clojars" "http://clojars.org/repo/"})

(defn make-model [project]
  (let [model (doto (Model.)
                (.setModelVersion "4.0.0")
                (.setArtifactId (:name project))
                (.setName (:name project))
                (.setVersion (:version project))
                (.setGroupId (:group project))
                (.setDescription (:description project))
                (.setScm (make-git-scm (file (:root project) ".git"))))]
{'fraction_non_alphanumeric': 0.16748865653975142, 'fraction_numerical': 0.0023673308344841193, 'mean_word_length': 2.600852272727273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5964729', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1645, 'n_words': 472}