├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── external-version-api ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── apache │ └── maven │ └── version │ └── strategy │ ├── ExternalVersionException.java │ └── ExternalVersionStrategy.java ├── external-version-strategies ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── apache │ └── maven │ └── version │ └── strategy │ ├── FileStrategy.java │ ├── ScriptStrategy.java │ └── SystemPropertyStrategy.java ├── maven-external-version-plugin ├── pom.xml └── src │ ├── it │ ├── multi-module │ │ ├── level-one │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── App.java │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── AppTest.java │ │ ├── pom.xml │ │ └── sub-parent │ │ │ ├── level-three │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── App.java │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── AppTest.java │ │ │ └── pom.xml │ └── simple-module │ │ ├── VERSION │ │ ├── pom.xml │ │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── App.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── AppTest.java │ │ └── version.sh │ └── main │ └── java │ └── org │ └── apache │ └── maven │ └── version │ ├── ExternalVersionExtension.java │ └── ExternalVersionMojo.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | **/pom.xml.new-version 3 | .project 4 | .classpath 5 | .settings/ 6 | target/ 7 | **/.checkstyle 8 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Maven External Version 2 | Copyright 2015- The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Maven External Version 2 | ----------------------- 3 | 4 | > [!NOTE] 5 | > This usecase is now part of Maven 4. Please try Maven 4 and provide [feedback to the Maven team](https://maven.apache.org/mailing-lists.html)! 6 | > 7 | > [![The Current State of Apache Maven 4 - Karl Heinz Marbaise](https://img.youtube.com/vi/tAGv4QH29QU/0.jpg)](https://www.youtube.com/watch?v=tAGv4QH29QU&t=1112s) 8 | 9 | Archived Content 10 | --- 11 | 12 | Requires Maven 3.2.0 or later. 13 | 14 | (github is the temporary home.) 15 | 16 | What is this? 17 | -------------- 18 | 19 | The main use-case of this extension plugin is to allow the POM versions to be updated during a build and NOT require 20 | the pom.xml file to be modified (causing potential merge conflicts down the road, or untracked changes) 21 | 22 | When would I use this? 23 | ----------------------- 24 | 25 | Say, you have github-flow approach to branching, that is you create a lot of small feature branches, they get merged 26 | into 'master' then you release off of master. Currently if you want to build multiple SNAPSHOT branches in CI and 27 | and deploy them to a Maven repository, you need to update your POMs before you deploy. This will help you with that. 28 | 29 | For example if your `master` is at version `1.1.42-SNAPSHOT`, and for your feature branches you want to add your 30 | branch/feature name to the version, e.g. for branch `everything`, you want to end up with `1.1.42-everything-SNAPSHOT` 31 | 32 | 33 | Need to add real example here, when I'm more awake. Until then, look at [this](https://github.com/bdemers/maven-external-version/blob/master/maven-external-version-plugin/src/it/simple-module/pom.xml#L54-L68). 34 | 35 | Quick and Dirty Example 36 | ------------------------ 37 | 38 | 39 | In your pom add: 40 | 41 | ```xml 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-external-version-plugin 46 | 0.1.0-SNAPSHOT 47 | true 48 | 49 | 50 | 51 | 52 | 53 | ``` 54 | 55 | To replaced the whole version you can run: 56 | 57 | ``` 58 | mvn install -Dexternal.version=1.1.42 59 | ``` 60 | 61 | To add just a qualifier to the version: 62 | 63 | ``` 64 | mvn install -Dexternal.version-qualifier=rc1 65 | # if the original version was 1.1.1 the new version would be 1.1.1-rc1 66 | ``` 67 | 68 | Add a version qualifier to all non-master branches 69 | 70 | ``` 71 | mvn install -Dexternal.version-qualifier=$(git symbolic-ref --short HEAD| sed s_^master\$__) 72 | ``` 73 | 74 | Or how about a short git hash? 75 | 76 | ``` 77 | mvn install -Dexternal.version-qualifier=$(git rev-parse --short HEAD) 78 | ``` 79 | 80 | Configuration & parameters 81 | ----- 82 | 83 | ```xml 84 | 85 | 86 | org.apache.maven.plugins 87 | maven-external-version-plugin 88 | X.Y.Z 89 | true 90 | 91 | 92 | true/false 93 | true/false 94 | 95 | 96 | 97 | ``` 98 | 99 | - `strategy#hint` key defining which strategy implementation will be used, one of 100 | - file: read the version from the first line of a given file 101 | - script: version is given by the first line of the output execution of a given command 102 | - sysprop: allows to define project version & qualifier from system properties 103 | - `deleteTemporaryFile` will the generated pom files created by this extension will be deleted after execution. Set this parameter to _true_ to activate automatic deletion. Value is optional and defaults to _false_ 104 | - `generateTemporaryFile` if _true_ generated pom files will be created as temporary files inside the directory pointed by system property `java.io.tmpdir`. If omitted it defaults to _false_. When false, a file called `pom.xml.new-version` will be generated in the root project directory. 105 | 106 | ## Strategy : file 107 | 108 | This strategy reads the first line of a given file to extract the version to use. 109 | 110 | ### Usage 111 | 112 | ```xml 113 | 114 | 115 | org.apache.maven.plugins 116 | maven-external-version-plugin 117 | X.Y.Z 118 | true 119 | 120 | 121 | SOME_FILE 122 | 123 | 124 | 125 | 126 | ``` 127 | 128 | ### Parameters 129 | 130 | - `versionFilePath`: denotes the file which first line will be read to extract the version from. Can be a fully qualified path or a path relative to the project directory. The parameter is optional, it defaults to `VERSION`, meaning that if not provided, a file called `VERSION` will be read from the project root. 131 | 132 | ## Strategy : script 133 | 134 | This strategy allows to execute a given command ; the first line of stdout output will be used as version. 135 | 136 | ### Usage 137 | 138 | ```xml 139 | 140 | 141 | org.apache.maven.plugins 142 | maven-external-version-plugin 143 | X.Y.Z 144 | true 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | ``` 153 | 154 | ### Parameters 155 | 156 | - `script`: a command to execute. The parameter is optional and defaults to `./version.sh`, meaning that if not provided a file called `version.sh` in the project root will be executed. 157 | 158 | ## Strategy : sysprop 159 | 160 | This strategy uses 2 system properties to define the new project version: 161 | 162 | - `external.version`: the main version to use. If omitted, then it defaults to the current `project.version`. 163 | - `external.version-qualifier`: an optional qualifier that will be appended to the given version 164 | 165 | ### Usage 166 | 167 | ``` xml 168 | 169 | 170 | org.apache.maven.plugins 171 | maven-external-version-plugin 172 | X.Y.Z 173 | true 174 | 175 | 176 | 177 | 178 | 179 | ``` 180 | 181 | TODO: 182 | ----- 183 | 184 | * Add unit tests (Initial implementation was a bit exploratory hacking, hence why this is temporarily on github) 185 | * Finalize strategy API 186 | * Add APT for doc/site 187 | * find out if anyone else cares about this. 188 | * filter new versions into MavenProject and model ( dependency, dependency management, plugin, etc) 189 | 190 | Other Thoughts 191 | --------------- 192 | 193 | An extension isn't exactly the most flexible way of adding this feature to Maven, but it seems to work (at least with 194 | simple cases) 195 | 196 | 197 | -------------------------------------------------------------------------------- /external-version-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 4.0.0 23 | 24 | 25 | org.apache.maven.version 26 | maven-external-version 27 | 0.1.1-SNAPSHOT 28 | 29 | 30 | external-version-api 31 | 0.1.1-SNAPSHOT 32 | 33 | 34 | 35 | 36 | org.apache.maven 37 | maven-core 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /external-version-api/src/main/java/org/apache/maven/version/strategy/ExternalVersionException.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version.strategy; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | /** 23 | * Exception thrown when an version cannot be calculated or resolved. 24 | * 25 | * @author Brian Demers 26 | */ 27 | public class ExternalVersionException extends Exception 28 | { 29 | public ExternalVersionException( String message ) 30 | { 31 | super( message ); 32 | } 33 | 34 | public ExternalVersionException( String message, Throwable cause ) 35 | { 36 | super( message, cause ); 37 | } 38 | 39 | public ExternalVersionException( Throwable cause ) 40 | { 41 | super( cause ); 42 | } 43 | 44 | public ExternalVersionException( String message, Throwable cause, boolean enableSuppression, 45 | boolean writableStackTrace ) 46 | { 47 | super( message, cause, enableSuppression, writableStackTrace ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /external-version-api/src/main/java/org/apache/maven/version/strategy/ExternalVersionStrategy.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version.strategy; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.project.MavenProject; 23 | 24 | /** 25 | * Simple strategy for resolving a version. 26 | * 27 | * @author Brian Demers 28 | */ 29 | public interface ExternalVersionStrategy 30 | { 31 | /** 32 | * Returns a new version based on some other source. 33 | * 34 | * @param mavenProject project which will be updated. 35 | * @return a new String version. 36 | * @throws ExternalVersionException thrown if there is any problems loading the new version. 37 | */ 38 | String getVersion( MavenProject mavenProject ) 39 | throws ExternalVersionException; 40 | } 41 | -------------------------------------------------------------------------------- /external-version-strategies/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 4.0.0 24 | 25 | 26 | org.apache.maven.version 27 | maven-external-version 28 | 0.1.1-SNAPSHOT 29 | 30 | 31 | external-version-strategies 32 | 0.1.1-SNAPSHOT 33 | 34 | 35 | 36 | 37 | org.apache.maven.version 38 | external-version-api 39 | 0.1.1-SNAPSHOT 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.codehaus.plexus 49 | plexus-component-metadata 50 | 1.6 51 | 52 | 53 | 54 | generate-metadata 55 | generate-test-metadata 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /external-version-strategies/src/main/java/org/apache/maven/version/strategy/FileStrategy.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version.strategy; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.project.MavenProject; 23 | import org.codehaus.plexus.component.annotations.Component; 24 | import org.codehaus.plexus.component.annotations.Configuration; 25 | import org.codehaus.plexus.util.IOUtil; 26 | 27 | import java.io.BufferedReader; 28 | import java.io.File; 29 | import java.io.FileReader; 30 | import java.io.IOException; 31 | 32 | /** 33 | * Strategy which reads a version string from a 'VERSION' file which contains a single version string such as '1.2.3'. 34 | * 35 | * @author Brian Demers 36 | */ 37 | @Component( role = ExternalVersionStrategy.class, hint = "file" ) 38 | public class FileStrategy 39 | implements ExternalVersionStrategy 40 | { 41 | @Configuration( "VERSION" ) 42 | private String versionFilePath = "VERSION"; 43 | 44 | @Override 45 | public String getVersion( MavenProject mavenProject ) 46 | throws ExternalVersionException 47 | { 48 | String versionString = null; 49 | 50 | File versionFile = new File( mavenProject.getBasedir(), versionFilePath ); 51 | BufferedReader reader = null; 52 | try 53 | { 54 | reader = new BufferedReader( new FileReader( versionFile ) ); 55 | // just return the first line of the file, any other format is NOT supported. 56 | versionString = reader.readLine(); 57 | } 58 | catch ( IOException e ) 59 | { 60 | throw new ExternalVersionException( "Failed to read version file: [" + versionFile.getAbsolutePath() + "]", 61 | e ); 62 | } 63 | finally 64 | { 65 | IOUtil.close( reader ); 66 | } 67 | 68 | return versionString; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /external-version-strategies/src/main/java/org/apache/maven/version/strategy/ScriptStrategy.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version.strategy; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.project.MavenProject; 23 | import org.codehaus.plexus.component.annotations.Component; 24 | import org.codehaus.plexus.component.annotations.Configuration; 25 | import org.codehaus.plexus.component.annotations.Requirement; 26 | import org.codehaus.plexus.logging.Logger; 27 | import org.codehaus.plexus.util.IOUtil; 28 | 29 | import java.io.BufferedReader; 30 | import java.io.IOException; 31 | import java.io.InputStreamReader; 32 | 33 | /** 34 | * Executes a script or executable to resolve the version. 35 | * 36 | * @author Brian Demers 37 | */ 38 | @Component( role = ExternalVersionStrategy.class, hint = "script" ) 39 | public class ScriptStrategy 40 | implements ExternalVersionStrategy 41 | { 42 | 43 | @Configuration( "./version.sh" ) 44 | private String script; 45 | 46 | @Requirement 47 | private Logger log; 48 | 49 | @Override 50 | public String getVersion( MavenProject mavenProject ) 51 | throws ExternalVersionException 52 | { 53 | ProcessBuilder ps = new ProcessBuilder( script ); 54 | ps.redirectErrorStream( true ); 55 | BufferedReader reader = null; 56 | try 57 | { 58 | Process pr = ps.start(); 59 | reader = new BufferedReader( new InputStreamReader( pr.getInputStream() ) ); 60 | 61 | // we are only interested in the first line 62 | String versionString = reader.readLine(); 63 | pr.waitFor(); 64 | 65 | if ( pr.exitValue() != 0 ) 66 | { 67 | log.error( "Execution Exit Code: " + pr.exitValue() ); 68 | throw new ExternalVersionException( "The script exit status: " + pr.exitValue() ); 69 | } 70 | return versionString; 71 | } 72 | catch ( IOException e ) 73 | { 74 | throw new ExternalVersionException( "Failed to execute script: " + e.getMessage(), e ); 75 | } 76 | catch ( InterruptedException e ) 77 | { 78 | throw new ExternalVersionException( "Failed to execute script: " + e.getMessage(), e ); 79 | } 80 | finally 81 | { 82 | IOUtil.close( reader ); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /external-version-strategies/src/main/java/org/apache/maven/version/strategy/SystemPropertyStrategy.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version.strategy; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.project.MavenProject; 23 | import org.codehaus.plexus.component.annotations.Component; 24 | import org.codehaus.plexus.util.StringUtils; 25 | 26 | /** 27 | * Loads version from the System Property 'external.version'. 28 | * 29 | * @author Brian Demers 30 | */ 31 | @Component( role = ExternalVersionStrategy.class, hint = "sysprop" ) 32 | public class SystemPropertyStrategy 33 | implements ExternalVersionStrategy 34 | { 35 | private static final String EXTERNAL_VERSION = "external.version"; 36 | 37 | private static final String EXTERNAL_VERSION_QUALIFIER = "external.version-qualifier"; 38 | 39 | @Override 40 | public String getVersion( MavenProject mavenProject ) 41 | throws ExternalVersionException 42 | { 43 | String newVersion = System.getProperty( EXTERNAL_VERSION, mavenProject.getVersion() ); 44 | String qualifier = StringUtils.trim( System.getProperty( EXTERNAL_VERSION_QUALIFIER ) ); 45 | 46 | if ( StringUtils.isNotBlank( qualifier ) ) 47 | { 48 | // TODO: this needs to be cleaned up, the calling method will re-add the -SNAPSHOT if needed, but this is dirty 49 | newVersion = newVersion.replaceFirst( "-SNAPSHOT", "" ) + "-" + qualifier; 50 | } 51 | 52 | return newVersion; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /maven-external-version-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 4.0.0 24 | 25 | 26 | org.apache.maven.version 27 | maven-external-version 28 | 0.1.1-SNAPSHOT 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-external-version-plugin 33 | 0.1.1-SNAPSHOT 34 | 35 | maven-plugin 36 | 37 | 38 | 39 | org.apache.maven 40 | maven-plugin-api 41 | 2.0 42 | 43 | 44 | org.apache.maven.plugin-tools 45 | maven-plugin-annotations 46 | 3.4 47 | provided 48 | 49 | 50 | org.apache.maven 51 | maven-core 52 | 3.2.5 53 | provided 54 | 55 | 56 | org.apache.maven 57 | maven-archiver 58 | 2.5 59 | provided 60 | 61 | 62 | org.apache.maven.version 63 | external-version-api 64 | 0.1.1-SNAPSHOT 65 | 66 | 67 | org.apache.maven.version 68 | external-version-strategies 69 | 0.1.1-SNAPSHOT 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.codehaus.plexus 80 | plexus-component-metadata 81 | 1.6 82 | 83 | 84 | 85 | generate-metadata 86 | generate-test-metadata 87 | 88 | 89 | 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-plugin-plugin 95 | 3.4 96 | 97 | 98 | default-descriptor 99 | process-classes 100 | 101 | 102 | 103 | help-goal 104 | 105 | helpmojo 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/level-one/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | multi-module 8 | 1.0-SNAPSHOT 9 | 10 | com.example 11 | level-one 12 | 1.0-SNAPSHOT 13 | level-one 14 | http://maven.apache.org 15 | 16 | UTF-8 17 | 18 | 19 | 20 | junit 21 | junit 22 | 3.8.1 23 | test 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/level-one/src/main/java/com/example/App.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/level-one/src/test/java/com/example/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.example 5 | multi-module 6 | 1.0-SNAPSHOT 7 | pom 8 | multi-module 9 | 10 | 11 | level-one 12 | sub-parent 13 | 14 | 15 | 16 | 17 | 18 | 19 | maven-jar-plugin 20 | 2.5 21 | 22 | 23 | maven-install-plugin 24 | 2.5.2 25 | 26 | 27 | org.apache.maven.plugins 28 | maven-external-version-plugin 29 | 0.1.1-SNAPSHOT 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | true 40 | true 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/sub-parent/level-three/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | sub-parent 8 | 1.0-SNAPSHOT 9 | 10 | com.example 11 | level-three 12 | 1.0-SNAPSHOT 13 | level-three 14 | http://maven.apache.org 15 | 16 | UTF-8 17 | 18 | 19 | 20 | junit 21 | junit 22 | 3.8.1 23 | test 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/sub-parent/level-three/src/main/java/com/example/App.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World!" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/sub-parent/level-three/src/test/java/com/example/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/multi-module/sub-parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | multi-module 6 | com.example 7 | 1.0-SNAPSHOT 8 | 9 | com.example 10 | sub-parent 11 | 1.0-SNAPSHOT 12 | pom 13 | sub-parent 14 | 15 | level-three 16 | 17 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/simple-module/VERSION: -------------------------------------------------------------------------------- 1 | 1.2.3 -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/simple-module/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 23 | 24 | 4.0.0 25 | com.example 26 | simple-module 27 | jar 28 | 1.0-SNAPSHOT 29 | 30 | simple-module 31 | 32 | 33 | 34 | junit 35 | junit 36 | 3.8.1 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | maven-jar-plugin 48 | 2.5 49 | 50 | 51 | maven-install-plugin 52 | 2.5.2 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-external-version-plugin 57 | 0.1.1-SNAPSHOT 58 | true 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/simple-module/src/main/java/com/example/App.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | 23 | /** 24 | * Hello world! 25 | * 26 | */ 27 | public class App 28 | { 29 | public static void main( String[] args ) 30 | { 31 | System.out.println( "Hello World!" ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/simple-module/src/test/java/com/example/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | 23 | import junit.framework.Test; 24 | import junit.framework.TestCase; 25 | import junit.framework.TestSuite; 26 | 27 | /** 28 | * Unit test for simple App. 29 | */ 30 | public class AppTest 31 | extends TestCase 32 | { 33 | /** 34 | * Create the test case 35 | * 36 | * @param testName name of the test case 37 | */ 38 | public AppTest( String testName ) 39 | { 40 | super( testName ); 41 | } 42 | 43 | /** 44 | * @return the suite of tests being tested 45 | */ 46 | public static Test suite() 47 | { 48 | return new TestSuite( AppTest.class ); 49 | } 50 | 51 | /** 52 | * Rigourous Test :-) 53 | */ 54 | public void testApp() 55 | { 56 | assertTrue( true ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/it/simple-module/version.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | echo "3.2.1" 20 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/main/java/org/apache/maven/version/ExternalVersionExtension.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.AbstractMavenLifecycleParticipant; 23 | import org.apache.maven.MavenExecutionException; 24 | import org.apache.maven.artifact.ArtifactUtils; 25 | import org.apache.maven.artifact.versioning.VersionRange; 26 | import org.apache.maven.execution.MavenSession; 27 | import org.apache.maven.model.Model; 28 | import org.apache.maven.model.Plugin; 29 | import org.apache.maven.model.io.xpp3.MavenXpp3Reader; 30 | import org.apache.maven.model.io.xpp3.MavenXpp3Writer; 31 | import org.apache.maven.project.MavenProject; 32 | import org.apache.maven.version.strategy.ExternalVersionException; 33 | import org.apache.maven.version.strategy.ExternalVersionStrategy; 34 | import org.codehaus.plexus.PlexusContainer; 35 | import org.codehaus.plexus.component.annotations.Component; 36 | import org.codehaus.plexus.component.annotations.Requirement; 37 | import org.codehaus.plexus.component.configurator.ComponentConfigurationException; 38 | import org.codehaus.plexus.component.configurator.ComponentConfigurator; 39 | import org.codehaus.plexus.component.configurator.expression.DefaultExpressionEvaluator; 40 | import org.codehaus.plexus.component.repository.exception.ComponentLookupException; 41 | import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; 42 | import org.codehaus.plexus.logging.Logger; 43 | import org.codehaus.plexus.util.IOUtil; 44 | import org.codehaus.plexus.util.xml.Xpp3Dom; 45 | import org.codehaus.plexus.util.xml.pull.XmlPullParserException; 46 | 47 | import java.io.File; 48 | import java.io.FileReader; 49 | import java.io.FileWriter; 50 | import java.io.IOException; 51 | import java.io.Reader; 52 | import java.io.Writer; 53 | import java.util.HashMap; 54 | import java.util.Map; 55 | import java.util.regex.Pattern; 56 | 57 | /** 58 | * Maven Extension that will update all the projects in the reactor with an externally managed version. 59 | *

60 | * This extension MUST be configured as a plugin in order to be configured. 61 | *

62 | * 63 | * org.apache.maven.plugins 64 | * maven-external-version-plugin 65 | * true 66 | * 67 | * 68 | * VERSION 69 | * 70 | * 71 | * 72 | *

73 | * 'strategy' - The configuration for an ExternalVersionStrategy. 74 | * 'hint' - A component hint to load the ExternalVersionStrategy. 75 | * 76 | * @author Brian Demers 77 | */ 78 | @Component( role = AbstractMavenLifecycleParticipant.class, hint = "external-version" ) 79 | public class ExternalVersionExtension 80 | extends AbstractMavenLifecycleParticipant 81 | { 82 | 83 | @Requirement 84 | private Logger logger; 85 | 86 | @Requirement 87 | private PlexusContainer container; 88 | 89 | @Override 90 | public void afterProjectsRead( MavenSession session ) 91 | throws MavenExecutionException 92 | { 93 | logger.info( "About to change project version in reactor." ); 94 | 95 | Map gavVersionMap = new HashMap(); 96 | 97 | for ( MavenProject mavenProject : session.getAllProjects() ) 98 | { 99 | // Lookup this plugin's configuration 100 | Plugin plugin = mavenProject.getPlugin( "org.apache.maven.plugins:maven-external-version-plugin" ); 101 | 102 | // now we are going to wedge in the config 103 | Xpp3Dom configDom = (Xpp3Dom) plugin.getConfiguration(); 104 | 105 | ExternalVersionStrategy strategy = getStrategy( configDom, mavenProject.getFile() ); 106 | 107 | // grab the old version before changing it 108 | String oldVersion = mavenProject.getVersion(); 109 | 110 | try 111 | { 112 | // now use the strategy to figure out the new version 113 | String newVersion = getNewVersion( strategy, mavenProject ); 114 | 115 | // now that we have the new version update the project. 116 | mavenProject.setVersion( newVersion ); 117 | mavenProject.getArtifact().setVersion( newVersion ); 118 | // MNG-6641: setVersion nullifies versionRange 119 | mavenProject.getArtifact().setVersionRange( VersionRange.createFromVersion( newVersion ) ); 120 | 121 | // TODO: get the unfiltered string, and re-filter it with new version. 122 | String oldFinalName = mavenProject.getBuild().getFinalName(); 123 | String newFinalName = oldFinalName.replaceFirst( Pattern.quote( oldVersion ), newVersion ); 124 | logger.info( "Updating project.build.finalName: " + newFinalName ); 125 | mavenProject.getBuild().setFinalName( newFinalName ); 126 | 127 | gavVersionMap.put( buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), oldVersion ), 128 | newVersion ); 129 | logger.info( 130 | "new version added to map: " + buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), 131 | oldVersion ) + ": " + newVersion ); 132 | 133 | if ( mavenProject.getParent() != null ) 134 | { 135 | logger.info( "My parent is: " + buildGavKey( mavenProject.getParent() ) ); 136 | } 137 | 138 | 139 | } 140 | catch ( ExternalVersionException e ) 141 | { 142 | throw new MavenExecutionException( e.getMessage(), e ); 143 | } 144 | } 145 | 146 | // now we have only updated the versions of the projects, we need to update 147 | // the references between the updated projects 148 | 149 | for ( MavenProject mavenProject : session.getAllProjects() ) 150 | { 151 | try 152 | { 153 | 154 | if ( mavenProject.getParent() != null ) 155 | { 156 | logger.info( "looking for parent in map" ); 157 | 158 | if ( gavVersionMap.containsKey( buildGavKey( mavenProject.getParent() ) ) ) 159 | { 160 | // we need to update the parent 161 | logger.info( "WE NEED TO ACT NOW!" ); 162 | } 163 | } 164 | 165 | // write processed new pom out 166 | createNewVersionPom( mavenProject, gavVersionMap ); 167 | } 168 | catch ( XmlPullParserException e ) 169 | { 170 | throw new MavenExecutionException( e.getMessage(), e ); 171 | } 172 | catch ( IOException e ) 173 | { 174 | throw new MavenExecutionException( e.getMessage(), e ); 175 | } 176 | 177 | } 178 | 179 | } 180 | 181 | private String buildGavKey( MavenProject mavenProject ) 182 | { 183 | return buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion() ); 184 | } 185 | 186 | private String buildGavKey( MavenProject mavenProject, String oldVersion ) 187 | { 188 | return buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), oldVersion ); 189 | } 190 | 191 | private String buildGavKey( String groupId, String artifactId, String oldVersion ) 192 | { 193 | return new StringBuilder( groupId ).append( ":" ).append( artifactId ).append( ":" ).append( 194 | oldVersion ).toString(); 195 | } 196 | 197 | private void createNewVersionPom( MavenProject mavenProject, Map gavVersionMap ) 198 | throws IOException, XmlPullParserException 199 | { 200 | Reader fileReader = null; 201 | Writer fileWriter = null; 202 | try 203 | { 204 | fileReader = new FileReader( mavenProject.getFile() ); 205 | Model model = new MavenXpp3Reader().read( fileReader ); 206 | model.setVersion( mavenProject.getVersion() ); 207 | 208 | 209 | // TODO: this needs to be restructured when other references are updated (dependencies, dep-management, plugins, etc) 210 | if ( model.getParent() != null ) 211 | { 212 | String key = buildGavKey( model.getParent().getGroupId(), model.getParent().getArtifactId(), 213 | model.getParent().getVersion() ); 214 | String newVersionForParent = gavVersionMap.get( key ); 215 | if ( newVersionForParent != null ) 216 | { 217 | model.getParent().setVersion( newVersionForParent ); 218 | } 219 | } 220 | 221 | Plugin plugin = mavenProject.getPlugin( "org.apache.maven.plugins:maven-external-version-plugin" ); 222 | // now we are going to wedge in the config 223 | Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration(); 224 | 225 | File newPom = createFileFromConfiguration( mavenProject, pluginConfiguration ); 226 | logger.debug( ExternalVersionExtension.class.getSimpleName() + ": using new pom file => " + newPom ); 227 | fileWriter = new FileWriter( newPom ); 228 | new MavenXpp3Writer().write( fileWriter, model ); 229 | 230 | mavenProject.setFile( newPom ); 231 | } 232 | finally 233 | { 234 | IOUtil.close( fileReader ); 235 | IOUtil.close( fileWriter ); 236 | } 237 | 238 | 239 | } 240 | 241 | private File createFileFromConfiguration( MavenProject mavenProject, Xpp3Dom pluginConfig ) throws IOException 242 | { 243 | boolean deleteTemporaryFile = shouldDeleteTemporaryFile( pluginConfig ); 244 | boolean generateTemporaryFile = shouldGenerateTemporaryFile( pluginConfig ); 245 | 246 | // let's keep the default file as a default 247 | File f = new File( mavenProject.getBasedir(), "pom.xml.new-version" ); 248 | 249 | if ( generateTemporaryFile ) 250 | { 251 | f = File.createTempFile( "pom", ".maven-external-version" ); 252 | } 253 | 254 | if ( deleteTemporaryFile ) 255 | { 256 | f.deleteOnExit(); 257 | } 258 | return f; 259 | } 260 | 261 | /* 262 | * Looks for generateTemporaryFile child configuration node. 263 | * If not present then no deletion occurs, otherwise return true if value is true, false otherwise 264 | */ 265 | private boolean shouldGenerateTemporaryFile( Xpp3Dom pluginConfiguration ) 266 | { 267 | return evaluateBooleanNodeInConfiguration( pluginConfiguration, "generateTemporaryFile" ); 268 | } 269 | 270 | /* 271 | * Looks for deleteTemporaryFile child configuration node. 272 | * If not present then no deletion occurs, otherwise return true if value is true, false otherwise 273 | */ 274 | private boolean shouldDeleteTemporaryFile( Xpp3Dom pluginConfiguration ) 275 | { 276 | return evaluateBooleanNodeInConfiguration( pluginConfiguration, "deleteTemporaryFile" ); 277 | } 278 | 279 | private boolean evaluateBooleanNodeInConfiguration( Xpp3Dom pluginConfiguration, String nodeName ) 280 | { 281 | Xpp3Dom n = pluginConfiguration.getChild( nodeName ); 282 | return n != null && Boolean.parseBoolean( n.getValue() ); 283 | } 284 | 285 | private String getNewVersion( ExternalVersionStrategy strategy, MavenProject mavenProject ) 286 | throws ExternalVersionException 287 | { 288 | 289 | // snapshot detection against the old version. 290 | boolean isSnapshot = ArtifactUtils.isSnapshot( mavenProject.getVersion() ); 291 | 292 | // lookup the new version 293 | String newVersion = strategy.getVersion( mavenProject ); 294 | 295 | if ( newVersion != null ) 296 | { 297 | newVersion = newVersion.trim(); 298 | } 299 | 300 | boolean isNewSnapshot = ArtifactUtils.isSnapshot( newVersion ); 301 | // make sure we still have a SNAPSHOT if we had one previously. 302 | if ( isSnapshot && !isNewSnapshot ) 303 | { 304 | newVersion = newVersion + "-SNAPSHOT"; 305 | } 306 | return newVersion; 307 | } 308 | 309 | private ExternalVersionStrategy getStrategy( Xpp3Dom configDom, File pomFile ) 310 | throws MavenExecutionException 311 | { 312 | // get the strategy from the config 313 | Xpp3Dom strategyNode = configDom.getChild( "strategy" ); 314 | if ( strategyNode == null ) 315 | { 316 | throw new MavenExecutionException( "Missing configuration, 'strategy' is required. ", pomFile ); 317 | } 318 | 319 | String hint = strategyNode.getAttribute( "hint" ); 320 | if ( hint == null ) 321 | { 322 | throw new MavenExecutionException( "Missing configuration, '' is required. ", 323 | pomFile ); 324 | } 325 | 326 | try 327 | { 328 | ExternalVersionStrategy strategy = container.lookup( ExternalVersionStrategy.class, hint ); 329 | logger.info( "component: " + strategy ); 330 | 331 | ComponentConfigurator configurator = container.lookup( ComponentConfigurator.class, "basic" ); 332 | configurator.configureComponent( strategy, new XmlPlexusConfiguration( strategyNode ), 333 | new DefaultExpressionEvaluator(), null, null ); 334 | 335 | return strategy; 336 | 337 | } 338 | catch ( ComponentLookupException e ) 339 | { 340 | throw new MavenExecutionException( e.getMessage(), e ); 341 | } 342 | catch ( ComponentConfigurationException e ) 343 | { 344 | throw new MavenExecutionException( e.getMessage(), e ); 345 | } 346 | } 347 | 348 | } 349 | -------------------------------------------------------------------------------- /maven-external-version-plugin/src/main/java/org/apache/maven/version/ExternalVersionMojo.java: -------------------------------------------------------------------------------- 1 | package org.apache.maven.version; 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | import org.apache.maven.plugin.AbstractMojo; 23 | import org.apache.maven.plugin.MojoExecutionException; 24 | import org.apache.maven.plugin.MojoFailureException; 25 | import org.apache.maven.plugins.annotations.Component; 26 | import org.apache.maven.plugins.annotations.Mojo; 27 | import org.apache.maven.plugins.annotations.Parameter; 28 | import org.apache.maven.project.MavenProject; 29 | 30 | /** 31 | * External Version extension configuration Mojo. This mojo is ONLY used to configure the extension. 32 | * 33 | * @author Brian Demers 34 | */ 35 | @Mojo( name = "external-version" ) 36 | public class ExternalVersionMojo 37 | extends AbstractMojo 38 | { 39 | 40 | @Component 41 | private MavenProject project; 42 | 43 | @Parameter( property = "strategy", required = true ) 44 | private String strategy; 45 | 46 | @Parameter( property = "external-version.deleteTemporaryFile" , defaultValue = "false" ) 47 | private Boolean deleteTemporaryFile; 48 | 49 | @Parameter( property = "external-version.generateTemporaryFile" , defaultValue = "false" ) 50 | private Boolean generateTemporaryFile; 51 | 52 | @Override 53 | public void execute() 54 | throws MojoExecutionException, MojoFailureException 55 | { 56 | getLog().info( "This mojo is used to configure an extension, and should NOT be executed directly." ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 4.0.0 24 | 25 | 26 | org.apache.maven.plugins 27 | maven-plugins 28 | 27 29 | 30 | 31 | org.apache.maven.version 32 | maven-external-version 33 | 0.1.1-SNAPSHOT 34 | 35 | pom 36 | 37 | 38 | 1.6 39 | 1.6 40 | 41 | 42 | 43 | 44 | external-version-api 45 | external-version-strategies 46 | maven-external-version-plugin 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven 53 | maven-core 54 | 3.2.5 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.apache.rat 64 | apache-rat-plugin 65 | 66 | 67 | 68 | rat-check 69 | 70 | check 71 | 72 | 73 | 74 | .checkstyle 75 | DEPENDENCIES 76 | **/src/it/** 77 | README.md 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | --------------------------------------------------------------------------------