Skip to content

Commit

Permalink
Add a Maven Archetype for creating new Trino plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Feb 21, 2024
1 parent 3638d7c commit 9c2efbd
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 5 deletions.
35 changes: 35 additions & 0 deletions docs/src/main/sphinx/develop/spi-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,41 @@ of a library that Trino uses internally.
For an example `pom.xml` file, see the example HTTP connector in the
`plugin/trino-example-http` directory in the Trino source tree.

## Building plugins via Maven Archetype

To generate a complete example plugin Maven project, use the Maven Archetype.
It will require the following parameters:

* `archetypeVersion` should match a released Trino version
* `groupId` and `artifactId` are chosen by the plugin author
* `classPrefix` is used as the prefix for all Java classes in the plugin
* `connectorName` is used as the name of the connector

After creating the project, it also needs to be initialized as a git repository
and commited, before it can be built. Example:

```bash
mvn archetype:generate \
-DarchetypeGroupId=io.trino \
-DarchetypeArtifactId=trino-plugin-archetype \
-DarchetypeVersion=$trinoVersion \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-DclassPrefix=$classPrefix \
-DconnectorName=$connectorName

cd $artifactId
git init
git add --all .
git commit -m "Initial commit"

mvn clean package
```

The example connector provides a single table with 3 columns and queries
for table table return a single row. To change that, start with modifying
the `ExampleMetadata` and `ExampleRecordSetProvider` classes.

## Deploying a custom plugin

Because Trino plugins use the `trino-plugin` packaging type, building
Expand Down
5 changes: 0 additions & 5 deletions plugin/trino-example-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@
<artifactId>trino-maven-plugin</artifactId>
<version>13</version>
<extensions>true</extensions>
<configuration>
<pluginClassName>io.trino.spi.Plugin</pluginClassName>
<spiGroupId>io.trino</spiGroupId>
<spiArtifactId>trino-spi</spiArtifactId>
</configuration>
</plugin>

<plugin>
Expand Down
11 changes: 11 additions & 0 deletions plugin/trino-plugin-archetype-builder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
3 changes: 3 additions & 0 deletions plugin/trino-plugin-archetype-builder/archetype.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
excludePatterns=*.iml,interpolated-pom.xml,build.log
connectorName=example_connector
classPrefix=Example
162 changes: 162 additions & 0 deletions plugin/trino-plugin-archetype-builder/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.trino</groupId>
<artifactId>trino-root</artifactId>
<version>440-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>trino-plugin-archetype-builder</artifactId>
<packaging>pom</packaging>
<description>Trino - Maven Archetype Builder for Trino Plugins</description>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-example-plugin</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-sources</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/trino-example-plugin</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/../trino-example-plugin</directory>
<excludes>
<exclude>**/*.iml</exclude>
<exclude>target</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>overwrite-generated-meta</id>
<!-- Run after archetype:create-from-project -->
<goals>
<goal>copy-resources</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/trino-example-plugin/target/generated-sources/archetype/src/main/resources/META-INF/maven</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources/META-INF/maven</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>overwrite-generated-pom</id>
<!-- Run after archetype:create-from-project -->
<goals>
<goal>copy-resources</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/trino-example-plugin/target/generated-sources/archetype</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>pom.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<pomIncludes>
<pomInclude>pom.xml</pomInclude>
</pomIncludes>
<projectsDirectory>${project.build.directory}/trino-example-plugin/target/generated-sources/archetype</projectsDirectory>
<noLog>false</noLog>
<streamLogs>true</streamLogs>
</configuration>
<executions>
<execution>
<id>generate-archetype</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<projectsDirectory>${project.build.directory}/trino-example-plugin</projectsDirectory>

<goals>
<goal>org.apache.maven.plugins:maven-archetype-plugin:3.2.1:create-from-project -Darchetype.properties=${project.basedir}/archetype.properties -Darchetype.postPhase=validate</goal>
</goals>
</configuration>
</execution>
<execution>
<id>package-archetype</id>
<goals>
<goal>run</goal>
</goals>
<phase>package</phase>
<configuration>
<goals>
<!-- gib could be enabled by the CI workflow but it would fail -->
<goal>package -Dgib.disable</goal>
</goals>
</configuration>
</execution>
<execution>
<id>install-archetype</id>
<goals>
<goal>run</goal>
</goals>
<phase>install</phase>
<configuration>
<goals>
<goal>install -Dgib.disable</goal>
</goals>
</configuration>
</execution>
<execution>
<id>deploy-archetype</id>
<goals>
<goal>run</goal>
</goals>
<phase>deploy</phase>
<configuration>
<goals>
<goal>deploy -Dgib.disable</goal>
</goals>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" name="trino-example-plugin"
xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<requiredProperties>
<requiredProperty key="classPrefix"/>
<requiredProperty key="connectorName"/>
</requiredProperties>
<fileSets>
<fileSet filtered="false" packaged="false" encoding="UTF-8">
<directory />
<includes>
<include>.gitignore</include>
</includes>
</fileSet>

<fileSet filtered="true" packaged="false" encoding="UTF-8">
<directory />
<includes>
<include>README.md</include>
<include>LICENSE</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
</fileSet>
</fileSets>
</archetype-descriptor>
46 changes: 46 additions & 0 deletions plugin/trino-plugin-archetype-builder/src/main/resources/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.trino</groupId>
<artifactId>trino-root</artifactId>
<version>${project.version}</version>
<!-- this file is copied to ${project.build.directory}/trino-example-plugin/target/generated-sources/archetype so add 5 levels to the relative path -->
<relativePath>../../../../../../../pom.xml</relativePath>
</parent>

<artifactId>trino-plugin-archetype</artifactId>
<packaging>maven-archetype</packaging>
<description>Trino - Maven Archetype for Trino Plugins</description>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.2.1</version>
</extension>
</extensions>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package=it.pkg
groupId=com.it
artifactId=basic
version=0.1-SNAPSHOT
keepParent=false
connectorName=example_connector
classPrefix=Example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
verify
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<module>plugin/trino-password-authenticators</module>
<module>plugin/trino-phoenix5</module>
<module>plugin/trino-pinot</module>
<module>plugin/trino-plugin-archetype-builder</module>
<module>plugin/trino-postgresql</module>
<module>plugin/trino-prometheus</module>
<module>plugin/trino-raptor-legacy</module>
Expand Down

0 comments on commit 9c2efbd

Please sign in to comment.