@Test public void noOpLineNumberTest() throws IOException { InsertLine insertLine = new InsertLine(" color: yellow", 1427).relative("/src/main/resources/dogs.yaml"); TOExecutionResult executionResult = insertLine.execution(transformedAppFolder, transformationContext); Assert.assertEquals(executionResult.getType(), TOExecutionResult.Type.NO_OP); assertNotChangedFile("/src/main/resources/dogs.yaml"); }
@Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings (value="NP_ALWAYS_NULL_EXCEPTION") protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext); if (!fileToBeChanged.exists()) { FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found"); return TOExecutionResult.error(this, ex); } BufferedReader reader = null; BufferedWriter writer = null; TOExecutionResult result = null; try { final String eol = EolHelper.findEolDefaultToOs(fileToBeChanged); File readFile = getOrCreateReadFile(transformedAppFolder, transformationContext); reader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), StandardCharsets.UTF_8)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileToBeChanged), StandardCharsets.UTF_8)); switch (insertionMode) { case LINE_NUMBER: result = insertAtSpecificLine(reader, writer, eol); break; case REGEX_FIRST: result = insertRegex(reader, writer, true, true, eol); break; case REGEX_ALL: result = insertRegex(reader, writer, false, true, eol); break; case REGEX_BEFORE_FIRST: result = insertRegex(reader, writer, true, false, eol); break; case REGEX_BEFORE_ALL: result = insertRegex(reader, writer, false, false, eol); break; default: case CONCAT: result = concat(reader, writer, eol); break; } } catch (IOException e) { result = TOExecutionResult.error(this, e); } finally { try { if (writer != null) try { writer.close(); } catch (IOException e) { result.addWarning(e); } } finally { if(reader != null) try { reader.close(); } catch (IOException e) { result.addWarning(e); } } } return result; }
InsertLine extends TransformationOperation<InsertLine> { @Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings (value="NP_ALWAYS_NULL_EXCEPTION") protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext); if (!fileToBeChanged.exists()) { FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found"); return TOExecutionResult.error(this, ex); } BufferedReader reader = null; BufferedWriter writer = null; TOExecutionResult result = null; try { final String eol = EolHelper.findEolDefaultToOs(fileToBeChanged); File readFile = getOrCreateReadFile(transformedAppFolder, transformationContext); reader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), StandardCharsets.UTF_8)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileToBeChanged), StandardCharsets.UTF_8)); switch (insertionMode) { case LINE_NUMBER: result = insertAtSpecificLine(reader, writer, eol); break; case REGEX_FIRST: result = insertRegex(reader, writer, true, true, eol); break; case REGEX_ALL: result = insertRegex(reader, writer, false, true, eol); break; case REGEX_BEFORE_FIRST: result = insertRegex(reader, writer, true, false, eol); break; case REGEX_BEFORE_ALL: result = insertRegex(reader, writer, false, false, eol); break; default: case CONCAT: result = concat(reader, writer, eol); break; } } catch (IOException e) { result = TOExecutionResult.error(this, e); } finally { try { if (writer != null) try { writer.close(); } catch (IOException e) { result.addWarning(e); } } finally { if(reader != null) try { reader.close(); } catch (IOException e) { result.addWarning(e); } } } return result; } }
InsertLine extends TransformationOperation<InsertLine> { @Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings (value="NP_ALWAYS_NULL_EXCEPTION") protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext); if (!fileToBeChanged.exists()) { FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found"); return TOExecutionResult.error(this, ex); } BufferedReader reader = null; BufferedWriter writer = null; TOExecutionResult result = null; try { final String eol = EolHelper.findEolDefaultToOs(fileToBeChanged); File readFile = getOrCreateReadFile(transformedAppFolder, transformationContext); reader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), StandardCharsets.UTF_8)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileToBeChanged), StandardCharsets.UTF_8)); switch (insertionMode) { case LINE_NUMBER: result = insertAtSpecificLine(reader, writer, eol); break; case REGEX_FIRST: result = insertRegex(reader, writer, true, true, eol); break; case REGEX_ALL: result = insertRegex(reader, writer, false, true, eol); break; case REGEX_BEFORE_FIRST: result = insertRegex(reader, writer, true, false, eol); break; case REGEX_BEFORE_ALL: result = insertRegex(reader, writer, false, false, eol); break; default: case CONCAT: result = concat(reader, writer, eol); break; } } catch (IOException e) { result = TOExecutionResult.error(this, e); } finally { try { if (writer != null) try { writer.close(); } catch (IOException e) { result.addWarning(e); } } finally { if(reader != null) try { reader.close(); } catch (IOException e) { result.addWarning(e); } } } return result; } InsertLine();  InsertLine(String newLine);  InsertLine(String newLine, Integer lineNumber);  InsertLine(String newLine, String regex); }
InsertLine extends TransformationOperation<InsertLine> { @Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings (value="NP_ALWAYS_NULL_EXCEPTION") protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext); if (!fileToBeChanged.exists()) { FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found"); return TOExecutionResult.error(this, ex); } BufferedReader reader = null; BufferedWriter writer = null; TOExecutionResult result = null; try { final String eol = EolHelper.findEolDefaultToOs(fileToBeChanged); File readFile = getOrCreateReadFile(transformedAppFolder, transformationContext); reader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), StandardCharsets.UTF_8)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileToBeChanged), StandardCharsets.UTF_8)); switch (insertionMode) { case LINE_NUMBER: result = insertAtSpecificLine(reader, writer, eol); break; case REGEX_FIRST: result = insertRegex(reader, writer, true, true, eol); break; case REGEX_ALL: result = insertRegex(reader, writer, false, true, eol); break; case REGEX_BEFORE_FIRST: result = insertRegex(reader, writer, true, false, eol); break; case REGEX_BEFORE_ALL: result = insertRegex(reader, writer, false, false, eol); break; default: case CONCAT: result = concat(reader, writer, eol); break; } } catch (IOException e) { result = TOExecutionResult.error(this, e); } finally { try { if (writer != null) try { writer.close(); } catch (IOException e) { result.addWarning(e); } } finally { if(reader != null) try { reader.close(); } catch (IOException e) { result.addWarning(e); } } } return result; } InsertLine();  InsertLine(String newLine);  InsertLine(String newLine, Integer lineNumber);  InsertLine(String newLine, String regex); InsertLine setInsertionMode(InsertionMode insertionMode); InsertLine setNewLine(String newLine); InsertLine setLineNumber(Integer lineNumber); InsertLine setRegex(String regex); @Override String getDescription(); }
InsertLine extends TransformationOperation<InsertLine> { @Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings (value="NP_ALWAYS_NULL_EXCEPTION") protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext); if (!fileToBeChanged.exists()) { FileNotFoundException ex = new FileNotFoundException("File to be modified has not been found"); return TOExecutionResult.error(this, ex); } BufferedReader reader = null; BufferedWriter writer = null; TOExecutionResult result = null; try { final String eol = EolHelper.findEolDefaultToOs(fileToBeChanged); File readFile = getOrCreateReadFile(transformedAppFolder, transformationContext); reader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), StandardCharsets.UTF_8)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileToBeChanged), StandardCharsets.UTF_8)); switch (insertionMode) { case LINE_NUMBER: result = insertAtSpecificLine(reader, writer, eol); break; case REGEX_FIRST: result = insertRegex(reader, writer, true, true, eol); break; case REGEX_ALL: result = insertRegex(reader, writer, false, true, eol); break; case REGEX_BEFORE_FIRST: result = insertRegex(reader, writer, true, false, eol); break; case REGEX_BEFORE_ALL: result = insertRegex(reader, writer, false, false, eol); break; default: case CONCAT: result = concat(reader, writer, eol); break; } } catch (IOException e) { result = TOExecutionResult.error(this, e); } finally { try { if (writer != null) try { writer.close(); } catch (IOException e) { result.addWarning(e); } } finally { if(reader != null) try { reader.close(); } catch (IOException e) { result.addWarning(e); } } } return result; } InsertLine();  InsertLine(String newLine);  InsertLine(String newLine, Integer lineNumber);  InsertLine(String newLine, String regex); InsertLine setInsertionMode(InsertionMode insertionMode); InsertLine setNewLine(String newLine); InsertLine setLineNumber(Integer lineNumber); InsertLine setRegex(String regex); @Override String getDescription();  }