View Javadoc

1   package com.atlassian.plugin;
2   
3   import java.io.File;
4   import java.net.URI;
5   
6   /**
7    * Creates plugin artifacts by handling URI's that are files and looking at the file's extension
8    *
9    * @since 2.1.0
10   */
11  public class DefaultPluginArtifactFactory implements PluginArtifactFactory
12  {
13      /**
14       * Creates the artifact by looking at the file extension
15       *
16       * @param artifactUri The artifact URI
17       * @return The created artifact
18       * @throws IllegalArgumentException If an artifact cannot be created from the URL
19       */
20      public PluginArtifact create(URI artifactUri)
21      {
22          PluginArtifact artifact = null;
23  
24          String protocol = artifactUri.getScheme();
25  
26          if ("file".equalsIgnoreCase(protocol))
27          {
28              File artifactFile = new File(artifactUri);
29             
30              String file = artifactFile.getName();
31              if (file.endsWith(".jar"))
32                  artifact = new JarPluginArtifact(artifactFile);
33              else if (file.endsWith(".xml"))
34                  artifact = new XmlPluginArtifact(artifactFile);
35          }
36  
37          if (artifact == null)
38              throw new IllegalArgumentException("The artifact URI " + artifactUri + " is not a valid plugin artifact");
39          
40          return artifact;
41      }
42  }