1 package com.atlassian.plugin;
2
3 import java.io.InputStream;
4 import java.io.File;
5
6 /**
7 * Allows the retrieval of files and/or an input stream of a plugin artifact. Implementations
8 * must allow multiple calls to {@link #getInputStream()}.
9 *
10 * @see PluginController
11 * @since 2.0.0
12 */
13 public interface PluginArtifact
14 {
15 /**
16 * @return true if the resource exists in this artifact, otherwise false
17 * @since 2.2.0
18 */
19 boolean doesResourceExist(String name);
20
21 /**
22 * @return an input stream of the resource specified inside the artifact. Null if the resource cannot be found.
23 * @throws PluginParseException if the there was an exception retrieving the resource from the artifact
24 */
25 InputStream getResourceAsStream(String name) throws PluginParseException;
26
27 /**
28 * @return the original name of the plugin artifact file. Typically used
29 * for persisting it to disk with a meaningful name.
30 */
31 String getName();
32
33 /**
34 * @return an InputStream for the entire plugin artifact. Calling this
35 * multiple times will return a fresh input stream each time.
36 */
37 InputStream getInputStream();
38
39 /**
40 * @return the artifact as a file, or its underlying file if it is already one
41 * @since 2.2.0
42 */
43 File toFile();
44
45 /**
46 * @return {@code true} if the plugin contains or references java executable code.
47 * @since 3.0
48 */
49 boolean containsJavaExecutableCode();
50
51 /**
52 * Additional interface for a plugin artifact which may support reference installation.
53 */
54 interface AllowsReference
55 {
56 /**
57 * Query whether or not the PluginArtifact may be reference installed.
58 *
59 * @return true iff the artifact may be reference installed.
60 */
61 boolean allowsReference();
62
63 /**
64 * Host class for a static accessor which defaults allowsReference to false.
65 */
66 class Default
67 {
68 /**
69 * Determine if a PluginArtifact allows reference installation.
70 *
71 * If the PluginArtifact supports AllowsReference, it's allowsReference is queried, otherwise
72 * it defaults to false.
73 *
74 * @param pluginArtifact the plugin artifact to check.
75 * @return true iff a reference install should be attempted for pluginArtifact.
76 */
77 public static boolean allowsReference(PluginArtifact pluginArtifact)
78 {
79 return (pluginArtifact instanceof PluginArtifact.AllowsReference) &&
80 ((PluginArtifact.AllowsReference) pluginArtifact).allowsReference();
81 }
82 }
83 }
84 }