Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Compiled class file
*.class

# Build and IDE directories
target
.idea
CHANGELOG.md

# Log file
*.log

Expand Down
6 changes: 6 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -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 <mcpierce@gmail.com>
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
203 changes: 203 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.comixedproject</groupId>
<artifactId>comixed-plugin-language-groovy</artifactId>
<packaging>jar</packaging>
<version>0.1-SNAPSHOT</version>
<name>comixed-plugin-language-groovy</name>
<url>https://github.com/comixed/comixed-plugin-language-groovy</url>

<scm>
<connection>scm:git:git@github.com:comixed/comixed-plugin-language-groovy.git</connection>
<developerConnection>scm:git:git@github.com:comixed/comixed-plugin-language-groovy.git</developerConnection>
<url>scm:git:git@github.com:comixed/comixed-plugin-language-groovy.git</url>
<tag>main</tag>
</scm>

<issueManagement>
<system>GitHub</system>
<url>https://github.com/comixed/comixed-plugin-language-groovy/issues</url>
</issueManagement>

<properties>
<java.version>21</java.version>
<assembly.name>local</assembly.name>
<maven-git-code-format.version>5.1</maven-git-code-format.version>
<sonar.organization>comixed</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.links.scm>https://github.com/comixed/comixed-plugin-language-groovy</sonar.links.scm>
<sonar.links.issue>https://github.com/comixed/comixed-plugin-language-groovy/issues</sonar.links.issue>
<sonar.sources>${project.basedir}/src/main/java</sonar.sources>
<lombok.version>1.18.30</lombok.version>
<log4j.version>2.20.0</log4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>5.0.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.comixedproject</groupId>
<artifactId>comixed-plugins</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>${maven-git-code-format.version}</version>
<executions>
<execution>
<id>install-formatter-hook</id>
<goals>
<goal>install-hooks</goal>
</goals>
</execution>
<execution>
<id>validate-code-format</id>
<goals>
<goal>validate-code-format</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.cosium.code</groupId>
<artifactId>google-java-format</artifactId>
<version>4.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}</directory>
<includes>CHANGELOG.md</includes>
<includes>comixed-metadata-comicvine-*.zip</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}</directory>
<includes>CHANGELOG.md</includes>
<includes>comixed-plugin-language-groovy-*.zip</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>com.github.danielflower.mavenplugins</groupId>
<artifactId>gitlog-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<reportTitle>Changelog for the ComiXed Groovy Language Plugin v0.1-SNAPSHOT</reportTitle>
<verbose>false</verbose>
<outputDirectory>${project.basedir}</outputDirectory>
<generateMarkdownChangeLog>true</generateMarkdownChangeLog>
<markdownChangeLogFilename>CHANGELOG.md</markdownChangeLogFilename>
<generateSimpleHTMLChangeLog>false</generateSimpleHTMLChangeLog>
<generatePlainTextChangeLog>false</generatePlainTextChangeLog>
<generateAsciidocChangeLog>false</generateAsciidocChangeLog>
<generateJSONChangeLog>false</generateJSONChangeLog>
<generateHTMLTableOnlyChangeLog>false</generateHTMLTableOnlyChangeLog>
<issueManagementSystem>GitHub issue tracker</issueManagementSystem>
<issueManagementUrl>https://github.com/comixed/comixed/issues</issueManagementUrl>
<fullGitMessage>false</fullGitMessage>
<dateFormat>yyyy-MM-dd HH:mm:ss Z</dateFormat>
<bugzillaPattern>(?:Bug|UPDATE|FIX|ADD|NEW|#) ?#?(\d+)</bugzillaPattern>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>4.0.0.4121</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<descriptors>
<descriptor>src/main/assembly/src.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
30 changes: 30 additions & 0 deletions src/main/assembly/src.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>${assembly.name}</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<includes>
<include>org.comixedproject:comixed-plugin-language-groovy:jar:</include>
<include>org.apache.groovy:groovy:jar:</include>
</includes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>CHANGELOG.md</include>
<include>CONTRIBUTORS.md</include>
<include>INSTALLATION.md</include>
<include>LICENSE</include>
<include>README.md</include>
<include>CHANGELOG.md</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses>
*/

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;

/**
* <code>GroovyPluginRuntime</code> 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<LibraryPluginProperty> 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<LibraryPluginProperty>)
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);
}
}
Loading