private String buildCommandString(ProjectInfo info) throws PhrescoException {
    if (isDebugEnabled) {
      S_LOGGER.debug("Entering Method ArchetypeExecutorImpl.buildCommandString(ProjectInfo info)");
      S_LOGGER.debug("buildCommandString() ProjectCode=" + info.getCode());
    }

    ArchetypeInfo archInfo = PhrescoServerFactory.getRepositoryManager().getArchetype(info);
    if (archInfo == null) {
      throw new PhrescoException("Archetype not defined for " + info.getTechnology().getName());
    }

    // For Thread-Safe,using StringBuffer instead of StringBuilder
    StringBuffer commandStr = new StringBuffer();

    commandStr
        .append(Constants.MVN_COMMAND)
        .append(STR_BLANK_SPACE)
        .append(Constants.MVN_ARCHETYPE)
        .append(STR_COLON)
        .append(Constants.MVN_GOAL_GENERATE)
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_ARCHETYPEGROUPID)
        .append(STR_EQUALS)
        .append(archInfo.getGroupId())
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_ARCHETYPEARTIFACTID)
        .append(STR_EQUALS)
        .append(archInfo.getArtifactId())
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_ARCHETYPEVERSION)
        .append(STR_EQUALS)
        .append(archInfo.getVersion())
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_GROUPID)
        .append(STR_EQUALS)
        .append(archInfo.getProjectGroupId())
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_ARTIFACTID)
        .append(STR_EQUALS)
        .append(STR_DOUBLE_QUOTES)
        .append(info.getCode())
        .append(STR_DOUBLE_QUOTES) // artifactId --> project name could have space in between
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_VERSION)
        .append(STR_EQUALS)
        .append(info.getVersion())
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_ARCHETYPEREPOSITORYURL)
        .append(STR_EQUALS)
        .append(serverConfig.getRepositoryURL())
        .append(STR_BLANK_SPACE)
        .append(ARCHETYPE_INTERACTIVEMODE)
        .append(STR_EQUALS)
        .append(INTERACTIVE_MODE);

    return commandStr.toString();
  }
  public File execute(ProjectInfo info) throws PhrescoException {
    if (isDebugEnabled) {
      S_LOGGER.debug("Entering Method ArchetypeExecutorImpl.execute(ProjectInfo info)");
      S_LOGGER.debug("execute() ProjectCode=" + info.getCode());
    }
    String commandString = buildCommandString(info);

    Commandline cl = new Commandline(commandString);
    cl.setWorkingDirectory(getTempFolderPath());

    if (S_LOGGER.isDebugEnabled()) {
      S_LOGGER.debug("command String " + commandString);
    }

    try {
      Process p = cl.execute();

      // the below implementation is required since a new command or shell is forked
      // from the existing running web server command or shell instance
      BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
      while (in.readLine() != null) {}
      createProjectFolders(info, cl.getWorkingDirectory());
    } catch (CommandLineException e) {
      throw new PhrescoException(e);
    } catch (IOException e) {
      throw new PhrescoException(e);
    }
    return cl.getWorkingDirectory();
  }
 private void createProjectFolders(ProjectInfo info, File file) throws PhrescoException {
   if (isDebugEnabled) {
     S_LOGGER.debug(
         "Entering Method ArchetypeExecutorImpl.createProjectFolders(ProjectInfo info, File file)");
     S_LOGGER.debug("createProjectFolders()  path=" + file.getPath());
   }
   // create .phresco folder inside the project
   if (isDebugEnabled) {
     S_LOGGER.debug("createProjectFolders()  ProjectCode=" + info.getCode());
   }
   File phrescoFolder =
       new File(
           file.getPath() + File.separator + info.getCode() + File.separator + DOT_PHRESCO_FOLDER);
   phrescoFolder.mkdirs();
   if (isDebugEnabled) {
     S_LOGGER.info("create .phresco folder inside the project");
   }
   ProjectUtils.writeProjectInfo(info, phrescoFolder);
 }
示例#4
0
  @Override
  public void directoryWalkStep(int percentage, File file) {

    BufferedReader reader = null;
    Gson gson = new Gson();
    try {
      if (file.getName().equals("project.info")) {
        reader = new BufferedReader(new FileReader(file));
        String content = reader.readLine();
        ProjectInfo projInfo = gson.fromJson(content, ProjectInfo.class);
        String code = projInfo.getCode();
        if (!code.equals(file.getParentFile().getParentFile().getName())) {
          invalidProjects.add(code);
        }
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 public ClientResponse updateDocumentProject(ProjectInfo info) throws PhrescoException {
   if (debugEnabled) {
     S_LOGGER.debug("Entering Method ServiceManagerImpl.updateProject(ProjectInfo info)");
   }
   Client client = ClientHelper.createClient();
   FrameworkConfiguration configuration = PhrescoFrameworkFactory.getFrameworkConfig();
   WebResource resource =
       client.resource(
           configuration.getServerPath() + FrameworkConstants.REST_APPS_UPDATEDOC_PATH);
   resource.accept(MediaType.APPLICATION_OCTET_STREAM);
   if (debugEnabled) {
     S_LOGGER.debug("updateDocumentProject() ProjectName = " + info.getName());
   }
   ClientResponse response =
       resource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, info);
   return response;
 }
 public ClientResponse createProject(ProjectInfo info, User userInfo) throws PhrescoException {
   if (debugEnabled) {
     S_LOGGER.debug("Entering Method ServiceManagerImpl.createProject(ProjectInfo info)");
   }
   Client client = ClientHelper.createClient();
   FrameworkConfiguration configuration = PhrescoFrameworkFactory.getFrameworkConfig();
   WebResource resource =
       client.resource(configuration.getServerPath() + FrameworkConstants.REST_APPS_PATH);
   resource.accept(MediaType.APPLICATION_OCTET_STREAM);
   if (debugEnabled) {
     S_LOGGER.debug("createProject() ProjectName = " + info.getName());
   }
   ClientResponse response =
       resource
           .header(Constants.AUTH_TOKEN, userInfo.getToken())
           .type(MediaType.APPLICATION_JSON)
           .post(ClientResponse.class, info);
   //        reSetCacheAppTypes();
   return response;
 }