public static void startRepository()

in src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java [63:110]


    public static void startRepository() throws RepositoryException {
        if ( adminSession == null ) {
            // copy the repository configuration file to the repository HOME_DIR
            InputStream ins = RepositoryUtil.class.getClassLoader().getResourceAsStream(
                CONFIG_FILE);
            if (ins == null) {
                throw new RepositoryException("Cannot get " + CONFIG_FILE);
            }

            File configFile = new File(HOME_DIR, "repository.xml");
            configFile.getParentFile().mkdirs();

            FileOutputStream out = null;
            try {
                out = new FileOutputStream(configFile);
                byte[] buf = new byte[1024];
                int rd;
                while ((rd = ins.read(buf)) >= 0) {
                    out.write(buf, 0, rd);
                }
            } catch (IOException ioe) {
                throw new RepositoryException("Cannot copy configuration file to "
                    + configFile);
            } finally {
                try {
                    ins.close();
                } catch (IOException ignore) {
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException ignore) {
                    }
                }
            }

            // somewhat dirty hack to have the derby.log file in a sensible
            // location, but don't overwrite anything already set
            if (System.getProperty("derby.stream.error.file") == null) {
                String derbyLog = HOME_DIR + "/derby.log";
                System.setProperty("derby.stream.error.file", derbyLog);
            }

            final File f = new File(HOME_DIR);
            repository = new RepositoryWrapper(JcrUtils.getRepository(f.toURI().toString()));
            adminSession = repository.loginAdministrative(null);
        }
    }