Exemple #1
1
 private String getCIJobPath(ApplicationInfo appInfo) {
   StringBuilder builder = new StringBuilder(Utility.getProjectHome());
   builder.append(appInfo.getAppDirName());
   builder.append(File.separator);
   builder.append(FOLDER_DOT_PHRESCO);
   builder.append(File.separator);
   builder.append(CI_JOB_INFO_NAME);
   return builder.toString();
 }
 @PUT
 @Path("/testcases")
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
 public Response updateTestCase(
     com.photon.phresco.commons.model.TestCase testCase,
     @QueryParam("testSuiteName") String testSuiteName,
     @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
     @QueryParam(REST_QUERY_MODULE_NAME) String moduleName)
     throws PhrescoException {
   ResponseInfo responseData = new ResponseInfo();
   try {
     String rootModulePath = "";
     String subModuleName = "";
     if (StringUtils.isNotEmpty(moduleName)) {
       rootModulePath = Utility.getProjectHome() + appDirName;
       subModuleName = moduleName;
     } else {
       rootModulePath = Utility.getProjectHome() + appDirName;
     }
     FrameworkUtil frameworkUtil = FrameworkUtil.getInstance();
     ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName);
     File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName);
     String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName);
     StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir);
     frameworkUtil.readManualTestCaseFile(sb.toString(), testSuiteName, testCase);
     ResponseInfo finalOutput =
         responseDataEvaluation(responseData, null, testCase, RESPONSE_STATUS_SUCCESS, PHRQ400006);
     return Response.status(Status.OK).entity(finalOutput).build();
   } catch (PhrescoException e) {
     ResponseInfo finalOutput =
         responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410008);
     return Response.status(Status.OK).entity(finalOutput).build();
   }
 }
 @POST
 @Path(REST_API_TESTSUITES)
 @Produces(MediaType.APPLICATION_JSON)
 public Response createTestSuite(
     @QueryParam(REST_API_TESTSUITE) String testSuiteName,
     @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
     @QueryParam(REST_QUERY_MODULE_NAME) String moduleName)
     throws PhrescoException {
   ResponseInfo responseData = new ResponseInfo();
   try {
     String rootModulePath = "";
     String subModuleName = "";
     if (StringUtils.isNotEmpty(moduleName)) {
       rootModulePath = Utility.getProjectHome() + appDirName;
       subModuleName = moduleName;
     } else {
       rootModulePath = Utility.getProjectHome() + appDirName;
     }
     FrameworkUtil frameworkUtil = FrameworkUtil.getInstance();
     ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName);
     File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName);
     String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName);
     StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir);
     String cellValue[] = {"", "", testSuiteName, "", "", "", "", "", "", "", "", "", ""};
     frameworkUtil.addNew(sb.toString(), testSuiteName, cellValue);
     ResponseInfo finalOutput =
         responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_SUCCESS, PHRQ400004);
     return Response.status(Status.OK).entity(finalOutput).build();
   } catch (PhrescoException e) {
     e.printStackTrace();
     ResponseInfo finalOutput =
         responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410006);
     return Response.status(Status.OK).entity(finalOutput).build();
   }
 }
  @Override
  public PossibleValues getValues(Map<String, Object> map)
      throws IOException, ParserConfigurationException, SAXException, ConfigurationException,
          PhrescoException {
    String rootModulePath = "";
    String subModuleName = "";
    PossibleValues possibleValues = new PossibleValues();
    ApplicationInfo applicationInfo = (ApplicationInfo) map.get(KEY_APP_INFO);
    String rootModule = (String) map.get(KEY_ROOT_MODULE);
    if (StringUtils.isNotEmpty(rootModule)) {
      rootModulePath = Utility.getProjectHome() + rootModule;
      subModuleName = applicationInfo.getAppDirName();
    } else {
      rootModulePath = Utility.getProjectHome() + applicationInfo.getAppDirName();
    }

    String buildInfoPath = getBuildInfoPath(rootModulePath, subModuleName).toString();
    List<BuildInfo> buildInfos = Utility.getBuildInfos(new File(buildInfoPath));
    if (buildInfos != null) {
      for (BuildInfo buildInfo : buildInfos) {
        Value value = new Value();
        value.setValue(Integer.toString(buildInfo.getBuildNo()));
        String dependency = getDependency(buildInfo.getBuildNo(), rootModulePath, subModuleName);
        if (!StringUtils.isEmpty(dependency)) {
          value.setDependency(dependency);
        }
        possibleValues.getValue().add(value);
      }
    }
    return possibleValues;
  }
 @Override
 public void postFeatureConfiguration(
     ApplicationInfo appInfo, List<Configuration> configs, String featureName)
     throws PhrescoException {
   try {
     String propertyValue = getPropertyValue(appInfo, Constants.POM_PROP_KEY_SQL_FILE_DIR);
     File featureManifest =
         new File(
             Utility.getProjectHome()
                 + appInfo.getAppDirName()
                 + getThirdPartyFolder(appInfo)
                 + File.separator
                 + featureName
                 + File.separator
                 + XML);
     File featureSqlDir =
         new File(Utility.getProjectHome() + appInfo.getAppDirName() + propertyValue);
     if (CollectionUtils.isNotEmpty(configs)) {
       String envName = configs.get(0).getEnvName();
       storeConfigObj(configs, featureManifest, featureSqlDir, envName);
     }
   } catch (Exception e) {
     throw new PhrescoException(e);
   }
 }
