Tampilkan postingan dengan label Leiningen. Tampilkan semua postingan
Tampilkan postingan dengan label Leiningen. Tampilkan semua postingan

Agustus 14, 2012

Working with GitHub and Clojars


This guide is used as a note for myself. If you can benefit from this note, that's fine. Here I just wish to document how I work with GitHub and Clojars. I need to do this since I have my own need for Ring middleware to reload automatically a server without restart whenever a namespace in Ring is modified. The original version was not maintained I think, since it uses Clojure 1.2.0.

GitHub

I forked the ring-reload-modified to my Github account. This can be done easily using step 1 and 2 from https://help.github.com/articles/fork-a-repo (I use only step 1 and 2 since I only want to fork and modified my forked version, not upstream version).

Let's say for this time I just want to edit the README.md and project.clj files. After I edit those files, I just put them in committed state:

[bpdp@bpdp-arch ring-reload-modified]$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add [file]..." to update what will be committed)
#   (use "git checkout -- [file]..." to discard changes in working directory)
#
# modified:   README.md
# modified:   project.clj
#
no changes added to commit (use "git add" and/or "git commit -a")
[bpdp@bpdp-arch ring-reload-modified]$

We can see from the status that it has 2 changes: README.md and project.clj but I haven't commit anything. Here's how to commit:

[bpdp@bpdp-arch ring-reload-modified]$ git commit -a
[master ada41aa] Adjust to latest Clojure version (1.4.0)
 2 files changed, 8 insertions(+), 4 deletions(-)
[bpdp@bpdp-arch ring-reload-modified]$ 

Then it's time to push the committed version to Github repository:

 [bpdp@bpdp-arch ring-reload-modified]$ git push origin master
 Username for 'https://github.com': bpdp
 Password for 'https://bpdp@github.com': 
 Counting objects: 7, done.
 Delta compression using up to 2 threads.
 Compressing objects: 100% (4/4), done.
 Writing objects: 100% (4/4), 721 bytes, done.
 Total 4 (delta 2), reused 0 (delta 0)
 To https://github.com/bpdp/ring-reload-modified.git
    6dfdc5c..ada41aa  master -> master
 [bpdp@bpdp-arch ring-reload-modified]$

Let's see the result in Github profile:



The result in Github project page (I have pushed another commit so the history is different with above).



Clojars

To upload the library, I need to prepare my ssh public key first:

[bpdp@bpdp-arch ring-reload-modified]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bpdp/.ssh/id_rsa): 
/home/bpdp/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/bpdp/.ssh/id_rsa.
Your public key has been saved in /home/bpdp/.ssh/id_rsa.pub.
The key fingerprint is:
87:fc:8f:35:18:20:2e:8f:73:d2:b5:71:ea:0e:85:01 bpdp@bpdp-arch
The key's randomart image is:
+--[ RSA 2048]----+
|    E            |
|     .           |
|      o .        |
|     . = o       |
|    . o S +      |
|     = o B o     |
|    + = o o o    |
|     + o   + .   |
|       .o . .    |
+-----------------+
[bpdp@bpdp-arch ring-reload-modified]$

The public key should be put into the Clojars first. So, first we need to register by using http://clojars.org/register:



Now, it's time to upload to Clojars:

[bpdp@bpdp-arch ring-reload-modified]$ lein2 jar   
Created /home/bpdp/master/clojure/libs/ring-reload-modified/target/ring-reload-modified-0.1.2.jar
[bpdp@bpdp-arch ring-reload-modified]$ lein2 pom
Wrote /home/bpdp/master/clojure/libs/ring-reload-modified/pom.xml
[bpdp@bpdp-arch ring-reload-modified]$ scp pom.xml target/ring-reload-modified-0.1.2.jar clojars@clojars.org:
Enter passphrase for key '/home/bpdp/.ssh/id_rsa': 
Welcome to Clojars, bpdp!
pom.xml                                                           100% 2672     2.6KB/s   00:00    
ring-reload-modified-0.1.2.jar                                    100% 5328     5.2KB/s   00:00    

Deploying org.clojars.bpdp/ring-reload-modified 0.1.2

Success! Your jars are now available from http://clojars.org/
[bpdp@bpdp-arch ring-reload-modified]$

