Package org.apache.felix.utils.properties

Examples of org.apache.felix.utils.properties.Properties


            }
            if (Felix.NAME.equalsIgnoreCase(framework))
                frwk = new Felix(new File(KARAF_BASE));
            else
                frwk = new Equinox(new File(KARAF_BASE));
            Properties props = new Properties(new File(System.getProperty("karaf.etc"), "config.properties"));
            props.put("karaf.framework", framework.toLowerCase());
            props.save();
        }
        if (debug) {
            if (frwk == null)
                frwk = getFramework();
            System.out.printf("Enabling debug for OSGi framework (%s)%n", frwk.getName());
View Full Code Here


            return "Equinox";
        }
    }

    public void frameworkOptions(boolean debug, String framework) throws Exception {
        Properties properties = new Properties(new File(System.getProperty("karaf.etc"), "config.properties"));
        if (framework != null) {
            // switch the framework is use
            if (!framework.equalsIgnoreCase("felix") && !framework.equalsIgnoreCase("equinox")) {
                throw new IllegalArgumentException("Unsupported framework " + framework);
            }
            properties.put("karaf.framework", framework.toLowerCase());
        }
        if (debug) {
            properties.put("felix.log.level", "4");
            properties.put("osgi.debug", "etc/equinox-debug.properties");
            // TODO populate the equinox-debug.properties file with the one provided in shell/dev module
        } else {
            properties.remove("felix.log.level");
            properties.remove("osgi.debug");
        }
        properties.save();
    }
View Full Code Here

    }

    public void setProperty(String key, String value, boolean persistent) throws Exception {
        if (persistent) {
            String etc = System.getProperty("karaf.etc");
            Properties props = new Properties(new File(etc, "system.properties"));
            props.put(key, value);
            props.save();
        }
        System.setProperty(key, value);
    }
View Full Code Here

        }

        if (value != null) {
            if (persistent) {
                String base = System.getProperty("karaf.base");
                Properties props = new Properties(new File(base, "etc/system.properties"));
                props.put(key, value);
                props.save();
            }
            System.setProperty(key, value);
        } else {
            System.out.println(System.getProperty(key));
        }
View Full Code Here

    public static void execute(File file, final RunnableWithProperties callback, final boolean writeToFile) throws IOException {
        execute(file, new Runnable() {
            public void run(RandomAccessFile file) throws IOException {
                byte[] buffer = new byte[(int) file.length()];
                file.readFully(buffer);
                Properties props = new Properties();
                props.load(new ByteArrayInputStream(buffer));
                callback.run(props);
                if (writeToFile) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    props.store(baos, null);
                    file.setLength(0);
                    file.write(baos.toByteArray());
                }
            }
        });
View Full Code Here

    public static <T> T execute(File file, final CallableWithProperties<T> callback, final boolean writeToFile) throws IOException {
        return execute(file, new Callable<T>() {
            public T call(RandomAccessFile file) throws IOException {
                byte[] buffer = new byte[(int) file.length()];
                file.readFully(buffer);
                Properties props = new Properties();
                props.load(new ByteArrayInputStream(buffer));
                T result = callback.call(props);
                if (writeToFile) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    props.store(baos, null);
                    file.setLength(0);
                    file.write(baos.toByteArray());
                }
                return result;
            }
View Full Code Here

    public void setName(String name) {
        try {
            String karafEtc = bundleContext.getProperty("karaf.etc");
            File syspropsFile = new File(karafEtc, "system.properties");
            FileInputStream fis = new FileInputStream(syspropsFile);
            Properties props = new Properties();
            props.load(fis);
            fis.close();
            props.setProperty("karaf.name", name);
            FileOutputStream fos = new FileOutputStream(syspropsFile);
            props.store(fos, "");
            fos.close();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
View Full Code Here

    public void reboot(String time, boolean cleanup) throws Exception {
        reboot(timeToSleep(time), cleanup);
    }

    public void setFrameworkDebug(boolean debug) throws Exception {
        Properties properties = new Properties(new File(System.getProperty("karaf.etc"), "config.properties"));
        if (debug) {
            properties.put("felix.log.level", "4");
            properties.put("osgi.debug", "etc/equinox-debug.properties");
            // TODO populate the equinox-debug.properties file with the one provided in shell/dev module
        } else {
            properties.remove("felix.log.level");
            properties.remove("osgi.debug");
        }
        properties.save();
    }
View Full Code Here

    private boolean batch;
    private String file = null;
    private String command;

    public ClientConfig(String[] args) throws IOException {
        Properties shellCfg = new Properties(new File(System.getProperty("karaf.etc"), "org.apache.karaf.shell.cfg"));

        host = shellCfg.getProperty("sshHost", "localhost");
        port = Integer.parseInt(shellCfg.getProperty("sshPort", "8101"));
        level = SimpleLogger.WARN;
        retryAttempts = 0;
        retryDelay = 2;
        batch = false;
        file = null;
        user = null;
        password = null;
        StringBuilder commandBuilder = new StringBuilder();

        for (int i = 0; i < args.length; i++) {
            if (args[i].charAt(0) == '-') {
                if (args[i].equals("-a")) {
                    port = Integer.parseInt(args[++i]);
                } else if (args[i].equals("-h")) {
                    host = args[++i];
                } else if (args[i].equals("-u")) {
                    user = args[++i];
                } else if (args[i].equals("-v")) {
                    level++;
                } else if (args[i].equals("-r")) {
                    retryAttempts = Integer.parseInt(args[++i]);
                } else if (args[i].equals("-d")) {
                    retryDelay = Integer.parseInt(args[++i]);
                } else if (args[i].equals("-b")) {
                    batch = true;
                } else if (args[i].equals("-f ")) {
                    file = args[++i];
                } else if (args[i].equals("--help")) {
                    showHelp();
                } else {
                    System.err.println("Unknown option: " + args[i]);
                    System.err.println("Run with --help for usage");
                    System.exit(1);
                }
            } else {
                commandBuilder.append(args[i]);
                commandBuilder.append(' ');
            }
        }
        command = commandBuilder.toString();

        Properties usersCfg = new Properties(new File(System.getProperty("karaf.etc") + "/users.properties"));
        if (!usersCfg.isEmpty()) {
            if (user == null) {
                user = (String) usersCfg.keySet().iterator().next();
            }
            password = (String) usersCfg.getProperty(user);
            if (password != null && password.contains(ROLE_DELIMITER)) {
                password = password.substring(0, password.indexOf(ROLE_DELIMITER));
            }
        }
View Full Code Here

        ParserUtils.addDefaultVariables(vars);
        return vars;
    }

    private static Properties loadConfigSubstitutions(File configSubstitutionsFile) {
        Properties properties = new Properties();
        if (configSubstitutionsFile != null) {
            if (!configSubstitutionsFile.exists()) {
                //write out empty file with instructions as a hint to users.
                storeConfigSubstitutions(configSubstitutionsFile, properties);
            } else {
                try {
                    FileInputStream in = new FileInputStream(configSubstitutionsFile);
                    try {
                        properties.load(in);
                    } finally {
                        in.close();
                    }
                } catch (Exception e) {
                    log.error("Caught exception {} trying to read properties file {}", e, configSubstitutionsFile.getAbsolutePath());
View Full Code Here

TOP

Related Classes of org.apache.felix.utils.properties.Properties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.