diff --git a/docs/src/main/sphinx/develop/spi-overview.md b/docs/src/main/sphinx/develop/spi-overview.md index 872619f2dda1..c1367e1cc6a3 100644 --- a/docs/src/main/sphinx/develop/spi-overview.md +++ b/docs/src/main/sphinx/develop/spi-overview.md @@ -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 diff --git a/plugin/trino-example-plugin/pom.xml b/plugin/trino-example-plugin/pom.xml index dd03f4f7e45b..48bbe5473c41 100644 --- a/plugin/trino-example-plugin/pom.xml +++ b/plugin/trino-example-plugin/pom.xml @@ -186,11 +186,6 @@ trino-maven-plugin 13 true - - io.trino.spi.Plugin - io.trino - trino-spi - diff --git a/plugin/trino-plugin-archetype-builder/.gitignore b/plugin/trino-plugin-archetype-builder/.gitignore new file mode 100644 index 000000000000..0e13eebbeaad --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/.gitignore @@ -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 diff --git a/plugin/trino-plugin-archetype-builder/archetype.properties b/plugin/trino-plugin-archetype-builder/archetype.properties new file mode 100644 index 000000000000..828b7852ad71 --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/archetype.properties @@ -0,0 +1,3 @@ +excludePatterns=*.iml,interpolated-pom.xml,build.log +connectorName=example_connector +classPrefix=Example diff --git a/plugin/trino-plugin-archetype-builder/pom.xml b/plugin/trino-plugin-archetype-builder/pom.xml new file mode 100644 index 000000000000..79843d06d683 --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/pom.xml @@ -0,0 +1,162 @@ + + + 4.0.0 + + + io.trino + trino-root + 440-SNAPSHOT + ../../pom.xml + + + trino-plugin-archetype-builder + pom + Trino - Maven Archetype Builder for Trino Plugins + + + ${project.parent.basedir} + UTF-8 + + + + + io.trino + trino-example-plugin + 0.1-SNAPSHOT + + + + + + + maven-resources-plugin + + + copy-sources + + copy-resources + + generate-sources + + ${project.build.directory}/trino-example-plugin + + + ${project.basedir}/../trino-example-plugin + + **/*.iml + target + + false + + + + + + overwrite-generated-meta + + + copy-resources + + process-sources + + ${project.build.directory}/trino-example-plugin/target/generated-sources/archetype/src/main/resources/META-INF/maven + true + + + ${project.basedir}/src/main/resources/META-INF/maven + false + + + + + + overwrite-generated-pom + + + copy-resources + + process-sources + + ${project.build.directory}/trino-example-plugin/target/generated-sources/archetype + true + + + ${project.basedir}/src/main/resources + true + + pom.xml + + + + + + + + + maven-invoker-plugin + 3.3.0 + + + pom.xml + + ${project.build.directory}/trino-example-plugin/target/generated-sources/archetype + false + true + + + + generate-archetype + + run + + generate-sources + + ${project.build.directory}/trino-example-plugin + + + org.apache.maven.plugins:maven-archetype-plugin:3.2.1:create-from-project -Darchetype.properties=${project.basedir}/archetype.properties -Darchetype.postPhase=validate + + + + + package-archetype + + run + + package + + + + package -Dgib.disable + + + + + install-archetype + + run + + install + + + install -Dgib.disable + + + + + deploy-archetype + + run + + deploy + + + deploy -Dgib.disable + + + + + + + + diff --git a/plugin/trino-plugin-archetype-builder/src/main/resources/META-INF/maven/archetype-metadata.xml b/plugin/trino-plugin-archetype-builder/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000000..b0ce8d909351 --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + .gitignore + + + + + + + README.md + LICENSE + + + + src/main/java + + + src/test/java + + + diff --git a/plugin/trino-plugin-archetype-builder/src/main/resources/pom.xml b/plugin/trino-plugin-archetype-builder/src/main/resources/pom.xml new file mode 100644 index 000000000000..97608c76895d --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/src/main/resources/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + + io.trino + trino-root + ${project.version} + + ../../../../../../../pom.xml + + + trino-plugin-archetype + maven-archetype + Trino - Maven Archetype for Trino Plugins + + + ${project.parent.basedir} + + + + + + + org.apache.maven.plugins + maven-archetype-plugin + 3.2.1 + + + + + + org.apache.maven.plugins + maven-archetype-plugin + 3.2.1 + + + + + org.apache.maven.archetype + archetype-packaging + 3.2.1 + + + + diff --git a/plugin/trino-plugin-archetype-builder/src/test/resources/projects/basic/archetype.properties b/plugin/trino-plugin-archetype-builder/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 000000000000..a6368b9c4673 --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,7 @@ +package=it.pkg +groupId=com.it +artifactId=basic +version=0.1-SNAPSHOT +keepParent=false +connectorName=example_connector +classPrefix=Example diff --git a/plugin/trino-plugin-archetype-builder/src/test/resources/projects/basic/goal.txt b/plugin/trino-plugin-archetype-builder/src/test/resources/projects/basic/goal.txt new file mode 100644 index 000000000000..0b5987362fe3 --- /dev/null +++ b/plugin/trino-plugin-archetype-builder/src/test/resources/projects/basic/goal.txt @@ -0,0 +1 @@ +verify diff --git a/pom.xml b/pom.xml index 469ba9e080c7..3ede0b5e467e 100644 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,7 @@ plugin/trino-password-authenticators plugin/trino-phoenix5 plugin/trino-pinot + plugin/trino-plugin-archetype-builder plugin/trino-postgresql plugin/trino-prometheus plugin/trino-raptor-legacy