@Test public void testRemoveNotificationFromTravisYML() throws IOException { File resourceFile = new File("./src/test/resources/travis-file/.travis.yml"); tmpDir = Files.createTempDirectory("test_removeNotificationFromTravisYML").toFile(); FileUtils.copyFileToDirectory(resourceFile, tmpDir); JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath()); ProjectInspector inspector = ProjectInspectorMocker.mockProjectInspector(jobStatus, tmpDir.getAbsolutePath()); CloneRepository cloneStep = new CloneRepository(inspector); FileHelper.removeNotificationFromTravisYML(tmpDir, cloneStep); File bak = new File(tmpDir.getAbsolutePath() + "/bak.travis.yml"); File travis = new File(tmpDir.getAbsolutePath() + "/.travis.yml"); assertTrue(bak.exists()); assertTrue(travis.exists()); List<String> lines = Files.readAllLines(travis.toPath()); int i; for (i = 0; i < lines.size(); i++) { if (lines.get(i).contains("notification")) break; } assertTrue(nextLevelIsLowestLevel(lines, getIndexOfFirstLineAfterConsecutiveHashes(lines, i))); }
public static void removeNotificationFromTravisYML(File directory, AbstractStep step) { File travisFile = new File(directory, Utils.TRAVIS_FILE); if (!travisFile.exists()) { getLogger().warn("Travis file has not been detected. It should however exists."); } else { try { List<String> lines = Files.readAllLines(travisFile.toPath()); List<String> newLines = new ArrayList<>(); boolean changed = false; boolean inNotifBlock = false; for (String line : lines) { if (line.trim().equals("notifications:")) { changed = true; inNotifBlock = true; } if (inNotifBlock) { if (line.trim().isEmpty()) { inNotifBlock = false; newLines.add(line); } else { newLines.add("#" + line); } } else { newLines.add(line); } } if (changed) { getLogger().info("Notification block detected. The travis file will be changed."); File bakTravis = new File(directory, "bak" + Utils.TRAVIS_FILE); Files.deleteIfExists(bakTravis.toPath()); Files.move(travisFile.toPath(), bakTravis.toPath()); FileWriter fw = new FileWriter(travisFile); for (String line : newLines) { fw.append(line); fw.append("\n"); fw.flush(); } fw.close(); step.getInspector().getJobStatus().addFileToPush(Utils.TRAVIS_FILE); step.getInspector().getJobStatus().addFileToPush("bak" + Utils.TRAVIS_FILE); } } catch (IOException e) { getLogger().warn("Error while changing travis file", e); } } }
FileHelper { public static void removeNotificationFromTravisYML(File directory, AbstractStep step) { File travisFile = new File(directory, Utils.TRAVIS_FILE); if (!travisFile.exists()) { getLogger().warn("Travis file has not been detected. It should however exists."); } else { try { List<String> lines = Files.readAllLines(travisFile.toPath()); List<String> newLines = new ArrayList<>(); boolean changed = false; boolean inNotifBlock = false; for (String line : lines) { if (line.trim().equals("notifications:")) { changed = true; inNotifBlock = true; } if (inNotifBlock) { if (line.trim().isEmpty()) { inNotifBlock = false; newLines.add(line); } else { newLines.add("#" + line); } } else { newLines.add(line); } } if (changed) { getLogger().info("Notification block detected. The travis file will be changed."); File bakTravis = new File(directory, "bak" + Utils.TRAVIS_FILE); Files.deleteIfExists(bakTravis.toPath()); Files.move(travisFile.toPath(), bakTravis.toPath()); FileWriter fw = new FileWriter(travisFile); for (String line : newLines) { fw.append(line); fw.append("\n"); fw.flush(); } fw.close(); step.getInspector().getJobStatus().addFileToPush(Utils.TRAVIS_FILE); step.getInspector().getJobStatus().addFileToPush("bak" + Utils.TRAVIS_FILE); } } catch (IOException e) { getLogger().warn("Error while changing travis file", e); } } } }
FileHelper { public static void removeNotificationFromTravisYML(File directory, AbstractStep step) { File travisFile = new File(directory, Utils.TRAVIS_FILE); if (!travisFile.exists()) { getLogger().warn("Travis file has not been detected. It should however exists."); } else { try { List<String> lines = Files.readAllLines(travisFile.toPath()); List<String> newLines = new ArrayList<>(); boolean changed = false; boolean inNotifBlock = false; for (String line : lines) { if (line.trim().equals("notifications:")) { changed = true; inNotifBlock = true; } if (inNotifBlock) { if (line.trim().isEmpty()) { inNotifBlock = false; newLines.add(line); } else { newLines.add("#" + line); } } else { newLines.add(line); } } if (changed) { getLogger().info("Notification block detected. The travis file will be changed."); File bakTravis = new File(directory, "bak" + Utils.TRAVIS_FILE); Files.deleteIfExists(bakTravis.toPath()); Files.move(travisFile.toPath(), bakTravis.toPath()); FileWriter fw = new FileWriter(travisFile); for (String line : newLines) { fw.append(line); fw.append("\n"); fw.flush(); } fw.close(); step.getInspector().getJobStatus().addFileToPush(Utils.TRAVIS_FILE); step.getInspector().getJobStatus().addFileToPush("bak" + Utils.TRAVIS_FILE); } } catch (IOException e) { getLogger().warn("Error while changing travis file", e); } } }  }
FileHelper { public static void removeNotificationFromTravisYML(File directory, AbstractStep step) { File travisFile = new File(directory, Utils.TRAVIS_FILE); if (!travisFile.exists()) { getLogger().warn("Travis file has not been detected. It should however exists."); } else { try { List<String> lines = Files.readAllLines(travisFile.toPath()); List<String> newLines = new ArrayList<>(); boolean changed = false; boolean inNotifBlock = false; for (String line : lines) { if (line.trim().equals("notifications:")) { changed = true; inNotifBlock = true; } if (inNotifBlock) { if (line.trim().isEmpty()) { inNotifBlock = false; newLines.add(line); } else { newLines.add("#" + line); } } else { newLines.add(line); } } if (changed) { getLogger().info("Notification block detected. The travis file will be changed."); File bakTravis = new File(directory, "bak" + Utils.TRAVIS_FILE); Files.deleteIfExists(bakTravis.toPath()); Files.move(travisFile.toPath(), bakTravis.toPath()); FileWriter fw = new FileWriter(travisFile); for (String line : newLines) { fw.append(line); fw.append("\n"); fw.flush(); } fw.close(); step.getInspector().getJobStatus().addFileToPush(Utils.TRAVIS_FILE); step.getInspector().getJobStatus().addFileToPush("bak" + Utils.TRAVIS_FILE); } } catch (IOException e) { getLogger().warn("Error while changing travis file", e); } } }  static void copyDirectory(File sourceDir, File targetDir, String[] excludedFileNames,
            boolean isToPerfectlyMatch, AbstractStep step); static void deleteFile(File file); static void removeNotificationFromTravisYML(File directory, AbstractStep step); static void removeGhOauthFromCreatedFilesToPush(File directory, List<String> fileNames); static void removeTargetFolderFromFilesToPush(File directory); }
