集册 Java实例教程 执行Maven

执行Maven

欢马劈雪     最近更新时间:2020-01-02 10:19:05

672
在目录上执行Maven样式的过滤。
/*n o w j a   v  a . c o m - 时  代  Java 提 供*/


//package com.nowjava;

import java.io.File;

import java.util.Properties;


public class Main {

    /**

     * Performs Maven-style filtering on a directory. Allows filenames to be dynamically renamed, based on properties.

     * 

     * @param directory

     *            Directory to scan

     * @param properties

     *            List of properties used by the target Maven project

     */

    public static void doFilenameFiltering(final File directory,

            final Properties properties) {

        for (final File file : directory.listFiles()) {

            if (file.isDirectory()) {

                doFilenameFiltering(file, properties);

            } else {

                String fileName = file.getName();

                int i = fileName.indexOf("${");

                while (i >= 0) {

                    final String property = fileName.substring(i + 2,

                            fileName.indexOf('}', i));

                    if (properties.containsKey(property)) {

                        final String value = properties

                                .getProperty(property);//from 时代Java公众号 - N o w J a  v a . c o m

                        fileName = fileName.replaceAll("\\$\\{" + property

                                + "\\}", value);

       
展开阅读全文