-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation of dirac.main
- Loading branch information
Showing
47 changed files
with
1,641 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
log4j.rootLogger=DEBUG, console | ||
log4j.appender.console=org.apache.log4j.ConsoleAppender | ||
log4j.appender.console.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.console.layout.ConversionPattern=%-5p %c: %m%n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# this script tries to launch dirac.main from command line | ||
# | ||
# usage ./main-launcher.sh [args] | ||
# | ||
|
||
set -e | ||
|
||
VERSION=${DIRAC_MAIN_VERSION:-LATEST} # e.g. 0.1.0 or LATEST | ||
GROUP=${DIRAC_MAIN_GROUP:-binaryage} | ||
ARTIFACT=${DIRAC_MAIN_ARTIFACT:-dirac} | ||
|
||
DIRAC_DEP=${DIRAC_MAIN_DIRAC_DEP:-"{$GROUP/$ARTIFACT {:mvn/version \"$VERSION\"}}"} | ||
DEPS=${DIRAC_MAIN_DEPS:-"{:deps $DIRAC_DEP}"} | ||
CLI_NS=${DIRAC_MAIN_CLI_NS:-"dirac.main"} | ||
|
||
# $DEPS should be something like '{:deps {binaryage/dirac {:mvn/version "LATEST"}}}' | ||
set -x | ||
exec clojure -Sdeps "$DEPS" -m "$CLI_NS" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
# this script tries to launch dirac.main via lein | ||
# | ||
# usage ./main.sh [args] | ||
# | ||
|
||
set -e | ||
|
||
ARGS=() | ||
if [[ -t 1 ]] ; then | ||
# please note that lein run does some internal piping and prevents TTY detection, we have to force colors by hand | ||
# https://stackoverflow.com/a/29425613/84283 | ||
ARGS+=("--force-color") | ||
fi | ||
|
||
# set -x | ||
exec lein run -m dirac.main -- "${ARGS[@]}" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e -o pipefail | ||
# shellcheck source=_config.sh | ||
source "$(dirname "${BASH_SOURCE[0]}")/_config.sh" | ||
|
||
cd "$ROOT" | ||
|
||
export DIRAC_TEST_PLAYGROUND="$ROOT/test/playground" | ||
|
||
echo "Running CLI tests..." | ||
lein run-cli-tests-110 | ||
lein run-cli-tests-19 | ||
|
||
# because matcher-combinators.matchers uses some 1.9 apis | ||
#lein run-cli-tests-18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# this will run browser tests against fully optimized dirac extension (release build) | ||
|
||
set -e -o pipefail | ||
# shellcheck source=_config.sh | ||
source "$(dirname "${BASH_SOURCE[0]}")/_config.sh" | ||
|
||
redirect_to_test_stage_if_needed | ||
|
||
cd "$ROOT" | ||
|
||
./scripts/run-cli-tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(ns dirac.home | ||
(:require [dirac.home.locations :as locations])) | ||
|
||
(def get-home-dir-path locations/get-home-dir-path) | ||
|
||
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
(comment | ||
(get-home-dir-path) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(ns dirac.home.chromium | ||
(:require [dirac.home.chromium.scout :as scout] | ||
[dirac.home.chromium.link :as link] | ||
[dirac.home.chromium.profiles :as profiles] | ||
[dirac.home.defaults :as defaults] | ||
[dirac.home.chromium.extra-args :as extra-args] | ||
[dirac.home.chromium.mapping :as mapping] | ||
[dirac.home.locations :as locations])) | ||
|
||
(def find-chrome-executable scout/find-chrome-executable) | ||
(def determine-chrome-version scout/determine-chrome-version) | ||
|
||
(def chromium-link-exists? link/chromium-link-exists?) | ||
(def resolve-chromium-link link/resolve-chromium-link) | ||
|
||
(def resolve-dirac-release! mapping/resolve-dirac-release!) | ||
(def try-download-releases-file-if-needed! mapping/try-download-releases-file-if-needed!) | ||
|
||
(def get-chromium-profile-dir-path profiles/get-chromium-profile-dir-path) | ||
|
||
(def read-chromium-extra-args extra-args/read-chromium-extra-args) | ||
|
||
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
(comment | ||
(find-chrome-executable) | ||
(determine-chrome-version (find-chrome-executable)) | ||
(resolve-dirac-release! "81.1.4014.0" defaults/releases-file-url (locations/get-releases-file-path)) | ||
(read-chromium-extra-args) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns dirac.home.chromium.extra-args | ||
(:require [dirac.home.helpers :as helpers] | ||
[dirac.home.locations :as locations] | ||
[clojure.java.io :as io]) | ||
(:import (java.io File))) | ||
|
||
(def get-chromium-extra-args-file-path locations/get-chromium-extra-args-file-path) | ||
|
||
(defn read-chromium-extra-args | ||
([] (read-chromium-extra-args (get-chromium-extra-args-file-path))) | ||
([^File file] | ||
(let [file (io/file file)] | ||
(if (.exists file) | ||
(-> file | ||
(helpers/read-trimmed-lines) | ||
(helpers/filter-commented-lines)))))) | ||
|
||
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
(comment | ||
(get-chromium-extra-args-file-path) | ||
(read-chromium-extra-args) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(ns dirac.home.chromium.link | ||
(:require [clojure.java.io :as io] | ||
[clojure.string :as string] | ||
[dirac.home.helpers :as helpers] | ||
[dirac.home.locations :as locations])) | ||
|
||
(def get-chromium-link-path locations/get-chromium-link-path) | ||
|
||
(defn prepare-followed-paths-chain [paths] | ||
(string/join " -> " paths)) | ||
|
||
(defn explain-followed-paths [paths] | ||
(let [chain (prepare-followed-paths-chain paths)] | ||
(if-not (string/blank? chain) | ||
(str " Followed paths: '" chain "'.")))) | ||
|
||
; for users without filesystem links we support text files simulating links | ||
(defn follow-text-file-link [file] | ||
(let [target-path (helpers/read-and-trim-first-line file) | ||
target-file (io/file target-path)] | ||
(if (.isAbsolute target-file) | ||
(.getPath target-file) | ||
(let [parent-dir (.getParent file) | ||
target-file (io/file parent-dir target-path)] | ||
(.getPath target-file))))) | ||
|
||
(defn resolve-link | ||
"Try to resolve default chromium link file (or provided file) by following symlinks or textual links recursively. | ||
Stops when it finds an executable and returns {:executable [absolute-path]}. | ||
In case of a failure returns textual description {:failure [text]}. | ||
" | ||
([file-path] (resolve-link file-path [])) | ||
([file-path followed-paths] | ||
(try | ||
(let [file (io/file file-path)] | ||
(if-not (.exists file) | ||
(let [paths (dedupe followed-paths)] | ||
{:failure (str "File path '" (.getPath file) "' does not exist." (explain-followed-paths paths)) | ||
:paths (dedupe (conj paths (.getPath file)))}) | ||
(let [resolved-file (.getCanonicalFile file)] | ||
(if-not (.exists resolved-file) | ||
(let [paths (dedupe (conj followed-paths (.getPath file)))] | ||
{:failure (str "File path '" (.getPath resolved-file) "' does not exist." (explain-followed-paths paths)) | ||
:paths (dedupe (conj paths (.getPath resolved-file)))}) | ||
(let [paths (concat followed-paths [(.getPath file) (.getPath resolved-file)])] | ||
(if (.canExecute resolved-file) | ||
{:executable (.getAbsolutePath resolved-file) | ||
:paths (dedupe paths)} | ||
(resolve-link (follow-text-file-link resolved-file) paths))))))) | ||
(catch Exception e | ||
{:failure (str "Exception: " (.getMessage e))})))) | ||
|
||
(defn resolve-chromium-link | ||
([] (resolve-chromium-link (get-chromium-link-path))) | ||
([chromium-file] | ||
(resolve-link chromium-file))) | ||
|
||
(defn chromium-link-exists? [] | ||
(.exists (io/file (get-chromium-link-path)))) | ||
|
||
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
(comment | ||
(resolve-chromium-link) | ||
(chromium-link-exists?) | ||
(read-and-trim-first-line (io/file *file*)) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
(ns dirac.home.chromium.mapping | ||
(:require [clojure.java.io :as io] | ||
[dirac.home.helpers :as helpers] | ||
[dirac.home.locations :as locations] | ||
[dirac.home.chromium.version :as version] | ||
[clojure.tools.logging :as log] | ||
[dirac.home.defaults :as defaults]) | ||
(:import (java.io FileNotFoundException))) | ||
|
||
(def ^:dynamic *mock-releases*) | ||
|
||
(def get-releases-file-path locations/get-releases-file-path) | ||
|
||
(defn read-releases-file [file] | ||
(if (bound? #'*mock-releases*) | ||
*mock-releases* | ||
(helpers/read-edn file))) | ||
|
||
(defn lookup-dirac-release [chromium-mapping chromium-version] | ||
(let [version-keys (filter string? (keys chromium-mapping)) | ||
sorted-version-keys (sort version/compare-versions version-keys) | ||
match? (fn [v] (not= (version/compare-versions chromium-version v) -1)) | ||
resolved-version (last (filter match? sorted-version-keys))] | ||
(if (some? resolved-version) | ||
(get chromium-mapping resolved-version) | ||
(get chromium-mapping :unsupported)))) | ||
|
||
; -- public API ------------------------------------------------------------------------------------------------------------- | ||
|
||
(defn try-download-releases-file-if-needed! [releases-file-url releases-file-path] | ||
(when-not (bound? #'*mock-releases*) | ||
(try | ||
; TODO: implement Etag or caching | ||
(helpers/download! releases-file-url releases-file-path) | ||
(catch FileNotFoundException e | ||
(log/info (str "Unable to download '" releases-file-url "':\n" e)) | ||
(if (.exists (io/file releases-file-path)) | ||
(log/info (str "Using on-disk version from '" releases-file-path "' which might be outdated."))))))) | ||
|
||
(defn resolve-dirac-release! | ||
([chromium-version url releases-file-path] | ||
(try-download-releases-file-if-needed! url releases-file-path) | ||
(resolve-dirac-release! chromium-version releases-file-path)) | ||
([chromium-version releases-file] | ||
(let [releases (read-releases-file releases-file) | ||
chromium-mapping (:chromium releases) | ||
_ (assert chromium-mapping) | ||
release-descriptor (lookup-dirac-release chromium-mapping chromium-version)] | ||
(if (string? release-descriptor) | ||
release-descriptor | ||
(throw (ex-info (str "Unable to retrieve Dirac release for Chromium " chromium-version ".\n" | ||
"Reason: " (:message release-descriptor)) | ||
{:chromium-version chromium-version | ||
:release-descriptor release-descriptor})))))) | ||
|
||
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
(comment | ||
(get-releases-file-path) | ||
(try-download-releases-file-if-needed! defaults/releases-file-url (get-releases-file-path)) | ||
(read-releases-file (get-releases-file-path)) | ||
(let [mapping {"81.1.4014.0" "1.5.0" | ||
"81.0.4014.3" "1.4.7" | ||
"81.0.4014.1" "1.4.6" | ||
"81.0.4013.0" "1.4.5" | ||
:unsupported {:message "This chromium version is not supported."}}] | ||
[(lookup-dirac-release mapping "82.1.4010") ; => "1.5.0" | ||
(lookup-dirac-release mapping "81.1.4014") ; => "1.5.0" | ||
(lookup-dirac-release mapping "81.0.4016") ; => "1.4.7" | ||
(lookup-dirac-release mapping "81.0.4014.6") ; => "1.4.7" | ||
(lookup-dirac-release mapping "81.0.4014.3") ; => "1.4.7" | ||
(lookup-dirac-release mapping "81.0.4014.2") ; => "1.4.6" | ||
(lookup-dirac-release mapping "81.0.4014.1") ; => "1.4.6" | ||
(lookup-dirac-release mapping "81.0.4013.1") ; => "1.4.5" | ||
(lookup-dirac-release mapping "81.0.4012.0")] ; => :message | ||
) | ||
(binding [*mock-releases* {:chromium {"81.0.4014.0" "1.2.3"}}] | ||
(resolve-dirac-release! "81.0.4014.1")) | ||
(binding [*mock-releases* {:chromium {"81.0.4014.0" "1.2.3" | ||
:unsupported {:message "NOT SUPPORTED"}}}] | ||
(resolve-dirac-release! "81.0.4010.0")) | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(ns dirac.home.chromium.profiles | ||
(:require [dirac.home.locations :as locations])) | ||
|
||
(def get-chromium-profiles-dir-path locations/get-chromium-profiles-dir-path) | ||
|
||
(defn get-chromium-profile-dir-path [name] | ||
(locations/canonical-path (get-chromium-profiles-dir-path) name)) | ||
|
||
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
(comment | ||
(get-chromium-profiles-dir-path) | ||
(get-chromium-profile-dir-path "test") | ||
) |
Oops, something went wrong.