From 23487f63e619084896fc361e5a6c41ff3803b26a Mon Sep 17 00:00:00 2001 From: Joakim Tengstrand Date: Sun, 18 Nov 2018 15:36:46 +0100 Subject: [PATCH] Resources has wrong name (#21) - Fix for wrong resources names when implementing the same interface multiple times. - Fix for wrong aliases in the example tests when implementing the same interface multiple times. --- .../polylith/cmd/create/component.clj | 16 ++++---- test/leiningen/polylith/cmd/add_test.clj | 26 ++++++------- .../polylith/cmd/create_component_test.clj | 38 +++++++++---------- test/leiningen/polylith/cmd/delete_test.clj | 21 +++++----- test/leiningen/polylith/cmd/remove_test.clj | 16 ++++---- 5 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/leiningen/polylith/cmd/create/component.clj b/src/leiningen/polylith/cmd/create/component.clj index 0dbbf0b..21e0939 100644 --- a/src/leiningen/polylith/cmd/create/component.clj +++ b/src/leiningen/polylith/cmd/create/component.clj @@ -17,7 +17,7 @@ components (set/intersection entities (shared/all-components ws-path))] (first (filter #(= interface (shared/interface-of ws-path top-dir %)) components)))) -(defn create-dev-links! [ws-path dev-dir component interface-dir component-dir] +(defn create-dev-links! [ws-path dev-dir component interface interface-dir component-dir] (let [root (str ws-path "/environments/" dev-dir) relative-parent-path (shared/relative-parent-path component-dir) path (str "../../../components/" component) @@ -30,8 +30,8 @@ (str relative-component-path "/test/" interface-dir)) (file/create-symlink (str root "/src/" interface-dir) (str relative-component-path "/src/" interface-dir)) - (file/create-symlink (str root "/resources/" component) - (str path "/resources/" component)))) + (file/create-symlink (str root "/resources/" interface) + (str path "/resources/" interface)))) (defn create [ws-path top-dir top-ns clojure-version component interface-name] (let [interface (if (str/blank? interface-name) component interface-name) @@ -57,11 +57,11 @@ "add documentation here..."] test-content [(str "(ns " interface-ns-name ".core-test") (str " (:require [clojure.test :refer :all]") - (str " [" interface-ns-name ".interface :as " component "]))") + (str " [" interface-ns-name ".interface :as " interface "]))") "" ";; add your tests here..." "(deftest test-add-two" - (str " (is (= 42 (" component "/add-two 40))))")] + (str " (is (= 42 (" interface "/add-two 40))))")] project-content [(str "(defproject " project-ns " \"0.1\"") (str " :description \"A " component " component.\"") (str " :dependencies [[" interfaces-dependencies " \"1.0\"]") @@ -72,8 +72,8 @@ (file/create-dir comp-root-dir) (file/create-dir (str comp-root-dir "/resources")) (file/create-file (str comp-root-dir "/resources/.keep") [""]) - (file/create-dir (str comp-root-dir "/resources/" component)) - (file/create-file (str comp-root-dir "/resources/" component "/.keep") [""]) + (file/create-dir (str comp-root-dir "/resources/" interface)) + (file/create-file (str comp-root-dir "/resources/" interface "/.keep") [""]) (shared/create-src-dirs! ws-path (str "components/" component "/src") [interface-dir]) (shared/create-src-dirs! ws-path (str "components/" component "/test") [interface-dir]) (file/create-file (str comp-root-dir "/project.clj") project-content) @@ -87,7 +87,7 @@ (doseq [dev-dir dev-dirs] (if (create-dev-links? ws-path top-dir dev-dir interface) - (create-dev-links! ws-path dev-dir component interface-dir component-dir) + (create-dev-links! ws-path dev-dir component interface interface-dir component-dir) (println (str "FYI: the component " component " was created but not added to " dev-dir " because it's interface " interface " was already " "used by " (used-by-component ws-path top-dir dev-dir interface) ".")))))) diff --git a/test/leiningen/polylith/cmd/add_test.clj b/test/leiningen/polylith/cmd/add_test.clj index 513f02e..5dfb72c 100644 --- a/test/leiningen/polylith/cmd/add_test.clj +++ b/test/leiningen/polylith/cmd/add_test.clj @@ -59,8 +59,8 @@ "components/comp1/readme.md" "components/comp1/resources" "components/comp1/resources/.keep" - "components/comp1/resources/comp1" - "components/comp1/resources/comp1/.keep" + "components/comp1/resources/ifc1" + "components/comp1/resources/ifc1/.keep" "components/comp1/src" "components/comp1/src/my" "components/comp1/src/my/company" @@ -97,8 +97,8 @@ "environments/development/resources/.keep" "environments/development/resources/base1" "environments/development/resources/base1/.keep" - "environments/development/resources/comp1" - "environments/development/resources/comp1/.keep" + "environments/development/resources/ifc1" + "environments/development/resources/ifc1/.keep" "environments/development/src" "environments/development/src/my" "environments/development/src/my/company" @@ -114,6 +114,8 @@ "environments/development/test/my/company/base1/core_test.clj" "environments/development/test/my/company/ifc1" "environments/development/test/my/company/ifc1/core_test.clj" + "images" + "images/logo.png" "interfaces" "interfaces/project.clj" "interfaces/src" @@ -121,8 +123,6 @@ "interfaces/src/my/company" "interfaces/src/my/company/ifc1" "interfaces/src/my/company/ifc1/interface.clj" - "images" - "images/logo.png" "project.clj" "readme.md" "systems" @@ -135,7 +135,6 @@ "systems/sys1/resources/base1" "systems/sys1/resources/base1/.keep" "systems/sys1/resources/comp1" - "systems/sys1/resources/comp1/.keep" "systems/sys1/src" "systems/sys1/src/my" "systems/sys1/src/my/company" @@ -205,8 +204,8 @@ "components/comp-1/readme.md" "components/comp-1/resources" "components/comp-1/resources/.keep" - "components/comp-1/resources/comp-1" - "components/comp-1/resources/comp-1/.keep" + "components/comp-1/resources/ifc-1" + "components/comp-1/resources/ifc-1/.keep" "components/comp-1/src" "components/comp-1/src/my" "components/comp-1/src/my/company" @@ -223,8 +222,8 @@ "components/comp-2/readme.md" "components/comp-2/resources" "components/comp-2/resources/.keep" - "components/comp-2/resources/comp-2" - "components/comp-2/resources/comp-2/.keep" + "components/comp-2/resources/ifc-1" + "components/comp-2/resources/ifc-1/.keep" "components/comp-2/src" "components/comp-2/src/my" "components/comp-2/src/my/company" @@ -261,8 +260,8 @@ "environments/development/resources/.keep" "environments/development/resources/base-1" "environments/development/resources/base-1/.keep" - "environments/development/resources/comp-1" - "environments/development/resources/comp-1/.keep" + "environments/development/resources/ifc-1" + "environments/development/resources/ifc-1/.keep" "environments/development/src" "environments/development/src/my" "environments/development/src/my/company" @@ -299,7 +298,6 @@ "systems/sys-1/resources/base-1" "systems/sys-1/resources/base-1/.keep" "systems/sys-1/resources/comp-1" - "systems/sys-1/resources/comp-1/.keep" "systems/sys-1/src" "systems/sys-1/src/my" "systems/sys-1/src/my/company" diff --git a/test/leiningen/polylith/cmd/create_component_test.clj b/test/leiningen/polylith/cmd/create_component_test.clj index e0df6fc..84c0298 100644 --- a/test/leiningen/polylith/cmd/create_component_test.clj +++ b/test/leiningen/polylith/cmd/create_component_test.clj @@ -17,15 +17,15 @@ ['defn 'add-two ['x] ['+ '2 'x]]]) -(defn ->add-two [component] - (symbol (name component) "add-two")) +(defn ->add-two [interface] + (symbol (name interface) "add-two")) -(defn component-core-test-content [component ns-name require-ns] +(defn component-core-test-content [interface ns-name require-ns] [['ns ns-name [:require ['clojure.test :refer :all] - [require-ns :as component]]] + [require-ns :as interface]]] ['deftest 'test-add-two - ['is ['= 42 [(->add-two component) 40]]]]]) + ['is ['= 42 [(->add-two interface) 40]]]]]) (defn src-interface-content [ns-name require-ns] [['ns ns-name @@ -320,8 +320,8 @@ "components/log-4j/project.clj" "components/log-4j/resources" "components/log-4j/resources/.keep" - "components/log-4j/resources/log-4j" - "components/log-4j/resources/log-4j/.keep" + "components/log-4j/resources/logg-ing" + "components/log-4j/resources/logg-ing/.keep" "components/log-4j/src" "components/log-4j/src/my" "components/log-4j/src/my/company" @@ -352,8 +352,8 @@ "environments/development/project.clj" "environments/development/resources" "environments/development/resources/.keep" - "environments/development/resources/log-4j" - "environments/development/resources/log-4j/.keep" + "environments/development/resources/logg-ing" + "environments/development/resources/logg-ing/.keep" "environments/development/src" "environments/development/src/my" "environments/development/src/my/company" @@ -390,7 +390,7 @@ (is (= (src-core-content 'my.company.logg-ing.core) (helper/content ws-dir "components/log-4j/src/my/company/logg_ing/core.clj"))) - (is (= (component-core-test-content 'log-4j 'my.company.logg-ing.core-test 'my.company.logg-ing.interface) + (is (= (component-core-test-content 'logg-ing 'my.company.logg-ing.core-test 'my.company.logg-ing.interface) (helper/content ws-dir "components/log-4j/test/my/company/logg_ing/core_test.clj"))) (is (= (src-interface-content 'my.company.logg-ing.interface 'my.company.logg-ing.core) @@ -411,7 +411,7 @@ (is (= (helper/component-project-content "log-4j" 'my.company/log-4j 'my.company/interfaces) (helper/content ws-dir "environments/development/project-files/components/log-4j-project.clj"))) - (is (= (component-core-test-content 'log-4j 'my.company.logg-ing.core-test 'my.company.logg-ing.interface) + (is (= (component-core-test-content 'logg-ing 'my.company.logg-ing.core-test 'my.company.logg-ing.interface) (helper/content ws-dir "environments/development/test/my/company/logg_ing/core_test.clj"))) (is (= (development-project-content 'my.company/development) @@ -443,8 +443,8 @@ "components/commonslogging/project.clj" "components/commonslogging/resources" "components/commonslogging/resources/.keep" - "components/commonslogging/resources/commonslogging" - "components/commonslogging/resources/commonslogging/.keep" + "components/commonslogging/resources/logging" + "components/commonslogging/resources/logging/.keep" "components/commonslogging/src" "components/commonslogging/src/my" "components/commonslogging/src/my/company" @@ -461,8 +461,8 @@ "components/log4j/project.clj" "components/log4j/resources" "components/log4j/resources/.keep" - "components/log4j/resources/log4j" - "components/log4j/resources/log4j/.keep" + "components/log4j/resources/logging" + "components/log4j/resources/logging/.keep" "components/log4j/src" "components/log4j/src/my" "components/log4j/src/my/company" @@ -493,8 +493,8 @@ "environments/development/project.clj" "environments/development/resources" "environments/development/resources/.keep" - "environments/development/resources/log4j" - "environments/development/resources/log4j/.keep" + "environments/development/resources/logging" + "environments/development/resources/logging/.keep" "environments/development/src" "environments/development/src/my" "environments/development/src/my/company" @@ -531,7 +531,7 @@ (is (= (src-core-content 'my.company.logging.core) (helper/content ws-dir "components/log4j/src/my/company/logging/core.clj"))) - (is (= (component-core-test-content 'log4j 'my.company.logging.core-test 'my.company.logging.interface) + (is (= (component-core-test-content 'logging 'my.company.logging.core-test 'my.company.logging.interface) (helper/content ws-dir "components/log4j/test/my/company/logging/core_test.clj"))) (is (= (src-interface-content 'my.company.logging.interface 'my.company.logging.core) @@ -552,7 +552,7 @@ (is (= (helper/component-project-content "log4j" 'my.company/log4j 'my.company/interfaces) (helper/content ws-dir "environments/development/project-files/components/log4j-project.clj"))) - (is (= (component-core-test-content 'log4j 'my.company.logging.core-test 'my.company.logging.interface) + (is (= (component-core-test-content 'logging 'my.company.logging.core-test 'my.company.logging.interface) (helper/content ws-dir "environments/development/test/my/company/logging/core_test.clj"))) (is (= (development-project-content 'my.company/development) diff --git a/test/leiningen/polylith/cmd/delete_test.clj b/test/leiningen/polylith/cmd/delete_test.clj index b1165d2..7733f26 100644 --- a/test/leiningen/polylith/cmd/delete_test.clj +++ b/test/leiningen/polylith/cmd/delete_test.clj @@ -127,6 +127,7 @@ "environments/development/resources/comp-1/.keep" "environments/development/resources/comp-3" "environments/development/resources/comp-3/.keep" + "environments/development/resources/interface-2" "environments/development/resources/system-1" "environments/development/resources/system-1/.keep" "environments/development/src" @@ -260,8 +261,8 @@ "components/comp-3/readme.md" "components/comp-3/resources" "components/comp-3/resources/.keep" - "components/comp-3/resources/comp-3" - "components/comp-3/resources/comp-3/.keep" + "components/comp-3/resources/interface-2" + "components/comp-3/resources/interface-2/.keep" "components/comp-3/src" "components/comp-3/src/my" "components/comp-3/src/my/company" @@ -299,6 +300,7 @@ "environments/development/resources/.keep" "environments/development/resources/comp-1" "environments/development/resources/comp-1/.keep" + "environments/development/resources/interface-2" "environments/development/resources/system-1" "environments/development/resources/system-1/.keep" "environments/development/src" @@ -411,8 +413,8 @@ "components/component-3/readme.md" "components/component-3/resources" "components/component-3/resources/.keep" - "components/component-3/resources/component-3" - "components/component-3/resources/component-3/.keep" + "components/component-3/resources/interface-1" + "components/component-3/resources/interface-1/.keep" "components/component-3/src" "components/component-3/src/my" "components/component-3/src/my/company" @@ -429,8 +431,8 @@ "components/component-5/readme.md" "components/component-5/resources" "components/component-5/resources/.keep" - "components/component-5/resources/component-5" - "components/component-5/resources/component-5/.keep" + "components/component-5/resources/component-4" + "components/component-5/resources/component-4/.keep" "components/component-5/src" "components/component-5/src/my" "components/component-5/src/my/company" @@ -471,10 +473,9 @@ "environments/development/resources/.keep" "environments/development/resources/base-1" "environments/development/resources/base-1/.keep" - "environments/development/resources/component-3" - "environments/development/resources/component-3/.keep" - "environments/development/resources/component-5" - "environments/development/resources/component-5/.keep" + "environments/development/resources/component-4" + "environments/development/resources/component-4/.keep" + "environments/development/resources/interface-1" "environments/development/src" "environments/development/src/my" "environments/development/src/my/company" diff --git a/test/leiningen/polylith/cmd/remove_test.clj b/test/leiningen/polylith/cmd/remove_test.clj index d67a2fb..73d040a 100644 --- a/test/leiningen/polylith/cmd/remove_test.clj +++ b/test/leiningen/polylith/cmd/remove_test.clj @@ -62,8 +62,8 @@ "components/comp-2/readme.md" "components/comp-2/resources" "components/comp-2/resources/.keep" - "components/comp-2/resources/comp-2" - "components/comp-2/resources/comp-2/.keep" + "components/comp-2/resources/ifc-2" + "components/comp-2/resources/ifc-2/.keep" "components/comp-2/src" "components/comp-2/src/my" "components/comp-2/src/my/company" @@ -106,8 +106,8 @@ "environments/development/resources/base-1/.keep" "environments/development/resources/comp-1" "environments/development/resources/comp-1/.keep" - "environments/development/resources/comp-2" - "environments/development/resources/comp-2/.keep" + "environments/development/resources/ifc-2" + "environments/development/resources/ifc-2/.keep" "environments/development/src" "environments/development/src/my" "environments/development/src/my/company" @@ -211,8 +211,8 @@ "components/comp2/readme.md" "components/comp2/resources" "components/comp2/resources/.keep" - "components/comp2/resources/comp2" - "components/comp2/resources/comp2/.keep" + "components/comp2/resources/ifc2" + "components/comp2/resources/ifc2/.keep" "components/comp2/src" "components/comp2/src/ifc2" "components/comp2/src/ifc2/core.clj" @@ -249,8 +249,8 @@ "environments/development/resources/base1/.keep" "environments/development/resources/comp1" "environments/development/resources/comp1/.keep" - "environments/development/resources/comp2" - "environments/development/resources/comp2/.keep" + "environments/development/resources/ifc2" + "environments/development/resources/ifc2/.keep" "environments/development/src" "environments/development/src/base1" "environments/development/src/base1/core.clj"