commit df545f4fc89a706003b939b32d4f0bae1574dca5 Author: Xor Boole Date: Fri Feb 20 19:52:58 2015 -0500 Initial Commit diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..88f0cf8 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +PluginAnnotations \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..1238a1f --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..74c0d0a --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/libraries/Maven__com_google_guava_guava_17_0.xml b/.idea/libraries/Maven__com_google_guava_guava_17_0.xml new file mode 100644 index 0000000..2a9069c --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_guava_17_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml new file mode 100644 index 0000000..f3f3738 --- /dev/null +++ b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml b/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml new file mode 100644 index 0000000..2ec8376 --- /dev/null +++ b/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml b/.idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml new file mode 100644 index 0000000..e60370e --- /dev/null +++ b/.idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_10.xml b/.idea/libraries/Maven__junit_junit_4_10.xml new file mode 100644 index 0000000..ed8bf5f --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_10.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml b/.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml new file mode 100644 index 0000000..91f161a --- /dev/null +++ b/.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_bukkit_bukkit_1_8_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_bukkit_bukkit_1_8_R0_1_SNAPSHOT.xml new file mode 100644 index 0000000..624897d --- /dev/null +++ b/.idea/libraries/Maven__org_bukkit_bukkit_1_8_R0_1_SNAPSHOT.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml new file mode 100644 index 0000000..acdf443 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_yaml_snakeyaml_1_14.xml b/.idea/libraries/Maven__org_yaml_snakeyaml_1_14.xml new file mode 100644 index 0000000..d9fbe59 --- /dev/null +++ b/.idea/libraries/Maven__org_yaml_snakeyaml_1_14.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3a32f24 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..aa8be29 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e5453c4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,764 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + 1424030427326 + 1424030427326 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + MayhemData + + + + + + + + 1.7 + + + + + + + + PluginAnnotations + + + + + + + + 1.7 + + + + + + + + + + + + + + + + diff --git a/PluginAnnotations.iml b/PluginAnnotations.iml new file mode 100644 index 0000000..d979331 --- /dev/null +++ b/PluginAnnotations.iml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..47f56c1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,119 @@ + + 4.0.0 + + + org.sonatype.oss + oss-parent + 9 + + + org.bukkit + plugin-annotations + 1.0.0-SNAPSHOT + jar + + Plugin Annotations + http://www.spigotmc.org/ + A annotaion-based compiletime plugin.yml generator. + + + 1.6 + 1.6 + UTF-8 + + + + + + spigotmc-releases + https://hub.spigotmc.org/nexus/content/repositories/releases/ + + + spigotmc-releases + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + spigotmc-public + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + + org.bukkit + bukkit + 1.8-R0.1-SNAPSHOT + compile + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 3.1 + + + eclipse + + true + + + + + org.codehaus.plexus + plexus-compiler-eclipse + 2.5.0-spigotmc + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + 1.13 + + + process-classes + + check + + + + + + org.codehaus.mojo.signature + java16 + 1.1 + + + + + + + src/main/resources/META-INF + META-INF + + + + \ No newline at end of file diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Author.java b/src/main/java/org/bukkit/plugin/java/annotation/Author.java new file mode 100644 index 0000000..d226d7d --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Author.java @@ -0,0 +1,18 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the author(s) of the plugin. Translates to {@code author} + * in plugin.yml if a single author, otherwise {@code authors} + */ + +@Target(ElementType.TYPE) +public @interface Author { + + public String[] value(); + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Commands.java b/src/main/java/org/bukkit/plugin/java/annotation/Commands.java new file mode 100644 index 0000000..c730b59 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Commands.java @@ -0,0 +1,52 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents a list of this plugin's registered commands. + */ + +@Target(ElementType.TYPE) +public @interface Commands { // TODO: in java 8, make repeatable. + + public Cmd[] value(); + + @Target({}) + public static @interface Cmd { + + /** + * This command's name. + */ + public String value(); + + /** + * This command's description. + */ + + public String desc() default ""; + + /** + * This command's aliases. + */ + public String[] aliases() default {}; + + /** + * This command's permission node. + */ + public String permission() default ""; + + /** + * This command's permission-check-fail message. + */ + public String permissionMessage() default ""; + + /** + * This command's usage message. + */ + public String usage() default ""; + } + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/DependsOn.java b/src/main/java/org/bukkit/plugin/java/annotation/DependsOn.java new file mode 100644 index 0000000..892a267 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/DependsOn.java @@ -0,0 +1,17 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the plugin's hard dependencies. + */ + +@Target(ElementType.TYPE) +public @interface DependsOn { + + public String[] value(); + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Description.java b/src/main/java/org/bukkit/plugin/java/annotation/Description.java new file mode 100644 index 0000000..4595d06 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Description.java @@ -0,0 +1,17 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents a short description for the plugin. + */ + +@Target(ElementType.TYPE) +public @interface Description { + + public String value(); + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/LoadBefore.java b/src/main/java/org/bukkit/plugin/java/annotation/LoadBefore.java new file mode 100644 index 0000000..d0802f4 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/LoadBefore.java @@ -0,0 +1,17 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the plugins this plugin should be loaded before + */ + +@Target(ElementType.TYPE) +public @interface LoadBefore { + + public String[] value(); + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/LoadOn.java b/src/main/java/org/bukkit/plugin/java/annotation/LoadOn.java new file mode 100644 index 0000000..9e5372d --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/LoadOn.java @@ -0,0 +1,18 @@ +package org.bukkit.plugin.java.annotation; + +import org.bukkit.plugin.PluginLoadOrder; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the optional load order of the plugin. + */ + +@Target(ElementType.TYPE) +public @interface LoadOn { + + public PluginLoadOrder value(); +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/LogPrefix.java b/src/main/java/org/bukkit/plugin/java/annotation/LogPrefix.java new file mode 100644 index 0000000..e8d6ed4 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/LogPrefix.java @@ -0,0 +1,16 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the prefix used for the plugin's log entries, defaults to plugin name. + */ + +@Target(ElementType.TYPE) +public @interface LogPrefix { + + public String value(); +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Main.java b/src/main/java/org/bukkit/plugin/java/annotation/Main.java new file mode 100644 index 0000000..ebef467 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Main.java @@ -0,0 +1,55 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Marks this class (which must subclass JavaPlugin) as this plugin's main class. + *

