/** * Get the property under the given partial key, prefixed with any possible * configuration prefix. */ public static Object getProperty(String partialKey, Map m) { if (partialKey == null || m == null || m.isEmpty()) return null; else return m.get(ProductDerivations.getConfigurationKey(partialKey, m)); }
boolean hasKnownPrefix(String key) { String[] prefixes = ProductDerivations.getConfigurationPrefixes(); for (String prefix : prefixes) { if (key.startsWith(prefix)) return true; } return false; }
public void valueChanged(Value value) { if (this.getClass().isInstance(value)) ProductDerivations.afterSpecificationSet(_conf); } }
/** * Default constructor. */ public XMLConfiguration() { super(false, false); // override the default and the current value of lock manager plugin // from our superclass to use the single-jvm lock manager lockManagerPlugin.setDefault("version"); lockManagerPlugin.setString("version"); ProductDerivations.beforeConfigurationLoad(this); loadGlobals(); }
/** * Return a {@link ConfigurationProvider} that has parsed system defaults. */ public static ConfigurationProvider loadDefaults(ClassLoader loader) { return load(loader, false); }
if ((AccessController.doPrivileged(J2DoPrivHelper .isFileAction(file))).booleanValue()) provider = ProductDerivations.load(file, anchor, null); else { file = new File("META-INF" + File.separatorChar + path); if ((AccessController.doPrivileged(J2DoPrivHelper .isFileAction(file))).booleanValue()) provider = ProductDerivations.load(file, anchor, null); else provider = ProductDerivations.load(path, anchor, null); props); } else { provider = ProductDerivations.loadDefaults(null); if (provider != null) provider.setInto(conf);
if (propertiesLocation == null) { String loc = _derivations[i].getDefaultResourceLocation(); addAll(fqAnchors, loc, _derivations[i].getAnchorsInResource(loc)); continue; if (((Boolean) J2DoPrivHelper.isFileAction(f).run()) .booleanValue()) { addAll(fqAnchors, propertiesLocation, _derivations[i].getAnchorsInFile(f)); } else { if (((Boolean) J2DoPrivHelper.isFileAction(f).run()) .booleanValue()) { addAll(fqAnchors, propertiesLocation, _derivations[i].getAnchorsInFile(f)); } else { addAll(fqAnchors, propertiesLocation, _derivations[i].getAnchorsInResource( propertiesLocation)); reportErrors(errs, propertiesLocation, err); return fqAnchors;
private static BrokerFactory invokeFactory(ConfigurationProvider conf, ClassLoader loader, String methodName, Class<?>[] argTypes, Object[] args) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { if (conf == null) conf = new MapConfigurationProvider(); ProductDerivations.beforeConfigurationConstruct(conf); Class cls = getFactoryClass(conf, loader); Method meth; try { meth = cls.getMethod(methodName, argTypes); } catch (NoSuchMethodException nsme) { // handle cases where there is a mismatch between loaders by falling // back to the configuration's class loader for broker resolution cls = getFactoryClass(conf, AccessController.doPrivileged( J2DoPrivHelper.getClassLoaderAction(conf.getClass()))); meth = cls.getMethod(methodName, argTypes); } return (BrokerFactory) meth.invoke(null, args); }
/** * Prints product derivation information. */ public static void main(String[] args) { // START - ALLOW PRINT STATEMENTS System.err.println(derivationErrorsToString()); // STOP - ALLOW PRINT STATEMENTS }
/** * Closes all closeable values and plugins. */ public final void close() { ProductDerivations.beforeClose(this); preClose(); ObjectValue val; for (int i = 0; i < _vals.size(); i++) { if (_vals.get(i) instanceof Closeable) { try { ((Closeable) _vals.get(i)).close(); } catch (Exception e) {} continue; } if (!(_vals.get(i) instanceof ObjectValue)) continue; val = (ObjectValue) _vals.get(i); if (val.get() instanceof Closeable) { try { ((Closeable) val.get()).close(); } catch (Exception e) { } } } }
/** * Return a List<String> of all the fully-qualified anchors specified in the * properties location listed in <code>opts</code>. If no properties * location is listed in <code>opts</code>, this returns whatever the * product derivations can find in their default configurations. * If the properties location specified in <code>opts</code> already * contains an anchor spec, this returns that anchor. Note that in this * fully-qualified-input case, the logic involving product derivations * and resource parsing is short-circuited, so this method * should not be used as a means to test that a particular anchor is * defined in a given location by invoking with a fully-qualified anchor. * * This does not mutate <code>opts</code>. * * @since 1.1.0 */ public static List getFullyQualifiedAnchorsInPropertiesLocation( Options opts) { String props = opts.getProperty("properties", "p", null); if (props != null) { int anchorPosition = props.indexOf("#"); if (anchorPosition > -1) return Arrays.asList(new String[] { props }); } return ProductDerivations.getFullyQualifiedAnchorsInPropertiesLocation( props); }
/** * Default constructor. */ public XMLConfiguration() { super(false, false); // override the default and the current value of lock manager plugin // from our superclass to use the single-jvm lock manager lockManagerPlugin.setDefault("version"); lockManagerPlugin.setString("version"); ProductDerivations.beforeConfigurationLoad(this); loadGlobals(); }
/** * Return a {@link ConfigurationProvider} that has parsed system defaults. */ public static ConfigurationProvider loadDefaults(ClassLoader loader) { return load(loader, false); }
public void execute() throws BuildException { // if the user didn't supply a conf file, load the default if (_conf == null) _conf = newConfiguration(); ConfigurationProvider cp = null; String propertiesResource = _conf.getPropertiesResource(); if ( propertiesResource == null) { cp = ProductDerivations.loadDefaults(getConfigPropertiesResourceLoader()); } else if (_conf.isDeferResourceLoading() && !StringUtils.isEmpty(propertiesResource)) { Map<String, String> result = Configurations.parseConfigResource(propertiesResource); String path = result.get(Configurations.CONFIG_RESOURCE_PATH); String anchor = result.get(Configurations.CONFIG_RESOURCE_ANCHOR); cp = ProductDerivations.load(path, anchor, getConfigPropertiesResourceLoader()); } if (cp != null){ cp.setInto(_conf); } String[] files = getFiles(); try { executeOn(files); } catch (Throwable e) { e.printStackTrace(); if (haltOnError) throw new BuildException(e); } finally { _conf.close(); _conf = null; } }
if (propertiesLocation == null) { String loc = _derivations[i].getDefaultResourceLocation(); addAll(fqAnchors, loc, _derivations[i].getAnchorsInResource(loc)); continue; if (((Boolean) J2DoPrivHelper.isFileAction(f).run()) .booleanValue()) { addAll(fqAnchors, propertiesLocation, _derivations[i].getAnchorsInFile(f)); } else { if (((Boolean) J2DoPrivHelper.isFileAction(f).run()) .booleanValue()) { addAll(fqAnchors, propertiesLocation, _derivations[i].getAnchorsInFile(f)); } else { addAll(fqAnchors, propertiesLocation, _derivations[i].getAnchorsInResource( propertiesLocation)); reportErrors(errs, propertiesLocation, err); return fqAnchors;
private static BrokerFactory invokeFactory(ConfigurationProvider conf, ClassLoader loader, String methodName) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { if (conf == null) conf = new MapConfigurationProvider(); ProductDerivations.beforeConfigurationConstruct(conf); Class cls = getFactoryClass(conf, loader); Method meth; try { meth = cls.getMethod(methodName, FACTORY_ARGS); } catch (NoSuchMethodException nsme) { // handle cases where there is a mismatch between loaders by falling // back to the configuration's class loader for broker resolution cls = getFactoryClass(conf, (ClassLoader) AccessController.doPrivileged( J2DoPrivHelper.getClassLoaderAction(conf.getClass()))); meth = cls.getMethod(methodName, FACTORY_ARGS); } return (BrokerFactory) meth.invoke(null, new Object[]{ conf }); }
/** * Prints product derivation information. */ public static void main(String[] args) { System.err.println(derivationErrorsToString()); }
/** * Closes all closeable values and plugins. */ public final void close() { ProductDerivations.beforeClose(this); preClose(); ObjectValue val; for(Value v : _vals) { if (v instanceof Closeable) { try { ((Closeable)v).close(); } catch (Exception e) {} continue; } if (!(v instanceof ObjectValue)) continue; val = (ObjectValue) v; if (val.get() instanceof Closeable) { try { ((Closeable) val.get()).close(); } catch (Exception e) { } } } }
/** * Return a List<String> of all the fully-qualified anchors specified in the * properties location listed in <code>opts</code>. If no properties * location is listed in <code>opts</code>, this returns whatever the * product derivations can find in their default configurations. * If the properties location specified in <code>opts</code> already * contains an anchor spec, this returns that anchor. Note that in this * fully-qualified-input case, the logic involving product derivations * and resource parsing is short-circuited, so this method * should not be used as a means to test that a particular anchor is * defined in a given location by invoking with a fully-qualified anchor. * * This does not mutate <code>opts</code>. * * @since 1.1.0 */ public static List<String> getFullyQualifiedAnchorsInPropertiesLocation( Options opts) { String props = opts.getProperty("properties", "p", null); if (props != null) { int anchorPosition = props.indexOf("#"); if (anchorPosition > -1) return Arrays.asList(new String[] { props }); } return ProductDerivations.getFullyQualifiedAnchorsInPropertiesLocation( props); }
/** * Test whether the map contains the given partial key, prefixed with any * possible configuration prefix. */ public static boolean containsProperty(String partialKey, Map props) { if (partialKey == null || props == null || props.isEmpty()) return false; else return props.containsKey( ProductDerivations.getConfigurationKey(partialKey, props)); }