Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class ConfigDefDetector extends AbstractJavaParserDetector {
private static final Pattern DEFINE_RE = Pattern.compile("\\.define\\s*\\(\\s*\"([^\"]+)\"");
private static final Pattern VALUE_RE = Pattern.compile("@Value\\s*\\(\\s*\"\\$\\{([^}]+)\\}\"");
private static final Pattern CONFIG_PROPS_RE = Pattern.compile("@ConfigurationProperties\\s*\\(\\s*(?:prefix\\s*=\\s*)?\"([^\"]+)\"");
private static final Pattern VALUE_KEY_RE = Pattern.compile("\"\\$\\{([^}]+)\\}\"");
private static final Pattern QUOTED_STRING_RE = Pattern.compile("\"([^\"]+)\"");

private static final String VALUE_ANNOTATION = "Value";
private static final String CONFIG_PROPS_ANNOTATION = "ConfigurationProperties";
Expand Down Expand Up @@ -157,15 +159,15 @@ private DetectorResult detectWithAst(CompilationUnit cu, DetectorContext ctx) {
private Optional<String> extractValueKey(AnnotationExpr ann) {
// @Value("${some.key}") or @Value(value = "${some.key}")
String raw = ann.toString();
Matcher m = Pattern.compile("\"\\$\\{([^}]+)\\}\"").matcher(raw);
Matcher m = VALUE_KEY_RE.matcher(raw);
if (m.find()) return Optional.of(m.group(1));
return Optional.empty();
}

private Optional<String> extractAnnotationStringValue(AnnotationExpr ann) {
// @ConfigurationProperties("prefix") or @ConfigurationProperties(prefix = "prefix")
String raw = ann.toString();
Matcher m = Pattern.compile("\"([^\"]+)\"").matcher(raw);
Matcher m = QUOTED_STRING_RE.matcher(raw);
if (m.find()) return Optional.of(m.group(1));
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class KafkaDetector extends AbstractRegexDetector {
private static final Pattern KAFKA_SEND_RE = Pattern.compile(
"(?:kafkaTemplate|KafkaTemplate)\\s*\\.send\\s*\\(\\s*\"([^\"]+)\"");
private static final Pattern GROUP_ID_RE = Pattern.compile("groupId\\s*=\\s*\"([^\"]+)\"");
private static final Pattern QUOTED_TOPIC_RE = Pattern.compile("\"([^\"]+)\"");

@Override
public String getName() {
Expand Down Expand Up @@ -84,7 +85,7 @@ public DetectorResult detect(DetectorContext ctx) {
Matcher m = KAFKA_LISTENER_RE.matcher(lines[i]);
if (!m.find()) {
if (i > 0 && lines[i - 1].contains("@KafkaListener")) {
Matcher fallback = Pattern.compile("\"([^\"]+)\"").matcher(lines[i]);
Matcher fallback = QUOTED_TOPIC_RE.matcher(lines[i]);
if (fallback.find()) {
String topic = fallback.group(1);
String topicId = ensureTopicNode(topic, seenTopics, nodes, registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SpringRestDetector extends AbstractJavaParserDetector {
// ---- HTTP client patterns (for CALLS edge emission) ----
private static final Pattern REST_TEMPLATE_RE = Pattern.compile("RestTemplate");
private static final Pattern WEB_CLIENT_RE = Pattern.compile("WebClient");
private static final Pattern BARE_QUOTED_RE = Pattern.compile("\"([^\"]*)\"");
private static final Pattern FEIGN_CLIENT_RE = Pattern.compile(
"@FeignClient\\s*\\(\\s*(?:name\\s*=\\s*)?[\"']([^\"']+)[\"']");

Expand Down Expand Up @@ -342,7 +343,7 @@ private DetectorResult detectWithRegex(DetectorContext ctx) {

String path = extractAttr(attrStr, VALUE_RE);
if (path == null && attrStr != null) {
Matcher bare = Pattern.compile("\"([^\"]*)\"").matcher(attrStr);
Matcher bare = BARE_QUOTED_RE.matcher(attrStr);
if (bare.find()) path = bare.group(1);
}
if (path == null) path = "";
Expand Down
Loading