commit 848fbbafb536814be419776282d5619a4ccca115 Author: JFronny Date: Tue Nov 15 20:35:00 2022 +0100 Example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fc7603 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..4df2235 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + id("java") +} + +group = "io.gitlab.jfronny" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + val manifoldVersion = "2022.1.23" + + implementation("systems.manifold:manifold-props-rt:$manifoldVersion") + + testAnnotationProcessor(annotationProcessor("systems.manifold:manifold-ext:$manifoldVersion")!!) + testAnnotationProcessor(annotationProcessor("systems.manifold:manifold-props:$manifoldVersion")!!) + testAnnotationProcessor(annotationProcessor("systems.manifold:manifold-strings:$manifoldVersion")!!) +} + +if (sourceSets.main.get().allJava.files.any {it.name == "module-info.java"}) { + tasks.withType { + options.compilerArgs.addAll(arrayOf("-Xplugin:Manifold no-bootstrap", "--module-path", classpath.asPath)) + } +} else { + tasks.withType { + options.compilerArgs.addAll(arrayOf("-Xplugin:Manifold no-bootstrap")) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..0230f6d --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,2 @@ +rootProject.name = "manifold-example" + diff --git a/src/main/java/extensions/java/lang/Iterable/StructuralIterable.java b/src/main/java/extensions/java/lang/Iterable/StructuralIterable.java new file mode 100644 index 0000000..5e3d1ef --- /dev/null +++ b/src/main/java/extensions/java/lang/Iterable/StructuralIterable.java @@ -0,0 +1,9 @@ +package extensions.java.lang.Iterable; + +import manifold.ext.rt.api.Extension; +import manifold.ext.rt.api.Structural; + +@Extension +@Structural +public class StructuralIterable { +} diff --git a/src/main/java/extensions/org/w3c/dom/Node/NodeExt.java b/src/main/java/extensions/org/w3c/dom/Node/NodeExt.java new file mode 100644 index 0000000..45ad5fc --- /dev/null +++ b/src/main/java/extensions/org/w3c/dom/Node/NodeExt.java @@ -0,0 +1,14 @@ +package extensions.org.w3c.dom.Node; + +import manifold.ext.rt.api.Extension; +import manifold.ext.rt.api.This; +import org.w3c.dom.Node; + +@Extension +public class NodeExt { + public static boolean isWhitespace(@This Node thiz) { + if (thiz.nodeType == Node.TEXT_NODE && thiz.textContent.isBlank()) return true; + if (thiz.nodeType == Node.COMMENT_NODE) return true; + return false; + } +} diff --git a/src/main/java/extensions/org/w3c/dom/NodeList/NodeListExt.java b/src/main/java/extensions/org/w3c/dom/NodeList/NodeListExt.java new file mode 100644 index 0000000..96ea000 --- /dev/null +++ b/src/main/java/extensions/org/w3c/dom/NodeList/NodeListExt.java @@ -0,0 +1,20 @@ +package extensions.org.w3c.dom.NodeList; + +import io.gitlab.jfronny.inceptum.common.dom.NodeListIterator; +import manifold.ext.rt.api.Extension; +import manifold.ext.rt.api.This; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.Iterator; + +@Extension +public abstract class NodeListExt implements Iterable { + public static Iterator iterator(@This NodeList thiz) { + return new NodeListIterator(thiz); + } + + public static Node get(@This NodeList thiz, int index) { + return thiz.item(index); + } +} diff --git a/src/main/java/io/gitlab/jfronny/inceptum/Main.java b/src/main/java/io/gitlab/jfronny/inceptum/Main.java new file mode 100644 index 0000000..29c6d30 --- /dev/null +++ b/src/main/java/io/gitlab/jfronny/inceptum/Main.java @@ -0,0 +1,85 @@ +package io.gitlab.jfronny.inceptum; + +import io.gitlab.jfronny.inceptum.common.model.maven.Pom; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import javax.xml.parsers.*; +import java.io.IOException; +import java.io.InputStream; + +public class Main { + private static final DocumentBuilder FACTORY; + + static { + try { + FACTORY = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RuntimeException("Could not create document builder", e); + } + } + + public static void main(String[] args) throws IOException, SAXException { + Pom result; + try (InputStream is = Main.class.getResourceAsStream("/ExamplePom.xml")) { + Document doc = FACTORY.parse(is); + doc.documentElement.normalize(); + result = new Pom(); + if (!"project".equals(doc.documentElement.nodeName)) throw new IOException("Illegal document name"); + boolean hasModelVersion = false; + boolean hasGroupId = false; + boolean hasArtifactId = false; + boolean hasVersion = false; + for (Node node : doc.documentElement.childNodes) { + switch (node.nodeName) { + case "modelVersion" -> { + hasModelVersion = true; + result.modelVersion = node.textContent; + } + case "parent" -> { + // Dirty hack to get slf4j working: simply assume the groupId and version of the parent is also the groupId of this + if (!hasGroupId) { + for (Node child : node.childNodes) { + switch (child.nodeName) { + case "groupId" -> { + if (!hasGroupId) { + hasGroupId = true; + result.groupId = node.textContent; + } + } + case "version" -> { + if (!hasVersion) { + hasVersion = true; + result.version = node.textContent; + } + } + } + } + } + } + case "groupId" -> { + hasGroupId = true; + result.groupId = node.textContent; + } + case "artifactId" -> { + hasArtifactId = true; + result.artifactId = node.textContent; + } + case "version" -> { + hasVersion = true; + result.version = node.textContent; + } + case "packaging" -> result.packaging = node.textContent; + case "classifier" -> result.classifier = node.textContent; + default -> {} + } + } + if (!hasModelVersion) throw new IOException("Pom lacks modelVersion"); + if (!hasGroupId) throw new IOException("Pom lacks groupId"); + if (!hasArtifactId) throw new IOException("Pom lacks artifactId"); + if (!hasVersion) throw new IOException("Pom lacks version"); + } + System.out.println("Parsed: $result"); + } +} diff --git a/src/main/java/io/gitlab/jfronny/inceptum/common/dom/NodeListIterator.java b/src/main/java/io/gitlab/jfronny/inceptum/common/dom/NodeListIterator.java new file mode 100644 index 0000000..466437f --- /dev/null +++ b/src/main/java/io/gitlab/jfronny/inceptum/common/dom/NodeListIterator.java @@ -0,0 +1,30 @@ +package io.gitlab.jfronny.inceptum.common.dom; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +public class NodeListIterator implements Iterator { + private final NodeList list; + private int index = 0; + + public NodeListIterator(NodeList list) { + this.list = list; + } + + @Override + public boolean hasNext() { + while (index < list.length && list[index].isWhitespace()) { + index++; + } + return index < list.length; + } + + @Override + public Node next() { + if (!hasNext()) throw new NoSuchElementException(); + return list[index++]; + } +} diff --git a/src/main/java/io/gitlab/jfronny/inceptum/common/model/maven/Pom.java b/src/main/java/io/gitlab/jfronny/inceptum/common/model/maven/Pom.java new file mode 100644 index 0000000..df1f707 --- /dev/null +++ b/src/main/java/io/gitlab/jfronny/inceptum/common/model/maven/Pom.java @@ -0,0 +1,26 @@ +package io.gitlab.jfronny.inceptum.common.model.maven; + +import java.util.List; + +public class Pom { + public String modelVersion; + public String groupId; + public String artifactId; + public String version; + public String classifier; + public String snapshotVersion; + public String packaging; + + @Override + public String toString() { + return "Pom{" + + "modelVersion='" + modelVersion + '\'' + + ", groupId='" + groupId + '\'' + + ", artifactId='" + artifactId + '\'' + + ", version='" + version + '\'' + + ", classifier='" + classifier + '\'' + + ", snapshotVersion='" + snapshotVersion + '\'' + + ", packaging='" + packaging + '\'' + + '}'; + } +} diff --git a/src/main/resources/ExamplePom.xml b/src/main/resources/ExamplePom.xml new file mode 100644 index 0000000..6ff987c --- /dev/null +++ b/src/main/resources/ExamplePom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + + org.slf4j + slf4j-parent + 1.7.36 + + + slf4j-api + + jar + SLF4J API Module + The slf4j API + + http://www.slf4j.org + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + + org.slf4j.impl.StaticMDCBinder + org.slf4j.impl.StaticLoggerBinder + org.slf4j.impl.StaticMarkerBinder + + + + + org.apache.maven.plugins + maven-surefire-plugin + + once + plain + false + + **/AllTest.java + **/PackageTest.java + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + bundle-test-jar + package + + test-jar + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + process-classes + + run + + + + + + Removing slf4j-api's dummy StaticLoggerBinder and StaticMarkerBinder + + + + + + + + \ No newline at end of file