pax_global_header00006660000000000000000000000064126240614600014513gustar00rootroot0000000000000052 comment=ec5f3f2d514d7670e6eab41c8ca44058f93fb037 templating-maven-plugin-templating-maven-plugin-1.0.0/000077500000000000000000000000001262406146000230175ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/.gitignore000066400000000000000000000003451262406146000250110ustar00rootroot00000000000000# Maven target/ pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup pom.xml.next release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties # IDE's .settings .classpath .project *.iml .idea templating-maven-plugin-templating-maven-plugin-1.0.0/.travis.yml000066400000000000000000000001421262406146000251250ustar00rootroot00000000000000--- language: java script: mvn verify -B jdk: - oraclejdk8 - oraclejdk7 - openjdk7 - openjdk6 templating-maven-plugin-templating-maven-plugin-1.0.0/LICENSE000066400000000000000000000260521262406146000240310ustar00rootroot00000000000000Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2013 MojoHaus 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. templating-maven-plugin-templating-maven-plugin-1.0.0/README.md000066400000000000000000000016151262406146000243010ustar00rootroot00000000000000Templating Maven Plugin ======================= [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.mojo/templating-maven-plugin.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Ctemplating-maven-plugin) [![Build Status](https://travis-ci.org/mojohaus/templating-maven-plugin.svg)](https://travis-ci.org/mojohaus/templating-maven-plugin) The [Templating Maven Plugin](http://www.mojohaus.org/templating-maven-plugin/) handles copying files from a source to a given output directory, while filtering them. This plugin is useful to filter Java Source Code if you need for example to have things in that code replaced with some properties values. ## Releasing * Make sure `gpg-agent` is running. * Execute `mvn -B release:prepare release:perform` For publishing the site do the following: ``` cd target/checkout mvn verify site site:stage scm-publish:publish-scm ``` templating-maven-plugin-templating-maven-plugin-1.0.0/pom.xml000066400000000000000000000167621262406146000243500ustar00rootroot00000000000000 4.0.0 org.codehaus.mojo mojo-parent 38 templating-maven-plugin 1.0.0 maven-plugin http://www.mojohaus.org/templating-maven-plugin Templating Maven Plugin That project was designed to offer the Maven Right Way® :-) to filter sources. 2013 The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo Karl Heinz Marbaise +1 khmarbaise@apache.org Developer Baptiste Mathus +1 Developer Stephen Connolly stephen.alan.connolly@gmail.com Developer 0 Krzysztof Suszyński cardil@o2.pl http://suszynski.org/ ${mavenVersion} scm:git:https://github.com/mojohaus/templating-maven-plugin.git scm:git:ssh://git@github.com/mojohaus/templating-maven-plugin.git https://github.com/mojohaus/templating-maven-plugin templating-maven-plugin-1.0.0 GitHub https://github.com/mojohaus/templating-maven-plugin/issues/ Travis-CI https://travis-ci.org/mojohaus/templating-maven-plugin 2.2.1 1.5 1.3 target/staging/${project.artifactId} org.apache.maven.plugins maven-plugin-plugin true mojo-descriptor descriptor help-goal helpmojo org.apache.maven maven-model ${mavenVersion} org.apache.maven maven-project ${mavenVersion} org.apache.maven maven-core ${mavenVersion} org.apache.maven maven-plugin-api org.apache.maven maven-artifact ${mavenVersion} org.codehaus.plexus plexus-utils 3.0.22 org.codehaus.plexus plexus-interpolation 1.21 org.apache.maven.plugin-tools maven-plugin-annotations provided org.apache.maven.shared maven-filtering ${mavenFilteringVersion} org.sonatype.plexus plexus-build-api 0.0.7 junit junit test org.mockito mockito-core 1.9.5 test org.assertj assertj-core 1.7.1 test org.apache.maven.plugins maven-plugin-plugin run-its skipTests !true maven-invoker-plugin ${project.build.directory}/it true verify ${project.build.directory}/local-repo src/it/settings.xml integration-test install run templating-maven-plugin-templating-maven-plugin-1.0.0/src/000077500000000000000000000000001262406146000236065ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/000077500000000000000000000000001262406146000242225ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/000077500000000000000000000000001262406146000253525ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/colors.properties000066400000000000000000000000711262406146000307670ustar00rootroot00000000000000first-color = red second-color = green third-color = bluetemplating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/pom.xml000066400000000000000000000015271262406146000266740ustar00rootroot00000000000000 4.0.0 org.codehaus.mojo.templating.it mojo-2014 0.0.1-SNAPSHOT MOJO-2014 colors.properties @project.groupId@ @project.artifactId@ @project.version@ filter-src filter-sources templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/000077500000000000000000000000001262406146000261415ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/000077500000000000000000000000001262406146000270655ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/000077500000000000000000000000001262406146000320025ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/org/000077500000000000000000000000001262406146000325715ustar00rootroot00000000000000codehaus/000077500000000000000000000000001262406146000343055ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/orgmojo/000077500000000000000000000000001262406146000352515ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/org/codehaustemplating/000077500000000000000000000000001262406146000374155ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/org/codehaus/mojoit/000077500000000000000000000000001262406146000400315ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/org/codehaus/mojo/templatingColors.java000066400000000000000000000003711262406146000421360ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/src/main/java-templates/org/codehaus/mojo/templating/itpackage org.codehaus.mojo.templating.it; public class Colors { public static final String FIRST_COLOR = "${first-color}"; public static final String SECOND_COLOR = "${second-color}"; public static final String THIRD_COLOR = "${third-color}"; } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/MOJO-2014/verify.groovy000066400000000000000000000027241262406146000301320ustar00rootroot00000000000000/* * 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. */ def buildLog = new File(basedir, 'build.log') assert buildLog.exists() assert buildLog.text.contains("BUILD SUCCESS") assert new File(basedir, 'target').exists() assert new File(basedir, 'target/generated-sources/java-templates/org/codehaus/mojo/templating/it/Colors.java').exists() def javaClass = new File(basedir, 'target/generated-sources/java-templates/org/codehaus/mojo/templating/it/Colors.java') assert javaClass.text.contains('public static final String FIRST_COLOR = "red"') assert javaClass.text.contains('public static final String SECOND_COLOR = "green"') assert javaClass.text.contains('public static final String THIRD_COLOR = "blue"') templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/000077500000000000000000000000001262406146000306015ustar00rootroot00000000000000invoker.properties000066400000000000000000000015421262406146000343170ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation# # 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. # invoker.goals=clean test invoker.buildResult = success templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/pom.xml000066400000000000000000000022761262406146000321250ustar00rootroot00000000000000 4.0.0 org.codehaus.mojo.templating.it simple 1.0-specialversion coquinou org.apache.maven.plugins maven-compiler-plugin 3.3 1.5 1.5 org.codehaus.mojo templating-maven-plugin @project.version@ filter-sources junit junit 4.11 templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/000077500000000000000000000000001262406146000313705ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/000077500000000000000000000000001262406146000323145ustar00rootroot00000000000000java-templates/000077500000000000000000000000001262406146000351525ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/mainpkg/000077500000000000000000000000001262406146000357335ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templatesA.java000066400000000000000000000003171262406146000367570ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templates/pkgpackage pkg; import org.junit.Ignore; @Ignore("${someprop}") public class A { public static final String FILTER_A="${someprop}"; public static final String FILTER_B="@someprop@"; }B.java000066400000000000000000000003101262406146000367510ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templates/pkgpackage pkg; import org.junit.Ignore; @Ignore( "@someprop@") public class B { public static final String FILTER_A="${someprop}"; public static final String FILTER_B="@someprop@"; } C.java000066400000000000000000000002341262406146000367570ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templates/pkgpackage pkg; import org.junit.Ignore; @Ignore( "${someprop}" + "@someprop@" + "${someprop}@someprop@ @someprop@${someprop}" ) public class C { }SomeClass.java000066400000000000000000000003611262406146000404670ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templates/pkgpackage pkg; import org.junit.Ignore; /* some stupid doc * basedir=${basedir} * * some new code * et bim */ @Ignore("${someprop}") public class SomeClass { public static final String VERSION = "<${project.version}>"; } some/000077500000000000000000000000001262406146000366765ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templates/pkgSomeOtherClass.java000066400000000000000000000001741262406146000424360ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java-templates/pkg/somepackage pkg.some; public class SomeOtherClass { public static final String POUET="${project.build.sourceEncoding}"; }templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java/000077500000000000000000000000001262406146000332355ustar00rootroot00000000000000net/000077500000000000000000000000001262406146000337445ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/javabatmat/000077500000000000000000000000001262406146000352145ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java/netmaven/000077500000000000000000000000001262406146000363225ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java/net/batmatApp.java000066400000000000000000000007621262406146000377120ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/main/java/net/batmat/mavenpackage net.batmat.maven; import pkg.some.SomeOtherClass; // That one is impossible to do using a .properties file // which you load for example in a static code block. // So this is the kind of use where it comes useful. @SuppressWarnings("for some "+pkg.SomeClass.VERSION) public class App { public static void main(String[] args ) { System.out.println("Hello World!" + pkg.some.SomeOtherClass.POUET); System.out.println("Version:" + pkg.SomeClass.VERSION); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/test/000077500000000000000000000000001262406146000323475ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/test/java/000077500000000000000000000000001262406146000332705ustar00rootroot00000000000000net/000077500000000000000000000000001262406146000337775ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/test/javabatmat/000077500000000000000000000000001262406146000352475ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/test/java/netmaven/000077500000000000000000000000001262406146000363555ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/test/java/net/batmatAppTest.java000066400000000000000000000023611262406146000406020ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/src/test/java/net/batmat/mavenpackage net.batmat.maven; import static org.junit.Assert.assertEquals; import org.junit.Ignore; import org.junit.Test; public class AppTest { @Test public void testApp() { assertEquals("<1.0-specialversion>", pkg.SomeClass.VERSION); assertEquals("coquinou", pkg.SomeClass.class.getAnnotation(Ignore.class).value()); } @Test public void testA() throws Exception { assertEquals("coquinou", pkg.A.class.getAnnotation(Ignore.class).value()); assertEquals("coquinou", pkg.A.class.getDeclaredField("FILTER_A").get(null)); assertEquals("coquinou", pkg.A.class.getDeclaredField("FILTER_B").get(null)); } @Test public void testB() throws Exception { assertEquals("coquinou", pkg.B.class.getDeclaredField("FILTER_A").get(null)); assertEquals("coquinou", pkg.B.class.getDeclaredField("FILTER_B").get(null)); } @Ignore("See MOJO-2012, not sure it will ever work. To be continued...") @Test public void testB_TwoArobases() throws Exception { assertEquals("coquinou", pkg.B.class.getAnnotation(Ignore.class).value()); } @Test public void testC() throws Exception { assertEquals("coquinoucoquinoucoquinoucoquinou coquinoucoquinou", pkg.C.class.getAnnotation(Ignore.class).value()); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main-annotation/verify.groovy000066400000000000000000000020641262406146000333560ustar00rootroot00000000000000/* * 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. */ File buildLog = new File(basedir, 'build.log') assert buildLog.exists() assert buildLog.text.contains("BUILD SUCCESS") assert new File(basedir, 'target').exists(); assert new File(basedir, 'target/generated-sources/java-templates').exists(); templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/000077500000000000000000000000001262406146000264315ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/invoker.properties000066400000000000000000000015421262406146000322260ustar00rootroot00000000000000# # 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. # invoker.goals=clean test invoker.buildResult = success templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/pom.xml000066400000000000000000000021761262406146000277540ustar00rootroot00000000000000 4.0.0 org.codehaus.mojo.templating.it simple 1.0-specialversion org.apache.maven.plugins maven-compiler-plugin 3.3 1.5 1.5 org.codehaus.mojo templating-maven-plugin @project.version@ filter-sources junit junit 4.11 templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/000077500000000000000000000000001262406146000272205ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/000077500000000000000000000000001262406146000301445ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java-templates/000077500000000000000000000000001262406146000330615ustar00rootroot00000000000000pkg/000077500000000000000000000000001262406146000335635ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java-templatesSomeClass.java000066400000000000000000000002751262406146000363230ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java-templates/pkgpackage pkg; /* some stupid doc * basedir=${basedir} * * some new code * et bim */ public class SomeClass { public static final String VERSION = "<${project.version}>"; } some/000077500000000000000000000000001262406146000345265ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java-templates/pkgSomeOtherClass.java000066400000000000000000000001741262406146000402660ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java-templates/pkg/somepackage pkg.some; public class SomeOtherClass { public static final String POUET="${project.build.sourceEncoding}"; }templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java/000077500000000000000000000000001262406146000310655ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java/net/000077500000000000000000000000001262406146000316535ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java/net/batmat/000077500000000000000000000000001262406146000331235ustar00rootroot00000000000000maven/000077500000000000000000000000001262406146000341525ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java/net/batmatApp.java000066400000000000000000000007621262406146000355420ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/main/java/net/batmat/mavenpackage net.batmat.maven; import pkg.some.SomeOtherClass; // That one is impossible to do using a .properties file // which you load for example in a static code block. // So this is the kind of use where it comes useful. @SuppressWarnings("for some "+pkg.SomeClass.VERSION) public class App { public static void main(String[] args ) { System.out.println("Hello World!" + pkg.some.SomeOtherClass.POUET); System.out.println("Version:" + pkg.SomeClass.VERSION); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/test/000077500000000000000000000000001262406146000301775ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/test/java/000077500000000000000000000000001262406146000311205ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/test/java/net/000077500000000000000000000000001262406146000317065ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/test/java/net/batmat/000077500000000000000000000000001262406146000331565ustar00rootroot00000000000000maven/000077500000000000000000000000001262406146000342055ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/test/java/net/batmatAppTest.java000066400000000000000000000003421262406146000364270ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/src/test/java/net/batmat/mavenpackage net.batmat.maven; import org.junit.Assert; public class AppTest { @org.junit.Test public void testApp() { Assert.assertEquals( "<1.0-specialversion>", pkg.SomeClass.VERSION); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-main/verify.groovy000066400000000000000000000020641262406146000312060ustar00rootroot00000000000000/* * 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. */ File buildLog = new File(basedir, 'build.log') assert buildLog.exists() assert buildLog.text.contains("BUILD SUCCESS") assert new File(basedir, 'target').exists(); assert new File(basedir, 'target/generated-sources/java-templates').exists(); templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/000077500000000000000000000000001262406146000266475ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/invoker.properties000066400000000000000000000015421262406146000324440ustar00rootroot00000000000000# # 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. # invoker.goals=clean test invoker.buildResult = success templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/pom.xml000066400000000000000000000027231262406146000301700ustar00rootroot00000000000000 4.0.0 org.codehaus.mojo.templating.it simple 1.0-specialtestversion junit junit 4.11 test org.apache.maven.plugins maven-compiler-plugin 3.3 1.5 1.5 org.codehaus.mojo templating-maven-plugin @project.version@ filter-sources filter-test-sources #{*} templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/000077500000000000000000000000001262406146000274365ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/000077500000000000000000000000001262406146000303625ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java-templates/000077500000000000000000000000001262406146000332775ustar00rootroot00000000000000pkg/000077500000000000000000000000001262406146000340015ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java-templatesSomeClass.java000066400000000000000000000002771262406146000365430ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java-templates/pkgpackage pkg; /* some stupid doc * basedir=${basedir} * * some new code * et bim */ public class SomeClass { public static final String VERSION = "est ${project.version}"; } some/000077500000000000000000000000001262406146000347445ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java-templates/pkgSomeOtherClass.java000066400000000000000000000001741262406146000405040ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java-templates/pkg/somepackage pkg.some; public class SomeOtherClass { public static final String POUET="${project.build.sourceEncoding}"; }templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java/000077500000000000000000000000001262406146000313035ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java/net/000077500000000000000000000000001262406146000320715ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java/net/batmat/000077500000000000000000000000001262406146000333415ustar00rootroot00000000000000maven/000077500000000000000000000000001262406146000343705ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java/net/batmatApp.java000066400000000000000000000007621262406146000357600ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/main/java/net/batmat/mavenpackage net.batmat.maven; import pkg.some.SomeOtherClass; // That one is impossible to do using a .properties file // which you load for example in a static code block. // So this is the kind of use where it comes useful. @SuppressWarnings("for some "+pkg.SomeClass.VERSION) public class App { public static void main(String[] args ) { System.out.println("Hello World!" + pkg.some.SomeOtherClass.POUET); System.out.println("Version:" + pkg.SomeClass.VERSION); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/000077500000000000000000000000001262406146000304155ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java-templates/000077500000000000000000000000001262406146000333325ustar00rootroot00000000000000net/000077500000000000000000000000001262406146000340415ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java-templatesbatmat/000077500000000000000000000000001262406146000353115ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java-templates/netmaven/000077500000000000000000000000001262406146000364175ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java-templates/net/batmatSomeTestClass.java000066400000000000000000000003161262406146000420130ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java-templates/net/batmat/mavenpackage net.batmat.maven; /* some stupid doc * basedir=${basedir} * * some new code * et bim */ public class SomeTestClass { public static final String VERSION = "%${project.version}%"; } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java/000077500000000000000000000000001262406146000313365ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java/some/000077500000000000000000000000001262406146000323015ustar00rootroot00000000000000testpkg/000077500000000000000000000000001262406146000337035ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java/someTheClass.java000066400000000000000000000004611262406146000362550ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/src/test/java/some/testpkgpackage some.testpkg; import org.junit.Assert; import org.junit.Test; @SuppressWarnings( net.batmat.maven.SomeTestClass.VERSION ) public class TheClass { @Test public void testFoo() { Assert.assertEquals( "%1.0-specialtestversion%", net.batmat.maven.SomeTestClass.VERSION ); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/filter-tests/verify.groovy000066400000000000000000000022101262406146000314150ustar00rootroot00000000000000/* * 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. */ File buildLog = new File(basedir, 'build.log') assert buildLog.exists() assert buildLog.text.contains("BUILD SUCCESS") assert new File(basedir, 'target').exists(); assert new File(basedir, 'target/generated-sources/java-templates').exists(); assert new File(basedir, 'target/generated-test-sources/java-templates').exists(); templating-maven-plugin-templating-maven-plugin-1.0.0/src/it/settings.xml000066400000000000000000000043521262406146000266100ustar00rootroot00000000000000 my.server me {iFtD2TFFjzoHEDN1RxW21zEBYW0Gt7GwbsOm6yDS63s=} it-repo true local.central @localRepositoryUrl@ true true apache.snapshots Apache Snapshot Repository http://people.apache.org/repo/m2-snapshot-repository false true local.central @localRepositoryUrl@ true true templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/000077500000000000000000000000001262406146000245325ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/000077500000000000000000000000001262406146000254535ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/000077500000000000000000000000001262406146000262425ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/codehaus/000077500000000000000000000000001262406146000300355ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/codehaus/mojo/000077500000000000000000000000001262406146000310015ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/codehaus/mojo/templating/000077500000000000000000000000001262406146000331455ustar00rootroot00000000000000AbstractFilterSourcesMojo.java000066400000000000000000000367521262406146000410500ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.zip.CRC32; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.filtering.MavenFilteringException; import org.apache.maven.shared.filtering.MavenResourcesExecution; import org.apache.maven.shared.filtering.MavenResourcesFiltering; import org.codehaus.plexus.util.FileUtils; import org.sonatype.plexus.build.incremental.BuildContext; /** * The base class for {@link FilterSourcesMojo} and {@link FilterTestSourcesMojo} */ public abstract class AbstractFilterSourcesMojo extends AbstractMojo { private static final int CHECKSUM_BUFFER = 4096; private int copied = 0; /** * @return The location of the source directory. */ protected abstract File getSourceDirectory(); /** * @return The location of the output directory. */ protected abstract File getOutputDirectory(); @Component private BuildContext buildContext; /** * The character encoding scheme to be applied when filtering resources. */ @Parameter( defaultValue = "${project.build.sourceEncoding}" ) private String encoding; /** * Expression preceded with the String won't be interpolated \${foo} will be replaced with ${foo} */ @Parameter( property = "maven.resources.escapeString" ) protected String escapeString; /** * Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form * 'beginToken*endToken'. If no '*' is given, the delimiter is assumed to be the same for start and end. So, the * default filtering delimiters might be specified as: * *
     * <delimiters>
     *   <delimiter>${*}</delimiter>
     *   <delimiter>@</delimiter>
     * </delimiters>
     * 
