Skip to content

Commit e326d18

Browse files
authored
Merge pull request #39 from theodo-group/feat/v2/clean-js-integration
Feat/v2/clean js integration
2 parents 3263cb6 + dc018a5 commit e326d18

27 files changed

Lines changed: 1388 additions & 253 deletions

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
.envrc
1717
.kubeconfig
1818
.aws/credentials
19-
.vscode/*
20-
*/.vscode/*
2119
target
2220

2321
*/spoon.classpath.tmp

.vscode/eclipse-java-google-style.xml

Lines changed: 919 additions & 0 deletions
Large diffs are not rendered by default.

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic",
3+
"java.format.settings.url": ".vscode/eclipse-java-google-style.xml",
4+
"java.compile.nullAnalysis.mode": "automatic"
5+
}

README.md

Lines changed: 3 additions & 3 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.3</version>
24+
<version>2.2.4</version>
2525
</plugin>
2626
<!-- ...existing plugins... -->
2727
</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.3</version>
138+
<version>2.2.4</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.3</version>
166+
<version>2.2.4</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.3</version>
9+
<version>2.2.4</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.3</tag>
55+
<tag>v2.2.4</tag>
5656
</scm>
5757

5858
<distributionManagement>

inspector-maven-plugin/src/main/java/com/theodo/plugin/InspectorMojo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ private String buildProjectDirectory() {
4343
@Override
4444
public void execute() throws MojoExecutionException {
4545
try {
46-
SpringAccessInspector inspector = new SpringAccessInspector(buildProjectDirectory(), buildHtmlOutputFile(), buildEditor());
46+
SpringAccessInspector inspector =
47+
new SpringAccessInspector(buildProjectDirectory(), buildHtmlOutputFile(), buildEditor());
4748
inspector.call();
4849
} catch (Exception e) {
49-
throw new MojoExecutionException(String.format("Exception occurred while inspecting project %s", projectBaseDir), e);
50+
throw new MojoExecutionException(
51+
String.format("Exception occurred while inspecting project %s", projectBaseDir), e);
5052
}
5153
}
5254
}

inspector/pom.xml

Lines changed: 43 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.3</version>
9+
<version>2.2.4</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.3</tag>
55+
<tag>v2.2.4</tag>
5656
</scm>
5757

5858
<distributionManagement>
@@ -167,6 +167,47 @@
167167

