1 package com.atlassian.plugin;
2
3 import java.io.File;
4 import java.net.URI;
5
6 import static com.atlassian.plugin.PluginArtifact.AllowsReference.ReferenceMode;
7
8
9
10
11
12
13 public class DefaultPluginArtifactFactory implements PluginArtifactFactory
14 {
15
16
17
18
19 final ReferenceMode referenceMode;
20
21
22
23
24 public DefaultPluginArtifactFactory()
25 {
26 this(ReferenceMode.FORBID_REFERENCE);
27 }
28
29
30
31
32
33
34
35 public DefaultPluginArtifactFactory(ReferenceMode referenceMode)
36 {
37 this.referenceMode = referenceMode;
38 }
39
40
41
42
43
44
45
46
47 public PluginArtifact create(URI artifactUri)
48 {
49 PluginArtifact artifact = null;
50
51 String protocol = artifactUri.getScheme();
52
53 if ("file".equalsIgnoreCase(protocol))
54 {
55 File artifactFile = new File(artifactUri);
56
57 String file = artifactFile.getName();
58 if (file.endsWith(".jar"))
59 {
60 artifact = new JarPluginArtifact(artifactFile, referenceMode);
61 }
62 else if (file.endsWith(".xml"))
63 {
64 artifact = new XmlPluginArtifact(artifactFile);
65 }
66 }
67
68 if (artifact == null)
69 {
70 throw new IllegalArgumentException("The artifact URI " + artifactUri + " is not a valid plugin artifact");
71 }
72
73 return artifact;
74 }
75 }