upToDatePropertySettings;
49 |
50 | /**
51 | * Disables the plug-in execution.
52 | */
53 | @Parameter(property = "buildhelper.uptodateproperties.skip", defaultValue = "false")
54 | private boolean skip;
55 |
56 | /** {@inheritDoc} */
57 | @Override
58 | public void execute() throws MojoExecutionException, MojoFailureException {
59 | if (skip) {
60 | getLog().info("uptodate-properties is skipped.");
61 | return;
62 | }
63 |
64 | if (upToDatePropertySettings != null) {
65 | for (UpToDatePropertySetting config : upToDatePropertySettings) {
66 | this.execute(config);
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/it/reserve-ports-with-min-root-range/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.codehaus.mojo
6 | build-helper-maven-plugin-reverse-port-it
7 | 1.0-SNAPSHOT
8 |
9 | build-helper-maven-plugin-reverse-port-it
10 |
11 |
12 |
13 |
14 | package
15 |
16 |
17 |
18 |
19 |
20 |
21 | @project.groupId@
22 | @project.artifactId@
23 | @project.version@
24 |
25 |
26 |
27 | reserve-ports
28 | process-test-resources
29 |
30 | reserve-network-port
31 |
32 |
33 |
34 | port1
35 | port2
36 | port3
37 |
38 |
39 | 10000
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-antrun-plugin
48 | @maven-antrun-plugin.version@
49 |
50 |
51 | mk-target-dir
52 | compile
53 |
54 | run
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | echo-reserve-ports
65 | test
66 |
67 | run
68 |
69 |
70 |
71 | port1=${port1}
72 | port2=${port2}
73 | port3=${port3}
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
92 |
93 |
--------------------------------------------------------------------------------
/src/it/reserve-ports-with-urls/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | org.codehaus.mojo
5 | build-helper-maven-plugin-reverse-port-it
6 | 1.0-SNAPSHOT
7 | build-helper-maven-plugin-reverse-port-it
8 |
9 |
10 | package
11 |
12 |
13 | @project.groupId@
14 | @project.artifactId@
15 | @project.version@
16 |
17 |
18 | reserve-ports
19 | process-test-resources
20 |
21 | reserve-network-port
22 |
23 |
24 |
25 | file:///${project.basedir}/names2.txt
26 |
27 |
28 |
29 |
30 | reserve-ports-to-files
31 | process-test-resources
32 |
33 | reserve-network-port
34 |
35 |
36 | ${project.build.directory}/ports.properties
37 |
38 | file:///${project.basedir}/names1.txt
39 | file:///${project.basedir}/names2.txt
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-antrun-plugin
48 | @maven-antrun-plugin.version@
49 |
50 |
51 | mk-target-dir
52 | compile
53 |
54 | run
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | echo-reserve-ports
65 | test
66 |
67 | run
68 |
69 |
70 |
71 | port1=${port1}
72 | port2=${port2}
73 | port3=${port3}
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/buildhelper/Artifact.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.buildhelper;
2 |
3 | /*
4 | * The MIT License
5 | *
6 | * Copyright (c) 2004, The Codehaus
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | * this software and associated documentation files (the "Software"), to deal in
10 | * the Software without restriction, including without limitation the rights to
11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 | * of the Software, and to permit persons to whom the Software is furnished to do
13 | * so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in all
16 | * copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | import java.io.File;
28 |
29 | /**
30 | *
31 | * Artifact class.
32 | *
33 | *
34 | * @author dtran
35 | */
36 | public class Artifact {
37 | private File file;
38 |
39 | private String type = "jar";
40 |
41 | private String classifier;
42 |
43 | /**
44 | *
45 | * Setter for the field file.
46 | *
47 | *
48 | * @param localFile a {@link java.io.File} object.
49 | */
50 | public void setFile(File localFile) {
51 | this.file = localFile;
52 | }
53 |
54 | /**
55 | *
56 | * Getter for the field file.
57 | *
58 | *
59 | * @return a {@link java.io.File} object.
60 | */
61 | public File getFile() {
62 | return this.file;
63 | }
64 |
65 | /**
66 | *
67 | * Setter for the field type.
68 | *
69 | *
70 | * @param type a {@link java.lang.String} object.
71 | */
72 | public void setType(String type) {
73 | this.type = type;
74 | }
75 |
76 | /**
77 | *
78 | * Getter for the field type.
79 | *
80 | *
81 | * @return a {@link java.lang.String} object.
82 | */
83 | public String getType() {
84 | return this.type;
85 | }
86 |
87 | /**
88 | *
89 | * Setter for the field classifier.
90 | *
91 | *
92 | * @param classifier a {@link java.lang.String} object.
93 | */
94 | public void setClassifier(String classifier) {
95 | this.classifier = classifier;
96 | }
97 |
98 | /**
99 | *
100 | * Getter for the field classifier.
101 | *
102 | *
103 | * @return a {@link java.lang.String} object.
104 | */
105 | public String getClassifier() {
106 | return this.classifier;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/buildhelper/UpToDatePropertyMojo.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.buildhelper;
2 |
3 | /*
4 | * The MIT License
5 | *
6 | * Copyright (c) 2004, The Codehaus
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | * this software and associated documentation files (the "Software"), to deal in
10 | * the Software without restriction, including without limitation the rights to
11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 | * of the Software, and to permit persons to whom the Software is furnished to do
13 | * so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in all
16 | * copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | import org.apache.maven.plugin.MojoExecutionException;
28 | import org.apache.maven.plugin.MojoFailureException;
29 | import org.apache.maven.plugins.annotations.LifecyclePhase;
30 | import org.apache.maven.plugins.annotations.Mojo;
31 | import org.apache.maven.plugins.annotations.Parameter;
32 | import org.apache.maven.shared.model.fileset.FileSet;
33 |
34 | /**
35 | * Sets a property according to whether one set of resources is up to date with respect to another.
36 | *
37 | * @author Adrian Price demonfiddler@virginmedia.com
38 | * @since 1.12
39 | */
40 | @Mojo(name = "uptodate-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true)
41 | public class UpToDatePropertyMojo extends AbstractUpToDatePropertyMojo {
42 | /**
43 | * The name of the property to set.
44 | */
45 | @Parameter(required = true)
46 | private String name;
47 |
48 | /**
49 | * Disables the plug-in execution.
50 | */
51 | @Parameter(property = "buildhelper.uptodateproperty.skip", defaultValue = "false")
52 | private boolean skip;
53 |
54 | /**
55 | * The file set to check.
56 | */
57 | @Parameter(required = true)
58 | private FileSet fileSet;
59 |
60 | /**
61 | * The property value to set if the up-to-date condition is fulfilled.
62 | */
63 | @Parameter(defaultValue = "true")
64 | private String value;
65 |
66 | /**
67 | * The property value to set if the up-to-date condition is not fulfilled.
68 | */
69 | @Parameter(alias = "else")
70 | private String elseValue;
71 |
72 | /** {@inheritDoc} */
73 | @Override
74 | public void execute() throws MojoExecutionException, MojoFailureException {
75 | if (skip) {
76 | getLog().info("uptodate-property is skipped.");
77 | return;
78 | }
79 |
80 | UpToDatePropertySetting config = new UpToDatePropertySetting();
81 | config.setName(name);
82 | config.setValue(value);
83 | config.setElse(elseValue);
84 | config.setFileSet(fileSet);
85 | execute(config);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/it/reserve-ports/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.codehaus.mojo
6 | build-helper-maven-plugin-reverse-port-it
7 | 1.0-SNAPSHOT
8 |
9 | build-helper-maven-plugin-reverse-port-it
10 |
11 |
12 |
13 |
14 | package
15 |
16 |
17 |
18 |
19 |
20 |
21 | @project.groupId@
22 | @project.artifactId@
23 | @project.version@
24 |
25 |
26 |
27 | reserve-ports
28 | process-test-resources
29 |
30 | reserve-network-port
31 |
32 |
33 |
34 | port1
35 | port2
36 | port3
37 |
38 |
39 |
40 |
41 | reserve-ports-to-files
42 | process-test-resources
43 |
44 | reserve-network-port
45 |
46 |
47 | ${project.build.directory}/ports.properties
48 |
49 | port3
50 | port4
51 | port5
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-antrun-plugin
61 | @maven-antrun-plugin.version@
62 |
63 |
64 | mk-target-dir
65 | compile
66 |
67 | run
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | echo-reserve-ports
78 | test
79 |
80 | run
81 |
82 |
83 |
84 | port1=${port1}
85 | port2=${port2}
86 | port3=${port3}
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
105 |
106 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.buildhelper;
2 |
3 | /*
4 | * The MIT License
5 | *
6 | * Copyright (c) 2004, The Codehaus
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | * this software and associated documentation files (the "Software"), to deal in
10 | * the Software without restriction, including without limitation the rights to
11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 | * of the Software, and to permit persons to whom the Software is furnished to do
13 | * so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in all
16 | * copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | import java.io.File;
28 |
29 | import org.apache.maven.plugin.AbstractMojo;
30 | import org.apache.maven.plugins.annotations.LifecyclePhase;
31 | import org.apache.maven.plugins.annotations.Mojo;
32 | import org.apache.maven.plugins.annotations.Parameter;
33 | import org.apache.maven.project.MavenProject;
34 |
35 | /**
36 | * Add more source directories to the POM.
37 | *
38 | * @author Dan T. Tran
39 | * @since 1.0
40 | */
41 | @Mojo(name = "add-source", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
42 | public class AddSourceMojo extends AbstractMojo {
43 | /**
44 | * Additional source directories.
45 | *
46 | * @since 1.0
47 | */
48 | @Parameter(property = "sources", required = true)
49 | private File[] sources;
50 |
51 | /**
52 | * @since 1.0
53 | */
54 | @Parameter(readonly = true, defaultValue = "${project}")
55 | private MavenProject project;
56 |
57 | /**
58 | * Skip plugin execution.
59 | *
60 | * @since 3.5.0
61 | */
62 | @Parameter(property = "buildhelper.addsource.skip", defaultValue = "false")
63 | private boolean skipAddSource;
64 |
65 | /**
66 | * If a directory does not exist, do not add it as a source root.
67 | *
68 | * @since 3.5.0
69 | */
70 | @Parameter(property = "buildhelper.addsource.skipIfMissing", defaultValue = "false")
71 | private boolean skipAddSourceIfMissing;
72 |
73 | public void execute() {
74 | if (skipAddSource) {
75 | if (getLog().isInfoEnabled()) {
76 | getLog().info("Skipping plugin execution!");
77 | }
78 | return;
79 | }
80 |
81 | for (File source : sources) {
82 | if (skipAddSourceIfMissing && !source.exists()) {
83 | if (getLog().isDebugEnabled()) {
84 | getLog().debug("Skipping directory: " + source + ", because it does not exist.");
85 | }
86 | } else {
87 | this.project.addCompileSourceRoot(source.getAbsolutePath());
88 | if (getLog().isInfoEnabled()) {
89 | getLog().info("Source directory: " + source + " added.");
90 | }
91 | }
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/buildhelper/AbstractRegexPropertyMojo.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.buildhelper;
2 |
3 | /*
4 | * The MIT License
5 | *
6 | * Copyright (c) 2004, The Codehaus
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | * this software and associated documentation files (the "Software"), to deal in
10 | * the Software without restriction, including without limitation the rights to
11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 | * of the Software, and to permit persons to whom the Software is furnished to do
13 | * so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in all
16 | * copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | import java.util.Locale;
28 | import java.util.regex.Matcher;
29 | import java.util.regex.Pattern;
30 | import java.util.regex.PatternSyntaxException;
31 |
32 | import org.apache.maven.plugin.MojoExecutionException;
33 | import org.apache.maven.plugin.MojoFailureException;
34 | import org.codehaus.plexus.util.StringUtils;
35 |
36 | public abstract class AbstractRegexPropertyMojo extends AbstractDefinePropertyMojo {
37 |
38 | protected void execute(RegexPropertySetting config) throws MojoExecutionException, MojoFailureException {
39 | try {
40 | config.validate();
41 | } catch (IllegalArgumentException e) {
42 | throw new MojoExecutionException(e.getMessage(), e);
43 | }
44 |
45 | Pattern pattern;
46 | try {
47 | pattern = Pattern.compile(config.getRegex());
48 | } catch (PatternSyntaxException e) {
49 | throw new MojoExecutionException(e.getMessage(), e);
50 | }
51 | Matcher matcher = pattern.matcher(config.getValue());
52 |
53 | if (matcher.find()) {
54 | // if the string replacement is empty, we define the value replacement to empty.
55 | config.setValue(
56 | (StringUtils.isNotEmpty(config.getReplacement())
57 | ? matcher.replaceAll(config.getReplacement())
58 | : matcher.replaceAll("")));
59 | } else {
60 | if (config.isFailIfNoMatch()) {
61 | throw new MojoFailureException(
62 | "No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'.");
63 | } else {
64 | getLog().info("No match to regex '" + config.getRegex() + "' found in '" + config.getValue() + "'. "
65 | + "The initial value '" + config.getValue() + "' is left as-is...");
66 | }
67 | }
68 |
69 | if (config.isToLowerCase()) {
70 | config.setValue(config.getValue().toLowerCase(Locale.getDefault()));
71 | }
72 |
73 | if (config.isToUpperCase()) {
74 | config.setValue(config.getValue().toUpperCase(Locale.getDefault()));
75 | }
76 |
77 | defineProperty(config.getName(), config.getValue());
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.buildhelper;
2 |
3 | /*
4 | * The MIT License
5 | *
6 | * Copyright (c) 2004, The Codehaus
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | * this software and associated documentation files (the "Software"), to deal in
10 | * the Software without restriction, including without limitation the rights to
11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 | * of the Software, and to permit persons to whom the Software is furnished to do
13 | * so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in all
16 | * copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | import java.io.File;
28 |
29 | import org.apache.maven.plugin.AbstractMojo;
30 | import org.apache.maven.plugins.annotations.LifecyclePhase;
31 | import org.apache.maven.plugins.annotations.Mojo;
32 | import org.apache.maven.plugins.annotations.Parameter;
33 | import org.apache.maven.project.MavenProject;
34 |
35 | /**
36 | * Add test source directories to the POM.
37 | *
38 | * @author Dan T. Tran
39 | * @since 1.0
40 | */
41 | @Mojo(name = "add-test-source", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, threadSafe = true)
42 | public class AddTestSourceMojo extends AbstractMojo {
43 |
44 | /**
45 | * Additional test source directories.
46 | *
47 | * @since 1.0
48 | */
49 | @Parameter(required = true)
50 | private File[] sources;
51 |
52 | /**
53 | * @since 1.0
54 | */
55 | @Parameter(readonly = true, defaultValue = "${project}")
56 | private MavenProject project;
57 |
58 | /**
59 | * Skip plugin execution.
60 | *
61 | * @since 3.5.0
62 | */
63 | @Parameter(property = "buildhelper.addtestsource.skip", defaultValue = "false")
64 | private boolean skipAddTestSource;
65 |
66 | /**
67 | * If a directory does not exist, do not add it as a test source root.
68 | *
69 | * @since 3.5.0
70 | */
71 | @Parameter(property = "buildhelper.addtestsource.skipIfMissing", defaultValue = "false")
72 | private boolean skipAddTestSourceIfMissing;
73 |
74 | public void execute() {
75 | if (skipAddTestSource) {
76 | if (getLog().isInfoEnabled()) {
77 | getLog().info("Skipping plugin execution!");
78 | }
79 | return;
80 | }
81 |
82 | for (File source : sources) {
83 | if (skipAddTestSourceIfMissing && !source.exists()) {
84 | if (getLog().isDebugEnabled()) {
85 | getLog().debug("Skipping directory: " + source + ", because it does not exist.");
86 | }
87 | } else {
88 | this.project.addTestCompileSourceRoot(source.getAbsolutePath());
89 | if (getLog().isInfoEnabled()) {
90 | getLog().info("Test Source directory: " + source + " added.");
91 | }
92 | }
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/codehaus/mojo/buildhelper/RegexPropertyMojo.java:
--------------------------------------------------------------------------------
1 | package org.codehaus.mojo.buildhelper;
2 |
3 | /*
4 | * The MIT License
5 | *
6 | * Copyright (c) 2004, The Codehaus
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 | * this software and associated documentation files (the "Software"), to deal in
10 | * the Software without restriction, including without limitation the rights to
11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 | * of the Software, and to permit persons to whom the Software is furnished to do
13 | * so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in all
16 | * copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | * SOFTWARE.
25 | */
26 |
27 | import org.apache.maven.plugin.MojoExecutionException;
28 | import org.apache.maven.plugin.MojoFailureException;
29 | import org.apache.maven.plugins.annotations.LifecyclePhase;
30 | import org.apache.maven.plugins.annotations.Mojo;
31 | import org.apache.maven.plugins.annotations.Parameter;
32 |
33 | /**
34 | * Sets a property by applying a regex replacement rule to a supplied value.
35 | *
36 | * @author Stephen Connolly
37 | * @since 1.7
38 | */
39 | @Mojo(name = "regex-property", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true)
40 | public class RegexPropertyMojo extends AbstractRegexPropertyMojo {
41 | /**
42 | * The property to set.
43 | */
44 | @Parameter(required = true)
45 | private String name;
46 |
47 | /**
48 | * The pre-transformation value.
49 | */
50 | @Parameter(required = true)
51 | private String value;
52 |
53 | /**
54 | * The regex to replace.
55 | */
56 | @Parameter(required = true)
57 | private String regex;
58 |
59 | /**
60 | * The replacement.
61 | */
62 | @Parameter(defaultValue = "")
63 | private String replacement;
64 |
65 | /**
66 | * Whether to fail if no match is found.
67 | */
68 | @Parameter(defaultValue = "true")
69 | private boolean failIfNoMatch;
70 |
71 | /**
72 | * Make the value of the resulting property upper case.
73 | *
74 | * @since 1.11
75 | */
76 | @Parameter(defaultValue = "false")
77 | private boolean toUpperCase;
78 |
79 | /**
80 | * Make the value of the resulting property lower case.
81 | *
82 | * @since 1.11
83 | */
84 | @Parameter(defaultValue = "false")
85 | private boolean toLowerCase;
86 |
87 | /**
88 | * {@inheritDoc}
89 | */
90 | public void execute() throws MojoExecutionException, MojoFailureException {
91 | RegexPropertySetting config = new RegexPropertySetting();
92 | config.setName(name);
93 | config.setValue(value);
94 | config.setRegex(regex);
95 | config.setReplacement(replacement);
96 | config.setFailIfNoMatch(failIfNoMatch);
97 | config.setToLowerCase(toLowerCase);
98 | config.setToUpperCase(toUpperCase);
99 |
100 | this.execute(config);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------