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

Release/v0.2.0 #13

Merged
merged 7 commits into from
Oct 27, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ workflows:
version: 2
build-and-deploy:
jobs:
- prepare
- prepare:
filters:
tags:
only: /.*/
- test:
requires:
- prepare
filters:
tags:
only: /.*/
- deploy:
requires:
- test
filters:
branches:
only:
- master
ignore: /.*/
tags:
only: /^v.*/
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject polylith/lein-polylith "0.1.1"
(defproject polylith/lein-polylith "0.2.0"
:description "Polylith - a component based architecture, by Joakim Tengstrand."
:url "https://github.com/tengstrand/lein-polylith"
:license {:name "Eclipse Public License",
Expand Down
48 changes: 23 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ The next thing to do is to add the Polylith plugin to `~/.lein/profiles.clj`. Af
This ensures that the Polylith plugin can be called from anywhere in the file system and not just from the *workspace root* where the *project.clj* file with the Polylith declaration resides:
```clojure
...
:plugins [[polylith/lein-polylith "0.1.0"]]
:plugins [[polylith/lein-polylith "0.2.0"]]
```

If called from the workspace root then it will use *0.1.0* in this case, otherwise it will use the latest version of the plugin.
If called from the workspace root then it will use *0.2.0* in this case, otherwise it will use the latest version of the plugin.

### Latest version
[![Clojars Project](https://clojars.org/polylith/lein-polylith/latest-version.svg)](http://clojars.org/polylith/lein-polylith)
Expand Down Expand Up @@ -160,7 +160,7 @@ The [Leiningen](https://leiningen.org) *project.clj* file defines which version
```clojure
(defproject se.example/example "1.0"
:description "A Polylith workspace."
:plugins [[polylith/lein-polylith "0.1.0"]]
:plugins [[polylith/lein-polylith "0.2.0"]]
:polylith {:top-namespace "se.example"
:clojure-version "1.9.0"})
```
Expand Down Expand Up @@ -322,7 +322,7 @@ example
cmd-line # link to bases/cmd-line/src/se/example/cmd-line
```

If we have a look at some of the generated files, we first find *systems/cmd-line/src/se/example/cmd_line/core.clj*:
If we have a look at some of the generated files, we first find *bases/cmd-line/src/se/example/cmd_line/core.clj*:
```clojure
(ns se.example.cmd-line.core
(:gen-class))
Expand All @@ -332,7 +332,7 @@ If we have a look at some of the generated files, we first find *systems/cmd-lin
(println "Hello world!"))
```

...with its corresponding test *systems/cmd-line/test/se/example/cmd_line/core_test.clj*:
...with its corresponding test *bases/cmd-line/test/se/example/cmd_line/core_test.clj*:
```clojure
(ns se.example.cmd-line.core-test
(:require [clojure.test :refer :all]
Expand Down Expand Up @@ -372,8 +372,8 @@ Changed bases: cmd-line
Changed systems: cmd-line

Compiling workspace interfaces
Created /Users/joakimtengstrand/Dropbox/Polylith/doc-script/example/interfaces/target/interfaces-1.0.jar
Wrote /Users/joakimtengstrand/Dropbox/Polylith/doc-script/example/interfaces/pom.xml
Created /Users/joakimtengstrand/IdeaProjects/example/interfaces/target/interfaces-1.0.jar
Wrote /Users/joakimtengstrand/IdeaProjects/example/interfaces/pom.xml
Installed jar and pom into local repo.

Compiling bases/cmd-line
Expand All @@ -389,8 +389,8 @@ Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Building systems/cmd-line
Created /Users/joakimtengstrand/Dropbox/Polylith/doc-script/example/systems/cmd-line/target/cmd-line-0.1.jar
Created /Users/joakimtengstrand/Dropbox/Polylith/doc-script/example/systems/cmd-line/target/cmd-line-0.1-standalone.jar
Created /Users/joakimtengstrand/IdeaProjects/example/systems/cmd-line/target/cmd-line-0.1.jar
Created /Users/joakimtengstrand/IdeaProjects/example/systems/cmd-line/target/cmd-line-0.1-standalone.jar

set :last-success in .polylith/time.edn

Expand Down Expand Up @@ -673,17 +673,17 @@ Now we have a *cmd-line* base and a *user* component:
$ lein polylith info

interfaces:
user *
user
components:
user *
user
bases:
cmd-line
systems:
cmd-line
cmd-line -> base
environments:
development
user * -> component
user -> component
cmd-line -> base
```

Expand Down Expand Up @@ -1232,26 +1232,24 @@ Finally you push your changes (5) and then the same plugin code will be executed
To understand how the plugin figures out what components and bases that have changed we can start by looking at the [diff](#diff) command:
```
$ lein polylith diff
interfaces/src/se/example/address/interface.clj
interfaces/src/se/example/address/interface.clj
systems/cmd-line/src/se/example/user/core.clj
systems/cmd-line/project.clj
components/address/src/se/example/address/interface.clj
components/address/src/se/example/address/core.clj
components/address/readme.md
components/address/test/se/example/address/core_test.clj
components/address/project.clj
components/user/src/se/example/user/core.clj
components/user/project.clj
bases/cmd-line/project.clj
environments/development/src/se/example/address/interface.clj
environments/development/src/se/example/address/core.clj
environments/development/src/se/example/user/core.clj
environments/development/interfaces/se/example/address/interface.clj
environments/development/development.iml
environments/development/docs/address-readme.md
environments/development/project-files/systems/cmd-line-project.clj
environments/development/project-files/components/address-project.clj
environments/development/project-files/components/user-project.clj
environments/development/project-files/bases/cmd-line-project.clj
environments/development/test/se/example/address/core_test.clj
environments/development/project.clj
```
Expand Down Expand Up @@ -1340,17 +1338,17 @@ components:
address-fake * > address
user *
bases:
cmd-line *
cmd-line (*)
systems:
cmd-line *
address * -> component
user * -> component
cmd-line * -> base
address * -> component
user * -> component
cmd-line (*) -> base
environments:
development
address * -> component
user * -> component
cmd-line * -> base
address * -> component
user * -> component
cmd-line (*) -> base
```

Now create the *cmd-line-test* system using the *cmd-line* base and then add *user* and *address-fake* to it:
Expand Down Expand Up @@ -1476,7 +1474,7 @@ $ lein polylith
```

```
Polylith 0.1.0 (2018-10-02) - https://github.com/tengstrand/lein-polylith
Polylith 0.2.0 (2018-10-27) - https://github.com/tengstrand/lein-polylith

lein polylith CMD [ARGS] - where CMD [ARGS] are:

Expand All @@ -1494,7 +1492,7 @@ $ lein polylith
remove C S Removes a component from a system.
settings Shows polylith settings.
success [B] Sets last-success or given bookmark.
sync [F] Syncs library dependencies and system components.
sync [F] Syncs library dependencies, system components and workspace interfaces.
test P [A] [S] Executes affected tests in components and bases.

Examples:
Expand Down
79 changes: 10 additions & 69 deletions src/leiningen/polylith.clj
Original file line number Diff line number Diff line change
@@ -1,76 +1,17 @@
(ns leiningen.polylith
(:require [clojure.string :as str]
[leiningen.polylith.cmd.add :as add]
[leiningen.polylith.cmd.build :as build]
[leiningen.polylith.cmd.changes :as changes]
[leiningen.polylith.cmd.compile :as compile]
[leiningen.polylith.cmd.create :as create]
[leiningen.polylith.cmd.delete :as delete]
[leiningen.polylith.cmd.deps :as deps]
[leiningen.polylith.cmd.diff :as diff]
;[leiningen.polylith.cmd.doc :as doc]]
(:require [clojure.stacktrace :as stacktrace]
[leiningen.polylith.cmd.help :as help]
[leiningen.polylith.cmd.info :as info]
[leiningen.polylith.cmd.prompt :as prompt]
[leiningen.polylith.cmd.remove :as remove]
[leiningen.polylith.cmd.settings :as settings]
[leiningen.polylith.cmd.success :as success]
[leiningen.polylith.cmd.sync :as sync]
[leiningen.polylith.cmd.test :as test]
[clojure.stacktrace :as stacktrace]
[leiningen.polylith.cmd.shared :as shared])
(:import (java.util.concurrent ExecutionException)))

(defn create-ws? [subtask args]
(and (= "create" subtask)
(or
(= "w" (first args))
(= "workspace" (first args)))))
[leiningen.polylith.commands :as commands]
[leiningen.polylith.cmd.shared :as shared]))

(defn ^:no-project-needed polylith
"Helps you develop component based systems"
([_]
(help/execute [] false))
([project command & cmd-args]
(let [ws-path (:root project)
settings (:polylith project)
top-ns (:top-namespace settings "")
github-url (:github-url settings "")
top-dir (str/replace top-ns #"\." "/")
clojure-version (:clojure-version settings "1.9.0")
args (vec (filter #(not= "-exit" %) cmd-args))
exit? (not (contains? (set cmd-args) "-exit"))
print-err? (not (contains? (set cmd-args) "-print-err"))]
(if (nil? settings)
(cond
(= "help" command) (help/execute args false)
(create-ws? command args) (create/execute ws-path top-dir top-ns clojure-version args)
:else (println (str "The command must be executed from the workspace root directory. Only 'help' and 'create w' commands can be executed outside of a workspace.")))
(try
(case command
"add" (add/execute ws-path top-dir args)
"build" (build/execute ws-path top-dir args)
"changes" (changes/execute ws-path top-dir args)
"compile" (compile/execute ws-path top-dir args)
"create" (create/execute ws-path top-dir top-ns clojure-version args)
"delete" (delete/execute ws-path top-dir args)
"deps" (deps/execute ws-path top-dir args)
"diff" (diff/execute ws-path args)
;"doc" (doc/execute ws-path top-dir github-url args)
"help" (help/execute args false)
"info" (info/execute ws-path top-dir args)
"prompt" (prompt/execute ws-path top-dir top-ns clojure-version settings github-url args)
"remove" (remove/execute ws-path top-dir args)
"settings" (settings/execute ws-path settings)
"success" (success/execute ws-path args)
"sync" (sync/execute ws-path top-dir)
"test" (test/execute ws-path top-dir args)
(println (str "Command '" command "' not found. Type 'lein polylith' for help.")))
(catch ExecutionException e
(when print-err?
(shared/print-error-message e))
(when exit?
(System/exit 1)))
(catch Exception e
(shared/print-error-message e)
(System/exit 1)))))))
([project command & args]
(let [{:keys [ok? system-error? exception]} (apply commands/execute project command args)]
(when (not ok?)
(if system-error?
(stacktrace/print-stack-trace exception)
(shared/print-error-message exception))
(System/exit 1)))))
22 changes: 9 additions & 13 deletions src/leiningen/polylith/cmd/add.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
[leiningen.polylith.utils :as utils]))

(defn system-components [ws-path top-dir system]
(let [dir (shared/full-name top-dir "/" "")
components (shared/all-components ws-path)
(let [dir (shared/full-name top-dir "/" "")
components (shared/all-components ws-path)
directories (file/directories (str ws-path "/systems/" system "/src/" dir))]
(filterv #(contains? components %) (map shared/path->file directories))))
(filterv #(contains? components %) (map #(shared/link->entity ws-path %) directories))))

(defn used-interface [ws-path top-dir system component]
(let [interface (shared/interface-of ws-path top-dir component)
components (system-components ws-path top-dir system)
(let [interface (shared/interface-of ws-path top-dir component)
components (system-components ws-path top-dir system)
component-interfaces (map #(vector (shared/interface-of ws-path top-dir %) %) components)]
(first (filter #(= interface (first %)) component-interfaces))))

(defn validate [ws-path top-dir system component]
(let [components (shared/all-components ws-path)
systems (shared/all-systems ws-path)
systems (shared/all-systems ws-path)
[interface comp] (used-interface ws-path top-dir system component)]
(cond
(utils/is-empty-str? component) [false "Missing component name."]
Expand All @@ -28,18 +28,14 @@
:else [true])))

(defn add-component-to-system [ws-path top-dir component system]
(let [component-dir (shared/full-dir-name top-dir component)
system-dir (shared/full-dir-name top-dir system)
(let [system-dir (shared/full-dir-name top-dir system)
relative-parent-path (shared/relative-parent-path system-dir)
relative-component-path (str relative-parent-path "components/" component)
system-path (str ws-path "/systems/" system)
interface (shared/interface-of ws-path top-dir component)
interface-dir (shared/full-dir-name top-dir interface)]
(when (not= interface component)
(file/create-symlink (str system-path "/src/" interface-dir)
(str relative-component-path "/src/" interface-dir)))
(file/create-symlink (str system-path "/src/" component-dir)
(str relative-component-path "/src/" component-dir))
(file/create-symlink (str system-path "/src/" interface-dir)
(str relative-component-path "/src/" interface-dir))
(file/create-symlink (str system-path "/resources/" component)
(str "../../../components/" component "/resources/" component))))

Expand Down