-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
5,203 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Please use one of the following templates: | ||
|
||
https://github.com/GITHUB_ORGANIZATION/GITHUB_REPOSITORY/issues/new/choose | ||
https://github.com/toolisticon/kotlin-code-generation/issues/new/choose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,3 @@ build/ | |
|
||
### DEV | ||
_tmp/ | ||
.repository/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--add-opens=java.base/java.lang=ALL-UNNAMED | ||
--add-opens=java.base/java.io=ALL-UNNAMED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
This product includes software developed by ZacSweers (https://github.com/ZacSweers). | ||
`dev.zacsweers.kctfork:core:<latest-version>` is published under the MPL-2 license which is considered to be | ||
compatible with the APACHE LICENSE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,79 @@ | ||
# BASE_ARTIFACT_ID | ||
|
||
Template repository for usage in organizations: toolisticon, holunda-io, holixon... | ||
# kotlin-code-generation | ||
|
||
[![incubating](https://img.shields.io/badge/lifecycle-INCUBATING-orange.svg)](https://github.com/holisticon#open-source-lifecycle) | ||
[![Build Status](https://github.com/GITHUB_ORGANIZATION/GITHUB_REPOSITORY/workflows/Development%20branches/badge.svg)](https://github.com/GITHUB_ORGANIZATION/GITHUB_REPOSITORY/actions) | ||
[![Build Status](https://github.com/toolisticon/kotlin-code-generation/workflows/Development%20branches/badge.svg)](https://github.com/toolisticon/kotlin-code-generation/actions) | ||
[![sponsored](https://img.shields.io/badge/sponsoredBy-Holisticon-RED.svg)](https://holisticon.de/) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/BASE_GROUP_ID/BASE_ARTIFACT_ID/badge.svg)](https://maven-badges.herokuapp.com/maven-central/BASE_GROUP_ID/BASE_ARTIFACT_ID) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.kotlin.generation/kotlin-code-generation/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.toolisticon.kotlin.generation/kotlin-code-generation) | ||
|
||
This repository is a **template repository** designed to be a template for the next project. | ||
**Usage:** | ||
|
||
## How to use | ||
```xml | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.generation</groupId> | ||
<artifactId>kotlin-code-generation-bom</artifactId> | ||
<version>LATEST_VERSION</version> | ||
<scope>import</scope> | ||
<type>pom</type> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
``` | ||
|
||
* create a new repo on github (can be in any organization). Choose this project as template repository. Copy all branches, so the `master`exists in your repo (for the github actions) | ||
* on the command line: clone your new repo locally | ||
* in the `setup.sh` script: set your organization, repository and base package | ||
* run the `setup.sh` script, all placeholders are filled with your information | ||
* delete the setup-script | ||
* Update the `README.md` | ||
* in the `developers` section of the `pom.xml`: mention yourself ... it is your project. | ||
## Documentation | ||
|
||
## Things to change after usage of template | ||
* see [kotlin-poet](https://square.github.io/kotlinpoet/) | ||
|
||
To change the following values, modify the placeholders in `setup.sh` and run it. | ||
This is a one-time operation, you can safely delete the `setup.sh` file afterwards. | ||
## Features | ||
|
||
Of course, you can also edit manually .... and do not forget to change this `README.md` with YOUR project specific information :-). | ||
* KotlinAnnotationSpec | ||
* KotlinAnnotationSpecBuilder | ||
* KotlinFileSpec | ||
* KotlinFileSpecBuilder | ||
* KotlinFunSpec | ||
* KotlinFunSpecBuilder | ||
* KotlinParameterSpec | ||
* KotlinParameterSpecBuilder | ||
* KotlinPropertySpec | ||
* KotlinPropertySpecBuilder | ||
|
||
### Maven pom.xml | ||
|
||
* Maven coordinates: `groupId`, `artifactId` and `version` | ||
* Main description: `name`, `url`, `description` | ||
* SCM: `connection`, `url`, `developerConnection` | ||
|
||
### Issue Template | ||
## Roadmap | ||
|
||
* correct the URL to repo | ||
### Specs to support | ||
|
||
### Issue Labels | ||
* com/squareup/kotlinpoet/TypeAliasSpec | ||
* com/squareup/kotlinpoet/TypeSpec | ||
|
||
* Check the release-notes.yml for details, but create the following labels: Type: dependencies, Type: bug, Type: documentation, Type: question, Type: enhancement | ||
### Builders to implement | ||
|
||
* com/squareup/kotlinpoet/AnnotationSpec$Builder | ||
* Taggable.Builder<Builder> | ||
* com/squareup/kotlinpoet/CodeBlock$Builder | ||
* None | ||
* com/squareup/kotlinpoet/FileSpec$Builder | ||
* Annotatable.Builder<Builder> | ||
* Taggable.Builder<Builder> | ||
* TypeSpecHolder.Builder<Builder> | ||
* com/squareup/kotlinpoet/FunSpec$Builder | ||
* Annotatable.Builder<Builder> | ||
* ContextReceivable.Builder<Builder> | ||
* Documentable.Builder<Builder> | ||
* Taggable.Builder<Builder> | ||
* OriginatingElementsHolder.Builder<Builder> | ||
* com/squareup/kotlinpoet/ParameterSpec$Builder | ||
* Annotatable.Builder<Builder> | ||
* Documentable.Builder<Builder> | ||
* Taggable.Builder<Builder> | ||
* com/squareup/kotlinpoet/PropertySpec$Builder | ||
* Annotatable.Builder<Builder> | ||
* ContextReceivable.Builder<Builder> | ||
* Documentable.Builder<Builder> | ||
* OriginatingElementsHolder.Builder<Builder> | ||
* Taggable.Builder<Builder> | ||
* com/squareup/kotlinpoet/TypeAliasSpec$Builder | ||
* Annotatable.Builder<Builder> | ||
* Documentable.Builder<Builder> | ||
* Taggable.Builder<Builder> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Kotlin Code Generation Integration tests | ||
|
||
The repository provides both, the generation module and the test module. | ||
As the test module depends on the generation module, we cannot provide tests using the test module inside that module. | ||
|
||
This additional module is used to define and run all nontrivial integration tests, where we "eat our own dog food" | ||
and use the generation tools and builders to created code and then compile and assert it is working correctly using | ||
the test module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<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.toolisticon.kotlin.generation._</groupId> | ||
<artifactId>kotlin-code-generation-parent</artifactId> | ||
<version>0.0.1</version> | ||
<relativePath>../_mvn/parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<groupId>io.toolisticon.kotlin.generation.itest</groupId> | ||
<artifactId>kotlin-code-generation-itest</artifactId> | ||
<name>test: ${project.artifactId}</name> | ||
<description>Integration Tests applied on specs, builders and compilation tests.</description> | ||
|
||
<properties> | ||
<!-- itest is excluded from install/deploy/release --> | ||
<maven.install.skip>true</maven.install.skip> | ||
<gpg.skip>true</gpg.skip> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.toolisticon.kotlin.generation</groupId> | ||
<artifactId>kotlin-code-generation-bom</artifactId> | ||
<version>${project.version}</version> | ||
<scope>import</scope> | ||
<type>pom</type> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- KOTLIN --> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.microutils</groupId> | ||
<artifactId>kotlin-logging-jvm</artifactId> | ||
</dependency> | ||
<!-- /KOTLIN --> | ||
|
||
<dependency> | ||
<groupId>io.toolisticon.kotlin.generation</groupId> | ||
<artifactId>kotlin-code-generation</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.toolisticon.kotlin.generation</groupId> | ||
<artifactId>kotlin-code-generation-test</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jetbrains.kotlinx</groupId> | ||
<artifactId>kotlinx-serialization-core-jvm</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<configuration> | ||
<args> | ||
<arg>-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi</arg> | ||
<arg>-opt-in=com.squareup.kotlinpoet.ExperimentalKotlinPoetApi</arg> | ||
</args> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
object KotlinCodeGenerationITest { | ||
const val ROOT_PACKAGE = "io.toolisticon.kotlin.generation.itest.created" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
import com.squareup.kotlinpoet.ClassName | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildAnnotationClass | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFile | ||
import io.toolisticon.kotlin.generation.itest.KotlinCodeGenerationITest.ROOT_PACKAGE | ||
|
||
object MyCustomAnnotationSpec { | ||
val name = ClassName(ROOT_PACKAGE, "MyCustomAnnotation") | ||
|
||
val spec = buildAnnotationClass(name) { | ||
mustBeDocumented() | ||
retention(AnnotationRetention.RUNTIME) | ||
target(AnnotationTarget.CLASS) | ||
addConstructorProperty("value", String::class) | ||
} | ||
|
||
val file = buildFile(name) { | ||
addType(spec) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
import com.squareup.kotlinpoet.ClassName | ||
import com.tschuchort.compiletesting.KotlinCompilation | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildClass | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFile | ||
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildFun | ||
import io.toolisticon.kotlin.generation.test.KotlinCodeGenerationTest | ||
import io.toolisticon.kotlin.generation.test.model.KotlinCompilationCommand | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
internal class HelloWorldExampleTest { | ||
|
||
@Test | ||
fun `hello world from kotlin poet talk`() { | ||
val name = ClassName("foo.bar", "HelloWorld") | ||
|
||
val type = buildClass(name) { | ||
addFunction( | ||
buildFun("helloWorld") { | ||
builder { | ||
returns(String::class) | ||
addCode("return %S", "Hello World!") | ||
} | ||
}) | ||
addKdoc("%L", "Simple hello world class") | ||
} | ||
|
||
val file = buildFile(name) { | ||
addType(type) | ||
} | ||
println(file.code) | ||
|
||
assertThat(file.packageName).isEqualTo("foo.bar") | ||
|
||
val result = KotlinCodeGenerationTest.compile(cmd = KotlinCompilationCommand(fileSpec = file)) | ||
|
||
println(result) | ||
|
||
KotlinCodeGenerationTest.assertThat(result).hasExitCode(KotlinCompilation.ExitCode.OK) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
import org.junit.jupiter.api.Test | ||
|
||
internal class KotlinAnnotationSpecTest { | ||
|
||
@Test | ||
fun `generate annotation spec`() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.toolisticon.kotlin.generation.itest | ||
|
||
import com.squareup.kotlinpoet.TypeSpec | ||
import org.junit.jupiter.api.Test | ||
|
||
internal class KotlinClassBuilderTest { | ||
|
||
@Test | ||
fun `kotlin poet only generation`() { | ||
val builder = TypeSpec.classBuilder("Bar") | ||
.addKdoc("%L","hello world") | ||
|
||
println(builder.build()) | ||
} | ||
} |
Oops, something went wrong.