Ejemplo n.º 1
0
  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    try {
      if (!project.isExecutionRoot()) {
        getLog().info("Not the execution root so ignoring this project");
        return;
      }
      buildDir.mkdirs();

      for (MavenProject reactorProject : reactorProjects) {
        // ignore the execution root which just aggregates stuff
        if (!reactorProject.isExecutionRoot()) {
          combineProfilesTo(reactorProject, buildDir);
        }
      }
      Zips.createZipFile(getLog(), buildDir, outputFile);

      projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputFile);

      String relativePath = Files.getRelativePath(project.getBasedir(), outputFile);
      while (relativePath.startsWith("/")) {
        relativePath = relativePath.substring(1);
      }
      getLog().info("Created profile zip file: " + relativePath);
    } catch (MojoExecutionException e) {
      throw e;
    } catch (Exception e) {
      throw new MojoExecutionException("Error executing", e);
    }
  }
 @Override
 public ProjectReactor bootstrap() {
   // Don't use session.getTopLevelProject or session.getProjects to keep compatibility with Maven
   // 2
   List<MavenProject> sortedProjects = session.getSortedProjects();
   MavenProject topLevelProject = null;
   for (MavenProject project : sortedProjects) {
     if (project.isExecutionRoot()) {
       topLevelProject = project;
       break;
     }
   }
   if (topLevelProject == null) {
     throw new IllegalStateException("Maven session does not declare a top level project");
   }
   return new ProjectReactor(mavenProjectConverter.configure(sortedProjects, topLevelProject));
 }
Ejemplo n.º 3
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);
  }