Exemple #6
0
  private void saveFile(String tech) throws PhrescoException {
    try {
      InputStream inputStream = null;
      URL url = new URL(getRepositoryUrl() + tech);
      URLConnection connection = url.openConnection();
      inputStream = connection.getInputStream();
      int index = tech.lastIndexOf(SEPERATOR);
      String fileName = tech.substring(index + 1);
      File imageFile = new File(BACK_FOLDER + WEB_APPS_FOLDER + serverContext + IMAGES_FOLDER);
      if (!imageFile.exists()) {
        imageFile.mkdirs();
      }
      FileOutputStream fileOutputStream = null;
      File archiveFile = new File(imageFile, fileName);
      fileOutputStream = new FileOutputStream(archiveFile);
      try {
        byte[] data = new byte[1024];
        int i = 0;
        while ((i = inputStream.read(data)) != -1) {
          fileOutputStream.write(data, 0, i);
        }
        fileOutputStream.flush();
        ArchiveUtil.extractArchive(archiveFile.getPath(), imageFile.getPath(), ArchiveType.ZIP);
      } finally {
        Utility.closeStream(inputStream);
        Utility.closeStream(fileOutputStream);
        archiveFile.delete();
      }
    } catch (Exception e) {
      throw new PhrescoException(e);
    } finally {

    }
  }
Exemple #7
0
  public String setup() {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method  CI.setup()");
    }
    try {
      ProjectRuntimeManager runtimeManager = PhrescoFrameworkFactory.getProjectRuntimeManager();
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = administrator.getProject(projectCode);
      ActionType actionType = ActionType.JENKINS_SETUP;
      actionType.setWorkingDirectory(Utility.getJenkinsHome());
      if (debugEnabled) {
        S_LOGGER.debug("Jenkins Home " + Utility.getJenkinsHome().toString());
      }

      // Here we have to place two files in jenkins_home environment variable location
      administrator.getJdkHomeXml();
      administrator.getMavenHomeXml();
      // place email ext plugin in plugin folder
      administrator.getEmailExtPlugin();
      BufferedReader reader = runtimeManager.performAction(project, actionType, null, null);
      getHttpSession().setAttribute(projectCode + CI_SETUP, reader);
      getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
      getHttpRequest().setAttribute(REQ_TEST_TYPE, CI_SETUP);
    } catch (Exception e) {
      if (debugEnabled) {
        S_LOGGER.error(
            "Entered into catch block of CI.setup()" + FrameworkUtil.getStackTraceAsString(e));
      }
    }
    return APP_ENVIRONMENT_READER;
  }
Exemple #8
0
  private void setSvnCredential(CIJob job) throws JDOMException, IOException {
    S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential");
    try {
      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String credentialFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CREDENTIAL_XML;
      if (debugEnabled) {
        S_LOGGER.debug("credentialFilePath ... " + credentialFilePath);
      }
      File credentialFile = new File(credentialFilePath);

      SvnProcessor processor = new SvnProcessor(credentialFile);

      //			DataInputStream in = new DataInputStream(new FileInputStream(credentialFile));
      //			while (in.available() != 0) {
      //				System.out.println(in.readLine());
      //			}
      //			in.close();

      processor.changeNodeValue("credentials/entry//userName", job.getUserName());
      processor.changeNodeValue("credentials/entry//password", job.getPassword());
      processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName()));

      // jenkins home location
      String jenkinsJobHome = System.getenv(JENKINS_HOME);
      StringBuilder builder = new StringBuilder(jenkinsJobHome);
      builder.append(File.separator);

      processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML));
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into the catch block of CIManagerImpl.setSvnCredential "
              + e.getLocalizedMessage());
    }
  }
 @DELETE
 @Path(REST_API_TESTSUITES_DELETE)
 @Produces(MediaType.APPLICATION_JSON)
 public Response deleteTestSuites(
     @QueryParam(REST_API_TESTSUITE) String testSuiteName,
     @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
     @QueryParam(REST_QUERY_MODULE_NAME) String moduleName)
     throws PhrescoException {
   ResponseInfo<String> responseData = new ResponseInfo<String>();
   ManualTestResult createManualTestResult = null;
   ResponseInfo<Boolean> finalOutput = null;
   try {
     String rootModulePath = "";
     String subModuleName = "";
     if (StringUtils.isNotEmpty(moduleName)) {
       rootModulePath = Utility.getProjectHome() + appDirName;
       subModuleName = moduleName;
     } else {
       rootModulePath = Utility.getProjectHome() + appDirName;
     }
     FrameworkUtil frameworkUtil = FrameworkUtil.getInstance();
     ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName);
     File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName);
     String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName);
     StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir);
     File manualFilePath = new File(sb.toString());
     if (!manualFilePath.exists()) {
       finalOutput =
           responseDataEvaluation(
               responseData, null, createManualTestResult, RESPONSE_STATUS_FAILURE, PHRQ000003);
       return Response.status(Status.OK)
           .entity(finalOutput)
           .header("Access-Control-Allow-Origin", "*")
           .build();
     }
     boolean deleteManualTestSuiteFile =
         frameworkUtil.deleteManualTestSuiteFile(sb.toString(), testSuiteName);
     finalOutput =
         responseDataEvaluation(
             responseData, null, deleteManualTestSuiteFile, RESPONSE_STATUS_SUCCESS, PHRQ400008);
     return Response.status(Status.OK)
         .entity(finalOutput)
         .header("Access-Control-Allow-Origin", "*")
         .build();
   } catch (Exception e) {
     finalOutput =
         responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410004);
     return Response.status(Status.OK)
         .entity(finalOutput)
         .header("Access-Control-Allow-Origin", "*")
         .build();
   }
 }
