This commit is contained in:
Johannes Frohnmeyer 2022-11-15 20:35:00 +01:00
commit 848fbbafb5
Signed by: Johannes
GPG Key ID: E76429612C2929F4
10 changed files with 334 additions and 0 deletions

33
.gitignore vendored Normal file
View File

@ -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

30
build.gradle.kts Normal file
View File

@ -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<JavaCompile> {
options.compilerArgs.addAll(arrayOf("-Xplugin:Manifold no-bootstrap", "--module-path", classpath.asPath))
}
} else {
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(arrayOf("-Xplugin:Manifold no-bootstrap"))
}
}

2
settings.gradle.kts Normal file
View File

@ -0,0 +1,2 @@
rootProject.name = "manifold-example"

View File

@ -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 {
}

View File

@ -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;
}
}

View File

@ -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<Node> {
public static Iterator<Node> iterator(@This NodeList thiz) {
return new NodeListIterator(thiz);
}
public static Node get(@This NodeList thiz, int index) {
return thiz.item(index);
}
}

View File

@ -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");
}
}

View File

@ -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<Node> {
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++];
}
}

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.7.36</version>
</parent>
<artifactId>slf4j-api</artifactId>
<packaging>jar</packaging>
<name>SLF4J API Module</name>
<description>The slf4j API</description>
<url>http://www.slf4j.org</url>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<!-- Signatures cannot be determined and will error unless excluded. This is isolated to
code otherwise already marked for removal in the module artifact. -->
<ignores>
<ignore>org.slf4j.impl.StaticMDCBinder</ignore>
<ignore>org.slf4j.impl.StaticLoggerBinder</ignore>
<ignore>org.slf4j.impl.StaticMarkerBinder</ignore>
</ignores>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<reportFormat>plain</reportFormat>
<trimStackTrace>false</trimStackTrace>
<excludes>
<exclude>**/AllTest.java</exclude>
<exclude>**/PackageTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>bundle-test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<tasks>
<echo>Removing slf4j-api's dummy StaticLoggerBinder and StaticMarkerBinder</echo>
<delete dir="target/classes/org/slf4j/impl"/>
</tasks>
</configuration>
</plugin>
</plugins>
</build>
</project>