private void markCreated(BundleContext bundleContext) throws IOException { File marker = new File(dataDir, ENSEMBLE_MARKER); if (!marker.exists() && !marker.getParentFile().exists() && !marker.getParentFile().mkdirs()) { throw new IOException("Cannot create marker file"); } org.apache.felix.utils.properties.Properties props = new org.apache.felix.utils.properties.Properties(marker); props.put("created", "true"); props.save(); }
@Override public Dictionary<String, Object> read(InputStream in) throws IOException { notNull(in, "Input stream cannot be null"); final Properties props = new Properties(); props.load(in); return new Hashtable<>(props); } }
public boolean update(Properties properties) { boolean modified = false; // Remove "removed" properties from the cfg file for (String key : new ArrayList<String>(this.keySet())) { if (!properties.containsKey(key)) { this.remove(key); modified = true; } } // Update existing keys for (String key : properties.keySet()) { String v = this.get(key); List<String> comments = properties.getComments(key); List<String> value = properties.getRaw(key); if (v == null) { this.put(key, comments, value); modified = true; } else if (!v.equals(properties.get(key))) { if (comments.isEmpty()) { comments = this.getComments(key); } this.put(key, comments, value); modified = true; } } return modified; }
public static Properties toProperties(Map<String, String> source) { if (source instanceof Properties) { return (Properties) source; } Properties rc = new Properties(false); rc.putAll(source); return rc; }
public static void setProperties(CuratorFramework curator, String path, Properties properties) throws Exception { try { org.apache.felix.utils.properties.Properties p = new org.apache.felix.utils.properties.Properties(); if(curator.checkExists().forPath(path) == null){ create(curator, path); } String org = getStringData(curator, path); if (org != null) { p.load(new StringReader(org)); } List<String> keys = new ArrayList<String>(); for (String key : properties.stringPropertyNames()) { p.put(key, properties.getProperty(key)); keys.add(key); } List<String> deleted = new ArrayList<String>(p.keySet()); deleted.removeAll(keys); for (String key : deleted) { p.remove(key); } StringWriter writer = new StringWriter(); p.save(writer); setData(curator, path, writer.toString()); } catch (IOException e) { // ignore } }
private void ensureTyped() { if (!storage.typed) { storage.typed = true; Set<String> keys = new HashSet<String>(storage.keySet()); for (String key : keys) { storage.put(key, storage.getComments(key), Arrays.asList(convertToString(storage.get(key)).split("\n"))); } } }
public boolean update(Map<String, String> props) { Properties properties; if (props instanceof Properties) { properties = (Properties) props; } else { properties = new Properties(); for (Map.Entry<? extends String, ? extends String> e : props.entrySet()) { properties.put(e.getKey(), e.getValue()); } } return update(properties); }
private void loadPropertiesFrom(Dictionary<String, Object> dictionary, String from) { InputStream is = null; Properties properties = new Properties(); try { is = new FileInputStream(from); properties.load(is); for (String key : properties.keySet()) { dictionary.put(key, properties.get(key)); } } catch (Exception e) { // Ignore } finally { if (is != null) { try { is.close(); } catch (Exception e) { // Ignore } } } }
public void setFrameworkDebug(boolean debug) { try { Properties properties = loadProps(); if (debug) { properties.put("felix.log.level", "4"); properties.put("osgi.debug", "etc/equinox-debug.properties"); } else { properties.remove("felix.log.level"); properties.remove("osgi.debug"); } // TODO populate the equinox-debug.properties file with the one provided in shell/dev module properties.save(); } catch (IOException e) { throw new RuntimeException("Error setting framework debugging: " + e.getMessage(), e); } }
public void setFramework(FrameworkType framework) { if (framework == null) { return; } try { Properties properties = loadProps(); properties.put("karaf.framework", framework.name()); properties.save(); } catch (IOException e) { throw new RuntimeException("Error setting framework: " + e.getMessage(), e); } }
/** * Store a properties into a output stream, preserving comments, special character, etc. * This method is mainly to be compatible with the java.util.Properties class. * * @param os an output stream. * @param comment this parameter is ignored as this Properties * @throws IOException If storing fails */ public void store(OutputStream os, String comment) throws IOException { this.save(os); }
/** * Calls the map method put. Provided for parallelism with the getProperty method. * Enforces use of strings for property keys and values. The value returned is the result of the map call to put. * * @param key the key to be placed into this property list. * @param value the value corresponding to the key. * @return the previous value of the specified key in this property list, or null if it did not have one. */ public Object setProperty(String key, String value) { return this.put(key, value); }
public Properties(File location, InterpolationHelper.SubstitutionCallback callback) throws IOException { this.location = location; this.callback = callback; if(location.exists()) load(location); }
private void reformatClauses(Properties config, String key) { String val = config.getProperty(key); if (val != null && !val.isEmpty()) { List<String> comments = config.getComments(key); Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseHeader(val); Set<String> strings = new LinkedHashSet<>(); for (Clause clause : clauses) { strings.add(clause.toString()); } List<String> lines = new ArrayList<>(); lines.add(""); int index = 0; for (String string : strings) { String s = " " + string; if (index++ < strings.size() - 1) { s += ", "; } lines.add(s); } config.put(key, comments, lines); } }
public Properties getProperties() { Properties props = new Properties(); try { org.apache.felix.utils.properties.Properties properties = new org.apache.felix.utils.properties.Properties(); properties.load(new StringReader(value)); for (Map.Entry<String, String> e : properties.entrySet()) { props.put(e.getKey(), e.getValue()); } } catch (IOException e) { // ignore?? } return props; }
public TypedProperties(SubstitutionCallback callback, boolean substitute) { this.storage = new Properties(false); this.callback = callback; this.substitute = substitute; }
private String getPropertyOrFail(String propertyName) { String value = props.getProperty(propertyName); if (value == null) { throw new IllegalArgumentException("Property " + propertyName + " must be set in the etc/" + CONFIG_PROPERTIES_FILE_NAME + " configuration file"); } return value; }