* * Since the '@' delimiter is the same on both ends, we don't need to specify '@*@' (though we can). */ @Parameter protected List delimiters; /** * Controls whether the default delimiters are included in addition to those configured {@link #delimiters}. Does * not have any effect if {@link #delimiters} is empty when the defaults will be included anyway. */ @Parameter( defaultValue = "true" ) protected boolean useDefaultDelimiters; @Parameter( defaultValue = "${session}", required = true, readonly = true ) private MavenSession session; @Parameter( defaultValue = "${project}", required = true, readonly = true ) private MavenProject project; /** * Controls whether to overwrite files that are not changed, by default files will not be overwritten */ @Parameter( defaultValue = "false" ) protected boolean overwrite; /** * Skips POM projects if set to true, which is the default option. */ @Parameter( defaultValue = "true" ) protected boolean skipPoms; /** * The resources filtering which is used. */ @Component( hint = "default" ) protected MavenResourcesFiltering mavenResourcesFiltering; /** {@inheritDoc} */ public void execute() throws MojoExecutionException { File sourceDirectory = getSourceDirectory(); if ( !preconditionsFulfilled( sourceDirectory ) ) { return; } buildContext.removeMessages( sourceDirectory ); // 1 Copy with filtering the given source to temporary dir copied = 0; File temporaryDirectory = getTemporaryDirectory( sourceDirectory ); logInfo( "Coping files with filtering to temporary directory." ); logDebug( "Temporary director for filtering is: %s", temporaryDirectory ); filterSourceToTemporaryDir( sourceDirectory, temporaryDirectory ); // 2 Copy if needed copyDirectoryStructure( temporaryDirectory, getOutputDirectory() ); cleanupTemporaryDirectory( temporaryDirectory ); if ( isSomethingBeenUpdated() ) { buildContext.refresh( getOutputDirectory() ); logInfo( "Copied %d files to output directory: %s", copied, getOutputDirectory() ); } else { logInfo( "No files needs to be copied to output directory. Up to date: %s", getOutputDirectory() ); } // 3 Add that dir to sources addSourceFolderToProject( this.project ); logInfo( "Source directory: %s added.", getOutputDirectory() ); } /** * @return number of copied files. */ protected int countCopiedFiles() { return copied; } private void logInfo( String format, Object... args ) { if ( getLog().isInfoEnabled() ) { getLog().info( String.format( format, args ) ); } } private void logDebug( String format, Object... args ) { if ( getLog().isDebugEnabled() ) { getLog().debug( String.format( format, args ) ); } } private boolean isSomethingBeenUpdated() { return copied > 0; } private void cleanupTemporaryDirectory( File temporaryDirectory ) throws MojoExecutionException { try { FileUtils.forceDelete( temporaryDirectory ); } catch ( IOException ex ) { throw new MojoExecutionException( ex.getMessage(), ex ); } } private void filterSourceToTemporaryDir( final File sourceDirectory, final File temporaryDirectory ) throws MojoExecutionException { List resources = new ArrayList(); Resource resource = new Resource(); resource.setFiltering( true ); logDebug( "Source absolute path: %s", sourceDirectory.getAbsolutePath() ); resource.setDirectory( sourceDirectory.getAbsolutePath() ); resources.add( resource ); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( resources, temporaryDirectory, project, encoding, Collections.emptyList(), Collections.emptyList(), session ); mavenResourcesExecution.setInjectProjectBuildFilters( true ); mavenResourcesExecution.setEscapeString( escapeString ); mavenResourcesExecution.setOverwrite( overwrite ); setDelimitersForExecution( mavenResourcesExecution ); try { mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException e ) { buildContext.addMessage( getSourceDirectory(), 1, 1, "Filtering Exception", BuildContext.SEVERITY_ERROR, e ); throw new MojoExecutionException( e.getMessage(), e ); } } private void setDelimitersForExecution( MavenResourcesExecution mavenResourcesExecution ) { // if these are NOT set, just use the defaults, which are '${*}' and '@'. if ( delimiters != null && !delimiters.isEmpty() ) { LinkedHashSet delims = new LinkedHashSet(); if ( useDefaultDelimiters ) { delims.addAll( mavenResourcesExecution.getDelimiters() ); } for ( String delim : delimiters ) { if ( delim == null ) { // FIXME: ${filter:*} could also trigger this condition. Need a better long-term solution. delims.add( "${*}" ); } else { delims.add( delim ); } } mavenResourcesExecution.setDelimiters( delims ); } } private void preconditionsCopyDirectoryStructure( final File sourceDirectory, final File destinationDirectory, final File rootDestinationDirectory ) throws IOException { if ( sourceDirectory == null ) { throw new IOException( "source directory can't be null." ); } if ( destinationDirectory == null ) { throw new IOException( "destination directory can't be null." ); } if ( sourceDirectory.equals( destinationDirectory ) ) { throw new IOException( "source and destination are the same directory." ); } if ( !sourceDirectory.exists() ) { throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); } } private void copyDirectoryStructure( final File sourceDirectory, final File destinationDirectory ) throws MojoExecutionException { try { File target = destinationDirectory; if ( !target.isAbsolute() ) { target = resolve( project.getBasedir(), destinationDirectory.getPath() ); } copyDirectoryStructureWithIO( sourceDirectory, target, target ); } catch ( IOException ex ) { throw new MojoExecutionException( ex.getMessage(), ex ); } } private void copyDirectoryStructureWithIO( final File sourceDirectory, final File destinationDirectory, final File rootDestinationDirectory ) throws IOException { preconditionsCopyDirectoryStructure( sourceDirectory, destinationDirectory, rootDestinationDirectory ); File[] files = sourceDirectory.listFiles(); if ( files == null ) { return; } String sourcePath = sourceDirectory.getAbsolutePath(); for ( File file : files ) { if ( file.equals( rootDestinationDirectory ) ) { // We don't copy the destination directory in itself continue; } String dest = file.getAbsolutePath(); dest = dest.substring( sourcePath.length() + 1 ); File destination = new File( destinationDirectory, dest ); if ( file.isFile() ) { destination = destination.getParentFile(); if ( isFileDifferent( file, destination ) ) { copied++; FileUtils.copyFileToDirectory( file, destination ); } } else if ( file.isDirectory() ) { if ( !destination.exists() && !destination.mkdirs() ) { throw new IOException( "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } copyDirectoryStructureWithIO( file, destination, rootDestinationDirectory ); } else { throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); } } } private File resolve( final File file, final String... subfile ) { StringBuilder path = new StringBuilder(); path.append( file.getPath() ); for ( String fi : subfile ) { path.append( File.separator ); path.append( fi ); } return new File( path.toString() ); } private boolean isFileDifferent( final File file, final File directory ) throws IOException { File targetFile = resolve( directory, file.getName() ).getAbsoluteFile(); return !targetFile.canRead() || getCrc32OfFile( file ) != getCrc32OfFile( targetFile ); } private long getCrc32OfFile( final File target ) throws IOException { FileInputStream fis = null; try { fis = new FileInputStream( target ); CRC32 crcMaker = new CRC32(); byte[] buffer = new byte[CHECKSUM_BUFFER]; int bytesRead; while ( ( bytesRead = fis.read( buffer ) ) != -1 ) { crcMaker.update( buffer, 0, bytesRead ); } return crcMaker.getValue(); } catch ( FileNotFoundException ex ) { close( fis ); throw new IOException( ex.getLocalizedMessage(), ex ); } finally { close( fis ); } } private void close( Closeable is ) throws IOException { if ( is != null ) { is.close(); } } private File getTemporaryDirectory( File sourceDirectory ) throws MojoExecutionException { File basedir = project.getBasedir(); File target = new File( project.getBuild().getDirectory() ); StringBuilder label = new StringBuilder( "templates-tmp" ); CRC32 crcMaker = new CRC32(); crcMaker.update( sourceDirectory.getPath().getBytes() ); label.append( crcMaker.getValue() ); String subfile = label.toString(); return target.isAbsolute() ? resolve( target, subfile ) : resolve( basedir, target.getPath(), subfile ); } private boolean preconditionsFulfilled( File sourceDirectory ) { if ( skipPoms && "pom".equals( project.getPackaging() ) ) { logInfo( "Skipping a POM project type. Change a `skipPoms` to false to run anyway." ); return false; } logDebug( "source=%s target=%s", sourceDirectory, getOutputDirectory() ); if ( !( sourceDirectory != null && sourceDirectory.exists() ) ) { logInfo( "Request to add '%s' folder. Not added since it does not exist.", sourceDirectory ); return false; } return true; } /** * @param mavenProject {@link MavenProject} */ protected abstract void addSourceFolderToProject( MavenProject mavenProject ); } FilterSourcesMojo.java000066400000000000000000000044621262406146000373550ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import java.io.File; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; /** * This mojo helps adding a filtered source folder in one go. This is typically useful if you want to use properties * coming from the POM inside parts of your source code that requires real constants, like annotations for example. */ @Mojo( name = "filter-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) public class FilterSourcesMojo extends AbstractFilterSourcesMojo { /** * Source directory that will be first filtered and then added as a classical source folder. */ @Parameter( defaultValue = "${basedir}/src/main/java-templates" ) File sourceDirectory; /** * Output folder where filtered sources will land. */ @Parameter( defaultValue = "${project.build.directory}/generated-sources/java-templates" ) private File outputDirectory; @Override protected File getSourceDirectory() { return sourceDirectory; } @Override protected File getOutputDirectory() { return outputDirectory; } @Override protected void addSourceFolderToProject( MavenProject mavenProject ) { mavenProject.addCompileSourceRoot( getOutputDirectory().getAbsolutePath() ); } } FilterTestSourcesMojo.java000066400000000000000000000045531262406146000402160ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import java.io.File; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; /** * This mojo helps adding a filtered source folder in one go. This is typically useful if you want to use properties * coming from the POM inside parts of your test source code that requires real constants, like annotations for example. */ @Mojo( name = "filter-test-sources", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, threadSafe = true ) public class FilterTestSourcesMojo extends AbstractFilterSourcesMojo { /** * Source directory that will be first filtered and then added as a classical source folder. */ @Parameter( defaultValue = "${basedir}/src/test/java-templates" ) private File testSourceDirectory; /** * Output folder where filtered test sources will land. */ @Parameter( defaultValue = "${project.build.directory}/generated-test-sources/java-templates" ) private File testOutputDirectory; @Override protected File getSourceDirectory() { return testSourceDirectory; } @Override protected File getOutputDirectory() { return testOutputDirectory; } @Override protected void addSourceFolderToProject( MavenProject mavenProject ) { mavenProject.addTestCompileSourceRoot( getOutputDirectory().getAbsolutePath() ); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/resources/000077500000000000000000000000001262406146000265445ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/resources/META-INF/000077500000000000000000000000001262406146000277045ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/resources/META-INF/m2e/000077500000000000000000000000001262406146000303675ustar00rootroot00000000000000lifecycle-mapping-metadata.xml000066400000000000000000000010241262406146000361750ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/main/resources/META-INF/m2e filter-sources filter-test-sources true true templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/000077500000000000000000000000001262406146000245525ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/apt/000077500000000000000000000000001262406146000253365ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/apt/examples/000077500000000000000000000000001262406146000271545ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/apt/examples/encoding.apt.vm000066400000000000000000000034131262406146000320720ustar00rootroot00000000000000 ------ Specifying a character encoding scheme ------ Baptiste Mathus ------ 2013-01-27 ------ ~~ 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. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Specifying a character encoding scheme A character encoding scheme such as <<>>, <<>> or <<>> can be chosen to be used for the reading and writing of files. For example, if we want to specify that the character encoding scheme be <<>>, we would simply have to configure that as in the following example: +-----+ ... UTF-8 org.codehaus.mojo templating-maven-plugin ${project.version} ... ... +-----+ templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/apt/examples/source-filtering.apt.vm000066400000000000000000000050421262406146000335650ustar00rootroot00000000000000 ------ Filtering a source folder ------ Baptiste Mathus ------ 2013-01-27 ------ ~~ 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. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Filtering a source folder The Templating Maven Plugin <> goal lets you filter a dedicated source folder. In one pass, it filters that folder and adds the resulting filtered folder to the POM model as a source folder. If, for example, you have some of your code where you would like to reference properties coming from the POM, you want to put those classes inside the <<>> tag. <<>> +-----+ ... org.codehaus.mojo templating-maven-plugin ${project.version} filter-src filter-sources ${basedir}/src/main/java-templates \${project.build.directory}/generated-sources/java-templates +-----+ templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/apt/index.apt000066400000000000000000000064711262406146000271630ustar00rootroot00000000000000 ------ Introduction ------ Baptiste Mathus ------ 2013-01-27 ------ ~~ 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. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Templating Maven Plugin The templating maven plugin handles copying files from a source to a given output directory, while filtering them. This plugin is useful to filter Java Source Code if you need for example to have things in that code replaced with some values. * Goals Overview * {{{./filter-sources-mojo.html}templating:filter-sources}} lets you filter your sources in one go. * {{{./filter-test-sources-mojo.html}templating:filter-test-sources}} lets you filter your test sources in one go. * Usage General instructions on how to use the Templating Plugin can be found on the {{{./usage.html}usage page}}. Some more specific use cases are described in the examples given below. In case you still have questions regarding the plugin's usage, please have a look at the {{{./faq.html}FAQ}} and feel free to contact the {{{./mail-lists.html}user mailing list}}. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the {{{./mail-lists.html}mail archive}}. If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our {{{./issue-tracking.html}issue tracker}}. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our {{{./source-repository.html}source repository}} and will find supplementary information in the {{{http://maven.apache.org/guides/development/guide-helping.html}guide to helping with Maven}}. * Examples The following examples show how to use the Templating Plugin in more advanced usecases: * {{{./examples/source-filtering.html}How to typically configure the filtering}} * {{{./examples/encoding.html}Specifying a character encoding scheme}} * Technical details Currently, it uses the {{{http://maven.apache.org/shared/maven-filtering/}Maven Filtering}} shared component for filtering resources. [] templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/apt/usage.apt.vm000066400000000000000000000046551262406146000276030ustar00rootroot00000000000000 ------ Usage ------ Baptiste Mathus ------ 2013-01-27 ------ ~~ 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. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Usage The Templating Maven Plugin handles the copying and filtering of project sources to the output directory. The following examples describe the basic usage of the plugin. To handle filtering this plugin uses the {{{http://maven.apache.org/shared/maven-filtering/index.html}Maven Filtering}} shared component (version ${mavenFilteringVersion}). * Copy and filters your source files to the specified output directory +-----+ mvn templating:filter-sources +-----+ Upon executing this command, your source files inside this directory will be copied and filtered to the output directory you specified (or the default one). Note: if you only want to filter resources files (not source code), you should use the standard src/main/resources directory and the associated Maven Resources Plugin. Moreover, this goal is bound by default to the <<>> phase. * Copy and filters your test source files to the specified output directory +-----+ mvn templating:filter-test-sources +-----+ Upon executing this command, your source files inside this directory will be copied and filtered to the output directory you specified (or the default one). Note: if you only want to filter resources files (not source code), you should use the standard src/test/resources directory and the associated Maven Resources Plugin. Moreover, this goal is bound by default to the <<>> phase. templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/fml/000077500000000000000000000000001262406146000253305ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/fml/faq.fml000066400000000000000000000031241262406146000265770ustar00rootroot00000000000000 Why this plugin?

When you want to filter for example java source code, you are left wandering around the Internet trying to find a solution. Most of the times, the solution in question requires you to add tens of lines to your POM.

This plugin provides you with the right way™ to do that with very few lines in your XML.

templating-maven-plugin-templating-maven-plugin-1.0.0/src/site/site.xml000066400000000000000000000040061262406146000262400ustar00rootroot00000000000000 www.mojohaus.org 5211 thin-badge mojohaus/${project.artifactId} right gray templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/000077500000000000000000000000001262406146000245655ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/000077500000000000000000000000001262406146000255065ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/000077500000000000000000000000001262406146000262755ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/000077500000000000000000000000001262406146000300705ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/mojo/000077500000000000000000000000001262406146000310345ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/mojo/templating/000077500000000000000000000000001262406146000332005ustar00rootroot00000000000000AbstractFilterSourcesMojoTest.java000066400000000000000000000121311262406146000417240ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import java.io.File; import java.io.IOException; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.filtering.MavenFilteringException; import org.apache.maven.shared.filtering.MavenResourcesExecution; import org.apache.maven.shared.filtering.MavenResourcesFiltering; import org.apache.maven.shared.utils.io.FileUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.sonatype.plexus.build.incremental.BuildContext; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; /** * @author Krzysztof Suszyński * @since 2015-11-17 */ @RunWith( MockitoJUnitRunner.class ) public class AbstractFilterSourcesMojoTest { @Spy private MavenProject project = MavenProjectStub.createProjectForITExample( "sample-simple" ); @Mock private MavenSession session; @Mock private MavenResourcesFiltering mavenResourcesFiltering; @Spy private File sourceDirectory = resolve( project.getBasedir(), "src", "main", "java-templates" ); @Spy private File outputDirectory = resolve( new File( "target" ), "generated-sources", "java-templates" ); @Mock private BuildContext buildContext; @InjectMocks private AbstractFilterSourcesMojo mojo = new FilterSourcesMojo(); @Before public void before() throws IOException { File target = resolve( project.getBasedir(), outputDirectory.getPath() ); FileUtils.forceDelete( target ); } @Test public void testGetOutputDirectory() { // when File file = mojo.getOutputDirectory(); // then assertThat( file ).isNotNull(); assertThat( file.getPath() ).contains( "generated-sources" ); } @Test public void testGetSourceDirectory() { // when File file = mojo.getSourceDirectory(); // then assertThat( file ).isNotNull(); assertThat( file ).exists(); assertThat( file ).isDirectory(); assertThat( file.getPath() ).contains( "src" ); assertThat( file.getPath() ).contains( "main" ); } @Test public void testExecute() throws MojoExecutionException, MavenFilteringException { // given doAnswer( new MockCopyAnswer() ).when( mavenResourcesFiltering ).filterResources( any( MavenResourcesExecution.class ) ); // when mojo.execute(); assertThat( mojo.countCopiedFiles() ).isEqualTo( 1 ); mojo.execute(); assertThat( mojo.countCopiedFiles() ).isEqualTo( 0 ); // then verify( mavenResourcesFiltering, times( 2 ) ).filterResources( any( MavenResourcesExecution.class ) ); verify( buildContext, times( 1 ) ).refresh( outputDirectory ); verify( project, times( 2 ) ).addCompileSourceRoot( outputDirectory.getAbsolutePath() ); } private static class MockCopyAnswer implements Answer { public Void answer( InvocationOnMock invocation ) throws Throwable { MavenResourcesExecution arg = MavenResourcesExecution.class.cast( invocation.getArguments()[0] ); File source = new File( arg.getResources().iterator().next().getDirectory() ); assertThat( source ).exists(); assertThat( source ).isDirectory(); File destination = arg.getOutputDirectory(); assertThat( destination ).doesNotExist(); FileUtils.copyDirectoryStructure( source, destination ); return null; } } private static File resolve( File file, String... paths ) { StringBuilder sb = new StringBuilder( file.getPath() ); for ( String path : paths ) { sb.append( File.separator ).append( path ); } return new File( sb.toString() ); } }FailingFilterSourcesMojoTest.java000066400000000000000000000051261262406146000415400ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import java.io.File; import java.util.Arrays; import java.util.Collection; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.filtering.MavenFilteringException; import org.apache.maven.shared.filtering.MavenResourcesFiltering; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyZeroInteractions; @RunWith( value = Parameterized.class ) // Let's play with Parameterized, I've been wanted to do that for quite a long time :-). public class FailingFilterSourcesMojoTest { @Parameter( 0 ) public File failingParam; @Parameters public static Collection getFailingParameters() { return Arrays.asList( new File[] { null }, new File[] { new File( "/non/existing/path/yodleyyyyeee" ) } ); } @Test public void testBadDirectoryDoesNotAddSourceFolder() throws MojoExecutionException, MavenFilteringException { FilterSourcesMojo filterSourcesMojo = new FilterSourcesMojo() { @Override protected void addSourceFolderToProject( MavenProject mavenProject ) { throw new IllegalArgumentException(); } }; filterSourcesMojo.sourceDirectory = failingParam; MavenResourcesFiltering mock = mock( MavenResourcesFiltering.class ); filterSourcesMojo.mavenResourcesFiltering = mock; filterSourcesMojo.execute(); verifyZeroInteractions( mock ); } } MavenProjectStub.java000066400000000000000000000072051262406146000372230ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.utils.ReaderFactory; /** * @author Krzysztof Suszyński * @since 2015-11-17 */ public class MavenProjectStub extends MavenProject { private final File basedir; public MavenProjectStub( File basedir ) { this.basedir = basedir; initiate(); } /** * {@inheritDoc} */ @Override public File getBasedir() { return basedir; } private void initiate() { MavenXpp3Reader pomReader = new MavenXpp3Reader(); Model model; try { model = pomReader.read( ReaderFactory.newXmlReader( new File( getBasedir(), "pom.xml" ) ) ); setModel( model ); } catch ( Exception e ) { throw new RuntimeException( e ); } setGroupId( model.getGroupId() ); setArtifactId( model.getArtifactId() ); setVersion( model.getVersion() ); setName( model.getName() ); setUrl( model.getUrl() ); setPackaging( model.getPackaging() ); Build build = new Build(); build.setFinalName( model.getArtifactId() ); build.setDirectory( getBasedir() + "/target" ); build.setSourceDirectory( getBasedir() + "/src/main/java" ); build.setOutputDirectory( getBasedir() + "/target/classes" ); build.setTestSourceDirectory( getBasedir() + "/src/test/java" ); build.setTestOutputDirectory( getBasedir() + "/target/test-classes" ); setBuild( build ); List compileSourceRoots = new ArrayList(); compileSourceRoots.add( getBasedir() + "/src/main/java" ); setCompileSourceRoots( compileSourceRoots ); List testCompileSourceRoots = new ArrayList(); testCompileSourceRoots.add( getBasedir() + "/src/test/java" ); setTestCompileSourceRoots( testCompileSourceRoots ); } public static MavenProject createProjectForITExample( String exampleName ) { String load = exampleName + File.separator + "pom.xml"; URL pomUrl = MavenProjectStub.class.getClassLoader().getResource( load ); assert pomUrl != null : "Could not load: " + load; String pomPath = pomUrl.getPath(); File pomFile = new File( pomPath ); assertThat( pomFile ).exists().isFile(); File baseDir = pomFile.getParentFile(); assertThat( baseDir ).exists().isDirectory(); return new MavenProjectStub( baseDir ); } } OkFilterSourcesMojoTest.java000066400000000000000000000043171262406146000405410ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/java/org/codehaus/mojo/templatingpackage org.codehaus.mojo.templating; /* * 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. */ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import java.io.File; import org.apache.maven.project.MavenProject; import org.junit.Test; import org.mockito.Mockito; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; public class OkFilterSourcesMojoTest { @Test public void testExistingDirectoryDoesNotAddSourceFolder() { final StringBuilder placeholder = new StringBuilder(); FilterSourcesMojo filterSourcesMojo = new FilterSourcesMojo() { @Override protected void addSourceFolderToProject( MavenProject mavenProject ) { placeholder.append( "called" ); } }; filterSourcesMojo.sourceDirectory = new File( "." ); MavenProject mock = mock( MavenProject.class ); Mockito.doThrow( IllegalArgumentException.class ).when( mock ).addCompileSourceRoot( anyString() ); Mockito.doThrow( IllegalArgumentException.class ).when( mock ).addTestCompileSourceRoot( anyString() ); filterSourcesMojo.addSourceFolderToProject( mock ); assertThat( placeholder.toString() ).isEqualTo( "called" ); verify( mock, never() ).addTestCompileSourceRoot( anyString() ); } } templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/000077500000000000000000000000001262406146000265775ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/000077500000000000000000000000001262406146000313475ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/pom.xml000066400000000000000000000023741262406146000326720ustar00rootroot00000000000000 4.0.0 org.codehaus.mojo.templating.it sample-simple 1.0.0-specialversion org.apache.maven.plugins maven-compiler-plugin 3.0 1.5 1.5 org.codehaus.mojo templating-maven-plugin @project.version@ filter-sources templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/src/000077500000000000000000000000001262406146000321365ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/src/main/000077500000000000000000000000001262406146000330625ustar00rootroot00000000000000java-templates/000077500000000000000000000000001262406146000357205ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/src/mainorg/000077500000000000000000000000001262406146000365075ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/src/main/java-templatesexample/000077500000000000000000000000001262406146000401425ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/src/main/java-templates/orgSample.java000066400000000000000000000001571262406146000422310ustar00rootroot00000000000000templating-maven-plugin-templating-maven-plugin-1.0.0/src/test/resources/sample-simple/src/main/java-templates/org/examplepackage org.example; public class Sample { public static final String VERSION = "<${project.version}>"; }