org.openrewrite.properties.AddProperty Maven / Gradle / Ivy
Show all versions of rewrite-properties Show documentation
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.properties;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.marker.Markers;
import org.openrewrite.properties.search.FindProperties;
import org.openrewrite.properties.tree.Properties;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.openrewrite.Tree.randomId;
@Value
@EqualsAndHashCode(callSuper = false)
public class AddProperty extends Recipe {
@Option(displayName = "Property key",
description = "The property key to add.",
example = "management.metrics.enable.process.files")
String property;
@Option(example = "newPropValue", displayName = "Property value",
description = "The value of the new property key.")
String value;
@Option(displayName = "Optional comment to be prepended to the property",
description = "A comment that will be added to the new property.",
required = false,
example = "This is a comment")
@Nullable
String comment;
@Option(displayName = "Optional delimiter",
description = "Property entries support different delimiters (`=`, `:`, or whitespace). The default value is `=` unless provided the delimiter of the new property entry.",
required = false,
example = ":")
@Nullable
String delimiter;
@Override
public String getDisplayName() {
return "Add a new property";
}
@Override
public String getDescription() {
return "Adds a new property to a property file. " +
"Attempts to place the new property in alphabetical order by the property keys. " +
"Whitespace before and after the `=` must be included in the property and value.";
}
@Override
public Validated