@alloy-js/java 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +7 -0
- package/api-extractor.json +4 -0
- package/babel.config.cjs +4 -0
- package/dist/src/arguments.d.ts +15 -0
- package/dist/src/arguments.d.ts.map +1 -0
- package/dist/src/arguments.js +27 -0
- package/dist/src/arguments.js.map +1 -0
- package/dist/src/builtins/index.d.ts +2 -0
- package/dist/src/builtins/index.d.ts.map +1 -0
- package/dist/src/builtins/index.js +1 -0
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/util.d.ts +4 -0
- package/dist/src/builtins/util.d.ts.map +1 -0
- package/dist/src/builtins/util.js +10 -0
- package/dist/src/builtins/util.js.map +1 -0
- package/dist/src/components/Annotation.d.ts +11 -0
- package/dist/src/components/Annotation.d.ts.map +1 -0
- package/dist/src/components/Annotation.js +12 -0
- package/dist/src/components/Annotation.js.map +1 -0
- package/dist/src/components/Block.d.ts +6 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +4 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/Class.d.ts +10 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/Class.js +36 -0
- package/dist/src/components/Class.js.map +1 -0
- package/dist/src/components/Constructor.d.ts +13 -0
- package/dist/src/components/Constructor.d.ts.map +1 -0
- package/dist/src/components/Constructor.js +23 -0
- package/dist/src/components/Constructor.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +12 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +18 -0
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/Enum.d.ts +13 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/Enum.js +38 -0
- package/dist/src/components/Enum.js.map +1 -0
- package/dist/src/components/Generics.d.ts +6 -0
- package/dist/src/components/Generics.d.ts.map +1 -0
- package/dist/src/components/Generics.js +8 -0
- package/dist/src/components/Generics.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts +11 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +9 -0
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +9 -0
- package/dist/src/components/Interface.d.ts.map +1 -0
- package/dist/src/components/Interface.js +35 -0
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/MavenProject.d.ts +13 -0
- package/dist/src/components/MavenProject.d.ts.map +1 -0
- package/dist/src/components/MavenProject.js +159 -0
- package/dist/src/components/MavenProject.js.map +1 -0
- package/dist/src/components/Method.d.ts +11 -0
- package/dist/src/components/Method.d.ts.map +1 -0
- package/dist/src/components/Method.js +25 -0
- package/dist/src/components/Method.js.map +1 -0
- package/dist/src/components/Name.d.ts +2 -0
- package/dist/src/components/Name.d.ts.map +1 -0
- package/dist/src/components/Name.js +10 -0
- package/dist/src/components/Name.js.map +1 -0
- package/dist/src/components/ObjectDeclaration.d.ts +13 -0
- package/dist/src/components/ObjectDeclaration.d.ts.map +1 -0
- package/dist/src/components/ObjectDeclaration.js +17 -0
- package/dist/src/components/ObjectDeclaration.js.map +1 -0
- package/dist/src/components/PackageDirectory.d.ts +16 -0
- package/dist/src/components/PackageDirectory.d.ts.map +1 -0
- package/dist/src/components/PackageDirectory.js +58 -0
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/Parameters.d.ts +11 -0
- package/dist/src/components/Parameters.d.ts.map +1 -0
- package/dist/src/components/Parameters.js +17 -0
- package/dist/src/components/Parameters.js.map +1 -0
- package/dist/src/components/ProjectDirectory.d.ts +23 -0
- package/dist/src/components/ProjectDirectory.d.ts.map +1 -0
- package/dist/src/components/ProjectDirectory.js +42 -0
- package/dist/src/components/ProjectDirectory.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +6 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +17 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +70 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/Value.d.ts +5 -0
- package/dist/src/components/Value.d.ts.map +1 -0
- package/dist/src/components/Value.js +17 -0
- package/dist/src/components/Value.js.map +1 -0
- package/dist/src/components/Variable.d.ts +9 -0
- package/dist/src/components/Variable.d.ts.map +1 -0
- package/dist/src/components/Variable.js +9 -0
- package/dist/src/components/Variable.js.map +1 -0
- package/dist/src/components/index.d.ts +21 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +21 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +86 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +24 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/create-library.d.ts +15 -0
- package/dist/src/create-library.d.ts.map +1 -0
- package/dist/src/create-library.js +34 -0
- package/dist/src/create-library.js.map +1 -0
- package/dist/src/generics.d.ts +28 -0
- package/dist/src/generics.d.ts.map +1 -0
- package/dist/src/generics.js +51 -0
- package/dist/src/generics.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +21 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/object-modifiers.d.ts +24 -0
- package/dist/src/object-modifiers.d.ts.map +1 -0
- package/dist/src/object-modifiers.js +31 -0
- package/dist/src/object-modifiers.js.map +1 -0
- package/dist/src/symbols/index.d.ts +6 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +6 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/java-output-symbol.d.ts +14 -0
- package/dist/src/symbols/java-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/java-output-symbol.js +21 -0
- package/dist/src/symbols/java-output-symbol.js.map +1 -0
- package/dist/src/symbols/java-package-scope.d.ts +6 -0
- package/dist/src/symbols/java-package-scope.d.ts.map +1 -0
- package/dist/src/symbols/java-package-scope.js +8 -0
- package/dist/src/symbols/java-package-scope.js.map +1 -0
- package/dist/src/symbols/java-project-scope.d.ts +67 -0
- package/dist/src/symbols/java-project-scope.d.ts.map +1 -0
- package/dist/src/symbols/java-project-scope.js +29 -0
- package/dist/src/symbols/java-project-scope.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +8 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +21 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +4 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +1 -0
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/test/annotation.test.d.ts +2 -0
- package/dist/test/annotation.test.d.ts.map +1 -0
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/constructor.test.d.ts +2 -0
- package/dist/test/constructor.test.d.ts.map +1 -0
- package/dist/test/enum.test.d.ts +2 -0
- package/dist/test/enum.test.d.ts.map +1 -0
- package/dist/test/externals.test.d.ts +2 -0
- package/dist/test/externals.test.d.ts.map +1 -0
- package/dist/test/generics.d.ts +2 -0
- package/dist/test/generics.d.ts.map +1 -0
- package/dist/test/interface.test.d.ts +2 -0
- package/dist/test/interface.test.d.ts.map +1 -0
- package/dist/test/maven.d.ts +2 -0
- package/dist/test/maven.d.ts.map +1 -0
- package/dist/test/method.test.d.ts +2 -0
- package/dist/test/method.test.d.ts.map +1 -0
- package/dist/test/package.test.d.ts +2 -0
- package/dist/test/package.test.d.ts.map +1 -0
- package/dist/test/reference.test.d.ts +2 -0
- package/dist/test/reference.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +6 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/values.test.d.ts +2 -0
- package/dist/test/values.test.d.ts.map +1 -0
- package/dist/test/variables.test.d.ts +2 -0
- package/dist/test/variables.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +49 -0
- package/src/arguments.ts +30 -0
- package/src/builtins/index.ts +1 -0
- package/src/builtins/util.ts +117 -0
- package/src/components/Annotation.tsx +23 -0
- package/src/components/Block.tsx +8 -0
- package/src/components/Class.tsx +33 -0
- package/src/components/Constructor.tsx +25 -0
- package/src/components/Declaration.tsx +24 -0
- package/src/components/Enum.tsx +40 -0
- package/src/components/Generics.tsx +12 -0
- package/src/components/ImportStatement.tsx +21 -0
- package/src/components/Interface.tsx +31 -0
- package/src/components/MavenProject.tsx +151 -0
- package/src/components/Method.tsx +31 -0
- package/src/components/Name.tsx +10 -0
- package/src/components/ObjectDeclaration.tsx +22 -0
- package/src/components/PackageDirectory.tsx +84 -0
- package/src/components/Parameters.tsx +21 -0
- package/src/components/ProjectDirectory.tsx +76 -0
- package/src/components/Reference.tsx +12 -0
- package/src/components/SourceFile.tsx +84 -0
- package/src/components/Value.tsx +22 -0
- package/src/components/Variable.tsx +16 -0
- package/src/components/index.ts +20 -0
- package/src/components/stc/index.ts +24 -0
- package/src/create-library.ts +67 -0
- package/src/generics.ts +59 -0
- package/src/index.ts +8 -0
- package/src/name-policy.ts +33 -0
- package/src/object-modifiers.ts +48 -0
- package/src/symbols/index.ts +5 -0
- package/src/symbols/java-output-symbol.ts +30 -0
- package/src/symbols/java-package-scope.ts +17 -0
- package/src/symbols/java-project-scope.ts +104 -0
- package/src/symbols/reference.ts +24 -0
- package/src/symbols/scopes.ts +4 -0
- package/temp/api.json +5805 -0
- package/test/annotation.test.tsx +56 -0
- package/test/class.test.tsx +133 -0
- package/test/constructor.test.tsx +96 -0
- package/test/enum.test.tsx +105 -0
- package/test/externals.test.tsx +46 -0
- package/test/generics.tsx +58 -0
- package/test/interface.test.tsx +84 -0
- package/test/maven.tsx +261 -0
- package/test/method.test.tsx +162 -0
- package/test/package.test.tsx +18 -0
- package/test/reference.test.tsx +88 -0
- package/test/utils.tsx +72 -0
- package/test/values.test.tsx +29 -0
- package/test/variables.test.tsx +101 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +11 -0
- package/tsdoc-metadata.json +11 -0
- package/vitest.config.ts +18 -0
package/test/maven.tsx
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Output, render } from "@alloy-js/core";
|
|
2
|
+
import { it } from "vitest";
|
|
3
|
+
import { ProjectDirectory } from "../src/components/index.js";
|
|
4
|
+
import { MavenProjectConfig } from "../src/index.js";
|
|
5
|
+
import { assertFileContents } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("generates barebones pom.xml file", () => {
|
|
8
|
+
const projectConfig: MavenProjectConfig = {
|
|
9
|
+
groupId: "me.example",
|
|
10
|
+
artifactId: "test",
|
|
11
|
+
version: "1.0.0",
|
|
12
|
+
javaVersion: 8,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const res = render(
|
|
16
|
+
<Output>
|
|
17
|
+
<ProjectDirectory name='TestMavenProject' mavenProjectConfig={projectConfig}>
|
|
18
|
+
</ProjectDirectory>
|
|
19
|
+
</Output>,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
assertFileContents(res, {
|
|
23
|
+
"pom.xml": `
|
|
24
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
25
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
26
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
27
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
28
|
+
|
|
29
|
+
<modelVersion>4.0.0</modelVersion>
|
|
30
|
+
<groupId>me.example</groupId>
|
|
31
|
+
<artifactId>test</artifactId>
|
|
32
|
+
<version>1.0.0</version>
|
|
33
|
+
|
|
34
|
+
<properties>
|
|
35
|
+
<maven.compiler.source>8</maven.compiler.source>
|
|
36
|
+
<maven.compiler.target>8</maven.compiler.target>
|
|
37
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
38
|
+
</properties>
|
|
39
|
+
|
|
40
|
+
</project>
|
|
41
|
+
`,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("generates complex configuration", () => {
|
|
46
|
+
// Some fields are duplicate, just to show it can handle array data
|
|
47
|
+
const projectConfig: MavenProjectConfig = {
|
|
48
|
+
groupId: "me.example",
|
|
49
|
+
artifactId: "test",
|
|
50
|
+
version: "1.0.0",
|
|
51
|
+
javaVersion: 8,
|
|
52
|
+
repositories: [
|
|
53
|
+
{ id: "central", url: "https://repo.maven.apache.org/maven2" },
|
|
54
|
+
{ id: "central", url: "https://repo.maven.apache.org/maven2" },
|
|
55
|
+
],
|
|
56
|
+
pluginRepositories: [
|
|
57
|
+
{ id: "central", url: "https://repo.maven.apache.org/maven2" },
|
|
58
|
+
{ id: "central", url: "https://repo.maven.apache.org/maven2" },
|
|
59
|
+
],
|
|
60
|
+
build: {
|
|
61
|
+
plugins: [
|
|
62
|
+
{
|
|
63
|
+
groupId: "org.apache.maven.plugins",
|
|
64
|
+
artifactId: "maven-compiler-plugin",
|
|
65
|
+
version: "3.8.1",
|
|
66
|
+
executions: [
|
|
67
|
+
{
|
|
68
|
+
id: "default-compile",
|
|
69
|
+
phase: "compile",
|
|
70
|
+
goals: ["compile", "test"],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "default-testCompile",
|
|
74
|
+
phase: "test-compile",
|
|
75
|
+
goals: ["testCompile", "test"],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
configuration: {
|
|
79
|
+
source: 8,
|
|
80
|
+
target: 8,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
groupId: "org.apache.maven.plugins",
|
|
85
|
+
artifactId: "maven-compiler-plugin",
|
|
86
|
+
version: "3.8.1",
|
|
87
|
+
executions: [
|
|
88
|
+
{
|
|
89
|
+
id: "default-compile",
|
|
90
|
+
phase: "compile",
|
|
91
|
+
goals: ["compile", "test"],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "default-testCompile",
|
|
95
|
+
phase: "test-compile",
|
|
96
|
+
goals: ["testCompile", "test"],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
configuration: {
|
|
100
|
+
source: 8,
|
|
101
|
+
target: 8,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
resources: [
|
|
106
|
+
{
|
|
107
|
+
directory: "src/main/resources",
|
|
108
|
+
filtering: true,
|
|
109
|
+
targetPath: "target/classes",
|
|
110
|
+
includes: ["**/*.properties", "**/*.xml"],
|
|
111
|
+
excludes: ["**/*.xml", "**/*.json"],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
directory: "src/main/resources",
|
|
115
|
+
filtering: true,
|
|
116
|
+
targetPath: "target/classes",
|
|
117
|
+
includes: ["**/*.properties", "**/*.xml"],
|
|
118
|
+
excludes: ["**/*.xml", "**/*.json"],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const res = render(
|
|
125
|
+
<Output>
|
|
126
|
+
<ProjectDirectory name='TestMavenProject' mavenProjectConfig={projectConfig}>
|
|
127
|
+
</ProjectDirectory>
|
|
128
|
+
</Output>,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
assertFileContents(res, {
|
|
132
|
+
"pom.xml": `
|
|
133
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
134
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
135
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
136
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
137
|
+
|
|
138
|
+
<modelVersion>4.0.0</modelVersion>
|
|
139
|
+
<groupId>me.example</groupId>
|
|
140
|
+
<artifactId>test</artifactId>
|
|
141
|
+
<version>1.0.0</version>
|
|
142
|
+
|
|
143
|
+
<properties>
|
|
144
|
+
<maven.compiler.source>8</maven.compiler.source>
|
|
145
|
+
<maven.compiler.target>8</maven.compiler.target>
|
|
146
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
147
|
+
</properties>
|
|
148
|
+
|
|
149
|
+
<repositories>
|
|
150
|
+
<repository>
|
|
151
|
+
<id>central</id>
|
|
152
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
153
|
+
</repository>
|
|
154
|
+
<repository>
|
|
155
|
+
<id>central</id>
|
|
156
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
157
|
+
</repository>
|
|
158
|
+
</repositories>
|
|
159
|
+
|
|
160
|
+
<pluginRepositories>
|
|
161
|
+
<pluginRepository>
|
|
162
|
+
<id>central</id>
|
|
163
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
164
|
+
</pluginRepository>
|
|
165
|
+
<pluginRepository>
|
|
166
|
+
<id>central</id>
|
|
167
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
168
|
+
</pluginRepository>
|
|
169
|
+
</pluginRepositories>
|
|
170
|
+
|
|
171
|
+
<build>
|
|
172
|
+
<plugins>
|
|
173
|
+
<plugin>
|
|
174
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
175
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
176
|
+
<version>3.8.1</version>
|
|
177
|
+
<executions>
|
|
178
|
+
<execution>
|
|
179
|
+
<id>default-compile</id>
|
|
180
|
+
<phase>compile</phase>
|
|
181
|
+
<goals>
|
|
182
|
+
<goal>compile</goal>
|
|
183
|
+
<goal>test</goal>
|
|
184
|
+
</goals>
|
|
185
|
+
</execution>
|
|
186
|
+
<execution>
|
|
187
|
+
<id>default-testCompile</id>
|
|
188
|
+
<phase>test-compile</phase>
|
|
189
|
+
<goals>
|
|
190
|
+
<goal>testCompile</goal>
|
|
191
|
+
<goal>test</goal>
|
|
192
|
+
</goals>
|
|
193
|
+
</execution>
|
|
194
|
+
</executions>
|
|
195
|
+
<configuration>
|
|
196
|
+
<source>8</source>
|
|
197
|
+
<target>8</target>
|
|
198
|
+
</configuration>
|
|
199
|
+
</plugin>
|
|
200
|
+
<plugin>
|
|
201
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
202
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
203
|
+
<version>3.8.1</version>
|
|
204
|
+
<executions>
|
|
205
|
+
<execution>
|
|
206
|
+
<id>default-compile</id>
|
|
207
|
+
<phase>compile</phase>
|
|
208
|
+
<goals>
|
|
209
|
+
<goal>compile</goal>
|
|
210
|
+
<goal>test</goal>
|
|
211
|
+
</goals>
|
|
212
|
+
</execution>
|
|
213
|
+
<execution>
|
|
214
|
+
<id>default-testCompile</id>
|
|
215
|
+
<phase>test-compile</phase>
|
|
216
|
+
<goals>
|
|
217
|
+
<goal>testCompile</goal>
|
|
218
|
+
<goal>test</goal>
|
|
219
|
+
</goals>
|
|
220
|
+
</execution>
|
|
221
|
+
</executions>
|
|
222
|
+
<configuration>
|
|
223
|
+
<source>8</source>
|
|
224
|
+
<target>8</target>
|
|
225
|
+
</configuration>
|
|
226
|
+
</plugin>
|
|
227
|
+
</plugins>
|
|
228
|
+
<resources>
|
|
229
|
+
<resource>
|
|
230
|
+
<directory>src/main/resources</directory>
|
|
231
|
+
<includes>
|
|
232
|
+
<include>**/*.properties</include>
|
|
233
|
+
<include>**/*.xml</include>
|
|
234
|
+
</includes>
|
|
235
|
+
<excludes>
|
|
236
|
+
<exclude>**/*.xml</exclude>
|
|
237
|
+
<exclude>**/*.json</exclude>
|
|
238
|
+
</excludes>
|
|
239
|
+
<filtering>true</filtering>
|
|
240
|
+
<targetPath>target/classes</targetPath>
|
|
241
|
+
</resource>
|
|
242
|
+
<resource>
|
|
243
|
+
<directory>src/main/resources</directory>
|
|
244
|
+
<includes>
|
|
245
|
+
<include>**/*.properties</include>
|
|
246
|
+
<include>**/*.xml</include>
|
|
247
|
+
</includes>
|
|
248
|
+
<excludes>
|
|
249
|
+
<exclude>**/*.xml</exclude>
|
|
250
|
+
<exclude>**/*.json</exclude>
|
|
251
|
+
</excludes>
|
|
252
|
+
<filtering>true</filtering>
|
|
253
|
+
<targetPath>target/classes</targetPath>
|
|
254
|
+
</resource>
|
|
255
|
+
</resources>
|
|
256
|
+
</build>
|
|
257
|
+
|
|
258
|
+
</project>
|
|
259
|
+
`,
|
|
260
|
+
});
|
|
261
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { code, Declaration, refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("declares basic empty function", () => {
|
|
8
|
+
const res = toSourceText(
|
|
9
|
+
<jv.Declaration name="Test">
|
|
10
|
+
{code`
|
|
11
|
+
class Test {
|
|
12
|
+
${<jv.Method public name="testMethod">
|
|
13
|
+
System.out.println("Test");
|
|
14
|
+
</jv.Method>}
|
|
15
|
+
}
|
|
16
|
+
`}
|
|
17
|
+
</jv.Declaration>,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(res).toBe(d`
|
|
21
|
+
package me.test.code;
|
|
22
|
+
|
|
23
|
+
class Test {
|
|
24
|
+
public void testMethod() {
|
|
25
|
+
System.out.println("Test");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("declares bodyless function", () => {
|
|
32
|
+
const res = toSourceText(
|
|
33
|
+
<jv.Declaration name="Test">
|
|
34
|
+
{code`
|
|
35
|
+
class Test {
|
|
36
|
+
${<jv.Method public name="testMethod" />}
|
|
37
|
+
}
|
|
38
|
+
`}
|
|
39
|
+
</jv.Declaration>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(res).toBe(d`
|
|
43
|
+
package me.test.code;
|
|
44
|
+
|
|
45
|
+
class Test {
|
|
46
|
+
public void testMethod();
|
|
47
|
+
}
|
|
48
|
+
`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("declares return type", () => {
|
|
52
|
+
const res = toSourceText(
|
|
53
|
+
<jv.Declaration name="Test">
|
|
54
|
+
{code`
|
|
55
|
+
class Test {
|
|
56
|
+
${<jv.Method public name="testMethod" return='String'>
|
|
57
|
+
System.out.println("Test");
|
|
58
|
+
return "Test";
|
|
59
|
+
</jv.Method>}
|
|
60
|
+
}
|
|
61
|
+
`}
|
|
62
|
+
</jv.Declaration>,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(res).toBe(d`
|
|
66
|
+
package me.test.code;
|
|
67
|
+
|
|
68
|
+
class Test {
|
|
69
|
+
public String testMethod() {
|
|
70
|
+
System.out.println("Test");
|
|
71
|
+
return "Test";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
`);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("declares parameters", () => {
|
|
78
|
+
const res = testRender(
|
|
79
|
+
<>
|
|
80
|
+
<jv.SourceFile path="Model.java">
|
|
81
|
+
<jv.Declaration name='Model'>
|
|
82
|
+
{code`
|
|
83
|
+
public class Model {
|
|
84
|
+
}
|
|
85
|
+
`}
|
|
86
|
+
</jv.Declaration>
|
|
87
|
+
</jv.SourceFile>
|
|
88
|
+
<jv.PackageDirectory package='imports'>
|
|
89
|
+
<jv.SourceFile path="Test.java">
|
|
90
|
+
<Declaration name="Test">
|
|
91
|
+
{code`
|
|
92
|
+
public class Test {
|
|
93
|
+
${<jv.Method public name="testMethod" parameters={{
|
|
94
|
+
myModel: refkey("Model"),
|
|
95
|
+
name: "String"
|
|
96
|
+
}}>
|
|
97
|
+
System.out.println("Test");
|
|
98
|
+
</jv.Method>}
|
|
99
|
+
}
|
|
100
|
+
`}
|
|
101
|
+
</Declaration>
|
|
102
|
+
</jv.SourceFile>
|
|
103
|
+
</jv.PackageDirectory>
|
|
104
|
+
</>,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
assertFileContents(res, {
|
|
108
|
+
"Test.java": d`
|
|
109
|
+
package me.test.code.imports;
|
|
110
|
+
|
|
111
|
+
import me.test.code.Model;
|
|
112
|
+
|
|
113
|
+
public class Test {
|
|
114
|
+
public void testMethod(Model myModel, String name) {
|
|
115
|
+
System.out.println("Test");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
`,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("defines generics", () => {
|
|
123
|
+
const res = testRender(
|
|
124
|
+
<>
|
|
125
|
+
<jv.SourceFile path="Model.java">
|
|
126
|
+
<jv.Declaration name='Model'>
|
|
127
|
+
{code`
|
|
128
|
+
public class Model {
|
|
129
|
+
}
|
|
130
|
+
`}
|
|
131
|
+
</jv.Declaration>
|
|
132
|
+
</jv.SourceFile>
|
|
133
|
+
<jv.PackageDirectory package='imports'>
|
|
134
|
+
<jv.SourceFile path="Test.java">
|
|
135
|
+
<Declaration name="Test">
|
|
136
|
+
{code`
|
|
137
|
+
public class Test {
|
|
138
|
+
${<jv.Method public generics={{ T: refkey("Model"), N: 'String', K: ''}} name="testMethod">
|
|
139
|
+
System.out.println("Test");
|
|
140
|
+
</jv.Method>}
|
|
141
|
+
}
|
|
142
|
+
`}
|
|
143
|
+
</Declaration>
|
|
144
|
+
</jv.SourceFile>
|
|
145
|
+
</jv.PackageDirectory>
|
|
146
|
+
</>,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
assertFileContents(res, {
|
|
150
|
+
"Test.java": d`
|
|
151
|
+
package me.test.code.imports;
|
|
152
|
+
|
|
153
|
+
import me.test.code.Model;
|
|
154
|
+
|
|
155
|
+
public class Test {
|
|
156
|
+
public <T extends Model, N extends String, K> void testMethod() {
|
|
157
|
+
System.out.println("Test");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
`,
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import * as jv from "../src/components/index.js";
|
|
3
|
+
import { findFile, testRender } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
it("emits correct package directory", () => {
|
|
6
|
+
const res = testRender(
|
|
7
|
+
<>
|
|
8
|
+
<jv.PackageDirectory package='my.emit.package'>
|
|
9
|
+
<jv.SourceFile path="Test.java">
|
|
10
|
+
</jv.SourceFile>
|
|
11
|
+
</jv.PackageDirectory>
|
|
12
|
+
</>,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
// Assert directory file is in is correct
|
|
16
|
+
const testFile = findFile(res, "Test.java");
|
|
17
|
+
expect(testFile.path).toBe("me/test/code/my/emit/package/Test.java");
|
|
18
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
|
+
import { it } from "vitest";
|
|
3
|
+
import * as jv from "../src/components/index.js";
|
|
4
|
+
import { assertFileContents, testRender } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
it("imports reference to source file", () => {
|
|
7
|
+
const res = testRender(
|
|
8
|
+
<>
|
|
9
|
+
<jv.SourceFile path="TestReference.java">
|
|
10
|
+
<jv.Declaration name="TestReference">
|
|
11
|
+
public class TestReference {"{"}
|
|
12
|
+
public TestReference() {"{}"}
|
|
13
|
+
{"}"}
|
|
14
|
+
</jv.Declaration>
|
|
15
|
+
</jv.SourceFile>
|
|
16
|
+
<jv.PackageDirectory package='import'>
|
|
17
|
+
<jv.SourceFile path="TestImport.java">
|
|
18
|
+
<jv.Declaration name="TestImport">
|
|
19
|
+
public class TestImport {"{"}
|
|
20
|
+
{refkey("TestReference")} myImportedVariable;
|
|
21
|
+
public TestImport() {"{}"}
|
|
22
|
+
{"}"}
|
|
23
|
+
</jv.Declaration>
|
|
24
|
+
</jv.SourceFile>
|
|
25
|
+
</jv.PackageDirectory>
|
|
26
|
+
</>,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
assertFileContents(res, {
|
|
30
|
+
"TestReference.java": `
|
|
31
|
+
package me.test.code;
|
|
32
|
+
|
|
33
|
+
public class TestReference {
|
|
34
|
+
public TestReference() {}
|
|
35
|
+
}
|
|
36
|
+
`,
|
|
37
|
+
"TestImport.java": `
|
|
38
|
+
package me.test.code.import;
|
|
39
|
+
|
|
40
|
+
import me.test.code.TestReference;
|
|
41
|
+
|
|
42
|
+
public class TestImport {
|
|
43
|
+
TestReference myImportedVariable;
|
|
44
|
+
public TestImport() {}
|
|
45
|
+
}
|
|
46
|
+
`,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("doesn't import if in same package", () => {
|
|
51
|
+
const res = testRender(
|
|
52
|
+
<>
|
|
53
|
+
<jv.SourceFile path="TestReference.java">
|
|
54
|
+
<jv.Declaration name="TestReference">
|
|
55
|
+
public class TestReference {"{"}
|
|
56
|
+
public TestReference() {"{}"}
|
|
57
|
+
{"}"}
|
|
58
|
+
</jv.Declaration>
|
|
59
|
+
</jv.SourceFile>
|
|
60
|
+
<jv.SourceFile path="TestImport.java">
|
|
61
|
+
<jv.Declaration name="TestImport">
|
|
62
|
+
public class TestImport {"{"}
|
|
63
|
+
{refkey("TestReference")} myImportedVariable;
|
|
64
|
+
public TestImport() {"{}"}
|
|
65
|
+
{"}"}
|
|
66
|
+
</jv.Declaration>
|
|
67
|
+
</jv.SourceFile>
|
|
68
|
+
</>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
assertFileContents(res, {
|
|
72
|
+
"TestReference.java": `
|
|
73
|
+
package me.test.code;
|
|
74
|
+
|
|
75
|
+
public class TestReference {
|
|
76
|
+
public TestReference() {}
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
79
|
+
"TestImport.java": `
|
|
80
|
+
package me.test.code;
|
|
81
|
+
|
|
82
|
+
public class TestImport {
|
|
83
|
+
TestReference myImportedVariable;
|
|
84
|
+
public TestImport() {}
|
|
85
|
+
}
|
|
86
|
+
`,
|
|
87
|
+
});
|
|
88
|
+
});
|
package/test/utils.tsx
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
Output,
|
|
4
|
+
OutputDirectory,
|
|
5
|
+
OutputFile,
|
|
6
|
+
render,
|
|
7
|
+
} from "@alloy-js/core";
|
|
8
|
+
import { dedent } from "@alloy-js/core/testing";
|
|
9
|
+
import { expect } from "vitest";
|
|
10
|
+
import * as jv from "../src/index.js";
|
|
11
|
+
|
|
12
|
+
export function toSourceText(c: Children): string {
|
|
13
|
+
const res = render(
|
|
14
|
+
<Output>
|
|
15
|
+
<jv.PackageDirectory package='me.test.code'>
|
|
16
|
+
<jv.SourceFile path="Test.java">{c}</jv.SourceFile>
|
|
17
|
+
</jv.PackageDirectory>
|
|
18
|
+
</Output>,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const file = findFile(res, "Test.java");
|
|
22
|
+
return file.contents;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function testRender(c: Children): OutputDirectory {
|
|
26
|
+
return render(
|
|
27
|
+
<Output>
|
|
28
|
+
<jv.PackageDirectory package='me.test.code'>
|
|
29
|
+
{c}
|
|
30
|
+
</jv.PackageDirectory>
|
|
31
|
+
</Output>,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function findFile(res: OutputDirectory, path: string): OutputFile {
|
|
36
|
+
const result = findFileWorker(res, path);
|
|
37
|
+
|
|
38
|
+
if (!result) {
|
|
39
|
+
throw new Error("Expected to find file " + path);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
|
|
43
|
+
function findFileWorker(
|
|
44
|
+
res: OutputDirectory,
|
|
45
|
+
path: string,
|
|
46
|
+
): OutputFile | null {
|
|
47
|
+
for (const item of res.contents) {
|
|
48
|
+
if (item.kind === "file") {
|
|
49
|
+
if (item.path.includes(path)) {
|
|
50
|
+
return item;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
} else {
|
|
54
|
+
const found = findFileWorker(item, path);
|
|
55
|
+
if (found) {
|
|
56
|
+
return found;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function assertFileContents(
|
|
65
|
+
res: OutputDirectory,
|
|
66
|
+
expectedFiles: Record<string, string>,
|
|
67
|
+
) {
|
|
68
|
+
for (const [path, contents] of Object.entries(expectedFiles)) {
|
|
69
|
+
const file = findFile(res, path);
|
|
70
|
+
expect(file.contents).toBe(dedent(contents));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "@alloy-js/core/testing";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import * as jv from "../src/components/index.js";
|
|
4
|
+
|
|
5
|
+
it("renders string value", () => {
|
|
6
|
+
expect(<jv.Value value={"Test"} />).toRenderTo('"Test"');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("renders null/undefined object", () => {
|
|
10
|
+
expect(<jv.Value value={undefined} />).toRenderTo("null");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("renders number", () => {
|
|
14
|
+
expect(<jv.Value value={123} />).toRenderTo("123");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("renders boolean", () => {
|
|
18
|
+
expect(<jv.Value value={true} />).toRenderTo("true");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("renders other objects", () => {
|
|
22
|
+
function Test() {
|
|
23
|
+
return <>
|
|
24
|
+
Test
|
|
25
|
+
</>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
expect(<jv.Value value={Test} />).toRenderTo("Test");
|
|
29
|
+
});
|