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
@@ -0,0 +1,21 @@
{
"resources": {
"includes": [
{
"pattern": "extensions_config.yaml"
},
{
"pattern": "languages_comment_config.yaml"
},
{
"pattern": "default_tag_mapping.yaml"
},
{
"pattern": "remediations.xsd"
},
{
"pattern": "webinspect.xsd"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
"allDeclaredMethods": true, "allPublicMethods": true,
"allDeclaredFields": true, "allPublicFields": true
},
{
"name":"com.fortify.cli.aviator.config.LanguagesCommentConfig",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredFields": true,
"allPublicFields": true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"setLineCommentSymbols","parameterTypes":["java.util.Map"] }]
},
{
"name":"com.fortify.cli.aviator.config.TagMappingConfig",
"allDeclaredFields":true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@

import com.fortify.cli.aviator._common.exception.AviatorBugException;
import com.fortify.cli.aviator.config.ExtensionsConfig;
import com.fortify.cli.aviator.config.LanguagesCommentConfig;
import com.fortify.cli.aviator.config.TagMappingConfig;
import com.fortify.cli.aviator.util.FileTypeLanguageMapperUtil;
import com.fortify.cli.aviator.util.LanguageCommentMapperUtil;
import com.fortify.cli.aviator.util.ResourceUtil;

public class AviatorConfigManager {
private static final Logger LOG = LoggerFactory.getLogger(AviatorConfigManager.class);
private static final String EXTENSIONS_CONFIG_RESOURCE = "extensions_config.yaml";
private static final String LANGUAGES_COMMENT_CONFIG_RESOURCE = "languages_comment_config.yaml";
private static final String DEFAULT_TAG_MAPPING_RESOURCE = "default_tag_mapping.yaml";

private static volatile AviatorConfigManager instance;
private static final Object lock = new Object();

private final ExtensionsConfig extensionsConfig;
private final LanguagesCommentConfig languagesCommentConfig;
private final TagMappingConfig defaultTagMappingConfig;

private AviatorConfigManager() {
LOG.debug("Initializing AviatorConfigManager...");
this.extensionsConfig = ResourceUtil.loadYamlResource(EXTENSIONS_CONFIG_RESOURCE, ExtensionsConfig.class);
this.languagesCommentConfig = ResourceUtil.loadYamlResource(LANGUAGES_COMMENT_CONFIG_RESOURCE, LanguagesCommentConfig.class);
this.defaultTagMappingConfig = ResourceUtil.loadYamlResource(DEFAULT_TAG_MAPPING_RESOURCE, TagMappingConfig.class);

if (this.extensionsConfig != null) {
Expand All @@ -43,6 +48,12 @@ private AviatorConfigManager() {
} else {
LOG.error("ExtensionsConfig is null, FileTypeLanguageMapperUtil cannot be initialized properly.");
}
if (this.languagesCommentConfig != null) {
LanguageCommentMapperUtil.initializeConfig(this.languagesCommentConfig);
LOG.debug("LanguageCommentMapperUtil initialized.");
} else {
LOG.error("LanguagesCommentConfig is null, LanguageCommentMapperUtil cannot be initialized properly.");
}
LOG.debug("AviatorConfigManager initialized successfully.");
}

Expand All @@ -65,6 +76,14 @@ public ExtensionsConfig getExtensionsConfig() {
return extensionsConfig;
}

public LanguagesCommentConfig getLanguagesCommentConfig() {
if (languagesCommentConfig == null) {
LOG.error("LanguagesCommentConfig was not loaded. This indicates a bug.");
throw new AviatorBugException("Critical: LanguagesCommentConfig not loaded.");
}
return languagesCommentConfig;
}

public TagMappingConfig getDefaultTagMappingConfig() {
if (defaultTagMappingConfig == null) {
LOG.error("DefaultTagMappingConfig was not loaded. This indicates a bug.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
import java.util.HashMap;
import java.util.Map;

import com.formkiq.graalvm.annotations.Reflectable;
import com.fortify.cli.aviator.util.StringUtil;

import lombok.NoArgsConstructor;

@NoArgsConstructor @Reflectable
public class LanguagesCommentConfig {
private Map<String, String> lineCommentSymbols = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ private void processFileForElement(StackTraceElement element, Map<String, File>
try {
if (Files.exists(actualSourcePath)) {
byte[] encodedBytes = Files.readAllBytes(actualSourcePath);
file.setContent(new String(encodedBytes));
String content = new String(encodedBytes);
// Preserve numbered source lines for prompt fidelity; content is later forwarded as-is.
file.setContent(fileUtils.appendLineNumbers(content, filename, 0));
file.setEndLine(fileUtils.countLines(actualSourcePath));
} else {
// This warning is now more accurate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public String getLineFromFile(FprHandle fprHandle, String relativePath, int line

List<String> lines = readFileWithFallback(fullSourcePath);
if (lineNumber > 0 && lines.size() >= lineNumber) {
return lines.get(lineNumber - 1);
return appendLineNumbers(lines.get(lineNumber - 1), relativePath, lineNumber - 1);
}
logger.info("Could not get line {} from file {} (total lines: {})", lineNumber, fullSourcePath, lines.size());
return "";
Expand Down Expand Up @@ -110,7 +110,7 @@ public Fragment getFragmentFromFile(FprHandle fprHandle, String relativePath, in
sb.append(lines.get(i)).append(System.lineSeparator());
}

return new Fragment(sb.toString(), startLine, endLine);
return new Fragment(appendLineNumbers(sb.toString(), relativePath, startLine - 1), startLine, endLine);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ private void processFileForElement(StackTraceElement element, Map<String, File>
try {
if (Files.exists(actualSourcePath)) {
byte[] encodedBytes = Files.readAllBytes(actualSourcePath);
file.setContent(new String(encodedBytes));
String content = new String(encodedBytes);
// Keep line markers in prompt file content; downstream gRPC/template rendering is pass-through.
file.setContent(fileUtils.appendLineNumbers(content, filename, 0));
file.setEndLine(fileUtils.countLines(actualSourcePath));
} else {
// This warning is now more accurate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.fortify.cli.aviator._common.config.AviatorConfigManager;
import com.fortify.cli.aviator.config.LanguagesCommentConfig;
import com.fortify.cli.aviator.util.LanguageCommentMapperUtil;

Expand Down Expand Up @@ -53,4 +54,14 @@ void shouldUseResolvedLanguageForBlockCommentSyntax() {

assertEquals("<div/> <!-- L1 -->", result);
}

@Test
void shouldUseConfiguredLanguageAndCommentMappingForFileExtension() {
AviatorConfigManager.getInstance();
FileUtils fileUtils = new FileUtils();

String result = fileUtils.appendLineNumbers("package com.example;", "src/main/java/com/example/HomeController.java", 0);

assertEquals("package com.example; // L1", result);
}
}
Loading