1 package com.atlassian.plugin;
2
3 import java.io.File;
4 import java.net.URISyntaxException;
5 import java.net.URL;
6
7
8
9
10
11
12 public class DefaultPluginArtifactFactory implements PluginArtifactFactory
13 {
14
15
16
17
18
19
20
21 public PluginArtifact create(URL artifactUrl)
22 {
23 PluginArtifact artifact = null;
24 String protocol = artifactUrl.getProtocol();
25 if ("file".equalsIgnoreCase(protocol))
26 {
27 File artifactFile;
28 try
29 {
30 artifactFile = new File(artifactUrl.toURI());
31 } catch (URISyntaxException e)
32 {
33 throw new IllegalArgumentException("Invalid artifact URI: "+artifactUrl, e);
34 }
35 String file = artifactUrl.getFile();
36 if (file.endsWith(".jar"))
37 artifact = new JarPluginArtifact(artifactFile);
38 else if (file.endsWith(".xml"))
39 artifact = new XmlPluginArtifact(artifactFile);
40 }
41
42 if (artifact == null)
43 throw new IllegalArgumentException("The artifact URI "+artifactUrl+" is not a valid plugin artifact");
44
45 return artifact;
46 }
47 }