Exemple #10
0
 private void deploysolution(
     String protocol, String serverContext, String host, String port, String wspFile)
     throws MojoExecutionException {
   BufferedReader bufferedReader = null;
   boolean errorParam = false;
   try {
     StringBuilder sb = new StringBuilder();
     sb.append(SHAREPOINT_STSADM);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_O);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_DEPLOYSOLUTION);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_NAME);
     sb.append(STR_SPACE);
     sb.append(wspFile);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_URL);
     sb.append(STR_SPACE);
     sb.append(protocol);
     sb.append(SHAREPOINT_STR_COLON);
     sb.append(SHAREPOINT_STR_DOUBLESLASH);
     sb.append(host);
     sb.append(SHAREPOINT_STR_COLON);
     sb.append(port);
     sb.append(SHAREPOINT_STR_BACKSLASH);
     sb.append(serverContext);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_IMMEDIATE);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_ALLOWACDEP);
     log.info("Deploy solution " + sb.toString());
     bufferedReader = Utility.executeCommand(sb.toString(), baseDir.getPath());
     String line = null;
     while ((line = bufferedReader.readLine()) != null) {
       if (line.startsWith("[ERROR]")) {
         errorParam = true;
       }
     }
     if (errorParam) {
       throw new MojoExecutionException("Deploying solution Failed ...");
     }
   } catch (IOException e) {
     throw new MojoExecutionException(e.getMessage(), e);
   } finally {
     Utility.closeStream(bufferedReader);
   }
 }
