RepositoryIndexManager(JcrRepository.RunningState repository, RepositoryConfiguration config) {
    this.repository = repository;
    this.config = config;
    this.context = repository.context();
    this.systemWorkspaceName = this.repository.repositoryCache().getSystemWorkspaceName();

    PathFactory pathFactory = this.context.getValueFactories().getPathFactory();
    this.indexesPath = pathFactory.createAbsolutePath(JcrLexicon.SYSTEM, ModeShapeLexicon.INDEXES);

    // Set up the index providers ...
    this.components = config.getIndexProviders();
    for (Component component : components) {
      try {
        IndexProvider provider =
            component.createInstance(ScanningQueryEngine.class.getClassLoader());
        register(provider);
      } catch (Throwable t) {
        if (t.getCause() != null) {
          t = t.getCause();
        }
        this.repository.error(
            t,
            JcrI18n.unableToInitializeIndexProvider,
            component,
            repository.name(),
            t.getMessage());
      }
    }
  }
 @Override
 protected void startRepositoryWithConfiguration(InputStream configInputStream) throws Exception {
   stopRepository();
   RepositoryConfiguration config =
       RepositoryConfiguration.read(configInputStream, REPO_NAME).with(new TestingEnvironment());
   Problems problems = config.validate();
   if (problems.hasProblems()) {
     System.out.println(problems);
     fail("Problems encountered during repository startup: " + problems);
   }
   repository = new JcrRepository(config);
   repository.start();
   session = repository.login();
   rootNode = session.getRootNode();
   addSequencingListeners(session);
 }
  @Test
  public void shouldBackupRepositoryWithMultipleWorkspaces() throws Exception {
    loadContent();
    Problems problems =
        session().getWorkspace().getRepositoryManager().backupRepository(backupDirectory);
    assertNoProblems(problems);

    // Make some changes that will not be in the backup ...
    session().getRootNode().addNode("node-not-in-backup");
    session().save();

    assertContentInWorkspace(repository(), "default", "/node-not-in-backup");
    assertContentInWorkspace(repository(), "ws2");
    assertContentInWorkspace(repository(), "ws3");

    // Start up a new repository
    ((LocalEnvironment) environment).setShared(true);
    RepositoryConfiguration config =
        RepositoryConfiguration.read("config/restore-repo-config.json").with(environment);
    JcrRepository newRepository = new JcrRepository(config);
    try {
      newRepository.start();

      // And restore it from the contents ...
      JcrSession newSession = newRepository.login();
      try {
        Problems restoreProblems =
            newSession.getWorkspace().getRepositoryManager().restoreRepository(backupDirectory);
        assertNoProblems(restoreProblems);
      } finally {
        newSession.logout();
      }

      // Check that the node that was added *after* the backup is not there ...
      assertContentNotInWorkspace(newRepository, "default", "/node-not-in-backup");

      // Before we assert the content, create a backup of it (for comparison purposes when
      // debugging) ...
      newSession = newRepository.login();
      try {
        Problems backupProblems =
            newSession.getWorkspace().getRepositoryManager().backupRepository(backupDirectory2);
        assertNoProblems(backupProblems);
      } finally {
        newSession.logout();
      }

      assertWorkspaces(newRepository, "default", "ws2", "ws3");

      assertContentInWorkspace(newRepository, null);
      assertContentInWorkspace(newRepository, "ws2");
      assertContentInWorkspace(newRepository, "ws3");
      queryContentInWorkspace(newRepository, null);
    } finally {
      newRepository.shutdown().get(10, TimeUnit.SECONDS);
    }
  }
  private static List<RemoteRepository> createRepositories(
      List<RepositoryConfiguration> repositoryConfigurations) {
    List<RemoteRepository> repositories =
        new ArrayList<RemoteRepository>(repositoryConfigurations.size());
    for (RepositoryConfiguration repositoryConfiguration : repositoryConfigurations) {
      RemoteRepository.Builder builder =
          new RemoteRepository.Builder(
              repositoryConfiguration.getName(),
              "default",
              repositoryConfiguration.getUri().toASCIIString());

      if (!repositoryConfiguration.getSnapshotsEnabled()) {
        builder.setSnapshotPolicy(
            new RepositoryPolicy(
                false,
                RepositoryPolicy.UPDATE_POLICY_NEVER,
                RepositoryPolicy.CHECKSUM_POLICY_IGNORE));
      }
      repositories.add(builder.build());
    }
    return repositories;
  }
  /**
   * Loads the repository interface contained in the given {@link RepositoryConfiguration} using the
   * given {@link ResourceLoader}.
   *
   * @param configuration must not be {@literal null}.
   * @param loader must not be {@literal null}.
   * @return the repository interface or {@literal null} if it can't be loaded.
   */
  private Class<?> loadRepositoryInterface(
      RepositoryConfiguration<?> configuration, ResourceLoader loader) {

    String repositoryInterface = configuration.getRepositoryInterface();
    ClassLoader classLoader = loader.getClassLoader();

    try {
      return org.springframework.util.ClassUtils.forName(repositoryInterface, classLoader);
    } catch (ClassNotFoundException e) {
      LOGGER.warn(
          String.format(CLASS_LOADING_ERROR, getModuleName(), repositoryInterface, classLoader), e);
    } catch (LinkageError e) {
      LOGGER.warn(
          String.format(CLASS_LOADING_ERROR, getModuleName(), repositoryInterface, classLoader), e);
    }

    return null;
  }
  protected RepositoryConfiguration createRepositoryConfiguration() {
    RepositoryConfiguration repoConfig =
        new RepositoryConfiguration(
            getConfigurationName(getName()),
            getProductionConfigManager(getName()),
            RepositoryType.PRODUCTION);

    repoConfig.setName(getName());
    repoConfig.setType(getType());
    repoConfig.setPath(getPath());

    if (this.isSecure()) {
      repoConfig.setLogin(getLogin());
      repoConfig.setPassword(getPassword());
    }

    repoConfig.commit();
    return repoConfig;
  }
 synchronized void importIndexDefinitions() throws RepositoryException {
   RepositoryConfiguration.Indexes indexes = config.getIndexes();
   if (indexes.isEmpty()) return;
   List<IndexDefinition> defns = new ArrayList<>();
   for (String indexName : indexes.getIndexNames()) {
     IndexDefinition defn = indexes.getIndex(indexName);
     if (defn != null) defns.add(defn);
   }
   if (!defns.isEmpty()) {
     IndexDefinition[] array = defns.toArray(new IndexDefinition[defns.size()]);
     registerIndexes(array, true);
     // Wait while the indexes get created ...
     try {
       Thread.sleep(500L + array.length * 50L);
     } catch (Exception e) {
       throw new SystemFailureException(e);
     }
     // We have to index the '/jcr:system' content, since it was created before these indexes were
     // registered ...
     repository.queryManager().reindexSystemContent();
   }
 }
  protected RepositoryConfiguration createAdminRepositoryConfiguration() {
    RepositoryConfiguration repoConfig =
        new RepositoryConfiguration(
            this.getName(), getProductionConfigManager(getName()), RepositoryType.PRODUCTION);

    repoConfig.setName(getName());
    repoConfig.setType(getType());
    repoConfig.setPath(getPath());

    if (this.isSecure()) {
      /*Default Admin credentials for creating new admin user in repo*/
      repoConfig.setLogin("admin");
      repoConfig.setPassword("admin");
    }

    return repoConfig;
  }
 @Override
 protected RepositoryConfiguration createRepositoryConfiguration(
     String repositoryName, Environment environment) throws Exception {
   return RepositoryConfiguration.read("config/backup-repo-config.json").with(environment);
 }
  public static synchronized void readRepositoryConfigurationFile() {

    // IPath configFile = getProductConfigurationCachePath();
    if (cacheFileRead
        || repositoryConfigurationFile == null
        || !repositoryConfigurationFile.exists()) {
      return;
    }

    synchronized (repositoryConfigurations) {
      ObjectInputStream in = null;
      try {
        in = new ObjectInputStream(new FileInputStream(repositoryConfigurationFile));
        int size = in.readInt();
        for (int nX = 0; nX < size; nX++) {
          RepositoryConfiguration item = (RepositoryConfiguration) in.readObject();
          if (item != null) {
            repositoryConfigurations.put(item.getRepositoryUrl(), item);
          }
        }
      } catch (Exception e) {
        log(
            new Status(
                IStatus.INFO, TargetProcessCorePlugin.ID_PLUGIN, ERROR_INCOMPATIBLE_CONFIGURATION));
        try {
          if (in != null) {
            in.close();
          }
          if (repositoryConfigurationFile != null && repositoryConfigurationFile.exists()) {
            if (repositoryConfigurationFile.delete()) {
              // successfully deleted
            } else {
              log(
                  new Status(
                      IStatus.ERROR,
                      TargetProcessCorePlugin.ID_PLUGIN,
                      0,
                      ERROR_DELETING_CONFIGURATION,
                      e));
            }
          }

        } catch (Exception ex) {
          log(
              new Status(
                  IStatus.ERROR,
                  TargetProcessCorePlugin.ID_PLUGIN,
                  0,
                  ERROR_DELETING_CONFIGURATION,
                  e));
        }
      } finally {
        cacheFileRead = true;
        if (in != null) {
          try {
            in.close();
          } catch (IOException e) {
            // ignore
          }
        }
      }
    }
  }
 private static void internalAddConfiguration(RepositoryConfiguration config) {
   repositoryConfigurations.remove(config.getRepositoryUrl());
   repositoryConfigurations.put(config.getRepositoryUrl(), config);
 }