View Javadoc
1   package com.atlassian.plugin;
2   
3   import java.io.BufferedInputStream;
4   import java.io.File;
5   import java.io.FileInputStream;
6   import java.io.FileNotFoundException;
7   import java.io.InputStream;
8   
9   /**
10   * An XML plugin artifact that is just the atlassian-plugin.xml file
11   *
12   * @since 2.1.0
13   */
14  public class XmlPluginArtifact implements PluginArtifact {
15      private final File xmlFile;
16  
17      public XmlPluginArtifact(File xmlFile) {
18          this.xmlFile = xmlFile;
19      }
20  
21      /**
22       * Always returns false, since it doesn't make sense for an XML artifact
23       */
24      public boolean doesResourceExist(String name) {
25          return false;
26      }
27  
28      /**
29       * Always returns null, since it doesn't make sense for an XML artifact
30       */
31      public InputStream getResourceAsStream(String name) throws PluginParseException {
32          return null;
33      }
34  
35      public String getName() {
36          return xmlFile.getName();
37      }
38  
39      /**
40       * @return a buffered file input stream of the file on disk. This input stream
41       * is not resettable.
42       */
43      public InputStream getInputStream() {
44          try {
45              return new BufferedInputStream(new FileInputStream(xmlFile));
46          } catch (FileNotFoundException e) {
47              throw new RuntimeException("Could not find XML file for eading: " + xmlFile, e);
48          }
49      }
50  
51      public File toFile() {
52          return xmlFile;
53      }
54  
55      @Override
56      public boolean containsJavaExecutableCode() {
57          return false;
58      }
59  
60      @Override
61      public boolean containsSpringContext() {
62          return false;
63      }
64  
65      @Override
66      public ReferenceMode getReferenceMode() {
67          // This is the safe default. If we ever need to support reference mode xml plugin artifacts (which is technically
68          // plausible although unlikely to be compelling on disk space grounds alone), we can add a suitable ctor and default.
69          return ReferenceMode.FORBID_REFERENCE;
70      }
71  }