View Javadoc

1   package com.atlassian.plugin;
2   
3   import com.google.common.collect.ImmutableSet;
4   
5   import java.io.BufferedInputStream;
6   import java.io.File;
7   import java.io.FileInputStream;
8   import java.io.FileNotFoundException;
9   import java.io.InputStream;
10  import java.util.Set;
11  
12  /**
13   * An XML plugin artifact that is just the atlassian-plugin.xml file
14   *
15   * @since 2.1.0
16   */
17  public class XmlPluginArtifact implements PluginArtifact
18  {
19      private final File xmlFile;
20  
21      public XmlPluginArtifact(File xmlFile)
22      {
23          this.xmlFile = xmlFile;
24      }
25  
26      /**
27       * Always returns false, since it doesn't make sense for an XML artifact
28       */
29      public boolean doesResourceExist(String name)
30      {
31          return false;
32      }
33  
34      /**
35       * Always returns null, since it doesn't make sense for an XML artifact
36       */
37      public InputStream getResourceAsStream(String name) throws PluginParseException
38      {
39          return null;
40      }
41  
42      public String getName()
43      {
44          return xmlFile.getName();
45      }
46  
47      /**
48       * @return a buffered file input stream of the file on disk. This input stream
49       * is not resettable.
50       */
51      public InputStream getInputStream()
52      {
53          try
54          {
55              return new BufferedInputStream(new FileInputStream(xmlFile));
56          }
57          catch (FileNotFoundException e)
58          {
59              throw new RuntimeException("Could not find XML file for eading: " + xmlFile, e);
60          }
61      }
62  
63      public File toFile()
64      {
65          return xmlFile;
66      }
67  
68      @Override
69      public boolean containsJavaExecutableCode()
70      {
71          return false;
72      }
73  
74  }