diff --git a/pom.xml b/pom.xml index 6ccd830..a09e7d7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,13 +1,13 @@ - - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd"> + 4.1.0 com.inteligr8 regex-maven-plugin - 1.0-SNAPSHOT + 2.0-SNAPSHOT maven-plugin Regular Expression Maven Plugin @@ -35,62 +35,90 @@ brian.long Brian Long brian@inteligr8.com - https://twitter.com/brianmlong + https://x.com/brianmlong UTF-8 - 1.8 - 1.8 - 3.9.11 + 17 + 17 + 17 + 4.0.0-rc-5 + + + + org.apache.commons + commons-lang3 + 3.20.0 + + + org.apache.maven.shared + file-management + 3.2.0 + + + org.apache.maven + maven-api-core + ${maven.version} + + + org.apache.maven + maven-api-annotations + ${maven.version} + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 3.5.1 + + + org.apache.maven + maven-compat + ${maven.version} + + + org.junit.jupiter + junit-jupiter-api + 6.0.3 + + + + org.apache.commons commons-lang3 - 3.20.0 org.apache.maven.shared file-management - 3.2.0 org.apache.maven - maven-plugin-api - ${maven.version} - provided - - - org.apache.maven.plugin-tools - maven-plugin-annotations - 3.15.1 + maven-api-core provided org.apache.maven - maven-core - ${maven.version} + maven-api-annotations provided org.apache.maven.plugin-testing maven-plugin-testing-harness - 3.3.0 test org.apache.maven maven-compat - ${maven.version} test - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-api test @@ -104,12 +132,7 @@ maven-invoker-plugin - 3.9.1 - - - org.codehaus.plexus - plexus-component-metadata - 2.2.0 + 3.10.1 @@ -134,6 +157,7 @@ + maven-invoker-plugin diff --git a/src/main/java/com/inteligr8/maven/ProjectPropertyResolver.java b/src/main/java/com/inteligr8/maven/ProjectPropertyResolver.java deleted file mode 100644 index 36e9c76..0000000 --- a/src/main/java/com/inteligr8/maven/ProjectPropertyResolver.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ -package com.inteligr8.maven; - -import java.util.Properties; - -public interface ProjectPropertyResolver { - - Properties resolveScope(String propertyName); - - String resolve(String propertyName); - - String resolve(String propertyName, String defaultValue); - -} diff --git a/src/main/java/com/inteligr8/maven/StandardProjectPropertyResolver.java b/src/main/java/com/inteligr8/maven/StandardProjectPropertyResolver.java deleted file mode 100644 index 0418c5d..0000000 --- a/src/main/java/com/inteligr8/maven/StandardProjectPropertyResolver.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ -package com.inteligr8.maven; - -import java.util.Properties; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Profile; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.AbstractLogEnabled; - -@Component(role = ProjectPropertyResolver.class, instantiationStrategy = "per-lookup") -public class StandardProjectPropertyResolver extends AbstractLogEnabled implements ProjectPropertyResolver { - - @Requirement - private MavenSession session; - - @Requirement - private MavenProject project; - - @Override - public String resolve(String propertyName) { - Properties props = this.findPropertiesObject(propertyName); - return props == null ? null : props.getProperty(propertyName); - } - - @Override - public String resolve(String propertyName, String defaultValue) { - Properties props = this.findPropertiesObject(propertyName); - return props == null ? null : props.getProperty(propertyName, defaultValue); - } - - @Override - public Properties resolveScope(String propertyName) { - return this.findPropertiesObject(propertyName); - } - - private Properties findPropertiesObject(String key) { - // search the user/cli properties first - Properties props = this.session.getUserProperties(); - if (props.containsKey(key)) { - this.getLogger().debug("Found in session user properties: " + key); - return props; - } - - MavenProject ancestor = this.project; - while (ancestor != null) { - // search the profiles next; in order (FIXME maybe we should go backwards?) - for (Profile profile : ancestor.getActiveProfiles()) { - props = profile.getProperties(); - if (props.containsKey(key)) { - this.getLogger().debug("Found in project profile properties: " + ancestor.getArtifact() + ": " + profile.getId() + ": " + key); - return props; - } - } - - // now look at the project props - props = ancestor.getProperties(); - if (props.containsKey(key)) { - this.getLogger().debug("Found in project properties: " + ancestor.getArtifact() + ": " + key); - return props; - } - - ancestor = ancestor.getParent(); - } - - // search the system properties last (FIXME is this right?) - props = this.session.getSystemProperties(); - if (props.containsKey(key)) { - this.getLogger().debug("Found in system properties: " + key); - return props; - } - - return null; - } - -} diff --git a/src/main/java/com/inteligr8/maven/regex/AbstractFileMojo.java b/src/main/java/com/inteligr8/maven/regex/AbstractFileMojo.java index ad2e90e..63b696a 100644 --- a/src/main/java/com/inteligr8/maven/regex/AbstractFileMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/AbstractFileMojo.java @@ -14,7 +14,6 @@ */ package com.inteligr8.maven.regex; -import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; @@ -22,29 +21,31 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Parameter; public abstract class AbstractFileMojo extends AbstractReplaceMojo { + + @Inject + private Log logger; @Parameter( property = "sourceDirectory", required = false ) - protected File sourceDirectory; + protected Path sourceDirectory; @Parameter( property = "targetDirectory", required = false ) - protected File targetDirectory; + protected Path targetDirectory; @Parameter( property = "overwrite", required = true, defaultValue = "true" ) protected boolean overwrite = true; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing file regex"); + public void go() throws MojoException { + this.logger.debug("Executing file regex"); - final Path sourcePath = this.sourceDirectory.toPath(); - final Path targetPath = this.targetDirectory.toPath(); try { - Files.walkFileTree(sourcePath, new FileVisitor() { + Files.walkFileTree(this.sourceDirectory, new FileVisitor() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { @@ -61,12 +62,12 @@ public abstract class AbstractFileMojo extends AbstractReplaceMojo { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!Files.isDirectory(file)) { - String relativePath = sourcePath.relativize(file).toString(); + String relativePath = sourceDirectory.relativize(file).toString(); String replacedRelativePath = replaceFirst(relativePath); if (!relativePath.equals(replacedRelativePath)) { - Path newFile = targetPath.resolve(replacedRelativePath); + Path newFile = targetDirectory.resolve(replacedRelativePath); if (file.equals(newFile)) { - AbstractFileMojo.this.getLog().error("Relative paths are different, but the resultant paths are the same??"); + AbstractFileMojo.this.logger.error("Relative paths are different, but the resultant paths are the same??"); throw new RuntimeException("This should never happen"); } @@ -83,14 +84,14 @@ public abstract class AbstractFileMojo extends AbstractReplaceMojo { } }); } catch (IOException ie) { - throw new MojoExecutionException(ie.getMessage(), ie); + throw new MojoException(ie.getMessage(), ie); } } protected abstract void executeOnFile(Path sourcePath, Path targetPath) throws IOException; @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); if (this.sourceDirectory == null) diff --git a/src/main/java/com/inteligr8/maven/regex/AbstractMatchMojo.java b/src/main/java/com/inteligr8/maven/regex/AbstractMatchMojo.java index 24af244..b9d003d 100644 --- a/src/main/java/com/inteligr8/maven/regex/AbstractMatchMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/AbstractMatchMojo.java @@ -22,17 +22,21 @@ import java.nio.file.StandardOpenOption; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; -import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Parameter; -import com.inteligr8.nio.DelimitedReadableByteChannel; +import com.inteligr8.maven.regex.nio.DelimitedReadableByteChannel; public abstract class AbstractMatchMojo extends AbstractRegexMojo { + + @Inject + private Log logger; @Parameter( property = "allowPartialMatch", required = true, defaultValue = "true" ) protected boolean allowPartialMatch = true; @@ -46,15 +50,14 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo { private List compiledPatterns; @Override - protected void executeOnText(Properties props, String text, String newPropertyName) { + protected void executeOnText(String text, String newPropertyName) { boolean matches = this.matches(text); if (this.verbose) - this.getLog().info("Setting property: " + newPropertyName + ": " + matches); + this.logger.info("Setting property: " + newPropertyName + ": " + matches); else if (matches) - this.getLog().info("Matches!"); - if (props == null) - props = this.project.getProperties(); - props.setProperty(newPropertyName, String.valueOf(matches)); + this.logger.info("Matches!"); + + this.manager.setProperty(this.project, newPropertyName, String.valueOf(matches)); } protected boolean matches(Path file, int chunkSize) throws IOException { @@ -94,20 +97,20 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo { text = ""; for (Pattern pattern : this.compiledPatterns) { - this.getLog().debug("Applying regex pattern: " + pattern); - this.getLog().debug("Operating on value: " + text); + this.logger.debug("Applying regex pattern: " + pattern); + this.logger.debug("Operating on value: " + text); Matcher matcher = pattern.matcher(text); if (this.allowPartialMatch) { if (matcher.find()) { if (this.verbose) - this.getLog().info("Pattern '" + pattern + "' matches text: " + text); + this.logger.info("Pattern '" + pattern + "' matches text: " + text); return !this.negate; } } else { if (matcher.matches()) { if (this.verbose) - this.getLog().info("Pattern '" + pattern + "' matches text: " + text); + this.logger.info("Pattern '" + pattern + "' matches text: " + text); return !this.negate; } } @@ -117,15 +120,15 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo { } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.patterns == null) - throw new MojoFailureException("A 'patterns' element is required"); + throw new MojoException("A 'patterns' element is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); ListIterator p = this.patterns.listIterator(); @@ -138,19 +141,19 @@ public abstract class AbstractMatchMojo extends AbstractRegexMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.patterns.isEmpty()) - throw new MojoFailureException("At least one 'patterns' element is required"); + throw new MojoException("At least one 'patterns' element is required"); this.compiledPatterns = new LinkedList<>(); for (String pattern : this.patterns) { - this.getLog().debug("Compiling regex pattern: " + pattern); + this.logger.debug("Compiling regex pattern: " + pattern); try { this.compiledPatterns.add(Pattern.compile(pattern)); } catch (PatternSyntaxException pse) { - throw new MojoFailureException("'" + pattern + "' is not a valid regular expression: " + pse.getMessage()); + throw new MojoException("'" + pattern + "' is not a valid regular expression: " + pse.getMessage()); } } } diff --git a/src/main/java/com/inteligr8/maven/regex/AbstractRegexMojo.java b/src/main/java/com/inteligr8/maven/regex/AbstractRegexMojo.java index c45e134..754770a 100644 --- a/src/main/java/com/inteligr8/maven/regex/AbstractRegexMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/AbstractRegexMojo.java @@ -14,28 +14,30 @@ */ package com.inteligr8.maven.regex; -import java.util.Properties; +import java.util.Map; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Requirement; +import org.apache.maven.api.Project; +import org.apache.maven.api.Session; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.Mojo; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Parameter; +import org.apache.maven.api.services.ProjectManager; -import com.inteligr8.maven.ProjectPropertyResolver; - -public abstract class AbstractRegexMojo extends AbstractMojo { +public abstract class AbstractRegexMojo implements Mojo { + + @Inject + private Log logger; - @Parameter( defaultValue = "${project}", readonly = true ) - protected MavenProject project; + @Inject + protected Project project; - @Parameter( defaultValue = "${session}", readonly = true ) - protected MavenSession session; - - @Requirement - private ProjectPropertyResolver propResolver; + @Inject + protected Session session; + + @Inject + protected ProjectManager manager; @Parameter( property = "allowMultiLineMatch", required = true, defaultValue = "false" ) protected boolean allowMultiLineMatch = false; @@ -49,9 +51,9 @@ public abstract class AbstractRegexMojo extends AbstractMojo { @Parameter( property = "verbose", required = true, defaultValue = "false" ) protected boolean verbose = false; - public final void execute() throws MojoExecutionException, MojoFailureException { + public final void execute() throws MojoException { if (this.skip) { - this.getLog().debug("Skipped execution"); + this.logger.debug("Skipped execution"); return; } @@ -62,31 +64,33 @@ public abstract class AbstractRegexMojo extends AbstractMojo { this.go(); } - protected abstract void go() throws MojoExecutionException, MojoFailureException; + protected abstract void go() throws MojoException; - protected void validateParamsPreNormalization() throws MojoFailureException { - this.getLog().debug("Validating parameters before their normalization"); + protected void validateParamsPreNormalization() throws MojoException { + this.logger.debug("Validating parameters before their normalization"); } - protected void normalizeParameters() throws MojoFailureException { - this.getLog().debug("Normalizing parameters"); + protected void normalizeParameters() throws MojoException { + this.logger.debug("Normalizing parameters"); } - protected void validateParamsPostNormalization() throws MojoFailureException { - this.getLog().debug("Validating parameters after their normalization"); + protected void validateParamsPostNormalization() throws MojoException { + this.logger.debug("Validating parameters after their normalization"); } protected final void executeOnProperty(String propertyName, String newPropertyName) { - this.getLog().debug("Finding property: " + propertyName); + this.logger.debug("Finding property: " + propertyName); - Properties props = this.propResolver.resolveScope(propertyName); - if (props == null) - this.getLog().debug("Property not found: " + propertyName); + // FIXME getEffectiveProperties() is not cached and could be expensive if called a lot + // maybe create a session scoped service that handles that part + Map props = this.session.getEffectiveProperties(this.project); + String existingPropertyValue = props.get(propertyName); + if (existingPropertyValue == null) + this.logger.debug("Property not found: " + propertyName); - String propertyValue = props == null ? null : props.getProperty(propertyName); - this.executeOnText(props, propertyValue, newPropertyName); + this.executeOnText(existingPropertyValue, newPropertyName); } - protected abstract void executeOnText(Properties props, String text, String newPropertyName); + protected abstract void executeOnText(String text, String newPropertyName); } diff --git a/src/main/java/com/inteligr8/maven/regex/AbstractReplaceMojo.java b/src/main/java/com/inteligr8/maven/regex/AbstractReplaceMojo.java index 0527dd3..263c285 100644 --- a/src/main/java/com/inteligr8/maven/regex/AbstractReplaceMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/AbstractReplaceMojo.java @@ -24,7 +24,6 @@ import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; import java.util.LinkedList; import java.util.List; -import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -32,13 +31,18 @@ import java.util.regex.PatternSyntaxException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutableTriple; import org.apache.commons.lang3.tuple.Triple; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Parameter; -import com.inteligr8.maven.model.Regex; -import com.inteligr8.nio.DelimitedReadableByteChannel; +import com.inteligr8.maven.regex.model.Regex; +import com.inteligr8.maven.regex.nio.DelimitedReadableByteChannel; public abstract class AbstractReplaceMojo extends AbstractRegexMojo { + + @Inject + private Log logger; @Parameter( property = "regexes", required = true ) protected Regex[] regexes; @@ -47,7 +51,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { private List> compiledRegexes; @Override - protected void executeOnText(Properties props, String text, String newPropertyName) { + protected void executeOnText(String text, String newPropertyName) { if (text == null) text = ""; String originalText = text; @@ -55,18 +59,17 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { if (!text.equals(originalText)) { if (this.verbose) - this.getLog().info("Setting property: " + newPropertyName + ": " + text); - else if (this.getLog().isDebugEnabled()) - this.getLog().debug("Manipulated value: " + text); + this.logger.info("Setting property: " + newPropertyName + ": " + text); + else if (this.logger.isDebugEnabled()) + this.logger.debug("Manipulated value: " + text); } - if (props == null) - props = this.project.getProperties(); - props.setProperty(newPropertyName, text); + + this.manager.setProperty(this.project, newPropertyName, text); } protected boolean replaceFirst(Path file, Path tofile, int chunkSize) throws IOException { - if (this.getLog().isDebugEnabled()) - this.getLog().debug("replace first: " + file + " => " + tofile); + if (this.logger.isDebugEnabled()) + this.logger.debug("replace first: " + file + " => " + tofile); boolean didReplace = false; Charset charset = Charset.forName(this.charsetName); @@ -119,12 +122,12 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { protected String replaceFirst(String text) { if (text == null) text = ""; - if (this.getLog().isDebugEnabled()) - this.getLog().debug("replace first: " + text.length()); + if (this.logger.isDebugEnabled()) + this.logger.debug("replace first: " + text.length()); for (Triple regex : this.compiledRegexes) { - this.getLog().debug("Applying regex pattern: " + regex.getLeft()); - this.getLog().debug("Operating on value: " + text); + this.logger.debug("Applying regex pattern: " + regex.getLeft()); + this.logger.debug("Operating on value: " + text); Matcher matcher = regex.getLeft().matcher(text); if (regex.getRight() == null) { @@ -142,8 +145,8 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { } protected boolean replaceAll(Path file, Path tofile, int chunkSize) throws IOException { - if (this.getLog().isDebugEnabled()) - this.getLog().debug("replace all: " + file + " => " + tofile); + if (this.logger.isDebugEnabled()) + this.logger.debug("replace all: " + file + " => " + tofile); boolean overwrite = file.equals(tofile); boolean didReplace = false; @@ -169,10 +172,10 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { strbuilder.append(rbchannel.getLastDelimiterRead()); } else { String line = strbuilder.toString(); - this.getLog().debug("line: " + line); + this.logger.debug("line: " + line); String processedLine = this.replaceAll(line); - if (!didReplace || (this.getLog().isDebugEnabled() && !line.equals(processedLine))) { - this.getLog().debug("replaced line: " + processedLine); + if (!didReplace || (this.logger.isDebugEnabled() && !line.equals(processedLine))) { + this.logger.debug("replaced line: " + processedLine); didReplace = true; } @@ -210,14 +213,14 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { text = ""; for (Triple regex : this.compiledRegexes) { - this.getLog().debug("Applying regex pattern: " + regex.getLeft()); - this.getLog().debug("Operating on value: " + text); + this.logger.debug("Applying regex pattern: " + regex.getLeft()); + this.logger.debug("Operating on value: " + text); Matcher matcher = regex.getLeft().matcher(text); if (regex.getRight() == null) { String newtext = matcher.replaceAll(regex.getMiddle()); if (this.verbose) - this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext); + this.logger.info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext); text = newtext; } else while (matcher.find()) { Integer previousMatchStart = this.findLastMatchIndex(regex.getRight(), text.substring(0, matcher.start())); @@ -226,7 +229,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { } else { String newtext = text.substring(0, previousMatchStart) + text.substring(matcher.start()); if (this.verbose) - this.getLog().info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text); + this.logger.info("Pattern '" + regex.getRight() + "' matches text: " + text + "; chopped until next pattern: " + text); text = newtext; matcher = regex.getLeft().matcher(text); @@ -234,7 +237,7 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { String newtext = matcher.replaceFirst(regex.getMiddle()); if (this.verbose) - this.getLog().info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext); + this.logger.info("Pattern '" + regex.getLeft() + "' matches text: " + text + "; replaced with: " + newtext); text = newtext; } } @@ -252,15 +255,15 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.regexes == null || this.regexes.length == 0) - throw new MojoFailureException("A 'regexes' element is required"); + throw new MojoException("A 'regexes' element is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); for (Regex regex : this.regexes) @@ -268,22 +271,22 @@ public abstract class AbstractReplaceMojo extends AbstractRegexMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.regexes == null || this.regexes.length == 0) - throw new MojoFailureException("At least one 'regexes' element is required"); + throw new MojoException("At least one 'regexes' element is required"); this.compiledRegexes = new LinkedList<>(); for (Regex regex : this.regexes) { - this.getLog().debug("Compiling regex pattern: " + regex.getPattern()); + this.logger.debug("Compiling regex pattern: " + regex.getPattern()); try { Pattern pattern = Pattern.compile(regex.getPattern()); String previousPatternStr = StringUtils.trimToNull(regex.getPreviousPattern()); Pattern previousPattern = previousPatternStr == null ? null : Pattern.compile(previousPatternStr); this.compiledRegexes.add(new ImmutableTriple<>(pattern, regex.getReplacement(), previousPattern)); } catch (PatternSyntaxException pse) { - throw new MojoFailureException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage()); + throw new MojoException("'" + regex.getPattern() + "' is not a valid regular expression: " + pse.getMessage()); } } } diff --git a/src/main/java/com/inteligr8/maven/regex/CopyFileMojo.java b/src/main/java/com/inteligr8/maven/regex/CopyFileMojo.java index 5f56c77..e5d1ce7 100644 --- a/src/main/java/com/inteligr8/maven/regex/CopyFileMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/CopyFileMojo.java @@ -19,12 +19,15 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import org.apache.maven.plugins.annotations.Mojo; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.annotations.Mojo; -@Mojo( name = "copy-file", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "copy-file") public class CopyFileMojo extends AbstractFileMojo { + + @Inject + private Log logger; @Override protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException { @@ -35,9 +38,9 @@ public class CopyFileMojo extends AbstractFileMojo { } if (this.verbose) { - this.getLog().info("Copied " + sourcePath + " to " + targetPath); + this.logger.info("Copied " + sourcePath + " to " + targetPath); } else { - this.getLog().info("Copied " + sourcePath.getFileName() + " to " + targetPath); + this.logger.info("Copied " + sourcePath.getFileName() + " to " + targetPath); } } diff --git a/src/main/java/com/inteligr8/maven/regex/MatchFileContentMojo.java b/src/main/java/com/inteligr8/maven/regex/MatchFileContentMojo.java index 2a59c62..703e2c9 100644 --- a/src/main/java/com/inteligr8/maven/regex/MatchFileContentMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/MatchFileContentMojo.java @@ -21,17 +21,19 @@ import java.nio.file.Path; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.util.FileSetManager; -import org.codehaus.plexus.component.annotations.Component; -@Mojo( name = "match-file", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "match-file") public class MatchFileContentMojo extends AbstractMatchMojo { + + @Inject + private Log logger; @Parameter( property = "chunkSize", required = true, defaultValue = "1024" ) protected int chunkSize = 1024; @@ -43,20 +45,20 @@ public class MatchFileContentMojo extends AbstractMatchMojo { protected String newProperty; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing file regex match"); + public void go() throws MojoException { + this.logger.debug("Executing file regex match"); boolean matches = this.matchesContentInFileSet(); if (this.verbose) - this.getLog().info("Setting property: " + this.newProperty + ": " + matches); + this.logger.info("Setting property: " + this.newProperty + ": " + matches); else if (matches) - this.getLog().info("Matches!"); - this.project.getProperties().setProperty(this.newProperty, String.valueOf(matches)); + this.logger.info("Matches!"); + this.manager.setProperty(this.project, this.newProperty, String.valueOf(matches)); } - private boolean matchesContentInFileSet() throws MojoExecutionException { + private boolean matchesContentInFileSet() throws MojoException { FileSetManager fsman = new FileSetManager(); - Path basepath = this.project.getBasedir().toPath(); + Path basepath = this.project.getBasedir(); try { for (FileSet fileSet : this.filesets) { @@ -68,58 +70,58 @@ public class MatchFileContentMojo extends AbstractMatchMojo { if (!Files.isDirectory(file)) if (this.matches(file, this.chunkSize)) { if (this.verbose) - this.getLog().info("A pattern matches file: " + file); + this.logger.info("A pattern matches file: " + file); return true; } } } } catch (IOException ie) { - throw new MojoExecutionException("Execution failed due to an I/O related issue", ie); + throw new MojoException("Execution failed due to an I/O related issue", ie); } return this.negate; } - private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoExecutionException { + private Path resolveDirectory(Path basepath, String directory, String errorName) throws IOException, MojoException { Path path = new File(directory).toPath(); if (!path.isAbsolute()) path = basepath.resolve(path); if (!Files.exists(path)) - throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory); + throw new MojoException("A " + errorName + " directory does not exist: " + directory); if (!Files.isDirectory(path)) - throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory); + throw new MojoException("A " + errorName + " does reference a directory: " + directory); return path; } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.filesets == null || this.filesets.isEmpty()) - throw new MojoFailureException("At least one 'fileset' is required"); + throw new MojoException("At least one 'fileset' is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); for (FileSet fileset : this.filesets) { if (fileset.getDirectory() == null) - fileset.setDirectory(this.project.getBasedir().getAbsolutePath()); + fileset.setDirectory(this.project.getBasedir().toAbsolutePath().toString()); } this.newProperty = StringUtils.trimToNull(this.newProperty); } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.newProperty == null) - throw new MojoFailureException("The 'newProperty' element is required"); + throw new MojoException("The 'newProperty' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/MatchFilenameMojo.java b/src/main/java/com/inteligr8/maven/regex/MatchFilenameMojo.java index b540699..ebbe6fe 100644 --- a/src/main/java/com/inteligr8/maven/regex/MatchFilenameMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/MatchFilenameMojo.java @@ -14,7 +14,6 @@ */ package com.inteligr8.maven.regex; -import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; @@ -24,31 +23,32 @@ import java.nio.file.attribute.BasicFileAttributes; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableBoolean; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "match-filename", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "match-filename") public class MatchFilenameMojo extends AbstractMatchMojo { + + @Inject + private Log logger; @Parameter( property = "sourceDirectory", required = false ) - protected File sourceDirectory; + protected Path sourceDirectory; @Parameter( property = "newProperty", required = true ) protected String newProperty; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing file regex match"); + public void go() throws MojoException { + this.logger.debug("Executing file regex match"); final MutableBoolean matches = new MutableBoolean(false); - final Path basepath = this.sourceDirectory.toPath(); try { - Files.walkFileTree(basepath, new FileVisitor() { + Files.walkFileTree(this.sourceDirectory, new FileVisitor() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { @@ -65,11 +65,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!Files.isDirectory(file)) { - getLog().debug("Visiting file: " + file); + logger.debug("Visiting file: " + file); - if (matches(basepath.relativize(file).toString())) { + if (matches(sourceDirectory.relativize(file).toString())) { if (MatchFilenameMojo.this.verbose) - MatchFilenameMojo.this.getLog().info("A pattern matches filename: " + file); + MatchFilenameMojo.this.logger.info("A pattern matches filename: " + file); matches.setTrue(); } } @@ -82,18 +82,18 @@ public class MatchFilenameMojo extends AbstractMatchMojo { } }); } catch (IOException ie) { - throw new MojoExecutionException(ie.getMessage(), ie); + throw new MojoException(ie.getMessage(), ie); } if (this.verbose) - this.getLog().info("Setting property: " + this.newProperty + ": " + matches); + this.logger.info("Setting property: " + this.newProperty + ": " + matches); else if (matches.booleanValue()) - this.getLog().info("Matches!"); - this.project.getProperties().setProperty(this.newProperty, matches.toString()); + this.logger.info("Matches!"); + this.manager.setProperty(this.project, this.newProperty, matches.toString()); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); if (this.sourceDirectory == null) @@ -102,11 +102,11 @@ public class MatchFilenameMojo extends AbstractMatchMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.newProperty == null) - throw new MojoFailureException("The 'newProperty' element is required"); + throw new MojoException("The 'newProperty' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/MatchPropertiesMojo.java b/src/main/java/com/inteligr8/maven/regex/MatchPropertiesMojo.java index 5bf2ac5..6a6458b 100644 --- a/src/main/java/com/inteligr8/maven/regex/MatchPropertiesMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/MatchPropertiesMojo.java @@ -18,15 +18,17 @@ import java.util.List; import java.util.ListIterator; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "match-properties", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "match-properties") public class MatchPropertiesMojo extends AbstractMatchMojo { + + @Inject + private Log logger; @Parameter( property = "properties", required = true ) protected List properties; @@ -35,8 +37,8 @@ public class MatchPropertiesMojo extends AbstractMatchMojo { protected String propertySuffix; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing properties regex match"); + public void go() throws MojoException { + this.logger.debug("Executing properties regex match"); for (String propertyName : this.properties) { this.executeOnProperty(propertyName, propertyName + this.propertySuffix); @@ -44,15 +46,15 @@ public class MatchPropertiesMojo extends AbstractMatchMojo { } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.properties == null) - throw new MojoFailureException("A 'properties' element is required"); + throw new MojoException("A 'properties' element is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); // make sure we have a list and it is nice and neat @@ -74,13 +76,13 @@ public class MatchPropertiesMojo extends AbstractMatchMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.propertySuffix == null) - throw new MojoFailureException("The 'propertySuffix' element is required"); + throw new MojoException("The 'propertySuffix' element is required"); if (this.properties.isEmpty()) - throw new MojoFailureException("At least one 'property' element is required"); + throw new MojoException("At least one 'property' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/MatchPropertyMojo.java b/src/main/java/com/inteligr8/maven/regex/MatchPropertyMojo.java index 3aef8bd..51f1227 100644 --- a/src/main/java/com/inteligr8/maven/regex/MatchPropertyMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/MatchPropertyMojo.java @@ -15,15 +15,17 @@ package com.inteligr8.maven.regex; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "match-property", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "match-property") public class MatchPropertyMojo extends AbstractMatchMojo { + + @Inject + private Log logger; @Parameter( property = "property", required = true ) protected String property; @@ -32,14 +34,14 @@ public class MatchPropertyMojo extends AbstractMatchMojo { protected String newProperty; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing property regex match"); + public void go() throws MojoException { + this.logger.debug("Executing property regex match"); this.executeOnProperty(this.property, this.newProperty); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); this.property = StringUtils.trimToNull(this.property); @@ -49,11 +51,11 @@ public class MatchPropertyMojo extends AbstractMatchMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.property == null) - throw new MojoFailureException("The 'property' element is required"); + throw new MojoException("The 'property' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/MatchTextMojo.java b/src/main/java/com/inteligr8/maven/regex/MatchTextMojo.java index 490a754..b1cd6e1 100644 --- a/src/main/java/com/inteligr8/maven/regex/MatchTextMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/MatchTextMojo.java @@ -15,15 +15,17 @@ package com.inteligr8.maven.regex; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "match-text", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "match-text") public class MatchTextMojo extends AbstractMatchMojo { + + @Inject + private Log logger; @Parameter( property = "text", required = true ) protected String text; @@ -32,33 +34,33 @@ public class MatchTextMojo extends AbstractMatchMojo { protected String newProperty; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing property regex match"); + public void go() throws MojoException { + this.logger.debug("Executing property regex match"); - this.executeOnText(this.project.getProperties(), this.text, this.newProperty); + this.executeOnText(this.text, this.newProperty); } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.text == null) - throw new MojoFailureException("The 'text' element is required"); + throw new MojoException("The 'text' element is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); this.newProperty = StringUtils.trimToNull(this.newProperty); } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.newProperty == null) - throw new MojoFailureException("The 'newProperty' element is required"); + throw new MojoException("The 'newProperty' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/MoveFileMojo.java b/src/main/java/com/inteligr8/maven/regex/MoveFileMojo.java index 5146578..e76b5d7 100644 --- a/src/main/java/com/inteligr8/maven/regex/MoveFileMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/MoveFileMojo.java @@ -19,12 +19,15 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import org.apache.maven.plugins.annotations.Mojo; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.annotations.Mojo; -@Mojo( name = "move-file", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "move-file") public class MoveFileMojo extends AbstractFileMojo { + + @Inject + private Log logger; @Override protected void executeOnFile(Path sourcePath, Path targetPath) throws IOException { @@ -35,9 +38,9 @@ public class MoveFileMojo extends AbstractFileMojo { } if (this.verbose) { - this.getLog().info("Moved " + sourcePath + " to " + targetPath); + this.logger.info("Moved " + sourcePath + " to " + targetPath); } else { - this.getLog().info("Moved " + sourcePath.getFileName() + " to " + targetPath); + this.logger.info("Moved " + sourcePath.getFileName() + " to " + targetPath); } } diff --git a/src/main/java/com/inteligr8/maven/regex/ReplaceFileContentMojo.java b/src/main/java/com/inteligr8/maven/regex/ReplaceFileContentMojo.java index e6b4814..3b78313 100644 --- a/src/main/java/com/inteligr8/maven/regex/ReplaceFileContentMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/ReplaceFileContentMojo.java @@ -20,17 +20,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.util.FileSetManager; -import org.codehaus.plexus.component.annotations.Component; -@Mojo( name = "replace-file", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "replace-file") public class ReplaceFileContentMojo extends AbstractReplaceMojo { + + @Inject + private Log logger; @Parameter( property = "chunkSize", required = true, defaultValue = "1024" ) protected int chunkSize = 1024; @@ -39,16 +41,16 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo { protected List filesets; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing file regex replace"); + public void go() throws MojoException { + this.logger.debug("Executing file regex replace"); this.replaceContentInFileSet(); } - private boolean replaceContentInFileSet() throws MojoExecutionException { + private boolean replaceContentInFileSet() throws MojoException { boolean didReplace = false; FileSetManager fsman = new FileSetManager(); - Path basepath = this.project.getBasedir().toPath(); + Path basepath = this.project.getBasedir(); try { for (FileSet fileSet : this.filesets) { @@ -65,22 +67,22 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo { if (!Files.isDirectory(file)) { if (this.replaceAll(file, tofile, this.chunkSize)) { if (this.verbose) - this.getLog().info("A pattern replaced in file: " + file + " => " + tofile); + this.logger.info("A pattern replaced in file: " + file + " => " + tofile); didReplace = true; } } } } } catch (IOException ie) { - throw new MojoExecutionException("Execution failed due to an I/O related issue", ie); + throw new MojoException("Execution failed due to an I/O related issue", ie); } return didReplace; } - private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoExecutionException { + private Path resolveDirectory(Path basepath, String directory, boolean createIfMissing, String errorName) throws IOException, MojoException { if (directory == null) - return this.project.getBasedir().toPath(); + return this.project.getBasedir(); Path path = new File(directory).toPath(); if (!path.isAbsolute()) @@ -90,31 +92,31 @@ public class ReplaceFileContentMojo extends AbstractReplaceMojo { if (createIfMissing) { Files.createDirectories(path); } else { - throw new MojoExecutionException("A " + errorName + " directory does not exist: " + directory); + throw new MojoException("A " + errorName + " directory does not exist: " + directory); } } if (!Files.isDirectory(path)) - throw new MojoExecutionException("A " + errorName + " does reference a directory: " + directory); + throw new MojoException("A " + errorName + " does reference a directory: " + directory); return path; } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.filesets == null || this.filesets.isEmpty()) - throw new MojoFailureException("At least one 'fileset' is required"); + throw new MojoException("At least one 'fileset' is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); for (FileSet fileset : this.filesets) { if (fileset.getDirectory() == null) - fileset.setDirectory(this.project.getBasedir().getAbsolutePath()); + fileset.setDirectory(this.project.getBasedir().toAbsolutePath().toString()); if (fileset.getOutputDirectory() == null) fileset.setOutputDirectory(fileset.getDirectory()); } diff --git a/src/main/java/com/inteligr8/maven/regex/ReplacePropertiesMojo.java b/src/main/java/com/inteligr8/maven/regex/ReplacePropertiesMojo.java index 33e60c1..e7554e7 100644 --- a/src/main/java/com/inteligr8/maven/regex/ReplacePropertiesMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/ReplacePropertiesMojo.java @@ -18,15 +18,18 @@ import java.util.List; import java.util.ListIterator; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.di.MojoExecutionScoped; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "replace-properties", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "replace-properties") public class ReplacePropertiesMojo extends AbstractReplaceMojo { + + @Inject + private Log logger; @Parameter( property = "properties", required = true ) protected List properties; @@ -35,8 +38,8 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo { protected String propertySuffix; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing properties regex replacement"); + public void go() throws MojoException { + this.logger.debug("Executing properties regex replacement"); for (String propertyName : this.properties) { this.executeOnProperty(propertyName, propertyName + this.propertySuffix); @@ -44,15 +47,15 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo { } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.properties == null) - throw new MojoFailureException("A 'properties' element is required"); + throw new MojoException("A 'properties' element is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); // make sure we have a list and it is nice and neat @@ -74,13 +77,13 @@ public class ReplacePropertiesMojo extends AbstractReplaceMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.propertySuffix == null) - throw new MojoFailureException("The 'propertySuffix' element is required"); + throw new MojoException("The 'propertySuffix' element is required"); if (this.properties.isEmpty()) - throw new MojoFailureException("At least one 'property' element is required"); + throw new MojoException("At least one 'property' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/ReplacePropertyMojo.java b/src/main/java/com/inteligr8/maven/regex/ReplacePropertyMojo.java index 1103d92..668c2a1 100644 --- a/src/main/java/com/inteligr8/maven/regex/ReplacePropertyMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/ReplacePropertyMojo.java @@ -15,15 +15,17 @@ package com.inteligr8.maven.regex; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "replace-property", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "replace-property") public class ReplacePropertyMojo extends AbstractReplaceMojo { + + @Inject + private Log logger; @Parameter( property = "property", required = true ) protected String property; @@ -32,14 +34,14 @@ public class ReplacePropertyMojo extends AbstractReplaceMojo { protected String newProperty; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing property regex replacement"); + public void go() throws MojoException { + this.logger.debug("Executing property regex replacement"); this.executeOnProperty(this.property, this.newProperty); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); this.property = StringUtils.trimToNull(this.property); @@ -49,11 +51,11 @@ public class ReplacePropertyMojo extends AbstractReplaceMojo { } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.property == null) - throw new MojoFailureException("The 'property' element is required"); + throw new MojoException("The 'property' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/regex/ReplaceTextMojo.java b/src/main/java/com/inteligr8/maven/regex/ReplaceTextMojo.java index 60e50c4..ab55fa0 100644 --- a/src/main/java/com/inteligr8/maven/regex/ReplaceTextMojo.java +++ b/src/main/java/com/inteligr8/maven/regex/ReplaceTextMojo.java @@ -15,15 +15,17 @@ package com.inteligr8.maven.regex; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.component.annotations.Component; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; -@Mojo( name = "replace-text", threadSafe = true ) -@Component( role = org.apache.maven.plugin.Mojo.class ) +@Mojo(name = "replace-text") public class ReplaceTextMojo extends AbstractReplaceMojo { + + @Inject + private Log logger; @Parameter( property = "text", required = true ) protected String text; @@ -32,33 +34,33 @@ public class ReplaceTextMojo extends AbstractReplaceMojo { protected String newProperty; @Override - public void go() throws MojoExecutionException { - this.getLog().debug("Executing property regex replacement"); + public void go() throws MojoException { + this.logger.debug("Executing property regex replacement"); - this.executeOnText(this.project.getProperties(), this.text, this.newProperty); + this.executeOnText(this.text, this.newProperty); } @Override - protected void validateParamsPreNormalization() throws MojoFailureException { + protected void validateParamsPreNormalization() throws MojoException { super.validateParamsPreNormalization(); if (this.text == null) - throw new MojoFailureException("The 'text' element is required"); + throw new MojoException("The 'text' element is required"); } @Override - protected void normalizeParameters() throws MojoFailureException { + protected void normalizeParameters() throws MojoException { super.normalizeParameters(); this.newProperty = StringUtils.trimToNull(this.newProperty); } @Override - protected void validateParamsPostNormalization() throws MojoFailureException { + protected void validateParamsPostNormalization() throws MojoException { super.validateParamsPostNormalization(); if (this.newProperty == null) - throw new MojoFailureException("The 'newProperty' element is required"); + throw new MojoException("The 'newProperty' element is required"); } } diff --git a/src/main/java/com/inteligr8/maven/model/Normalizable.java b/src/main/java/com/inteligr8/maven/regex/model/Normalizable.java similarity index 94% rename from src/main/java/com/inteligr8/maven/model/Normalizable.java rename to src/main/java/com/inteligr8/maven/regex/model/Normalizable.java index 22a7282..e89c4ee 100644 --- a/src/main/java/com/inteligr8/maven/model/Normalizable.java +++ b/src/main/java/com/inteligr8/maven/regex/model/Normalizable.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -package com.inteligr8.maven.model; +package com.inteligr8.maven.regex.model; public interface Normalizable { diff --git a/src/main/java/com/inteligr8/maven/model/Regex.java b/src/main/java/com/inteligr8/maven/regex/model/Regex.java similarity index 97% rename from src/main/java/com/inteligr8/maven/model/Regex.java rename to src/main/java/com/inteligr8/maven/regex/model/Regex.java index ed38d81..b88dd59 100644 --- a/src/main/java/com/inteligr8/maven/model/Regex.java +++ b/src/main/java/com/inteligr8/maven/regex/model/Regex.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -package com.inteligr8.maven.model; +package com.inteligr8.maven.regex.model; public class Regex implements Normalizable { diff --git a/src/main/java/com/inteligr8/nio/DelimitedReadableByteChannel.java b/src/main/java/com/inteligr8/maven/regex/nio/DelimitedReadableByteChannel.java similarity index 98% rename from src/main/java/com/inteligr8/nio/DelimitedReadableByteChannel.java rename to src/main/java/com/inteligr8/maven/regex/nio/DelimitedReadableByteChannel.java index 77541ea..6b15987 100644 --- a/src/main/java/com/inteligr8/nio/DelimitedReadableByteChannel.java +++ b/src/main/java/com/inteligr8/maven/regex/nio/DelimitedReadableByteChannel.java @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -package com.inteligr8.nio; +package com.inteligr8.maven.regex.nio; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/src/test/java/com/inteligr8/maven/regex/FileSetUnitTest.java b/src/test/java/com/inteligr8/maven/regex/FileSetUnitTest.java index 5e1fffb..510c892 100644 --- a/src/test/java/com/inteligr8/maven/regex/FileSetUnitTest.java +++ b/src/test/java/com/inteligr8/maven/regex/FileSetUnitTest.java @@ -7,8 +7,8 @@ import java.util.Set; import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.util.FileSetManager; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class FileSetUnitTest { @@ -21,9 +21,9 @@ public class FileSetUnitTest { String fs = File.separator; FileSetManager fsman = new FileSetManager(); Set files = new HashSet<>(Arrays.asList(fsman.getIncludedFiles(fileset))); - Assert.assertTrue(files.size() > 15); + Assertions.assertTrue(files.size() > 15); System.err.println(files); - Assert.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java")); + Assertions.assertTrue(files.contains("com"+fs+"inteligr8"+fs+"maven"+fs+"regex"+fs+"AbstractFileMojo.java")); } } diff --git a/src/test/java/com/inteligr8/nio/DelimitedReadableByteChannelUnitTest.java b/src/test/java/com/inteligr8/maven/regex/nio/DelimitedReadableByteChannelUnitTest.java similarity index 62% rename from src/test/java/com/inteligr8/nio/DelimitedReadableByteChannelUnitTest.java rename to src/test/java/com/inteligr8/maven/regex/nio/DelimitedReadableByteChannelUnitTest.java index cc2523e..34c5a22 100644 --- a/src/test/java/com/inteligr8/nio/DelimitedReadableByteChannelUnitTest.java +++ b/src/test/java/com/inteligr8/maven/regex/nio/DelimitedReadableByteChannelUnitTest.java @@ -1,4 +1,4 @@ -package com.inteligr8.nio; +package com.inteligr8.maven.regex.nio; import java.io.File; import java.io.IOException; @@ -10,8 +10,8 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DelimitedReadableByteChannelUnitTest { @@ -24,9 +24,9 @@ public class DelimitedReadableByteChannelUnitTest { DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\n"); try { StringBuilder strbuilder = new StringBuilder(); - Assert.assertEquals(-1L, drbchannel.read(strbuilder)); - Assert.assertEquals(0, strbuilder.length()); - Assert.assertNull(drbchannel.getLastDelimiterRead()); + Assertions.assertEquals(-1L, drbchannel.read(strbuilder)); + Assertions.assertEquals(0, strbuilder.length()); + Assertions.assertNull(drbchannel.getLastDelimiterRead()); } finally { drbchannel.close(); } @@ -44,18 +44,18 @@ public class DelimitedReadableByteChannelUnitTest { DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n"); try { StringWriter writer = new StringWriter(1024); - Assert.assertNotEquals(-1L, drbchannel.read(writer)); - Assert.assertEquals("", writer.toString()); - Assert.assertNotNull(drbchannel.getLastDelimiterRead()); + Assertions.assertNotEquals(-1L, drbchannel.read(writer)); + Assertions.assertEquals("", writer.toString()); + Assertions.assertNotNull(drbchannel.getLastDelimiterRead()); writer = new StringWriter(1024); - Assert.assertNotEquals(-1L, drbchannel.read(writer)); - Assert.assertEquals("here is a line", writer.toString()); - Assert.assertNotNull(drbchannel.getLastDelimiterRead()); + Assertions.assertNotEquals(-1L, drbchannel.read(writer)); + Assertions.assertEquals("here is a line", writer.toString()); + Assertions.assertNotNull(drbchannel.getLastDelimiterRead()); writer = new StringWriter(1024); - Assert.assertEquals(-1L, drbchannel.read(writer)); - Assert.assertNull(drbchannel.getLastDelimiterRead()); + Assertions.assertEquals(-1L, drbchannel.read(writer)); + Assertions.assertNull(drbchannel.getLastDelimiterRead()); } finally { drbchannel.close(); } @@ -73,18 +73,18 @@ public class DelimitedReadableByteChannelUnitTest { DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(fchannel, Charset.defaultCharset(), "\r\n", "\n"); try { StringWriter writer = new StringWriter(1024); - Assert.assertNotEquals(-1L, drbchannel.read(writer)); - Assert.assertEquals("the first line", writer.toString()); - Assert.assertNotNull(drbchannel.getLastDelimiterRead()); + Assertions.assertNotEquals(-1L, drbchannel.read(writer)); + Assertions.assertEquals("the first line", writer.toString()); + Assertions.assertNotNull(drbchannel.getLastDelimiterRead()); writer = new StringWriter(1024); - Assert.assertNotEquals(-1L, drbchannel.read(writer)); - Assert.assertEquals("the last line", writer.toString()); - Assert.assertNull(drbchannel.getLastDelimiterRead()); + Assertions.assertNotEquals(-1L, drbchannel.read(writer)); + Assertions.assertEquals("the last line", writer.toString()); + Assertions.assertNull(drbchannel.getLastDelimiterRead()); writer = new StringWriter(1024); - Assert.assertEquals(-1L, drbchannel.read(writer)); - Assert.assertNull(drbchannel.getLastDelimiterRead()); + Assertions.assertEquals(-1L, drbchannel.read(writer)); + Assertions.assertNull(drbchannel.getLastDelimiterRead()); } finally { drbchannel.close(); } @@ -111,14 +111,14 @@ public class DelimitedReadableByteChannelUnitTest { DelimitedReadableByteChannel drbchannel = new DelimitedReadableByteChannel(chunkSize, fchannel, Charset.defaultCharset(), "\n"); try { StringWriter writer = new StringWriter(1024); - Assert.assertNotEquals(-1L, drbchannel.read(writer)); - Assert.assertEquals("", writer.toString()); - Assert.assertEquals("\n", drbchannel.getLastDelimiterRead()); + Assertions.assertNotEquals(-1L, drbchannel.read(writer)); + Assertions.assertEquals("", writer.toString()); + Assertions.assertEquals("\n", drbchannel.getLastDelimiterRead()); writer = new StringWriter(1024); - Assert.assertEquals(1, drbchannel.read(writer)); - Assert.assertEquals("", writer.toString()); - Assert.assertEquals("\n", drbchannel.getLastDelimiterRead()); + Assertions.assertEquals(1, drbchannel.read(writer)); + Assertions.assertEquals("", writer.toString()); + Assertions.assertEquals("\n", drbchannel.getLastDelimiterRead()); } finally { drbchannel.close(); }