Exemple #11
0
 private void restore(String protocol, String serverContext, String host, String port)
     throws MojoExecutionException {
   BufferedReader bufferedReader = null;
   boolean errorParam = false;
   try {
     File file = new File(build.getPath() + "\\phresco-pilot.dat");
     if (!file.exists()) {
       return;
     }
     StringBuilder sb = new StringBuilder();
     sb.append(SHAREPOINT_STSADM);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_O);
     sb.append(SHAREPOINT_RESTORE);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_URL);
     sb.append(STR_SPACE);
     sb.append(protocol);
     sb.append(SHAREPOINT_STR_COLON);
     sb.append(SHAREPOINT_STR_DOUBLESLASH);
     sb.append(host);
     sb.append(SHAREPOINT_STR_COLON);
     sb.append(port);
     sb.append(SHAREPOINT_STR_BACKSLASH);
     sb.append(serverContext);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_OVERWRITE);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_FILENAME);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_DOUBLEQUOTES + file + SHAREPOINT_STR_DOUBLEQUOTES);
     log.info("Restore command " + sb.toString());
     bufferedReader = Utility.executeCommand(sb.toString(), baseDir.getPath());
     String line = null;
     while ((line = bufferedReader.readLine()) != null) {
       if (line.startsWith("[ERROR]")) {
         System.out.println(
             line); // do not use getLog() here as this line already contains the log type.
         errorParam = true;
       }
     }
     if (errorParam) {
       throw new MojoExecutionException("Restore Failed ...");
     }
   } catch (IOException e) {
     throw new MojoExecutionException(e.getMessage(), e);
   } finally {
     Utility.closeStream(bufferedReader);
   }
 }
 @POST
 @Path(REST_API_TESTCASES)
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
 public Response createTestCase(
     com.photon.phresco.commons.model.TestCase testCase,
     @QueryParam("testSuiteName") String testSuiteName,
     @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
     @QueryParam(REST_QUERY_MODULE_NAME) String moduleName)
     throws PhrescoException {
   ResponseInfo responseData = new ResponseInfo();
   try {
     String rootModulePath = "";
     String subModuleName = "";
     if (StringUtils.isNotEmpty(moduleName)) {
       rootModulePath = Utility.getProjectHome() + appDirName;
       subModuleName = moduleName;
     } else {
       rootModulePath = Utility.getProjectHome() + appDirName;
     }
     FrameworkUtil frameworkUtil = FrameworkUtil.getInstance();
     ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName);
     File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName);
     String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName);
     StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir);
     String cellValue[] = {
       "",
       testCase.getFeatureId(),
       "",
       testCase.getTestCaseId(),
       testCase.getDescription(),
       testCase.getPreconditions(),
       testCase.getSteps(),
       "",
       "",
       testCase.getExpectedResult(),
       testCase.getActualResult(),
       testCase.getStatus(),
       testCase.getBugComment()
     };
     frameworkUtil.addNewTestCase(sb.toString(), testSuiteName, cellValue, testCase.getStatus());
     ResponseInfo finalOutput =
         responseDataEvaluation(responseData, null, testCase, RESPONSE_STATUS_SUCCESS, PHRQ400005);
     return Response.status(Status.OK).entity(finalOutput).build();
   } catch (PhrescoException e) {
     e.printStackTrace();
     ResponseInfo finalOutput =
         responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410007);
     return Response.status(Status.OK).entity(finalOutput).build();
   }
 }
  @GET
  @Path(REST_API_TESTCASE_VALIDATION)
  @Produces(MediaType.APPLICATION_JSON)
  public Response testCaseValidation(
      @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
      @QueryParam(REST_QUERY_TESTCASE_NAME) String testCaseId,
      @QueryParam("testSuiteName") String testsuitename,
      @QueryParam(REST_QUERY_MODULE_NAME) String moduleName)
      throws PhrescoException {
    ResponseInfo<String> responseData = new ResponseInfo<String>();
    List<com.photon.phresco.commons.model.TestCase> readTestCase = null;
    boolean hasError = true;
    try {
      String rootModulePath = "";
      String subModuleName = "";
      if (StringUtils.isNotEmpty(moduleName)) {
        rootModulePath = Utility.getProjectHome() + appDirName;
        subModuleName = moduleName;
      } else {
        rootModulePath = Utility.getProjectHome() + appDirName;
      }
      FrameworkUtil frameworkUtil = FrameworkUtil.getInstance();
      ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName);
      File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName);
      String manualTestDir = getManualTestReportDir(rootModulePath, subModuleName);
      StringBuilder sb = new StringBuilder(manualDir.toString()).append(manualTestDir);
      readTestCase = frameworkUtil.readManualTestCaseFile(sb.toString(), testsuitename, null);
      for (com.photon.phresco.commons.model.TestCase testCase : readTestCase) {
        if (testCase.getTestCaseId().equalsIgnoreCase(testCaseId)) {
          hasError = false;
          break;
        }
      }

      ResponseInfo<Boolean> finalOutput =
          responseDataEvaluation(responseData, null, hasError, RESPONSE_STATUS_SUCCESS, PHRQ400007);
      return Response.status(Status.OK)
          .entity(finalOutput)
          .header("Access-Control-Allow-Origin", "*")
          .build();
    } catch (Exception e) {
      ResponseInfo<Boolean> finalOutput =
          responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHRQ410009);
      return Response.status(Status.OK)
          .entity(finalOutput)
          .header("Access-Control-Allow-Origin", "*")
          .build();
    }
  }
  private String getDependency(int buildNumber, String rootModulePath, String subModuleName)
      throws PhrescoException {
    try {
      BuildInfo buildInfo =
          Utility.getBuildInfo(
              buildNumber, getBuildInfoPath(rootModulePath, subModuleName).toString());
      if (buildInfo == null) {
        throw new PhrescoException("Build info is not found for build number " + buildNumber);
      }

      Map<String, Boolean> options = buildInfo.getOptions();
      if (options != null) {
        boolean createIpa = MapUtils.getBooleanValue(buildInfo.getOptions(), CAN_CREATE_IPA);
        boolean deviceDeploy = MapUtils.getBooleanValue(buildInfo.getOptions(), DEVICE_DEPLOY);

        if (!createIpa
            && !deviceDeploy) { // if it is simulator, show popup for following dependency
          return "";
        } else { // if it is device, it should return null and should not show any popup
          return DEVICE_ID;
        }
      }

    } catch (Exception e) {
      throw new PhrescoException(e);
    }
    return "";
  }
