Skip to content

Commit f695c18

Browse files
authored
Merge pull request #42 from theodo-group/v2/editor-dropdown
Add editor dropdown selector
2 parents 7525fa8 + ba63c9e commit f695c18

8 files changed

Lines changed: 76 additions & 14 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Follow these three steps to quickly use the Spring Access Inspector:
2121
<plugin>
2222
<groupId>com.theodo</groupId>
2323
<artifactId>spring-access-inspector-plugin</artifactId>
24-
<version>2.2.4</version>
24+
<version>2.3.0</version>
2525
</plugin>
2626
<!-- ...existing plugins... -->
2727
</plugins>
@@ -42,7 +42,7 @@ Follow these three steps to quickly use the Spring Access Inspector:
4242
<plugin>
4343
<groupId>com.theodo</groupId>
4444
<artifactId>spring-access-inspector-plugin</artifactId>
45-
<version>1.2.4</version>
45+
<version>1.3.0</version>
4646
</plugin>
4747
<!-- ...existing plugins... -->
4848
</plugins>
@@ -135,7 +135,7 @@ The Maven plugin simplifies launching the inspector by adding it to the `pom.xml
135135
<plugin>
136136
<groupId>com.theodo</groupId>
137137
<artifactId>spring-access-inspector-plugin</artifactId>
138-
<version>2.2.4</version>
138+
<version>2.3.0</version>
139139
</plugin>
140140
</plugins>
141141
</pluginManagement>
@@ -163,7 +163,7 @@ You can customize the plugin behavior by adding the following configuration opti
163163
<plugin>
164164
<groupId>com.theodo</groupId>
165165
<artifactId>spring-access-inspector-plugin</artifactId>
166-
<version>2.2.4</version>
166+
<version>2.3.0</version>
167167
<configuration>
168168
<projectBaseDir>${project.basedir}</projectBaseDir>
169169
<outputFileName>~/my/output_file</outputFileName>

inspector-maven-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.theodo</groupId>
88
<artifactId>spring-access-inspector-plugin</artifactId>
9-
<version>2.2.4</version>
9+
<version>2.3.0</version>
1010
<name>Spring access inspector Maven plugin</name>
1111
<description>Use Spoon AST analysis to discover and analyse @PreAuthorize annotations</description>
1212
<url>https://github.com/theodo-group/spring-access-inspector</url>
@@ -52,7 +52,7 @@
5252
<connection>scm:git:git://github.com/theodo-group/spring-access-inspector.git</connection>
5353
<developerConnection>scm:git:ssh://github.com/theodo-group/spring-access-inspector.git</developerConnection>
5454
<url>https://github.com/theodo-group/spring-access-inspector</url>
55-
<tag>v2.2.4</tag>
55+
<tag>v2.3.0</tag>
5656
</scm>
5757

5858
<distributionManagement>

inspector/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.theodo</groupId>
88
<artifactId>spring-access-inspector</artifactId>
9-
<version>2.2.4</version>
9+
<version>2.3.0</version>
1010
<name>Spring access inspector</name>
1111
<description>Use Spoon AST analysis to discover and analyse @PreAuthorize annotations</description>
1212
<url>https://github.com/theodo-group/spring-access-inspector</url>
@@ -52,7 +52,7 @@
5252
<connection>scm:git:git://github.com/theodo-group/spring-access-inspector.git</connection>
5353
<developerConnection>scm:git:ssh://github.com/theodo-group/spring-access-inspector.git</developerConnection>
5454
<url>https://github.com/theodo-group/spring-access-inspector</url>
55-
<tag>v2.2.4</tag>
55+
<tag>v2.3.0</tag>
5656
</scm>
5757

5858
<distributionManagement>

inspector/scripts/generate-embedded-assets.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ for js_file in "$JS_FOLDER"/*.js; do
4343
constant_name=$(basename "$js_file" .js | sed -E 's/([a-z])([A-Z])/\1_\2/g' | tr '[:lower:]' '[:upper:]' | tr '-' '_' | tr '.' '_')_JS
4444
{
4545
echo " public static final String $constant_name = \"\"\""
46-
cat "$js_file"
46+
# Double backslashes so Java doesn't treat things like \? as escapes
47+
sed 's/\\/\\\\/g' "$js_file"
4748
echo "\"\"\";"
4849
echo ""
4950
} >> "$JAVA_FILE"

inspector/src/main/java/com/theodo/inspector/builder/HtmlBuilder.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public static void generateHtmlTable(List<AnnotationDto> annotations, String htm
1818
htmlTable.append("\n<head>\n");
1919
htmlTable.append(generateStyles());
2020
htmlTable.append(generateScripts());
21-
htmlTable.append("</head>\n<body>\n<table>\n<tr>\n");
21+
htmlTable.append("</head>\n<body>\n");
22+
htmlTable.append(generateEditorSelector(editor));
23+
htmlTable.append("<table>\n<tr>\n");
2224
htmlTable.append(generateTableHeader("Endpoint", 0, "43%"));
2325
htmlTable.append(generateTableHeader("Method", 1, "14%"));
2426
htmlTable.append(generateTableHeader("PreAuthorize", 2, "43%"));
@@ -87,7 +89,7 @@ private static String generateScripts() {
8789
// in "inspector/target/generated-sources/embedded/com/theodo/inspector/utils/EmbeddedAssets.java"
8890
return """
8991
<script>
90-
""" + EmbeddedAssets.SORT_TABLE_JS + EmbeddedAssets.FILTER_TABLE_JS + """
92+
""" + EmbeddedAssets.SORT_TABLE_JS + EmbeddedAssets.FILTER_TABLE_JS + EmbeddedAssets.SWITCH_EDITOR_JS + """
9193
</script>
9294
""";
9395
}
@@ -103,6 +105,16 @@ private static String generateTableHeader(String title, int columnIndex, String
103105
"</th>";
104106
}
105107

108+
private static String generateEditorSelector(Editor defaulEditor) {
109+
return "<div style=\"margin-bottom: 10px;\">" +
110+
"<label for=\"linkPrefix\">Select IDE: </label>" +
111+
"<select id=\"linkPrefix\" onchange=\"updateLinks()\">" +
112+
"<option value=\"none\"" + (defaulEditor == Editor.NONE ? " selected" : "") + ">None</option>" +
113+
"<option value=\"vscode\"" + (defaulEditor == Editor.VSCODE ? " selected" : "") + ">VSCode</option>" +
114+
"<option value=\"intellij\"" + (defaulEditor == Editor.INTELLIJ ? " selected" : "") + ">IntelliJ</option>" +
115+
"</select></div>";
116+
}
117+
106118
private static void addTableRow(StringBuilder htmlTable, AnnotationDto annotation, Editor editor) {
107119
String url;
108120
boolean openInNewTab = false;
@@ -119,7 +131,7 @@ private static void addTableRow(StringBuilder htmlTable, AnnotationDto annotatio
119131
openInNewTab = true;
120132
break;
121133
}
122-
htmlTable.append("<tr>\n<td><a href='").append(StringEscapeUtils.escapeHtml4(url)).append("'")
134+
htmlTable.append("<tr>\n<td><a class=\"link\" href='").append(StringEscapeUtils.escapeHtml4(url)).append("'")
123135
.append(openInNewTab ? "target='_blank'" : "").append(">")
124136
.append(StringEscapeUtils.escapeHtml4(annotation.endpoint())).append("</a></td>\n").append("<td>")
125137
.append(StringEscapeUtils.escapeHtml4(annotation.method().replace("Mapping", "").toUpperCase()))
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Updates the href attributes of all links in the table based on the selected IDE.
3+
*/
4+
function updateLinks() {
5+
const prefix = document.getElementById('linkPrefix').value;
6+
const links = document.querySelectorAll('.link');
7+
8+
links.forEach(link => {
9+
const href = link.getAttribute('href');
10+
const originalEditor = href.split('://')[0];
11+
let originalPath = '';
12+
let lineNumber = '';
13+
switch (originalEditor) {
14+
case 'file':
15+
originalPath = href.replace('file://', '').split('#')[0];
16+
lineNumber = href.split('#')[1] || '';
17+
break;
18+
case 'vscode':
19+
originalPath = href.replace('vscode://file', '').split(':')[0];
20+
lineNumber = href.replace('vscode://file', '').split(':')[1] || '';
21+
break;
22+
case 'idea':
23+
originalPath = href.replace('idea://open?file=', '').split('&line=')[0];
24+
lineNumber = href.split('&line=')[1] || '';
25+
break;
26+
default:
27+
return;
28+
}
29+
30+
let newHref = '';
31+
switch (prefix) {
32+
case 'vscode':
33+
newHref = `vscode://file${originalPath}${lineNumber ? `:${lineNumber}` : ''}`;
34+
link.removeAttribute('target');
35+
break;
36+
case 'intellij':
37+
newHref = `idea://open?file=${originalPath}${lineNumber ? `&line=${lineNumber}` : ''}`;
38+
link.removeAttribute('target');
39+
break;
40+
case 'none':
41+
default:
42+
newHref = `file://${originalPath}${lineNumber ? `#${lineNumber}` : ''}`;
43+
link.setAttribute('target', '_blank');
44+
break;
45+
}
46+
47+
link.setAttribute('href', newHref);
48+
});
49+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>com.theodo</groupId>
1010
<artifactId>spring-access-inspector-aggregate</artifactId>
11-
<version>2.2.4</version>
11+
<version>2.3.0</version>
1212
<name>Spring access inspector aggregate</name>
1313
<description>Aggregation project that contains tests projects and inspector projects</description>
1414
<url>https://github.com/theodo-group/spring-access-inspector</url>

sample/microservice-example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<plugin>
6565
<groupId>com.theodo</groupId>
6666
<artifactId>spring-access-inspector-plugin</artifactId>
67-
<version>2.2.4</version>
67+
<version>2.3.0</version>
6868
</plugin>
6969

7070
<plugin>

0 commit comments

Comments
 (0)