Skip to content

Commit

Permalink
Independent Gradle Project Parser via GradleProjectData model
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Aug 14, 2023
1 parent e8fcb8d commit afe292d
Show file tree
Hide file tree
Showing 45 changed files with 2,405 additions and 0 deletions.
54 changes: 54 additions & 0 deletions sbm-gradle-tooling-model/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
* text eol=lf

#
# The above will handle all files NOT found below
# https://help.github.com/articles/dealing-with-line-endings/
# https://github.com/Danimoth/gitattributes

# These are explicitly windows files and should use crlf
*.bat text eol=crlf

# These files are text and should be normalized (Convert crlf => lf)
*.bash text eol=lf
*.css text diff=css
*.htm text diff=html
*.html text diff=html
*.java text diff=java
*.sh text eol=lf


# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.a binary
*.lib binary
*.icns binary
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.jar binary
*.tar binary
*.tar.gz binary
*.7z binary
*.ttf binary
*.pyc binary
*.gpg binary
*.bin binary
*.exe binary
*.dll binary
*.so binary
*.dylib binary
*.class binary
*.jar binary
*.war binary
*.ear binary
*.rar binary
5 changes: 5 additions & 0 deletions sbm-gradle-tooling-model/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
.gradle/
out/
.idea/
/spring-petclinic/
21 changes: 21 additions & 0 deletions sbm-gradle-tooling-model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SBM Gradle Project Parser
The project consists of modules:
- **model** - Defines data structures to be pulled from Gradle Build process via Gradle Tooling API. Also contains utility to query Gradle Build process for a specific model type
- **plugin** - Registers the `GradelProject` data model builder and has logic for creating a serializable instance of the `GradleProjectData`
- **parser** - Defines a `GradelProjectParser` which delegates to `DefaultProjectParser` which is very close to Rewrite's `org.openrewrite.gradle.isolated.DefaultProjectParser`which takes `GradleProjectData` obtained from **model** via **plugin** project as a parameter.

Use the `GradelProjectParser` as follows:
```java
GradleProjectParser.parse(new File("/Users/aboyko/Documents/STS4-arm/spring-petclinic"), new File("/Users/aboyko/Documents/STS4-arm/spring-petclinic/build.gradle"), new InMemoryExecutionContext(), new DefaultParserConfig()).collect(Collectors.toList());
```
Parameters:
1. Project root folder
2. Project build script file
3. Rewrite's `ExecutionContext`
4. `ParserConfig` object. (Typically one would use `DefaultParserConfig`)

Before making references to the project and using it as a library it is required to build it:
```bash
./gradlew clean build publishToMavenLocal
```
(It is important to publish to maven local such that when **model** project quries gradle process for the model the plugin is present in the local maven repo)
9 changes: 9 additions & 0 deletions sbm-gradle-tooling-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("org.openrewrite.build.root") version("latest.release")
}


allprojects {
group = "org.springframework.sbm.gradle.tooling"
description = "A model for extracting semantic information out of Gradle build files necessary for refactoring them."
}
37 changes: 37 additions & 0 deletions sbm-gradle-tooling-model/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
25 changes: 25 additions & 0 deletions sbm-gradle-tooling-model/demo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
java
id("org.springframework.boot") version "3.1.2"
id("io.spring.dependency-management") version "1.1.2"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_17
}

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType<Test> {
useJUnitPlatform()
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit afe292d

Please sign in to comment.