Exemple #15
0
 public String localJenkinsLocalAlive() {
   S_LOGGER.debug("Entering Method CI.localJenkinsLocalAlive()");
   try {
     URL url =
         new URL(
             HTTP_PROTOCOL
                 + PROTOCOL_POSTFIX
                 + LOCALHOST
                 + COLON
                 + Integer.parseInt(getPortNo(Utility.getJenkinsHome()))
                 + FORWARD_SLASH
                 + CI);
     URLConnection connection = url.openConnection();
     HttpURLConnection httpConnection = (HttpURLConnection) connection;
     int code = httpConnection.getResponseCode();
     localJenkinsAlive = code + "";
     S_LOGGER.debug("localJenkinsAlive => " + localJenkinsAlive);
   } catch (ConnectException e) {
     localJenkinsAlive = "404";
     S_LOGGER.debug("localJenkinsAlive => " + localJenkinsAlive);
   } catch (Exception e) {
     localJenkinsAlive = "404";
     S_LOGGER.debug("localJenkinsAlive => " + localJenkinsAlive);
   }
   return SUCCESS;
 }
  private void writeToFile(String fileName, List jsonObjects) throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug(
          "Entering Method ServiceManagerImpl.writeToFile(String fileName, List jsonObjects)");
    }
    String settingsInfoJson = gson.toJson(jsonObjects);
    FileWriter writer = null;

    try {
      if (debugEnabled) {
        S_LOGGER.debug("writeToFile() file Name = " + fileName);
      }
      File file = new File(Utility.getPhrescoTemp(), fileName);
      writer = new FileWriter(file);
      writer.write(settingsInfoJson);
      writer.flush();
    } catch (IOException e) {
      throw new PhrescoException(e);
    } finally {
      if (writer != null) {
        try {
          writer.close();
        } catch (IOException e) {
          throw new PhrescoException(e);
        }
      }
    }
  }
  private List<SettingsTemplate> loadSettingsTemplateFromFile() throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method ServiceManagerImpl.loadSettingsTemplateFromFile()");
    }
    File file = new File(Utility.getPhrescoTemp(), SETTINGS_FILE);
    if (!file.exists()) {
      return null;
    }

    FileReader reader = null;
    try {
      if (debugEnabled) {
        S_LOGGER.debug("loadSettingsTemplateFromFile() file path = " + file.getPath());
      }
      reader = new FileReader(file);
      BufferedReader bufferedReader = new BufferedReader(reader);
      Type type = new TypeToken<List<SettingsTemplate>>() {}.getType();
      return gson.fromJson(bufferedReader, type);
    } catch (FileNotFoundException e) {
      throw new PhrescoException(e);
    } finally {
      if (reader != null)
        try {
          reader.close();
        } catch (IOException e) {
          throw new PhrescoException(e);
        }
    }
  }
 @Override
 public void postUpdate(
     ApplicationInfo appInfo,
     List<ArtifactGroup> artifactGroups,
     List<ArtifactGroup> deletedFeatures)
     throws PhrescoException {
   File pomFile =
       new File(
           Utility.getProjectHome()
               + appInfo.getAppDirName()
               + File.separator
               + Constants.POM_NAME);
   ProjectUtils projectUtils = new ProjectUtils();
   projectUtils.deletePluginExecutionFromPom(pomFile);
   if (CollectionUtils.isNotEmpty(deletedFeatures)) {
     projectUtils.removeExtractedFeatures(appInfo, deletedFeatures);
   }
   if (CollectionUtils.isNotEmpty(artifactGroups)) {
     projectUtils.updatePOMWithPluginArtifact(pomFile, artifactGroups);
     excludeModule(appInfo, artifactGroups);
   }
   BufferedReader breader = projectUtils.ExtractFeature(appInfo);
   try {
     String line = "";
     while ((line = breader.readLine()) != null) {
       if (line.startsWith("[ERROR]")) {
         System.err.println(line);
       }
     }
   } catch (IOException e) {
     throw new PhrescoException(e);
   }
 }
  @POST
  @Path(REST_API_UPLOADTEMPLATE)
  @Consumes(MediaType.APPLICATION_OCTET_STREAM)
  @Produces(MediaType.APPLICATION_JSON)
  public Response uploadManualTemplate(
      @Context HttpServletRequest request, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName)
      throws PhrescoException {
    ResponseInfo response = new ResponseInfo();
    try {
      String uploadedFileName = request.getHeader(FrameworkConstants.X_FILE_NAME);
      String fileName = URLDecoder.decode(uploadedFileName, "UTF-8");
      InputStream inputStream = request.getInputStream();
      String moduleName = request.getHeader("moduleName");
      String rootModulePath = "";
      String subModuleName = "";
      if (StringUtils.isNotEmpty(moduleName)) {
        rootModulePath = Utility.getProjectHome() + appDirName;
        subModuleName = moduleName;
      } else {
        rootModulePath = Utility.getProjectHome() + appDirName;
      }

      String manualTestPath = getManualTestReportDir(rootModulePath, subModuleName);
      ProjectInfo projectinfo = Utility.getProjectInfo(rootModulePath, subModuleName);
      File manualDir = Utility.getTestFolderLocation(projectinfo, rootModulePath, subModuleName);
      StringBuilder builder = new StringBuilder(manualDir.toString());
      builder.append(manualTestPath);
      File existingFile = new File(builder.toString());
      FileUtils.cleanDirectory(existingFile);
      File file = new File(builder.toString() + File.separator + fileName);
      FileUtils.copyInputStreamToFile(inputStream, file);
    } catch (Exception e) {
      ResponseInfo finalOutput =
          responseDataEvaluation(response, e, null, RESPONSE_STATUS_ERROR, PHRQ410002);
      return Response.status(Status.OK)
          .entity(finalOutput)
          .header("Access-Control-Allow-Origin", "*")
          .build();
    }
    ResponseInfo responseData =
        responseDataEvaluation(response, null, null, RESPONSE_STATUS_SUCCESS, PHRQ400001);
    return Response.status(Status.OK)
        .header("Access-Control-Allow-Origin", "*")
        .entity(responseData)
        .build();
  }
  public List<String> validateProjectCode() {
    DirectoryWalker walker = new DirectoryWalker();
    walker.setBaseDir(new File(Utility.getProjectHome()));
    walker.addDirectoryWalkListener(this);
    walker.scan();

    return invalidProjects;
  }
