Skip to content

Commit

Permalink
Gradle Project Parser independent of Rewrite via GradleProjectData
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Aug 14, 2023
1 parent e0346d0 commit d5d958f
Show file tree
Hide file tree
Showing 25 changed files with 698 additions and 290 deletions.
1 change: 1 addition & 0 deletions sbm-gradle-tooling-model/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
.gradle/
out/
.idea/
/spring-petclinic/
1 change: 1 addition & 0 deletions sbm-gradle-tooling-model/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.caching=true
org.gradle.parallel=true
git.root=/Users/aboyko/git/spring-boot-migrator
12 changes: 0 additions & 12 deletions sbm-gradle-tooling-model/model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ plugins {
dependencies {
implementation(gradleApi())

implementation("org.openrewrite:rewrite-core:latest.integration")
implementation("org.openrewrite:rewrite-maven:latest.integration")
implementation("org.openrewrite:rewrite-gradle:latest.integration")
implementation("org.openrewrite:rewrite-java:latest.integration")
implementation("org.openrewrite:rewrite-yaml:latest.integration")
implementation("org.openrewrite:rewrite-properties:latest.integration")
implementation("org.openrewrite:rewrite-json:latest.integration")
implementation("org.openrewrite:rewrite-protobuf:latest.integration")
implementation("org.openrewrite:rewrite-java-17:latest.integration")
implementation("org.openrewrite:rewrite-hcl:latest.integration")
implementation("org.openrewrite:rewrite-python:latest.integration")
implementation("org.openrewrite:plugin:latest.integration")
implementation("org.openrewrite.gradle.tooling:model:latest.integration")

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.springframework.sbm.gradle.tooling;

import org.openrewrite.gradle.marker.GradleSettings;
import org.openrewrite.gradle.toolingapi.GradleProject;
import org.openrewrite.gradle.toolingapi.GradleSettings;

import java.io.File;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.sbm.gradle.tooling;

import org.openrewrite.gradle.JavaVersionInfo;

import java.io.File;
import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;
import org.gradle.tooling.internal.consumer.DefaultGradleConnector;
import org.openrewrite.internal.lang.Nullable;

import java.io.File;
import java.io.IOException;
Expand All @@ -31,7 +30,7 @@
import java.util.List;

public class ModelBuilder {
public static <T> T forProjectDirectory(File projectDir, @Nullable File buildFile, Class<T> modelClass) {
public static <T> T forProjectDirectory(File projectDir, File buildFile, Class<T> modelClass) {
DefaultGradleConnector connector = (DefaultGradleConnector) GradleConnector.newConnector();
if (Files.exists(projectDir.toPath().resolve("gradle/wrapper/gradle-wrapper.properties"))) {
connector.useBuildDistribution();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ initscript {
classpath 'org.springframework.sbm.gradle.tooling:plugin:latest.integration'
classpath 'org.springframework.sbm.gradle.tooling:model:latest.integration'
classpath 'org.openrewrite.gradle.tooling:model:latest.integration'
classpath 'org.openrewrite:plugin:latest.integration'
classpath 'org.openrewrite:rewrite-maven:latest.integration'
classpath gradleApi()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,13 @@
*/
package org.openrewrite.gradle.toolingapi;

import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.gradle.ProjectInfo;
import org.springframework.sbm.gradle.tooling.GradleProjectData;
import org.springframework.sbm.gradle.tooling.GradleProjectParser;
import org.springframework.sbm.gradle.tooling.ModelBuilder;

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;

public class UseToolingModel {
public static void main(String[] args) {
// GradleProjectParser parser = new GradleProjectParser();
//
// List<SourceFile> cus = parser.parse(new File("sample"), new File("sample/build.gradle"), new InMemoryExecutionContext(e -> e.printStackTrace())).collect(Collectors.toList());
// System.out.println(cus.size());
//
// cus = parser.parse(new File("demo"), new File("demo/build.gradle.kts"), new InMemoryExecutionContext(e -> e.printStackTrace())).collect(Collectors.toList());
// System.out.println(cus.size());

GradleProjectData projectData = ModelBuilder.forProjectDirectory(new File("sample"), new File("sample/build.gradle"), GradleProjectData.class);
System.out.println(projectData.getBuildDir());
System.out.println(projectData.getBuildscriptClasspath());
Expand Down
45 changes: 45 additions & 0 deletions sbm-gradle-tooling-model/parser/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
id("org.openrewrite.build.language-library")
}

group = "org.springframework.sbm.gradle.tooling"

repositories {
if (!project.hasProperty("releasing")) {
mavenLocal {
mavenContent {
excludeVersionByRegex(".+", ".+", ".+-rc-?[0-9]*")
}
}

maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}

mavenCentral {
mavenContent {
excludeVersionByRegex(".+", ".+", ".+-rc-?[0-9]*")
}
}
}

dependencies {
implementation(project(":model"))
implementation("org.openrewrite:rewrite-core:latest.integration")
implementation("org.openrewrite:rewrite-gradle:latest.integration")
implementation("org.openrewrite.gradle.tooling:model:latest.integration")
implementation("org.openrewrite:rewrite-groovy:latest.integration")
implementation("org.openrewrite:rewrite-hcl:latest.integration")
implementation("org.openrewrite:rewrite-java:latest.integration")
implementation("org.openrewrite:rewrite-json:latest.integration")
implementation("org.openrewrite:rewrite-kotlin:latest.integration")
implementation("org.openrewrite:rewrite-python:latest.integration")
implementation("org.openrewrite:rewrite-properties:latest.integration")
implementation("org.openrewrite:rewrite-protobuf:latest.integration")
implementation("org.openrewrite:rewrite-xml:latest.integration")
implementation("org.openrewrite:rewrite-yaml:latest.integration")
implementation("org.openrewrite.recipe:rewrite-all:latest.integration")
implementation(gradleApi())
implementation("org.openrewrite.gradle.tooling:model:latest.integration")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2023 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.sbm.gradle.parser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DefaultParserConfig implements ParseConfig {

private final List<String> exclusions = new ArrayList<>();
private final List<String> plainTextMasks = new ArrayList<>();

private int sizeThresholdMb = 10;

@Override
public List<String> getPlainTextMasks() {
if (plainTextMasks.isEmpty()) {
plainTextMasks.addAll(Arrays.asList(
"**gradlew",
"**META-INF/services/**",
"**/META-INF/spring.factories",
"**/META-INF/spring/**",
"**.gitignore",
"**.gitattributes",
"**.java-version",
"**.sdkmanrc",
"**.sh",
"**.bash",
"**.bat",
"**.ksh",
"**.txt",
"**.jsp",
"**.sql",
"**Dockerfile",
"**Jenkinsfile",
"**.kts"
));
}
return plainTextMasks;
}

@Override
public List<String> getExclusions() {
return exclusions;
}

@Override
public int getSizeThresholdMb() {
return sizeThresholdMb;
}

}
Loading

0 comments on commit d5d958f

Please sign in to comment.