Skip to content

Commit

Permalink
adding jar file to emacs package as requested in melpa/melpa#6365
Browse files Browse the repository at this point in the history
  • Loading branch information
rksm committed Aug 12, 2019
1 parent 8fc39a8 commit eb46d4a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 90 deletions.
42 changes: 22 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.1.0
VERSION := 0.2.0

CLJ_FILES := $(shell find . -type f \
\( -path "./test/*" -o -path "./dev/*" -o -path "./src/*" \) \
Expand All @@ -24,24 +24,6 @@ chrome:
http-server:
clojure -A:http-server ~/org

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# emacs

EMACS_PACKAGE_NAME:=org-analyzer-$(VERSION)
EMACS_PACKAGE_DIR:=/tmp/$(EMACS_PACKAGE_NAME)

update-version:
sed -e "s/[0-9].[0-9].[0-9]/$(VERSION)/" -i org-analyzer-el/org-analyzer-pkg.el

emacs-package: $(EMACS_PACKAGE_DIR)
mkdir -p target
tar cvf target/$(EMACS_PACKAGE_NAME).tar \
-C $(EMACS_PACKAGE_DIR)/.. $(EMACS_PACKAGE_NAME)

$(EMACS_PACKAGE_DIR): update-version
@mkdir -p $@
cp -r org-analyzer-el/*el $@

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# cljs

Expand Down Expand Up @@ -70,8 +52,9 @@ $(AOT): $(CLJ_FILES) $(CLJS_FILES)
mkdir -p $(AOT)
clojure -A:aot

JAR := org-analyzer-$(VERSION).jar
JAR := target/org-analyzer-$(VERSION).jar
$(JAR): cljs $(AOT) pom.xml
mkdir -p $(dir $(JAR))
clojure -C:http-server:aot -A:depstar -m hf.depstar.uberjar $(JAR) -m org_analyzer.http_server
chmod a+x $(JAR)

Expand Down Expand Up @@ -112,6 +95,25 @@ run-bin: bin
$(BIN)


# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# emacs

EMACS_PACKAGE_NAME:=org-analyzer-$(VERSION)
EMACS_PACKAGE_DIR:=/tmp/$(EMACS_PACKAGE_NAME)

update-version:
sed -e "s/[0-9].[0-9].[0-9]/$(VERSION)/" -i org-analyzer-el/org-analyzer-pkg.el

emacs-package: $(EMACS_PACKAGE_DIR)
mkdir -p target
tar cvf target/$(EMACS_PACKAGE_NAME).tar \
-C $(EMACS_PACKAGE_DIR)/.. $(EMACS_PACKAGE_NAME)

$(EMACS_PACKAGE_DIR): update-version $(JAR)
cp $(JAR) org-analyzer-el/org-analyzer.jar
@mkdir -p $@
cp -r org-analyzer-el/*el org-analyzer-el/*jar $@

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

clean:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ via `M-x org-analyzer-start`.

You start org-analyzer either directly via [a jar file you can download
here](TODO). Place the jar file in the directory that contains your org files.
Then double click it or start from the command line with `java -jar org-analyzer-0.1.0.jar`.
Then double click it or start from the command line with `java -jar org-analyzer-0.2.0.jar`.
It will bring up a page in your default web browser that displays the clock data
found in all the org files.

When using the jar file, place it in the directory where your org files are
located and double click it or start from a terminal via
`java -jar org-analyzer-0.1.0.jar`.
`java -jar org-analyzer-0.2.0.jar`.

You can also start the tool from within emacs, see the install instructions
above.

### Command line options

Command line options from `java -jar org-analyzer-0.1.0.jar --help`:
Command line options from `java -jar org-analyzer-0.2.0.jar --help`:

```
Usage: java -jar org-analyzer-0.1.0.jar [opt*] [org-file-or-dir*]
Usage: java -jar org-analyzer-0.2.0.jar [opt*] [org-file-or-dir*]
Interactive visualization of timetracking data (org clocks).
Expand Down
2 changes: 1 addition & 1 deletion org-analyzer-el/org-analyzer-pkg.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(define-package
"org-analyzer"
"0.1.0"
"0.2.0"
"org-analyzer is a tool that extracts time tracking data from org files.")
99 changes: 35 additions & 64 deletions org-analyzer-el/org-analyzer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Robert Krahn <[email protected]>
;; URL: https://github.com/rksm/clj-org-analyzer
;; Keywords: calendar
;; Version: 0.1.0
;; Version: 0.2.0
;; Package-Requires: ((emacs "24"))

;; Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -43,13 +43,9 @@

(defvar org-analyzer-process-buffer nil "The buffer for running the jar.")

(defvar org-analyzer-version "0.1.0" "Version to sync with jar.")
(defvar org-analyzer-version "0.2.0" "Version to sync with jar.")

(defvar org-analyzer-jar-url
(format "https://github.com/rksm/clj-org-analyzer/releases/download/%s/org-analyzer-%s.jar"
org-analyzer-version
org-analyzer-version)
"The URL of the jar of the org-analyzer server.")
(defvar org-analyzer-jar-file-name "org-analyzer.jar" "The name of the jar of the org-analyzer server.")

(defcustom org-analyzer-emacs-dir
(replace-regexp-in-string "/+" "/" (concat user-emacs-directory "/org-analyzer/") t t)
Expand Down Expand Up @@ -80,36 +76,9 @@ When nil, defaults to `org-directory'. When that is nil defaults to ~/org."
(and (boundp 'org-directory) org-directory)
(expand-file-name "~/org")))

(defun org-analyzer-jar-name ()
"The thing to run."
(format "org-analyzer-%s.jar" org-analyzer-version))

(defun org-analyzer-jar-path ()
"The path to the thing to run."
(expand-file-name (org-analyzer-jar-name) org-analyzer-emacs-dir))

(defun org-analyzer-ensure-jar-exists ()
"Will download the org-analyzer jar and store it into `org-analyzer-jar-path'."
(unless (file-exists-p (org-analyzer-jar-path))
(if (y-or-n-p
(format "Org-analyzer needs a jar file to run. Is it OK to download %s? "
org-analyzer-jar-url))
(progn
(message "Installing org-analyzer jar (%s)" (org-analyzer-jar-path))
(unless (file-directory-p org-analyzer-emacs-dir)
(make-directory org-analyzer-emacs-dir))
(url-copy-file org-analyzer-jar-url (org-analyzer-jar-path) t))
(message "org-analyzer cannot be started"))))

(defun org-analyzer-warn-no-java ()
"Check if java is available.
If it is returns nil. If it isn't will put up a warning and return t."
(if (executable-find org-analyzer-java-program)
nil
(warn "org-analyzer could not find java.
If it is not installed please install it, e.g. via
https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot")
t))
(defun org-analyzer-locate-jar ()
"Will try to find `org-analyzer-jar-file-name' on `load-path'."
(locate-file org-analyzer-jar-file-name load-path))

(defun org-analyzer-cleanup-process-state ()
"Kill the org-analyzer process + buffer."
Expand All @@ -121,32 +90,36 @@ If it is not installed please install it, e.g. via
"Start the org analyzer process .
Argument ORG-DIR is where the org-files are located."
(org-analyzer-cleanup-process-state)
(let* ((full-java-command (executable-find "java"))
(name (format " *org-analyzer [org-dir:%s]*" org-dir))
(proc-buffer (generate-new-buffer name))
(proc nil))
(let ((jar-file (org-analyzer-locate-jar))
(full-java-command (executable-find org-analyzer-java-program)))
(unless jar-file
(error "Can't find %s. Is the package correctly installed?"
org-analyzer-jar-file-name))
(unless full-java-command
(error "Can't find java — please install it!"))
(setq org-analyzer-process-buffer proc-buffer)
(with-current-buffer proc-buffer
(setq default-directory org-dir
proc (condition-case err
(let ((process-connection-type nil)
(process-environment process-environment))
(start-process name
(current-buffer)
full-java-command
"-jar"
(concat org-analyzer-emacs-dir "org-analyzer.jar")
"--port"
(format "%d" org-analyzer-http-port)
org-dir))
(error
(concat "Can't start org-analyzer (%s: %s)"
(car err) (cadr err)))))
(set-process-query-on-exit-flag proc nil)
(set-process-filter proc #'org-analyzer-process-filter))
proc-buffer))
(let* ((name (format " *org-analyzer [org-dir:%s]*" org-dir))
(proc-buffer (generate-new-buffer name))
(proc nil))
(setq org-analyzer-process-buffer proc-buffer)
(with-current-buffer proc-buffer
(setq default-directory org-dir
proc (condition-case err
(let ((process-connection-type nil)
(process-environment process-environment))
(start-process name
(current-buffer)
full-java-command
"-jar"
jar-file
"--port"
(format "%d" org-analyzer-http-port)
org-dir))
(error
(concat "Can't start org-analyzer (%s: %s)"
(car err) (cadr err)))))
(set-process-query-on-exit-flag proc nil)
(set-process-filter proc #'org-analyzer-process-filter))
proc-buffer)))

(defun org-analyzer-process-filter (process output)
"Filter to detect port collisons.
Expand All @@ -165,9 +138,7 @@ Argument OUTPUT is the process output received."
(defun org-analyzer-start ()
"Start org-analyzer."
(interactive)
(unless (org-analyzer-warn-no-java)
(org-analyzer-ensure-jar-exists)
(org-analyzer-start-process (org-analyzer-effective-org-dir))))
(org-analyzer-start-process (org-analyzer-effective-org-dir)))

;; (pop-to-buffer org-analyzer-process-buffer)

Expand Down
Binary file added org-analyzer-el/org-analyzer.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.rksm</groupId>
<artifactId>org-analyzer</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<version>0.2.0</version>
<name>org-analyzer</name>
<description>An app that creates an interactive visualization of org-mode time-tracking data (org clockin).</description>
<url>http://github.com/rksm/clj-org-analyzer</url>
Expand Down

0 comments on commit eb46d4a

Please sign in to comment.