backend-skeleton 1.0.0-beta.1
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 +21 -0
- package/README.md +284 -0
- package/bin/bskel.mjs +2384 -0
- package/contracts/completeness.mjs +176 -0
- package/contracts/emit.mjs +287 -0
- package/contracts/export.mjs +325 -0
- package/contracts/openapi.mjs +869 -0
- package/contracts/validate.mjs +147 -0
- package/handles/_engine.mjs +281 -0
- package/handles/codec.mjs +119 -0
- package/handles/conformance.mjs +74 -0
- package/handles/providers/java-spring/ast-bridge.mjs +59 -0
- package/handles/providers/java-spring/ast-helper/build.gradle +34 -0
- package/handles/providers/java-spring/ast-helper/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/handles/providers/java-spring/ast-helper/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/handles/providers/java-spring/ast-helper/gradlew +248 -0
- package/handles/providers/java-spring/ast-helper/gradlew.bat +82 -0
- package/handles/providers/java-spring/ast-helper/settings.gradle +1 -0
- package/handles/providers/java-spring/ast-helper/src/main/java/com/backendskeleton/asthelper/Main.java +178 -0
- package/handles/providers/java-spring/emit.mjs +232 -0
- package/handles/providers/java-spring/patch-strategy.mjs +229 -0
- package/handles/providers/java-spring/plan.mjs +377 -0
- package/handles/providers/java-spring/templates/HandleAspect.java.tmpl +125 -0
- package/handles/providers/java-spring/templates/HandleCodec.java.tmpl +150 -0
- package/handles/providers/java-spring/templates/HandleController.java.tmpl +177 -0
- package/handles/providers/java-spring/templates/HandleRegistry.java.tmpl +107 -0
- package/handles/providers/java-spring/templates/HandleRegistryRepository.java.tmpl +8 -0
- package/handles/providers/java-spring/templates/HandleService.java.tmpl +95 -0
- package/handles/providers/java-spring/templates/HandleSnapshot.java.tmpl +75 -0
- package/handles/providers/java-spring/templates/HandleSnapshotRepository.java.tmpl +20 -0
- package/handles/providers/java-spring/templates/RecordHandleSnapshot.java.tmpl +50 -0
- package/handles/providers/java-spring/templates/ResourceResolver.java.tmpl +50 -0
- package/handles/providers/java-spring/templates/ResourceResolverStub.java.tmpl +77 -0
- package/handles/providers/java-spring/templates/migration.sql.tmpl +34 -0
- package/handles/providers/java-spring.mjs +21 -0
- package/handles/providers/python-fastapi/emit.mjs +171 -0
- package/handles/providers/python-fastapi/plan.mjs +186 -0
- package/handles/providers/python-fastapi/templates/__init__.py.tmpl +1 -0
- package/handles/providers/python-fastapi/templates/codec.py.tmpl +122 -0
- package/handles/providers/python-fastapi/templates/handle_service.py.tmpl +96 -0
- package/handles/providers/python-fastapi/templates/migration.sql.tmpl +35 -0
- package/handles/providers/python-fastapi/templates/record_snapshot.py.tmpl +155 -0
- package/handles/providers/python-fastapi/templates/registry.py.tmpl +37 -0
- package/handles/providers/python-fastapi/templates/resolver.py.tmpl +59 -0
- package/handles/providers/python-fastapi/templates/resolvers_init.py.tmpl +13 -0
- package/handles/providers/python-fastapi/templates/router.py.tmpl +140 -0
- package/handles/providers/python-fastapi/templates/tables.py.tmpl +66 -0
- package/handles/providers/python-fastapi.mjs +22 -0
- package/handles/providers/typescript-express/emit.mjs +128 -0
- package/handles/providers/typescript-express/plan.mjs +234 -0
- package/handles/providers/typescript-express/templates/codec.ts.tmpl +116 -0
- package/handles/providers/typescript-express/templates/registry.ts.tmpl +39 -0
- package/handles/providers/typescript-express/templates/resolver.ts.tmpl +55 -0
- package/handles/providers/typescript-express/templates/resolvers_index.ts.tmpl +11 -0
- package/handles/providers/typescript-express/templates/router.ts.tmpl +122 -0
- package/handles/providers/typescript-express.mjs +20 -0
- package/handles/registry.mjs +90 -0
- package/lib/cli.mjs +430 -0
- package/lib/doctor.mjs +200 -0
- package/lib/exit-codes.mjs +67 -0
- package/lib/featureid.mjs +55 -0
- package/lib/featurelifecycle.mjs +205 -0
- package/lib/fsutil.mjs +50 -0
- package/lib/gate-definitions.mjs +293 -0
- package/lib/gates.mjs +263 -0
- package/lib/handles-manifest.mjs +92 -0
- package/lib/lock.mjs +68 -0
- package/lib/patch-approvals.mjs +56 -0
- package/lib/paths.mjs +21 -0
- package/lib/repo.mjs +44 -0
- package/lib/schema-validate.mjs +56 -0
- package/lib/state.mjs +124 -0
- package/lib/template.mjs +35 -0
- package/lib/verify.mjs +206 -0
- package/lib/workflow.mjs +142 -0
- package/new/fastapi.mjs +165 -0
- package/new/index.mjs +62 -0
- package/new/params.mjs +233 -0
- package/new/spring.mjs +198 -0
- package/new/templates/fastapi/README.md +26 -0
- package/new/templates/fastapi/app/__init__.py +0 -0
- package/new/templates/fastapi/app/main.py +8 -0
- package/new/templates/fastapi/gitignore +6 -0
- package/new/templates/fastapi/pyproject.toml +14 -0
- package/package.json +50 -0
- package/scanners/adapters/_express-shared.mjs +238 -0
- package/scanners/adapters/_java-spring-analyzer.mjs +273 -0
- package/scanners/adapters/generic-grep.mjs +128 -0
- package/scanners/adapters/java-spring.mjs +301 -0
- package/scanners/adapters/javascript-express.mjs +422 -0
- package/scanners/adapters/python-fastapi.mjs +348 -0
- package/scanners/adapters/typescript-express.mjs +299 -0
- package/scanners/capabilities.mjs +90 -0
- package/scanners/conformance.mjs +59 -0
- package/scanners/db/introspect.mjs +109 -0
- package/scanners/db/migrations.mjs +126 -0
- package/scanners/index.mjs +281 -0
- package/scanners/registry.mjs +130 -0
- package/scanners/render.mjs +136 -0
- package/scanners/text-util.mjs +8 -0
- package/schemas/adapter.schema.json +23 -0
- package/schemas/agent-envelope.schema.json +21 -0
- package/schemas/contract-resolution.schema.json +28 -0
- package/schemas/feature-contract.schema.json +78 -0
- package/schemas/feature-index.schema.json +25 -0
- package/schemas/feature.schema.json +17 -0
- package/schemas/gate-event.schema.json +19 -0
- package/schemas/handles-plan.schema.json +31 -0
- package/schemas/handles-provider.schema.json +26 -0
- package/schemas/patch-approvals.schema.json +28 -0
- package/schemas/scan-report.schema.json +102 -0
- package/schemas/stack-choice.schema.json +89 -0
- package/schemas/stack-record.schema.json +20 -0
- package/schemas/state.schema.json +43 -0
- package/scripts/preflight-base-ref.sh +226 -0
- package/stack/apply.mjs +159 -0
- package/stack/bootstrap/_lib.sh +73 -0
- package/stack/bootstrap/ngrok.sh +90 -0
- package/stack/catalog/ngrok.yml +63 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// A2 Phase 2 (D-java-ast-helper): the Node-side bridge to the real JavaParser + Symbol Solver
|
|
2
|
+
// helper (ast-helper/) -- invoked only when a human explicitly passes `--ast` to
|
|
3
|
+
// `bskel handles plan`, never a hard dependency of the base install, never invoked silently.
|
|
4
|
+
// See DECISIONS.md.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { promisify } from 'node:util';
|
|
10
|
+
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const HELPER_DIR = path.join(__dirname, 'ast-helper');
|
|
14
|
+
|
|
15
|
+
function gradlewPath() {
|
|
16
|
+
return path.join(HELPER_DIR, process.platform === 'win32' ? 'gradlew.bat' : 'gradlew');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Cheap, synchronous -- used by both `bskel doctor` and the `--ast` flag's own upfront check, so
|
|
20
|
+
// a missing JDK fails loud with a clear remediation message instead of a confusing subprocess
|
|
21
|
+
// error surfacing from deep inside a Gradle invocation.
|
|
22
|
+
export function detectAstHelperAvailable() {
|
|
23
|
+
if (!fs.existsSync(gradlewPath())) return { available: false, reason: 'the bundled AST helper (handles/providers/java-spring/ast-helper/) is missing its Gradle wrapper -- this installation may be corrupt' };
|
|
24
|
+
try {
|
|
25
|
+
execFileSync('java', ['-version'], { stdio: 'pipe' });
|
|
26
|
+
} catch {
|
|
27
|
+
return { available: false, reason: 'no `java` found on PATH -- the AST helper needs a JDK (17+) to run. Install one, e.g. via your platform\'s package manager or https://adoptium.net' };
|
|
28
|
+
}
|
|
29
|
+
return { available: true, reason: null };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Async -- spawns the helper's own Gradle wrapper. First invocation on a machine downloads
|
|
33
|
+
// JavaParser's own dependency from Maven Central (a real, one-time network access) -- logged
|
|
34
|
+
// explicitly here, matching this project's own established "network access must be explicit,
|
|
35
|
+
// never silent" precedent (P2's Spring Initializr call).
|
|
36
|
+
export async function runAstClassify(dtoFilePath, srcRoot) {
|
|
37
|
+
const detection = detectAstHelperAvailable();
|
|
38
|
+
if (!detection.available) {
|
|
39
|
+
throw new Error(detection.reason);
|
|
40
|
+
}
|
|
41
|
+
if (!fs.existsSync(path.join(HELPER_DIR, 'gradle', 'wrapper', 'gradle-wrapper.jar'))) {
|
|
42
|
+
throw new Error('the bundled AST helper is missing its Gradle wrapper jar -- this installation may be corrupt');
|
|
43
|
+
}
|
|
44
|
+
console.error('bskel: running the AST helper (downloads its own dependencies from Maven Central on first use -- one-time, requires network)...');
|
|
45
|
+
let stdout;
|
|
46
|
+
try {
|
|
47
|
+
({ stdout } = await execFileAsync(gradlewPath(), ['run', '--console=plain', '-q', `--args="${dtoFilePath}" "${srcRoot}"`], {
|
|
48
|
+
cwd: HELPER_DIR,
|
|
49
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
50
|
+
}));
|
|
51
|
+
} catch (err) {
|
|
52
|
+
throw new Error(`AST helper invocation failed: ${err.stderr || err.message}`);
|
|
53
|
+
}
|
|
54
|
+
const jsonLine = stdout.split('\n').find((line) => line.trim().startsWith('{'));
|
|
55
|
+
if (!jsonLine) {
|
|
56
|
+
throw new Error(`AST helper produced no parseable JSON output:\n${stdout}`);
|
|
57
|
+
}
|
|
58
|
+
return JSON.parse(jsonLine);
|
|
59
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// A2 Phase 2 (D-java-ast-helper): the real JVM helper CATALOG.md's own A2 entry names --
|
|
2
|
+
// JavaParser + Symbol Solver, invoked only when installed via handles/providers/java-spring/
|
|
3
|
+
// ast-bridge.mjs, never a hard dependency of the base `bskel` install. See DECISIONS.md.
|
|
4
|
+
plugins {
|
|
5
|
+
id 'application'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
group = 'com.backendskeleton'
|
|
9
|
+
version = '1.0.0'
|
|
10
|
+
|
|
11
|
+
java {
|
|
12
|
+
toolchain {
|
|
13
|
+
languageVersion = JavaLanguageVersion.of(17)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
mavenCentral()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
dependencies {
|
|
22
|
+
// Verified live against Maven Central before pinning this version -- see D-java-ast-helper.
|
|
23
|
+
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.28.2'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
application {
|
|
27
|
+
mainClass = 'com.backendskeleton.asthelper.Main'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Real args (DTO file path, source root) are passed via `--args` at invocation time
|
|
31
|
+
// (handles/providers/java-spring/ast-bridge.mjs) -- nothing hardcoded here.
|
|
32
|
+
run {
|
|
33
|
+
standardInput = System.in
|
|
34
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
distributionBase=GRADLE_USER_HOME
|
|
2
|
+
distributionPath=wrapper/dists
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
|
|
4
|
+
networkTimeout=10000
|
|
5
|
+
retries=0
|
|
6
|
+
retryBackOffMs=500
|
|
7
|
+
validateDistributionUrl=true
|
|
8
|
+
zipStoreBase=GRADLE_USER_HOME
|
|
9
|
+
zipStorePath=wrapper/dists
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Copyright © 2015 the original authors.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
##############################################################################
|
|
22
|
+
#
|
|
23
|
+
# Gradle start up script for POSIX generated by Gradle.
|
|
24
|
+
#
|
|
25
|
+
# Important for running:
|
|
26
|
+
#
|
|
27
|
+
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
28
|
+
# noncompliant, but you have some other compliant shell such as ksh or
|
|
29
|
+
# bash, then to run this script, type that shell name before the whole
|
|
30
|
+
# command line, like:
|
|
31
|
+
#
|
|
32
|
+
# ksh Gradle
|
|
33
|
+
#
|
|
34
|
+
# Busybox and similar reduced shells will NOT work, because this script
|
|
35
|
+
# requires all of these POSIX shell features:
|
|
36
|
+
# * functions;
|
|
37
|
+
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
38
|
+
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
39
|
+
# * compound commands having a testable exit status, especially «case»;
|
|
40
|
+
# * various built-in commands including «command», «set», and «ulimit».
|
|
41
|
+
#
|
|
42
|
+
# Important for patching:
|
|
43
|
+
#
|
|
44
|
+
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
45
|
+
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
46
|
+
#
|
|
47
|
+
# The "traditional" practice of packing multiple parameters into a
|
|
48
|
+
# space-separated string is a well documented source of bugs and security
|
|
49
|
+
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
50
|
+
# options in "$@", and eventually passing that to Java.
|
|
51
|
+
#
|
|
52
|
+
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
53
|
+
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
54
|
+
# see the in-line comments for details.
|
|
55
|
+
#
|
|
56
|
+
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
57
|
+
# Darwin, MinGW, and NonStop.
|
|
58
|
+
#
|
|
59
|
+
# (3) This script is generated from the Groovy template
|
|
60
|
+
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
61
|
+
# within the Gradle project.
|
|
62
|
+
#
|
|
63
|
+
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
64
|
+
#
|
|
65
|
+
##############################################################################
|
|
66
|
+
|
|
67
|
+
# Attempt to set APP_HOME
|
|
68
|
+
|
|
69
|
+
# Resolve links: $0 may be a link
|
|
70
|
+
app_path=$0
|
|
71
|
+
|
|
72
|
+
# Need this for daisy-chained symlinks.
|
|
73
|
+
while
|
|
74
|
+
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
|
75
|
+
[ -h "$app_path" ]
|
|
76
|
+
do
|
|
77
|
+
ls=$( ls -ld "$app_path" )
|
|
78
|
+
link=${ls#*' -> '}
|
|
79
|
+
case $link in #(
|
|
80
|
+
/*) app_path=$link ;; #(
|
|
81
|
+
*) app_path=$APP_HOME$link ;;
|
|
82
|
+
esac
|
|
83
|
+
done
|
|
84
|
+
|
|
85
|
+
# This is normally unused
|
|
86
|
+
# shellcheck disable=SC2034
|
|
87
|
+
APP_BASE_NAME=${0##*/}
|
|
88
|
+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
89
|
+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
|
90
|
+
|
|
91
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
92
|
+
MAX_FD=maximum
|
|
93
|
+
|
|
94
|
+
warn () {
|
|
95
|
+
echo "$*"
|
|
96
|
+
} >&2
|
|
97
|
+
|
|
98
|
+
die () {
|
|
99
|
+
echo
|
|
100
|
+
echo "$*"
|
|
101
|
+
echo
|
|
102
|
+
exit 1
|
|
103
|
+
} >&2
|
|
104
|
+
|
|
105
|
+
# OS specific support (must be 'true' or 'false').
|
|
106
|
+
cygwin=false
|
|
107
|
+
msys=false
|
|
108
|
+
darwin=false
|
|
109
|
+
nonstop=false
|
|
110
|
+
case "$( uname )" in #(
|
|
111
|
+
CYGWIN* ) cygwin=true ;; #(
|
|
112
|
+
Darwin* ) darwin=true ;; #(
|
|
113
|
+
MSYS* | MINGW* ) msys=true ;; #(
|
|
114
|
+
NONSTOP* ) nonstop=true ;;
|
|
115
|
+
esac
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# Determine the Java command to use to start the JVM.
|
|
120
|
+
if [ -n "$JAVA_HOME" ] ; then
|
|
121
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
122
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
|
123
|
+
JAVACMD=$JAVA_HOME/jre/sh/java
|
|
124
|
+
else
|
|
125
|
+
JAVACMD=$JAVA_HOME/bin/java
|
|
126
|
+
fi
|
|
127
|
+
if [ ! -x "$JAVACMD" ] ; then
|
|
128
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
129
|
+
|
|
130
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
131
|
+
location of your Java installation."
|
|
132
|
+
fi
|
|
133
|
+
else
|
|
134
|
+
JAVACMD=java
|
|
135
|
+
if ! command -v java >/dev/null 2>&1
|
|
136
|
+
then
|
|
137
|
+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
138
|
+
|
|
139
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
140
|
+
location of your Java installation."
|
|
141
|
+
fi
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
# Increase the maximum file descriptors if we can.
|
|
145
|
+
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
146
|
+
case $MAX_FD in #(
|
|
147
|
+
max*)
|
|
148
|
+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
149
|
+
# shellcheck disable=SC2039,SC3045
|
|
150
|
+
MAX_FD=$( ulimit -H -n ) ||
|
|
151
|
+
warn "Could not query maximum file descriptor limit"
|
|
152
|
+
esac
|
|
153
|
+
case $MAX_FD in #(
|
|
154
|
+
'' | soft) :;; #(
|
|
155
|
+
*)
|
|
156
|
+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
157
|
+
# shellcheck disable=SC2039,SC3045
|
|
158
|
+
ulimit -n "$MAX_FD" ||
|
|
159
|
+
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
160
|
+
esac
|
|
161
|
+
fi
|
|
162
|
+
|
|
163
|
+
# Collect all arguments for the java command, stacking in reverse order:
|
|
164
|
+
# * args from the command line
|
|
165
|
+
# * the main class name
|
|
166
|
+
# * -classpath
|
|
167
|
+
# * -D...appname settings
|
|
168
|
+
# * --module-path (only if needed)
|
|
169
|
+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
170
|
+
|
|
171
|
+
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
172
|
+
if "$cygwin" || "$msys" ; then
|
|
173
|
+
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
174
|
+
|
|
175
|
+
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
176
|
+
|
|
177
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
178
|
+
for arg do
|
|
179
|
+
if
|
|
180
|
+
case $arg in #(
|
|
181
|
+
-*) false ;; # don't mess with options #(
|
|
182
|
+
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
183
|
+
[ -e "$t" ] ;; #(
|
|
184
|
+
*) false ;;
|
|
185
|
+
esac
|
|
186
|
+
then
|
|
187
|
+
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
188
|
+
fi
|
|
189
|
+
# Roll the args list around exactly as many times as the number of
|
|
190
|
+
# args, so each arg winds up back in the position where it started, but
|
|
191
|
+
# possibly modified.
|
|
192
|
+
#
|
|
193
|
+
# NB: a `for` loop captures its iteration list before it begins, so
|
|
194
|
+
# changing the positional parameters here affects neither the number of
|
|
195
|
+
# iterations, nor the values presented in `arg`.
|
|
196
|
+
shift # remove old arg
|
|
197
|
+
set -- "$@" "$arg" # push replacement arg
|
|
198
|
+
done
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
203
|
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
204
|
+
|
|
205
|
+
# Collect all arguments for the java command:
|
|
206
|
+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
|
207
|
+
# and any embedded shellness will be escaped.
|
|
208
|
+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
|
209
|
+
# treated as '${Hostname}' itself on the command line.
|
|
210
|
+
|
|
211
|
+
set -- \
|
|
212
|
+
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
213
|
+
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
|
214
|
+
"$@"
|
|
215
|
+
|
|
216
|
+
# Stop when "xargs" is not available.
|
|
217
|
+
if ! command -v xargs >/dev/null 2>&1
|
|
218
|
+
then
|
|
219
|
+
die "xargs is not available"
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
# Use "xargs" to parse quoted args.
|
|
223
|
+
#
|
|
224
|
+
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
225
|
+
#
|
|
226
|
+
# In Bash we could simply go:
|
|
227
|
+
#
|
|
228
|
+
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
229
|
+
# set -- "${ARGS[@]}" "$@"
|
|
230
|
+
#
|
|
231
|
+
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
232
|
+
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
233
|
+
# character that might be a shell metacharacter, then use eval to reverse
|
|
234
|
+
# that process (while maintaining the separation between arguments), and wrap
|
|
235
|
+
# the whole thing up as a single "set" statement.
|
|
236
|
+
#
|
|
237
|
+
# This will of course break if any of these variables contains a newline or
|
|
238
|
+
# an unmatched quote.
|
|
239
|
+
#
|
|
240
|
+
|
|
241
|
+
eval "set -- $(
|
|
242
|
+
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
243
|
+
xargs -n1 |
|
|
244
|
+
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
245
|
+
tr '\n' ' '
|
|
246
|
+
)" '"$@"'
|
|
247
|
+
|
|
248
|
+
exec "$JAVACMD" "$@"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
@rem
|
|
2
|
+
@rem Copyright 2015 the original author or authors.
|
|
3
|
+
@rem
|
|
4
|
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
@rem you may not use this file except in compliance with the License.
|
|
6
|
+
@rem You may obtain a copy of the License at
|
|
7
|
+
@rem
|
|
8
|
+
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
@rem
|
|
10
|
+
@rem Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
@rem See the License for the specific language governing permissions and
|
|
14
|
+
@rem limitations under the License.
|
|
15
|
+
@rem
|
|
16
|
+
@rem SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
@rem
|
|
18
|
+
|
|
19
|
+
@if "%DEBUG%"=="" @echo off
|
|
20
|
+
@rem ##########################################################################
|
|
21
|
+
@rem
|
|
22
|
+
@rem Gradle startup script for Windows
|
|
23
|
+
@rem
|
|
24
|
+
@rem ##########################################################################
|
|
25
|
+
|
|
26
|
+
@rem Set local scope for the variables, and ensure extensions are enabled
|
|
27
|
+
setlocal EnableExtensions
|
|
28
|
+
|
|
29
|
+
set DIRNAME=%~dp0
|
|
30
|
+
if "%DIRNAME%"=="" set DIRNAME=.
|
|
31
|
+
@rem This is normally unused
|
|
32
|
+
set APP_BASE_NAME=%~n0
|
|
33
|
+
set APP_HOME=%DIRNAME%
|
|
34
|
+
|
|
35
|
+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
36
|
+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
37
|
+
|
|
38
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
39
|
+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
40
|
+
|
|
41
|
+
@rem Find java.exe
|
|
42
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
43
|
+
|
|
44
|
+
set JAVA_EXE=java.exe
|
|
45
|
+
%JAVA_EXE% -version >NUL 2>&1
|
|
46
|
+
if %ERRORLEVEL% equ 0 goto execute
|
|
47
|
+
|
|
48
|
+
echo. 1>&2
|
|
49
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
|
50
|
+
echo. 1>&2
|
|
51
|
+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
|
52
|
+
echo location of your Java installation. 1>&2
|
|
53
|
+
|
|
54
|
+
"%COMSPEC%" /c exit 1
|
|
55
|
+
|
|
56
|
+
:findJavaFromJavaHome
|
|
57
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
|
58
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
59
|
+
|
|
60
|
+
if exist "%JAVA_EXE%" goto execute
|
|
61
|
+
|
|
62
|
+
echo. 1>&2
|
|
63
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
|
64
|
+
echo. 1>&2
|
|
65
|
+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
|
66
|
+
echo location of your Java installation. 1>&2
|
|
67
|
+
|
|
68
|
+
"%COMSPEC%" /c exit 1
|
|
69
|
+
|
|
70
|
+
:execute
|
|
71
|
+
@rem Setup the command line
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@rem Execute Gradle
|
|
76
|
+
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
|
77
|
+
@rem which allows us to clear the local environment before executing the java command
|
|
78
|
+
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
|
79
|
+
|
|
80
|
+
:exitWithErrorLevel
|
|
81
|
+
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
|
82
|
+
"%COMSPEC%" /c exit %ERRORLEVEL%
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rootProject.name = 'bskel-java-ast-helper'
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
package com.backendskeleton.asthelper;
|
|
2
|
+
|
|
3
|
+
import com.github.javaparser.ParserConfiguration;
|
|
4
|
+
import com.github.javaparser.StaticJavaParser;
|
|
5
|
+
import com.github.javaparser.ast.CompilationUnit;
|
|
6
|
+
import com.github.javaparser.ast.ImportDeclaration;
|
|
7
|
+
import com.github.javaparser.ast.body.Parameter;
|
|
8
|
+
import com.github.javaparser.ast.body.RecordDeclaration;
|
|
9
|
+
import com.github.javaparser.ast.expr.AnnotationExpr;
|
|
10
|
+
import com.github.javaparser.ast.type.Type;
|
|
11
|
+
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
|
|
12
|
+
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
|
|
13
|
+
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
|
|
14
|
+
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
|
|
15
|
+
|
|
16
|
+
import java.io.File;
|
|
17
|
+
import java.nio.file.Files;
|
|
18
|
+
import java.nio.file.Path;
|
|
19
|
+
import java.util.HashMap;
|
|
20
|
+
import java.util.List;
|
|
21
|
+
import java.util.Map;
|
|
22
|
+
import java.util.Optional;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A2 Phase 2 (D-java-ast-helper): the real JavaParser + Symbol Solver analysis CATALOG.md's own
|
|
26
|
+
* A2 entry names. Invoked only via handles/providers/java-spring/ast-bridge.mjs, only when a
|
|
27
|
+
* human explicitly passes {@code --ast} to {@code bskel handles plan} -- never a hard dependency,
|
|
28
|
+
* never invoked silently. Scope is deliberately narrow: DTO field type + annotation resolution
|
|
29
|
+
* for a top-level {@code record} declaration, matching classifyDtoFields()'s own current scope
|
|
30
|
+
* (patch-strategy.mjs) exactly -- a class-shaped DTO is an out-of-scope gap on BOTH the regex and
|
|
31
|
+
* this AST path, not newly introduced here. Service-signature and security-expression resolution
|
|
32
|
+
* (the other two surface areas CATALOG.md's A2 text names) are explicitly out of scope for this
|
|
33
|
+
* item -- see D-java-ast-helper in DECISIONS.md.
|
|
34
|
+
*
|
|
35
|
+
* <p>Annotation names are resolved via the CompilationUnit's own import list (a plain name map),
|
|
36
|
+
* deliberately NOT via JavaSymbolSolver's AnnotationExpr-specific resolution -- that API has a
|
|
37
|
+
* documented history of unreliability (javaparser/javaparser#1621, a real ClassCastException with
|
|
38
|
+
* no working fix in that thread). Field TYPES are resolved via the standard, reliably-documented
|
|
39
|
+
* {@code Type#resolve()} Symbol Solver pattern instead, which has no comparable reliability
|
|
40
|
+
* history -- this is what actually exercises CombinedTypeSolver/ReflectionTypeSolver/
|
|
41
|
+
* JavaParserTypeSolver for real.
|
|
42
|
+
*
|
|
43
|
+
* <p>Every resolution attempt is wrapped so a single field's failure degrades to the as-written
|
|
44
|
+
* text for THAT field only, never crashes the whole run -- an unusual generic shape or an
|
|
45
|
+
* unresolvable third-party type must never take down analysis of the rest of the DTO.
|
|
46
|
+
*/
|
|
47
|
+
public final class Main {
|
|
48
|
+
|
|
49
|
+
private Main() {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static void main(String[] args) throws Exception {
|
|
53
|
+
if (args.length < 2) {
|
|
54
|
+
System.err.println("usage: Main <dto-file-path> <src-root>");
|
|
55
|
+
System.exit(2);
|
|
56
|
+
}
|
|
57
|
+
String dtoFilePath = args[0];
|
|
58
|
+
String srcRoot = args[1];
|
|
59
|
+
|
|
60
|
+
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
|
|
61
|
+
typeSolver.add(new ReflectionTypeSolver());
|
|
62
|
+
typeSolver.add(new JavaParserTypeSolver(new File(srcRoot)));
|
|
63
|
+
// Found live: JavaParser's default configured language level does not support `record`
|
|
64
|
+
// declarations (the exact DTO shape this helper exists to analyze) -- confirmed by a real
|
|
65
|
+
// ParseProblemException before this line existed. Every generated resolver stub/patch DTO
|
|
66
|
+
// this project's own oracle repos actually use is on a modern Spring Boot toolchain; JDK
|
|
67
|
+
// 17 matches the java-compile fixture's own pinned toolchain elsewhere in this repo.
|
|
68
|
+
StaticJavaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17);
|
|
69
|
+
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
|
|
70
|
+
|
|
71
|
+
CompilationUnit cu = StaticJavaParser.parse(Path.of(dtoFilePath));
|
|
72
|
+
Optional<RecordDeclaration> recordDecl = cu.findFirst(RecordDeclaration.class);
|
|
73
|
+
if (recordDecl.isEmpty()) {
|
|
74
|
+
System.out.println("{\"recordName\":null,\"fields\":[],\"note\":\"no top-level record declaration found\"}");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
RecordDeclaration decl = recordDecl.get();
|
|
78
|
+
|
|
79
|
+
Map<String, String> importsBySimpleName = buildImportMap(cu);
|
|
80
|
+
|
|
81
|
+
StringBuilder json = new StringBuilder();
|
|
82
|
+
json.append("{\"recordName\":").append(jsonString(decl.getNameAsString())).append(",\"fields\":[");
|
|
83
|
+
List<Parameter> components = decl.getParameters();
|
|
84
|
+
for (int i = 0; i < components.size(); i++) {
|
|
85
|
+
if (i > 0) json.append(',');
|
|
86
|
+
appendField(json, components.get(i), importsBySimpleName);
|
|
87
|
+
}
|
|
88
|
+
json.append("]}");
|
|
89
|
+
System.out.println(json);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Simple-name -> fully-qualified-name, from real (non-static, non-asterisk) imports only. */
|
|
93
|
+
private static Map<String, String> buildImportMap(CompilationUnit cu) {
|
|
94
|
+
Map<String, String> map = new HashMap<>();
|
|
95
|
+
for (ImportDeclaration imp : cu.getImports()) {
|
|
96
|
+
if (imp.isAsterisk() || imp.isStatic()) continue;
|
|
97
|
+
String full = imp.getNameAsString();
|
|
98
|
+
int lastDot = full.lastIndexOf('.');
|
|
99
|
+
String simple = lastDot >= 0 ? full.substring(lastDot + 1) : full;
|
|
100
|
+
map.put(simple, full);
|
|
101
|
+
}
|
|
102
|
+
return map;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private static void appendField(StringBuilder json, Parameter param, Map<String, String> importsBySimpleName) {
|
|
106
|
+
String name = param.getNameAsString();
|
|
107
|
+
Type type = param.getType();
|
|
108
|
+
String rawType = type.asString();
|
|
109
|
+
String resolvedType = resolveTypeSafely(type);
|
|
110
|
+
|
|
111
|
+
json.append("{\"name\":").append(jsonString(name))
|
|
112
|
+
.append(",\"rawType\":").append(jsonString(rawType))
|
|
113
|
+
.append(",\"resolvedType\":").append(resolvedType == null ? "null" : jsonString(resolvedType))
|
|
114
|
+
.append(",\"annotations\":[");
|
|
115
|
+
List<AnnotationExpr> annotations = param.getAnnotations();
|
|
116
|
+
for (int i = 0; i < annotations.size(); i++) {
|
|
117
|
+
if (i > 0) json.append(',');
|
|
118
|
+
appendAnnotation(json, annotations.get(i), importsBySimpleName);
|
|
119
|
+
}
|
|
120
|
+
json.append("]}");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Standard, reliable Symbol Solver pattern (type.resolve().describe()) -- this is what
|
|
125
|
+
* actually exercises CombinedTypeSolver against the real classpath. Any resolution failure
|
|
126
|
+
* (an unresolvable generic, a type outside the configured solvers) degrades to null for THIS
|
|
127
|
+
* field only -- the caller falls back to rawType, never crashes the run.
|
|
128
|
+
*/
|
|
129
|
+
private static String resolveTypeSafely(Type type) {
|
|
130
|
+
try {
|
|
131
|
+
return type.resolve().describe();
|
|
132
|
+
} catch (Exception e) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Deliberately NOT AnnotationExpr#resolve() (documented unreliable, see this class's own
|
|
139
|
+
* javadoc) -- a written-fully-qualified annotation (contains a dot) is already fully
|
|
140
|
+
* qualified in the AST with zero resolution needed; a simple-name annotation is looked up
|
|
141
|
+
* against this compilation unit's own real import list.
|
|
142
|
+
*/
|
|
143
|
+
private static void appendAnnotation(StringBuilder json, AnnotationExpr annotation, Map<String, String> importsBySimpleName) {
|
|
144
|
+
String asWritten = annotation.getNameAsString();
|
|
145
|
+
String resolvedFqn;
|
|
146
|
+
if (asWritten.contains(".")) {
|
|
147
|
+
resolvedFqn = asWritten;
|
|
148
|
+
} else {
|
|
149
|
+
resolvedFqn = importsBySimpleName.getOrDefault(asWritten, asWritten);
|
|
150
|
+
}
|
|
151
|
+
json.append("{\"asWritten\":").append(jsonString(asWritten))
|
|
152
|
+
.append(",\"resolvedFqn\":").append(jsonString(resolvedFqn))
|
|
153
|
+
.append('}');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private static String jsonString(String s) {
|
|
157
|
+
StringBuilder sb = new StringBuilder("\"");
|
|
158
|
+
for (int i = 0; i < s.length(); i++) {
|
|
159
|
+
char c = s.charAt(i);
|
|
160
|
+
switch (c) {
|
|
161
|
+
case '"' -> sb.append("\\\"");
|
|
162
|
+
case '\\' -> sb.append("\\\\");
|
|
163
|
+
case '\n' -> sb.append("\\n");
|
|
164
|
+
case '\r' -> sb.append("\\r");
|
|
165
|
+
case '\t' -> sb.append("\\t");
|
|
166
|
+
default -> {
|
|
167
|
+
if (c < 0x20) {
|
|
168
|
+
sb.append(String.format("\\u%04x", (int) c));
|
|
169
|
+
} else {
|
|
170
|
+
sb.append(c);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
sb.append('"');
|
|
176
|
+
return sb.toString();
|
|
177
|
+
}
|
|
178
|
+
}
|