From d61f74780490b2dc4f0fd1922f45b15ddd701ba5 Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Thu, 25 Jul 2024 23:31:56 +0200 Subject: [PATCH] 2.1.1 release - multiple fixes --- README.md | 7 ++++--- src/main/java/JPM.java | 37 +++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5e582c1..2757242 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,15 @@ Meaning instead of writing XML (Maven) or Groovy/DSL (Gradle), your build file i - Earlier Java versions are not supported You can also clone/download this repository since it also functions as a template. -Note that 1JPM is now a Maven pom.xml generator, since the complexity as a fully independent build tool -(see version [1.0.3](https://github.com/Osiris-Team/1JPM/blob/1.0.3/src/main/java/JPM.java)) was too high for a single file. +Note that 1JPM is now using Maven under the hood, since the complexity as a fully independent build tool +(see version [1.0.3](https://github.com/Osiris-Team/1JPM/blob/1.0.3/src/main/java/JPM.java)) was too high for a single file. It will download and use the Maven-Wrapper. Below you can see the example configuration which runs the `clean package` tasks. This compiles and creates a jar file from your code, and additionally creates the sources, javadoc and with-dependencies jars. -Third-party plugins can be added simply by appending their Java code inside ThirdPartyPlugins. +A 1JPM plugin is basically a wrapper around a Maven plugin (its xml), providing easy access to its features. +These third-party plugins can be added simply by appending their Java code inside ThirdPartyPlugins. You can find a list here at [#1jpm-plugin](https://github.com/topics/1jpm-plugin?o=desc&s=updated). (these must be written in Java 8 and not use external dependencies). diff --git a/src/main/java/JPM.java b/src/main/java/JPM.java index 95925e4..7ad8e69 100644 --- a/src/main/java/JPM.java +++ b/src/main/java/JPM.java @@ -47,7 +47,7 @@ class ThirdPartyPlugins extends JPM.Plugins{ // (If you want to develop a plugin take a look at "JPM.Clean" class further below to get started) } -// 1JPM version 2.1.0 by Osiris-Team: https://github.com/Osiris-Team/1JPM +// 1JPM version 2.1.1 by Osiris-Team: https://github.com/Osiris-Team/1JPM // To upgrade JPM, replace the JPM class below with its newer version public class JPM { public static final List plugins = new ArrayList<>(); @@ -197,9 +197,16 @@ public Repository(String id, String url) { } public static Repository fromUrl(String url){ - String id = url.split("//")[0].split("/")[0].replace(".", "").replace("-", ""); + String id = url.split("//")[1].split("/")[0].replace(".", "").replace("-", ""); return new Repository(id, url); } + + public XML toXML(){ + XML xml = new XML("repository"); + xml.put("id", id); + xml.put("url", url); + return xml; + } } public static class XML { @@ -282,19 +289,26 @@ public XML putAttributes(String key, Map attributes) { // Helper method to traverse or create elements based on a path. private Element getOrCreateElement(String key) { - if(key == null || key.trim().isEmpty()) return root; + if (key == null || key.trim().isEmpty()) return root; String[] path = key.split(" "); Element currentElement = root; for (String nodeName : path) { - NodeList children = currentElement.getElementsByTagName(nodeName); - if (children.getLength() > 0) { - currentElement = (Element) children.item(0); - } else { - Element newElement = document.createElement(nodeName); - currentElement.appendChild(newElement); - currentElement = newElement; + Element childElement = null; + NodeList children = currentElement.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(nodeName)) { + childElement = (Element) child; + break; + } + } + + if (childElement == null) { + childElement = document.createElement(nodeName); + currentElement.appendChild(childElement); } + currentElement = childElement; } return currentElement; @@ -549,8 +563,7 @@ public void generatePom() throws IOException { // Add if not empty if (!repositories.isEmpty()) { for (Repository rep : repositories) { - pom.put("repositories repository id", rep.id); - pom.put("repositories repository url", rep.url); + pom.add("repositories", rep.toXML()); } }