@Test public void testAddPluginRepoPrevious() { Path filePath = Paths.get("./src/test/resources/pom-examples", "test-plugin-repository.xml"); File tempDir = com.google.common.io.Files.createTempDir(); Path tempFile = Paths.get(tempDir.toPath().toString(), filePath.getFileName().toString()); try { Files.copy(filePath, tempFile); } catch (IOException e) { System.err.println("Something went wrong when copying the pom-file."); } String fileName = tempFile.toString(); try { POMModifier.addPluginRepo(fileName, "test-plugin-id", "test-plugin-name", "test-plugin-url"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fileName); Node node = doc.getElementsByTagName("pluginRepositories").item(0); assertTrue(node != null); NodeList nodes = node.getChildNodes(); nodes = nodes.item(3).getChildNodes(); System.out.println(nodes.item(1).getTextContent()); assertTrue(nodes.item(1).getTextContent().equals("test-plugin-id")); assertTrue(nodes.item(3).getTextContent().equals("test-plugin-name")); assertTrue(nodes.item(5).getTextContent().equals("test-plugin-url")); } catch (ParserConfigurationException | SAXException | IOException | TransformerException e) { e.printStackTrace(); } }
public static void addPluginRepo(String fileName, String id, String name, String url) throws ParserConfigurationException, SAXException, IOException, TransformerException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); Element root = doc.getDocumentElement(); Node pluginRepos = doc.getElementsByTagName("pluginRepositories").item(0); if(pluginRepos == null) { pluginRepos = doc.createElement("pluginRepositories"); root.appendChild(pluginRepos); } Node repairRepo = doc.createElement("pluginRepository"); pluginRepos.appendChild(repairRepo); Node repoId = doc.createElement("id"); repoId.setTextContent(id); Node repoName = doc.createElement("name"); repoName.setTextContent(name); Node repoUrl = doc.createElement("url"); repoUrl.setTextContent(url); repairRepo.appendChild(repoId); repairRepo.appendChild(repoName); repairRepo.appendChild(repoUrl); replaceFile(fileName, doc); }
POMModifier { public static void addPluginRepo(String fileName, String id, String name, String url) throws ParserConfigurationException, SAXException, IOException, TransformerException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); Element root = doc.getDocumentElement(); Node pluginRepos = doc.getElementsByTagName("pluginRepositories").item(0); if(pluginRepos == null) { pluginRepos = doc.createElement("pluginRepositories"); root.appendChild(pluginRepos); } Node repairRepo = doc.createElement("pluginRepository"); pluginRepos.appendChild(repairRepo); Node repoId = doc.createElement("id"); repoId.setTextContent(id); Node repoName = doc.createElement("name"); repoName.setTextContent(name); Node repoUrl = doc.createElement("url"); repoUrl.setTextContent(url); repairRepo.appendChild(repoId); repairRepo.appendChild(repoName); repairRepo.appendChild(repoUrl); replaceFile(fileName, doc); } }
POMModifier { public static void addPluginRepo(String fileName, String id, String name, String url) throws ParserConfigurationException, SAXException, IOException, TransformerException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); Element root = doc.getDocumentElement(); Node pluginRepos = doc.getElementsByTagName("pluginRepositories").item(0); if(pluginRepos == null) { pluginRepos = doc.createElement("pluginRepositories"); root.appendChild(pluginRepos); } Node repairRepo = doc.createElement("pluginRepository"); pluginRepos.appendChild(repairRepo); Node repoId = doc.createElement("id"); repoId.setTextContent(id); Node repoName = doc.createElement("name"); repoName.setTextContent(name); Node repoUrl = doc.createElement("url"); repoUrl.setTextContent(url); repairRepo.appendChild(repoId); repairRepo.appendChild(repoName); repairRepo.appendChild(repoUrl); replaceFile(fileName, doc); }  }
POMModifier { public static void addPluginRepo(String fileName, String id, String name, String url) throws ParserConfigurationException, SAXException, IOException, TransformerException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); Element root = doc.getDocumentElement(); Node pluginRepos = doc.getElementsByTagName("pluginRepositories").item(0); if(pluginRepos == null) { pluginRepos = doc.createElement("pluginRepositories"); root.appendChild(pluginRepos); } Node repairRepo = doc.createElement("pluginRepository"); pluginRepos.appendChild(repairRepo); Node repoId = doc.createElement("id"); repoId.setTextContent(id); Node repoName = doc.createElement("name"); repoName.setTextContent(name); Node repoUrl = doc.createElement("url"); repoUrl.setTextContent(url); repairRepo.appendChild(repoId); repairRepo.appendChild(repoName); repairRepo.appendChild(repoUrl); replaceFile(fileName, doc); }  static void addPluginRepo(String fileName, String id, String name, String url); static void removePluginRepo(String fileName, String id); }
POMModifier { public static void addPluginRepo(String fileName, String id, String name, String url) throws ParserConfigurationException, SAXException, IOException, TransformerException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); Element root = doc.getDocumentElement(); Node pluginRepos = doc.getElementsByTagName("pluginRepositories").item(0); if(pluginRepos == null) { pluginRepos = doc.createElement("pluginRepositories"); root.appendChild(pluginRepos); } Node repairRepo = doc.createElement("pluginRepository"); pluginRepos.appendChild(repairRepo); Node repoId = doc.createElement("id"); repoId.setTextContent(id); Node repoName = doc.createElement("name"); repoName.setTextContent(name); Node repoUrl = doc.createElement("url"); repoUrl.setTextContent(url); repairRepo.appendChild(repoId); repairRepo.appendChild(repoName); repairRepo.appendChild(repoUrl); replaceFile(fileName, doc); }  static void addPluginRepo(String fileName, String id, String name, String url); static void removePluginRepo(String fileName, String id);  }