public Map<String, Map<String, String>> parseHeader(String value) { return parseHeader(value, this); }
/** * Print a standard Map based OSGi header. * * @param exports * map { name => Map { attribute|directive => value } } * @return the clauses */ public static String printClauses(Map<String, Map<String, String>> exports, String allowedDirectives) { return printClauses(exports, allowedDirectives, false); }
public void addProperties(File file) throws Exception { addIncluded(file); Properties p = loadProperties(file); setProperties(p); }
Map<String, Map<String, String>> getClauses(String header) { return parseHeader(getProperty(header)); }
String includes = p.getProperty(INCLUDE); if (includes != null) { includes = getReplacer().process(includes); p.remove(INCLUDE); Collection<String> clauses = parseHeader(includes).keySet(); File file = getFile(ubase, value).getAbsoluteFile(); if (file.isFile()) { if (included != null && included.contains(file)) { error("Cyclic include of " + file); } else { addIncluded(file); updateModified(file.lastModified(), "Include " + value); InputStream in = new FileInputStream(file); Properties sub; if (file.getName().toLowerCase().endsWith(".mf")) { sub = getManifestAsProperties(in); } else sub = loadProperties(in, file.getAbsolutePath()); in.close(); doIncludes(file.getParentFile(), sub, done); error("Included file " + file + (file.exists() ? " does not exist" error("Error in processing included file: " + value, e);
String spe = getProperty(Analyzer.PLUGIN, DEFAULT_PLUGINS); Map<String, Map<String, String>> plugins = parseHeader(spe); List<Object> list = new ArrayList<Object>(); String key = (String) entry.getKey(); if (key.equals(NONE)) return this.plugins = newList(); CL loader = getLoader(); String path = entry.getValue().get(PATH_DIRECTIVE); if (path != null) { File f = getFile(path).getAbsoluteFile(); loader.add(f.toURL()); trace("Using plugin %s", key); key = removeDuplicateMarker(key); error("Problem loading the plugin: %s exception: (%s)", key, t); else { Collection<String> cs = split(commands); missingCommand.addAll(cs); error("Problem loading the plugin: " + key + " exception: " + e);
Map<String, Map<String, String>> plugins = parseHeader(spe); for (Map.Entry<String, Map<String, String>> entry : plugins.entrySet()) { String key = (String) entry.getKey(); CL loader = getLoader(); String path = entry.getValue().get(PATH_DIRECTIVE); if (path != null) { String parts[] = path.split("\\s*,\\s*"); for (String p : parts) { File f = getFile(p).getAbsoluteFile(); loader.add(f.toURI().toURL()); trace("Using plugin %s", key); key = removeDuplicateMarker(key); customize(plugin, entry.getValue()); list.add(plugin); } catch (Throwable t) { error("Problem loading the plugin: %s exception: (%s)", key, t); else { Collection<String> cs = split(commands); missingCommand.addAll(cs); error("Problem loading the plugin: " + key + " exception: " + e);
/** * @param file * @param parent * @param done * @param overwrite * @throws FileNotFoundException * @throws IOException */ public void doIncludeFile(File file, boolean overwrite, Properties target) throws Exception { if (included != null && included.contains(file)) { error("Cyclic or multiple include of " + file); } else { addIncluded(file); updateModified(file.lastModified(), file.toString()); InputStream in = new FileInputStream(file); Properties sub; if (file.getName().toLowerCase().endsWith(".mf")) { sub = getManifestAsProperties(in); } else sub = loadProperties(in, file.getAbsolutePath()); in.close(); doIncludes(file.getParentFile(), sub); // make sure we do not override properties for (Map.Entry<?, ?> entry : sub.entrySet()) { if (overwrite || !target.containsKey(entry.getKey())) target.setProperty((String) entry.getKey(), (String) entry.getValue()); } } }
String includes = p.getProperty(INCLUDE); if (includes != null) { includes = getReplacer().process(includes); p.remove(INCLUDE); Collection<String> clauses = parseHeader(includes).keySet(); File file = getFile(ubase, value).getAbsoluteFile(); if (!file.isFile() && fileMustExist) { error("Included file " + file + (file.exists() ? " does not exist" : " is directory")); } else doIncludeFile(file, overwrite, p); } catch (Exception e) { if (fileMustExist) error("Error in processing included file: " + value, e);
public void setProperties(File propertiesFile, File base) { this.propertiesFile = propertiesFile.getAbsoluteFile(); setBase(base); try { if (propertiesFile.isFile()) { // System.out.println("Loading properties " + propertiesFile); long modified = propertiesFile.lastModified(); if (modified > System.currentTimeMillis() + 100) { System.out.println("Huh? This is in the future " + propertiesFile); this.modified = System.currentTimeMillis(); } else this.modified = modified; included = null; Properties p = loadProperties(propertiesFile); setProperties(p); } else { if (fileMustExist) { error("No such properties file: " + propertiesFile); } } } catch (IOException e) { error("Could not load properties " + propertiesFile); } }
public void mergeProperties(File file, boolean override) { if (file.isFile()) { try { Properties properties = loadProperties(file); mergeProperties(properties, override); } catch (Exception e) { error("Error loading properties file: " + file); } } else { if (!file.exists()) error("Properties file does not exist: " + file); else error("Properties file must a file, not a directory: " + file); } }
public void execute() throws BuildException { try { if (propertyFile.exists()) { Properties properties = new Properties(); properties.putAll((Map<?,?>)getProject().getProperties()); Processor processor = new Processor(properties); processor.setProperties(propertyFile); Project project = getProject(); Properties flattened = processor.getFlattenedProperties(); for (Iterator<Object> i = flattened.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); if (project.getProperty(key) == null) { project.setProperty(key, flattened.getProperty(key)); } } } report(); } catch (IOException e) { e.printStackTrace(); throw new BuildException(e); } }
public void report(boolean warnings, boolean acknowledge , Processor reporter, final String title, final String extra ) { if (reporter.getErrors().size() > 0 || (warnings && reporter.getWarnings().size() > 0)) { final StringBuffer sb = new StringBuffer(); sb.append("\n"); if (reporter.getErrors().size() > 0) { sb.append("[Errors]\n"); for (String msg : reporter.getErrors()) { sb.append(msg); sb.append("\n"); if (reporter.getWarnings().size() > 0) { sb.append("[Warnings]\n"); for (String msg : reporter.getWarnings()) { sb.append(msg); sb.append("\n"); reporter.clear();
public void setProperties(Properties properties) { doIncludes(getBase(), properties); this.properties.putAll(properties); }
Properties loadProperties(InputStream in, String name) throws IOException { int n = name.lastIndexOf('/'); if (n > 0) name = name.substring(0, n); if (name.length() == 0) name = "."; try { Properties p = new Properties(); p.load(in); return replaceAll(p, "\\$\\{\\.\\}", name); } catch (Exception e) { error("Error during loading properties file: " + name + ", error:" + e); return new Properties(); } }
/** * System command. Execute a command and insert the result. * * @param args * @param help * @param patterns * @param low * @param high */ public String system_internal(boolean allowFail, String args[]) throws Exception { verifyCommand(args, "${" + (allowFail ? "system-allow-fail" : "system") + ";<command>[;<in>]}, execute a system command", null, 2, 3); String command = args[1]; String input = null; if (args.length > 2) { input = args[2]; } Process process = Runtime.getRuntime().exec(command, null, domain.getBase()); if (input != null) { process.getOutputStream().write(input.getBytes("UTF-8")); } process.getOutputStream().close(); String s = IO.collect(process.getInputStream(), "UTF-8"); int exitValue = process.waitFor(); if (!allowFail && (exitValue != 0)) { domain.error("System command " + command + " failed with " + exitValue); } return s.trim(); }
private String doCommand(Object target, String method, String[] args) { if (target == null) ; // System.out.println("Huh? Target should never be null " + // domain); else { String cname = "_" + method.replaceAll("-", "_"); try { Method m = target.getClass().getMethod(cname, new Class[] { String[].class }); return (String) m.invoke(target, new Object[] { args }); } catch (NoSuchMethodException e) { // Ignore } catch (InvocationTargetException e) { if ( e.getCause() instanceof IllegalArgumentException ) { domain.error("%s, for cmd: %s, arguments; %s", e.getMessage(), method, Arrays.toString(args)); } else { domain.warning("Exception in replace: " + e.getCause()); e.getCause().printStackTrace(); } } catch (Exception e) { domain.warning("Exception in replace: " + e + " method=" + method); e.printStackTrace(); } } return null; }
String version(Version version, String mask) { if (version == null) { String v = domain.getProperty("@"); if (v == null) { domain .error( "No version specified for ${version} or ${range} and no implicit version ${@} either, mask=%s", mask);