FileHelper { public static void removeNotificationFromTravisYML(File directory, AbstractStep step) { File travisFile = new File(directory, Utils.TRAVIS_FILE); if (!travisFile.exists()) { getLogger().warn("Travis file has not been detected. It should however exists."); } else { try { List<String> lines = Files.readAllLines(travisFile.toPath()); List<String> newLines = new ArrayList<>(); boolean changed = false; boolean inNotifBlock = false; for (String line : lines) { if (line.trim().equals("notifications:")) { changed = true; inNotifBlock = true; } if (inNotifBlock) { if (line.trim().isEmpty()) { inNotifBlock = false; newLines.add(line); } else { newLines.add("#" + line); } } else { newLines.add(line); } } if (changed) { getLogger().info("Notification block detected. The travis file will be changed."); File bakTravis = new File(directory, "bak" + Utils.TRAVIS_FILE); Files.deleteIfExists(bakTravis.toPath()); Files.move(travisFile.toPath(), bakTravis.toPath()); FileWriter fw = new FileWriter(travisFile); for (String line : newLines) { fw.append(line); fw.append("\n"); fw.flush(); } fw.close(); step.getInspector().getJobStatus().addFileToPush(Utils.TRAVIS_FILE); step.getInspector().getJobStatus().addFileToPush("bak" + Utils.TRAVIS_FILE); } } catch (IOException e) { getLogger().warn("Error while changing travis file", e); } } }  static void copyDirectory(File sourceDir, File targetDir, String[] excludedFileNames,
            boolean isToPerfectlyMatch, AbstractStep step); static void deleteFile(File file); static void removeNotificationFromTravisYML(File directory, AbstractStep step); static void removeGhOauthFromCreatedFilesToPush(File directory, List<String> fileNames); static void removeTargetFolderFromFilesToPush(File directory);  }