|
11 | 11 | @ShellComponent |
12 | 12 | public class MavenExtensionCommands { |
13 | 13 |
|
14 | | - @ShellMethod("add mvn extensions and config") |
15 | | - public String extensions() { |
16 | | - try { |
17 | | - mavenConfigDir(); |
18 | | - extensionsConfig(); |
19 | | - jgitverConfig(); |
20 | | - } |
21 | | - catch (IOException ioException) { |
22 | | - return "There was a problem adding jgitver extension and config"; |
23 | | - } |
24 | | - return "Successfully added jgitver extension and config in ./.mvn"; |
25 | | - } |
| 14 | + @ShellMethod("add mvn extensions and config") |
| 15 | + public String extensions() { |
| 16 | + try { |
| 17 | + mavenConfigDir(); |
| 18 | + extensionsConfig(); |
| 19 | + mavenGitVersioningExtension(); |
| 20 | + } catch (IOException ioException) { |
| 21 | + return "There was a problem adding extensions and config"; |
| 22 | + } |
| 23 | + return "Successfully added extensions and config in ./.mvn"; |
| 24 | + } |
26 | 25 |
|
27 | | - private void extensionsConfig() throws IOException { |
28 | | - File file = new File("./.mvn/extensions.xml"); |
29 | | - if (!file.exists()) { |
30 | | - writeStringToFile(extensionsFile(), file); |
31 | | - } |
32 | | - } |
| 26 | + private void extensionsConfig() throws IOException { |
| 27 | + File file = new File("./.mvn/extensions.xml"); |
| 28 | + if (!file.exists()) { |
| 29 | + writeStringToFile(extensionsFile(), file); |
| 30 | + } |
| 31 | + } |
33 | 32 |
|
34 | | - private void jgitverConfig() throws IOException { |
35 | | - File file = new File("./.mvn/jgitver.config.xml"); |
36 | | - if (!file.exists()) { |
37 | | - writeStringToFile(jgitverConfigFile(), file); |
38 | | - } |
39 | | - } |
| 33 | + private void mavenGitVersioningExtension() throws IOException { |
| 34 | + File file = new File("./.mvn/maven-git-versioning-extension.xml"); |
| 35 | + if (!file.exists()) { |
| 36 | + writeStringToFile(mavenGitVersioningExtensionConfig(), file); |
| 37 | + } |
| 38 | + } |
40 | 39 |
|
41 | | - private String extensionsFile() { |
42 | | - return """ |
43 | | - <extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
44 | | - xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd"> |
45 | | - <extension> |
46 | | - <groupId>fr.brouillard.oss</groupId> |
47 | | - <artifactId>jgitver-maven-plugin</artifactId> |
48 | | - <version>1.9.0</version> |
49 | | - </extension> |
50 | | - <extension> |
51 | | - <groupId>kr.motd.maven</groupId> |
52 | | - <artifactId>os-maven-plugin</artifactId> |
53 | | - <version>1.7.1</version> |
54 | | - </extension> |
55 | | - </extensions> |
56 | | - """; |
57 | | - } |
| 40 | + private String extensionsFile() { |
| 41 | + return """ |
| 42 | + <extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 43 | + xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd"> |
| 44 | + <extension> |
| 45 | + <groupId>me.qoomon</groupId> |
| 46 | + <artifactId>maven-git-versioning-extension</artifactId> |
| 47 | + <version>9.11.0</version> |
| 48 | + </extension> |
| 49 | + <extension> |
| 50 | + <groupId>kr.motd.maven</groupId> |
| 51 | + <artifactId>os-maven-plugin</artifactId> |
| 52 | + <version>1.7.1</version> |
| 53 | + </extension> |
| 54 | + </extensions> |
| 55 | + """; |
| 56 | + } |
58 | 57 |
|
59 | | - private String jgitverConfigFile() { |
60 | | - return """ |
61 | | - <configuration xmlns="http://jgitver.github.io/maven/configuration/1.1.0" |
62 | | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
63 | | - xsi:schemaLocation="http://jgitver.github.io/maven/configuration/1.1.0 https://jgitver.github.io/maven/configuration/jgitver-configuration-v1_1_0.xsd"> |
64 | | - <strategy>CONFIGURABLE</strategy> |
65 | | - <policy>MAX</policy> |
66 | | - <autoIncrementPatch>true</autoIncrementPatch> |
67 | | - <useDirty>false</useDirty> |
68 | | - <useGitCommitId>false</useGitCommitId> |
69 | | - <useSnapshot>false</useSnapshot> |
70 | | - <gitCommitIdLength>8</gitCommitIdLength> |
71 | | - <nonQualifierBranches>main</nonQualifierBranches> |
72 | | - <useDefaultBranchingPolicy>true</useDefaultBranchingPolicy> |
73 | | - <exclusions> <!-- Optional list of directory path --> |
74 | | - <exclusion>.m2</exclusion> <!-- relative path from project root directory --> |
75 | | - </exclusions> |
76 | | - </configuration> |
77 | | - """; |
78 | | - } |
| 58 | + private String mavenGitVersioningExtensionConfig() { |
| 59 | + return """ |
| 60 | + <configuration xmlns="https://github.com/qoomon/maven-git-versioning-extension" |
| 61 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 62 | + xsi:schemaLocation="https://github.com/qoomon/maven-git-versioning-extension https://qoomon.github.io/maven-git-versioning-extension/configuration-9.4.0.xsd"> |
| 63 | + |
| 64 | + <refs considerTagsOnBranches="true"> |
| 65 | + <ref type="tag"> |
| 66 | + <pattern><![CDATA[v(?<version>.*)]]></pattern> |
| 67 | + <version>${ref.version}</version> |
| 68 | + </ref> |
| 69 | + <ref type="branch"> |
| 70 | + <pattern>(main|release.*)</pattern> |
| 71 | + <version>${describe.tag.version.major}.${describe.tag.version.minor}.${describe.tag.version.patch.next}-SNAPSHOT</version> |
| 72 | + </ref> |
| 73 | + <ref type="branch"> |
| 74 | + <pattern><![CDATA[feature/(?<feature>.+)]]></pattern> |
| 75 | + <version>${describe.tag.version}-${ref.feature}-SNAPSHOT</version> |
| 76 | + </ref> |
| 77 | + </refs> |
| 78 | + <rev> |
| 79 | + <version>${commit}</version> |
| 80 | + </rev> |
| 81 | + </configuration> |
| 82 | + """; |
| 83 | + } |
79 | 84 |
|
80 | | - private void mavenConfigDir() throws IOException { |
81 | | - File file = new File("./.mvn"); |
82 | | - if (!file.exists()) { |
83 | | - if (!file.mkdir()) { |
84 | | - throw new IOException("Couldn't create directory"); |
85 | | - } |
86 | | - } |
87 | | - } |
| 85 | + private void mavenConfigDir() throws IOException { |
| 86 | + File file = new File("./.mvn"); |
| 87 | + if (!file.exists()) { |
| 88 | + if (!file.mkdir()) { |
| 89 | + throw new IOException("Couldn't create directory"); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
88 | 93 |
|
89 | 94 | } |
0 commit comments