168168
<build>
169169
<plugins>
170+
<plugin>
171+
<groupId>org.codehaus.mojo</groupId>
172+
<artifactId>exec-maven-plugin</artifactId>
173+
<version>3.5.0</version>
174+
<executions>
175+
<execution>
176+
<id>generate-embedded-assets</id>
177+
<phase>generate-sources</phase>
178+
<goals>
179+
<goal>exec</goal>
180+
</goals>
181+
<configuration>
182+
<executable>bash</executable>
183+
<arguments>
184+
<argument>${project.basedir}/scripts/generate-embedded-assets.sh</argument>
185+
</arguments>
186+
</configuration>
187+
</execution>
188+
</executions>
189+
</plugin>
190+
191+
<plugin>
192+
<groupId>org.codehaus.mojo</groupId>
193+
<artifactId>build-helper-maven-plugin</artifactId>
194+
<version>3.6.0</version>
195+
<executions>
196+
<execution>
197+
<id>add-generated-sources</id>
198+
<phase>generate-sources</phase>
199+
<goals>
200+
<goal>add-source</goal>
201+
</goals>
202+
<configuration>
203+
<sources>
204+
<source>target/generated-sources/embedded</source>
205+
</sources>
206+
</configuration>
207+
</execution>
208+
</executions>
209+
</plugin>
210+
170211
<plugin>
171212
<groupId>org.apache.maven.plugins</groupId>
172213
<artifactId>maven-compiler-plugin</artifactId>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# ==========================
6+
# Script description
7+
# ==========================
8+
9+
# This script generates a Java class containing the content of all JavaScript files in the src/main/resources folder as string constants.
10+
# It is used to embed the JavaScript files into our HTML output.
11+
# The script is run as part of the build process to ensure that the JavaScript files are always up to date, thanks to exec-maven-plugin.
12+
13+
# ==========================
14+
# Configuration
15+
# ==========================
16+
17+
JS_FOLDER="src/main/resources"
18+
JAVA_FILE="target/generated-sources/embedded/com/theodo/inspector/utils/EmbeddedAssets.java"
19+
PACKAGE_NAME="com.theodo.inspector.utils"
20+
21+
# ==========================
22+
# Script
23+
# ==========================
24+
25+
if [ ! -d "$JS_FOLDER" ]; then
26+
echo "Error: The $JS_FOLDER folder does not exist."
27+
exit 1
28+
fi
29+
30+
mkdir -p "$(dirname "$JAVA_FILE")"
31+
32+
{
33+
echo "package $PACKAGE_NAME;"
34+
echo ""
35+
echo "public class EmbeddedAssets {"
36+
echo ""
37+
} > "$JAVA_FILE"
38+
39+
# Iterate over all JavaScript files in the folder
40+
for js_file in "$JS_FOLDER"/*.js; do
41+
if [ -f "$js_file" ]; then
42+
# Convert file name to uppercase with underscores between words
43+
constant_name=$(basename "$js_file" .js | sed -E 's/([a-z])([A-Z])/\1_\2/g' | tr '[:lower:]' '[:upper:]' | tr '-' '_' | tr '.' '_')_JS
44+
{
45+
echo " public static final String $constant_name = \"\"\""
46+
cat "$js_file"
47+
echo "\"\"\";"
48+
echo ""
49+
} >> "$JAVA_FILE"
50+
fi
51+
done
52+
53+
{
54+
echo "}"
55+
} >> "$JAVA_FILE"
56+
57+
echo "✅ EmbeddedAssets.java generated in $JAVA_FILE"

inspector/src/main/java/com/theodo/inspector/SpringAccessInspector.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
import org.apache.logging.log4j.Level;
1313
import org.apache.logging.log4j.core.config.Configurator;
1414

15+
import com.theodo.inspector.analyzer.ASTReader;
16+
import com.theodo.inspector.analyzer.AnnotationDto;
17+
import com.theodo.inspector.analyzer.AnnotationProcessing;
18+
import com.theodo.inspector.builder.HtmlBuilder;
1519
import com.theodo.inspector.cli.InspectorCommand;
16-
import com.theodo.inspector.impl.PreAuthorizeAnnotationProcessing;
17-
import com.theodo.inspector.impl.ast.ASTReader;
18-
import com.theodo.inspector.impl.utils.AnnotationDto;
19-
import com.theodo.inspector.impl.utils.HtmlTableGenerator;
2020

2121
import lombok.Getter;
2222
import lombok.extern.slf4j.Slf4j;
2323
import picocli.CommandLine;
2424
import spoon.reflect.CtModel;
2525

26-
2726
@Slf4j
2827
public class SpringAccessInspector extends InspectorCommand {
2928
public enum Editor {
30-
VSCODE,
31-
INTELLIJ,
32-
NONE
29+
VSCODE, INTELLIJ, NONE
3330
}
3431

3532
@Getter
@@ -64,26 +61,24 @@ public List<AnnotationDto> analyzer() throws IOException {
6461
List<AnnotationDto> annotations = new ArrayList<>();
6562
walk.forEach(pomFile -> {
6663
CtModel astModel = ASTReader.readAst(pomFile); // Analyze JAVA AST
67-
List<AnnotationDto> temporaryAnnotation = PreAuthorizeAnnotationProcessing
68-
.visitAllAnnotations(astModel);
64+
List<AnnotationDto> temporaryAnnotation = AnnotationProcessing.visitAllAnnotations(astModel);
6965
annotations.addAll(temporaryAnnotation);
7066

7167
});
7268
return annotations;
7369
}
7470
}
7571

76-
@Override
7772
public Integer call() throws Exception {
7873
List<AnnotationDto> annotations = analyzer();
79-
HtmlTableGenerator.generateHtmlTable(annotations, this.htmlOutputFile, this.editor);
74+
75+
HtmlBuilder.generateHtmlTable(annotations, this.htmlOutputFile, this.editor);
8076
return 0;
8177
}
8278

8379
public static Stream<File> findPoms(String basePath) throws IOException {
8480
// noinspection resource
85-
return Files.walk(Paths.get(basePath))
86-
.filter(path -> path.getFileName().toString().contains("pom.xml"))
81+
return Files.walk(Paths.get(basePath)).filter(path -> path.getFileName().toString().contains("pom.xml"))
8782
.map(Path::toFile);
8883
}
8984
}

inspector/src/main/java/com/theodo/inspector/impl/ast/ASTReader.java renamed to inspector/src/main/java/com/theodo/inspector/analyzer/ASTReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.theodo.inspector.impl.ast;
1+
package com.theodo.inspector.analyzer;
22

33
import java.io.File;
44

@@ -10,7 +10,8 @@
1010
public class ASTReader {
1111
public static CtModel readAst(File pomFile) {
1212
try {
13-
log.info("🌱 Analyzing Module directory '{}' with POM {}", pomFile.getParentFile().getName(), "file://" + pomFile.getAbsolutePath());
13+
log.info("🌱 Analyzing Module directory '{}' with POM {}", pomFile.getParentFile().getName(),
14+
"file://" + pomFile.getAbsolutePath());
1415
MavenLauncher launcher = new MavenLauncher(pomFile.toString(), MavenLauncher.SOURCE_TYPE.ALL_SOURCE, true);
1516
launcher.getEnvironment().setNoClasspath(true);
1617
launcher.getEnvironment().setIgnoreDuplicateDeclarations(true);

0 commit comments

Comments
 (0)