Java Code Examples for org.apache.maven.model.Model#removeDependency()
The following examples show how to use
org.apache.maven.model.Model#removeDependency() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PomRemoveDependency.java From butterfly with MIT License | 5 votes |
@Override protected TOExecutionResult pomExecution(String relativePomFile, Model model) { TOExecutionResult result = null; String details; Dependency dependency = getDependency(model, groupId, artifactId); if (dependency != null) { model.removeDependency(dependency); details = String.format("Dependency %s:%s has been removed from POM file %s", groupId, artifactId, relativePomFile); result = TOExecutionResult.success(this, details); } else { details = String.format("Dependency %s:%s has NOT been removed from POM file %s because it is not present", groupId, artifactId, relativePomFile); switch (ifNotPresent) { case Warn: result = TOExecutionResult.warning(this, new TransformationOperationException(details)); break; case NoOp: result = TOExecutionResult.noOp(this, details); break; case Fail: // Fail is the default default: result = TOExecutionResult.error(this, new TransformationOperationException(details)); break; } } return result; }
Example 2
Source File: PomChangeDependency.java From butterfly with MIT License | 5 votes |
@Override protected TOExecutionResult pomExecution(String relativePomFile, Model model) { TOExecutionResult result; Dependency dependency = getDependency(model, groupId, artifactId); if (dependency != null) { model.removeDependency(dependency); if (removeVersion) dependency.setVersion(null); else if (version != null) dependency.setVersion(version); if (removeScope) dependency.setScope(null); else if (scope != null) dependency.setScope(scope); if (removeType) dependency.setType(null); else if (type != null) dependency.setType(type); if (removeOptional) dependency.setOptional(null); else if (optional != null) dependency.setOptional(optional); model.addDependency(dependency); String details = String.format("Dependency %s:%s has been changed in %s", groupId, artifactId, getRelativePath()); result = TOExecutionResult.success(this, details); } else { String message = String.format("Dependency %s:%s is not present in %s", groupId, artifactId, getRelativePath()); switch (ifNotPresent) { case Warn: result = TOExecutionResult.warning(this, new TransformationOperationException(message)); break; case NoOp: result = TOExecutionResult.noOp(this, message); break; case Fail: // Fail is the default default: result = TOExecutionResult.error(this, new TransformationOperationException(message)); break; } } return result; }
Example 3
Source File: PomReplaceDependency.java From butterfly with MIT License | 4 votes |
@Override protected TOExecutionResult pomExecution(String relativePomFile, Model model) { TOExecutionResult result = null; String details; Dependency oldDependency = getDependency(model, groupId, artifactId); if (oldDependency != null) { model.removeDependency(oldDependency); Dependency newDependency = new Dependency(); newDependency.setGroupId(newGroupId); newDependency.setArtifactId(newArtifactId); if (newVersion != null) { newDependency.setVersion(newVersion); } if (newScope != null) { newDependency.setScope(newScope); } else { newDependency.setScope(oldDependency.getScope()); } model.addDependency(newDependency); details = String.format("Dependency %s:%s has been replaced by %s:%s in POM file %s", groupId, artifactId, newGroupId, newArtifactId, relativePomFile); result = TOExecutionResult.success(this, details); } else { details = String.format("Dependency %s:%s has not been replaced by %s:%s in POM file %s because it is not present", groupId, artifactId, newGroupId, newArtifactId, relativePomFile); switch (ifNotPresent) { case Warn: result = TOExecutionResult.warning(this, new TransformationOperationException(details)); break; case NoOp: result = TOExecutionResult.noOp(this, details); break; case Fail: // Fail is the default default: result = TOExecutionResult.error(this, new TransformationOperationException(details)); break; } } return result; }