📄 conditionalbuild.java
字号:
srcDir.mkdirs(); File file = new File(srcDir, filename + ".java"); System.err.println("\tCreate conditional build file : " + srcDirName + File.separatorChar + file.getName()); PrintWriter writer = new PrintWriter(new FileWriter(file)); insertCopyright(writer); writer.println(); writer.println("/* **** THIS IS A GENERATED FILE. DO NOT EDIT. **** */"); writer.println(); writer.println("package " + firstStaticField.packageName + ";"); writer.println(); writer.println("import net.jxta.impl.meter.*;"); writer.println(); writer.print("public interface " + firstStaticField.className); if (!firstStaticField.className.equals("MeterBuildSettings")) { writer.print(" extends MeterBuildSettings"); } writer.println(" {"); for (StaticField staticField : staticFields) { writer.print("\tpublic static final boolean " + staticField.fieldName + " = "); switch (staticField.config) { case OFF: case ON: writer.print(Boolean.toString(BuildConfig.ON == staticField.config)); break; case RUNTIME: String conditionalClassName = "Conditional" + staticField.className; File conditionalFile = new File(srcDir, "Conditional" + staticField.className + ".java"); writer.print(conditionalClassName + ".isRuntimeMetering()"); makeConditionalFile(conditionalFile, staticField.packageName, conditionalClassName, staticField.attr); } writer.println(";"); } writer.println("}"); writer.close(); } private void makeConditionalFile(File conditionalFile, String packageName, String className, String propertyName) throws IOException { PrintWriter writer = new PrintWriter(new FileWriter(conditionalFile)); System.err.println("\tCreate runtime conditional build file : " + packageName.replace('.', File.separatorChar) + File.separatorChar + conditionalFile.getName()); insertCopyright(writer); writer.println(); writer.println("/* **** THIS IS A GENERATED FILE. DO NOT EDIT. **** */"); writer.println(); writer.println("package " + packageName + ";"); writer.println(); writer.println("import java.util.ResourceBundle;"); writer.println("import net.jxta.impl.meter.*;"); writer.println(); writer.println("public class " + className + " {"); writer.println("\tpublic static boolean isRuntimeMetering() {"); writer.println("\t\tboolean runtimeMetering = false; "); writer.println(); writer.println("\t\ttry { "); writer.println("\t\t\tResourceBundle userResourceBundle = ResourceBundle.getBundle( \"net.jxta.user\" ); "); writer.println("\t\t\tString meteringProperty = \"" + propertyName + "\"; "); writer.println("\t\t\tString meteringValue = userResourceBundle.getString( meteringProperty ); "); writer.println("\t\t\truntimeMetering = \"on\".equalsIgnoreCase( meteringValue ); "); writer.println("\t\t} catch (Exception ignored) { "); writer.println("\t\t}"); writer.println(); writer.println("\t\treturn runtimeMetering;"); writer.println("\t}"); writer.print("}"); writer.close(); } private void parseProperty(String propertyName, String value) { int pos = propertyName.lastIndexOf('.'); String fullClassName = propertyName.substring(0, pos); String fieldName = propertyName.substring(pos + 1); int pos2 = fullClassName.lastIndexOf('.'); String packageName = fullClassName.substring(0, pos2); String className = fullClassName.substring(pos2 + 1); StringTokenizer st = new StringTokenizer(value, ", \t"); String buildConfig = st.nextToken(); BuildConfig config = BuildConfig.toBuildConfig(buildConfig); String attr = st.nextToken(); StaticField staticField = new StaticField(packageName, className, fieldName, config, attr); List<StaticField> fields = sourceFiles.get(className); if (fields == null) { fields = new ArrayList<StaticField>(); sourceFiles.put(className, fields); } fields.add(staticField); } private void insertCopyright(PrintWriter writer) { writer.println("/*"); writer.println(" * The Sun Project JXTA(TM) Software License"); writer.println(" * "); writer.println(" * Copyright (c) 2001-2006 Sun Microsystems, Inc. All rights reserved."); writer.println(" * "); writer.println(" * Redistribution and use in source and binary forms, with or without "); writer.println(" * modification, are permitted provided that the following conditions are met:"); writer.println(" * "); writer.println(" * 1. Redistributions of source code must retain the above copyright notice,"); writer.println(" * this list of conditions and the following disclaimer."); writer.println(" * "); writer.println(" * 2. Redistributions in binary form must reproduce the above copyright notice, "); writer.println(" * this list of conditions and the following disclaimer in the documentation "); writer.println(" * and/or other materials provided with the distribution."); writer.println(" * "); writer.println(" * 3. The end-user documentation included with the redistribution, if any, must "); writer.println(" * include the following acknowledgment: \"This product includes software "); writer.println(" * developed by Sun Microsystems, Inc. for JXTA(TM) technology.\" "); writer.println(" * Alternately, this acknowledgment may appear in the software itself, if "); writer.println(" * and wherever such third-party acknowledgments normally appear."); writer.println(" * "); writer.println(" * 4. The names \"Sun\", \"Sun Microsystems, Inc.\", \"JXTA\" and \"Project JXTA\" must "); writer.println(" * not be used to endorse or promote products derived from this software "); writer.println(" * without prior written permission. For written permission, please contact "); writer.println(" * Project JXTA at https://jxta.dev.java.net."); writer.println(" * "); writer.println(" * 5. Products derived from this software may not be called \"JXTA\", nor may "); writer.println(" * \"JXTA\" appear in their name, without prior written permission of Sun."); writer.println(" * "); writer.println(" * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,"); writer.println(" * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND "); writer.println(" * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN "); writer.println(" * MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, "); writer.println(" * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT "); writer.println(" * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, "); writer.println(" * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF "); writer.println(" * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING "); writer.println(" * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, "); writer.println(" * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."); writer.println(" * "); writer.println(" * JXTA is a registered trademark of Sun Microsystems, Inc. in the United "); writer.println(" * States and other countries."); writer.println(" * "); writer.println(" * Please see the license information page at :"); writer.println(" * <https://jxta.dev.java.net/license.html> for instructions on use of "); writer.println(" * the license in source files."); writer.println(" * "); writer.println(" * ===================================================================="); writer.println(""); writer.println(" * This software consists of voluntary contributions made by many individuals "); writer.println(" * on behalf of Project JXTA. For more information on Project JXTA, please see "); writer.println(" * https://jxta.dev.java.net/"); writer.println(" * "); writer.println(" * This license is based on the BSD license adopted by the Apache Foundation. "); writer.println(" * "); writer.println(" */"); writer.println(); } public static void main(String[] args) { try { if (args.length != 2) { System.err.println("# ConditionalBuild <buildConfig.properties> <rootDir>"); System.err.println("# <buildConfig.properties> The configuration properties file."); System.err.println("# <rootDir> The root directory which will contain the generated configuration files."); System.exit(1); } final String propertyFile = args[0]; final String targetDir = args[1]; ConditionalBuild conditionalBuild = new ConditionalBuild(targetDir); final File configProperties = new File(propertyFile); conditionalBuild.createFiles(configProperties); } catch (Exception e) { e.printStackTrace(System.err); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -