Exemplo n.º 1
0
  public IPath createNewProject(
      String projectName,
      ArrayList<String> arguments,
      String type,
      String workingDir,
      IProgressMonitor monitor)
      throws CoreException {
    CreateHelper createHelper = new CreateHelper(this, monitor);

    final IPath pluginFolder = getLocation().append(getPluginFolder(type));

    final IPath newPath = pluginFolder.append(projectName + getPluginSuffix(type));

    String createScript = ISDKConstants.CREATE_BAT;

    if (!CoreUtil.isWindows()) {
      createScript = ISDKConstants.CREATE_SH;
    }

    final IPath createFilePath = pluginFolder.append(createScript);

    final File createFile = createFilePath.toFile();

    String originalCreateConetent = "";

    if (!CoreUtil.isWindows() && createFile.exists()) {
      originalCreateConetent = FileUtil.readContents(createFile, true);

      if (originalCreateConetent.contains("DisplayName=\\\"$2\\\"")) {
        String createContent =
            originalCreateConetent.replace("DisplayName=\\\"$2\\\"", "DisplayName=\"$2\"");

        try {
          FileUtil.writeFile(
              createFile,
              new ByteArrayInputStream(createContent.toString().getBytes("UTF-8")),
              null);
        } catch (Exception e) {
          SDKCorePlugin.logError(e);
        }
      }
    }

    createHelper.runTarget(createFilePath, arguments, workingDir);

    if (!newPath.toFile().exists()) {
      throw new CoreException(
          SDKCorePlugin.createErrorStatus("Create script did not complete successfully."));
    }

    if (!CoreUtil.isNullOrEmpty(originalCreateConetent)) {
      try {
        FileUtil.writeFile(
            createFile,
            new ByteArrayInputStream(originalCreateConetent.toString().getBytes("UTF-8")),
            null);
      } catch (Exception e) {
        SDKCorePlugin.logError(e);
      }
    }

    return newPath;
  }