Boot error on Windows "Couldn't delete target" - windows

Well, basically I'm facing a problem just on Windows, when I run "boot run dev" on macOS or Linux, it works perfectly, but on Windows, the dream is over, the boot starts but get an error soon as it starts, this is my build.boot:
(set-env!
:source-paths #{"src"}
:resource-paths #{"src" "resources"}
:dependencies '[[org.clojure/clojure "1.9.0" :scope "provided"]
[adzerk/boot-cljs "2.1.4" :scope "test"]
[adzerk/boot-reload "0.5.2" :scope "test"]
[pandeiro/boot-http "0.8.3" :scope "test"]
[nightlight "RELEASE"]
[org.clojure/clojurescript "1.9.946"]
[rum "0.10.8"]
[org.roman01la/cljss "1.5.13"]
[org.clojure/core.async "0.4.474"]
[io.replikativ/konserve "0.4.11"]
[ring/ring-core "1.6.3"]
[bidi "2.1.2"]
[congomongo "0.5.0"]
[cljs-http "0.1.44"]
[http-kit "2.2.0"]
[com.hypirion/clj-xchart "0.2.0"]])
(require
'[adzerk.boot-cljs :refer [cljs]]
'[adzerk.boot-reload :refer [reload]]
'[pandeiro.boot-http :refer [serve]]
'[nightlight.boot :refer [nightlight sandbox]])
(task-options!
aot {:namespace #{'brad.server}}
pom {:project 'brad
:version "0.1.0"
:description "FIXME: write description"
:url "http://example/FIXME"
:scm {:url "https://github.com/yourname/brad"}
:license {"Eclipse Public License"
"http://www.eclipse.org/legal/epl-v10.html"}}
jar {:main 'brad.server
:file "brad.jar"}
cljs {:ids #{"brad/admins" "brad/fisicos"}})
(deftask dev []
(comp
(watch)
(reload :asset-path "brad"
:cljs-asset-path ".")
(sandbox :file "java.policy")
(cljs :source-map true
:optimizations :none)
(target)))
(deftask run []
(comp
(serve :dir "target/brad" :port 3000)
(dev)
(nightlight :port 4000 :url "http://localhost:3000")))
(deftask build []
(comp
(cljs :optimizations :advanced
:compiler-options {:fn-invoke-direct true})
(aot)
(pom)
(uber)
(jar)
(target)))
Sorry about the extensive code, I think that maybe the problem is with some permission that I didn't give, I was trying to run boot on git bash, then I tried on windows powershell, the same error was ocurred, please, help me, and I'm sorry about my english.

There are known issues on Windows, please try on Windows 10.

Related

How do I register IEDriver and Edge Driver with Capybara while using the Webdrivers gem?

The ruby webdrivers gem allows automatic downloads of drivers without me having to do it manually when my browser is updated.
And I know that latest Capybara supports drivers out of the box like :selenium, :selenium_chrome, :selenium_chrome_headless just to name a few. This makes it easy in that I don't have to register any drivers beforehand.
Are there similar keywords I can use for IEDriver and Edge Driver? The Webdrivers gem supports these but I am not sure how to get it working with Capybara so that the drivers are automatically downloaded and then run. If there are no keywords/default driver names I can use, how do I register these?
No, there are no preregistered drivers for IE or Edge. To add them you need to use register_driver - https://www.rubydoc.info/github/jnicklas/capybara/Capybara.register_driver - and inside the block pass the options to configure selenium to use the browser you want. You can see how Capybara registers the provided drivers by looking in https://github.com/teamcapybara/capybara/blob/master/lib/capybara/registrations/drivers.rb
Capybara.register_driver :internetExplorer do |app|
# p Capybara::Selenium::Driver::InternetExplorerDriver.options
Capybara::Selenium::Driver.new(
app,
:browser => :internet_explorer,
:options => Selenium::WebDriver::IE::Options.new({
:ignore_zoom_levels => true,
:ignore_zoom_setting => true,
# :browser_attach_timeout => 1,
:javascript_enabled => true,
:persistent_hover => true,
# :require_window_focus => true,
:ignore_protected_mode_settings =>true,
})
)
end
Capybara.register_driver :edgeBrowser do |app|
# p Capybara::Selenium::Driver::InternetExplorerDriver.options
Capybara::Selenium::Driver.new(
app,
:browser => :edge,
:desired_capabilities =>Selenium::WebDriver::Remote::Capabilities::edge({
:javascript_enabled => true,
:css_selectors_enabled => true,
}),
)
end

Get Postgres-activerecord setup to work both locally and in Heroku

I'm automating DB creation (with a Rakefile in a Sinatra App).
I would like to be able to run the rakefile from my Linux user "pete" (eg pete#pete_laptop: /path $ rake db:create) AND from Heroku.
It comes down to the settings in my config/database.rb:
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:port => db.port,
# pete#ubuntu_14.04_laptop--------
# :username => 'pete',
# :password => 'password',
# OR
# heroku -----------------
# :username => db.user,
# :password => db.password,
:database => DB_NAME,
:encoding => 'utf8'
)
If I use the pete#ubuntu_laptop settings, the database works in localhost but not in Heroku,
If I use the heroku settings, the database works in localhost but not in Heroku.
How can I setup this file/my ubuntu laptop so that the app works both on localhost & in Heroku?
Cheers,
Pete
You can use environment variables which can be accessed like ENV["PG_USER"] in Ruby. If you want to use it in a yml file you can put it in erb tags <%= ENV["PG_USER"] %> and render it with erb before passing it to your config.
You can set environment variables in your .bashrc or you can use something like the dotenv gem. On heroku you can set environment variables like heroku config:set PG_USER=postgres.
But check whether this is really necessary for heroku. In Rails, for instance, heroku provides a database configuration, so there is no need to configure it.
oK! With help got it working!
used:
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:port => db.port,
:username => ENV['PG_USER'] || db.user,
:password => ENV['PG_PASSWORD'] || db.password,
:database => DB_NAME,
:encoding => 'utf8'
)
AND
added this to my shell-rc (in my case ~/.zshrc)
export PG_USER='pete'
export PG_PASSWORD='password'
now in my local environment the username & password pick up the ENV['PG...] variables from the terminal I launch the app in.
Note: 'export' is important - without it the variables don't get sent to the app's 'ENV'

css won't modify html in clojure/heroku web-app

I am making a simple Clojure web-app to be deployed on Heroku consisting of one html and one css file. I created the file using the "lein new heroku MYAPP" command and am trying to modify it from a simple "hello world" to have it render an html file in another folder on startup. I have managed to get the html to load on a local host in my browser, but it is not being modified by the css when I do it. What do I need to change to get the css to modify the html to have it render properly in the browser and then deploy to heroku?
html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<img id="sun" src="http://goo.gl/dEEssP">
<div id='earth-orbit'>
<img id="earth" src="http://goo.gl/o3YWu9">
</div>
</body>
</html>
project.clj
(defproject solar_system "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://solar_system.herokuapp.com"
:license {:name "FIXME: choose"
:url "http://example.com/FIXME"}
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.1"]
[ring/ring-jetty-adapter "1.1.0"]
[ring/ring-devel "1.1.0"]
[ring-basic-authentication "1.0.1"]
[environ "0.2.1"]
[com.cemerick/drawbridge "0.0.6"]]
:uberjar-name "solar_system-standalone.jar"
:min-lein-version "2.0.0"
:plugins [[environ/environ.lein "0.2.1"]]
:hooks [environ.leiningen.hooks]
:profiles {:production {:env {:production true}}})
web.clj:
(ns solar_system.web
(:require [compojure.core :refer [defroutes GET PUT POST DELETE ANY]]
[compojure.handler :refer [site]]
[compojure.route :as route]
[clojure.java.io :as io]
[ring.middleware.stacktrace :as trace]
[ring.middleware.session :as session]
[ring.middleware.session.cookie :as cookie]
[ring.adapter.jetty :as jetty]
[ring.middleware.basic-authentication :as basic]
[cemerick.drawbridge :as drawbridge]
[environ.core :refer [env]]))
(defn- authenticated? [user pass]
;; TODO: heroku config:add REPL_USER=[...] REPL_PASSWORD=[...]
(= [user pass] [(env :repl-user false) (env :repl-password false)]))
(def ^:private drawbridge
(-> (drawbridge/ring-handler)
(session/wrap-session)
(basic/wrap-basic-authentication authenticated?)))
(defroutes app
(ANY "/repl" {:as req}
(drawbridge req))
(GET "/" []
{:status 200
:headers {"Content-Type" "text/html"}
:body (slurp (io/resource "index.html"))})
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))
(defn wrap-error-page [handler]
(fn [req]
(try (handler req)
(catch Exception e
{:status 500
:headers {"Content-Type" "text/html"}
:body (slurp (io/resource "500.html"))}))))
(defn -main [& [port]]
(let [port (Integer. (or port (env :port) 5000))
;; TODO: heroku config:add SESSION_SECRET=$RANDOM_16_CHARS
store (cookie/cookie-store {:key (env :session-secret)})]
(jetty/run-jetty (-> #'app
((if (env :production)
wrap-error-page
trace/wrap-stacktrace))
(site {:session {:store store}}))
{:port port :join? false})))
;; For interactive development:
;; (.stop server)
;; (def server (-main))
here is the directory tree. The html and css files are in resources (with the error.html files), web.clj is in src/solar_system and project.clj is in the root folder:
solar_system
├── resources
├── src
│   └── solar_system
├── target
│   ├── classes
│   └── stale
└── test
└── solar_system
I don't know why the lein new heroku _ template doesn't do this for you.
Use compojure.route/resources to tell the handler where to look for static files.
(defroutes app
(ANY "/repl" ...)
(GET "/" [] ...)
(route/resources "/")
(ANY "*" [] ...))
Now, if you visit http://example.com/style.css, it will expect resources/public/style.css.
Aside: It's better to serve static assets from resources/public/ rather than resources/ because you may want to have resources/secrets.txt without anybody being able to access it.
You have a css file, but no route to serve it! Your browser is begging for a CSS file, but the server says "404, man, never heard of that file." You can either add another route like the one for index.html, or you can use compojure's resources or files route to serve all files in a directory.
As the others have said, you're missing a route to your css file.
(defroutes app
(ANY "/repl" {:as req}
(drawbridge req))
(GET "/" []
{:status 200
:headers {"Content-Type" "text/html"}
:body (slurp (io/resource "index.html"))})
(route/resources "/") ; special route for serving static files like css
; default root directory is resources/public/
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))
http://my-website.com/style.css should display your css file. If it doesn't, there's something wrong with your routes or your file isn't there. It expects resources/public/style.css. Make sure you are restarting your app and doing a cacheless refresh in your browser (shift F5 in most instances) to make sure there's nothing weird giving you weird results.

Heroku clojure webapp crashes with error "That's not a task. Use "lein help" to list all tasks.'

I can deploy the sample heroku clojure webapp as described here. However a custom webapp, running fine locally, crashes on access.
heroku logs:
2013-11-28T02:01:57.142302+00:00 heroku[web.1]: State changed from crashed to starting
2013-11-28T02:01:57.124843+00:00 heroku[web.1]: Process exited with status 1
2013-11-28T02:02:02.579325+00:00 heroku[web.1]: Starting process with command `lein with-profile production trampoline run`
2013-11-28T02:02:03.366402+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Djava.rmi.server.useCodebaseOnly=true
2013-11-28T02:02:05.136478+00:00 app[web.1]: That's not a task. Use "lein help" to list all tasks.
2013-11-28T02:02:06.366976+00:00 heroku[web.1]: Process exited with status 1
2013-11-28T02:02:06.377083+00:00 heroku[web.1]: State changed from starting to crashed
I can't see heroku config listing JAVA_TOOL_OPTIONS either. What am i missing?
project.clj:
(defproject xxx "0.1.0"
:warn-on-reflection false
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/tools.nrepl "0.2.3"]
[ring "1.2.1"]
[ring/ring-jetty-adapter "1.1.6"]
[compojure "1.1.6"]
[enlive "1.1.4"]
[ring/ring-devel "1.1.0"]
[ring-basic-authentication "1.0.1"]
[com.cemerick/drawbridge "0.0.6" :exclusions [org.clojure/tools.nrepl]]
[environ "0.4.0"]]
:plugins [[lein-ring "0.8.8"]
[lein-environ "0.4.0"]]
:main xxx.web)
web.clj:
(ns xxx.web
(:require [compojure.core :refer [defroutes GET PUT POST DELETE ANY]]
[compojure.handler :refer [site]]
[compojure.route :as route]
[clojure.java.io :as io]
[ring.middleware.stacktrace :as trace]
[ring.middleware.session :as session]
[ring.middleware.session.cookie :as cookie]
[ring.adapter.jetty :as jetty]
[ring.middleware.basic-authentication :as basic]
[cemerick.drawbridge :as drawbridge]
[ring.middleware.params :as params]
[ring.middleware.keyword-params :as keyword-params]
[ring.middleware.nested-params :as nested-params]
[ring.middleware.session :as session]
[ring.middleware.basic-authentication :as basic]
[environ.core :refer [env]]
[xxx.templates :as templates]))
(defn- authenticated? [user pass]
;; TODO: heroku config:add REPL_USER=[...] REPL_PASSWORD=[...]
(= [user pass] [(env :repl-user false) (env :repl-password false)]))
(def ^:private drawbridge
(-> (drawbridge/ring-handler)
(session/wrap-session)
(basic/wrap-basic-authentication authenticated?)))
(defroutes app
(ANY "/repl" {:as req}
(drawbridge req))
(GET "/" []
{:status 200
:headers {"Content-Type" "text/html"}
:body (templates/index "Hello.") })
(ANY "*" []
(route/not-found (slurp (io/resource "404.html")))))
(defn wrap-error-page [handler]
(fn [req]
(try (handler req)
(catch Exception e
{:status 500
:headers {"Content-Type" "text/html"}
:body (slurp (io/resource "500.html"))}))))
(def drawbridge-handler
(-> (cemerick.drawbridge/ring-handler)
(keyword-params/wrap-keyword-params)
(nested-params/wrap-nested-params)
(params/wrap-params)
(session/wrap-session)))
(defn wrap-drawbridge [handler]
(fn [req]
(let [handler (if (= "/repl" (:uri req))
(basic/wrap-basic-authentication
drawbridge-handler authenticated?)
handler)]
(handler req))))
(defn -main [port]
(let [port (Integer. (or port (System/getenv "PORT")))]
;(jetty/run-jetty #'app {:port port :join? false})))
(jetty/run-jetty (wrap-drawbridge app) {:port port :join? false})))
You're probably using a different version of Leiningen locally than # Heroku.
From Heroku doc:
Leiningen 1.7.1 will be used by default, but if you have :min-lein-version "2.0.0" in project.clj (highly recommended) then the latest Leiningen 2.x release will be used instead.

How to create a config file for multiple environments in Ruby?

I don't want to confuse you so what I want to do is the following:
I have three environments:
www.env1.com
www.env2.com
www.env3.com
I want to create something to define the setup phase according the environment over which I want to run the scripts, that is:
Current set-up:
def setup
#verification_errors = []
#selenium = Selenium::Client::Driver.new(
:host => "localhost",
:port => 4444,
:browser => "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
:url => "www.env1.com",
:timeout_in_second => 60
)
#selenium.start_new_browser_session
end
What I want:
def setup
#verification_errors = []
#selenium = Selenium::Client::Driver.new(
:host => "localhost",
:port => 4444,
:browser => "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
**:url => This parameter configurable from a file or other source.**
:timeout_in_second => 60
)
#selenium.start_new_browser_session
end
If this is possible I can switch environments without having to re-write all test cases.
Hope you can help me out, I really need to do this.
YAML is a great data serialization language for handling configuration information. It comes with Ruby so you only have to do:
require 'yaml'
to load it in, then something like:
configuration = YAML::load_file('path/to/yamldata.yaml')
All your configuration data will be available inside the configuration variable.
Generally I create a stub for my YAML files by writing some Ruby code, defining the configuration hash that contains it, then telling YAML to generate the file for me. See the docs for load_file and dump for ways to do that.
For something like you're doing I'd create a hash like:
configuration = {
'env1' => "www.env1.com",
'env2' => "www.env2.com",
'env3' => "www.env3.com",
}
Using YAML::dump(configuration) returns:
---
env1: www.env1.com
env2: www.env2.com
env3: www.env3.com
which you'd want to write to your .yaml file, then load later at run-time and access it like:
#selenium = Selenium::Client::Driver.new(
:host => "localhost",
:port => 4444,
:browser => "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
:timeout_in_second => 60
:url => configuration['env1'],
)
You can replace 'env1' with the other keys to use env2 or env3.
Rails uses YAML to make one file handle the development, test and production information for an application. At work I use it to do similar things, where one file contains our development and production environmental information for apps, plus the definitions of some hashes we need to maintain, but don't want to have to modify the code to do so.

Resources