Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 420a834

Browse files
committed
Skunkworks testing: Java as a docs language
* Configure Kotlin and Java sources to coexist in the testsuite * Make a real Java port of an existing Kotlin test * Hook Java snippets into docs * Add Java support to Shnippet * Configure Docusaurus CodeBlock component for Java syntax highlighting * Add Java support to CodeSnippet component
1 parent 0ac70f1 commit 420a834

File tree

7 files changed

+165
-11
lines changed

7 files changed

+165
-11
lines changed

shnippet.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"rootDirectory": "./site/testsuites",
33
"outputDirectory": "./site/snippets",
4-
"fileExtensions": [".js", ".ts", ".kt", ".gradle", ".xml", ".bash"],
4+
"fileExtensions": [".java", ".js", ".ts", ".kt", ".gradle", ".xml", ".bash"],
55
"exclude": ["pfiOverviewReadOfferingsJs", "pfiOverviewWriteJs", "pfiOverviewWriteOfferingsJs"],
66
"snippetTags": {
77
"start": ":snippet-start:",

site/docs/web5/build/decentralized-identifiers/how-to-create-did.mdx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ sidebar_position: 1
77
import createDidDht from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/decentralized-identifiers/createDidDht.snippet.js';
88
import createDidJwk from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/decentralized-identifiers/createDidJwk.snippet.js'
99
import requiredDidImports from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/decentralized-identifiers/requiredDidImports.snippet.js';
10+
import createDidDhtJava from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/java/website/tbd/developer/site/java/docs/web5/build/decentralizedidentifiers/createDidDhtJava.snippet.java';
1011
import createDidDhtKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/decentralizedidentifiers/createDidDhtKt.snippet.kt';
12+
import createDidJwtJava from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/java/website/tbd/developer/site/java/docs/web5/build/decentralizedidentifiers/createDidJwtJava.snippet.java';
1113
import createDidJwkKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/decentralizedidentifiers/createDidJwkKt.snippet.kt'
1214
import requiredDidImportsKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/decentralizedidentifiers/requiredDidImportsKt.snippet.kt';
1315
import createADidDependencyGradle from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/decentralized-identifiers/createADidDependencyGradle.snippet.gradle';
1416
import createADidDependencyMaven from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/decentralized-identifiers/createADidDependencyMaven.snippet.xml';
1517
import createADidDependency from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/decentralized-identifiers/createADidDependency.snippet.bash';
1618

17-
<LanguageSwitcher languages="JavaScript, Kotlin" />
19+
<LanguageSwitcher languages="JavaScript, Kotlin, Java" />
1820

1921
# Create a DID
2022

@@ -39,7 +41,20 @@ You can create a DID using any of the [Web5-supported DID methods](/docs/web5/le
3941
nestedSnippets: {
4042
Gradle: {
4143
snippet: createADidDependencyGradle,
42-
language: 'js',
44+
language: 'kt',
45+
},
46+
Maven: {
47+
snippet: createADidDependencyMaven,
48+
language: 'xml',
49+
},
50+
},
51+
},
52+
{
53+
language: 'Java',
54+
nestedSnippets: {
55+
Gradle: {
56+
snippet: createADidDependencyGradle,
57+
language: 'kt',
4358
},
4459
Maven: {
4560
snippet: createADidDependencyMaven,
@@ -68,6 +83,7 @@ The following DID methods are supported:
6883
snippets={[
6984
{ snippetContent: createDidDht, language: 'JavaScript' },
7085
{ snippetContent: createDidDhtKt, language: 'Kotlin' },
86+
{ snippetContent: createDidDhtJava, language: 'Java' },
7187
]}
7288
/>
7389

@@ -78,7 +94,8 @@ The following DID methods are supported:
7894
snippets={[
7995
{ snippetContent: createDidJwk, language: 'JavaScript' },
8096
{ snippetContent: createDidJwkKt, language: 'Kotlin' },
81-
]}
97+
{ snippetContent: createDidKeyJava, language: 'Java' },
98+
]}
8299
/>
83100

84101
## Example of DID properties
@@ -234,4 +251,4 @@ In the example below, the `d` property of the private key component is masked. T
234251
}
235252
]
236253
}
237-
```
254+
```

site/docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ let config = {
256256
},
257257
],
258258
},
259-
additionalLanguages: ['kotlin', 'swift', 'dart', 'rust'],
259+
additionalLanguages: ['java', 'kotlin', 'swift', 'dart', 'rust'],
260260
},
261261
}),
262262
};

