Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: skuro/lein-amp
base: 6ee985eef5
...
head fork: skuro/lein-amp
compare: 15f5940f77
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
6 project.clj
@@ -9,13 +9,17 @@
; Contributors:
; Peter Monks - initial implementation
-(defproject lein-amp "0.2.0-SNAPSHOT"
+(defproject lein-amp "0.3.0-SNAPSHOT"
:description "Leiningen plugin for generating Alfresco Module Package (AMP) files."
:url "https://github.com/pmonks/lein-amp"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.0.0"
+ :repositories [
+ ["alfresco" "https://artifacts.alfresco.com/nexus/content/groups/public/"]
+ ]
:dependencies [
[me.raynes/fs "1.4.5"]
+ [org.alfresco/alfresco-mmt "4.2.f"]
]
:eval-in-leiningen true)
View
5 src/leiningen/amp.clj
@@ -10,8 +10,9 @@
; Peter Monks - initial implementation
(ns leiningen.amp
- (:require [clojure.string :as s]
- [leiningen.amp.impl :refer [package-amp! deploy-amp!]]))
+ (:require [clojure.string :as s]
+ [leiningen.amp.package :refer [package-amp!]]
+ [leiningen.amp.deploy :refer [deploy-amp!]]))
(def ^:private dispatch-table
{ "package" package-amp!
View
128 src/leiningen/amp/deploy.clj
@@ -0,0 +1,128 @@
+;
+; Copyright © 2014 Peter Monks (pmonks@gmail.com)
+;
+; All rights reserved. This program and the accompanying materials
+; are made available under the terms of the Eclipse Public License v1.0
+; which accompanies this distribution, and is available at
+; http://www.eclipse.org/legal/epl-v10.html
+;
+; Contributors:
+; Peter Monks - initial implementation
+
+(ns leiningen.amp.deploy
+ (:require [clojure.java.io :as io]
+ [cemerick.pomegranate.aether :as aether]
+ [leiningen.amp.package :as package]
+ [leiningen.core.main :as main])
+ (:import [org.alfresco.repo.module.tool ModuleManagementTool]))
+
+(defn- locate-amp
+ "Finds the AMP file produced by the given project"
+ [{:keys [target-path] :as project}]
+ (if-let [amp (package/target-file project (io/file target-path))]
+ amp
+ (main/abort "The AMP file was not found. Did you remember to run `lein amp package` first?")))
+
+(defn- repo-map
+ "Builds a Pomegranate compatible map of repositories given the project configured ones.
+ The repositories are found in the project to be a sequence of something like:
+ [<id> {:url \"http://url.to.repo\" ...}]"
+ [repos]
+ (let [result
+ (reduce (fn [m [id {:keys [url]}]]
+ (assoc m id url)) {} repos)]
+ result))
+
+(defn- depname
+ "Stringifies the filename of a leiningen dependency"
+ [dep]
+ (-> dep first name))
+
+(defn- version
+ "Stringifies the version of a leiningen dependency"
+ [dep]
+ (str "-" (second dep)))
+
+(defn- classifier
+ "Provides an appendable string for the classifier"
+ [dep]
+ (if-let [classifier (:classifier dep)]
+ (str "-" classifier)
+ ""))
+
+(defn- extension
+ "Provides an appenavle string for the extension"
+ [dep]
+ (if-let [ext (:extension dep)]
+ (str "." extension)
+ ".war"))
+
+(defn- dep-to-filename
+ "Translates a dependency in a filename"
+ [dep]
+ (str (depname dep) (version dep) (classifier dep) (extension dep)))
+
+(defn- dep-filter
+ "Creates a function suitable to `filter` a seq of dependencies to find the requested one"
+ [dep]
+ (fn [^java.io.File file]
+ (let [name (.getName file)
+ dep-name (dep-to-filename dep)]
+ (= dep-name name))))
+
+(defn- find-one
+ "Finds one and only one dependency that matches the given file"
+ [file files]
+ (let [filtered (filter (dep-filter file) files)
+ file (first filtered)]
+ (if file
+ file
+ (main/abort "The target WAR couldn't be found in the configured repository"))))
+
+(defn- find-dependency
+ "Finds the WAR from the project then returns its file"
+ [{:keys [repositories amp-target-war]}]
+ (let [files (aether/dependency-files
+ (aether/resolve-dependencies :repositories (repo-map repositories)
+ :coordinates [amp-target-war]))]
+ (if (empty? files)
+ (main/abort "No target WAR was found. Did you set :amp-target-war in your project.clj?")
+ (find-one amp-target-war files))))
+
+(defn- reference-war
+ "Creates and validates a path to a target WAR file"
+ [loc]
+ (let [file (io/file loc)]
+ (if (not (.exists ^java.io.File file))
+ (main/abort "The specified WAR file does not exist")
+ file)))
+
+(defn- dependency-war
+ "Creates and validates a target WAR file specified as a project dependency"
+ [{:keys [amp-target-war] :as project}]
+ (let [dependency (find-dependency project)
+ temp-war (io/file (:target-path project) (dep-to-filename amp-target-war))]
+ (io/copy dependency temp-war)
+ temp-war))
+
+(defn- locate-war
+ "Locates the WAR file to deploy to. The WAR can be specified as the argument,
+ or as a dependency in the project at the entry :amp-target-war"
+ [{:keys [amp-target-war] :as project} args]
+ (if-let [target-war (first args)]
+ (reference-war target-war)
+ (dependency-war project)))
+
+(defn- install!
+ "Uses the Alfresco MMT to install the AMP into the target WAR"
+ [amp war]
+ (ModuleManagementTool/main (into-array String ["install" (.toString amp) (.toString war)])))
+
+(defn deploy-amp!
+ "Installs the generated AMP into the specified WAR. If the target WAR is not
+ specified as an argument, it is retrieved from the project at the
+ :amp-target-war"
+ [project args]
+ (let [amp (locate-amp project)
+ war (locate-war project args)]
+ (install! amp war)))
View
17 src/leiningen/amp/impl.clj → src/leiningen/amp/package.clj
@@ -9,7 +9,7 @@
; Contributors:
; Peter Monks - initial implementation
-(ns leiningen.amp.impl
+(ns leiningen.amp.package
(:require [clojure.string :as s]
[clojure.java.io :as io]
[leiningen.uberjar :as uj]
@@ -97,6 +97,12 @@
(spit module-context-file rewritten-content))
nil)
+(defn target-file
+ [project target]
+ (io/file target
+ (or (get-in project [:amp-name])
+ (str (:name project) "-" (:version project) ".amp"))))
+
(defn package-amp!
[project args]
(let [project-home (io/file (:root project))
@@ -132,9 +138,7 @@
tgt-web (io/file tgt-amp "web")
; Output AMP file
- tgt-amp-file (io/file target
- (or (get-in project [:amp-name])
- (str (:name project) "-" (:version project) ".amp")))]
+ tgt-amp-file (target-file project target)]
; Cleanup anything left from a prior build
(if (fexists tgt-amp)
@@ -179,8 +183,3 @@
(zip-directory! tgt-amp-file tgt-amp)
(main/info (str "Created AMP " module-id " v" module-version " in " (str tgt-amp-file)))))
-
-
-(defn deploy-amp!
- [project args]
- (main/abort "AMP deployment is not yet implemented. Sorry!"))

No commit comments for this range

Something went wrong with that request. Please try again.