Exemplo n.º 1
0
 /** Combines any files from the appSourceDir into the output directory */
 public static void appendAppConfigFiles(File appSourceDir, File outputDir) throws IOException {
   if (appSourceDir.exists() && appSourceDir.isDirectory()) {
     File[] files = appSourceDir.listFiles();
     if (files != null) {
       outputDir.mkdirs();
       for (File file : files) {
         File outFile = new File(outputDir, file.getName());
         if (file.isDirectory()) {
           appendAppConfigFiles(file, outFile);
         } else {
           if (outFile.exists() && file.getName().endsWith(".properties")) {
             System.out.println("Combining properties: file " + file.getAbsolutePath());
             combinePropertiesFiles(file, outFile);
           } else {
             System.out.println("Copying file " + file.getAbsolutePath());
             Files.copy(file, outFile);
           }
         }
       }
     }
   }
 }
Exemplo n.º 2
0
  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (isIgnoreProject()) return;

    try {
      boolean newUserAdded = false;

      fabricServer = mavenSettings.getServer(serverId);

      if (Strings.isNullOrBlank(consoleUrl)) {
        consoleUrl = DEFAULT_CONSOLE_URL;
      }

      // we may have username and password from consoleUrl
      String jolokiaUsername = null;
      String jolokiaPassword = null;
      try {
        URL url = new URL(consoleUrl);
        String s = url.getUserInfo();
        if (Strings.isNotBlank(s) && s.indexOf(':') > 0) {
          int idx = s.indexOf(':');
          jolokiaUsername = s.substring(0, idx);
          jolokiaPassword = s.substring(idx + 1);
        }
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Option consoleUrl is invalid due " + e.getMessage());
      }

      // jolokia url overrides username/password configured in maven settings
      if (jolokiaUsername != null) {
        if (fabricServer == null) {
          fabricServer = new Server();
        }
        getLog()
            .info(
                "Using username: "******" and password from provided consoleUrl option");
        fabricServer.setUsername(jolokiaUsername);
        fabricServer.setPassword(jolokiaPassword);
      }

      if (fabricServer == null) {
        boolean create = false;
        if (mavenSettings.isInteractiveMode() && mavenSettingsWriter != null) {
          System.out.println("Maven settings file: " + mavenSettingsFile.getAbsolutePath());
          System.out.println();
          System.out.println();
          System.out.println(
              "There is no <server> section in your ~/.m2/settings.xml file for the server id: "
                  + serverId);
          System.out.println();
          System.out.println(
              "You can enter the username/password now and have the settings.xml updated or you can do this by hand if you prefer.");
          System.out.println();
          while (true) {
            String value =
                readInput("Would you like to update the settings.xml file now? (y/n): ")
                    .toLowerCase();
            if (value.startsWith("n")) {
              System.out.println();
              System.out.println();
              break;
            } else if (value.startsWith("y")) {
              create = true;
              break;
            }
          }
          if (create) {
            System.out.println("Please let us know the login details for this server: " + serverId);
            System.out.println();
            String userName = readInput("Username: "******"Password: "******"Repeat Password: "******"Passwords do not match, please try again.");
              password = readPassword("Password: "******"Repeat Password: "******".backup-" + counter++ + ".xml");
                if (!backupFile.exists()) {
                  System.out.println(
                      "Copied original: "
                          + mavenSettingsFile.getAbsolutePath()
                          + " to: "
                          + backupFile.getAbsolutePath());
                  Files.copy(mavenSettingsFile, backupFile);
                  break;
                }
              }
            }
            Map<String, Object> config = new HashMap<String, Object>();
            mavenSettingsWriter.write(mavenSettingsFile, config, mavenSettings);
            System.out.println("Updated settings file: " + mavenSettingsFile.getAbsolutePath());
            System.out.println();

            newUserAdded = true;
          }
        }
      }
      if (fabricServer == null) {
        String message =
            "No <server> element can be found in ~/.m2/settings.xml for the server <id>"
                + serverId
                + "</id> so we cannot connect to fabric8!\n\n"
                + "Please add the following to your ~/.m2/settings.xml file (using the correct user/password values):\n\n"
                + "<servers>\n"
                + "  <server>\n"
                + "    <id>"
                + serverId
                + "</id>\n"
                + "    <username>admin</username>\n"
                + "    <password>admin</password>\n"
                + "  </server>\n"
                + "</servers>\n";
        getLog().error(message);
        throw new MojoExecutionException(message);
      }

      if (!isIgnoreProject()) {
        uploadAppZip(newUserAdded);
      } else {
        getLog().info("Ignoring this project so not uploading the App Zip");
      }
    } catch (MojoExecutionException e) {
      throw e;
    } catch (Exception e) {
      throw new MojoExecutionException("Error executing", e);
    }
  }
Exemplo n.º 3
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);
    }
  }