Exemple #21
0
 private void addSolution(String wspFile) throws MojoExecutionException {
   BufferedReader bufferedReader = null;
   boolean errorParam = false;
   try {
     StringBuilder sb = new StringBuilder();
     sb.append(SHAREPOINT_STSADM);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_O);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_ADDSOLUTION);
     sb.append(STR_SPACE);
     sb.append(SHAREPOINT_STR_HYPEN);
     sb.append(SHAREPOINT_STR_FILENAME);
     sb.append(STR_SPACE);
     sb.append(
         SHAREPOINT_STR_DOUBLEQUOTES
             + baseDir.getPath()
             + "\\source"
             + "\\"
             + wspFile
             + SHAREPOINT_STR_DOUBLEQUOTES);
     File file = new File(baseDir.getPath() + "\\source" + "\\" + wspFile);
     log.info("Add soluition file " + file);
     if (file.exists()) {
       log.info("Add Solution command " + sb.toString());
       bufferedReader = Utility.executeCommand(sb.toString(), baseDir.getPath());
       String line = null;
       while ((line = bufferedReader.readLine()) != null) {
         if (line.startsWith("[ERROR]")) {
           System.out.println(
               line); // do not use getLog() here as this line already contains the log type.
           errorParam = true;
         }
       }
       if (errorParam) {
         throw new MojoExecutionException("Adding of Solution Failed ...");
       }
     } else {
       log.error("File Not found Exception");
     }
   } catch (IOException e) {
     throw new MojoExecutionException(e.getMessage(), e);
   } finally {
     Utility.closeStream(bufferedReader);
   }
 }
 private String getManualTestReportDir(String rootModulePath, String subModuleName)
     throws PhrescoException {
   try {
     PomProcessor pomProcessor = Utility.getPomProcessor(rootModulePath, subModuleName);
     String manualDir = pomProcessor.getProperty(Constants.POM_PROP_KEY_MANUALTEST_RPT_DIR);
     return manualDir;
   } catch (PhrescoPomException e) {
     throw new PhrescoException(e);
   }
 }
Exemple #23
0
  public String ci() {
    S_LOGGER.debug("Entering Method CI.ci()");
    try {
      boolean jenkinsAlive = false;
      // UI didnt trigger anybuild from here
      getHttpRequest().setAttribute(CI_BUILD_TRIGGERED_FROM_UI, FALSE);
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = (Project) administrator.getProject(projectCode);
      getHttpRequest().setAttribute(REQ_PROJECT, project);
      getHttpRequest().setAttribute(REQ_SELECTED_MENU, APPLICATIONS);
      getHttpRequest().setAttribute(CI_JENKINS_ALIVE, jenkinsAlive);

      jenkinsAlive =
          DiagnoseUtil.isConnectionAlive(
              HTTP_PROTOCOL, LOCALHOST, Integer.parseInt(getPortNo(Utility.getJenkinsHome())));
      S_LOGGER.debug("jenkins Alive " + jenkinsAlive);
      getHttpRequest().setAttribute(CI_JENKINS_ALIVE, jenkinsAlive);

      List<CIJob> existingJobs = administrator.getJobs(project);
      Map<String, List<CIBuild>> ciJobsAndBuilds = new HashMap<String, List<CIBuild>>();
      if (existingJobs != null) {
        for (CIJob ciJob : existingJobs) {
          boolean buildJenkinsAlive = false;
          boolean isJobCreatingBuild = false;
          int noOfJobsIsInProgress = 0;
          List<CIBuild> builds = null;
          buildInProgress = false;
          buildJenkinsAlive =
              DiagnoseUtil.isConnectionAlive(
                  HTTP_PROTOCOL, ciJob.getJenkinsUrl(), Integer.parseInt(ciJob.getJenkinsPort()));
          isJobCreatingBuild = administrator.isJobCreatingBuild(ciJob);
          S_LOGGER.debug("ciJob.getName() ====> " + ciJob.getName());
          S_LOGGER.debug("ciJob.getName() alive  ====> " + buildJenkinsAlive);
          S_LOGGER.debug("ciJob.getName() isJobCreatingBuild  ====> " + isJobCreatingBuild);
          getHttpRequest()
              .setAttribute(CI_BUILD_JENKINS_ALIVE + ciJob.getName(), buildJenkinsAlive);
          getHttpRequest()
              .setAttribute(CI_BUILD_IS_IN_PROGRESS + ciJob.getName(), isJobCreatingBuild);
          if (buildJenkinsAlive == true) {
            builds = administrator.getBuilds(ciJob);
          }
          S_LOGGER.debug("ciJob.getName() builds ====> " + builds);
          ciJobsAndBuilds.put(ciJob.getName(), builds);
        }
      }
      getHttpRequest().setAttribute(REQ_EXISTING_JOBS, ciJobsAndBuilds);
      numberOfJobsIsInProgress();
      S_LOGGER.debug("numberOfJobsInProgress " + numberOfJobsInProgress);
      getHttpRequest().setAttribute(CI_NO_OF_JOBS_IN_PROGRESS, numberOfJobsInProgress);
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of CI.ci()" + FrameworkUtil.getStackTraceAsString(e));
    }
    return APP_CI;
  }
