@orsetra/camel-pom-gen 1.0.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/index.ts +232 -0
- package/package.json +42 -0
- package/src/catalog/catalog.ts +81 -0
- package/src/catalog/types.ts +66 -0
- package/src/catalogs/camel-catalog-3.15.3.yaml +3041 -0
- package/src/catalogs/catalog-3.15.3.ts +3044 -0
- package/src/catalogs/index.ts +23 -0
- package/src/config.ts +79 -0
- package/src/dependencies/manager.ts +176 -0
- package/src/dependencies/normalizer.ts +27 -0
- package/src/dependencies/types.ts +75 -0
- package/src/fs-provider.ts +99 -0
- package/src/generator/pom.ts +221 -0
- package/src/generator/project.ts +114 -0
- package/src/generator/template.ts +125 -0
- package/src/global-config.ts +25 -0
- package/src/inspector/base.ts +193 -0
- package/src/inspector/index.ts +30 -0
- package/src/inspector/java.ts +30 -0
- package/src/inspector/types.ts +17 -0
- package/src/inspector/xml.ts +54 -0
- package/src/inspector/yaml.ts +98 -0
- package/src/templates/plain-quarkus.ts +61 -0
- package/src/templates/quarkus.ts +54 -0
- package/src/workspace-config.ts +40 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CamelCatalog } from '../catalog/types'
|
|
2
|
+
import type { InspectionResult, SourceLanguage } from './types'
|
|
3
|
+
import { inspectJavaSource } from './java'
|
|
4
|
+
import { inspectYamlSource } from './yaml'
|
|
5
|
+
import { inspectXmlSource } from './xml'
|
|
6
|
+
import { createEmptyResult } from './base'
|
|
7
|
+
export { createEmptyResult } from './base'
|
|
8
|
+
|
|
9
|
+
export { inspectJavaSource } from './java'
|
|
10
|
+
export { inspectYamlSource } from './yaml'
|
|
11
|
+
export { inspectXmlSource } from './xml'
|
|
12
|
+
export type { InspectionResult, SourceLanguage } from './types'
|
|
13
|
+
|
|
14
|
+
/** Inspect a route source file and return all detected dependencies. */
|
|
15
|
+
export function inspect(
|
|
16
|
+
catalog: CamelCatalog,
|
|
17
|
+
source: string,
|
|
18
|
+
language: SourceLanguage,
|
|
19
|
+
): InspectionResult {
|
|
20
|
+
switch (language) {
|
|
21
|
+
case 'java':
|
|
22
|
+
return inspectJavaSource(catalog, source)
|
|
23
|
+
case 'yaml':
|
|
24
|
+
return inspectYamlSource(catalog, source)
|
|
25
|
+
case 'xml':
|
|
26
|
+
return inspectXmlSource(catalog, source)
|
|
27
|
+
default:
|
|
28
|
+
return createEmptyResult()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Java DSL inspector — mirrors pkg/util/source/java_source_inspector.go.
|
|
3
|
+
* Scans Java source text for route URIs using regex.
|
|
4
|
+
*/
|
|
5
|
+
import type { CamelCatalog } from '../catalog/types'
|
|
6
|
+
import {
|
|
7
|
+
RE_FROM, RE_FROM_F, RE_TO, RE_TO_D, RE_TO_F, RE_WIRE_TAP,
|
|
8
|
+
matchAll, createEmptyResult, analyzeWithCatalog,
|
|
9
|
+
} from './base'
|
|
10
|
+
import type { InspectionResult } from './types'
|
|
11
|
+
|
|
12
|
+
export function inspectJavaSource(catalog: CamelCatalog, source: string): InspectionResult {
|
|
13
|
+
const result = createEmptyResult()
|
|
14
|
+
|
|
15
|
+
result.fromURIs = [
|
|
16
|
+
...matchAll(RE_FROM, source),
|
|
17
|
+
...matchAll(RE_FROM_F, source),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
result.toURIs = [
|
|
21
|
+
...matchAll(RE_TO, source),
|
|
22
|
+
...matchAll(RE_TO_D, source),
|
|
23
|
+
...matchAll(RE_TO_F, source),
|
|
24
|
+
...matchAll(RE_WIRE_TAP, source),
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
analyzeWithCatalog(catalog, result, source)
|
|
28
|
+
|
|
29
|
+
return result
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Result of inspecting a route source file. */
|
|
2
|
+
export interface InspectionResult {
|
|
3
|
+
/** Consumer URIs (from/fromF) */
|
|
4
|
+
fromURIs: string[]
|
|
5
|
+
/** Producer URIs (to/toD/toF/wireTap) */
|
|
6
|
+
toURIs: string[]
|
|
7
|
+
/** Resolved Maven dependency IDs ("mvn:groupId:artifactId") */
|
|
8
|
+
dependencies: string[]
|
|
9
|
+
/** Required capabilities (e.g. "circuit-breaker", "rest", "platform-http") */
|
|
10
|
+
capabilities: string[]
|
|
11
|
+
/** Whether any HTTP endpoint is exposed (platform-http / jetty / etc.) */
|
|
12
|
+
exposesHTTP: boolean
|
|
13
|
+
/** True when all consumer URIs are passive (no active polling) */
|
|
14
|
+
passiveOnly: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SourceLanguage = 'java' | 'yaml' | 'xml' | 'groovy' | 'js' | 'kts'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XML DSL inspector — mirrors pkg/util/source/xml_inspector.go.
|
|
3
|
+
*
|
|
4
|
+
* XML route format:
|
|
5
|
+
* <routes>
|
|
6
|
+
* <route>
|
|
7
|
+
* <from uri="timer:tick"/>
|
|
8
|
+
* <to uri="log:info"/>
|
|
9
|
+
* <toD uri="{{dynamic}}"/>
|
|
10
|
+
* <wireTap uri="direct:tap"/>
|
|
11
|
+
* </route>
|
|
12
|
+
* </routes>
|
|
13
|
+
*
|
|
14
|
+
* We use regex rather than a full XML parser to stay dependency-free.
|
|
15
|
+
*/
|
|
16
|
+
import type { CamelCatalog } from '../catalog/types'
|
|
17
|
+
import { createEmptyResult, analyzeWithCatalog } from './base'
|
|
18
|
+
import type { InspectionResult } from './types'
|
|
19
|
+
|
|
20
|
+
const RE_XML_FROM = /<from[^>]+uri\s*=\s*["']([a-zA-Z0-9-]+:[^"']+)["']/g
|
|
21
|
+
const RE_XML_TO = /<to\s[^>]*uri\s*=\s*["']([a-zA-Z0-9-]+:[^"']+)["']/g
|
|
22
|
+
const RE_XML_TOD = /<toD[^>]+uri\s*=\s*["']([a-zA-Z0-9-]+:[^"']+)["']/g
|
|
23
|
+
const RE_XML_WIRETAP = /<wireTap[^>]+uri\s*=\s*["']([a-zA-Z0-9-]+:[^"']+)["']/g
|
|
24
|
+
// <from><![CDATA[timer:tick]]></from> — rare but possible
|
|
25
|
+
const RE_XML_FROM_CDATA = /<from>\s*<!\[CDATA\[([a-zA-Z0-9-]+:[^\]]+)\]\]>\s*<\/from>/g
|
|
26
|
+
const RE_XML_TO_CDATA = /<to>\s*<!\[CDATA\[([a-zA-Z0-9-]+:[^\]]+)\]\]>\s*<\/to>/g
|
|
27
|
+
|
|
28
|
+
function matchAllXml(re: RegExp, text: string): string[] {
|
|
29
|
+
const results: string[] = []
|
|
30
|
+
re.lastIndex = 0
|
|
31
|
+
let m: RegExpExecArray | null
|
|
32
|
+
while ((m = re.exec(text)) !== null) results.push(m[1])
|
|
33
|
+
re.lastIndex = 0
|
|
34
|
+
return results
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function inspectXmlSource(catalog: CamelCatalog, source: string): InspectionResult {
|
|
38
|
+
const result = createEmptyResult()
|
|
39
|
+
|
|
40
|
+
result.fromURIs = [
|
|
41
|
+
...matchAllXml(RE_XML_FROM, source),
|
|
42
|
+
...matchAllXml(RE_XML_FROM_CDATA, source),
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
result.toURIs = [
|
|
46
|
+
...matchAllXml(RE_XML_TO, source),
|
|
47
|
+
...matchAllXml(RE_XML_TOD, source),
|
|
48
|
+
...matchAllXml(RE_XML_WIRETAP, source),
|
|
49
|
+
...matchAllXml(RE_XML_TO_CDATA, source),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
analyzeWithCatalog(catalog, result, source)
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML DSL inspector — mirrors pkg/util/source/yaml_inspector.go.
|
|
3
|
+
*
|
|
4
|
+
* YAML route format (Camel K YAML DSL):
|
|
5
|
+
* - from:
|
|
6
|
+
* uri: timer:tick
|
|
7
|
+
* steps:
|
|
8
|
+
* - to: log:info
|
|
9
|
+
* - to:
|
|
10
|
+
* uri: kafka:topic
|
|
11
|
+
* - to-d:
|
|
12
|
+
* uri: "{{dynamic}}"
|
|
13
|
+
* - wire-tap:
|
|
14
|
+
* uri: direct:tap
|
|
15
|
+
*/
|
|
16
|
+
import yaml from 'js-yaml'
|
|
17
|
+
import type { CamelCatalog } from '../catalog/types'
|
|
18
|
+
import { createEmptyResult, analyzeWithCatalog } from './base'
|
|
19
|
+
import type { InspectionResult } from './types'
|
|
20
|
+
|
|
21
|
+
type AnyObj = Record<string, unknown>
|
|
22
|
+
|
|
23
|
+
function extractURIs(node: unknown, fromURIs: string[], toURIs: string[], isFrom = false): void {
|
|
24
|
+
if (!node || typeof node !== 'object') return
|
|
25
|
+
|
|
26
|
+
if (Array.isArray(node)) {
|
|
27
|
+
for (const item of node) extractURIs(item, fromURIs, toURIs, isFrom)
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const obj = node as AnyObj
|
|
32
|
+
|
|
33
|
+
// --- from / from block ---
|
|
34
|
+
if ('from' in obj) {
|
|
35
|
+
const from = obj['from']
|
|
36
|
+
if (typeof from === 'string') {
|
|
37
|
+
fromURIs.push(from)
|
|
38
|
+
} else if (from && typeof from === 'object') {
|
|
39
|
+
const uri = (from as AnyObj)['uri']
|
|
40
|
+
if (typeof uri === 'string') fromURIs.push(uri)
|
|
41
|
+
extractURIs((from as AnyObj)['steps'], fromURIs, toURIs, false)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// --- to / to block ---
|
|
46
|
+
for (const key of ['to', 'to-d', 'toD']) {
|
|
47
|
+
if (key in obj) {
|
|
48
|
+
const to = obj[key]
|
|
49
|
+
if (typeof to === 'string') {
|
|
50
|
+
toURIs.push(to)
|
|
51
|
+
} else if (to && typeof to === 'object') {
|
|
52
|
+
const uri = (to as AnyObj)['uri']
|
|
53
|
+
if (typeof uri === 'string') toURIs.push(uri)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// --- wire-tap / wireTap ---
|
|
59
|
+
for (const key of ['wire-tap', 'wireTap']) {
|
|
60
|
+
if (key in obj) {
|
|
61
|
+
const wt = obj[key]
|
|
62
|
+
if (typeof wt === 'string') {
|
|
63
|
+
toURIs.push(wt)
|
|
64
|
+
} else if (wt && typeof wt === 'object') {
|
|
65
|
+
const uri = (wt as AnyObj)['uri']
|
|
66
|
+
if (typeof uri === 'string') toURIs.push(uri)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// --- kamelet step ---
|
|
72
|
+
if ('kamelet' in obj) {
|
|
73
|
+
const k = obj['kamelet']
|
|
74
|
+
const name = typeof k === 'string' ? k : (k as AnyObj)?.['name']
|
|
75
|
+
if (typeof name === 'string' && !name.includes('/')) {
|
|
76
|
+
toURIs.push(`kamelet:${name}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --- recurse into steps and route blocks ---
|
|
81
|
+
for (const key of ['steps', 'routes', 'route']) {
|
|
82
|
+
if (key in obj) extractURIs(obj[key], fromURIs, toURIs, false)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function inspectYamlSource(catalog: CamelCatalog, source: string): InspectionResult {
|
|
87
|
+
const result = createEmptyResult()
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const parsed = yaml.load(source)
|
|
91
|
+
extractURIs(parsed, result.fromURIs, result.toURIs, true)
|
|
92
|
+
} catch {
|
|
93
|
+
// malformed YAML — fall through with empty URIs
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
analyzeWithCatalog(catalog, result, source)
|
|
97
|
+
return result
|
|
98
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default pom.xml template for plain-quarkus runtime (Camel K v2.11+).
|
|
3
|
+
*
|
|
4
|
+
* Tokens: {{operatorVersion}}, {{runtimeVersion}}, {{outputTimestamp}}, {{dependencies}}
|
|
5
|
+
*
|
|
6
|
+
* JIB profile is intentionally absent — the operator injects it via
|
|
7
|
+
* injectJibProfile() in git mode (pkg/builder/git.go).
|
|
8
|
+
*
|
|
9
|
+
* Format mirrors the operator's maven_project.go serializer:
|
|
10
|
+
* xml.Header + e.Indent("", " ") → 2-space indentation, UTF-8 declared.
|
|
11
|
+
*/
|
|
12
|
+
export const PLAIN_QUARKUS_TEMPLATE = `<?xml version="1.0" encoding="UTF-8"?>
|
|
13
|
+
<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">
|
|
14
|
+
<modelVersion>4.0.0</modelVersion>
|
|
15
|
+
<groupId>org.apache.camel.k.integration</groupId>
|
|
16
|
+
<artifactId>camel-k-integration</artifactId>
|
|
17
|
+
<version>{{operatorVersion}}</version>
|
|
18
|
+
<properties>
|
|
19
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
20
|
+
<quarkus.package.jar.type>fast-jar</quarkus.package.jar.type>
|
|
21
|
+
<project.build.outputTimestamp>{{outputTimestamp}}</project.build.outputTimestamp>
|
|
22
|
+
</properties>
|
|
23
|
+
<dependencyManagement>
|
|
24
|
+
<dependencies>
|
|
25
|
+
<dependency>
|
|
26
|
+
<groupId>io.quarkus.platform</groupId>
|
|
27
|
+
<artifactId>quarkus-camel-bom</artifactId>
|
|
28
|
+
<version>{{runtimeVersion}}</version>
|
|
29
|
+
<type>pom</type>
|
|
30
|
+
<scope>import</scope>
|
|
31
|
+
</dependency>
|
|
32
|
+
<dependency>
|
|
33
|
+
<groupId>io.quarkus.platform</groupId>
|
|
34
|
+
<artifactId>quarkus-bom</artifactId>
|
|
35
|
+
<version>{{runtimeVersion}}</version>
|
|
36
|
+
<type>pom</type>
|
|
37
|
+
<scope>import</scope>
|
|
38
|
+
</dependency>
|
|
39
|
+
</dependencies>
|
|
40
|
+
</dependencyManagement>
|
|
41
|
+
{{dependencies}}
|
|
42
|
+
<build>
|
|
43
|
+
<plugins>
|
|
44
|
+
<plugin>
|
|
45
|
+
<groupId>io.quarkus</groupId>
|
|
46
|
+
<artifactId>quarkus-maven-plugin</artifactId>
|
|
47
|
+
<version>{{runtimeVersion}}</version>
|
|
48
|
+
<extensions>true</extensions>
|
|
49
|
+
<executions>
|
|
50
|
+
<execution>
|
|
51
|
+
<id>build-integration</id>
|
|
52
|
+
<goals>
|
|
53
|
+
<goal>build</goal>
|
|
54
|
+
</goals>
|
|
55
|
+
</execution>
|
|
56
|
+
</executions>
|
|
57
|
+
</plugin>
|
|
58
|
+
</plugins>
|
|
59
|
+
</build>
|
|
60
|
+
</project>
|
|
61
|
+
`
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default pom.xml template for legacy quarkus runtime (Camel K v2.10 and below).
|
|
3
|
+
*
|
|
4
|
+
* Tokens: {{operatorVersion}}, {{runtimeVersion}}, {{quarkusPlatformVersion}}, {{outputTimestamp}}, {{dependencies}}
|
|
5
|
+
*
|
|
6
|
+
* JIB profile is intentionally absent — the operator injects it via
|
|
7
|
+
* injectJibProfile() in git mode (pkg/builder/git.go).
|
|
8
|
+
*
|
|
9
|
+
* Format mirrors the operator's maven_project.go serializer:
|
|
10
|
+
* xml.Header + e.Indent("", " ") → 2-space indentation, UTF-8 declared.
|
|
11
|
+
*/
|
|
12
|
+
export const QUARKUS_TEMPLATE = `<?xml version="1.0" encoding="UTF-8"?>
|
|
13
|
+
<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">
|
|
14
|
+
<modelVersion>4.0.0</modelVersion>
|
|
15
|
+
<groupId>org.apache.camel.k.integration</groupId>
|
|
16
|
+
<artifactId>camel-k-integration</artifactId>
|
|
17
|
+
<version>{{operatorVersion}}</version>
|
|
18
|
+
<properties>
|
|
19
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
20
|
+
<quarkus.package.jar.type>fast-jar</quarkus.package.jar.type>
|
|
21
|
+
<project.build.outputTimestamp>{{outputTimestamp}}</project.build.outputTimestamp>
|
|
22
|
+
</properties>
|
|
23
|
+
<dependencyManagement>
|
|
24
|
+
<dependencies>
|
|
25
|
+
<dependency>
|
|
26
|
+
<groupId>org.apache.camel.k</groupId>
|
|
27
|
+
<artifactId>camel-k-runtime-bom</artifactId>
|
|
28
|
+
<version>{{runtimeVersion}}</version>
|
|
29
|
+
<type>pom</type>
|
|
30
|
+
<scope>import</scope>
|
|
31
|
+
</dependency>
|
|
32
|
+
</dependencies>
|
|
33
|
+
</dependencyManagement>
|
|
34
|
+
{{dependencies}}
|
|
35
|
+
<build>
|
|
36
|
+
<plugins>
|
|
37
|
+
<plugin>
|
|
38
|
+
<groupId>io.quarkus</groupId>
|
|
39
|
+
<artifactId>quarkus-maven-plugin</artifactId>
|
|
40
|
+
<version>{{quarkusPlatformVersion}}</version>
|
|
41
|
+
<extensions>true</extensions>
|
|
42
|
+
<executions>
|
|
43
|
+
<execution>
|
|
44
|
+
<id>build-integration</id>
|
|
45
|
+
<goals>
|
|
46
|
+
<goal>build</goal>
|
|
47
|
+
</goals>
|
|
48
|
+
</execution>
|
|
49
|
+
</executions>
|
|
50
|
+
</plugin>
|
|
51
|
+
</plugins>
|
|
52
|
+
</build>
|
|
53
|
+
</project>
|
|
54
|
+
`
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import jsyaml from 'js-yaml'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Schema for camel-pom-gen.yaml — the workspace-level config file
|
|
5
|
+
* committed to the git repo alongside the routes.
|
|
6
|
+
*
|
|
7
|
+
* Manual dependencies and pom customizations (repositories, profiles, plugins)
|
|
8
|
+
* are added directly to the generated pom.xml — updatePom() preserves them.
|
|
9
|
+
* This config only covers what cannot be expressed in the pom itself.
|
|
10
|
+
*
|
|
11
|
+
* Supported locations (IDE reads one of these, in order):
|
|
12
|
+
* camel-pom-gen.yaml
|
|
13
|
+
* .camel/camel-pom-gen.yaml
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkspaceConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Target operator version. Drives the runtime flavor (plain-quarkus vs quarkus),
|
|
18
|
+
* BOM versions, and quarkus-maven-plugin version.
|
|
19
|
+
* Defaults to the latest known version when omitted.
|
|
20
|
+
*/
|
|
21
|
+
operatorVersion?: string
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parse a camel-pom-gen.yaml file content into a WorkspaceConfig.
|
|
27
|
+
* The IDE reads the file and passes its content here.
|
|
28
|
+
*/
|
|
29
|
+
export function parseWorkspaceConfig(yamlContent: string): WorkspaceConfig {
|
|
30
|
+
const parsed = jsyaml.load(yamlContent)
|
|
31
|
+
if (!parsed || typeof parsed !== 'object') return {}
|
|
32
|
+
const raw = parsed as Record<string, unknown>
|
|
33
|
+
|
|
34
|
+
const config: WorkspaceConfig = {}
|
|
35
|
+
|
|
36
|
+
if (typeof raw.operatorVersion === 'string') {
|
|
37
|
+
config.operatorVersion = raw.operatorVersion
|
|
38
|
+
}
|
|
39
|
+
return config
|
|
40
|
+
}
|