All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taotao.boot.data.p6spy.ext.SmartPropertiesFieldsGenerator Maven / Gradle / Ivy

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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy