source: trunk/abcl/contrib/abcl-asdf/maven-embedder.lisp @ 13354

Last change on this file since 13354 was 13354, checked in by Mark Evenson, 10 years ago

Incorrect start on Maven repository saved for posterity.

File size: 4.3 KB
Line 
1(in-package :abcl-asdf)
2
3(require :abcl-contrib)
4(require :jss)
5
6(defvar *mvn-directory*
7  "/export/home/evenson/work/apache-maven-3.0.3/lib/"
8  "Location of 'maven-core-3.<m>.<p>.jar', 'maven-embedder-3.<m>.<p>.jar' etc.")
9
10(defun init () 
11  (jss:add-directory-jars-to-class-path *mvn-directory* nil))
12
13(defconstant +null+
14  (java:make-immediate-object :ref nil))
15
16(defun resolve (group-id artifact-id version)
17  (let* ((configuration (find-configuration))
18         (embedder (jss:new 'MavenEmbedder configuration))
19         (artifact (#"create" embedder group-id version +null+ "jar")))
20    (pathname (#"toString" (#"getFile" artifact)))))
21
22(defun find-configuration ())
23
24
25
26
27#|
28// http://developers-blog.org/blog/default/2009/09/18/How-to-resolve-an-artifact-with-maven-embedder
29
30import java.util.ArrayList;
31
32import java.util.List;
33import org.apache.log4j.Logger;
34import org.apache.maven.artifact.Artifact;
35import org.apache.maven.artifact.repository.ArtifactRepository;
36import org.apache.maven.artifact.repository.DefaultArtifactRepository;
37import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
38import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
39import org.apache.maven.artifact.resolver.ArtifactResolutionException;
40import org.apache.maven.embedder.Configuration;
41import org.apache.maven.embedder.ConfigurationValidationResult;
42import org.apache.maven.embedder.DefaultConfiguration;
43import org.apache.maven.embedder.MavenEmbedder;
44import org.apache.maven.embedder.MavenEmbedderException;
45import org.apache.maven.model.Profile;
46import org.apache.maven.model.Repository;
47import org.apache.maven.settings.SettingsUtils;
48
49
50/**
51 * resolve artifact.
52 * @param groupId group id of artifact
53 * @param artifactId artifact id of artifact
54 * @param version version of artifact
55 * @return downloaded artifact file
56 * @throws HostingOrderException error occured during resolution
57 */
58
59public File resolveArtifact(String groupId, String artifactId, String version)
60  throws Exception
61{
62  LOG.debug("request to resolve '" + groupId + ":"
63            + artifactId + ":" + version + "'");
64  Artifact artifact = null;
65  LOG.debug("using settings: " + this.settingsFile);
66  File settings = new File(this.getClass().getClassLoader()
67                           .getResource(this.settingsFile).getFile());
68  Configuration configuration = new DefaultConfiguration()
69    .setGlobalSettingsFile(SETTINGS)
70    .setClassLoader(this.classLoader);
71  ConfigurationValidationResult validationResult =
72    MavenEmbedder.validateConfiguration(configuration);
73  if (validationResult.isValid()) {
74    try {
75      MavenEmbedder embedder = new MavenEmbedder(configuration);
76      artifact = embedder.createArtifact(groupId,
77                                         artifactId, version, null, "jar");
78      // assign repos,
79      List repos = new ArrayList();
80      Profile profile = SettingsUtils.convertFromSettingsProfile((org.apache.maven.settings.Profile)
81                                                                 embedder.getSettings().getProfiles().get(0));
82      for (Repository r : (List < Repository > ) profile.
83             getRepositories()) {
84        ArtifactRepository repo = new DefaultArtifactRepository(r.getId(),
85                                                                r.getUrl(),
86                                                                new DefaultRepositoryLayout());
87        repos.add(repo);
88        LOG.debug("added repo " + r.getId() + ":"
89                  + r.getUrl());
90      }
91      embedder.resolve(artifact, repos,
92                       embedder.getLocalRepository());
93    } catch (MavenEmbedderException mee) {
94    } catch (ArtifactResolutionException are) {
95    } catch (ArtifactNotFoundException ane) {
96    } finally {
97      configuration = null;
98      validationResult = null;
99    }
100    LOG.info(artifact.getFile().getPath());
101    return artifact.getFile();
102  } else {
103    LOG.error("settings file did not validate !!");
104    if (!validationResult.isUserSettingsFilePresent()) {
105      LOG.warn("The specific user settings file "'  + settings + "' is not present.);
106    } else if (!validationResult.isUserSettingsFileParses()) {
107      LOG.warn("Please check your settings file, it is not well formed XML.");
108    }
109  }
110  return null;
111}
112|#
Note: See TracBrowser for help on using the repository browser.