Skip to content

Commit

Permalink
Test of dependency loading capability
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlasov committed Sep 11, 2024
1 parent 6c08611 commit c39aac8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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>
<groupId>org.nasdanika</groupId>
<version>2024.8.0</version>
<version>2024.9.0-SNAPSHOT</version>
<artifactId>cli-launcher</artifactId>
<packaging>jar</packaging>
<name>Nasdanika CLI launcher</name>
Expand All @@ -27,7 +27,7 @@
<dependency>
<groupId>org.nasdanika.html</groupId>
<artifactId>app-model-gen-cli</artifactId>
<version>2024.8.0</version>
<version>2024.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nasdanika.models.java</groupId>
Expand All @@ -47,7 +47,12 @@
<dependency>
<groupId>org.nasdanika.core</groupId>
<artifactId>http</artifactId>
<version>2024.8.0</version>
<version>2024.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nasdanika.core</groupId>
<artifactId>maven</artifactId>
<version>2024.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nasdanika.models.echarts</groupId>
Expand All @@ -58,8 +63,15 @@
<groupId>org.nasdanika.models.ecore</groupId>
<artifactId>cli</artifactId>
<version>2024.8.0</version>
</dependency>
</dependency>

<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>4.0.22</version>
<type>pom</type>
</dependency>

<!-- To prevent slf4j complaining -->
<!--
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.nasdanika.launcher.tests;

import java.io.File;
import java.util.Collection;

import org.junit.jupiter.api.Test;
import org.nasdanika.capability.CapabilityLoader;
import org.nasdanika.capability.CapabilityProvider;
import org.nasdanika.capability.maven.DependencyRequestRecord;
import org.nasdanika.common.PrintStreamProgressMonitor;
import org.nasdanika.common.ProgressMonitor;

public class TestDependencyAndObjectLoading {

@Test
public void testDependencyLoading() {
CapabilityLoader capabilityLoader = new CapabilityLoader();
DependencyRequestRecord requirement = new DependencyRequestRecord(
new String[] { "org.apache.groovy:groovy-all:pom:4.0.22" },
null,
null,
"target/test-repo");

ProgressMonitor progressMonitor = new PrintStreamProgressMonitor();
Iterable<CapabilityProvider<Object>> cpi = capabilityLoader.load(requirement, progressMonitor);
for (CapabilityProvider<Object> cp: cpi) {
@SuppressWarnings("unchecked")
Collection<File> result = (Collection<File>) cp.getPublisher().blockFirst();
System.out.println(result);
}
}

}
44 changes: 44 additions & 0 deletions src/test/java/org/nasdanika/launcher/tests/TestGroovy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.nasdanika.launcher.tests;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.junit.jupiter.api.Test;

public class TestGroovy {

@Test
public void testAnnotations() throws ScriptException {
String source = """
class MyProcessor {
@org.nasdanika.graph.processor.Processor
def annotatedMethod() {
z
}
}
new MyProcessor();
""";

ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine scriptEngine = sem.getEngineByName("groovy");
scriptEngine.put("z", 185);
Object result = scriptEngine.eval(source);
System.out.println(result);
for (Method method: result.getClass().getDeclaredMethods()) {
System.out.println(method);
for (Annotation annotation: method.getAnnotations()) {
System.out.println("\t" + annotation);
}
}
}

}

0 comments on commit c39aac8

Please sign in to comment.