Skip to content

Independent Gradle Project Parser via GradleProjectData model #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2023
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
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