📄 conditionalbuild.java
字号:
/* * * $Id: ConditionalBuild.java,v 1.8 2006/03/01 19:53:48 bondolo Exp $ * * Copyright (c) 2002 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Sun Microsystems, Inc. for Project JXTA." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" * must not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact Project JXTA at http://www.jxta.org. * * 5. Products derived from this software may not be called "JXTA", * nor may "JXTA" appear in their name, without prior written * permission of Sun. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of Project JXTA. For more * information on Project JXTA, please see * <http://www.jxta.org/>. * * This license is based on the BSD license adopted by the Apache Foundation. */package net.jxta.build;import java.util.*;import java.io.*;/** * Builds the conditional compilation files which control the metering and * monitoring functionality. The provided properties file will direct the * generation of java source files into the provided directory. * <p/><pre> * # ConditionalBuild <buildConfig.properties> <rootDir> * # <buildConfig.properties> The configuration properties file. * # <rootDir> The root directory which will contain the generated configuration files. * </pre> */public class ConditionalBuild { /** * Conditional build states */ enum BuildConfig { /* Metering and monitoring will be unconditionally disabled in generated * source files. */ OFF("off"), /* Metering and monitoring will be unconditionally enabled in generated * source files. */ ON("on"), /* Metering and monitoring will be conditionally disabled in generated * source files. System environment variables will allow metering and * monitoring to be enabled. */ RUNTIME("runtime"); /** * The properties file value which matches this state. */ private final String config; /** * Construct a new BuildConfig value. * * @param config The configuration value as it would appear in a * properties file. */ private BuildConfig(String config) { this.config = config; } /** * Convert a properties file String value to an enum value. * * @param key String * @return A ConditionaBuildState object. * @throws IllegalArgumentException For illegal protocol codes. */ public static BuildConfig toBuildConfig(String config) { if (OFF.config.equals(config)) { return OFF; } else if (ON.config.equals(config)) { return ON; } else if (RUNTIME.config.equals(config)) { return RUNTIME; } else { throw new IllegalArgumentException("Unknown Build Type: " + config + " found in property file (valid Types: on, off, runtime)"); } } /** * Return the value that would appear in a properties file for this State. * * @return The value that would appear in a properties file for this State. */ public String toPropertiesKey() { return config; } } private class StaticField { final String packageName; final String className; final String fieldName; final BuildConfig config; final String attr; StaticField(String packageName, String className, String fieldName, BuildConfig config, String attr) { this.packageName = packageName; this.className = className; this.fieldName = fieldName; this.config = config; this.attr = attr; } } private final File baseDir; private final Map<String, List<StaticField>> sourceFiles = new HashMap<String, List<StaticField>>(); public ConditionalBuild(String baseDirName) throws IOException { baseDir = new File(baseDirName); } public void createFiles(File configProperties) throws IOException { System.err.println("Creating Conditional Build files in " + baseDir); Properties properties = new Properties(); properties.load(new FileInputStream(configProperties)); for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { String propertyName = (String) e.nextElement(); parseProperty(propertyName, properties.getProperty(propertyName)); } generateFiles(); } private void generateFiles() throws IOException { for (String filename : sourceFiles.keySet()) { List<StaticField> staticFields = sourceFiles.get(filename); generateFile(filename, staticFields); } } private void generateFile(String filename, List<StaticField> staticFields) throws IOException { StaticField firstStaticField = staticFields.get(0); String srcDirName = firstStaticField.packageName.replace('.', File.separatorChar); File srcDir = new File(baseDir, srcDirName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -