@Test public void existentNoOpTest() { TOExecutionResult executionResult = new PomFile(model).relative("/").noOpIfPresent().execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.NO_OP); assertNull(executionResult.getException()); assertEquals(executionResult.getDetails(), "There is already a pom file at /"); }
@Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { if (attribute != null) { if (!transformationContext.contains(attribute)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " does not exist")); } Object modelObj = transformationContext.get(attribute); if (modelObj == null) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is null")); } if (!(modelObj instanceof Model)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is not a Model object, but " + modelObj.getClass().getName())); } model = (Model) modelObj; } else if (model == null) { return TOExecutionResult.error(this, new TransformationOperationException("Neither transformation context attribute nor Model object were specified")); } File pomFile = new File(getAbsoluteFile(transformedAppFolder, transformationContext), "pom.xml"); TOExecutionResult errorResult; if (pomFile.exists()) { switch (ifPresent) { case Fail: return TOExecutionResult.error(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case WarnNotAdd: return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case NoOp: return TOExecutionResult.noOp(this, "There is already a pom file at " + getRelativePath()); case WarnButAdd: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath()), "Pom file overwritten at " + getRelativePath()); case Overwrite: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file overwritten at " + getRelativePath()); } } else { try { pomFile.createNewFile(); } catch (IOException e) { return TOExecutionResult.error(this, new TransformationOperationException("There was an error when creating pom.xml file at " + getRelativePath() + ", double check if that directory exists")); } } errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file written at " + getRelativePath()); }
PomFile extends AddElementTO<PomFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { if (attribute != null) { if (!transformationContext.contains(attribute)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " does not exist")); } Object modelObj = transformationContext.get(attribute); if (modelObj == null) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is null")); } if (!(modelObj instanceof Model)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is not a Model object, but " + modelObj.getClass().getName())); } model = (Model) modelObj; } else if (model == null) { return TOExecutionResult.error(this, new TransformationOperationException("Neither transformation context attribute nor Model object were specified")); } File pomFile = new File(getAbsoluteFile(transformedAppFolder, transformationContext), "pom.xml"); TOExecutionResult errorResult; if (pomFile.exists()) { switch (ifPresent) { case Fail: return TOExecutionResult.error(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case WarnNotAdd: return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case NoOp: return TOExecutionResult.noOp(this, "There is already a pom file at " + getRelativePath()); case WarnButAdd: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath()), "Pom file overwritten at " + getRelativePath()); case Overwrite: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file overwritten at " + getRelativePath()); } } else { try { pomFile.createNewFile(); } catch (IOException e) { return TOExecutionResult.error(this, new TransformationOperationException("There was an error when creating pom.xml file at " + getRelativePath() + ", double check if that directory exists")); } } errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file written at " + getRelativePath()); } }
PomFile extends AddElementTO<PomFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { if (attribute != null) { if (!transformationContext.contains(attribute)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " does not exist")); } Object modelObj = transformationContext.get(attribute); if (modelObj == null) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is null")); } if (!(modelObj instanceof Model)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is not a Model object, but " + modelObj.getClass().getName())); } model = (Model) modelObj; } else if (model == null) { return TOExecutionResult.error(this, new TransformationOperationException("Neither transformation context attribute nor Model object were specified")); } File pomFile = new File(getAbsoluteFile(transformedAppFolder, transformationContext), "pom.xml"); TOExecutionResult errorResult; if (pomFile.exists()) { switch (ifPresent) { case Fail: return TOExecutionResult.error(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case WarnNotAdd: return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case NoOp: return TOExecutionResult.noOp(this, "There is already a pom file at " + getRelativePath()); case WarnButAdd: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath()), "Pom file overwritten at " + getRelativePath()); case Overwrite: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file overwritten at " + getRelativePath()); } } else { try { pomFile.createNewFile(); } catch (IOException e) { return TOExecutionResult.error(this, new TransformationOperationException("There was an error when creating pom.xml file at " + getRelativePath() + ", double check if that directory exists")); } } errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file written at " + getRelativePath()); } PomFile();  PomFile(String attribute);  PomFile(Model model); }
PomFile extends AddElementTO<PomFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { if (attribute != null) { if (!transformationContext.contains(attribute)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " does not exist")); } Object modelObj = transformationContext.get(attribute); if (modelObj == null) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is null")); } if (!(modelObj instanceof Model)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is not a Model object, but " + modelObj.getClass().getName())); } model = (Model) modelObj; } else if (model == null) { return TOExecutionResult.error(this, new TransformationOperationException("Neither transformation context attribute nor Model object were specified")); } File pomFile = new File(getAbsoluteFile(transformedAppFolder, transformationContext), "pom.xml"); TOExecutionResult errorResult; if (pomFile.exists()) { switch (ifPresent) { case Fail: return TOExecutionResult.error(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case WarnNotAdd: return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case NoOp: return TOExecutionResult.noOp(this, "There is already a pom file at " + getRelativePath()); case WarnButAdd: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath()), "Pom file overwritten at " + getRelativePath()); case Overwrite: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file overwritten at " + getRelativePath()); } } else { try { pomFile.createNewFile(); } catch (IOException e) { return TOExecutionResult.error(this, new TransformationOperationException("There was an error when creating pom.xml file at " + getRelativePath() + ", double check if that directory exists")); } } errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file written at " + getRelativePath()); } PomFile();  PomFile(String attribute);  PomFile(Model model); PomFile setAttribute(String attribute); PomFile setModel(Model model); String getAttribute(); Model getModel(); @Override String getDescription(); }
PomFile extends AddElementTO<PomFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { if (attribute != null) { if (!transformationContext.contains(attribute)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " does not exist")); } Object modelObj = transformationContext.get(attribute); if (modelObj == null) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is null")); } if (!(modelObj instanceof Model)) { return TOExecutionResult.error(this, new TransformationOperationException("Transformation context attribute " + attribute + " is not a Model object, but " + modelObj.getClass().getName())); } model = (Model) modelObj; } else if (model == null) { return TOExecutionResult.error(this, new TransformationOperationException("Neither transformation context attribute nor Model object were specified")); } File pomFile = new File(getAbsoluteFile(transformedAppFolder, transformationContext), "pom.xml"); TOExecutionResult errorResult; if (pomFile.exists()) { switch (ifPresent) { case Fail: return TOExecutionResult.error(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case WarnNotAdd: return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath())); case NoOp: return TOExecutionResult.noOp(this, "There is already a pom file at " + getRelativePath()); case WarnButAdd: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.warning(this, new TransformationOperationException("There is already a pom file at " + getRelativePath()), "Pom file overwritten at " + getRelativePath()); case Overwrite: errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file overwritten at " + getRelativePath()); } } else { try { pomFile.createNewFile(); } catch (IOException e) { return TOExecutionResult.error(this, new TransformationOperationException("There was an error when creating pom.xml file at " + getRelativePath() + ", double check if that directory exists")); } } errorResult = writePomFile(pomFile); if (errorResult != null) return errorResult; return TOExecutionResult.success(this, "Pom file written at " + getRelativePath()); } PomFile();  PomFile(String attribute);  PomFile(Model model); PomFile setAttribute(String attribute); PomFile setModel(Model model); String getAttribute(); Model getModel(); @Override String getDescription();  }