com.taotao.boot.data.p6spy.ext.SmartPropertiesFieldsGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of taotao-boot-starter-data-p6spy Show documentation
Show all versions of taotao-boot-starter-data-p6spy Show documentation
taotao-boot-starter-data-p6spy
The newest version!
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* 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 com.taotao.boot.data.p6spy.ext;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** 根据p6spy官方配置文件,快速生成字段 */
public class SmartPropertiesFieldsGenerator {
static final Pattern FIELD_PATTERN = Pattern.compile("^#(\\w+)=.*");
public static void main(String[] args) throws IOException {
try (BufferedReader bufferedReader = new BufferedReader(new FileReader("src/main/resources/spy.properties"))) {
String line;
Set fieldsSet = new HashSet<>(32, 1);
while ((line = bufferedReader.readLine()) != null) {
Matcher matcher = FIELD_PATTERN.matcher(line);
if (matcher.find()) {
String field = matcher.group(1);
field = String.format("private String %s;", field);
fieldsSet.add(field);
}
}
fieldsSet.forEach(System.out::println);
}
}
}