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); } }
private void updateDrupalVersion(File path, ApplicationInfo info) throws PhrescoException { try { File xmlFile = new File(path, Constants.POM_NAME); PomProcessor processor = new PomProcessor(xmlFile); String selectedVersion = info.getTechInfo().getVersion(); processor.setProperty(Constants.DRUPAL_VERSION, selectedVersion); processor.save(); } catch (PhrescoPomException e) { throw new PhrescoException(e); } }
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); } }
private String getThirdPartyFolder(ApplicationInfo appInfo) throws PhrescoException { File pomPath = new File( Utility.getProjectHome() + appInfo.getAppDirName() + File.separator + Constants.POM_NAME); try { PomProcessor processor = new PomProcessor(pomPath); String property = processor.getProperty(Constants.POM_PROP_KEY_MODULE_SOURCE_DIR); if (StringUtils.isNotEmpty(property)) { return property; } } catch (PhrescoPomException e) { throw new PhrescoException(e); } return ""; }
private String getPropertyValue(ApplicationInfo appInfo, String propertyKey) throws PhrescoException { File pomPath = new File( Utility.getProjectHome() + appInfo.getAppDirName() + File.separator + Constants.POM_NAME); try { PomProcessor processor = new PomProcessor(pomPath); String property = processor.getProperty(propertyKey); if (StringUtils.isNotEmpty(property)) { return property; } } catch (PhrescoPomException e) { throw new PhrescoException(e); } return ""; }
@Override public void execute() throws MojoExecutionException, MojoFailureException { File outputFile = null, outputAlignedFile = null, destFile = null, destAlignedFile = null; String techId; if (baseDir.getPath().endsWith("source") || baseDir.getPath().endsWith("unit") || baseDir.getPath().endsWith("functional") || baseDir.getPath().endsWith("performance")) { try { if (baseDir.getPath().endsWith("source")) { rootPomFile = new File( baseDir.getParentFile().getPath() + File.separator + PluginConstants.POM_XML); } else { String rootDir = baseDir.getParentFile().getParentFile().getParentFile().getPath(); SplitedSourceDirName = rootDir.substring(rootDir.lastIndexOf(File.separator) + 1); rootPomFile = new File( baseDir.getParentFile().getParentFile().getParentFile().getPath() + File.separator + SplitedSourceDirName + File.separator + PluginConstants.POM_XML); } try { if (rootPomFile.exists()) { rootPomProcessor = new PomProcessor(rootPomFile); if (StringUtils.isNotEmpty( rootPomProcessor.getProperty(Constants.POM_PROP_KEY_SPLIT_PHRESCO_DIR))) { dotPhrescoDirName = rootPomProcessor.getProperty(Constants.POM_PROP_KEY_SPLIT_PHRESCO_DIR); testDirName = rootPomProcessor.getProperty(Constants.POM_PROP_KEY_SPLIT_TEST_DIR); } } } catch (PhrescoPomException e) { e.printStackTrace(); } buildInfoList = new ArrayList<BuildInfo>(); // initialization if (baseDir.getPath().endsWith("source") && dotPhrescoDirName == null) { buildDir = new File(baseDir.getParentFile().getPath() + buildDirectory); packageInfoFile = new File( baseDir.getParentFile().getPath() + File.separator + ".phresco" + File.separator + "phresco-package-info.xml"); } else if (baseDir.getPath().endsWith("source") && dotPhrescoDirName != null) { // code for new archetype changes starts dotPhrescoDir = baseDir.getParentFile().getParentFile().getPath() + File.separator + dotPhrescoDirName; File projectDir = new File(baseDir.getParentFile().getParentFile().getPath()); File[] filesInDir = projectDir.listFiles(); fileProcessor(filesInDir); // code for new archetype changes ends buildDir = new File(finalBuildDir + File.separator + buildDirectory); packageInfoFile = new File( dotPhrescoDir + File.separator + ".phresco" + File.separator + "phresco-package-info.xml"); } else if (dotPhrescoDirName != null) { dotPhrescoDir = baseDir.getParentFile().getParentFile().getParentFile().getPath() + File.separator + dotPhrescoDirName; buildDir = new File(baseDir.getPath() + buildDirectory); } else { buildDir = new File(baseDir.getPath() + buildDirectory); } if (!buildDir.exists()) { buildDir.mkdir(); } buildInfoFile = new File(buildDir.getPath() + "/build.info"); if ((baseDir.getPath().endsWith("unit") || baseDir.getPath().endsWith("functional") || baseDir.getPath().endsWith("performance")) && dotPhrescoDir != null) { packageInfoFile = new File( dotPhrescoDir + File.separator + ".phresco" + File.separator + "phresco-package-info.xml"); } else if (baseDir.getPath().endsWith("unit") || baseDir.getPath().endsWith("functional") || baseDir.getPath().endsWith("performance")) { packageInfoFile = new File( baseDir.getParentFile().getParentFile() + File.separator + ".phresco" + File.separator + "phresco-package-info.xml"); buildDir = baseDir.getParentFile().getParentFile(); buildInfoFile = new File(baseDir.getPath() + buildDirectory + "/build.info"); } MojoProcessor processor = new MojoProcessor(packageInfoFile); Configuration configuration = processor.getConfiguration("package"); Map<String, String> configs = MojoUtil.getAllValues(configuration); techId = configs.get("techId"); if (StringUtils.isNotEmpty(techId)) { outputFile = new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + '.' + APKLIB); } else { outputFile = new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + '.' + APK); outputAlignedFile = new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + "-aligned." + APK); } nextBuildNo = generateNextBuildNo(); currentDate = Calendar.getInstance().getTime(); } catch (IOException e) { throw new MojoFailureException("APK could not initialize " + e.getLocalizedMessage()); } catch (PhrescoException e) { throw new MojoFailureException("APK could not initialize " + e.getLocalizedMessage()); } if (outputFile.exists()) { try { if (StringUtils.isNotEmpty(techId)) { getLog().info("APKLib created.. Copying to Build directory....."); } else { getLog().info("APK created.. Copying to Build directory....."); } String buildNameLocal = project.getBuild().getFinalName() + '_' + getTimeStampForBuildName(currentDate); if (baseDir.getPath().endsWith("unit") || baseDir.getPath().endsWith("functional") || baseDir.getPath().endsWith("performance")) { buildDir = new File(baseDir.getPath() + buildDirectory); } if (buildName != null) { if (StringUtils.isNotEmpty(techId)) { destFile = new File(buildDir, buildName + '.' + APKLIB); } else { destFile = new File(buildDir, buildName + '.' + APK); // Creating the file in build folder for copying the aligned APK - Created by Hari - // 20-May-2013 destAlignedFile = new File(buildDir, buildName + "-aligned." + APK); } FileUtils.copyFile(outputFile, destFile); getLog().info("copied to..." + destFile.getName()); /* If outputAlignedFile exists in target folder, * Then we are copying it to destinationFile in build folder * Added By - Hari - May, 20 , 2013 */ if (outputAlignedFile != null && outputAlignedFile.exists()) { FileUtils.copyFile(outputAlignedFile, destAlignedFile); } apkFileName = destFile.getName(); getLog().info("Creating deliverables....."); ZipArchiver zipArchiver = new ZipArchiver(); File tmpFile = new File(buildDir, buildName); if (!tmpFile.exists()) { tmpFile.mkdirs(); } FileUtils.copyFileToDirectory(destFile, tmpFile); /*To Copy the aligned apk into zip file in build folder, *It is for downloading the aligned apk from build Tab * Added by - Hari -May, 20 ,2013 */ if (destAlignedFile != null && destAlignedFile.exists()) { FileUtils.copyFileToDirectory(destAlignedFile, tmpFile); } if (!packageInfoFile.exists()) { PluginUtils.createBuildResources(packageInfoFile, baseDir, tmpFile); } File inputFile = new File(apkFileName); zipArchiver.addDirectory(tmpFile); File deliverableZip = new File(buildDir, buildName + ".zip"); zipArchiver.setDestFile(deliverableZip); zipArchiver.createArchive(); deliverable = deliverableZip.getPath(); getLog().info("Deliverables available at " + deliverableZip.getName()); if (tmpFile.exists()) { FileUtil.delete(tmpFile); } writeBuildInfo(true); } else { if (StringUtils.isNotEmpty(techId)) { destFile = new File(buildDir, buildNameLocal + '.' + APKLIB); } else { destFile = new File(buildDir, buildNameLocal + '.' + APK); // Creating the file in build folder for copying the aligned APK - Created by Hari - // 20-May-2013 destAlignedFile = new File(buildDir, buildNameLocal + "-aligned." + APK); } FileUtils.copyFile(outputFile, destFile); getLog().info("copied to..." + destFile.getName()); /* If outputAlignedFile exists in target folder, * Then we are copying it to destinationFile in build folder * Added By - Hari - May, 20 , 2013 */ if (outputAlignedFile != null && outputAlignedFile.exists()) { FileUtils.copyFile(outputAlignedFile, destAlignedFile); } apkFileName = destFile.getName(); getLog().info("Creating deliverables....."); ZipArchiver zipArchiver = new ZipArchiver(); File tmpFile = new File(buildDir, buildNameLocal); if (!tmpFile.exists()) { tmpFile.mkdirs(); } FileUtils.copyFileToDirectory(destFile, tmpFile); /*To Copy the aligned apk into zip file in build folder, *It is for downloading the aligned apk from build Tab * Added by - Hari -May, 20 ,2013 */ if (destAlignedFile != null && destAlignedFile.exists()) { FileUtils.copyFileToDirectory(destAlignedFile, tmpFile); } if (!packageInfoFile.exists()) { PluginUtils.createBuildResources(packageInfoFile, baseDir, tmpFile); } File inputFile = new File(apkFileName); zipArchiver.addDirectory(tmpFile); File deliverableZip = new File(buildDir, buildNameLocal + ".zip"); zipArchiver.setDestFile(deliverableZip); zipArchiver.createArchive(); deliverable = deliverableZip.getPath(); getLog().info("Deliverables available at " + deliverableZip.getName()); if (tmpFile.exists()) { FileUtil.delete(tmpFile); } writeBuildInfo(true); } } catch (IOException e) { throw new MojoExecutionException("Error in writing output..."); } } } else { getLog().info("It is a component "); } }