Exemple #24
0
  public String stopJenkins() {
    S_LOGGER.debug("Entering Method  CI.stopJenkins()");
    try {
      ProjectRuntimeManager runtimeManager = PhrescoFrameworkFactory.getProjectRuntimeManager();
      ProjectAdministrator administrator = PhrescoFrameworkFactory.getProjectAdministrator();
      Project project = administrator.getProject(projectCode);
      ActionType actionType = ActionType.JENKINS_STOP;
      actionType.setWorkingDirectory(Utility.getJenkinsHome());
      S_LOGGER.debug("Jenkins Home " + Utility.getJenkinsHome().toString());
      BufferedReader reader = runtimeManager.performAction(project, actionType, null, null);

      getHttpSession().setAttribute(projectCode + CI_STOP, reader);
      getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode);
      getHttpRequest().setAttribute(REQ_TEST_TYPE, CI_STOP);
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of CI.stopJenkins()" + FrameworkUtil.getStackTraceAsString(e));
    }
    return APP_ENVIRONMENT_READER;
  }
 private StringBuilder getBuildInfoPath(String rootModulePath, String subModuleName)
     throws PhrescoException {
   File pomFileLocation = Utility.getPomFileLocation(rootModulePath, subModuleName);
   StringBuilder builder = new StringBuilder(pomFileLocation.getParent());
   builder.append(File.separator);
   builder.append(DO_NOT_CHECKIN_DIR);
   builder.append(File.separator);
   builder.append(BUILD);
   builder.append(File.separator);
   builder.append(BUILD_INFO_FILE_NAME);
   return builder;
 }
 @Override
 public void postConfiguration(ApplicationInfo appInfo, List<Configuration> configurations)
     throws PhrescoException {
   String envName = configurations.get(0).getEnvName();
   String featureName = configurations.get(0).getProperties().getProperty(Constants.FEATURE_NAME);
   String propertyValue = getPropertyValue(appInfo, Constants.POM_PROP_KEY_SQL_FILE_DIR);
   File featureManifest =
       new File(
           Utility.getProjectHome()
               + appInfo.getAppDirName()
               + getThirdPartyFolder(appInfo)
               + File.separator
               + featureName
               + File.separator
               + XML);
   File featureSqlDir =
       new File(Utility.getProjectHome() + appInfo.getAppDirName() + propertyValue);
   if (StringUtils.isNotEmpty(featureName)) {
     storeConfigObj(configurations, featureManifest, featureSqlDir, envName);
   }
 }
