List of usage examples for org.apache.commons.configuration HierarchicalINIConfiguration HierarchicalINIConfiguration
public HierarchicalINIConfiguration(URL url) throws ConfigurationException
From source file:org.porquebox.core.processors.AbstractSplitIniParsingProcessor.java
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit unit = phaseContext.getDeploymentUnit(); ResourceRoot resourceRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT); PorqueBoxMetaData globalMetaData = unit.getAttachment(PorqueBoxMetaData.ATTACHMENT_KEY); Object data = null;// w w w. j av a 2 s.co m if (globalMetaData != null) { data = globalMetaData.getSection(getSectionName()); } VirtualFile root = resourceRoot.getRoot(); if (data == null && isSupportsStandalone()) { VirtualFile metaDataFile = getMetaDataFile(root, getFileName()); if ((metaDataFile == null || !metaDataFile.exists()) && this.supportsSuffix) { List<VirtualFile> matches = getMetaDataFileBySuffix(root, "-" + getFileName()); if (!matches.isEmpty()) { if (matches.size() > 1) { log.warn("Multiple matches: " + matches); } metaDataFile = matches.get(0); } } if ((metaDataFile != null) && metaDataFile.exists()) { if (!metaDataFile.equals(root) && this.standaloneDeprecated) { logDeprecation(unit, "Usage of " + getFileName() + " is deprecated. Please use porquebox.ini."); } try { //TODO import Configuration into data. Configuration conf = new HierarchicalINIConfiguration(metaDataFile.asFileURL()); } catch (Exception e) { throw new DeploymentUnitProcessingException("Error processing yaml: ", e); } } } else { // If data has been specified for this section, and the deployment // is rootless, // but rootlessness is not supported, then error out. PhpAppMetaData phpMetaData = unit.getAttachment(PhpAppMetaData.ATTACHMENT_KEY); if (data != null && !isSupportsRootless() && phpMetaData != null && DeploymentUtils.isUnitRootless(unit)) { throw new DeploymentUnitProcessingException(String.format( "Error processing deployment %s: The section %s requires an app root to be specified, but none has been provided.", unit.getName(), getSectionName())); } } if (data == null) { return; } try { parse(unit, data); } catch (DeploymentUnitProcessingException e) { throw e; } catch (Exception e) { e.printStackTrace(); throw new DeploymentUnitProcessingException(e); } }
From source file:org.porquebox.core.processors.PorqueBoxIniParsingProcessor.java
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit unit = phaseContext.getDeploymentUnit(); ResourceRoot resourceRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT); VirtualFile root = resourceRoot.getRoot(); VirtualFile file = getMetaDataFile(root, PORQUEBOX_INI_FILE); if (file != null) { Map<String, Object> data = null; try {/*from w w w .j av a2s . co m*/ Configuration conf = new HierarchicalINIConfiguration(file.asFileURL()); //TODO: Import configuration into data Map. } catch (Exception e) { throw new DeploymentUnitProcessingException("Error processing ini: ", e); } PorqueBoxMetaData metaData = new PorqueBoxMetaData(data); PorqueBoxMetaData externalMetaData = unit.getAttachment(PorqueBoxMetaData.ATTACHMENT_KEY); if (externalMetaData != null) { metaData = externalMetaData.overlayOnto(metaData); } try { metaData.validate(); } catch (Exception e) { throw new DeploymentUnitProcessingException("Configuration validation failed: ", e); } unit.putAttachment(PorqueBoxMetaData.ATTACHMENT_KEY, metaData); } }
From source file:org.settings4j.helper.configuration.ConfigurationToConnectorAdapterTest.java
private HierarchicalINIConfiguration addINIConfiguration(final Settings4jRepository testSettings, final String connectorName, final String fileName, final String propertyDelimiter) throws ConfigurationException { ConfigurationToConnectorAdapter connector = (ConfigurationToConnectorAdapter) testSettings.getSettings()// .getConnector(connectorName); if (connector == null) { final File iniConfig = new File(TestUtils.getTestFolder(), "helper/configuration/" + fileName); iniConfig.delete();/*from w ww .ja va 2s . co m*/ HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(iniConfig); final DefaultExpressionEngine expressionEngine = new DefaultExpressionEngine(); expressionEngine.setPropertyDelimiter(propertyDelimiter); configuration.setExpressionEngine(expressionEngine); connector = new ConfigurationToConnectorAdapter(connectorName, configuration); testSettings.getSettings().addConnector(// connector, ConnectorPositions.afterLast(SystemPropertyConnector.class)); } return (HierarchicalINIConfiguration) connector.getConfiguration(); }
From source file:org.zanata.client.commands.init.UserConfigHandler.java
/** * Search for zanata.ini. (If there's none, link them to the help page). * Provide a list of servers to choose from. * @throws Exception/*from w w w. j a v a 2 s .c om*/ */ @VisibleForTesting protected void verifyUserConfig() throws Exception { File userConfig = opts.getUserConfig(); if (!userConfig.exists()) { throw new RuntimeException(get("missing.user.config")); } clearValueSetByConfigurableMojo(); // read in content and get all available server urls HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(opts.getUserConfig()); List<URL> serverUrls = readServerUrlsFromUserConfig(config); // apply user config if (serverUrls.isEmpty()) { String msg = get("missing.server.url"); log.warn(msg); throw new RuntimeException(msg); } if (serverUrls.size() == 1) { opts.setUrl(serverUrls.get(0)); } else { consoleInteractor.printfln(get("found.servers"), opts.getUserConfig().getName()); List<String> answers = listServerUrlsPrefixedWithNumber(serverUrls); consoleInteractor.printf(Question, get("which.server")); String chosenNumber = consoleInteractor.expectAnswerWithRetry(expect(answers)); URL url = serverUrls.get(Integer.parseInt(chosenNumber) - 1); consoleInteractor.printfln(Confirmation, get("server.selection"), url); opts.setUrl(url); } OptionsUtil.applyUserConfig(opts, config); }
From source file:rascal.storage.FileSystemConfigurationSource.java
public FileSystemConfigurationSource(FileSystemStorageLayout storageLayout) { try {// www . j a v a2s. co m commonsConfiguration = new HierarchicalINIConfiguration(storageLayout.getConfigurationFile()); } catch (ConfigurationException e) { // TODO: some special excaptions for this case throw new RuntimeException(e); } }
From source file:sf.net.experimaestro.tasks.ServerTask.java
/** * Server thread/*from w w w . j a v a 2 s. co m*/ */ public int execute() throws Throwable { if (configuration == null || configuration.getFile() == null) { final String envConfFile = System.getenv("EXPERIMAESTRO_CONFIG_FILE"); File file = null; if (envConfFile != null) { file = new File(envConfFile); LOGGER.info("Using configuration file set in environment: '" + file + "'"); } else { file = new File(new File(System.getProperty("user.home"), ".experimaestro"), "settings.ini"); LOGGER.info("Using the default configuration file " + file); } assert file != null; configuration = new HierarchicalINIConfiguration(file); } LOGGER.info("Reading configuration from " + configuration.getFileName()); // --- Get the server settings ServerSettings serverSettings = new ServerSettings(configuration.subset("server")); // --- Get the port port = configuration.getInt("server.port", 8080); LOGGER.info("Starting server on port %d", port); // --- Set up the task manager final String property = configuration.getString("server.database"); if (property == null) throw new IllegalArgumentException("No 'database' in 'server' section of the configuration file"); File taskmanagerDirectory = new File(property); scheduler = new Scheduler(taskmanagerDirectory); // Early initialization to detect errors XPMContext.init(); // Main repository final Repositories repositories = new Repositories(new File("/").toPath()); Server webServer = new Server(); // TCP-IP socket ServerConnector connector = new ServerConnector(webServer); connector.setPort(port); webServer.addConnector(connector); // Unix domain socket if (configuration.containsKey(KEY_SERVER_SOCKET)) { // TODO: move this to the target class String libraryPath = System.getProperty("org.newsclub.net.unix.library.path"); if (libraryPath == null) { URL url = ServerTask.class.getProtectionDomain().getCodeSource().getLocation(); File file = new File(url.toURI()); while (file != null && !new File(file, "native-libs").exists()) { file = file.getParentFile(); } if (file == null) throw new UnsatisfiedLinkError("Cannot find the native-libs directory"); file = new File(file, "native-libs"); LOGGER.info("Using path for junixsocket library [%s]", file); System.setProperty("org.newsclub.net.unix.library.path", file.getAbsolutePath()); } String socketSpec = configuration.getString(KEY_SERVER_SOCKET); UnixSocketConnector unixSocketConnector = new UnixSocketConnector(webServer); unixSocketConnector.setSocketFile(new File(socketSpec)); webServer.addConnector(unixSocketConnector); } HandlerList collection = new HandlerList(); // --- Non secure context ServletContextHandler nonSecureContext = new ServletContextHandler(collection, "/"); nonSecureContext.getServletHandler().setEnsureDefaultServlet(false); // no 404 default page nonSecureContext.addServlet(new ServletHolder(new NotificationServlet(serverSettings, scheduler)), "/notification/*"); // --- Sets the password on all pages ServletContextHandler context = new ServletContextHandler(collection, "/"); ConstraintSecurityHandler csh = getSecurityHandler(); context.setSecurityHandler(csh); // --- Add the JSON RPC servlet final JsonRPCServlet jsonRpcServlet = new JsonRPCServlet(webServer, scheduler, repositories); JsonRPCMethods.initMethods(); final ServletHolder jsonServletHolder = new ServletHolder(jsonRpcServlet); context.addServlet(jsonServletHolder, JSON_RPC_PATH); // --- Add the web socket servlet final XPMWebSocketServlet webSocketServlet = new XPMWebSocketServlet(webServer, scheduler, repositories); final ServletHolder webSocketServletHolder = new ServletHolder(webSocketServlet); context.addServlet(webSocketServletHolder, "/web-socket"); // --- Add the status servlet context.addServlet(new ServletHolder(new StatusServlet(serverSettings, scheduler)), "/status/*"); // --- Add the status servlet final ServletHolder taskServlet = new ServletHolder( new TasksServlet(serverSettings, repositories, scheduler)); context.addServlet(taskServlet, "/tasks/*"); // --- Add the JS Help servlet context.addServlet(new ServletHolder(new JSHelpServlet(serverSettings)), "/jshelp/*"); // --- Add the default servlet context.addServlet(new ServletHolder(new ContentServlet(serverSettings)), "/*"); // final URL warUrl = // this.getClass().getClassLoader().getResource("web"); // final String warUrlString = warUrl.toExternalForm(); // server.setHandler(new WebAppContext(warUrlString, "/")); // --- Sets the main handler webServer.setHandler(collection); // --- start the server and wait webServer.start(); if (wait) { webServer.join(); } LOGGER.info("Servers are stopped. Clean exit!"); return 0; }
From source file:sg.sfd2015.demo.utils.Config.java
synchronized private static void init() { String environment = System.getProperty("appenv") == null ? "development" : System.getProperty("appenv"); String path = System.getProperty("appconfig"); String pathFile = path + File.separator + environment + ".app.ini"; System.out.println("pathFile:" + pathFile); // init configuration config = new CompositeConfiguration(); _hashConfig = new ConcurrentHashMap<String, String>(); try {/* w ww . j a v a 2 s .c om*/ config.addConfiguration(new HierarchicalINIConfiguration(pathFile)); } catch (ConfigurationException ex) { logger_.error("Can't load configuration file", ex); System.err.println("Bad configuration; unable to start server"); System.exit(1); } }
From source file:uk.q3c.krail.core.config.DefaultApplicationConfigurationService.java
/** * The {@link #iniFiles} map is processed in ascending key order. If a file does not exist or fails to load for any * reason, and it is not marked as optional in IniFileConfig, a {@link ConfigurationException} is thrown. If, * however, the file fails to load, and is optional, no exception is raised. * * @throws ConfigurationException//from w w w . j a va 2 s.co m * if an error occurs while loading a file */ @Override protected void doStart() throws ConfigurationException { Set<Integer> keySorter = new TreeSet<>(iniFiles.keySet()); for (Integer k : keySorter) { IniFileConfig iniConfig = iniFiles.get(k); File file = new File(ResourceUtils.configurationDirectory(), iniConfig.getFilename()); try { if (!file.exists()) { throw new FileNotFoundException(file.getAbsolutePath()); } HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(file); configuration.addConfiguration(config); log.debug("adding configuration from {} at index {}", file.getAbsolutePath(), k); } catch (Exception ce) { if (!iniConfig.isOptional()) { String msg = ("Configuration Service failed to start, unable to load required configuration file:" + " " + file.getAbsolutePath()); status = Status.FAILED_TO_START; log.error(msg); throw new ConfigurationException(ce); } else { log.info("Optional configuration file not found at {}, but as it is optional, " + "" + "continuing without it", file); } } } log.info("Application Configuration Service started"); }
From source file:uk.q3c.krail.core.config.InheritingConfigurationTest.java
private HierarchicalINIConfiguration config(String filename) throws ConfigurationException { File root = TestResource.testJavaRootDir("krail"); File dir = new File(root, "uk/q3c/krail/core/config"); File file = new File(dir, filename); System.out.println(file.getAbsolutePath()); HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(file); return config; }
From source file:uk.q3c.krail.core.navigate.sitemap.DefaultSitemapServiceTest.java
@Before public void setup() throws ConfigurationException { File inifile = new File(ResourceUtils.userTempDirectory(), "WEB-INF/krail.ini"); iniConfig = new HierarchicalINIConfiguration(inifile); iniConfig.clear();//from ww w. java2s .c o m iniConfig.save(); }