+ * This class is part of the plugin annotation framework that automates plugin.yml. + *

+ * Example: + *

+ * {@literal @}Main
+ * {@literal @}Name("Test")
+ * {@literal @}Version("v1.0")
+ * {@literal @}Description("A test plugin.")
+ * {@literal @}LoadOn(PluginLoadOrder.POSTWORLD)
+ * {@literal @}Author("md_5")
+ * {@literal @}Website("spigotmc.org")
+ * {@literal @}UsesDatabase
+ * {@literal @}DependsOn({"WorldEdit", "Towny"})
+ * {@literal @}SoftDependsOn("Vault")
+ * {@literal @}LogPrefix("Testing")
+ * {@literal @}LoadBefore("Essentials")
+ * {@literal @}Commands({
+ *     {@literal @}Cmd(
+ *         value = "foo",
+ *         desc = "Foo command",
+ *         aliases = {"foobar", "fubar"},
+ *         permission = "test.foo",
+ *         permissionMessage = "You do not have permission!",
+ *         usage = "/ [test|stop]"
+ *     ),
+ *     {@literal @}Cmd("bar")
+ * })
+ * {@literal @}Permissions({
+ *     {@literal @}Perm(
+ *         value = "test.foo",
+ *         desc = "Allows foo command",
+ *         defaultValue = PermissionDefault.OP,
+ *     ),
+ *     {@literal @}Perm(
+ *         value = "test.*",
+ *         desc = "Wildcard perm",
+ *         defaultValue = PermissionDefault.OP,
+ *         children = {"test.foo"}
+ *     )
+ * })
+ * public class Test extends JavaPlugin { ... }
+ * 
+ * 
+ */ + +@Target(ElementType.TYPE) +public @interface Main {} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Name.java b/src/main/java/org/bukkit/plugin/java/annotation/Name.java new file mode 100644 index 0000000..2ef196b --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Name.java @@ -0,0 +1,18 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the name of the plugin. + *

