-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 49 additions & 3 deletions
52
build-action/src/main/java/org/gradle/client/build/action/GetResolvedDomAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,59 @@ | ||
package org.gradle.client.build.action; | ||
|
||
import org.gradle.client.build.model.ResolvedDomPrerequisites; | ||
import org.gradle.declarative.dsl.schema.AnalysisSchema; | ||
import org.gradle.declarative.dsl.tooling.models.DeclarativeSchemaModel; | ||
import org.gradle.tooling.BuildAction; | ||
import org.gradle.tooling.BuildController; | ||
import org.gradle.tooling.model.gradle.GradleBuild; | ||
|
||
public class GetResolvedDomAction implements BuildAction<GradleBuild> { | ||
import java.io.File; | ||
|
||
public class GetResolvedDomAction implements BuildAction<ResolvedDomPrerequisites> { | ||
|
||
@Override | ||
public GradleBuild execute(BuildController controller) { | ||
return controller.getModel(GradleBuild.class); | ||
public ResolvedDomPrerequisites execute(BuildController controller) { | ||
AnalysisSchema projectSchema = getProjectSchema(controller); | ||
String buildFileContent = getBuildFileContent(controller); | ||
return new ResolvedDomPrerequisitesImpl(projectSchema, buildFileContent); | ||
} | ||
|
||
private static AnalysisSchema getProjectSchema(BuildController controller) { | ||
DeclarativeSchemaModel declarativeSchemaModel = controller.getModel(DeclarativeSchemaModel.class); | ||
return declarativeSchemaModel.getProjectSchema(); | ||
} | ||
|
||
private static String getBuildFileContent(BuildController controller) { | ||
GradleBuild gradleBuild = controller.getModel(GradleBuild.class); | ||
File randomProjectBuildFile = gradleBuild.getProjects().getAll().stream() | ||
.map(p -> new File(p.getProjectDirectory(), "build.gradle.dcl")) | ||
.filter(File::exists) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException("Declarative project file not found")); | ||
|
||
return randomProjectBuildFile.getAbsolutePath(); | ||
|
||
|
||
} | ||
|
||
private static final class ResolvedDomPrerequisitesImpl implements ResolvedDomPrerequisites { | ||
|
||
private final AnalysisSchema analysisSchema; | ||
private final String buildFilePath; | ||
|
||
public ResolvedDomPrerequisitesImpl(AnalysisSchema analysisSchema, String buildFilePath) { | ||
this.analysisSchema = analysisSchema; | ||
this.buildFilePath = buildFilePath; | ||
} | ||
|
||
@Override | ||
public AnalysisSchema getAnalysisSchema() { | ||
return analysisSchema; | ||
} | ||
|
||
@Override | ||
public String getBuildFilePath() { | ||
return buildFilePath; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
build-action/src/main/java/org/gradle/client/build/model/ResolvedDomPrerequisites.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.gradle.client.build.model; | ||
|
||
import org.gradle.declarative.dsl.schema.AnalysisSchema; | ||
|
||
import java.io.Serializable; | ||
|
||
public interface ResolvedDomPrerequisites extends Serializable { | ||
|
||
AnalysisSchema getAnalysisSchema(); | ||
|
||
String getBuildFilePath(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 29 additions & 7 deletions
36
gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/connected/actions/GetResolvedDom.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
package org.gradle.client.ui.connected.actions | ||
|
||
import androidx.compose.foundation.layout.ColumnScope | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import org.gradle.client.build.action.GetResolvedDomAction | ||
import org.gradle.client.build.model.ResolvedDomPrerequisites | ||
import org.gradle.internal.declarativedsl.analysis.analyzeEverything | ||
import org.gradle.internal.declarativedsl.dom.resolvedDocument | ||
import org.gradle.internal.declarativedsl.language.LanguageTreeResult | ||
import org.gradle.internal.declarativedsl.language.SourceIdentifier | ||
import org.gradle.internal.declarativedsl.parsing.DefaultLanguageTreeBuilder | ||
import org.gradle.internal.declarativedsl.parsing.parse | ||
import org.gradle.tooling.BuildAction | ||
import org.gradle.tooling.model.gradle.GradleBuild | ||
import java.io.File | ||
|
||
class GetResolvedDom : GetModelAction.GetCompositeModelAction<GradleBuild> { | ||
class GetResolvedDom : GetModelAction.GetCompositeModelAction<ResolvedDomPrerequisites> { | ||
|
||
override val modelType = GradleBuild::class | ||
override val modelType = ResolvedDomPrerequisites::class | ||
|
||
override fun getBuildAction(): BuildAction<GradleBuild> = | ||
GetResolvedDomAction() | ||
override val buildAction: BuildAction<ResolvedDomPrerequisites> = GetResolvedDomAction() | ||
|
||
@Composable | ||
override fun ColumnScope.ModelContent(model: GradleBuild) { | ||
TODO("Not yet implemented") | ||
override fun ColumnScope.ModelContent(model: ResolvedDomPrerequisites) { | ||
val buildFile = File(model.buildFilePath) | ||
val buildFileContent = buildFile.readText() | ||
val parsedLightTree = parse(buildFileContent) | ||
val languageTreeResult = DefaultLanguageTreeBuilder().build(parsedLightTree, SourceIdentifier(buildFile.name)) | ||
|
||
val resolvedDocument = resolvedDocument(model.analysisSchema, languageTreeResult, analyzeEverything, true) | ||
|
||
Text( | ||
text = "Gradle Resolved DOM", | ||
style = MaterialTheme.typography.titleMedium | ||
) | ||
Text( | ||
text = "Schema: $resolvedDocument", | ||
style = MaterialTheme.typography.labelSmall | ||
) | ||
} | ||
} |