From 20a14dfa57612de3b75c946c32de310cd087474d Mon Sep 17 00:00:00 2001 From: Mirko Raner Date: Sun, 21 Jan 2024 16:38:44 -0800 Subject: [PATCH] Issue #273: enabled fileExtension option for template generation (#274) * Issue #273: added more complex template generation test * Issue #273: honored file extension when processing templates * Issue #273: removed additional Maven step --- pom.xml | 4 +- projo-jackson/pom.xml | 4 +- projo-jax-rs/pom.xml | 4 +- projo-runtime-code-generation/pom.xml | 4 +- projo-template-annotation/pom.xml | 4 +- projo-template-configuration/pom.xml | 4 +- projo-template-generation-test/pom.xml | 4 +- .../template/$test/Dimension$Dimension.java | 52 ++++++++ .../template/exponents/Exponent.java | 18 +++ .../generation/template/exponents/Minus1.java | 18 +++ .../generation/template/exponents/Minus2.java | 18 +++ .../generation/template/exponents/Minus3.java | 18 +++ .../generation/template/exponents/Minus4.java | 18 +++ .../generation/template/exponents/Plus1.java | 18 +++ .../generation/template/exponents/Plus2.java | 18 +++ .../generation/template/exponents/Plus3.java | 18 +++ .../generation/template/exponents/Plus4.java | 18 +++ .../generation/template/exponents/Zero.java | 18 +++ .../options/$test/Dimension$Dimension.java | 52 ++++++++ .../template/test/TestDimensions.java | 66 +++++++++ .../template/test/TestTemplateOptions.java | 37 +++++ projo-template-generation/pom.xml | 4 +- .../ProjoTemplateFactoryProcessor.java | 30 ++++- projo/pom.xml | 4 +- .../TestDimensionTemplateConfiguration.java | 126 ++++++++++++++++++ ...DimensionTemplateOptionsConfiguration.java | 41 ++++++ .../pro/projo/test/options/package-info.java | 27 ++++ 27 files changed, 626 insertions(+), 21 deletions(-) create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/$test/Dimension$Dimension.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Exponent.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus1.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus2.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus3.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus4.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus1.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus2.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus3.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus4.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Zero.java create mode 100644 projo-template-generation-test/src/main/java/pro/projo/generation/template/options/$test/Dimension$Dimension.java create mode 100644 projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestDimensions.java create mode 100644 projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestTemplateOptions.java create mode 100644 projo/src/test/java/pro/projo/test/TestDimensionTemplateConfiguration.java create mode 100644 projo/src/test/java/pro/projo/test/options/TestDimensionTemplateOptionsConfiguration.java create mode 100644 projo/src/test/java/pro/projo/test/options/package-info.java diff --git a/pom.xml b/pom.xml index 0f273d0..994be0f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ - + @@ -22,7 +22,7 @@ 4.0.0 pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT Projo Parent POM https://github.com/raner/projo pom diff --git a/projo-jackson/pom.xml b/projo-jackson/pom.xml index b9ce91b..d6fbe4f 100644 --- a/projo-jackson/pom.xml +++ b/projo-jackson/pom.xml @@ -1,6 +1,6 @@ - + @@ -24,7 +24,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT projo-jackson diff --git a/projo-jax-rs/pom.xml b/projo-jax-rs/pom.xml index 8c2fdcf..06edc0e 100644 --- a/projo-jax-rs/pom.xml +++ b/projo-jax-rs/pom.xml @@ -1,6 +1,6 @@ - + @@ -23,7 +23,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT Projo JAX-RS Integration for Jersey projo-jax-rs diff --git a/projo-runtime-code-generation/pom.xml b/projo-runtime-code-generation/pom.xml index 4465e1f..2fea7ec 100644 --- a/projo-runtime-code-generation/pom.xml +++ b/projo-runtime-code-generation/pom.xml @@ -1,6 +1,6 @@ - + @@ -26,7 +26,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT diff --git a/projo-template-annotation/pom.xml b/projo-template-annotation/pom.xml index 59b0e17..86f7265 100644 --- a/projo-template-annotation/pom.xml +++ b/projo-template-annotation/pom.xml @@ -1,6 +1,6 @@ - + @@ -25,7 +25,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT diff --git a/projo-template-configuration/pom.xml b/projo-template-configuration/pom.xml index 6e31c9f..4c4863b 100644 --- a/projo-template-configuration/pom.xml +++ b/projo-template-configuration/pom.xml @@ -1,6 +1,6 @@ - + @@ -25,7 +25,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT diff --git a/projo-template-generation-test/pom.xml b/projo-template-generation-test/pom.xml index 254a876..b370558 100644 --- a/projo-template-generation-test/pom.xml +++ b/projo-template-generation-test/pom.xml @@ -1,6 +1,6 @@ - + @@ -24,7 +24,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT projo-template-generation-test Projo Template Generation Tests diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/$test/Dimension$Dimension.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/$test/Dimension$Dimension.java new file mode 100644 index 0000000..caf089b --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/$test/Dimension$Dimension.java @@ -0,0 +1,52 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.$test; + +/* *#* The following imports will only appear in generated files: *#/ +import pro.projo.generation.template.exponents.Exponent; +import pro.projo.generation.template.exponents.Minus4; +import pro.projo.generation.template.exponents.Minus3; +import pro.projo.generation.template.exponents.Minus2; +import pro.projo.generation.template.exponents.Minus1; +import pro.projo.generation.template.exponents.Zero; +import pro.projo.generation.template.exponents.Plus1; +import pro.projo.generation.template.exponents.Plus2; +import pro.projo.generation.template.exponents.Plus3; +import pro.projo.generation.template.exponents.Plus4; +/* */ +/*#*/ // The following imports are only part of the template file: +import pro.projo.template.annotation.Template; +import pro.projo.test.TestDimensionTemplateConfiguration; +/*#*/ +/** +*#* +* The {@link Dimension$Dimension} interface is a test type. +*# +* This interface defines a Dimension type. +* +* THIS IS A GENERATED INTERFACE. +* +* @author Mirko Raner +**/ +/*#*/@Template(input=TestDimensionTemplateConfiguration.class)/*#*/ +public interface Dimension$Dimension +{ +/* *#**#/ +#foreach ($method in $methods) + $method +#end +/* */ +} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Exponent.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Exponent.java new file mode 100644 index 0000000..afcfb66 --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Exponent.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus1.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus1.java new file mode 100644 index 0000000..cd5febe --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus1.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Minus1 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus2.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus2.java new file mode 100644 index 0000000..c20504c --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus2.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Minus2 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus3.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus3.java new file mode 100644 index 0000000..550241c --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus3.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Minus3 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus4.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus4.java new file mode 100644 index 0000000..bbfaf97 --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Minus4.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Minus4 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus1.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus1.java new file mode 100644 index 0000000..a4e92c4 --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus1.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Plus1 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus2.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus2.java new file mode 100644 index 0000000..ca4ff46 --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus2.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Plus2 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus3.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus3.java new file mode 100644 index 0000000..a27733c --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus3.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Plus3 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus4.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus4.java new file mode 100644 index 0000000..a001a4d --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Plus4.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Plus4 extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Zero.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Zero.java new file mode 100644 index 0000000..d2ea190 --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/exponents/Zero.java @@ -0,0 +1,18 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.exponents; + +public interface Zero extends Exponent {} diff --git a/projo-template-generation-test/src/main/java/pro/projo/generation/template/options/$test/Dimension$Dimension.java b/projo-template-generation-test/src/main/java/pro/projo/generation/template/options/$test/Dimension$Dimension.java new file mode 100644 index 0000000..df7d80f --- /dev/null +++ b/projo-template-generation-test/src/main/java/pro/projo/generation/template/options/$test/Dimension$Dimension.java @@ -0,0 +1,52 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.options.$test; + +/* *#* The following imports will only appear in generated files: *#/ +import pro.projo.generation.template.exponents.Exponent; +import pro.projo.generation.template.exponents.Minus4; +import pro.projo.generation.template.exponents.Minus3; +import pro.projo.generation.template.exponents.Minus2; +import pro.projo.generation.template.exponents.Minus1; +import pro.projo.generation.template.exponents.Zero; +import pro.projo.generation.template.exponents.Plus1; +import pro.projo.generation.template.exponents.Plus2; +import pro.projo.generation.template.exponents.Plus3; +import pro.projo.generation.template.exponents.Plus4; +/* */ +/*#*/ // The following imports are only part of the template file: +import pro.projo.template.annotation.Template; +import pro.projo.test.options.TestDimensionTemplateOptionsConfiguration; +/*#*/ +/** +*#* +* The {@link Dimension$Dimension} interface is a test type. +*# +* This interface defines a Dimension type. +* +* THIS IS A GENERATED INTERFACE. +* +* @author Mirko Raner +**/ +/*#*/@Template(input=TestDimensionTemplateOptionsConfiguration.class)/*#*/ +public interface Dimension$Dimension +{ +/* *#**#/ +#foreach ($method in $methods) + $method +#end +/* */ +} diff --git a/projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestDimensions.java b/projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestDimensions.java new file mode 100644 index 0000000..c0bf541 --- /dev/null +++ b/projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestDimensions.java @@ -0,0 +1,66 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.test; + +import pro.projo.generation.template.test.dimensions.Dimension; +import pro.projo.generation.template.exponents.Minus4; +import pro.projo.generation.template.exponents.Minus3; +import pro.projo.generation.template.exponents.Minus2; +import pro.projo.generation.template.exponents.Minus1; +import pro.projo.generation.template.exponents.Zero; +import pro.projo.generation.template.exponents.Plus1; +import pro.projo.generation.template.exponents.Plus2; +import pro.projo.generation.template.exponents.Plus3; +import pro.projo.generation.template.exponents.Plus4; + +/** +* {@link TestDimensions} is a non-executable test that verifies the type safety of +* the generated dimensions API. The test is considered passing if it compiles without +* errors. Any problems with the dimensions API will be detected at compile time. +* +* @author Mirko Raner +**/ +public interface TestDimensions +{ + Dimension dimensions(); + + default void testDimensions() + { + Dimension time1 = dimensions().t(); + Dimension time2 = dimensions().t().plus1(); + Dimension time3 = dimensions().m().zero().t(); + Dimension frequency = dimensions().t().minus1(); + Dimension velocity1 = dimensions().t().minus1().l(); + Dimension velocity2 = dimensions().t().minus1().l().plus1(); + Dimension velocity3 = dimensions().t().minus1().l().plus1().m().zero(); + Dimension velocity4 = dimensions().l().t().minus1(); + Dimension velocity5 = dimensions().l().plus1().t().minus1(); + Dimension pressure1 = dimensions().t().minus2().l().minus1().m(); + Dimension pressure2 = dimensions().t().minus2().l().minus1().m().plus1(); + Dimension pressure3 = dimensions().m().plus1().t().minus2().l().minus1(); + Dimension pressure4 = dimensions().m().t().minus2().l().minus1(); + Dimension capacitance = dimensions().t().plus4().l().minus2().m().minus1().i().plus2(); + Dimension thermalConductance = dimensions().t().minus3().l().plus2().m().plus1().θ().minus1(); + Dimension catalyticActivity = dimensions().n().t().minus1(); + Dimension luminousEfficacy = dimensions().t().plus3().l().minus2().m().minus1().j().plus1(); + Dimension jounce = dimensions().l().t().minus4(); + use(time1, time2, time3, frequency, velocity1, velocity2, velocity3, velocity4, velocity5); + use(pressure1, pressure2, pressure3, pressure4, capacitance, thermalConductance, catalyticActivity); + use(luminousEfficacy, jounce); + } + + void use(Dimension... dimensions); +} diff --git a/projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestTemplateOptions.java b/projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestTemplateOptions.java new file mode 100644 index 0000000..1867557 --- /dev/null +++ b/projo-template-generation-test/src/test/java/pro/projo/generation/template/test/TestTemplateOptions.java @@ -0,0 +1,37 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.generation.template.test; + +import java.net.URL; +import org.junit.Test; +import static org.junit.Assert.assertNotNull; + +public class TestTemplateOptions +{ + @Test(expected=ClassNotFoundException.class) + public void noGeneratedJavaTypesShouldExist() throws ClassNotFoundException + { + Class.forName("pro.projo.generation.template.options.test.dimensions.Dimension"); + } + + @Test + public void generatedKavaFilesShouldExist() + { + ClassLoader classLoader = getClass().getClassLoader(); + URL url = classLoader.getResource("pro/projo/generation/template/options/test/dimensions/Dimension.kava"); + assertNotNull(url); + } +} diff --git a/projo-template-generation/pom.xml b/projo-template-generation/pom.xml index d5c02bc..f7a2f7d 100644 --- a/projo-template-generation/pom.xml +++ b/projo-template-generation/pom.xml @@ -1,6 +1,6 @@ - + @@ -26,7 +26,7 @@ pro.projo projo-parent - 1.5.3 + 1.5.4-SNAPSHOT diff --git a/projo-template-generation/src/main/java/pro/projo/generation/ProjoTemplateFactoryProcessor.java b/projo-template-generation/src/main/java/pro/projo/generation/ProjoTemplateFactoryProcessor.java index 0be7e34..36281e9 100644 --- a/projo-template-generation/src/main/java/pro/projo/generation/ProjoTemplateFactoryProcessor.java +++ b/projo-template-generation/src/main/java/pro/projo/generation/ProjoTemplateFactoryProcessor.java @@ -1,5 +1,5 @@ // // -// Copyright 2018 - 2022 Mirko Raner // +// Copyright 2018 - 2024 Mirko Raner // // // // Licensed under the Apache License, Version 2.0 (the "License"); // // you may not use this file except in compliance with the License. // @@ -31,7 +31,7 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import javax.tools.FileObject; -import javax.tools.JavaFileObject; +import pro.projo.interfaces.annotation.Options; import pro.projo.template.annotation.Configuration; import pro.projo.template.annotation.Template; import static java.io.File.separatorChar; @@ -86,7 +86,17 @@ public boolean process(Set annotations, RoundEnvironment TypeElement typeElement = elements.getTypeElement(className); try { - JavaFileObject sourceFile = filer.createSourceFile(className, typeElement); + Options options = configuration.options(); + String fileExtension = configuration.options().fileExtension(); + FileObject sourceFile = fileExtension.equals(".java")? + filer.createSourceFile(className, typeElement): + filer.createResource + ( + options.outputLocation(), + packageName(configuration), + fileName(configuration), + typeElement + ); try (PrintWriter writer = new PrintWriter(sourceFile.openWriter(), true)) { try (Reader reader = templateFile.openReader(true)) @@ -107,6 +117,20 @@ public boolean process(Set annotations, RoundEnvironment return true; } + private String packageName(Configuration configuration) + { + String name = configuration.fullyQualifiedClassName(); + int index = name.lastIndexOf('.'); + return name.substring(0, index); + } + + private String fileName(Configuration configuration) + { + String name = configuration.fullyQualifiedClassName(); + int index = name.lastIndexOf('.'); + return name.substring(index+1) + configuration.options().fileExtension(); + } + private FileObject getTemplateFile(Element element) { String simpleName = element.getSimpleName().toString(); diff --git a/projo/pom.xml b/projo/pom.xml index bb5bfc6..b1e8646 100644 --- a/projo/pom.xml +++ b/projo/pom.xml @@ -1,6 +1,6 @@ - + @@ -26,7 +26,7 @@ projo-parent pro.projo - 1.5.3 + 1.5.4-SNAPSHOT diff --git a/projo/src/test/java/pro/projo/test/TestDimensionTemplateConfiguration.java b/projo/src/test/java/pro/projo/test/TestDimensionTemplateConfiguration.java new file mode 100644 index 0000000..fa012b0 --- /dev/null +++ b/projo/src/test/java/pro/projo/test/TestDimensionTemplateConfiguration.java @@ -0,0 +1,126 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collector; +import java.util.stream.Stream; +import pro.projo.interfaces.annotation.Options; +import pro.projo.template.annotation.Configuration; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toCollection; +import static java.util.stream.Collectors.toList; +import static java.util.stream.IntStream.rangeClosed; + +/** +* The {@link TestDimensionTemplateConfiguration} is used for internal testing. +* +* @author Mirko Raner +**/ +public class TestDimensionTemplateConfiguration extends ArrayList +{ + private final static long serialVersionUID = 5849315222475315976L; + + private final String[] dimensions = {"T", "L", "M", "I", "ϴ", "N", "J"}; + private final String[] exponents = {"Minus4", "Minus3", "Minus2", "Minus1", "Zero", "Plus1", "Plus2", "Plus3", "Plus4"}; + + public TestDimensionTemplateConfiguration() + { + rangeClosed(0, 7).mapToObj(count -> new Configuration() + { + @Override + public String fullyQualifiedClassName() + { + return targetPackage() + ".Dimension" + suffix(); + } + + @Override + public Options options() + { + return TestDimensionTemplateConfiguration.this.options(); + } + + @Override + public Map parameters() + { + return new HashMap() + { + private static final long serialVersionUID = 1L; + { + put("Dimension", suffix()+typeParameters()+extend()); + put("methods", methods()); + put("test", subpackage()); + } + }; + } + + List methods() + { + if (count == 0) + { + return Stream.of(dimensions) + .map(dimension -> "Dimension" + dimension + Stream.of(dimensions).map(it -> it.equals(dimension)? "Plus1":it).collect(joined()) + " " + dimension.toLowerCase() + "();") + .collect(toList()); + } + else + { + return Stream.of(exponents) + .map(exponent -> "Dimension" + Stream.of(dimensions).map(it -> it.equals(suffix())? exponent:it).collect(joined()) + " " + exponent.toLowerCase() + "();") + .collect(toList()); + } + } + + String suffix() + { + return count == 0? "":dimensions[count-1]; + } + + String extend() + { + return count == 0? "":" extends Dimension" + Stream.of(dimensions).collect(joined()); + } + }) + .collect(toCollection(() -> this)); + } + + protected Options options() + { + return Configuration.defaults(); + } + + protected String targetPackage() + { + return "pro.projo.generation.template.test.dimensions"; + } + + protected String subpackage() + { + return "test.dimensions"; + } + + String typeParameters() + { + return Stream.of(dimensions).map(it -> it + " extends Exponent").collect(joined()); + } + + Collector joined() + { + return joining(", ", "<", ">"); + } +} diff --git a/projo/src/test/java/pro/projo/test/options/TestDimensionTemplateOptionsConfiguration.java b/projo/src/test/java/pro/projo/test/options/TestDimensionTemplateOptionsConfiguration.java new file mode 100644 index 0000000..7cfb258 --- /dev/null +++ b/projo/src/test/java/pro/projo/test/options/TestDimensionTemplateOptionsConfiguration.java @@ -0,0 +1,41 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +package pro.projo.test.options; + +import pro.projo.interfaces.annotation.Options; +import pro.projo.test.TestDimensionTemplateConfiguration; + +/** +* The {@link TestDimensionTemplateOptionsConfiguration} is used for internal testing. +* +* @author Mirko Raner +**/ +public class TestDimensionTemplateOptionsConfiguration extends TestDimensionTemplateConfiguration +{ + private final static long serialVersionUID = -8492805138996252572L; + + @Override + protected Options options() + { + return getClass().getPackage().getAnnotation(Options.class); + } + + @Override + protected String targetPackage() + { + return "pro.projo.generation.template.options.test.dimensions"; + } +} diff --git a/projo/src/test/java/pro/projo/test/options/package-info.java b/projo/src/test/java/pro/projo/test/options/package-info.java new file mode 100644 index 0000000..0495be2 --- /dev/null +++ b/projo/src/test/java/pro/projo/test/options/package-info.java @@ -0,0 +1,27 @@ +// // +// Copyright 2024 Mirko Raner // +// // +// Licensed 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. // +// // +@Options(fileExtension=".kava", outputLocation=CLASS_OUTPUT) +package pro.projo.test.options; + +import pro.projo.interfaces.annotation.Options; +import static javax.tools.StandardLocation.CLASS_OUTPUT; + +/** +* This {@code package-info} file serves the only purpose of providing easy access +* to an {@link Options} instance that has some custom values. +* +* @author Mirko Raner +**/