diff --git a/.gitignore b/.gitignore index 524f096..65b7775 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,11 @@ # Compiled class file *.class +# Build and IDE directories +target +.idea +CHANGELOG.md + # Log file *.log diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 0000000..a15bfa0 --- /dev/null +++ b/.mvn/jvm.config @@ -0,0 +1,6 @@ +--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..28ab91a --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +# Project Contributors + +The following people have provided their time and efforts to help make the ComiXed Python plugin what it is today. + + * Darryl L. Pierce diff --git a/README.md b/README.md index 8258ca9..8da7a77 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ -# comixed-plugin-language-groovy -The Groovy plugin language runtime for ComiXed +# ComiXed Plugin Language Python + +This project provides a language runtime for ComiXed that executes plugins +written in [Groovy](https://groovy-lang.org/). + +It does **not** provide the full Groovy language's runtime libraries. Instead, +it only provides the core **language** interpreter to execute plugins. + +# Status + +[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=comixed_comixed-plugin-language-groovy)](https://sonarcloud.io/dashboard?id=comixed_comixed-plugin-language-groovy)\ +[![Github All Releases](https://img.shields.io/github/downloads/comixed/comixed-plugin-language-groovy/total.svg)](https://github.com/comixed/comixed-plugin-language-groovy/releases) + +# Installation And Configuration + +See the [installation](INSTALLATION.md) file for details. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f1d3c1b --- /dev/null +++ b/pom.xml @@ -0,0 +1,203 @@ + + 4.0.0 + org.comixedproject + comixed-plugin-language-groovy + jar + 0.1-SNAPSHOT + comixed-plugin-language-groovy + https://github.com/comixed/comixed-plugin-language-groovy + + + scm:git:git@github.com:comixed/comixed-plugin-language-groovy.git + scm:git:git@github.com:comixed/comixed-plugin-language-groovy.git + scm:git:git@github.com:comixed/comixed-plugin-language-groovy.git + main + + + + GitHub + https://github.com/comixed/comixed-plugin-language-groovy/issues + + + + 21 + local + 5.1 + comixed + https://sonarcloud.io + https://github.com/comixed/comixed-plugin-language-groovy + https://github.com/comixed/comixed-plugin-language-groovy/issues + ${project.basedir}/src/main/java + 1.18.30 + 2.20.0 + + + + + org.apache.groovy + groovy-all + 5.0.0 + pom + + + org.comixedproject + comixed-plugins + 3.0.3 + + + org.projectlombok + lombok + ${lombok.version} + compile + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + junit + junit + 4.13.2 + test + + + org.mockito + mockito-core + 4.0.0 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + + + + + com.cosium.code + git-code-format-maven-plugin + ${maven-git-code-format.version} + + + install-formatter-hook + + install-hooks + + + + validate-code-format + + validate-code-format + + + + + + com.cosium.code + google-java-format + 4.2 + + + + + maven-clean-plugin + 3.1.0 + + + + ${project.basedir} + CHANGELOG.md + comixed-metadata-comicvine-*.zip + + + + + + maven-clean-plugin + 3.1.0 + + + + ${project.basedir} + CHANGELOG.md + comixed-plugin-language-groovy-*.zip + + + + + + com.github.danielflower.mavenplugins + gitlog-maven-plugin + 1.14.0 + + Changelog for the ComiXed Groovy Language Plugin v0.1-SNAPSHOT + false + ${project.basedir} + true + CHANGELOG.md + false + false + false + false + false + GitHub issue tracker + https://github.com/comixed/comixed/issues + false + yyyy-MM-dd HH:mm:ss Z + (?:Bug|UPDATE|FIX|ADD|NEW|#) ?#?(\d+) + + + + + generate + + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 4.0.0.4121 + + + maven-assembly-plugin + 3.2.0 + + ${project.basedir} + + src/main/assembly/src.xml + + + + + make-assembly + package + + single + + + + + + + diff --git a/src/main/assembly/src.xml b/src/main/assembly/src.xml new file mode 100644 index 0000000..93aef60 --- /dev/null +++ b/src/main/assembly/src.xml @@ -0,0 +1,30 @@ + + ${assembly.name} + + zip + + + + false + + org.comixedproject:comixed-plugin-language-groovy:jar: + org.apache.groovy:groovy:jar: + + + + + + ${project.basedir} + + CHANGELOG.md + CONTRIBUTORS.md + INSTALLATION.md + LICENSE + README.md + CHANGELOG.md + + + + diff --git a/src/main/java/org/comixedproject/plugins/groovy/GroovyPluginRuntime.java b/src/main/java/org/comixedproject/plugins/groovy/GroovyPluginRuntime.java new file mode 100644 index 0000000..e449ff1 --- /dev/null +++ b/src/main/java/org/comixedproject/plugins/groovy/GroovyPluginRuntime.java @@ -0,0 +1,109 @@ +/* + * ComiXed - A digital comic book library management application. + * Copyright (C) 2023, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package org.comixedproject.plugins.groovy; + +import groovy.lang.Binding; +import groovy.lang.GroovyShell; +import groovy.lang.Script; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import lombok.extern.log4j.Log4j2; +import org.comixedproject.model.plugin.LibraryPlugin; +import org.comixedproject.model.plugin.LibraryPluginProperty; +import org.comixedproject.plugins.AbstractPluginRuntime; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * GroovyPluginRuntime provides a runtime environment that loads and executes a Groovy + * plugin. + * + * @author Darryl L. Pierce + */ +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Log4j2 +public class GroovyPluginRuntime extends AbstractPluginRuntime { + @Override + public String getName(final String filename) { + final GroovyShell shell = doCreatePluginShell(); + try { + log.trace("Loading plugin properties: {}", filename); + final Script script = shell.parse(new File(filename)); + return (String) script.invokeMethod("plugin_name", new Object[] {}); + } catch (Exception error) { + log.error("Failed to load plugin properties", error); + return ""; + } + } + + @Override + public String getVersion(final String filename) { + final GroovyShell shell = doCreatePluginShell(); + try { + log.trace("Loading plugin properties: {}", filename); + final Script script = shell.parse(new File(filename)); + return (String) script.invokeMethod("plugin_version", new Object[] {}); + } catch (Exception error) { + log.error("Failed to load plugin properties", error); + return ""; + } + } + + @Override + public List getProperties(final String filename) { + final GroovyShell shell = doCreatePluginShell(); + try { + log.trace("Loading plugin properties: {}", filename); + final Script script = shell.parse(new File(filename)); + return (List) + script.invokeMethod("plugin_properties", new Object[] {}); + } catch (Exception error) { + log.error("Failed to load plugin properties", error); + return new ArrayList<>(); + } + } + + @Override + public Boolean execute(final LibraryPlugin libraryPlugin) { + final var shell = doCreatePluginShell(); + try { + log.trace( + "Executing libraryPlugin: {} v{}", libraryPlugin.getName(), libraryPlugin.getVersion()); + this.getProperties() + .entrySet() + .forEach(entry -> shell.setProperty(entry.getKey(), entry.getValue())); + shell.evaluate(new File(libraryPlugin.getFilename())); + log.trace("LibraryPlugin completed without error"); + return true; + } catch (Exception error) { + log.error("Failed to execute libraryPlugin", error); + return false; + } + } + + private GroovyShell doCreatePluginShell() { + log.trace("Creating plugin binding"); + final Binding binding = new Binding(); + log.trace("Creating plugin runtime shell"); + return new GroovyShell(binding); + } +} diff --git a/src/main/java/org/comixedproject/plugins/groovy/GroovyPluginRuntimeProvider.java b/src/main/java/org/comixedproject/plugins/groovy/GroovyPluginRuntimeProvider.java new file mode 100644 index 0000000..248ec8a --- /dev/null +++ b/src/main/java/org/comixedproject/plugins/groovy/GroovyPluginRuntimeProvider.java @@ -0,0 +1,42 @@ +/* + * ComiXed - A digital comic book library management application. + * Copyright (C) 2023, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package org.comixedproject.plugins.groovy; + +import lombok.extern.log4j.Log4j2; +import org.comixedproject.plugins.PluginRuntime; +import org.comixedproject.plugins.PluginRuntimeProvider; + +/** + * GroovyPluginRuntimeProvider defines a {@link PluginRuntimeProvider} for Groovy. + * + * @author Darryl L. Pierce + */ +@Log4j2 +public class GroovyPluginRuntimeProvider implements PluginRuntimeProvider { + @Override + public PluginRuntime create() { + log.trace("Creating an instance of the Groovy plugin runtime"); + return new GroovyPluginRuntime(); + } + + @Override + public String getName() { + return "groovy"; + } +} diff --git a/src/main/resources/META-INF/services/org.comixedproject.plugins.PluginRuntimeProvider b/src/main/resources/META-INF/services/org.comixedproject.plugins.PluginRuntimeProvider new file mode 100644 index 0000000..aea80a6 --- /dev/null +++ b/src/main/resources/META-INF/services/org.comixedproject.plugins.PluginRuntimeProvider @@ -0,0 +1 @@ +org.comixedproject.plugins.groovy.GroovyPluginRuntimeProvider