Skip to content

Commit

Permalink
Allow replacement to be null for ReplaceRegex of plugin maven
Browse files Browse the repository at this point in the history
  • Loading branch information
Apache9 committed Oct 3, 2022
1 parent 7667a84 commit aa48b8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,10 +35,12 @@ public class Replace implements FormatterStepFactory {

@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
if (name == null || search == null || replacement == null) {
throw new IllegalArgumentException("Must specify 'name', 'search' and 'replacement'.");
if (name == null || search == null) {
throw new IllegalArgumentException("Must specify 'name' and 'search'.");
}

return ReplaceStep.create(name, search, replacement);
// Use empty string if replacement is not provided. In pom.xml there is no way to specify
// an empty string as a property value as maven will always trim the value and if it is
// empty, maven will consider the property as not provided.
return ReplaceStep.create(name, search, replacement != null ? replacement : "");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,10 +35,12 @@ public class ReplaceRegex implements FormatterStepFactory {

@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
if (name == null || searchRegex == null || replacement == null) {
throw new IllegalArgumentException("Must specify 'name', 'searchRegex' and 'replacement'.");
if (name == null || searchRegex == null) {
throw new IllegalArgumentException("Must specify 'name' and 'searchRegex'.");
}

return ReplaceRegexStep.create(name, searchRegex, replacement);
// Use empty string if replacement is not provided. In pom.xml there is no way to specify
// an empty string as a property value as maven will always trim the value and if it is
// empty, maven will consider the property as not provided.
return ReplaceRegexStep.create(name, searchRegex, replacement != null ? replacement : "");
}
}

0 comments on commit aa48b8d

Please sign in to comment.