File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
src/main/java/com/yourorganization/maven_sample Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public static void main(String[] args) {
24
24
// SourceRoot is a tool that read and writes Java files from packages on a certain root directory.
25
25
// In this case the root directory is found by taking the root from the current Maven module,
26
26
// with src/main/resources appended.
27
- SourceRoot sourceRoot = new SourceRoot (CodeGenerationUtils . mavenModuleRoot (LogicPositivizer .class ).resolve ("src/main/resources" ));
27
+ SourceRoot sourceRoot = new SourceRoot (Util . gradleModuleRoot (LogicPositivizer .class ).resolve ("src/main/resources" ));
28
28
29
29
// Our sample is in the root of this directory, so no package name.
30
30
CompilationUnit cu = sourceRoot .parse ("" , "Blabla.java" );
Original file line number Diff line number Diff line change
1
+ package com .yourorganization .maven_sample ;
2
+
3
+ import com .github .javaparser .utils .CodeGenerationUtils ;
4
+
5
+ import java .nio .file .Path ;
6
+ import java .nio .file .Paths ;
7
+
8
+ public class Util {
9
+
10
+
11
+ /**
12
+ * Temporary addition until JavaParser itself contains a similar method.
13
+ * This is almost identical to the maven equivalent at CodeGenerationUtils#mavenModuleRoot()
14
+ *
15
+ * Useful for locating source code within your Gradle project. Finds the classpath for the given class,
16
+ * then backs up out of multiple directories, until reaching the directory containing build.gradle
17
+ * "build/(test-)classes/java/main"
18
+ */
19
+ public static Path gradleModuleRoot (Class <?> c ) {
20
+ return CodeGenerationUtils
21
+ .classLoaderRoot (c )
22
+ .resolve (Paths .get (".." , ".." , ".." , ".." ))
23
+ .normalize ();
24
+ }
25
+
26
+ }
You can’t perform that action at this time.
0 commit comments