<commit_before>(println "ccw.leiningen.classpath-container before ns decl")

(ns ccw.leiningen.classpath-container
  (:use [clojure.core.incubator :only [-?> -?>>]])
  (:require [leiningen.core.project :as p]
            [leiningen.core.classpath :as cp]
            [cemerick.pomegranate.aether :as aether]
            [clojure.string :as str]
            [ccw.eclipse :as e]
            [ccw.jdt :as jdt]
            [clojure.java.io :as io]
            [ccw.leiningen.util :as u])
  (:import [org.eclipse.core.runtime CoreException
                                     IPath
                                     Path]
           [org.eclipse.jdt.core ClasspathContainerInitializer
                                 IClasspathContainer
                                 IClasspathEntry
                                 IJavaProject
                                 IClasspathEntry
                                 JavaCore]
           [org.eclipse.swt.widgets Composite]
           [org.eclipse.core.resources IResource
                                       IProject
                                       IMarker
                                       ResourcesPlugin]
           [org.sonatype.aether.resolution DependencyResolutionException]
           [ccw.util Logger
                     Logger$Severity]
           [java.io File
                    FilenameFilter]))

(println "ccw.leiningen.classpath-container load starts")

(def CONTAINER-PATH (Path. "ccw.LEININGEN_CONTAINER"))

(def CONTAINER-DESCRIPTION "Leiningen dependencies")

(def LEININGEN_CLASSPATH_CONTAINER_PROBLEM_MARKER_TYPE
  "ccw.leiningen.problemmarkers.classpathcontainer")

(def logger (Logger. (ccw.CCWPlugin/PLUGIN_ID)))