Now I can use the library that I upload to Clojars:



That's all big guy. Have a happy hacking!


Agustus 12, 2012

Mengakses Basis Data Graph OrientDB Menggunakan Clojure

OrientDB adalah salah satu basis data NOSQL dengan kemampuan basis data obyek, graph, document, serta flat. API untuk basis data ini bermacam-macam dan karena dikembangkan menggunakan Java, maka API yang paling utama adalah Java, meski demikian, tersedia juga API untuk JavaScript dan implementasi bahasa-bahasa pemrograman berbasis JVM seperti Clojure dan Scala.

Pada tulisan ini saya akan sedikit membahas tentang akses dengan menggunakan Clojure. Wrapper Clojure untuk API OrientDB dibuat oleh Eduardo Julián. Versi binary bisa diperoleh dari http://clojars.org melalui Leiningen dan versi kode sumber bisa diperoleh di https://github.com/eduardoejp/clj-orient (sayangnya, dokumentasi kurang jelas). Langkah sederhana berikut digunakan untuk mengakses OrientDB dari Clojure menggunakan Leiningen.

1. Buat project

$ lein new orientweb

2. Hasil:

[bpdp@bpdp-arch orientweb]$ tree
|-- README.md
|-- doc
|   `-- intro.md
|-- project.clj
|-- src
|   `-- orientweb
|       `-- core.clj
`-- test
    `-- orientweb
        `-- core_test.clj
5 directories, 6 files
[bpdp@bpdp-arch orientweb]$ 

3. Edit project.clj, isikan berikut ini:
 
(defproject orientweb "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
               :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.4.0"]
                         [clj-orient "0.5.0"]]
  :main orientweb.core)

4. Download dependencies dengan perintah:
 
lein deps

5. Koneksi terdapat pada file core.clj
 
(ns orientweb.core)
(require '[clj-orient.core :as orientcore]
            '[clj-orient.graph :as orientgraph])
 
(orientcore/set-db! (orientgraph/open-graph-db! "remote:localhost/demo" "admin" "admin"))

(def mydb (orientcore/db-info orientcore/*db*))

(defn -main 
   [& args]
   (println "Information about the database:")
   (doseq [[key val] mydb] (prn key val))
   (orientcore/close-db!))

6. Hasil eksekusi:
 
[bpdp@bpdp-arch orientweb]$ lein compile
Compiling orientweb.core
Compilation succeeded.
[bpdp@bpdp-arch orientweb]$ lein run
All namespaces already :aot compiled
Information about the database:
:name "demo"
:url "remote:localhost/demo"
:status "OPEN"
:user #
[bpdp@bpdp-arch orientweb]$ 

Happy hacking!

Juli 13, 2012

Utilizing Leiningen Profile

In my previous post about setting up Emacs for Clojure development, I suggest to include lein-swank inside the plugins' project.clj. Eventhough this approach work, here I will explain how to use Leiningen profile to separate the plugins / libraries which will act as helper and with other plugins / libraries which will be included in the project result. You will find that separation of concerns is beatiful.

Ok, now here's the problem. I would like to use lein-swank for my development with Emacs but I don't want to interfere my project with all of those clutters, I just want my project to include my source code and my libraries. This is where Leiningen profile comes into play. To this end, use profile.clj inside Leiningen home (that is $HOME/.lein/). The default profile which will be executed is "user". Here is mine:

[bpdp@bpdp-arch ~]$ tree .lein/
.lein/
|-- profiles.clj
`-- self-installs   
     |-- leiningen-1.7.1-standalone.jar   
      `-- leiningen-2.0.0-preview7-standalone.jar
 
1 directory, 3 files[bpdp@bpdp-arch ~]$ 


Here's the profile.clj content:

[bpdp@bpdp-arch .lein]$ cat profiles.clj 
{:user {:plugins [[lein-swank "1.4.4"]
                         [lein-pprint "1.1.1"]]}}
[bpdp@bpdp-arch .lein]$ 


This way, you can - for example - execute lein-swank without include them in your project.clj anymore. You may add other plugins. I just use lein-pprint in the meantime. There are still many things that can be done using this profile, for example, you can use this profile to test multiversion plugins / libraries, etc. I will write them later.

Happy hacking!