@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);
    }
  }
Beispiel #2
0
 protected void addZipFile(File file) throws MojoExecutionException, IOException, GitAPIException {
   if (file == null || !file.exists() || !file.isFile()) {
     throw new MojoExecutionException("Zip file does not exist: " + file);
   }
   File unzipDir = new File(buildDir, "fabric/profiles");
   unzipDir.mkdirs();
   try {
     Zips.unzip(new FileInputStream(file), unzipDir);
   } catch (IOException e) {
     throw new MojoExecutionException(
         "Failed to unzip file "
             + file.getCanonicalPath()
             + " to "
             + getGitBuildPathDescription()
             + ". "
             + e,
         e);
   }
 }
Beispiel #3
0
  private static Collection<String> extract(final String zip) throws IOException {
    final File tmp = new File(SystemInstance.get().getBase().getDirectory(), TEMP_DIR);
    if (!tmp.exists()) {
      try {
        Files.mkdirs(tmp);
      } catch (Files.FileRuntimeException fre) {
        // ignored
      }
    }

    final File zipFile = new File(realLocation(zip));
    final File extracted = new File(tmp, zipFile.getName().replace(".zip", ""));
    if (extracted.exists()) {
      return list(extracted);
    } else {
      Files.mkdirs(extracted);
    }

    Zips.unzip(zipFile, extracted);
    return list(extracted);
  }
Beispiel #4
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);
  }
Beispiel #5
0
  protected void generateZip()
      throws DependencyTreeBuilderException, MojoExecutionException, IOException,
          MojoFailureException {

    File appBuildDir = buildDir;
    if (Strings.isNotBlank(pathInZip)) {
      appBuildDir = new File(buildDir, pathInZip);
    }
    appBuildDir.mkdirs();

    if (hasConfigDir()) {
      copyAppConfigFiles(appBuildDir, appConfigDir);

    } else {
      getLog()
          .info(
              "The app configuration files directory "
                  + appConfigDir
                  + " doesn't exist, so not copying any additional project documentation or configuration files");
    }
    MavenProject project = getProject();

    if (!ignoreProject) {
      File kubernetesJson = getKubernetesJson();
      if (kubernetesJson != null && kubernetesJson.isFile() && kubernetesJson.exists()) {
        File jsonFile = new File(appBuildDir, "kubernetes.json");
        jsonFile.getParentFile().mkdirs();
        Files.copy(kubernetesJson, jsonFile);
      }

      // TODO if no iconRef is specified we could try guess based on the project?

      // lets check if we can use an icon reference
      copyIconToFolder(appBuildDir);
    }

    // lets only generate a app zip if we have a requirement (e.g. we're not a parent pom packaging
    // project) and
    // we have defined some configuration files or dependencies
    // to avoid generating dummy apps for parent poms
    if (hasConfigDir() || !ignoreProject) {

      if (includeReadMe) {
        copyReadMe(appBuildDir);
      }

      if (generateSummaryFile) {
        copySummaryText(appBuildDir);
      }

      if (generateAppPropertiesFile) {
        String name = project.getName();
        if (Strings.isNullOrBlank(name)) {
          name = project.getArtifactId();
        }
        String description = project.getDescription();
        Properties appProperties = new Properties();
        appProperties.put("name", name);
        if (Strings.isNotBlank(description)) {
          appProperties.put("description", description);
        }
        appProperties.put("groupId", project.getGroupId());
        appProperties.put("artifactId", project.getArtifactId());
        appProperties.put("version", project.getVersion());
        File appPropertiesFile = new File(appBuildDir, "fabric8.properties");
        appPropertiesFile.getParentFile().mkdirs();
        if (!appPropertiesFile.exists()) {
          appProperties.store(new FileWriter(appPropertiesFile), "Fabric8 Properties");
        }
      }

      File outputZipFile = getZipFile();
      File legalDir = null;
      if (includeLegal) {
        legalDir = new File(project.getBuild().getOutputDirectory(), "META-INF");
      }
      Zips.createZipFile(getLog(), buildDir, outputZipFile, legalDir);

      projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputZipFile);
      getLog().info("Created app zip file: " + outputZipFile);
    }
  }