+ * If not present in a class annotated with {@link Main} the name defaults to Class.getSimpleName() and will emmit a warning. + */ + +@Target(ElementType.TYPE) +public @interface Name { + + public String value(); +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Permissions.java b/src/main/java/org/bukkit/plugin/java/annotation/Permissions.java new file mode 100644 index 0000000..c6097c3 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Permissions.java @@ -0,0 +1,50 @@ +package org.bukkit.plugin.java.annotation; + +import org.bukkit.permissions.PermissionDefault; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents a list of this plugin's registered permissions. + */ + +@Target(ElementType.TYPE) +public @interface Permissions { // TODO: in java 8, make repeatable. + + public Perm[] value(); + + @Target({}) + public static @interface Perm { + + /** + * This perm's name. + */ + public String value(); + + /** + * This perm's description. + */ + + public String desc() default ""; + + /** + * This perm's default. + */ + public PermissionDefault defaultValue() default PermissionDefault.OP; + + /** + * This perm's child nodes + */ + public String[] children() default {}; + + /** + * This perms's negated child nodes + */ + public String[] antichildren() default {}; + + } + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java new file mode 100644 index 0000000..9266c97 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java @@ -0,0 +1,194 @@ +package org.bukkit.plugin.java.annotation; + +import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.plugin.java.JavaPlugin; +import org.yaml.snakeyaml.Yaml; + +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.StandardLocation; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +@SupportedAnnotationTypes("org.bukkit.plugin.java.annotation.*") +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class PluginAnnotationProcessor extends AbstractProcessor { + + private boolean hasMainBeenFound = false; + + private static final DateFormat dFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + @Override + public boolean process(Set annots, RoundEnvironment rEnv) { + Element main = null; + for(Element el : rEnv.getElementsAnnotatedWith(Main.class)) { + if(main != null){ + raiseError("More than one class with @Main found, aborting!"); + return false; + } + main = el; + } + + if(main == null) return false; + + if(hasMainBeenFound){ + raiseError("More than one class with @Main found, aborting!"); + return false; + } + hasMainBeenFound = true; + + TypeElement mainType; + if(main instanceof TypeElement){ + mainType = (TypeElement) main; + } else { + raiseError("Element annotated with @Main is not a type!"); + return false; + } + + if(!(mainType.getEnclosingElement() instanceof PackageElement) && !mainType.getModifiers().contains(Modifier.STATIC)){ + raiseError("Element annotated with @Main is not top-level or static nested!"); + return false; + } + + if(!processingEnv.getTypeUtils().isSubtype(mainType.asType(), fromClass(JavaPlugin.class))){ + raiseError("Class annotated with @Main is not an subclass of JavaPlugin!"); + } + + Map yml = new HashMap(); + + final String mainName = mainType.getQualifiedName().toString(); + yml.put("main", mainName); + + processAndPut(yml, "name", mainType, mainName.substring(mainName.lastIndexOf('.') + 1), Name.class, String.class); + + processAndPut(yml, "version", mainType, Version.DEFAULT_VERSION, Version.class, String.class); + + processAndPut(yml, "description", mainType, null, Description.class, String.class); + + processAndPut(yml, "load", mainType, null, LoadOn.class, String.class); + + { + String[] authors = process(mainType, new String[0], Author.class, String[].class); + switch(authors.length) { + case 0: break; + case 1: yml.put("author", authors[0]); break; + default: yml.put("authors", authors); break; + } + } + + processAndPut(yml, "website", mainType, null, Website.class, String.class); + + if(mainType.getAnnotation(UsesDatabase.class) != null) yml.put("database", true); + + processAndPut(yml, "depend", mainType, null, DependsOn.class, String[].class); + + processAndPut(yml, "softdepend", mainType, null, SoftDependsOn.class, String[].class); + + processAndPut(yml, "prefix", mainType, null, LogPrefix.class, String.class); + + processAndPut(yml, "loadbefore", mainType, null, LoadBefore.class, String[].class); + + Commands.Cmd[] commands = process(mainType, new Commands.Cmd[0], Commands.class, Commands.Cmd[].class); + + Map commandMap = new HashMap(); + + for(Commands.Cmd cmd : commands) { + String name = cmd.value(); + Map desc = new HashMap(); + if(!cmd.desc().isEmpty()) desc.put("description", cmd.desc()); + if(cmd.aliases().length != 0) desc.put("aliases", cmd.aliases()); + if(!cmd.permission().isEmpty()) desc.put("permission", cmd.permission()); + if(!cmd.permissionMessage().isEmpty()) desc.put("permission-message", cmd.permissionMessage()); + if(!cmd.usage().isEmpty()) desc.put("usage", cmd.usage()); + commandMap.put(name, desc); + } + + if(!commandMap.isEmpty()) yml.put("commands", commandMap); + + Permissions.Perm[] perms = process(mainType, new Permissions.Perm[0], Permissions.class, Permissions.Perm[].class); + + Map permMap = new HashMap(); + + for(Permissions.Perm perm : perms) { + String name = perm.value(); + Map desc = new HashMap(); + if(!perm.desc().isEmpty()) desc.put("description", perm.desc()); + desc.put("default", perm.defaultValue().toString()); + Map children = new HashMap(); + for(String p : perm.children()) children.put(p, true); + for(String p : perm.antichildren()) children.put(p, false); + if(!children.isEmpty()) desc.put("children", children); + permMap.put(name, desc); + } + + if(!permMap.isEmpty()) yml.put("permissions", permMap); + + Yaml yaml = new Yaml(); + + try { + FileObject file = this.processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "plugin.yml"); + Writer w = file.openWriter(); + try{ + w.append("# Auto-generated plugin.yml, generated at ").append(dFormat.format(new Date())).append(" by ").append(this.getClass().getName()).append("\n\n"); + yaml.dump(yml, w); + } finally { + w.flush(); + w.close(); + } + + } catch (IOException e) { + throw new RuntimeException(e); + } + + processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "NOTE: You are using org.bukkit.plugin.java.annotation, an experimental API!"); + + return true; + } + + private void raiseError(String message) { + this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message); + } + + private TypeMirror fromClass(Class clazz) { + return processingEnv.getElementUtils().getTypeElement(clazz.getName()).asType(); + } + + private R processAndPut( + Map map, String name, Element el, R defaultVal, Class annotationType, Class returnType) { + R result = process(el, defaultVal, annotationType, returnType); + if(result != null) + map.put(name, result); + return result; + } + private R process(Element el, R defaultVal, Class annotationType, Class returnType) { + R result; + A ann = el.getAnnotation(annotationType); + if(ann == null) result = defaultVal; + else { + try { + Method value = annotationType.getMethod("value"); + Object res = value.invoke(ann); + result = (R) (returnType == String.class ? res.toString() : returnType.cast(res)); + } catch (Exception e) { + throw new RuntimeException(e); // shouldn't happen in theory + } + } + return result; + } +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/SoftDependsOn.java b/src/main/java/org/bukkit/plugin/java/annotation/SoftDependsOn.java new file mode 100644 index 0000000..81e8662 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/SoftDependsOn.java @@ -0,0 +1,17 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the plugin's soft dependencies. + */ + +@Target(ElementType.TYPE) +public @interface SoftDependsOn { + + public String[] value(); + +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/UsesDatabase.java b/src/main/java/org/bukkit/plugin/java/annotation/UsesDatabase.java new file mode 100644 index 0000000..e73ebfc --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/UsesDatabase.java @@ -0,0 +1,13 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Denotes this plugin as using Bukkit's bundled database system. + */ + +@Target(ElementType.TYPE) +public @interface UsesDatabase {} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Version.java b/src/main/java/org/bukkit/plugin/java/annotation/Version.java new file mode 100644 index 0000000..2d7ab66 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Version.java @@ -0,0 +1,20 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the version of the plugin. + *

+ * If not present in a class annotated with {@link Main} the name defaults to "v0.0" and will emmit a warning. + */ + +@Target(ElementType.TYPE) +public @interface Version { + + public String value(); + + public static final String DEFAULT_VERSION = "v0.0"; +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/Website.java b/src/main/java/org/bukkit/plugin/java/annotation/Website.java new file mode 100644 index 0000000..385483f --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/Website.java @@ -0,0 +1,17 @@ +package org.bukkit.plugin.java.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the website of the plugin. + */ + +@Target(ElementType.TYPE) +public @interface Website { + + public String value(); + +} \ No newline at end of file diff --git a/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..387e75c --- /dev/null +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.bukkit.plugin.java.annotation.PluginAnnotationProcessor diff --git a/target/classes/META-INF/services/javax.annotation.processing.Processor b/target/classes/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..387e75c --- /dev/null +++ b/target/classes/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.bukkit.plugin.java.annotation.PluginAnnotationProcessor diff --git a/target/classes/org/bukkit/plugin/java/annotation/Author.class b/target/classes/org/bukkit/plugin/java/annotation/Author.class new file mode 100644 index 0000000..1cc34d5 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Author.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Commands$Cmd.class b/target/classes/org/bukkit/plugin/java/annotation/Commands$Cmd.class new file mode 100644 index 0000000..2dc72f5 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Commands$Cmd.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Commands.class b/target/classes/org/bukkit/plugin/java/annotation/Commands.class new file mode 100644 index 0000000..3d32d72 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Commands.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/DependsOn.class b/target/classes/org/bukkit/plugin/java/annotation/DependsOn.class new file mode 100644 index 0000000..36da70c Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/DependsOn.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Description.class b/target/classes/org/bukkit/plugin/java/annotation/Description.class new file mode 100644 index 0000000..be254d1 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Description.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/LoadBefore.class b/target/classes/org/bukkit/plugin/java/annotation/LoadBefore.class new file mode 100644 index 0000000..9b5f5a1 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/LoadBefore.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/LoadOn.class b/target/classes/org/bukkit/plugin/java/annotation/LoadOn.class new file mode 100644 index 0000000..f260a92 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/LoadOn.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/LogPrefix.class b/target/classes/org/bukkit/plugin/java/annotation/LogPrefix.class new file mode 100644 index 0000000..e678a78 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/LogPrefix.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Main.class b/target/classes/org/bukkit/plugin/java/annotation/Main.class new file mode 100644 index 0000000..76ef4dd Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Main.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Name.class b/target/classes/org/bukkit/plugin/java/annotation/Name.class new file mode 100644 index 0000000..8119a13 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Name.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Permissions$Perm.class b/target/classes/org/bukkit/plugin/java/annotation/Permissions$Perm.class new file mode 100644 index 0000000..28fc5c7 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Permissions$Perm.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Permissions.class b/target/classes/org/bukkit/plugin/java/annotation/Permissions.class new file mode 100644 index 0000000..5559370 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Permissions.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.class b/target/classes/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.class new file mode 100644 index 0000000..2fb1a5c Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/SoftDependsOn.class b/target/classes/org/bukkit/plugin/java/annotation/SoftDependsOn.class new file mode 100644 index 0000000..bb83d97 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/SoftDependsOn.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/UsesDatabase.class b/target/classes/org/bukkit/plugin/java/annotation/UsesDatabase.class new file mode 100644 index 0000000..69d6cb2 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/UsesDatabase.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Version.class b/target/classes/org/bukkit/plugin/java/annotation/Version.class new file mode 100644 index 0000000..a8e3a21 Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Version.class differ diff --git a/target/classes/org/bukkit/plugin/java/annotation/Website.class b/target/classes/org/bukkit/plugin/java/annotation/Website.class new file mode 100644 index 0000000..fb2dc7f Binary files /dev/null and b/target/classes/org/bukkit/plugin/java/annotation/Website.class differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..4716c8f --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri Feb 20 19:51:13 EST 2015 +version=1.0.0-SNAPSHOT +groupId=org.bukkit +artifactId=plugin-annotations diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..d1fddfb --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,17 @@ +org/bukkit/plugin/java/annotation/Version.class +org/bukkit/plugin/java/annotation/Commands$Cmd.class +org/bukkit/plugin/java/annotation/Permissions.class +org/bukkit/plugin/java/annotation/Main.class +org/bukkit/plugin/java/annotation/DependsOn.class +org/bukkit/plugin/java/annotation/Author.class +org/bukkit/plugin/java/annotation/Permissions$Perm.class +org/bukkit/plugin/java/annotation/Description.class +org/bukkit/plugin/java/annotation/Name.class +org/bukkit/plugin/java/annotation/Commands.class +org/bukkit/plugin/java/annotation/UsesDatabase.class +org/bukkit/plugin/java/annotation/SoftDependsOn.class +org/bukkit/plugin/java/annotation/LoadOn.class +org/bukkit/plugin/java/annotation/LogPrefix.class +org/bukkit/plugin/java/annotation/Website.class +org/bukkit/plugin/java/annotation/LoadBefore.class +org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..a87a200 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,15 @@ +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Main.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/LogPrefix.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/UsesDatabase.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/LoadOn.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Permissions.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Website.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Description.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/LoadBefore.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Commands.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/DependsOn.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Name.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Author.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/Version.java +/Users/xor/PluginsWorkspace/misc/PluginAnnotations/src/main/java/org/bukkit/plugin/java/annotation/SoftDependsOn.java diff --git a/target/plugin-annotations-1.0.0-SNAPSHOT.jar b/target/plugin-annotations-1.0.0-SNAPSHOT.jar new file mode 100644 index 0000000..6cedd20 Binary files /dev/null and b/target/plugin-annotations-1.0.0-SNAPSHOT.jar differ