Skip to content

Commit

Permalink
2.1.1 release
Browse files Browse the repository at this point in the history
- multiple fixes
  • Loading branch information
Osiris-Team committed Jul 25, 2024
1 parent 4a09f02 commit d61f747
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
37 changes: 25 additions & 12 deletions src/main/java/JPM.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Plugin> plugins = new ArrayList<>();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -282,19 +289,26 @@ public XML putAttributes(String key, Map<String, String> 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;
Expand Down Expand Up @@ -549,8 +563,7 @@ public void generatePom() throws IOException {
// Add <repositories> 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());
}
}

Expand Down

0 comments on commit d61f747

Please sign in to comment.