Пример #1
0
  protected void createAggregatedZip(
      File projectBaseDir,
      File projectBuildDir,
      String reactorProjectOutputPath,
      File projectOutputFile,
      boolean includeReadMe,
      Set<MavenProject> pomZipProjects)
      throws IOException {
    projectBuildDir.mkdirs();

    for (MavenProject reactorProject : pomZipProjects) {
      // ignoreProject the execution root which just aggregates stuff
      if (!reactorProject.isExecutionRoot()) {
        Log log = getLog();

        // TODO allow the project nesting to be defined via a property?
        String relativePath = getChildProjectRelativePath(projectBaseDir, reactorProject);
        File outDir = new File(projectBuildDir, relativePath);
        combineAppFilesToFolder(reactorProject, outDir, log, reactorProjectOutputPath);
      }
    }

    // we may want to include readme files for pom projects
    if (includeReadMe) {

      Map<String, File> pomNames = new HashMap<String, File>();

      for (MavenProject pomProject : pomZipProjects) {
        File src = pomProject.getFile().getParentFile();
        String relativePath = getChildProjectRelativePath(projectBaseDir, pomProject);
        File outDir = new File(projectBuildDir, relativePath);
        File copiedFile = copyReadMe(src, outDir);

        if (copiedFile != null) {
          String key = getReadMeFileKey(relativePath);
          pomNames.put(key, copiedFile);
        }
      }

      if (replaceReadmeLinksPrefix != null) {

        // now parse each readme file and replace github links
        for (Map.Entry<String, File> entry : pomNames.entrySet()) {
          File file = entry.getValue();
          String key = entry.getKey();

          boolean changed = false;
          List<String> lines = Files.readLines(file);
          for (int i = 0; i < lines.size(); i++) {
            String line = lines.get(i);
            String newLine = replaceGithubLinks(pomNames.keySet(), key, line);
            if (newLine != null) {
              lines.set(i, newLine);
              changed = true;
            }
          }
          if (changed) {
            Files.writeLines(file, lines);
            getLog().info("Replaced github links to fabric apps in reaadme file: " + file);
          }
        }
      }
    }

    Zips.createZipFile(getLog(), projectBuildDir, projectOutputFile, null);
    String relativePath = Files.getRelativePath(projectBaseDir, projectOutputFile);
    while (relativePath.startsWith("/")) {
      relativePath = relativePath.substring(1);
    }
    getLog().info("Created app zip file: " + relativePath);
  }