Example #1
0
  public static InitAction create(
      File prideDirectory,
      RuntimeConfiguration globalConfig,
      VcsManager vcsManager,
      boolean force,
      boolean addExisting,
      boolean ignoreExistingConfig)
      throws Exception {
    boolean prideExistsAlready = Pride.containsPride(prideDirectory);
    if (prideExistsAlready && !force) {
      throw new PrideException("A pride already exists in " + prideDirectory);
    }

    Configuration existingPrideConfig = new BaseConfiguration();
    Map<String, Module> modulesFromExistingPrideConfig = Collections.emptyMap();

    if (prideExistsAlready && !ignoreExistingConfig) {
      try {
        Pride pride = Pride.getPride(prideDirectory, globalConfig, vcsManager);
        existingPrideConfig = pride.getLocalConfiguration();
        // Get existing modules
        if (addExisting) {
          modulesFromExistingPrideConfig =
              Maps.uniqueIndex(
                  pride.getModules(),
                  new Function<Module, String>() {
                    @Override
                    public String apply(Module module) {
                      return module.getName();
                    }
                  });
        }
      } catch (Exception ex) {
        logger.warn("Could not load existing pride, ignoring existing configuration");
        logger.debug("Exception was", ex);
      }
    }
    return new InitAction(
        prideDirectory,
        globalConfig,
        existingPrideConfig,
        vcsManager,
        modulesFromExistingPrideConfig,
        addExisting);
  }
Example #2
0
  @Override
  protected void initPride(PrideInitializer prideInitializer, Pride pride, boolean verbose)
      throws Exception {
    boolean prideModified = false;
    if (addExisting) {
      logger.debug("Adding existing modules");
      for (File dir :
          pride
              .getRootDirectory()
              .listFiles(
                  new FileFilter() {
                    @Override
                    public boolean accept(File path) {
                      return path.isDirectory();
                    }
                  })) {
        String moduleName = dir.getName();
        Vcs vcs;

        Module existingModule = modulesFromExistingPrideConfig.get(moduleName);
        if (existingModule != null) {
          logger.info("Found existing module from previous configuration: {}", moduleName);
          vcs = existingModule.getVcs();
        } else if (Pride.isValidModuleDirectory(dir)) {
          vcs = vcsManager.findSupportingVcs(dir, globalConfig);
        } else {
          continue;
        }
        logger.info("Adding existing {} module in {}", vcs.getType(), dir);
        pride.addModule(moduleName, vcs);
        prideModified = true;
      }
    }
    if (prideModified) {
      pride.save();
      prideInitializer.reinitialize(pride);
    }
  }