Package org.apache.felix.utils.properties

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


    public BackingEngine build(Map options) {
        PropertiesBackingEngine engine = null;
        String usersFile = (String) options.get(USER_FILE);

        File f = new File(usersFile);
        Properties users;
        try {
            users = new Properties(f);
            EncryptionSupport encryptionSupport = new EncryptionSupport(options);
            engine = new PropertiesBackingEngine(users, encryptionSupport);
        } catch (IOException ioe) {
            LOGGER.warn("Cannot open users file: {}", usersFile);
        } finally {
View Full Code Here


                    }
                } catch (Exception e) {
                    throw (IOException) new IOException(e.getMessage()).initCause(e);
                }
            }
            Properties p = new Properties(storageFile);
            p.clear();
            for (Enumeration keys = properties.keys(); keys.hasMoreElements(); ) {
                Object key = keys.nextElement();
                if (!Constants.SERVICE_PID.equals(key)
                        && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                        && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
                    p.put((String) key, (String) properties.get(key));
                }
            }
            // remove "removed" properties from the file
            ArrayList<String> propertiesToRemove = new ArrayList<String>();
            for (Object key : p.keySet()) {
                if (properties.get(key) == null
                        && !Constants.SERVICE_PID.equals(key)
                        && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                        && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
                    propertiesToRemove.add(key.toString());
                }
            }
            for (String key : propertiesToRemove) {
                p.remove(key);
            }
            // save the cfg file
            storage.mkdirs();
            p.save();
            updateFileInstall(storageFile);
        } else {
            Configuration cfg = configurationAdmin.getConfiguration(pid, null);
            if (cfg.getProperties() == null) {
                String[] pids = parsePid(pid);
View Full Code Here

        @Override
        public void addRepository(URI uri) throws Exception {
            if (dontAddToStartup) {
                getLog().info("Adding feature repository to system: " + uri);
                if (featuresCfgFile.exists()) {
                    Properties properties = new Properties();
                    InputStream in = new FileInputStream(featuresCfgFile);
                    try {
                        properties.load(in);
                    } finally {
                        in.close();
                    }
                    String existingFeatureRepos = retrieveProperty(properties, FEATURES_REPOSITORIES);
                    if (!existingFeatureRepos.contains(uri.toString())) {
                        existingFeatureRepos = existingFeatureRepos + uri.toString();
                        properties.put(FEATURES_REPOSITORIES, existingFeatureRepos);
                    }
                    Features repo = readFeatures(uri);
                    for (String innerRepository : repo.getRepository()) {
                        String innerRepositoryPath = dependencyHelper.pathFromMaven(innerRepository);
                        File innerRepositoryTargetInSystemRepository = new File(system.resolve(innerRepositoryPath));
                        if (!innerRepositoryTargetInSystemRepository.exists()) {
                            File innerRepositorySourceFile = dependencyHelper.resolveById(innerRepository, getLog());
                            innerRepositoryTargetInSystemRepository.getParentFile().mkdirs();
                            copy(innerRepositorySourceFile, innerRepositoryTargetInSystemRepository);

                            // add metadata for snapshot
                            Artifact innerRepositoryArtifact = dependencyHelper.mvnToArtifact(innerRepository);
                            if (innerRepositoryArtifact.isSnapshot()) {
                                getLog().debug("Feature repository " + innerRepository + " is a SNAPSHOT, generate the maven-metadata-local.xml file");
                                File metadataTarget = new File(innerRepositoryTargetInSystemRepository.getParentFile(), "maven-metadata-local.xml");
                                try {
                                    MavenUtil.generateMavenMetadata(innerRepositoryArtifact, metadataTarget);
                                } catch (Exception e) {
                                    getLog().warn("Could not create maven-metadata-local.xml", e);
                                    getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
                                }
                            }
                        }
                    }
                    for (Feature feature : repo.getFeature()) {
                        featureSet.add(feature);
                        if (startupFeatures != null && startupFeatures.contains(feature.getName())) {
                            installFeature(feature, null);
                        } else if (bootFeatures != null && bootFeatures.contains(feature.getName())) {
                            localRepoFeatures.add(feature);
                            missingDependencies.addAll(feature.getDependencies());
                            String existingBootFeatures = retrieveProperty(properties, FEATURES_BOOT);
                            if (!existingBootFeatures.contains(feature.getName())) {
                                existingBootFeatures = existingBootFeatures + feature.getName();
                                properties.put(FEATURES_BOOT, existingBootFeatures);
                            }
                        } else if (installedFeatures != null && installedFeatures.contains(feature.getName())) {
                            localRepoFeatures.add(feature);
                            missingDependencies.addAll(feature.getDependencies());
                        }
                    }
                    if (addTransitiveFeatures) {
                        addMissingDependenciesToRepo();
                    }
                    FileOutputStream out = new FileOutputStream(featuresCfgFile);
                    try {
                        properties.save(out);
                    } finally {
                        out.close();
                    }
                }
            } else {
View Full Code Here

    public static void execute(File file, final RunnableWithProperties callback) 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);
                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) 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);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                props.store(baos, null);
                file.setLength(0);
                file.write(baos.toByteArray());
                return result;
            }
        });
View Full Code Here

        try {
            String karafEtc = bundleContext.getProperty("karaf.etc");
            File etcDir = new File(karafEtc);
            File syspropsFile = new File(etcDir, "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

            return FrameworkType.equinox;
        }
    }

    private Properties loadProps() throws IOException {
        return new Properties(new File(System.getProperty("karaf.etc"), "config.properties"));
    }
View Full Code Here

    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);
        }
    }
View Full Code Here

        }
    }

    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 settting framework debugging: " + e.getMessage(), e);
        }
    }
View Full Code Here

    @Override
    public String setSystemProperty(String key, String value, boolean persist) {
        if (persist) {
            try {
                String etc = System.getProperty("karaf.etc");
                Properties props = new Properties(new File(etc, "system.properties"));
                props.put(key, value);
                props.save();
            } catch (IOException e) {
                throw new RuntimeException("Error persisting system property", e);
            }
        }
        return System.setProperty(key, value);
View Full Code Here

TOP

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

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.