Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created June 19, 2011 04:36
Show Gist options
  • Save hugoduncan/1033762 to your computer and use it in GitHub Desktop.
Save hugoduncan/1033762 to your computer and use it in GitHub Desktop.
Use aether for artifact resolving
(ns pallet.aether
"Wrapper for aether resolution
See:
https://docs.sonatype.org/display/AETHER/Home"
(:require
[clojure.java.io :as io]
[clojure.contrib.logging :as logging])
(import
org.apache.maven.repository.internal.MavenRepositorySystemSession
org.sonatype.aether.RepositorySystem
org.sonatype.aether.repository.LocalRepository
org.sonatype.aether.repository.RemoteRepository
org.sonatype.aether.resolution.ArtifactRequest
org.sonatype.aether.util.artifact.DefaultArtifact
org.codehaus.plexus.DefaultPlexusContainer))
(defn repository-system []
(.lookup (DefaultPlexusContainer.) RepositorySystem))
(defn session [system local-repo-path]
(doto (MavenRepositorySystemSession.)
(.setLocalRepositoryManager
(.newLocalRepositoryManager
system
(LocalRepository. local-repo-path )))))
(defn resolver-objects
"Given a repository map with :name, :snapshot-repository and
:release-repository keys, returns a repository system, session
and list of repositories."
[repository-name release-repository snapshot-repository local-path]
(let [repository-system (repository-system)
session (session
repository-system
(or (io/file local-path)
(io/file
(System/getProperty "user.home")
".pallet" "deploy-repository")))
snapshots (when snapshot-repository
(RemoteRepository.
(str repository-name "-snapshots")
"default"
snapshot-repository))
releases (when release-repository
(RemoteRepository.
(str repository-name "-releases")
"default"
release-repository))]
[repository-system session (keep identity [releases snapshots])]))
;;; (def resolver-objects (memoize resolver-objects))
(defn resolve-artifact
[repository-system session repositories group-id artifact-id extension
version]
(logging/info
(format
"resolving %s %s %s in %s"
group-id artifact-id version repositories))
(let [artifact (DefaultArtifact. group-id artifact-id extension version)
request (ArtifactRequest. artifact repositories nil)]
(..
(.resolveArtifact repository-system session request)
getArtifact
getFile)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment