📄 main.java
字号:
} else { File xargsFile2 = new File(defDir, defaultXArgsInit); println("No restart xargs file " + xargsFile + ", trying " + xargsFile2 + " instead.", 0); xargsFile = xargsFile2; } } else { println("no fwdir at " + fwDir.getAbsolutePath(), 1); xargsFile = new File(defDir, defaultXArgsInit); if(xargsFile.exists()) { println("\n" + "Default init xargs file: " + xargsFile + "\n", 5); } else { xargsFile = new File(defDir, defaultXArgsInit2); if(xargsFile.exists()) { println("\n" + "Deafult secondary init xargs file: " + xargsFile + "\n", 5); } } } } else { // No parent dir to fwdir } return xargsFile != null ? xargsFile.getAbsolutePath() : null; } /** * Default values for some system properties. */ static String[][] defaultSysProps = new String[][] { {"org.osgi.framework.system.packages", "javax.swing,javax.swing.border,javax.swing.event,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.table,javax.swing.text,javax.swing.tree"}, {FWDIR_PROP, FWDIR_DEFAULT}, {CMDIR_PROP, CMDIR_DEFAULT}, // { "oscar.repository.url", "http://www.knopflerfish.org/repo/repository.xml" }, }; /** * Check current system properties and set default values * if importand ones are missing. The default values * are taken from the <tt>defaultSysProps</tt> variable. * * <p> * The <tt>org.knopflerfish.gosg.jars</tt> property (if not defined) * is created by scanning the "jars" directory for subdirs. * </p> * * @see defaultSysProps */ static void setDefaultSysProps() { // Make modifications to temporary dictionary and write // it back in end of this method Properties sysProps = System.getProperties(); println("setDefaultSysProps", 1); for(int i = 0; i < defaultSysProps.length; i++) { if(null == System.getProperty(defaultSysProps[i][0])) { println("Using default " + defaultSysProps[i][0] + "=" + defaultSysProps[i][1], 1); sysProps.put(defaultSysProps[i][0], defaultSysProps[i][1]); } else { println("system prop " + defaultSysProps[i][0] + "=" + System.getProperty(defaultSysProps[i][0]), 1); } } // Set version info if(null == System.getProperty(PRODVERSION_PROP)) { sysProps.put(PRODVERSION_PROP, version); } // If jar dir is not specified, default to "file:jars/" and its // subdirs String jars = System.getProperty(JARDIR_PROP, null); if(jars == null || "".equals(jars)) { String jarBaseDir = topDir + "jars"; println("jarBaseDir=" + jarBaseDir, 1); File jarDir = new File(jarBaseDir); if(jarDir.exists() && jarDir.isDirectory()) { // avoid FileNameFilter since some profiles don't have it String [] names = jarDir.list(); Vector v = new Vector(); for(int i = 0; i < names.length; i++) { File f = new File(jarDir, names[i]); if(f.isDirectory()) { v.addElement(names[i]); } } String [] subdirs = new String[v.size()]; v.copyInto(subdirs); StringBuffer sb = new StringBuffer(); sb.append("file:" + jarBaseDir + "/"); for(int i = 0; i < subdirs.length; i++) { sb.append(";file:" + jarBaseDir + "/" + subdirs[i] + "/"); } jars = sb.toString().replace('\\', '/'); sysProps.put("org.knopflerfish.gosg.jars", jars); println("scanned org.knopflerfish.gosg.jars=" + jars, 1); } } // Write back system properties System.setProperties(sysProps); } /** * Loop over args array and check that it looks reasonable. * If really bad things are found, they might be fixed ;) * * <p> * This method is intended to be called in the "zeroargs" * startup case to preserve backwards compatibility. * </p> * * @return new, fixed args array. */ static String [] sanityArgs(String[] args) { Vector v = new Vector(); // First, clone everything for(int i = 0; i < args.length; i++) { v.addElement(args[i]); } // ...since this is really annoying if(!v.contains("-launch")) { println("adding last -launch command", 1); v.addElement("-launch"); } // ...and copy back into array String [] arg2 = new String[v.size()]; v.copyInto(arg2); return arg2; } /** * Helper method when OS shell does not allow long command lines. This * method has nowadays become the only reasonable way to start the * framework due to the amount of properties. * * <p> * Loads a specified file or URL and * creates a new String array where each entry corresponds to entries * in the loaded file. * </p> * * <p> * File format:<br> * * <ul> * <li>Each line starting with '-D' and containing an '=' is set as * a system property. * Example "-Dorg.knopflerfish.test=apa" is equivalent * to <code>System.setProperty("org.knopflerfish.test", "apa");</code> * <li>Each line of length zero is ignored. * <li>Each line starting with '#' is ignored. * <li>Lines starting with '-' is used a command with optional argument * after space. * <li>All other lines is used directly as an entry to the new * command line array. * </ul> * </p> * * * @param argv Original command line arguments. These should begin * with "-xargs" "<file to load>". If argv.length < 2 * return original argv. * @return Original argv + argv loaded from file */ static String [] loadArgs(String xargsPath, String[] oldArgs) { if(XARGS_DEFAULT.equals(xargsPath)) { xargsPath = getDefaultXArgs(oldArgs); } // out result Vector v = new Vector(); try { BufferedReader in = null; // Check as file first, then as a URL File f = new File(xargsPath); if(f.exists()) { println("Loading xargs file " + f.getAbsolutePath(), 0); in = new BufferedReader(new FileReader(f)); } if(in == null) { try { URL url = new URL(xargsPath); println("Loading xargs url " + url, 0); in = new BufferedReader(new InputStreamReader(url.openStream())); } catch (MalformedURLException e) { throw new IllegalArgumentException("Bad xargs URL " + xargsPath + ": " + e); } } Properties sysProps = System.getProperties(); StringBuffer contLine = new StringBuffer(); String line = null; String tmpline = null; int lineno = 0; for(tmpline = in.readLine(); tmpline != null; tmpline = in.readLine()) { lineno++; tmpline = tmpline.trim(); // check for line continuation char and // build up line until aline without such a mark is found. if(tmpline.endsWith("\\")) { // found continuation mark, store actual line to // buffered continuation line tmpline = tmpline.substring(0, tmpline.length() - 1); if(contLine == null) { contLine = new StringBuffer(tmpline); } else { contLine.append(tmpline); } // read next line continue; } else { // No continuation mark, gather stored line + newly read line if(contLine != null) { contLine.append(tmpline); line = contLine.toString(); contLine = null; } else { // this is the normal case if no continuation char is found // or any buffered line is found line = tmpline; } } if(line.startsWith("-D")) { // Set system property int ix = line.indexOf("="); if(ix != -1) { String name = line.substring(2, ix); String val = line.substring(ix + 1); // replace "${syspropname}" with system prop value if found if(-1 != val.indexOf("${")) { for(Enumeration e = sysProps.keys(); e.hasMoreElements();) { String k = (String)e.nextElement(); if(-1 != val.indexOf(k)) { String sv = (String)sysProps.get(k); val = Util.replace(val, "${" + k + "}", sv); } } } sysProps.put(name, val); } } else if(line.startsWith("#")) { // Ignore comments } else if(line.startsWith("-")) { int i = line.indexOf(' '); if (i != -1) { v.addElement(line.substring(0,i)); line = line.substring(i).trim(); if(line.length() > 0) { v.addElement(line); } } else { v.addElement(line); } } else if(line.length() > 0) { // Add argument v.addElement(line); } } setSecurityManager(sysProps); System.setProperties(sysProps); } catch (Exception e) { throw new IllegalArgumentException("xargs loading failed: " + e); } String [] args2 = new String[v.size()]; v.copyInto(args2); return args2; } /** * Print string to System.out if level >= current verbosity. * * @param s String to print. * @param level print level. */ static void println(String s, int level) { if(verbosity >= level) { System.out.println((level > 0 ? ("#" + level + ": ") : "") + s); } } static void setSecurityManager(Properties props) { try { String manager = (String)props.get("java.security.manager"); String policy = (String)props.get("java.security.policy"); if(manager != null) { if(System.getSecurityManager() == null) { println("Setting security manager=" + manager + ", policy=" + policy, 1); System.setProperty("java.security.manager", manager); if(policy != null) { System.setProperty("java.security.policy", policy); } SecurityManager sm = null; if("".equals(manager)) { sm = new SecurityManager(); } else { Class clazz = Class.forName(manager); Constructor cons = clazz.getConstructor(new Class[0]); sm = (SecurityManager)cons.newInstance(new Object[0]); } System.setSecurityManager(sm); } } } catch (Exception e) { error("Failed to set security manager", e); } } /** * Report error and exit. */ static void error(String s) { error(s, null); } static void error(String s, Exception e) { System.err.println("Error: " + s); if(e != null) { e.printStackTrace(); } System.exit(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -