private String removeChild(String xml) { tempModel.getStructuredDocument().setText(StructuredModelManager.getModelManager(), xml); Document doc = tempModel.getDocument(); Element parent = doc.getDocumentElement(); Element child = PomEdits.findChild(parent, PomEdits.BUILD); PomEdits.removeChild(parent, child); return tempModel.getStructuredDocument().getText(); }
private static void assertDependencyChild( String msg, String groupId, String artifactId, String tag, Element dep) { if (groupId != null) { assertEquals(msg + ":groupId", groupId, PomEdits.getTextValue(findChild(dep, "groupId"))); } else { assertNull(msg + ":groupId", findChild(dep, "groupId")); } if (artifactId != null) { assertEquals( msg + ":artifactId", artifactId, PomEdits.getTextValue(findChild(dep, "artifactId"))); } else { assertNull(msg + ":artifactId", findChild(dep, "artifactId")); } assertNotNull(msg + ":tag", findChild(dep, tag)); }
public void testAddExclusion_existingExclusion() throws Exception { document.setText( StructuredModelManager.getModelManager(), // "<project><dependencies>" + // "<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "<dependency><groupId>AAA</groupId><artifactId>BBBB</artifactId><version>1.0</version>" + // "<exclusions><exclusion><groupId>g</groupId><artifactId>b</artifactId><version>1.0</version></exclusion></exclusions></dependency>" + // "</dependencies></project>"); PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new AddExclusionOperation(d, e))); assertEquals( "Expected no dependency: " + d.toString() + "\n" + document.getText(), 1, dependencyCount(tempModel, d)); assertTrue( "Has exclusion " + e.toString() + "\n" + document.getText(), hasExclusion(tempModel, d, e)); ArtifactKey key = new ArtifactKey("g", "b", "1.0", null); assertTrue( "Existing Exclusion Present " + key.toString() + "\n" + document.getText(), hasExclusion(tempModel, d, key)); assertEquals("Exclusions", 2, getExclusionCount(tempModel, d)); assertEquals("Dependency Count: \n" + document.getText(), 3, getDependencyCount(tempModel)); }
private String getTextChild(Element depEl, String name) { Element child = findChild(depEl, name); if (child != null) { return PomEdits.getTextValue(child); } return null; }
public void testMissingDependency_noDependenciesElement() throws Exception { document.setText( StructuredModelManager.getModelManager(), // "<project></project>"); PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new AddExclusionOperation(d, e))); assertEquals( "Expected no dependency: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d)); }
public Element find(Document document) { Element toRet = null; Element parent = document.getDocumentElement(); for (String pathEl : path) { toRet = PomEdits.findChild(parent, pathEl); if (toRet == null) { return null; } parent = toRet; } return toRet; }
public void testMissingDependency_withDependencies() throws Exception { document.setText( StructuredModelManager.getModelManager(), // "<project><dependencies>" + // "<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + // "</dependencies></project>"); PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new AddExclusionOperation(d, e))); assertEquals( "Expected no dependency: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d)); assertEquals("Dependency Count: \n" + document.getText(), 2, getDependencyCount(tempModel)); }
/** * finds exactly one (first) occurence of child element with the given name (eg. dependency) that * fulfills conditions expressed by the Matchers (eg. groupId/artifactId match) * * @param parent * @param name * @param matchers * @return */ public static Element findChild(Element parent, String name, PomEdits.Matcher... matchers) { return PomEdits.findChild(parent, name, matchers); }
public static String getTextValue(Node element) { return PomEdits.getTextValue(element); }
public static List<Element> findChilds(Element parent, String name) { return PomEdits.findChilds(parent, name); }
public static Element findChild(Element parent, String name) { return PomEdits.findChild(parent, name); }
public String getValue(Document document) { return PomEdits.getTextValue(find(document)); }
public Element get(Document document) { return PomEdits.getChild(document.getDocumentElement(), path); }