KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > MavenURLBuilder


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant;
8
9
10 import java.io.File JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12 import java.net.URL JavaDoc;
13
14
15 /**
16  * <p>
17  * This class is the implementation of the URLBuilder interface
18  * for Maven URLs.
19  * </p>
20  *
21  * <p>
22  * Maven's URL scheme is
23  * <b>domain</b>/<b>project</b>/jars/<b>name</b>-<b>version</b>.jar
24  * </p>
25  *
26  * @author Brian Pontarelli
27  */

28 public class MavenURLBuilder extends AbstractURLBuilder {
29
30     /**
31      * Builds the URL to the artifact using Maven style URLs.
32      *
33      * @param defaultDomain The default domain to use while building the URL
34      * @param mapping (optional) Mapping file that might override the default
35      * domain URL
36      * @param artifact The artifact to build the URL for
37      * @return The URL or null if it couldn't be built (default domain was null
38      * or something)
39      * @throws SavantException If the URL could not be built
40      */

41     public URL JavaDoc buildURL(String JavaDoc defaultDomain, File JavaDoc mapping, Artifact artifact)
42     throws SavantException {
43         String JavaDoc baseURL = makeBaseURLSpec(defaultDomain, mapping, artifact);
44         URL JavaDoc url = null;
45         if (baseURL != null) {
46             String JavaDoc urlSpec = baseURL + "/" + makeURLSpec(artifact);
47             try {
48                 url = new URL JavaDoc(urlSpec);
49             } catch (MalformedURLException JavaDoc mue) {
50                 throw new SavantException(mue);
51             }
52         }
53
54         return url;
55     }
56
57     /**
58      * Builds the URL to the MD5 for the artifact using Maven style URLs.
59      *
60      * @param defaultDomain The default domain to use while building the URL
61      * @param mapping (optional) Mapping file that might override the default
62      * domain URL
63      * @param artifact The artifact to build the URL for
64      * @return The URL or null if it couldn't be built (default domain was null
65      * or something)
66      * @throws SavantException If the URL could not be built
67      */

68     public URL JavaDoc buildMD5URL(String JavaDoc defaultDomain, File JavaDoc mapping, Artifact artifact)
69     throws SavantException {
70         String JavaDoc baseURL = makeBaseURLSpec(defaultDomain, mapping, artifact);
71         URL JavaDoc url = null;
72         if (baseURL != null) {
73             String JavaDoc urlSpec = baseURL + "/" + makeURLSpec(artifact) + ".md5";
74             try {
75                 url = new URL JavaDoc(urlSpec);
76             } catch (MalformedURLException JavaDoc mue) {
77                 throw new SavantException(mue);
78             }
79         }
80
81         return url;
82     }
83
84     /**
85      * Maven doesn't handle per-artifact dependencies, therefore this always
86      * returns null.
87      *
88      * @param artifact The artifact to build the URL for
89      * @param defaultDomain The default domain URL specification (base URL)
90      * @param mapping A Mapping file that can be used to map groups to base URLs
91      * to override the default
92      * @return The XML dependency URL or null if one could not be built
93      */

94     public URL JavaDoc buildDepsURL(String JavaDoc defaultDomain, File JavaDoc mapping,
95             Artifact artifact)
96     throws SavantException {
97         return null;
98     }
99
100     /**
101      * Makes the URL additions specifically for Savant URLs.
102      *
103      * @param artifact The artifact to build the URL for
104      * @return The url and never null
105      */

106     private String JavaDoc makeURLSpec(Artifact artifact) {
107         return artifact.getProjectname() + "/jars/" + artifact.getName() + "-" +
108             artifact.getVersion() + ".jar";
109     }
110 }
111
Popular Tags