From 5f96f94f6f4210bf625ae41ee3514fdafa3f7259 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sat, 26 Jan 2019 23:27:30 -0700 Subject: [PATCH 01/38] Update travis --- .travis.yml | 11 +++++++---- Makefile => .travis/Makefile | 0 2 files changed, 7 insertions(+), 4 deletions(-) rename Makefile => .travis/Makefile (100%) diff --git a/.travis.yml b/.travis.yml index 1a1856b9..dff06707 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,11 @@ jdk: - openjdk12 - openjdk13 -services: - - docker +install: make --file=.travis/Makefile deps +script: make --file=.travis/Makefile test -install: curl https://raw.githubusercontent.com/boot-clj/docker-boot/master/boot/3/Dockerfile | docker build -t bootclj/boot:latest -f - . -script: docker run -t bootclj/boot:latest cd ~/.boot/cache/bin/3.0.0-SNAPSHOT/ && ls -a +cache: + directories: + - $HOME/.m2 + - $HOME/.boot/cache + - $HOME/bin diff --git a/Makefile b/.travis/Makefile similarity index 100% rename from Makefile rename to .travis/Makefile From 80c0153497e4ae0b41ffbd296d2072a22882fe4d Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sat, 26 Jan 2019 23:33:10 -0700 Subject: [PATCH 02/38] Update Makefile --- .travis/Makefile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.travis/Makefile b/.travis/Makefile index bc7567a1..d601a650 100644 --- a/.travis/Makefile +++ b/.travis/Makefile @@ -44,11 +44,8 @@ bin/boot: mkdirs deps: bin/lein bin/boot -boot/base/pom.xml: $(verfile) boot/base/pom.in.xml - (cd boot/base && cat pom.in.xml |sed 's/__VERSION__/$(version)/' > pom.xml) - -$(basejar): boot/base/pom.xml $(shell find boot/base/src/main/java) - (cd boot/base && mvn -q install) +$(basejar): boot/base/project.clj $(shell find boot/base/src/main/java) + (cd boot/base && lein install) $(podjar): $(verfile) boot/pod/project.clj $(shell find boot/pod/src) (cd boot/pod && lein install) @@ -64,8 +61,8 @@ $(workerjar): $(verfile) boot/worker/project.clj $(shell find boot/worker/src) $(corejar): $(verfile) boot/core/project.clj $(shell find boot/core/src) (cd boot/core && lein install) -$(baseuber): boot/base/pom.xml $(shell find boot/base/src/main) - (cd boot/base && mvn -q assembly:assembly -DdescriptorId=jar-with-dependencies) +$(baseuber): boot/base/project.clj $(shell find boot/base/src/main) + (cd boot/base && lein uberjar) $(bootjar): $(verfile) boot/boot/project.clj (cd boot/boot && lein install) From 3be7d7e3789a2b7172329e0eb57b73d5efbff008 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sat, 26 Jan 2019 23:37:44 -0700 Subject: [PATCH 03/38] Update Makefile --- .travis/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/Makefile b/.travis/Makefile index d601a650..f04b793f 100644 --- a/.travis/Makefile +++ b/.travis/Makefile @@ -14,7 +14,7 @@ aetheruber = aether.uber.jar workerjar = boot/worker/target/worker-$(version).jar corejar = boot/core/target/core-$(version).jar basejar = boot/base/target/base-$(version).jar -baseuber = boot/base/target/base-$(version)-jar-with-dependencies.jar +baseuber = boot/base/target/base-$(version)-standalone.jar alljars = $(podjar) $(aetherjar) $(workerjar) $(corejar) $(baseuber) $(bootjar) java_version = $(shell java -version 2>&1 | awk -F '"' '/version/ {print $$2}' |awk -F. '{print $$1 "." $$2}') From 8d636cd6cefd60244173a69f7cf94c9f3f373de3 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sat, 26 Jan 2019 23:50:26 -0700 Subject: [PATCH 04/38] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dff06707..02c38b6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ jdk: - openjdk13 install: make --file=.travis/Makefile deps -script: make --file=.travis/Makefile test +script: make --file=.travis/Makefile install cache: directories: From 17a0969defd82bfaf2c7a63ac9334234f9964c17 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 27 Jan 2019 02:20:22 -0700 Subject: [PATCH 05/38] remove root check (bootstrap) --- boot/base/src/main/java/boot/App.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 3cd51e3d..420e00b4 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -441,10 +441,6 @@ public class App { public static void main(String[] args) throws Exception { - String asroot = config("BOOT_AS_ROOT", "no"); - if (System.getProperty("user.name").equals("root") - && ! (asroot.equals("yes") || asroot.equals("1") || asroot.equals("true"))) - throw new Exception("refusing to run as root (set BOOT_AS_ROOT=yes to force)"); // BOOT_VERSION is decided by the loader; it will respect the // boot.properties files, env vars, system properties, etc. From 30839de99228deaef614147918418c896aaf9973 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Wed, 6 Feb 2019 14:04:04 -0700 Subject: [PATCH 06/38] move printVersion to bootstrap --- boot/base/src/main/java/boot/App.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 420e00b4..7b9284f6 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -474,12 +474,6 @@ public class App { updateBoot(bootprops, null, "(0,)"); System.exit(0); } - if (args.length > 0 - && ((args[0]).equals("-V") - || (args[0]).equals("--version"))) { - printVersion(); - System.exit(0); } - String repo = (localrepo == null) ? "default" : md5hash((new File(localrepo)).getCanonicalFile().getPath()); From ed74de4cdeac785c9ad2e42e5a5ceabe764dadb9 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Fri, 8 Feb 2019 23:56:48 -0700 Subject: [PATCH 07/38] Update App.java --- boot/base/src/main/java/boot/App.java | 293 +------------------------- 1 file changed, 1 insertion(+), 292 deletions(-) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 7b9284f6..909121da 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -54,20 +54,10 @@ public class App { public static String getClojureName() { return cljname; } private static final WeakHashMap pods = new WeakHashMap<>(); - private static final ConcurrentHashMap stash = new ConcurrentHashMap<>(); public static WeakHashMap getPods() { return pods; } - public static Object - getStash(String key) throws Exception { return stash.remove(key); } - - public static String - setStash(Object value) throws Exception { - String key = UUID.randomUUID().toString(); - stash.put(key, value); - return key; } - public static class Exit extends Exception { public Exit(String m) { super(m); } @@ -77,10 +67,6 @@ public class App { nextId() { return counter.addAndGet(1); } - public static File - getBootDir() throws Exception { - return bootdir(); } - public static boolean isWindows() throws Exception { return (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0); } @@ -101,16 +87,6 @@ public class App { tccl() throws Exception { return Thread.currentThread().getContextClassLoader(); } - public static InputStream - resource(String path) throws Exception { - return tccl().getResourceAsStream(path); } - - public static Properties - propertiesResource(String path) throws Exception { - Properties p = new Properties(); - try (InputStream is = resource(path)) { p.load(is); } - return p; } - public static File bootdir() throws Exception { File h = new File(System.getProperty("user.home")); @@ -119,194 +95,6 @@ public class App { String c = new File(h, ".boot").getCanonicalPath(); return new File((a != null) ? a : ((b != null) ? b : c)); } - public static String - md5hash(String data) throws Exception { - java.security.MessageDigest algo = java.security.MessageDigest.getInstance("MD5"); - return renderAsHex(algo.digest(data.getBytes())); } - - private static String - renderAsHex(byte[] content) { - Formatter formatter = new Formatter(); - for (byte b : content) { - formatter.format("%02X", b); - } - return formatter.toString(); } - - public static File - projectDir() throws Exception { - for (File f = workdir; f != null; f = f.getParentFile()) { - File tmp = new File(f, ".git"); - if (tmp.exists() && tmp.isDirectory()) return f; } - return null; } - - public static HashMap - properties2map(Properties p) throws Exception { - HashMap m = new HashMap<>(); - for (Map.Entry e : p.entrySet()) - m.put((String) e.getKey(), (String) e.getValue()); - return m; } - - public static Properties - map2properties(HashMap m) throws Exception { - Properties p = new Properties(); - for (Map.Entry e : m.entrySet()) - p.setProperty(e.getKey(), e.getValue()); - return p; } - - public static HashMap - propertiesFiles() throws Exception { - HashMap ret = new HashMap<>(); - String[] names = new String[]{"boot", "project", "cwd"}; - File[] dirs = new File[]{bootdir(), projectDir(), workdir}; - for (int i = 0; i < dirs.length; i++) - ret.put(names[i], new File(dirs[i], "boot.properties")); - return ret; } - - public static Properties - mergeProperties() throws Exception { - Properties p = new Properties(); - HashMap fs = propertiesFiles(); - for (String k : new String[]{"boot", "project", "cwd"}) - try (FileInputStream is = new FileInputStream(fs.get(k))) { - p.load(is); } - catch (FileNotFoundException e) {} - return p; } - - public static void - setDefaultProperty(Properties p, String k, String dfl) throws Exception { - if (p.getProperty(k) == null) p.setProperty(k, dfl); } - - public static HashMap - config() throws Exception { - HashMap ret = new HashMap<>(); - - ret.putAll(properties2map(mergeProperties())); - ret.remove("BOOT_HOME"); - ret.putAll(System.getenv()); - ret.putAll(properties2map(System.getProperties())); - - Iterator i = ret.keySet().iterator(); - while (i.hasNext()) { - String k = i.next(); - if (! k.startsWith("BOOT_")) i.remove(); } - - return ret; } - - public static String - config(String k) throws Exception { - return config().get(k); } - - public static String - config(String k, String dfl) throws Exception { - String v = config(k); - if (v != null) return v; - else { System.setProperty(k, dfl); return dfl; }} - - private static String - jarVersion(File f) throws Exception { - String ret = null; - JarEntry e = null; - String pat = "META-INF/maven/boot/boot/pom.properties"; - try (JarFile jar = new JarFile(f)) { - if ((e = jar.getJarEntry(pat)) != null) { - try (InputStream is = jar.getInputStream(e)) { - Properties p = new Properties(); - p.load(is); - ret = p.getProperty("version"); }}} - return ret; } - - private static Properties - writeProps(File f) throws Exception { - mkParents(f); - ClojureRuntimeShim a = aetherShim(); - Properties p = new Properties(); - String c = cljversion; - String n = cljname; - String t = null; - - try (FileInputStream is = new FileInputStream(f)) { - p.load(is); } - catch (FileNotFoundException e) {} - - if (bootversion == null) - for (File x : resolveDepJars(a, "boot", channel, n, c)) - if (null != (t = jarVersion(x))) bootversion = t; - - p.setProperty("BOOT_VERSION", bootversion); - setDefaultProperty(p, "BOOT_CLOJURE_NAME", n); - setDefaultProperty(p, "BOOT_CLOJURE_VERSION", c); - - try (FileOutputStream os = new FileOutputStream(f)) { - p.store(os, booturl); } - - return p; } - - private static Properties - readProps(File f, boolean create) throws Exception { - mkParents(f); - FileLock lock = null; - Properties p = new Properties(); - - if (!isWindows() && f.exists()) - lock = (new RandomAccessFile(f, "rw")).getChannel().lock(); - - try (FileInputStream is = new FileInputStream(f)) { - p.load(is); - if (p.getProperty("BOOT_CLOJURE_VERSION") == null - || p.getProperty("BOOT_VERSION") == null) - throw new Exception("missing info"); - return p; } - catch (Throwable e) { - if (! create) return null; - else return writeProps(f); } - finally { if (lock != null) lock.release(); }} - - private static HashMap - seedCache() throws Exception { - if (depsCache != null) return depsCache; - else { - ClojureRuntimeShim a = aetherShim(); - - HashMap cache = new HashMap<>(); - - cache.put("boot/pod", resolveDepJars(a, "boot/pod")); - cache.put("boot/core", resolveDepJars(a, "boot/core")); - cache.put("boot/worker", resolveDepJars(a, "boot/worker")); - - return depsCache = cache; }} - - private static Object - validateCache(File f, Object cache) throws Exception { - for (File[] fs : ((HashMap) cache).values()) - for (File d : fs) - if (! d.exists() || f.lastModified() < d.lastModified()) - throw new Exception("dep jar doesn't exist"); - return cache; } - - private static Object - writeCache(File f, Object m) throws Exception { - mkParents(f); - try (FileOutputStream os = new FileOutputStream(f); - ObjectOutputStream oos = new ObjectOutputStream(os)) { - oos.writeObject(m); } - return m; } - - private static Object - readCache(File f) throws Exception { - mkParents(f); - FileLock lock = null; - if (!isWindows()) - lock = (new RandomAccessFile(f, "rw")).getChannel().lock(); - try { - long max = 18 * 60 * 60 * 1000; - long age = System.currentTimeMillis() - f.lastModified(); - if (age > max) throw new Exception("cache age exceeds TTL"); - try (FileInputStream is = new FileInputStream(f); - ObjectInputStream ois = new ObjectInputStream(is)) { - return validateCache(f, ois.readObject()); }} - catch (Throwable e) { return writeCache(f, seedCache()); } - finally { if (lock != null) lock.release(); }} - public static ClojureRuntimeShim newShim(String name, Object data, File[] jarFiles) throws Exception { URL[] urls = new URL[jarFiles.length]; @@ -334,19 +122,6 @@ public class App { pods.put(rt, new Object()); return rt; } - public static ClojureRuntimeShim - newPod(String name, Object data) throws Exception { - return newShim(name, data, podjars); } - - public static ClojureRuntimeShim - newPod(String name, Object data, File[] jarFiles) throws Exception { - File[] files = new File[jarFiles.length + podjars.length]; - - for (int i=0; i 0) out.write(buf, 0, n); }} @@ -416,75 +191,9 @@ public class App { try { core.get().close(); } catch (InterruptedException ie) {}}} - public static String - readVersion() throws Exception { - Properties p = new Properties(); - try (InputStream in = resource("boot/base/version.properties")) { - p.load(in); } - return p.getProperty("version"); } - - public static void - printVersion() throws Exception { - Properties p = new Properties(); - p.setProperty("BOOT_VERSION", config("BOOT_VERSION")); - p.setProperty("BOOT_CLOJURE_NAME", config("BOOT_CLOJURE_NAME")); - p.setProperty("BOOT_CLOJURE_VERSION", config("BOOT_CLOJURE_VERSION")); - p.store(System.out, booturl); } - - public static void - updateBoot(File bootprops, String version, String chan) throws Exception { - update_always = true; - bootversion = version; - channel = chan; - Properties p = writeProps(bootprops); - p.store(System.out, booturl); } - public static void main(String[] args) throws Exception { - // BOOT_VERSION is decided by the loader; it will respect the - // boot.properties files, env vars, system properties, etc. - // or it will use the latest installed version. - // - // Since 2.4.0 we can assume that bootversion and appversion - // are the same (or boot.main will throw an exception). - bootversion = appversion = readVersion(); - - File cachehome = mkFile(bootdir(), "cache"); - File bootprops = mkFile(bootdir(), "boot.properties"); - File jardir = mkFile(cachehome, "lib", appversion); - File bootcache = mkFile(cachehome, "cache", "boot"); - - localrepo = config("BOOT_LOCAL_REPO"); - cljversion = config("BOOT_CLOJURE_VERSION", "1.8.0"); - cljname = config("BOOT_CLOJURE_NAME", "org.clojure/clojure"); - aetherfile = mkFile(cachehome, "lib", appversion, aetherjar); - - readProps(bootprops, true); - - if (args.length > 0 - && ((args[0]).equals("-u") - || (args[0]).equals("--update"))) { - updateBoot(bootprops, (args.length > 1) ? args[1] : null, "RELEASE"); - System.exit(0); } - - if (args.length > 0 - && ((args[0]).equals("-U") - || (args[0]).equals("--update-snapshot"))) { - updateBoot(bootprops, null, "(0,)"); - System.exit(0); } - - String repo = (localrepo == null) - ? "default" - : md5hash((new File(localrepo)).getCanonicalFile().getPath()); - - File cachefile = mkFile(bootcache, repo, cljversion, bootversion, "deps.cache"); - HashMap cache = (HashMap) readCache(cachefile); - - podjars = cache.get("boot/pod"); - corejars = cache.get("boot/core"); - workerjars = cache.get("boot/worker"); - Thread shutdown = new Thread() { public void run() { ex.shutdown(); }}; Runtime.getRuntime().addShutdownHook(shutdown); System.exit(runBoot(newCore(null), newWorker(), args)); }} From 13745cf74a1ff1ee1a724938c86f8e56002cb1a1 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sat, 9 Feb 2019 20:33:03 -0700 Subject: [PATCH 08/38] refactor for bootstrap --- boot/aether/project.clj | 1 + boot/aether/src/boot/aether.clj | 11 +++++------ boot/core/src/boot/core.clj | 10 +++++----- boot/core/src/boot/main.clj | 4 ---- boot/pod/src/boot/gpg.clj | 3 ++- boot/pod/src/boot/pod.clj | 17 +++++++++-------- boot/pod/src/boot/tmpdir.clj | 5 +++-- boot/pod/src/boot/util.clj | 17 +++++++++-------- boot/tasks/src/boot/task/built_in.clj | 5 +++-- 9 files changed, 37 insertions(+), 36 deletions(-) diff --git a/boot/aether/project.clj b/boot/aether/project.clj index 2c41d7a3..4a6e39e3 100644 --- a/boot/aether/project.clj +++ b/boot/aether/project.clj @@ -16,6 +16,7 @@ :dependencies [[org.clojure/clojure "1.9.0" :scope "compile"] [boot/base ~version :scope "provided"] [boot/pod ~version :scope "compile"] + [boot/bootstrap "3.0.0-SNAPSHOT" :scope "compile"] [com.cemerick/pomegranate "1.0.0" :scope "compile"] [org.apache.maven.wagon/wagon-http "2.12" :scope "compile" :exclusions [org.apache.maven.wagon/wagon-provider-api]]]) diff --git a/boot/aether/src/boot/aether.clj b/boot/aether/src/boot/aether.clj index c1afee41..929a3b2b 100644 --- a/boot/aether/src/boot/aether.clj +++ b/boot/aether/src/boot/aether.clj @@ -8,7 +8,8 @@ [boot.pod :as pod] [boot.gpg :as gpg] [boot.from.io.aviso.ansi :as ansi] - [boot.kahnsort :as ksort]) + [boot.kahnsort :as ksort] + [bootstrap.config :as conf]) (:import [boot App] [java.io File] @@ -20,12 +21,10 @@ (def offline? (atom false)) (def update? (atom :daily)) (def local-repo (atom nil)) -(def default-repositories (delay (let [c (boot.App/config "BOOT_CLOJARS_REPO") - m (boot.App/config "BOOT_MAVEN_CENTRAL_REPO")] +(def default-repositories (delay (let [{c :boot-clojars-repo m :boot-maven-central-repo} (conf/config)] [["clojars" {:url (or c "https://repo.clojars.org/")}] ["maven-central" {:url (or m "https://repo1.maven.org/maven2/")}]]))) -(def default-mirrors (delay (let [c (boot.App/config "BOOT_CLOJARS_MIRROR") - m (boot.App/config "BOOT_MAVEN_CENTRAL_MIRROR") +(def default-mirrors (delay (let [{c :boot-clojars-mirror m :boot-maven-central-mirror} (conf/config) f #(when %1 {%2 {:name (str %2 " mirror") :url %1}})] (merge {} (f c "clojars") (f m "maven-central"))))) @@ -391,7 +390,7 @@ context (make-context (into (default-certs) certs))] (override-wagon-registry! (https-registry context))))) -(when-let [certs (boot.App/config "BOOT_CERTIFICATES")] +(when-let [certs (:boot-certificates (conf/config))] (let [certs (string/split certs #":")] (util/dbug "Using SSL certificates: %s\n" certs) (load-certificates! certs))) diff --git a/boot/core/src/boot/core.clj b/boot/core/src/boot/core.clj index c810a638..184728c5 100644 --- a/boot/core/src/boot/core.clj +++ b/boot/core/src/boot/core.clj @@ -17,7 +17,8 @@ [boot.util :as util] [boot.from.io.aviso.exception :as ex] [boot.from.clojure.tools.cli :as cli] - [boot.from.backtick :as bt]) + [boot.from.backtick :as bt] + [bootstrap.config :as conf]) (:import [boot App] [java.io File] @@ -60,8 +61,7 @@ (def ^:private checkout-dirs (atom #{})) (def ^:private default-repos [["clojars" {:url "https://repo.clojars.org/"}] ["maven-central" {:url "https://repo1.maven.org/maven2"}]]) -(def ^:private default-mirrors (delay (let [c (boot.App/config "BOOT_CLOJARS_MIRROR") - m (boot.App/config "BOOT_MAVEN_CENTRAL_MIRROR") +(def ^:private default-mirrors (delay (let [{c :boot-clojars-mirror m :boot-maven-central-mirror} (conf/config) f #(when %1 {%2 {:name (str %2 " mirror") :url %1}})] (merge {} (f c "clojars") (f m "maven-central"))))) @@ -230,7 +230,7 @@ "compute a seq of [name new-coord old-coord] elements describing version conflicts when resolving the 'old' dependency vector and the 'new' dependency vector" [old new env] - (let [clj-name (symbol (boot.App/getClojureName)) + (let [clj-name (symbol (:boot-clojure-name (conf/config))) old-deps (-> (map-of-deps env old) (assoc clj-name (clojure-version)))] (->> (map-of-deps env new) (keep (fn [[name coord]] @@ -241,7 +241,7 @@ "Warn, when the version of a dependency changes. Call this with the result of find-version-conflicts as arguments" [coll] - (let [clj-name (symbol (boot.App/getClojureName))] + (let [clj-name (symbol (:boot-clojure-name (conf/config)))] (doseq [[name new-coord old-coord] coll] (let [op (if (= name clj-name) "NOT" "ALSO")] (-> "Classpath conflict: %s version %s already loaded, %s loading version %s\n" diff --git a/boot/core/src/boot/main.clj b/boot/core/src/boot/main.clj index 70efdaf3..f6074122 100644 --- a/boot/core/src/boot/main.clj +++ b/boot/core/src/boot/main.clj @@ -121,10 +121,6 @@ (->> (string/split (slurp f) #"\n") (remove string/blank?) (map re-pattern) set))) (defn -main [pod-id worker-pod shutdown-hooks [arg0 & args :as args*]] - (when (not= (boot.App/getVersion) (boot.App/getBootVersion)) - (let [url "https://github.com/boot-clj/boot#install"] - (util/exit-error - (println (format "Please download latest Boot binary: %s" url))))) (pod/set-pod-id! pod-id) (pod/set-worker-pod! worker-pod) diff --git a/boot/pod/src/boot/gpg.clj b/boot/pod/src/boot/gpg.clj index 7cddcf2d..1e67e52e 100644 --- a/boot/pod/src/boot/gpg.clj +++ b/boot/pod/src/boot/gpg.clj @@ -4,12 +4,13 @@ [clojure.java.shell :as shell] [boot.pod :as pod] [boot.util :as util]) + [bootstrap.config :as conf] (:import [java.io StringReader File])) (defn ^{:boot/from :technomancy/leiningen} gpg-program "Lookup the gpg program to use, defaulting to 'gpg'" [] - (or (boot.App/config "BOOT_GPG_COMMAND") "gpg")) + (or (:boot-gpg-command (conf/config)) "gpg")) (defn- ^{:boot/from :technomancy/leiningen} get-english-env [] "Returns environment variables as a map with clojure keywords and LANGUAGE set to 'en'" diff --git a/boot/pod/src/boot/pod.clj b/boot/pod/src/boot/pod.clj index b4f58f67..3696fc74 100644 --- a/boot/pod/src/boot/pod.clj +++ b/boot/pod/src/boot/pod.clj @@ -10,6 +10,7 @@ [clojure.java.io :as io] [dynapath.util :as dp] [dynapath.dynamic-classpath :as cp]) + [bootstrap.config :as conf] (:import [java.util.jar JarFile] [java.lang.ref WeakReference] @@ -70,7 +71,7 @@ dynapath.dynamic-classpath/DynamicClasspath boot.pod/sealed-classloader-fns)) (catch Exception _)) - + (try ;; this import will fail if the user is using Java 9 (import sun.misc.Launcher$AppClassLoader) @@ -336,7 +337,7 @@ that boot may be running inside another instance of boot, so shutdown hooks must be handled carefully as the JVM will not necessarily exit when this boot instance is finished. - + Functions added via add-shutdown-hook! will be processed at the correct time (i.e. when boot is finished in the case of nested instances of boot, or when the JVM exits otherwise)." @@ -400,7 +401,7 @@ The expr is expected to be of the form (f & args). It is evaluated in the pod by resolving f and applying it to args. - + Note: Since forms must be serialized to pass from one pod to another it is not always appropriate to include metadata, as metadata may contain eg. File objects which are not printable/readable by Clojure." @@ -590,7 +591,7 @@ will be excluded from the result (the clojure dependency is identified by the BOOT_CLOJURE_NAME environment setting, which defaults to org.clojure.clojure)." [env & [ignore-clj?]] - (let [clj-dep (symbol (boot.App/config "BOOT_CLOJURE_NAME")) + (let [clj-dep (symbol (:boot-clojure-name (conf/config))) rm-clj (if-not ignore-clj? identity (partial remove #(and (= clj-dep (first (:dep %))) @@ -762,7 +763,7 @@ (defn jars-in-dep-order "Returns a seq of all jar file dependencies specified in the boot environment map env, including transitive dependencies, and in dependency order. - + Dependency order means, eg. if jar B depends on jar A then jar A will appear before jar B in the returned list." [env] @@ -887,8 +888,8 @@ ([] (init-pod! env (boot.App/newPod nil data))) ([{:keys [directories dependencies] :as env} & {:keys [name data]}] (let [dirs (map io/file directories) - cljname (or (boot.App/getClojureName) "org.clojure/clojure") - dfl [['boot/pod (boot.App/getBootVersion)] + {cljname :boot-clojure-name ver :boot-version} (conf/config) + dfl [['boot/pod ver] [(symbol cljname) (clojure-version)]] env (default-dependencies dfl env) jars (resolve-dependency-jars env) @@ -938,7 +939,7 @@ Calling the function with no arguments produces a reference to the current pod. Expressions can be evaluated in this pod via with-eval-in, etc. - + Calling the function with the :refresh argument swaps out the current pod, destroys it, and promotes a pod from the reserve pool. A new pod is created asynchronously to replenish the reserve pool. diff --git a/boot/pod/src/boot/tmpdir.clj b/boot/pod/src/boot/tmpdir.clj index 6bb6f37e..6ce385ae 100644 --- a/boot/pod/src/boot/tmpdir.clj +++ b/boot/pod/src/boot/tmpdir.clj @@ -9,7 +9,8 @@ [boot.pod :as pod] [boot.file :as file] [boot.from.digest :as digest] - [boot.util :as util :refer [with-let]]) + [boot.util :as util :refer [with-let]] + [bootstrap.config :as conf]) (:import [java.io File] [java.util Properties] @@ -113,7 +114,7 @@ (defn- ^File cache-dir [cache-key] - (-> (boot.App/bootdir) + (-> (conf/boot-dir) (io/file "cache" "cache" "fileset") (io/file CACHE_VERSION cache-key))) diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj index 73dbe89a..207c6430 100644 --- a/boot/pod/src/boot/util.clj +++ b/boot/pod/src/boot/util.clj @@ -8,6 +8,7 @@ [boot.from.io.aviso.ansi :as ansi] [boot.from.io.aviso.exception :as pretty] [boot.from.me.raynes.conch :as conch]) + [bootstrap.config :as conf] (:import [java.io File] [java.nio ByteBuffer] @@ -25,7 +26,7 @@ configuration option BOOT_WATCHERS_DISABLE to either '1' or 'yes' or 'true' to disable inotify; any other value keeps normal behavior." [] - (let [value (boot.App/config "BOOT_WATCHERS_DISABLE")] + (let [value (:boot-watchers-disable (conf/config))] (if (string/blank? value) true (not (#{"1" "yes" "true"} @@ -40,7 +41,7 @@ either '1' or 'yes' or 'true' to enable it; any other value disables colorization." [] - (let [value (boot.App/config "BOOT_COLOR")] + (let [value (:boot-color (conf/config))] (if-not (string/blank? value) (#{"1" "yes" "true"} (string/lower-case value)) (not (boot.App/isWindows))))) @@ -48,7 +49,7 @@ (def ^:dynamic *verbosity* "Atom containing the verbosity level, 1 is lowest, 3 highest. Level 2 corresponds to the -v boot option, level 3 to -vv, etc. - + Levels: 1. Print INFO level messages or higher, colorize and prune stack traces @@ -167,13 +168,13 @@ Note that boot.util/*verbosity* in a pod needs to be altered AFTER pod creation or log level won't be affected." [& args] - (when-not (= "no" (boot.App/config "BOOT_WARN_DEPRECATED")) + (when-not (= "no" (:boot-warn-deprecated (conf/config))) (apply warn args))) (defmacro extends-protocol "Like extend-protocol but allows specifying multiple classes for each of the implementations: - + (extends-protocol IFoo clojure.lang.MapEntry ; <-- this is the difference, multiple clojure.lang.PersistentVector ; <-- classes per implementation @@ -232,7 +233,7 @@ (defmacro dotoseq "A cross between doto and doseq. For example: - + (-> (System/-err) (dotoseq [i (range 0 100)] (.printf \"i = %d\\n\" i)) @@ -339,9 +340,9 @@ A tree consists of a graph of nodes of the format [ ], where is a string and is a set of nodes (the children of this node). - + Example: - + (util/print-tree [[\"foo\" #{[\"bar\" #{[\"baz\"]}]}]] [\"--\" \"XX\"]) prints: diff --git a/boot/tasks/src/boot/task/built_in.clj b/boot/tasks/src/boot/task/built_in.clj index 26ce6e1f..d2c7ed99 100644 --- a/boot/tasks/src/boot/task/built_in.clj +++ b/boot/tasks/src/boot/task/built_in.clj @@ -19,7 +19,8 @@ [boot.from.digest :as digest] [boot.task-helpers :as helpers] [boot.task-helpers.notify :as notify] - [boot.pedantic :as pedantic]) + [boot.pedantic :as pedantic] + [bootstrap.config :as conf]) (:import [java.io File] [java.nio.file.attribute PosixFilePermissions] @@ -241,7 +242,7 @@ (pod/with-eval-in p boot.pod/env))] (when pods (util/info "\nPod: %s\n\n" pod-name)) (cond (or deps verify-deps) (print (pod/with-call-worker (boot.aether/dep-tree ~pod-env ~verify-deps))) - env (println (pretty-str (assoc pod-env :config (boot.App/config)))) + env (println (pretty-str (assoc pod-env :config (conf/config)))) updates (mapv prn (pod/outdated pod-env :snapshots update-snapshots)) pedantic (pedantic/prn-conflicts pod-env) :else @usage)))))))) From 061507fa2369d667a473b78e41b8e473ee1cf419 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 12:30:49 -0700 Subject: [PATCH 09/38] continue refactor --- boot/core/src/boot/main.clj | 9 +++++---- boot/pod/src/boot/pod.clj | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/boot/core/src/boot/main.clj b/boot/core/src/boot/main.clj index f6074122..6f8d7737 100644 --- a/boot/core/src/boot/main.clj +++ b/boot/core/src/boot/main.clj @@ -9,7 +9,8 @@ [boot.core :as core] [boot.file :as file] [boot.util :as util] - [boot.from.clojure.tools.cli :as cli])) + [boot.from.clojure.tools.cli :as cli] + [bootstrap.config :as conf])) (def cli-opts [["-a" "--asset-paths PATH" "Add PATH to set of asset directories." @@ -110,7 +111,7 @@ (defn shebang? [arg] (when (and (<= 0 (.indexOf arg (int \/))) (.exists (io/file arg))) (let [bang-line (str (first (string/split (slurp arg) #"\n"))) - full-path (System/getProperty "boot.app.path") + full-path (:boot-app-path (conf/config)) base-path (.getName (io/file full-path)) full-pat (re-pattern (format "^#!\\s*\\Q%s\\E(?:\\s+.*)?$" full-path)) base-pat (re-pattern (format "^#!\\s*/usr/bin/env\\s+\\Q%s\\E(?:\\s+.*)?$" base-path))] @@ -171,8 +172,8 @@ *err* (util/auto-flush *err*) core/*boot-opts* opts core/*boot-script* arg0 - core/*boot-version* (boot.App/getBootVersion) - core/*app-version* (boot.App/getVersion)] + core/*boot-version* (:boot-version (conf/config)) + core/*app-version* (:boot-version (conf/config))] (util/exit-ok (let [userscript (util/with-let [x (-> (System/getProperty "user.home") diff --git a/boot/pod/src/boot/pod.clj b/boot/pod/src/boot/pod.clj index 3696fc74..003204e3 100644 --- a/boot/pod/src/boot/pod.clj +++ b/boot/pod/src/boot/pod.clj @@ -910,7 +910,7 @@ are needed to bootstrap the pod, have no transitive dependencies, and are added automatically." [classpath & {:keys [name data]}] - (doto (->> (assoc env :dependencies [['boot/pod (boot.App/getBootVersion)]]) + (doto (->> (assoc env :dependencies [['boot/pod (:boot-version (conf/config))]]) (resolve-dependency-jars) (into (map io/file classpath)) (into-array java.io.File) From ca2f093746e4bc675b2a49d6ab624f6e22cc0ecd Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 12:30:58 -0700 Subject: [PATCH 10/38] add boot.host ns --- boot/core/src/boot/host.clj | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 boot/core/src/boot/host.clj diff --git a/boot/core/src/boot/host.clj b/boot/core/src/boot/host.clj new file mode 100644 index 00000000..57e6b982 --- /dev/null +++ b/boot/core/src/boot/host.clj @@ -0,0 +1,6 @@ +(ns boot.host + (:require [clojure.string :as str] + [bootstrap.config :as conf])) + +(defn isWindows [] + (str/starts-with? (:os-name (conf/config)) "Windows")) From 3acd1bc6f53969f3ded40fa00e21a53990d61616 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 12:36:12 -0700 Subject: [PATCH 11/38] refacrot host os checks --- boot/base/src/main/java/boot/App.java | 4 ---- boot/core/src/boot/host.clj | 6 ++++-- boot/pod/src/boot/file.clj | 7 +++---- boot/pod/src/boot/filesystem.clj | 9 ++++----- boot/pod/src/boot/util.clj | 3 ++- boot/tasks/src/boot/task/built_in.clj | 5 +++-- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 909121da..84718911 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -67,10 +67,6 @@ public class App { nextId() { return counter.addAndGet(1); } - public static boolean - isWindows() throws Exception { - return (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0); } - public static File mkFile(File parent, String... kids) throws Exception { File ret = parent; diff --git a/boot/core/src/boot/host.clj b/boot/core/src/boot/host.clj index 57e6b982..ed11760f 100644 --- a/boot/core/src/boot/host.clj +++ b/boot/core/src/boot/host.clj @@ -2,5 +2,7 @@ (:require [clojure.string :as str] [bootstrap.config :as conf])) -(defn isWindows [] - (str/starts-with? (:os-name (conf/config)) "Windows")) +(defn windows? [] + (-> (:os-name (conf/config)) + (str/lower-case) + (str/starts-with? "win"))) diff --git a/boot/pod/src/boot/file.clj b/boot/pod/src/boot/file.clj index e4202d38..756de108 100644 --- a/boot/pod/src/boot/file.clj +++ b/boot/pod/src/boot/file.clj @@ -4,6 +4,7 @@ [clojure.set :as set] [clojure.data :as data] [boot.from.digest :as digest] + [boot.host :as host] [clojure.string :as str]) (:import [java.net URI] @@ -21,11 +22,9 @@ (def ^:dynamic *sync-delete* true) (def ^:dynamic *hard-link* true) -(def windows? (boot.App/isWindows)) - (def tmpfile-permissions (into-array FileAttribute - (if windows? + (if host/windows? [] [(PosixFilePermissions/asFileAttribute (PosixFilePermissions/fromString "rw-------"))]))) @@ -251,7 +250,7 @@ (defn match-filter? [filters f] - (let [normalize #(if-not windows? % (str/replace % #"\\" "/"))] + (let [normalize #(if-not host/windows? % (str/replace % #"\\" "/"))] ((apply some-fn (map (partial partial re-find) filters)) (normalize (.getPath ^File f))))) (defn keep-filters? diff --git a/boot/pod/src/boot/filesystem.clj b/boot/pod/src/boot/filesystem.clj index 5f9d989c..5fa54bb6 100644 --- a/boot/pod/src/boot/filesystem.clj +++ b/boot/pod/src/boot/filesystem.clj @@ -7,7 +7,8 @@ [boot.filesystem.patch :as fsp] [boot.file :as file] [boot.from.digest :as digest :refer [md5]] - [boot.util :as util :refer [with-let]]) + [boot.util :as util :refer [with-let]] + [boot.host :as host]) (:import [java.net URI] [java.io File] @@ -38,8 +39,6 @@ (def read-only (PosixFilePermissions/fromString "r--r--r--")) -(def windows? (boot.App/isWindows)) - (defprotocol IToPath (->path [x] "Returns a java.nio.file.Path for x.")) @@ -162,7 +161,7 @@ (util/dbug* "Filesystem: copying %s...\n" (string/join "/" path)) (try (Files/copy ^Path src ^Path dst copy-opts) (Files/setLastModifiedTime dst (FileTime/fromMillis time)) - (when (and mode (not windows?)) (Files/setPosixFilePermissions dst mode)) + (when (and mode (not host/windows?)) (Files/setPosixFilePermissions dst mode)) (catch java.nio.file.NoSuchFileException ex (util/dbug* "Filesystem: %s\n", (str ex)))))) @@ -172,7 +171,7 @@ (util/dbug* "Filesystem: linking %s...\n" (string/join "/" path)) (try (Files/deleteIfExists dst) (Files/createLink (doto dst mkparents!) src) - (when (and mode (not windows?)) (Files/setPosixFilePermissions dst mode)) + (when (and mode (not host/windows?)) (Files/setPosixFilePermissions dst mode)) (catch java.nio.file.NoSuchFileException ex (util/dbug* "Filesystem: %s\n" (str ex)))))) diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj index 207c6430..5ce894f4 100644 --- a/boot/pod/src/boot/util.clj +++ b/boot/pod/src/boot/util.clj @@ -9,6 +9,7 @@ [boot.from.io.aviso.exception :as pretty] [boot.from.me.raynes.conch :as conch]) [bootstrap.config :as conf] + [boot.host :as host] (:import [java.io File] [java.nio ByteBuffer] @@ -44,7 +45,7 @@ (let [value (:boot-color (conf/config))] (if-not (string/blank? value) (#{"1" "yes" "true"} (string/lower-case value)) - (not (boot.App/isWindows))))) + (not (host/windows?))))) (def ^:dynamic *verbosity* "Atom containing the verbosity level, 1 is lowest, 3 highest. Level 2 diff --git a/boot/tasks/src/boot/task/built_in.clj b/boot/tasks/src/boot/task/built_in.clj index d2c7ed99..17be148a 100644 --- a/boot/tasks/src/boot/task/built_in.clj +++ b/boot/tasks/src/boot/task/built_in.clj @@ -20,7 +20,8 @@ [boot.task-helpers :as helpers] [boot.task-helpers.notify :as notify] [boot.pedantic :as pedantic] - [bootstrap.config :as conf]) + [bootstrap.config :as conf] + [boot.host :as host]) (:import [java.io File] [java.nio.file.attribute PosixFilePermissions] @@ -332,7 +333,7 @@ (defn- mk-posix-file-permissions [posix-string] (try (when posix-string - (if (boot.App/isWindows) + (if (host/windows?) (util/warn "Filemode not supported on Windows\n") (PosixFilePermissions/fromString posix-string))) (catch IllegalArgumentException _ From 59deedfd9650d3acc4d6c92961ceb5a175f3d5d3 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 12:46:57 -0700 Subject: [PATCH 12/38] Update project.clj --- boot/pod/project.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/boot/pod/project.clj b/boot/pod/project.clj index 3000848b..12c2f259 100644 --- a/boot/pod/project.clj +++ b/boot/pod/project.clj @@ -16,6 +16,7 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[boot/base ~version :scope "provided"] + [boot/bootstrap "3.0.0-SNAPSHOT" :scope "provided"] [org.clojure/clojure "1.9.0" :scope "provided"] [org.tcrawley/dynapath "1.0.0" :scope "compile"] [org.projectodd.shimdandy/shimdandy-impl "1.2.0" :scope "compile"]]) From 49ca48b2db69080aa1faa98cb0380deef38c3f55 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 13:05:53 -0700 Subject: [PATCH 13/38] Update project.clj --- boot/core/project.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boot/core/project.clj b/boot/core/project.clj index 371fd692..52b8c4d2 100644 --- a/boot/core/project.clj +++ b/boot/core/project.clj @@ -15,4 +15,5 @@ :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.9.0" :scope "provided"] [boot/base ~version :scope "provided"] - [boot/pod ~version :scope "compile"]]) + [boot/pod ~version :scope "compile"] + [boot/boostrap "3.0.0-SNAPSHOT" :scope "provided"]]) From d48c6daa1d99897b43919ec0f16a986a9c2a8303 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 13:11:54 -0700 Subject: [PATCH 14/38] Update project.clj --- boot/pod/project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/pod/project.clj b/boot/pod/project.clj index 12c2f259..7078dfb4 100644 --- a/boot/pod/project.clj +++ b/boot/pod/project.clj @@ -16,7 +16,7 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[boot/base ~version :scope "provided"] - [boot/bootstrap "3.0.0-SNAPSHOT" :scope "provided"] + [boot/bootstrap "3.0.0-SNAPSHOT" :scope "compile"] [org.clojure/clojure "1.9.0" :scope "provided"] [org.tcrawley/dynapath "1.0.0" :scope "compile"] [org.projectodd.shimdandy/shimdandy-impl "1.2.0" :scope "compile"]]) From aadc90b6c7a814a33aa4ddff894afdb3c389c86a Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 14:51:52 -0700 Subject: [PATCH 15/38] bump version fix ns typo --- boot/pod/project.clj | 4 ++-- boot/pod/src/boot/pod.clj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/boot/pod/project.clj b/boot/pod/project.clj index 7078dfb4..c8873267 100644 --- a/boot/pod/project.clj +++ b/boot/pod/project.clj @@ -17,6 +17,6 @@ :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[boot/base ~version :scope "provided"] [boot/bootstrap "3.0.0-SNAPSHOT" :scope "compile"] - [org.clojure/clojure "1.9.0" :scope "provided"] + [org.clojure/clojure "1.10.0" :scope "provided"] [org.tcrawley/dynapath "1.0.0" :scope "compile"] - [org.projectodd.shimdandy/shimdandy-impl "1.2.0" :scope "compile"]]) + [org.projectodd.shimdandy/shimdandy-impl "1.2.1" :scope "compile"]]) diff --git a/boot/pod/src/boot/pod.clj b/boot/pod/src/boot/pod.clj index 003204e3..3c674737 100644 --- a/boot/pod/src/boot/pod.clj +++ b/boot/pod/src/boot/pod.clj @@ -9,8 +9,8 @@ [boot.from.io.aviso.exception :as ex] [clojure.java.io :as io] [dynapath.util :as dp] - [dynapath.dynamic-classpath :as cp]) - [bootstrap.config :as conf] + [dynapath.dynamic-classpath :as cp] + [bootstrap.config :as conf]) (:import [java.util.jar JarFile] [java.lang.ref WeakReference] From 26ce63cd8d70c65f77f60a90771749bc48299f57 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 14:52:46 -0700 Subject: [PATCH 16/38] fix ns typo --- boot/pod/src/boot/util.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj index 5ce894f4..0e0bcce8 100644 --- a/boot/pod/src/boot/util.clj +++ b/boot/pod/src/boot/util.clj @@ -7,9 +7,9 @@ [boot.file :as file] [boot.from.io.aviso.ansi :as ansi] [boot.from.io.aviso.exception :as pretty] - [boot.from.me.raynes.conch :as conch]) + [boot.from.me.raynes.conch :as conch] [bootstrap.config :as conf] - [boot.host :as host] + [boot.host :as host]) (:import [java.io File] [java.nio ByteBuffer] @@ -254,7 +254,7 @@ is missing." [binding & body] (let [[ks m] [(butlast binding) (last binding)] - req-ks (set (map keyword ks)) ] + req-ks (set (map keyword ks))] `(if-let [dif-ks# (not-empty (set/difference ~req-ks (set (keys ~m))))] (throw (new AssertionError (apply format "missing key(s): %s" dif-ks#))) (let [{:keys ~ks} ~m] ~@body)))) From 8812148263d1f123b07e58aa977ba16dab16cffe Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 14:59:23 -0700 Subject: [PATCH 17/38] fix typos --- boot/pod/src/boot/file.clj | 22 +++++++++++----------- boot/pod/src/boot/gpg.clj | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/boot/pod/src/boot/file.clj b/boot/pod/src/boot/file.clj index 756de108..cd75ec2c 100644 --- a/boot/pod/src/boot/file.clj +++ b/boot/pod/src/boot/file.clj @@ -1,17 +1,17 @@ (ns boot.file (:require - [clojure.java.io :as io] - [clojure.set :as set] - [clojure.data :as data] - [boot.from.digest :as digest] - [boot.host :as host] - [clojure.string :as str]) + [clojure.java.io :as io] + [clojure.set :as set] + [clojure.data :as data] + [boot.from.digest :as digest] + [boot.host :as host] + [clojure.string :as str]) (:import - [java.net URI] - [java.io File] - [java.lang.management ManagementFactory] - [java.nio.file Files StandardCopyOption FileVisitOption] - [java.nio.file.attribute FileAttribute PosixFilePermissions]) + [java.net URI] + [java.io File] + [java.lang.management ManagementFactory] + [java.nio.file Files StandardCopyOption FileVisitOption] + [java.nio.file.attribute FileAttribute PosixFilePermissions]) (:refer-clojure :exclude [sync name file-seq])) (set! *warn-on-reflection* true) diff --git a/boot/pod/src/boot/gpg.clj b/boot/pod/src/boot/gpg.clj index 1e67e52e..573fbc10 100644 --- a/boot/pod/src/boot/gpg.clj +++ b/boot/pod/src/boot/gpg.clj @@ -3,8 +3,8 @@ [clojure.java.io :as io] [clojure.java.shell :as shell] [boot.pod :as pod] - [boot.util :as util]) - [bootstrap.config :as conf] + [boot.util :as util] + [bootstrap.config :as conf]) (:import [java.io StringReader File])) (defn ^{:boot/from :technomancy/leiningen} gpg-program @@ -76,7 +76,7 @@ pomfile (doto (File/createTempFile "pom" ".xml") (.deleteOnExit) (spit (pod/pom-xml jarfile pompath))) - pomout (io/file outdir (.replaceAll jarname "\\.jar$" ".pom.asc")) ] + pomout (io/file outdir (.replaceAll jarname "\\.jar$" ".pom.asc"))] (spit pomout (sign-it pomfile gpg-options)) [[:extension "pom.asc"] (.getPath pomout)]))) From 008592b835bb617243b3f3fde7ed4d4437bb48d3 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 15:04:08 -0700 Subject: [PATCH 18/38] move boot.host --- boot/{core => pod}/src/boot/host.clj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename boot/{core => pod}/src/boot/host.clj (100%) diff --git a/boot/core/src/boot/host.clj b/boot/pod/src/boot/host.clj similarity index 100% rename from boot/core/src/boot/host.clj rename to boot/pod/src/boot/host.clj From c901855df720bf5e7af9ee66963d7dfb69c1110c Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 10 Feb 2019 16:06:37 -0700 Subject: [PATCH 19/38] Update util.clj --- boot/pod/src/boot/util.clj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj index 0e0bcce8..e4ffa4f8 100644 --- a/boot/pod/src/boot/util.clj +++ b/boot/pod/src/boot/util.clj @@ -42,10 +42,8 @@ either '1' or 'yes' or 'true' to enable it; any other value disables colorization." [] - (let [value (:boot-color (conf/config))] - (if-not (string/blank? value) - (#{"1" "yes" "true"} (string/lower-case value)) - (not (host/windows?))))) + (if (#{"1" "yes" "true" true} (:boot-color (conf/config))) true + (not (host/windows?)))) (def ^:dynamic *verbosity* "Atom containing the verbosity level, 1 is lowest, 3 highest. Level 2 From 10d780741f9d2788cfeeabf0066f362f750bf303 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Mon, 11 Feb 2019 00:20:12 -0700 Subject: [PATCH 20/38] start rewriting boot.app in clojure --- boot/base/project.clj | 4 ++- boot/base/src/boot/app.clj | 63 +++++++++++++++++++++++++++++++++++++ boot/core/src/boot/main.clj | 2 -- boot/worker/build.boot | 11 +++---- 4 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 boot/base/src/boot/app.clj diff --git a/boot/base/project.clj b/boot/base/project.clj index 2cc8a49d..9d86af81 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -16,5 +16,7 @@ ["sonatype-snaps" {:url "https://oss.sonatype.org/content/repositories/snapshots"}]] :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.projectodd.shimdandy/shimdandy-api "1.2.1" :scope "compile"] + :dependencies [[org.clojure/clojure "1.9.0" :scope "provided"] + [boot/bootstrap "3.0.0-SNAPSHOT" :scope "compile"] + [org.projectodd.shimdandy/shimdandy-api "1.2.1" :scope "compile"] [junit/junit "3.8.1" :scope "test"]]) diff --git a/boot/base/src/boot/app.clj b/boot/base/src/boot/app.clj new file mode 100644 index 00000000..4ebb6a53 --- /dev/null +++ b/boot/base/src/boot/app.clj @@ -0,0 +1,63 @@ +(ns boot.app + (:require [clojure.java.io :as io] + [bootstrap.config :as conf]) + (:import [java.net URLClassLoader] + [java.util.concurrent Executors] + [org.projectodd.shimdandy ClojureRuntimeShim]) + (:gen-class)) + +(defn- invoke-hooks [runtime hooks] + (reduce #(when (.exists %2) (.invoke %1 "clojure.core/load-file" (.getPath %2)) %1) runtime hooks)) + +(def ^:private pods (atom [])) + +(defn- mkshim [name exec data jars] + (let [urls (map #(.toURL (.toURI %)) jars) + classldr (URLClassLoader. urls (ClassLoader/getPlatformClassLoader)) + runtime (ClojureRuntimeShim/newRuntime classldr) + hooks [(io/file (conf/boot-dir) "boot-shim.clj") (io/file "boot-shim.clj")]] + (doto runtime + (.setName (or name "anonymous")) + (invoke-hooks hooks) + (.require "boot.pod") + (.invoke "boot.pod/seal-app-classloader") + (.invoke "boot.pod/extend-addable-classloader") + (.invoke "boot.pod/set-data!" data) + (.invoke "boot.pod/set-pods!" pods) + (.invoke "boot.pod/set-this-pod!" runtime) + #(swap! pods conj %)))) + +(defn- set-pod-repo! [pod repo] + (if-not repo pod + (doto (.get pod) + (.require "boot.aether") + (.invoke "boot.aether/set-local-repo!" repo)))) + +(def ^:private pid (atom 0)) + +(defn- run-boot [corepod workerpod args] + (try + (let [repo (:boot-local-repo (conf/config) "default") + core (.get @corepod) + worker (set-pod-repo! @workerpod repo) + pid (and (swap! pid inc) @pid) + hooks (atom [])] + (doto core + (.require "boot.main") + (.invoke "boot.main/-main" pid worker hooks args)) + -1) + (catch Throwable t + (println "Boot failed to start:" + (if (instance? t Throwable/Exit) (.parseInt (.getMessage t)) + (and (.printStackTrace t) -2)))) + (finally + (doseq [hook hooks] @hook) + (.close core)))) + +(defn -main [& args] + (let [exec (Executors/newCachedThreadPool) + shutdown (future (.shutdown exec)) + corepod (future (mkshim "core" exec nil corejars)) + workerpod (future (mkshim "worker" exec nil workerjars))] + (.addShutdownHook (Runtime/getRuntime) (fn [] @shutdown)) + (System/exit (run-boot corepod workerpod args)))) diff --git a/boot/core/src/boot/main.clj b/boot/core/src/boot/main.clj index 6f8d7737..ee0b2184 100644 --- a/boot/core/src/boot/main.clj +++ b/boot/core/src/boot/main.clj @@ -201,8 +201,6 @@ (when (:boot-script opts) (util/exit-ok (print scriptstr))) - (when (:version opts) (util/exit-ok (boot.App/printVersion))) - (reset! core/bootignore (parse-bootignore (io/file ".bootignore"))) (#'core/init!) diff --git a/boot/worker/build.boot b/boot/worker/build.boot index 7d6d84c9..e8c0c56d 100644 --- a/boot/worker/build.boot +++ b/boot/worker/build.boot @@ -19,10 +19,9 @@ (require '[metosin.boot-alt-test :refer [alt-test]]) -(import boot.App) -(deftask test [] - (comp - (with-pass-thru [fs] - (boot.util/info "Testing against version %s\n" (App/config "BOOT_VERSION"))) - (alt-test))) +;(deftask test [] +; (comp +; (with-pass-thru [fs] +; (boot.util/info "Testing against version %s\n" (App/config "BOOT_VERSION")) +; (alt-test)) From 59109919f613d06475e93fa0022ce4d004a3b809 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Wed, 13 Feb 2019 12:48:57 -0700 Subject: [PATCH 21/38] wip --- boot/base/project.clj | 2 +- boot/base/src/boot/app.clj | 38 +++++++++++++++------------ boot/base/src/main/java/boot/App.java | 8 ------ 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/boot/base/project.clj b/boot/base/project.clj index 9d86af81..e9319d84 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -7,7 +7,7 @@ (defproject boot/base version :aot [#"^(?!boot\.repl-server).*$"] :jar-exclusions [#"^clojure/core/"] - :java-source-paths ["src/main/java"] + ;:java-source-paths ["src/main/java"] :description "Boot base module–this is the classloader shim." :url "https://github.com/boot-clj/boot" :scm {:url "https://github.com/boot-clj/boot.git" :dir "../../"} diff --git a/boot/base/src/boot/app.clj b/boot/base/src/boot/app.clj index 4ebb6a53..866d7a07 100644 --- a/boot/base/src/boot/app.clj +++ b/boot/base/src/boot/app.clj @@ -35,24 +35,28 @@ (def ^:private pid (atom 0)) +(defn Exit [code msg] + (ex-info msg {:error-code code})) + (defn- run-boot [corepod workerpod args] - (try - (let [repo (:boot-local-repo (conf/config) "default") - core (.get @corepod) - worker (set-pod-repo! @workerpod repo) - pid (and (swap! pid inc) @pid) - hooks (atom [])] - (doto core - (.require "boot.main") - (.invoke "boot.main/-main" pid worker hooks args)) - -1) - (catch Throwable t - (println "Boot failed to start:" - (if (instance? t Throwable/Exit) (.parseInt (.getMessage t)) - (and (.printStackTrace t) -2)))) - (finally - (doseq [hook hooks] @hook) - (.close core)))) + (let [hooks (atom []) + core (.get @corepod)] + (try + (let [repo (:boot-local-repo (conf/config) "default") + worker (set-pod-repo! @workerpod repo) + pid (and (swap! pid inc) @pid)] + (.require core "boot.main") + (.invoke core "boot.main/-main" pid worker hooks args) + -1) + (catch Throwable t + (println "Boot failed to start:") + (if-let [exdata (ex-data t)] + (:error-code exdata) + (and (.printStackTrace t) -2))) + (finally + (doseq [hook hooks] @hook) + (try (.close core) + (catch InterruptedException ie -3)))))) (defn -main [& args] (let [exec (Executors/newCachedThreadPool) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 84718911..9a00e758 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -83,14 +83,6 @@ public class App { tccl() throws Exception { return Thread.currentThread().getContextClassLoader(); } - public static File - bootdir() throws Exception { - File h = new File(System.getProperty("user.home")); - String a = System.getProperty("BOOT_HOME"); - String b = System.getenv("BOOT_HOME"); - String c = new File(h, ".boot").getCanonicalPath(); - return new File((a != null) ? a : ((b != null) ? b : c)); } - public static ClojureRuntimeShim newShim(String name, Object data, File[] jarFiles) throws Exception { URL[] urls = new URL[jarFiles.length]; From 60dbff2739659fd2eefc1e1c5a8c1e24b641803e Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:25:39 -0600 Subject: [PATCH 22/38] Update .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2d372135..8e4ba164 100644 --- a/.gitignore +++ b/.gitignore @@ -12,11 +12,11 @@ .installed .tested -### MAVEN (include pom.xml in /base) ########################################### +### MAVEN ########################################### *.jar *.war -#pom.xml +pom.xml pom.xml.asc ### NREPL ###################################################################### From 7332beaeebb4f872c8d2126e5f043e9ec1d0565c Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:26:35 -0600 Subject: [PATCH 23/38] wip --- boot/base/src/boot/{app.clj => app.clj_} | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) rename boot/base/src/boot/{app.clj => app.clj_} (73%) diff --git a/boot/base/src/boot/app.clj b/boot/base/src/boot/app.clj_ similarity index 73% rename from boot/base/src/boot/app.clj rename to boot/base/src/boot/app.clj_ index 866d7a07..9d9f5f03 100644 --- a/boot/base/src/boot/app.clj +++ b/boot/base/src/boot/app.clj_ @@ -33,6 +33,14 @@ (.require "boot.aether") (.invoke "boot.aether/set-local-repo!" repo)))) +(defn- resolve-dep-jars [shim sym] ;bootver cljname cljver] + (let [repo (:boot-local-repo (conf/config) "default")] + (doto shim + (.require "boot.aether") + (.invoke "boot.aether/set-local-repo!" repo) + (.invoke "boot.aether/update-always!") + (.invoke "boot.aether/resolve-dependency-jars" sym "3.0.0-SNAPSHOT" "org.clojure/clojure" "1.10.0")))) + (def ^:private pid (atom 0)) (defn Exit [code msg] @@ -59,9 +67,12 @@ (catch InterruptedException ie -3)))))) (defn -main [& args] - (let [exec (Executors/newCachedThreadPool) - shutdown (future (.shutdown exec)) - corepod (future (mkshim "core" exec nil corejars)) - workerpod (future (mkshim "worker" exec nil workerjars))] + (let [exec (Executors/newCachedThreadPool) + shutdown (future (.shutdown exec)) + aetherpod (future (mkshim "aether" exec nil "aether.uber.jar")) + corejars (resolve-dep-jars aetherpod "boot/core") + corepod (future (mkshim "core" exec nil corejars)) + workerjars (resolve-dep-jars aetherpod "boot/worker") + workerpod (future (mkshim "worker" exec nil workerjars))] (.addShutdownHook (Runtime/getRuntime) (fn [] @shutdown)) (System/exit (run-boot corepod workerpod args)))) From 5ea9ab78a0f00e14dc1f7da9fe72e9ac9ecba1f5 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:27:40 -0600 Subject: [PATCH 24/38] wip --- boot/base/project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/base/project.clj b/boot/base/project.clj index e9319d84..9d86af81 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -7,7 +7,7 @@ (defproject boot/base version :aot [#"^(?!boot\.repl-server).*$"] :jar-exclusions [#"^clojure/core/"] - ;:java-source-paths ["src/main/java"] + :java-source-paths ["src/main/java"] :description "Boot base module–this is the classloader shim." :url "https://github.com/boot-clj/boot" :scm {:url "https://github.com/boot-clj/boot.git" :dir "../../"} From 799da8e553f33473d88025cebb6db2c2702e279c Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:27:52 -0600 Subject: [PATCH 25/38] wip --- boot/core/project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/core/project.clj b/boot/core/project.clj index 52b8c4d2..000e7872 100644 --- a/boot/core/project.clj +++ b/boot/core/project.clj @@ -16,4 +16,4 @@ :dependencies [[org.clojure/clojure "1.9.0" :scope "provided"] [boot/base ~version :scope "provided"] [boot/pod ~version :scope "compile"] - [boot/boostrap "3.0.0-SNAPSHOT" :scope "provided"]]) + [boot/bootstrap "3.0.0-SNAPSHOT" :scope "provided"]]) From 9356b299256aa59c2db5087459d70a8f79424e6e Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:49:48 -0600 Subject: [PATCH 26/38] wip --- boot/pod/src/boot/util.clj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj index e4ffa4f8..b3825080 100644 --- a/boot/pod/src/boot/util.clj +++ b/boot/pod/src/boot/util.clj @@ -282,7 +282,7 @@ [& body] `(binding [*out* *err*] ~@body - (throw (boot.App$Exit. (str 1))))) + (throw (boot.app/Exit "Boot Error." (str 1))))) (defmacro exit-ok "Evaluates the body, and exits with non-zero status. @@ -296,11 +296,11 @@ [& body] `(try ~@body - (throw (boot.App$Exit. (str 0))) - (catch Throwable e# - (if (instance? boot.App$Exit e#) - (throw e#) - (exit-error (print-ex e#)))))) + (throw (boot.app/Exit "Boot OK." (str 0))))) + ;(catch Throwable e# + ;(if (instance? boot.App$Exit e#) + ; (throw e#)))) + ; (exit-error (print-ex e#))))) (defmacro with-err-str "Evaluates exprs in a context in which *err* is bound to a fresh StringWriter. From 11636479935f487af568b2603dabae36bf5e1d90 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:49:58 -0600 Subject: [PATCH 27/38] wip --- boot/core/build.boot | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/boot/core/build.boot b/boot/core/build.boot index 491a7ca9..23a95041 100644 --- a/boot/core/build.boot +++ b/boot/core/build.boot @@ -1,28 +1,28 @@ (set-env! :source-paths #{"src" "test"} - :dependencies '[[org.clojure/tools.reader "1.0.0-alpha2"] - [metosin/boot-alt-test "0.3.2" :scope "test"]]) + :dependencies '[[org.clojure/tools.reader "1.0.0-alpha2"]]) + ;[metosin/boot-alt-test "0.3.2" :scope "test"]]) -(ns-unmap 'boot.user 'test) +;(ns-unmap 'boot.user 'test) -(require '[boot.test :refer [runtests test-report test-exit]] - '[metosin.boot-alt-test :refer [alt-test]] - 'boot.test-test) +;(require '[boot.test :refer [runtests test-report test-exit]] +; '[metosin.boot-alt-test :refer [alt-test]] +; 'boot.test-test) -(import boot.App) +;(import boot.App) -(deftask integration-test [] - (comp - (runtests) - (test-report) - (test-exit))) +;(deftask integration-test [] +; (comp +; (runtests) +; (test-report) +; (test-exit)) -(deftask unit-test [] - (alt-test :test-matcher #"boot\.cli-test")) +;(deftask unit-test [] +; (alt-test :test-matcher #"boot\.cli-test")) -(deftask test [] - (comp - (with-pass-thru [fs] - (boot.util/info "Testing against version %s\n" (App/config "BOOT_VERSION"))) - (unit-test) - (integration-test))) +;(deftask test [] +; (comp +; (with-pass-thru [fs] +; (boot.util/info "Testing against version %s\n" (App/config "BOOT_VERSION")) +; (unit-test) +; (integration-test)) From 13b644d95633b59d5b4a11e523458ab9d719c797 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:50:15 -0600 Subject: [PATCH 28/38] wip --- boot/core/src/boot/core.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boot/core/src/boot/core.clj b/boot/core/src/boot/core.clj index 184728c5..74a88e65 100644 --- a/boot/core/src/boot/core.clj +++ b/boot/core/src/boot/core.clj @@ -20,7 +20,7 @@ [boot.from.backtick :as bt] [bootstrap.config :as conf]) (:import - [boot App] + ;[boot App] [java.io File] [java.nio.file Path Paths] [java.net URLClassLoader URL] @@ -46,7 +46,7 @@ .getCanonicalFile file/split-path rest - (apply io/file (App/getBootDir) "cache" "tmp") + (apply io/file (conf/boot-dir) "cache" "tmp") tmp/registry tmp/init! delay)) @@ -368,7 +368,7 @@ .getCanonicalFile file/split-path (when-not global) - (into [(App/getBootDir) "cache" "cache" (if global "global" "project")]) + (into [(conf/boot-dir) "cache" "cache" (if global "global" "project")]) (#(into % ((juxt namespace name) key))) (apply io/file) (#(doto % .mkdirs)))) From 4538652b63b691bad0b9108380f7d6f049eea898 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:50:24 -0600 Subject: [PATCH 29/38] wip --- boot/core/src/boot/main.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/boot/core/src/boot/main.clj b/boot/core/src/boot/main.clj index ee0b2184..392b72c7 100644 --- a/boot/core/src/boot/main.clj +++ b/boot/core/src/boot/main.clj @@ -1,6 +1,6 @@ (ns boot.main - (:import - [boot App]) + ;(:import + ; [boot App] (:require [clojure.java.io :as io] [clojure.string :as string] @@ -130,7 +130,7 @@ (let [[arg0 args args*] (if (seq args*) [arg0 args args*] ["--help" nil ["--help"]]) - bootscript (App/config "BOOT_FILE" "build.boot") + bootscript (:boot-file (conf/config) "build.boot") exists? #(when (.isFile (io/file %)) %) have-bootscript? (exists? bootscript) [arg0 args] (cond @@ -183,7 +183,7 @@ (util/warn "** WARNING: ~/.profile.boot is deprecated.\n") (util/warn "** Please use $BOOT_HOME/profile.boot instead.\n") (util/warn "** See: https://github.com/boot-clj/boot/issues/157\n"))) - userscript (or userscript (exists? (io/file (App/getBootDir) "profile.boot"))) + userscript (or userscript (exists? (io/file (conf/boot-dir) "profile.boot"))) localscript (exists? (io/file "profile.boot")) profile? (not (:no-profile opts)) bootstr (some->> arg0 slurp) From b9157b8ed7c0ca39dc8a9a50510b43a3d448988d Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 12:50:34 -0600 Subject: [PATCH 30/38] disable testing --- boot/core/src/boot/{test.clj => test.clj_} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename boot/core/src/boot/{test.clj => test.clj_} (100%) diff --git a/boot/core/src/boot/test.clj b/boot/core/src/boot/test.clj_ similarity index 100% rename from boot/core/src/boot/test.clj rename to boot/core/src/boot/test.clj_ From 3bd19c7a9d93f234ded375e855d78bde3e6743c0 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 13:36:37 -0600 Subject: [PATCH 31/38] remove boot-shim --- boot/base/src/main/java/boot/App.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 9a00e758..718ae803 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -94,7 +94,7 @@ public class App { rt.setName(name != null ? name : "anonymous"); - File[] hooks = {new File(bootdir(), "boot-shim.clj"), new File("boot-shim.clj")}; + File[] hooks = {}; for (File hook : hooks) if (hook.exists()) From deca6a4ac67080ce25aeca37bb0501c7c1d8f505 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 13:44:42 -0600 Subject: [PATCH 32/38] restore stash --- boot/base/src/main/java/boot/App.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index 718ae803..e864d62e 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -53,11 +53,21 @@ public class App { public static String getBootVersion() { return bootversion; } public static String getClojureName() { return cljname; } + private static final ConcurrentHashMap stash = new ConcurrentHashMap<>(); private static final WeakHashMap pods = new WeakHashMap<>(); public static WeakHashMap getPods() { return pods; } + public static Object + getStash(String key) throws Exception { return stash.remove(key); } + + public static String + setStash(Object value) throws Exception { + String key = UUID.randomUUID().toString(); + stash.put(key, value); + return key; } + public static class Exit extends Exception { public Exit(String m) { super(m); } From eee3ed2d5b7e7e5e5371de201e9e1cceceeaef50 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 13:46:03 -0600 Subject: [PATCH 33/38] restore newPod --- boot/base/src/main/java/boot/App.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index e864d62e..f841eeda 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -120,6 +120,19 @@ public class App { pods.put(rt, new Object()); return rt; } + public static ClojureRuntimeShim + newPod(String name, Object data) throws Exception { + return newShim(name, data, podjars); } + + public static ClojureRuntimeShim + newPod(String name, Object data, File[] jarFiles) throws Exception { + File[] files = new File[jarFiles.length + podjars.length]; + + for (int i=0; i Date: Sun, 14 Apr 2019 13:52:24 -0600 Subject: [PATCH 34/38] restore boot.app --- boot/base/src/boot/{app.clj_ => app.clj} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename boot/base/src/boot/{app.clj_ => app.clj} (100%) diff --git a/boot/base/src/boot/app.clj_ b/boot/base/src/boot/app.clj similarity index 100% rename from boot/base/src/boot/app.clj_ rename to boot/base/src/boot/app.clj From 5959142f415264ad6bc271357a1cf96d87a17882 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 13:57:10 -0600 Subject: [PATCH 35/38] add clojure to source paths --- boot/base/project.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/boot/base/project.clj b/boot/base/project.clj index 9d86af81..6256cd50 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -8,6 +8,7 @@ :aot [#"^(?!boot\.repl-server).*$"] :jar-exclusions [#"^clojure/core/"] :java-source-paths ["src/main/java"] + :source-paths ["src"] :description "Boot base module–this is the classloader shim." :url "https://github.com/boot-clj/boot" :scm {:url "https://github.com/boot-clj/boot.git" :dir "../../"} From c9511617841c322659baf4cd0643d51a2b0670d9 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 13:59:02 -0600 Subject: [PATCH 36/38] update cojure source location --- boot/base/project.clj | 2 +- boot/base/src/{ => main/clojure}/boot/app.clj | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename boot/base/src/{ => main/clojure}/boot/app.clj (100%) diff --git a/boot/base/project.clj b/boot/base/project.clj index 6256cd50..b7d2f3b6 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -8,7 +8,7 @@ :aot [#"^(?!boot\.repl-server).*$"] :jar-exclusions [#"^clojure/core/"] :java-source-paths ["src/main/java"] - :source-paths ["src"] + :source-paths ["src/main/clojure"] :description "Boot base module–this is the classloader shim." :url "https://github.com/boot-clj/boot" :scm {:url "https://github.com/boot-clj/boot.git" :dir "../../"} diff --git a/boot/base/src/boot/app.clj b/boot/base/src/main/clojure/boot/app.clj similarity index 100% rename from boot/base/src/boot/app.clj rename to boot/base/src/main/clojure/boot/app.clj From 1bdf7d33fb9dc755aee915d83eee15f4b5345515 Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 14:18:42 -0600 Subject: [PATCH 37/38] restore working boot --- boot/base/project.clj | 1 - .../boot/app.clj => core/src/boot/app.clj_} | 0 boot/core/src/boot/parallel.clj | 9 +++++---- boot/pod/src/boot/util.clj | 14 ++++---------- 4 files changed, 9 insertions(+), 15 deletions(-) rename boot/{base/src/main/clojure/boot/app.clj => core/src/boot/app.clj_} (100%) diff --git a/boot/base/project.clj b/boot/base/project.clj index b7d2f3b6..9d86af81 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -8,7 +8,6 @@ :aot [#"^(?!boot\.repl-server).*$"] :jar-exclusions [#"^clojure/core/"] :java-source-paths ["src/main/java"] - :source-paths ["src/main/clojure"] :description "Boot base module–this is the classloader shim." :url "https://github.com/boot-clj/boot" :scm {:url "https://github.com/boot-clj/boot.git" :dir "../../"} diff --git a/boot/base/src/main/clojure/boot/app.clj b/boot/core/src/boot/app.clj_ similarity index 100% rename from boot/base/src/main/clojure/boot/app.clj rename to boot/core/src/boot/app.clj_ diff --git a/boot/core/src/boot/parallel.clj b/boot/core/src/boot/parallel.clj index 55a122b3..2cb1e1e8 100644 --- a/boot/core/src/boot/parallel.clj +++ b/boot/core/src/boot/parallel.clj @@ -6,8 +6,9 @@ [boot.util :as util] [boot.from.io.aviso.exception :as ex]) (:import - [java.util HashMap Collections] - [java.util.concurrent CountDownLatch TimeUnit])) + [boot App] + [java.util HashMap Collections] + [java.util.concurrent CountDownLatch TimeUnit])) ;; AR we might need also to modify the map when a task/batch/computation ;; finishes. However, I might overengineer a bit and therefore I am leaving @@ -61,14 +62,14 @@ The first item of the vector is timeout, the second unit"} Clojure objects won't work)." [a args ARG [str] "The boot cli arguments." d data OBJECT ^:! code "The data to pass the (new) boot environment"] - (let [core (boot.App/newCore data) + (let [core (App/newCore data) worker (future pod/worker-pod) args (-> (vec (remove empty? args)) (->> (into-array String)))] (util/dbug "Runboot will run %s \n" (str "\"boot " (string/join " " args) "\"")) (core/with-pass-thru [fs] (future (try (.await (get pod/data "start-latch")) - (boot.App/runBoot core worker (into-array String (into ["-x"] args))) + (App/runBoot core worker (into-array String (into ["-x"] args))) (catch InterruptedException e (util/print-ex e)) (catch Throwable e diff --git a/boot/pod/src/boot/util.clj b/boot/pod/src/boot/util.clj index b3825080..019da479 100644 --- a/boot/pod/src/boot/util.clj +++ b/boot/pod/src/boot/util.clj @@ -277,12 +277,11 @@ * This is the preferred method for returning an exit code != 0, this method returns 1. * This macro does not call System.exit(), because this instance of boot - may be nested in another boot instance. Instead a special method on boot.App - is called which handles the exit behavior (calling shutdown hooks etc.)." + may be nested in another boot instance." [& body] `(binding [*out* *err*] ~@body - (throw (boot.app/Exit "Boot Error." (str 1))))) + (throw (Exception. "Boot Error." (str 1))))) (defmacro exit-ok "Evaluates the body, and exits with non-zero status. @@ -291,16 +290,11 @@ * Boot's main explicitly wraps user tasks in exit-ok so that in general it is not necessary to call it for exiting with 0. * This macro does not call System.exit(), because this instance of boot - may be nested in another boot instance. Instead a special method on boot.App - is called which handles the exit behavior (calling shutdown hooks etc.)." + may be nested in another boot instance." [& body] `(try ~@body - (throw (boot.app/Exit "Boot OK." (str 0))))) - ;(catch Throwable e# - ;(if (instance? boot.App$Exit e#) - ; (throw e#)))) - ; (exit-error (print-ex e#))))) + (throw (Exception. "Boot OK." (str 0))))) (defmacro with-err-str "Evaluates exprs in a context in which *err* is bound to a fresh StringWriter. From 701aa6411b625e7dccfa69928b57e4a4dd6e44cd Mon Sep 17 00:00:00 2001 From: Matthew Ratzke Date: Sun, 14 Apr 2019 15:05:28 -0600 Subject: [PATCH 38/38] wip --- boot.properties | 1 + boot/base/project.clj | 1 + boot/base/src/main/java/boot/App.java | 270 +++++++++++++++++- .../resources/boot/base/version.properties | 2 +- 4 files changed, 270 insertions(+), 4 deletions(-) diff --git a/boot.properties b/boot.properties index f7026cba..6852f6f1 100644 --- a/boot.properties +++ b/boot.properties @@ -1 +1,2 @@ +BOOT_VERSION=3.0.0-SNAPSHOT BOOT_AS_ROOT=yes diff --git a/boot/base/project.clj b/boot/base/project.clj index 9d86af81..9f76db49 100644 --- a/boot/base/project.clj +++ b/boot/base/project.clj @@ -8,6 +8,7 @@ :aot [#"^(?!boot\.repl-server).*$"] :jar-exclusions [#"^clojure/core/"] :java-source-paths ["src/main/java"] + :resource-paths ["src/main/resources"] :description "Boot base module–this is the classloader shim." :url "https://github.com/boot-clj/boot" :scm {:url "https://github.com/boot-clj/boot.git" :dir "../../"} diff --git a/boot/base/src/main/java/boot/App.java b/boot/base/src/main/java/boot/App.java index f841eeda..1ea86736 100644 --- a/boot/base/src/main/java/boot/App.java +++ b/boot/base/src/main/java/boot/App.java @@ -53,8 +53,8 @@ public class App { public static String getBootVersion() { return bootversion; } public static String getClojureName() { return cljname; } - private static final ConcurrentHashMap stash = new ConcurrentHashMap<>(); private static final WeakHashMap pods = new WeakHashMap<>(); + private static final ConcurrentHashMap stash = new ConcurrentHashMap<>(); public static WeakHashMap getPods() { return pods; } @@ -77,6 +77,14 @@ public class App { nextId() { return counter.addAndGet(1); } + public static File + getBootDir() throws Exception { + return bootdir(); } + + public static boolean + isWindows() throws Exception { + return (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0); } + public static File mkFile(File parent, String... kids) throws Exception { File ret = parent; @@ -93,6 +101,212 @@ public class App { tccl() throws Exception { return Thread.currentThread().getContextClassLoader(); } + public static InputStream + resource(String path) throws Exception { + return tccl().getResourceAsStream(path); } + + public static Properties + propertiesResource(String path) throws Exception { + Properties p = new Properties(); + try (InputStream is = resource(path)) { p.load(is); } + return p; } + + public static File + bootdir() throws Exception { + File h = new File(System.getProperty("user.home")); + String a = System.getProperty("BOOT_HOME"); + String b = System.getenv("BOOT_HOME"); + String c = new File(h, ".boot").getCanonicalPath(); + return new File((a != null) ? a : ((b != null) ? b : c)); } + + public static String + md5hash(String data) throws Exception { + java.security.MessageDigest algo = java.security.MessageDigest.getInstance("MD5"); + return renderAsHex(algo.digest(data.getBytes())); } + + private static String + renderAsHex(byte[] content) { + Formatter formatter = new Formatter(); + for (byte b : content) { + formatter.format("%02X", b); + } + return formatter.toString(); } + + public static File + projectDir() throws Exception { + for (File f = workdir; f != null; f = f.getParentFile()) { + File tmp = new File(f, ".git"); + if (tmp.exists() && tmp.isDirectory()) return f; } + return null; } + + public static HashMap + properties2map(Properties p) throws Exception { + HashMap m = new HashMap<>(); + for (Map.Entry e : p.entrySet()) + m.put((String) e.getKey(), (String) e.getValue()); + return m; } + + public static Properties + map2properties(HashMap m) throws Exception { + Properties p = new Properties(); + for (Map.Entry e : m.entrySet()) + p.setProperty(e.getKey(), e.getValue()); + return p; } + + public static HashMap + propertiesFiles() throws Exception { + HashMap ret = new HashMap<>(); + String[] names = new String[]{"boot", "project", "cwd"}; + File[] dirs = new File[]{bootdir(), projectDir(), workdir}; + for (int i = 0; i < dirs.length; i++) + ret.put(names[i], new File(dirs[i], "boot.properties")); + return ret; } + + public static Properties + mergeProperties() throws Exception { + Properties p = new Properties(); + HashMap fs = propertiesFiles(); + for (String k : new String[]{"boot", "project", "cwd"}) + try (FileInputStream is = new FileInputStream(fs.get(k))) { + p.load(is); } + catch (FileNotFoundException e) {} + return p; } + + public static void + setDefaultProperty(Properties p, String k, String dfl) throws Exception { + if (p.getProperty(k) == null) p.setProperty(k, dfl); } + + public static HashMap + config() throws Exception { + HashMap ret = new HashMap<>(); + + ret.putAll(properties2map(mergeProperties())); + ret.remove("BOOT_HOME"); + ret.putAll(System.getenv()); + ret.putAll(properties2map(System.getProperties())); + + Iterator i = ret.keySet().iterator(); + while (i.hasNext()) { + String k = i.next(); + if (! k.startsWith("BOOT_")) i.remove(); } + + return ret; } + + public static String + config(String k) throws Exception { + return config().get(k); } + + public static String + config(String k, String dfl) throws Exception { + String v = config(k); + if (v != null) return v; + else { System.setProperty(k, dfl); return dfl; }} + + private static String + jarVersion(File f) throws Exception { + String ret = null; + JarEntry e = null; + String pat = "META-INF/maven/boot/boot/pom.properties"; + try (JarFile jar = new JarFile(f)) { + if ((e = jar.getJarEntry(pat)) != null) { + try (InputStream is = jar.getInputStream(e)) { + Properties p = new Properties(); + p.load(is); + ret = p.getProperty("version"); }}} + return ret; } + + private static Properties + writeProps(File f) throws Exception { + mkParents(f); + ClojureRuntimeShim a = aetherShim(); + Properties p = new Properties(); + String c = cljversion; + String n = cljname; + String t = null; + + try (FileInputStream is = new FileInputStream(f)) { + p.load(is); } + catch (FileNotFoundException e) {} + + if (bootversion == null) + for (File x : resolveDepJars(a, "boot", channel, n, c)) + if (null != (t = jarVersion(x))) bootversion = t; + + p.setProperty("BOOT_VERSION", bootversion); + setDefaultProperty(p, "BOOT_CLOJURE_NAME", n); + setDefaultProperty(p, "BOOT_CLOJURE_VERSION", c); + + try (FileOutputStream os = new FileOutputStream(f)) { + p.store(os, booturl); } + + return p; } + + private static Properties + readProps(File f, boolean create) throws Exception { + mkParents(f); + FileLock lock = null; + Properties p = new Properties(); + + if (!isWindows() && f.exists()) + lock = (new RandomAccessFile(f, "rw")).getChannel().lock(); + + try (FileInputStream is = new FileInputStream(f)) { + p.load(is); + if (p.getProperty("BOOT_CLOJURE_VERSION") == null + || p.getProperty("BOOT_VERSION") == null) + throw new Exception("missing info"); + return p; } + catch (Throwable e) { + if (! create) return null; + else return writeProps(f); } + finally { if (lock != null) lock.release(); }} + + private static HashMap + seedCache() throws Exception { + if (depsCache != null) return depsCache; + else { + ClojureRuntimeShim a = aetherShim(); + + HashMap cache = new HashMap<>(); + + cache.put("boot/pod", resolveDepJars(a, "boot/pod")); + cache.put("boot/core", resolveDepJars(a, "boot/core")); + cache.put("boot/worker", resolveDepJars(a, "boot/worker")); + + return depsCache = cache; }} + + private static Object + validateCache(File f, Object cache) throws Exception { + for (File[] fs : ((HashMap) cache).values()) + for (File d : fs) + if (! d.exists() || f.lastModified() < d.lastModified()) + throw new Exception("dep jar doesn't exist"); + return cache; } + + private static Object + writeCache(File f, Object m) throws Exception { + mkParents(f); + try (FileOutputStream os = new FileOutputStream(f); + ObjectOutputStream oos = new ObjectOutputStream(os)) { + oos.writeObject(m); } + return m; } + + private static Object + readCache(File f) throws Exception { + mkParents(f); + FileLock lock = null; + if (!isWindows()) + lock = (new RandomAccessFile(f, "rw")).getChannel().lock(); + try { + long max = 18 * 60 * 60 * 1000; + long age = System.currentTimeMillis() - f.lastModified(); + if (age > max) throw new Exception("cache age exceeds TTL"); + try (FileInputStream is = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(is)) { + return validateCache(f, ois.readObject()); }} + catch (Throwable e) { return writeCache(f, seedCache()); } + finally { if (lock != null) lock.release(); }} + public static ClojureRuntimeShim newShim(String name, Object data, File[] jarFiles) throws Exception { URL[] urls = new URL[jarFiles.length]; @@ -104,7 +318,7 @@ public class App { rt.setName(name != null ? name : "anonymous"); - File[] hooks = {}; + File[] hooks = {new File(bootdir(), "boot-shim.clj"), new File("boot-shim.clj")}; for (File hook : hooks) if (hook.exists()) @@ -145,7 +359,7 @@ public class App { mkParents(outfile); int n = 0; byte[] buf = new byte[4096]; - try (InputStream in = tccl().getResourceAsStream(resource); + try (InputStream in = resource(resource); OutputStream out = new FileOutputStream(outfile)) { while ((n = in.read(buf)) > 0) out.write(buf, 0, n); }} @@ -202,9 +416,59 @@ public class App { try { core.get().close(); } catch (InterruptedException ie) {}}} + public static void + printVersion() throws Exception { + Properties p = new Properties(); + p.setProperty("BOOT_VERSION", config("BOOT_VERSION")); + p.setProperty("BOOT_CLOJURE_NAME", config("BOOT_CLOJURE_NAME")); + p.setProperty("BOOT_CLOJURE_VERSION", config("BOOT_CLOJURE_VERSION")); + p.store(System.out, booturl); } + + public static void + updateBoot(File bootprops, String version, String chan) throws Exception { + update_always = true; + bootversion = version; + channel = chan; + Properties p = writeProps(bootprops); + p.store(System.out, booturl); } + public static void main(String[] args) throws Exception { + String asroot = config("BOOT_AS_ROOT", "no"); + if (System.getProperty("user.name").equals("root") + && ! (asroot.equals("yes") || asroot.equals("1") || asroot.equals("true"))) + throw new Exception("refusing to run as root (set BOOT_AS_ROOT=yes to force)"); + + File cachehome = mkFile(bootdir(), "cache"); + File bootprops = mkFile(bootdir(), "boot.properties"); + File jardir = mkFile(cachehome, "lib", appversion); + File bootcache = mkFile(cachehome, "cache", "boot"); + + localrepo = config("BOOT_LOCAL_REPO"); + cljversion = config("BOOT_CLOJURE_VERSION", "1.8.0"); + cljname = config("BOOT_CLOJURE_NAME", "org.clojure/clojure"); + aetherfile = mkFile(cachehome, "lib", appversion, aetherjar); + + readProps(bootprops, true); + + String repo = (localrepo == null) + ? "default" + : md5hash((new File(localrepo)).getCanonicalFile().getPath()); + + File cachefile = mkFile(bootcache, repo, cljversion, bootversion, "deps.cache"); + HashMap cache = (HashMap) readCache(cachefile); + + podjars = cache.get("boot/pod"); + corejars = cache.get("boot/core"); + workerjars = cache.get("boot/worker"); Thread shutdown = new Thread() { public void run() { ex.shutdown(); }}; Runtime.getRuntime().addShutdownHook(shutdown); System.exit(runBoot(newCore(null), newWorker(), args)); }} + +// public static void +// main(String[] args) throws Exception { + +// Thread shutdown = new Thread() { public void run() { ex.shutdown(); }}; +// Runtime.getRuntime().addShutdownHook(shutdown); +// System.exit(runBoot(newCore(null), newWorker(), args)); }} diff --git a/boot/base/src/main/resources/boot/base/version.properties b/boot/base/src/main/resources/boot/base/version.properties index 5feebe97..cd92d6b0 100644 --- a/boot/base/src/main/resources/boot/base/version.properties +++ b/boot/base/src/main/resources/boot/base/version.properties @@ -1 +1 @@ -version=${pom.version} \ No newline at end of file +version=3.0.0-SNAPSHOT