diff --git a/CHANGELOG.md b/CHANGELOG.md index c8d817ff..faba5228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,13 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/). ## [Unreleased] -Bugfix: - * Fix java dependency on SLES 15 when building Puppet Platform 7 + +## [2.6.1] +* Complete the ability to add a resources directory to a project with :include-dir by copying the resources to the staging directory. ## [2.6.0] * Add the ability to add a directory for project resources (such as build templates) by specifying the :include-dir option under {:lein-ezbake {:resources :include-dir "resources"}}. +* Fix java dependency on SLES 15 when building Puppet Platform 7 ## [2.5.5] Bugfix: diff --git a/src/puppetlabs/ezbake/core.clj b/src/puppetlabs/ezbake/core.clj index 83beeb91..b30af03a 100644 --- a/src/puppetlabs/ezbake/core.clj +++ b/src/puppetlabs/ezbake/core.clj @@ -294,26 +294,50 @@ Additional uberjar dependencies: [jar] (deputils/find-files-in-dir-in-jar jar shared-cli-apps-prefix)) +(defn- get-cli-app-files-in-directory + [dir-path] + (deputils/find-files-in-dir dir-path shared-cli-apps-prefix)) + (defn- get-cli-defaults-files-in [jar] (deputils/find-files-in-dir-in-jar jar shared-cli-defaults-prefix)) +(defn- get-cli-defaults-files-in-directory + [dir-path] + (deputils/find-files-in-dir dir-path shared-cli-defaults-prefix)) + (defn- get-terminus-files-in [jar] (deputils/find-files-in-dir-in-jar jar terminus-prefix)) +(defn- get-terminus-files-in-directory + [dir-path] + (deputils/find-files-in-dir dir-path terminus-prefix)) + (defn- get-bin-files-in [jar] (deputils/find-files-in-dir-in-jar jar shared-bin-prefix)) +(defn- get-bin-files-in-directory + [dir-path] + (deputils/find-files-in-dir dir-path shared-bin-prefix)) + (defn- get-config-files-in [jar] (deputils/find-files-in-dir-in-jar jar shared-config-prefix)) +(defn- get-config-files-in-directory + [dir-path] + (deputils/find-files-in-dir dir-path shared-config-prefix)) + (defn- get-build-scripts-files-in [jar] (deputils/find-files-in-dir-in-jar jar build-scripts-prefix)) +(defn- get-build-scripts-files-in-directory + [dir-path] + (deputils/find-files-in-dir dir-path build-scripts-prefix)) + (defn cp-shared-files [dependencies files-fn] (let [files (for [{:keys [project jar]} dependencies] @@ -885,6 +909,9 @@ Additional uberjar dependencies: ;; Do not copy the contents of :resource-paths from the deps in this list. ;; Items should be symbols of the form `namespace/project`, e.g. `puppetlabs/puppetserver` exclude-resources-from (get-in lein-project [:lein-ezbake :exclude-resources-from]) + include-resources-dir (get-in lein-project [:lein-ezbake + :resources + :include-dir]) lein-project (update lein-project :dependencies #(deputils/expand-snapshot-versions lein-project % {:reproducible? reproducible?}))] @@ -916,11 +943,19 @@ Additional uberjar dependencies: (cp-shared-files non-excluded-deps get-cli-defaults-files-in) (cp-shared-files non-excluded-deps get-build-scripts-files-in) (cp-project-build-scripts lein-project) - (if cli-app-files + (when cli-app-files (cp-cli-wrapper-scripts (:name lein-project))) (cp-doc-files lein-project) (when additional-uberjar-info (copy-additional-uberjars! additional-uberjar-info)) + ;; if :include-dir is specified, copy directory's files into staging + (when (some? include-resources-dir) + (deputils/copy-files-to-dir (get-bin-files-in-directory include-resources-dir) staging-dir include-resources-dir) + (deputils/copy-files-to-dir (get-build-scripts-files-in-directory include-resources-dir) staging-dir include-resources-dir) + (deputils/copy-files-to-dir (get-config-files-in-directory include-resources-dir) staging-dir include-resources-dir) + (deputils/copy-files-to-dir (get-cli-app-files-in-directory include-resources-dir) staging-dir include-resources-dir) + (deputils/copy-files-to-dir (get-cli-defaults-files-in-directory include-resources-dir) staging-dir include-resources-dir) + (deputils/copy-files-to-dir (get-terminus-files-in-directory include-resources-dir) staging-dir include-resources-dir)) (generate-ezbake-config-file! lein-project build-target config-files diff --git a/src/puppetlabs/ezbake/dependency_utils.clj b/src/puppetlabs/ezbake/dependency_utils.clj index 7add6cab..22be4b66 100644 --- a/src/puppetlabs/ezbake/dependency_utils.clj +++ b/src/puppetlabs/ezbake/dependency_utils.clj @@ -2,6 +2,7 @@ (:import (java.util.jar JarFile JarEntry) (java.io File)) (:require [cemerick.pomegranate.aether :as aether] + [clojure.java.io :as io] [me.raynes.fs :as fs] [clojure.string :as str] [leiningen.core.main :as lein-main] @@ -109,6 +110,37 @@ (not (.isDirectory %))) (enumeration-seq (.entries jar-file)))) +(defn find-files-in-dir + "Given a directory path and prefix string, returns a sequence of java.io.File." + [path prefix] + {:pre [(string? path) (string? prefix)]} + (let [dir-add-prefix (str path "/" prefix) + dir (io/file path)] + (filter #(and (.startsWith (.getPath %) dir-add-prefix) + (not (.isDirectory %))) + (file-seq dir)))) + +(defn copy-files-to-dir + "Given a sequence of java.io.File, a destination path to copy to, copy all files including directory + structure except the directory, specified by exclude-dir-prefix." + [file-seq dest-dir exclude-dir-prefix] + {:pre [(seq? file-seq) (string? dest-dir)]} + (let [dest (io/file dest-dir)] + (when-not (.exists dest) + (.mkdirs dest)) + (doseq [file file-seq] + (let [exclude-dir-prefix-with-slash (if (.endsWith exclude-dir-prefix "/") + exclude-dir-prefix + (str exclude-dir-prefix "/")) + source-dir-path-excluding-prefix (clojure.string/replace (.getParent file) exclude-dir-prefix-with-slash "") + ultimate-dest-dir (io/file dest-dir source-dir-path-excluding-prefix) + dest-file (io/file ultimate-dest-dir (.getName file))] + (when-not (.exists ultimate-dest-dir) + (.mkdirs ultimate-dest-dir)) + (lein-main/info (format "Copying lein-ezbake resources from included directory: %s to %s." + file dest-file)) + (io/copy file dest-file))))) + (defn find-file-in-jar [jar-file file-path] {:pre [(instance? JarFile jar-file)