|
16 | 16 | [clojure.tools.deps.util.session :as session]) |
17 | 17 | (:import |
18 | 18 | [java.io File] |
19 | | - [java.util Properties] |
| 19 | + [java.util List Properties] |
20 | 20 | ;; maven-model |
21 | | - [org.apache.maven.model Model Dependency Exclusion] |
| 21 | + [org.apache.maven.model Model Dependency Exclusion Plugin PluginExecution] |
22 | 22 | ;; maven-model-builder |
23 | 23 | [org.apache.maven.model.building DefaultModelBuildingRequest DefaultModelBuilderFactory ModelSource FileModelSource] |
24 | 24 | [org.apache.maven.model.resolution ModelResolver] |
|
28 | 28 | [org.apache.maven.model Resource License] |
29 | 29 | ;; maven-core |
30 | 30 | [org.apache.maven.project ProjectModelResolver ProjectBuildingRequest$RepositoryMerging] |
| 31 | + ;; plexus-utils |
| 32 | + [org.codehaus.plexus.util.xml Xpp3Dom] |
31 | 33 | )) |
32 | 34 |
|
33 | 35 | (set! *warn-on-reflection* true) |
|
99 | 101 | model (read-model-file pom config)] |
100 | 102 | (model-deps model))) |
101 | 103 |
|
| 104 | +;; Leiningen (and others) use this plugin to attach additional source dirs when the lifecycle |
| 105 | +;; executes. To avoid executing (which has security and runtime issues), this function |
| 106 | +;; statically extracts those attached dirs from something like this: |
| 107 | +;; |
| 108 | +;; <plugin> |
| 109 | +;; <groupId>org.codehaus.mojo</groupId> |
| 110 | +;; <artifactId>build-helper-maven-plugin</artifactId> |
| 111 | +;; <version>1.7</version> |
| 112 | +;; <executions> |
| 113 | +;; <execution> |
| 114 | +;; <id>add-source</id> |
| 115 | +;; <phase>generate-sources</phase> |
| 116 | +;; <goals> |
| 117 | +;; <goal>add-source</goal> |
| 118 | +;; </goals> |
| 119 | +;; <configuration> |
| 120 | +;; <sources> |
| 121 | +;; <source>extra</source> <!-- deps.edn can't see this otherwise --> |
| 122 | +;; </sources> |
| 123 | +;; </configuration> |
| 124 | +;; </execution> |
| 125 | +;; </executions> |
| 126 | +;; </plugin> |
| 127 | +;; In addition, this code also includes add-resource goals including resources |
| 128 | +(defn- get-build-helper-paths |
| 129 | + [^Model model] |
| 130 | + (let [plugins (some-> model .getBuild .getPlugins) |
| 131 | + build-helper-plugins (filter (fn [^Plugin plugin] |
| 132 | + (and (= "org.codehaus.mojo" (.getGroupId plugin)) |
| 133 | + (= "build-helper-maven-plugin" (.getArtifactId plugin)))) |
| 134 | + plugins)] |
| 135 | + (when (not (empty? build-helper-plugins)) |
| 136 | + (let [^Plugin plugin (first plugins) |
| 137 | + extract-dirs (fn [^Plugin plugin goal ^String children] |
| 138 | + (->> (.getExecutions plugin) |
| 139 | + (filter (fn [^PluginExecution exec] (.contains ^List (.getGoals exec) goal))) |
| 140 | + (mapcat (fn [^PluginExecution exec] |
| 141 | + (let [^Xpp3Dom config (.getConfiguration exec) |
| 142 | + ^Xpp3Dom sources (.getChild config children)] |
| 143 | + (map #(.getValue ^Xpp3Dom %) (.getChildren sources)))))))] |
| 144 | + (concat |
| 145 | + (extract-dirs plugin "add-source" "sources") |
| 146 | + (extract-dirs plugin "add-resource" "resources")))))) |
| 147 | + |
102 | 148 | (defmethod ext/coord-paths :pom |
103 | 149 | [lib {:keys [deps/root] :as _coord} _mf config] |
104 | | - (let [pom (jio/file root "pom.xml") |
| 150 | + (let [relativize (fn [^String s] |
| 151 | + (let [f (jio/file s)] |
| 152 | + (if (.isAbsolute f) |
| 153 | + (.getCanonicalPath f) |
| 154 | + (.getCanonicalPath (jio/file root f))))) |
| 155 | + pom (jio/file root "pom.xml") |
105 | 156 | model (read-model-file pom config) |
106 | 157 |
|
107 | 158 | ;; Maven core 3.8.2 returns an absolute directory here, which is a breaking regression |
108 | 159 | ;; from previous versions (see https://issues.apache.org/jira/browse/MNG-7218). |
109 | 160 | ;; Working around this with conditional code that deals with either absolute or relative. |
110 | | - ;; When MNG-7218 is fixed and deps bumped, might be able to revert the absolute path here. |
| 161 | + ;; When MNG-7218 is fixed and deps bumped, might be able to revert the absolute path |
| 162 | + ;; handling in relativize |
111 | 163 | src-dir (jio/file (.. model getBuild getSourceDirectory)) |
112 | | - src-path (if (.isAbsolute src-dir) |
113 | | - (.getCanonicalPath src-dir) |
114 | | - (.getCanonicalPath (jio/file root src-dir))) |
115 | | - |
116 | | - srcs (into [src-path |
117 | | - (.getCanonicalPath (jio/file root "src/main/clojure"))] |
118 | | - (for [^Resource resource (.. model getBuild getResources)] |
119 | | - (let [dir (jio/file (.getDirectory resource))] |
120 | | - (when dir |
121 | | - (if (.isAbsolute dir) |
122 | | - (.getCanonicalPath dir) |
123 | | - (.getCanonicalPath (jio/file root dir)))))))] |
124 | | - (->> srcs (remove nil?) distinct))) |
| 164 | + |
| 165 | + resources (for [^Resource resource (.. model getBuild getResources)] |
| 166 | + (.getDirectory resource)) |
| 167 | + |
| 168 | + build-helper-srcs (get-build-helper-paths model) |
| 169 | + |
| 170 | + srcs (concat [src-dir (.getCanonicalPath (jio/file root "src/main/clojure"))] |
| 171 | + resources |
| 172 | + build-helper-srcs)] |
| 173 | + (->> srcs (remove nil?) (map relativize) distinct))) |
125 | 174 |
|
126 | 175 | (defmethod ext/manifest-file :pom |
127 | 176 | [_lib {:keys [deps/root] :as _coord} _mf _config] |
|
0 commit comments