Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PE-37713) Copy files included with :include-dir to staging directory #634

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
* Fix the ability to add a resources directory to a project with :include-dir by copying the resources to the staging directory directly.

## [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:
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ configuration necessary.
:resources {

; The resources type indicates where lein-ezbake gets resources from.
; With the :jar type resources can be copied from the jars composed with lein-ezbake. The :include-dir option allows a project to specify an additional resource directory as well. This is useful where a project needs to specify resources outside of what is included in the jars. When specified, the :include-dir resources will replace files from the included jars of the same name.
; Future versions of lein-ezbake may support pulling these resources from a
; With the :jar type resources can be copied from the jars composed with
; lein-ezbake. The :include-dir option allows a project to specify an additional
; resource directory as well. This is useful where a project needs to specify
; resources outside of what is included in the jars. When specified, the
; :include-dir resources will replace files from the included jars of the same
; name. Future versions of lein-ezbake may support pulling these resources from a
; specific version of some git repository.
:type :jar
;; optionally specify a directory path in the project to include resources from
Expand Down
27 changes: 2 additions & 25 deletions src/leiningen/ezbake_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@
jar-file-path resource-path))
(deputils/cp-files-from-jar jar-entries jar-file resource-path)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Resource Directory Type Helpers
(defn copy-dir [src-dir dest-dir]
(let [src (io/file src-dir)
dest (io/file dest-dir)]
(if (.exists src)
(if (.isDirectory src)
(do
(.mkdirs dest)
(doseq [file (.listFiles src)]
(copy-dir (.getPath file) (str (io/file dest (.getName file))))))
(do
(lein-main/info (format "Copying lein-ezbake resources from included directory: %s to %s."
src-dir dest-dir))
(io/copy src dest)))
(throw (RuntimeException. (format "Resource directory %s does not exist." (str src-dir)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Consumable API

Expand All @@ -63,15 +46,9 @@
(let [template-type (get-in project [:lein-ezbake
:resources
:type]
:jar)
include-resource-dir (get-in project [:lein-ezbake
:resources
:include-dir]
nil)]
:jar)]
(case template-type
:git (throw (RuntimeException.
(format "Resource type, %s, not implemented."
(str template-type))))
:jar (copy-jar-resources core/resource-prefix core/resource-path))
(when (some? include-resource-dir)
(copy-dir include-resource-dir core/resource-path))))
:jar (copy-jar-resources core/resource-prefix core/resource-path))))
37 changes: 36 additions & 1 deletion src/puppetlabs/ezbake/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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?}))]
Expand Down Expand Up @@ -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 resource 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
Expand Down
32 changes: 32 additions & 0 deletions src/puppetlabs/ezbake/dependency_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
Loading