site/src/components/CodeSnippet.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import codeSnippets from '../../src/util/code-snippets-map.json'; // Import for
55
// Define the language map for the new system
66
const languageExtensionMap = {
77
javascript: 'js',
8+
java: 'java',
89
kotlin: 'kt',
910
swift: 'swift',
1011
dart: 'dart',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="AutoImportedSourceRoots">
4+
<option name="directories">
5+
<list>
6+
<option value="$MODULE_DIR$/src/main/java" />
7+
<option value="$MODULE_DIR$/src/main/kotlin" />
8+
<option value="$MODULE_DIR$/src/test/java" />
9+
<option value="$MODULE_DIR$/src/test/kotlin" />
10+
</list>
11+
</option>
12+
</component>
13+
</module>

site/testsuites/testsuite-kotlin/pom.xml

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<java.version>17</java.version>
1617
<kotlin.jvm.target>17</kotlin.jvm.target>
1718
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
1819
<version.assertj>3.25.2</version.assertj>
@@ -114,8 +115,8 @@
114115
</dependencies>
115116

116117
<build>
117-
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
118-
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
118+
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
119+
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
119120
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
120121
<plugins>
121122
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
@@ -172,6 +173,66 @@
172173
<configuration>
173174
<jvmTarget>${kotlin.jvm.target}</jvmTarget>
174175
</configuration>
176+
<executions>
177+
<execution>
178+
<id>compile</id>
179+
<phase>process-sources</phase>
180+
<goals>
181+
<goal>compile</goal>
182+
</goals>
183+
<configuration>
184+
<sourceDirs>
185+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
186+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
187+
</sourceDirs>
188+
</configuration>
189+
</execution>
190+
<execution>
191+
<id>test-compile</id>
192+
<phase>process-test-sources</phase>
193+
<goals>
194+
<goal>test-compile</goal>
195+
</goals>
196+
<configuration>
197+
<sourceDirs>
198+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
199+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
200+
</sourceDirs>
201+
</configuration>
202+
</execution>
203+
</executions>
204+
</plugin>
205+
<plugin>
206+
<groupId>org.apache.maven.plugins</groupId>
207+
<artifactId>maven-compiler-plugin</artifactId>
208+
<configuration>
209+
<source>${java.version}</source>
210+
<target>${java.version}</target>
211+
</configuration>
212+
<executions>
213+
<execution>
214+
<id>default-compile</id>
215+
<phase>none</phase>
216+
</execution>
217+
<execution>
218+
<id>default-testCompile</id>
219+
<phase>none</phase>
220+
</execution>
221+
<execution>
222+
<id>java-compile</id>
223+
<phase>compile</phase>
224+
<goals>
225+
<goal>compile</goal>
226+
</goals>
227+
</execution>
228+
<execution>
229+
<id>java-test-compile</id>
230+
<phase>test-compile</phase>
231+
<goals>
232+
<goal>testCompile</goal>
233+
</goals>
234+
</execution>
235+
</executions>
175236
</plugin>
176237
</plugins>
177238
</build>
@@ -192,11 +253,11 @@
192253
<name>jboss</name>
193254
<url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/</url>
194255
</repository>
195-
<!--
196-
Address Danubetech being down
256+
<!--
257+
Address Danubetech being down
197258
https://github.com/TBD54566975/developer.tbd.website/issues/1242
198259
199-
Remove when we have TBD repo dependencies proxied in a more permanent
260+
Remove when we have TBD repo dependencies proxied in a more permanent
200261
Artifactory repo, or when we no longer have a danubetech dependency in the
201262
supply chain
202263
-->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package website.tbd.developer.site.java.docs.web5.build.decentralizedidentifiers;
2+
3+
import foundation.identity.did.DIDDocument;
4+
import org.junit.jupiter.api.Test;
5+
import web5.sdk.crypto.InMemoryKeyManager;
6+
import web5.sdk.dids.DidResolutionResult;
7+
import web5.sdk.dids.methods.dht.CreateDidDhtOptions;
8+
import web5.sdk.dids.methods.dht.DidDht;
9+
import web5.sdk.dids.methods.key.DidKey;
10+
11+
import static org.junit.jupiter.api.Assertions.*;
12+
13+
class HowToCreateDidTest
14+
{
15+
16+
@Test
17+
void createDidDht(){
18+
19+
// :snippet-start: createDidDhtJava
20+
// Creates a DID using the DHT method and publishes the DID Document to the DHT
21+
final DidDht didDht = DidDht.Default.create(
22+
new InMemoryKeyManager(),
23+
new CreateDidDhtOptions(null,null,true,null,null));
24+
25+
// DID String
26+
final String did = didDht.getUri();
27+
28+
// DID and its associated data which can be exported and used in different contexts/apps
29+
final DidResolutionResult portableDid = DidDht.Default.resolve(did,null);
30+
31+
// DID Document
32+
final DIDDocument didDocument = portableDid.getDidDocument();
33+
// :snippet-end:
34+
35+
assertNotNull(did,"DID should not be null");
36+
assertTrue(did.startsWith("did:dht"),"Did should start with 'did:dht'");
37+
assertEquals(did, didDocument.getId().toString(),"ID od DID Document should match DID");
38+
}
39+
40+
@Test
41+
void createDidKey() {
42+
// :snippet-start: createDidKeyJava
43+
// Creates a DID using the did:key method
44+
final DidKey didKey = DidKey.Companion.create(new InMemoryKeyManager(), null);
45+
46+
// DID and its associated data which can be exported and used in different contexts/apps
47+
final DidResolutionResult portableDid = didKey.resolve();
48+
49+
// DID String
50+
final String did = didKey.getUri();
51+
52+
// DID Document
53+
final DIDDocument didDocument = portableDid.getDidDocument();
54+
// :snippet-end:
55+
56+
assertNotNull(did, "DID should not be null");
57+
assertTrue(did.startsWith("did:key"), "DID should start with 'did:key'");
58+
assertNotNull(didDocument, "DID Document should not be null");
59+
assertEquals(did, didDocument.getId().toString(),"ID od DID Document should match DID");
60+
}
61+
62+
}

0 commit comments

Comments
 (0)