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