Exemple #27
0
  private void setMailCredential(CIJob job) {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.setMailCredential");
    }
    try {
      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String mailFilePath = jenkinsTemplateDir + MAIL + HYPHEN + CREDENTIAL_XML;
      if (debugEnabled) {
        S_LOGGER.debug("configFilePath ... " + mailFilePath);
      }
      File mailFile = new File(mailFilePath);

      SvnProcessor processor = new SvnProcessor(mailFile);

      //			DataInputStream in = new DataInputStream(new FileInputStream(mailFile));
      //			while (in.available() != 0) {
      //				System.out.println(in.readLine());
      //			}
      //			in.close();

      // Mail have to go with jenkins running email address
      InetAddress ownIP = InetAddress.getLocalHost();
      processor.changeNodeValue(
          CI_HUDSONURL,
          HTTP_PROTOCOL
              + PROTOCOL_POSTFIX
              + ownIP.getHostAddress()
              + COLON
              + job.getJenkinsPort()
              + FORWARD_SLASH
              + CI
              + FORWARD_SLASH);
      processor.changeNodeValue("smtpAuthUsername", job.getSenderEmailId());
      processor.changeNodeValue("smtpAuthPassword", job.getSenderEmailPassword());
      processor.changeNodeValue("adminAddress", job.getSenderEmailId());

      // jenkins home location
      String jenkinsJobHome = System.getenv(JENKINS_HOME);
      StringBuilder builder = new StringBuilder(jenkinsJobHome);
      builder.append(File.separator);

      processor.writeStream(new File(builder.toString() + CI_MAILER_XML));
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into the catch block of CIManagerImpl.setMailCredential "
              + e.getLocalizedMessage());
    }
  }
  @Override
  public List<Configuration> preConfiguration(
      ApplicationInfo appInfo, String featureName, String envName) throws PhrescoException {
    File featureManifest =
        new File(
            Utility.getProjectHome()
                + appInfo.getAppDirName()
                + getThirdPartyFolder(appInfo)
                + File.separator
                + featureName
                + File.separator
                + XML);
    List<Configuration> configs = getConfigObjFromXml(featureManifest.getPath());

    return configs;
  }
  private void excludeModule(ApplicationInfo appInfo, List<ArtifactGroup> artifactGroups)
      throws PhrescoException {
    try {
      File projectPath =
          new File(
              Utility.getProjectHome()
                  + File.separator
                  + appInfo.getAppDirName()
                  + File.separator
                  + Constants.POM_NAME);
      PomProcessor processor = new PomProcessor(projectPath);
      StringBuilder exclusionStringBuff = new StringBuilder();
      StringBuilder exclusionValueBuff = new StringBuilder();
      if (CollectionUtils.isEmpty(artifactGroups)) {
        return;
      }
      for (ArtifactGroup artifactGroup : artifactGroups) {
        List<CoreOption> appliesTo = artifactGroup.getAppliesTo();
        for (CoreOption coreOption : appliesTo) {
          if (coreOption.isCore()) {
            exclusionValueBuff.append(artifactGroup.getName().toLowerCase());
            exclusionValueBuff.append(",");
            exclusionStringBuff.append("**\\");
            exclusionStringBuff.append(artifactGroup.getName().toLowerCase());
            exclusionStringBuff.append("\\**");
            exclusionStringBuff.append(",");
          }
        }
      }
      String exclusionValue = exclusionStringBuff.toString();
      if (exclusionValue.lastIndexOf(',') != -1) {
        exclusionValue = exclusionValue.substring(0, exclusionValue.lastIndexOf(','));
      }

      String exclusiontoolValue = exclusionValueBuff.toString();
      if (exclusiontoolValue.lastIndexOf(',') != -1) {
        exclusiontoolValue = exclusiontoolValue.substring(0, exclusiontoolValue.lastIndexOf(','));
      }
      processor.setProperty("sonar.exclusions", exclusionValue);
      processor.setProperty("sonar.phpDepend.argumentLine", "--ignore=" + exclusiontoolValue);
      processor.setProperty("sonar.phpPmd.argumentLine", "--exclude" + exclusiontoolValue);
      processor.save();
    } catch (PhrescoPomException e) {
      throw new PhrescoException(e);
    }
  }
Exemple #30
0
  public String checkForSiteReport() {
    S_LOGGER.debug("Entering Method  SiteReport.checkForSiteReport()");

    try {
      Properties sysProps = System.getProperties();
      S_LOGGER.debug(
          "Phresco FileServer Value of "
              + PHRESCO_FILE_SERVER_PORT_NO
              + " is "
              + sysProps.getProperty(PHRESCO_FILE_SERVER_PORT_NO));
      String phrescoFileServerNumber = sysProps.getProperty(PHRESCO_FILE_SERVER_PORT_NO);
      StringBuilder sb = new StringBuilder();
      StringBuilder siteReportPath = new StringBuilder(Utility.getProjectHome());
      siteReportPath.append(projectCode);
      siteReportPath.append(File.separatorChar);
      siteReportPath.append(SITE_TARGET);
      siteReportPath.append(File.separatorChar);
      siteReportPath.append(INDEX_HTML);
      File indexPath = new File(siteReportPath.toString());
      if (indexPath.isFile() && StringUtils.isNotEmpty(phrescoFileServerNumber)) {
        sb.append(HTTP_PROTOCOL);
        sb.append(PROTOCOL_POSTFIX);
        sb.append(LOCALHOST);
        sb.append(COLON);
        sb.append(phrescoFileServerNumber);
        sb.append(FORWARD_SLASH);
        sb.append(projectCode);
        sb.append(FORWARD_SLASH);
        sb.append(SITE_TARGET);
        sb.append(FORWARD_SLASH);
        sb.append(INDEX_HTML);
        getHttpRequest().setAttribute(REQ_SITE_REPORT_PATH, sb.toString());
      } else {
        getHttpRequest().setAttribute(REQ_ERROR, false);
      }
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into catch block of SiteReport.checkForSiteReport()"
              + FrameworkUtil.getStackTraceAsString(e));
      new LogErrorReport(e, "Getting site report");
    }

    return APP_SITE_REPORT_VIEW;
  }