(defmacro with-exc-logged [& body]
  `(try ~@body
     (catch Exception e#
       (println (.getMessage e#))
       (.printStackTrace e#)
       nil)))

(defn plugin 
  "Return the plugin instance"
  []
  (ccw.CCWPlugin/getDefault))

(defn make-leiningen-classpath-container 
  "Create an instance of an IClasspathContainer given the arguments.
   classpath-entries: list of IClasspathEntry instances"
  [classpath-entries]
  (reify 
    IClasspathContainer
    (getClasspathEntries [this] 
       ; We explicitly create a new array everytime
       (into-array IClasspathEntry classpath-entries))
    (getDescription [this] CONTAINER-DESCRIPTION)
    (getKind [this] (IClasspathContainer/K_APPLICATION))
    (getPath [this] CONTAINER-PATH)))

(defn- library-entry
  "Wrapper for the ccw.leiningen.util/library-entry function"
  [{:keys [path native-path source-attachment-path]}]
  (let [params {:path path :source-attachment-path source-attachment-path}
        params (if native-path
                     (update-in params [:extra-attributes] 
                                assoc jdt/native-library (jdt/native-library-path native-path))
                     params)]
    (jdt/library-entry params)))

(defn leiningen-classpath-container
  "Given a project, grab its dependencies, and create an Eclipse Classpath Container
   for them. Lets any thrown exception pass through (e.g. Aether exception)"
  [project-dependencies]
  (let [entry-list (map library-entry project-dependencies)]
    (make-leiningen-classpath-container entry-list)))

;; copied from lein-ubersource
(defn- find-transitive-deps
  [deps repositories]
  (->> (aether/resolve-dependencies
        :coordinates deps
        :repositories repositories)
      keys
      set))

;; copied from lein-ubersource
(defn- resolve-artifact
  [dep repositories]
  (->> (find-transitive-deps [dep] repositories)
      (filter #(= % dep))
      first))

;; copied from lein-ubersource
(defn- try-resolve-sources-artifact!
  [dep repositories]
  (try
    (resolve-artifact (concat dep [:classifier "sources"]) repositories)
    (catch DependencyResolutionException ex
      nil)))

(defn- artifacts-entry
  [dep repositories]
  (let [main (resolve-artifact (take 2 dep) repositories)
        source (try-resolve-sources-artifact! dep repositories)]
    (if source [(-> main meta :file)
                (-> source meta :file)]
               nil)))

(defn get-source-map
  [{:keys [repositories dependencies] :as project} & args]
  (let [dep (find-transitive-deps dependencies repositories)]
    (into {} (keep #(artifacts-entry % repositories) dep))))

(defn resolve-dependencies
  "ADAPTED FROM LEININGEN-CORE resolve-dependencies.
  Simply delegate regular dependencies to pomegranate. This will
  ensure they are downloaded into ~/.m2/repositories and that native
  deps have been extracted to :native-path.  If :add-classpath? is
  logically true, will add the resolved dependencies to Leiningen's
  classpath.

   Returns a set of the dependencies' files."
  [project-name dependencies-key {:keys [repositories native-path] :as project} & rest]
  (let [deps-paths 
          ; We use eval-in-project or else we may not benefit from the right SSL
          ; certificates declared for the project
          (u/eval-in-project
            project-name<commit_msg>doc(classpath-container): explanation of (take 2 dep)<commit_after>(println "ccw.leiningen.classpath-container before ns decl")

(ns ccw.leiningen.classpath-container
  (:use [clojure.core.incubator :only [-?> -?>>]])
  (:require [leiningen.core.project :as p]
            [leiningen.core.classpath :as cp]
            [cemerick.pomegranate.aether :as aether]
            [clojure.string :as str]
            [ccw.eclipse :as e]
            [ccw.jdt :as jdt]
            [clojure.java.io :as io]
            [ccw.leiningen.util :as u])
  (:import [org.eclipse.core.runtime CoreException
                                     IPath
                                     Path]
           [org.eclipse.jdt.core ClasspathContainerInitializer
                                 IClasspathContainer
                                 IClasspathEntry
                                 IJavaProject
                                 IClasspathEntry
                                 JavaCore]
           [org.eclipse.swt.widgets Composite]
           [org.eclipse.core.resources IResource
                                       IProject
                                       IMarker
                                       ResourcesPlugin]
           [org.sonatype.aether.resolution DependencyResolutionException]
           [ccw.util Logger
                     Logger$Severity]
           [java.io File
                    FilenameFilter]))

(println "ccw.leiningen.classpath-container load starts")

(def CONTAINER-PATH (Path. "ccw.LEININGEN_CONTAINER"))

(def CONTAINER-DESCRIPTION "Leiningen dependencies")

(def LEININGEN_CLASSPATH_CONTAINER_PROBLEM_MARKER_TYPE
  "ccw.leiningen.problemmarkers.classpathcontainer")

(def logger (Logger. (ccw.CCWPlugin/PLUGIN_ID)))

(defmacro with-exc-logged [& body]
  `(try ~@body
     (catch Exception e#
       (println (.getMessage e#))
       (.printStackTrace e#)
       nil)))

(defn plugin 
  "Return the plugin instance"
  []
  (ccw.CCWPlugin/getDefault))

(defn make-leiningen-classpath-container 
  "Create an instance of an IClasspathContainer given the arguments.
   classpath-entries: list of IClasspathEntry instances"
  [classpath-entries]
  (reify 
    IClasspathContainer
    (getClasspathEntries [this] 
       ; We explicitly create a new array everytime
       (into-array IClasspathEntry classpath-entries))
    (getDescription [this] CONTAINER-DESCRIPTION)
    (getKind [this] (IClasspathContainer/K_APPLICATION))
    (getPath [this] CONTAINER-PATH)))

(defn- library-entry
  "Wrapper for the ccw.leiningen.util/library-entry function"
  [{:keys [path native-path source-attachment-path]}]
  (let [params {:path path :source-attachment-path source-attachment-path}
        params (if native-path
                     (update-in params [:extra-attributes] 
                                assoc jdt/native-library (jdt/native-library-path native-path))
                     params)]
    (jdt/library-entry params)))

(defn leiningen-classpath-container
  "Given a project, grab its dependencies, and create an Eclipse Classpath Container
   for them. Lets any thrown exception pass through (e.g. Aether exception)"
  [project-dependencies]
  (let [entry-list (map library-entry project-dependencies)]
    (make-leiningen-classpath-container entry-list)))

;; copied from lein-ubersource
(defn- find-transitive-deps
  [deps repositories]
  (->> (aether/resolve-dependencies
        :coordinates deps
        :repositories repositories)
      keys
      set))

;; copied from lein-ubersource
(defn- resolve-artifact
  [dep repositories]
  (->> (find-transitive-deps [dep] repositories)
      (filter #(= % dep))
      first))

;; copied from lein-ubersource
(defn- try-resolve-sources-artifact!
  [dep repositories]
  (try
    (resolve-artifact (concat dep [:classifier "sources"]) repositories)
    (catch DependencyResolutionException ex
      nil)))

(defn- artifacts-entry
  [dep repositories]
  (let [main (resolve-artifact
               (take 2 dep) ; take only id and version, not optional exclusion sections
               repositories)
        source (try-resolve-sources-artifact! dep repositories)]
    (if source [(-> main meta :file)
                (-> source meta :file)]
               nil)))

(defn get-source-map
  [{:keys [repositories dependencies] :as project} & args]
  (let [dep (find-transitive-deps dependencies repositories)]
    (into {} (keep #(artifacts-entry % repositories) dep))))

(defn resolve-dependencies
  "ADAPTED FROM LEININGEN-CORE resolve-dependencies.
  Simply delegate regular dependencies to pomegranate. This will
  ensure they are downloaded into ~/.m2/repositories and that native
  deps have been extracted to :native-path.  If :add-classpath? is
  logically true, will add the resolved dependencies to Leiningen's
  classpath.

   Returns a set of the dependencies' files."
  [project-name dependencies-key {:keys [repositories native-path] :as project} & rest]
  (let [deps-paths 
          ; We use eval-in-project or else we may not benefit from the right SSL
          ; certificates declared for the project
          (u/eval-in-project
            project-name
{'fraction_non_alphanumeric': 0.09756576364350215, 'fraction_numerical': 0.0004907734589713388, 'mean_word_length': 2.3527476143468244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '9578', 'n_tokens_mistral': 3039, 'n_tokens_neox': 2882, 'n_words': 755}