Skip to content
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

Slight refactorings and remove maven-model dependency #1365

Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Pre-Release - Publish VSCode Extensions

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 2,4,6"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public static Optional<TextDocumentEdit> computeTextDocEdit(TextDocument doc, St
log.error("Diff conversion failed", ex);
}
}
System.out.println("edits "+ edit);
return Optional.of(edit);
}
return Optional.empty();
Expand Down Expand Up @@ -170,7 +169,6 @@ public static Optional<WorkspaceEdit> createWorkspaceEdit(SimpleTextDocumentServ
createDeleteFileEdit(docUri, we);
} else {
String docUri = result.getBefore().getSourcePath().toUri().toASCIIString();
System.out.println(result.getBefore().getSourcePath().toString());
createUpdateFileEdit(documents, docUri, result.getBefore().printAll(), result.getAfter().printAll(), changeAnnotationId, we);
}

Expand Down
10 changes: 0 additions & 10 deletions headless-services/spring-boot-language-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,6 @@
<artifactId>commonmark</artifactId>
<version>0.22.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.8.1</version>
</dependency>
<!-- <dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>-->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ private CompletableFuture<Object> enhanceResponseHandler(ExecuteCommandParams pa
private CompletableFuture<WorkspaceEdit> createLspEdits(ExecuteCommandParams params) throws IOException {
log.info("Command Handler for lsp edits: ");
String docURI = ((JsonElement) params.getArguments().get(0)).getAsString();
String path = ((JsonElement) params.getArguments().get(0)).getAsString();
String content = ((JsonElement) params.getArguments().get(2)).getAsString();
String content = ((JsonElement) params.getArguments().get(1)).getAsString();

IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(docURI)).get();
List<ProjectArtifact> projectArtifacts = computeProjectArtifacts(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.eclipse.lsp4j.ChangeAnnotation;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.openrewrite.Result;
import org.openrewrite.xml.tree.Xml;
import org.springframework.ide.vscode.boot.java.copilot.InjectMavenActionHandler.MavenDependencyMetadata;
import org.springframework.ide.vscode.boot.java.copilot.util.ClassNameExtractor;
import org.springframework.ide.vscode.boot.java.copilot.util.PomReader;
import org.springframework.ide.vscode.boot.java.copilot.util.PropertyFileUtils;
import org.springframework.ide.vscode.boot.java.copilot.util.SpringCliException;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
Expand All @@ -40,22 +37,13 @@ public class ProjectArtifactEditGenerator {

private final Path projectPath;

private final String readmeFileName;

private final Pattern compiledGroupIdPattern;

private final Pattern compiledArtifactIdPattern;

private final SimpleTextDocumentService simpleTextDocumentService;

public ProjectArtifactEditGenerator(SimpleTextDocumentService simpleTextDocumentService,
List<ProjectArtifact> projectArtifacts, Path projectPath, String readmeFileName) {
this.simpleTextDocumentService = simpleTextDocumentService;
this.projectArtifacts = projectArtifacts;
this.projectPath = projectPath;
this.readmeFileName = readmeFileName;
compiledGroupIdPattern = Pattern.compile("<groupId>(.*?)</groupId>");
compiledArtifactIdPattern = Pattern.compile("<artifactId>(.*?)</artifactId>");
}

public ProcessArtifactResult<WorkspaceEdit> process() throws IOException {
Expand Down Expand Up @@ -136,24 +124,19 @@ private void writeTestCode(ProjectArtifact projectArtifact, Path projectPath, St

private void writeMavenDependencies(ProjectArtifact projectArtifact, Path projectPath, String changeAnnotationId,
WorkspaceEdit we) {
PomReader pomReader = new PomReader();
Path currentProjectPomPath = this.projectPath.resolve("pom.xml");
if (Files.notExists(currentProjectPomPath)) {
throw new SpringCliException("Could not find pom.xml in " + this.projectPath
+ ". Make sure you are running the command in the project's root directory.");
}
Model currentModel = pomReader.readPom(currentProjectPomPath.toFile());
List<Dependency> currentDependencies = currentModel.getDependencies();

InjectMavenActionHandler injectMavenActionHandler = new InjectMavenActionHandler(null, new HashMap<>(),
projectPath);

// Move the parsing to injectMavenActionHandler
List<Xml.Document> xmlDocuments = injectMavenActionHandler.parseToXml(projectArtifact.getText());
for (Xml.Document xmlDocument : xmlDocuments) {
MavenDependencyMetadata dep = injectMavenActionHandler.findMavenDependencyTags(xmlDocument);
if (!candidateDependencyAlreadyPresent(dep, currentDependencies)) {
injectMavenActionHandler.injectDependency(dep);
}
injectMavenActionHandler.injectDependency(dep);
}

List<Result> res = injectMavenActionHandler.run().getChangeset().getAllResults();
Expand All @@ -164,23 +147,6 @@ private void writeMavenDependencies(ProjectArtifact projectArtifact, Path projec
}
}

private boolean candidateDependencyAlreadyPresent(MavenDependencyMetadata dep,
List<Dependency> currentDependencies) {
String candidateGroupId = dep.groupId();
String candidateArtifactId = dep.artifactId();
boolean candidateDependencyAlreadyPresent = false;
for (Dependency currentDependency : currentDependencies) {
String currentGroupId = currentDependency.getGroupId();
String currentArtifactId = currentDependency.getArtifactId();
if (candidateGroupId.equals(currentGroupId) && candidateArtifactId.equals(currentArtifactId)) {
candidateDependencyAlreadyPresent = true;
break;
}
}
return candidateDependencyAlreadyPresent;

}

private void writeApplicationProperties(ProjectArtifact projectArtifact, Path projectPath,
String changeAnnotationId, WorkspaceEdit we) throws IOException {
Path applicationPropertiesPath = projectPath.resolve("src").resolve("main").resolve("resources")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.openrewrite.config.YamlResourceLoader;
import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.java.JavaParser;
import org.openrewrite.maven.AddDependency;
import org.openrewrite.maven.MavenParser;
import org.openrewrite.tree.ParseError;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function applyLspEdit(uri: Uri) {
}, async (progress, cancellation) => {
progress.report({ message: "applying edits..." });
const fileContent = (await readResponseFromFile(uri)).toString();
const lspEdit = await commands.executeCommand("sts/copilot/agent/lspEdits", uri.toString(), path.dirname(uri.fsPath), fileContent);
const lspEdit = await commands.executeCommand("sts/copilot/agent/lspEdits", uri.toString(), fileContent);
const workspaceEdit = await CONVERTER.asWorkspaceEdit(lspEdit);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,21 @@ export default class SpringBootChatAgent {

// Chat request to copilot LLM
const response = await this.copilotRequest.chatRequest(messages, {}, cancellationToken);

// write the response to markdown file
const targetMarkdownUri = await writeResponseToFile(response, bootProjInfo.name, selectedProject.fsPath);

let documentContent;

if (!targetMarkdownUri) {
documentContent = 'Note: The code provided is just an example and may not be suitable for production use. \n ' + response;
if (response == null || response === '') {
documentContent = 'Failed to process the request. Please try again.';
} else {
// modify the response from copilot LLM i.e. make response Boot 3 compliant if necessary
if (bootProjInfo.springBootVersion.startsWith('3')) {
const enhancedResponse = await commands.executeCommand("sts/copilot/agent/enhanceResponse", response) as string;
await writeResponseToFile(enhancedResponse, bootProjInfo.name, selectedProject.fsPath);
documentContent = await commands.executeCommand("sts/copilot/agent/enhanceResponse", response) as string;
} else {
documentContent = 'Note: The code provided is just an example and may not be suitable for production use. \n ' + response;
}
documentContent = await workspace.fs.readFile(targetMarkdownUri);
}

// write the final response to markdown file
await writeResponseToFile(documentContent, bootProjInfo.name, selectedProject.fsPath);

const chatResponse = Buffer.from(documentContent).toString();
stream.markdown(chatResponse);
stream.button({
Expand Down
3 changes: 0 additions & 3 deletions vscode-extensions/vscode-spring-boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"activationEvents": [
"onCommand:vscode-spring-boot.ls.start"
],
"enabledApiProposals": [
"chatVariableResolver"
],
"contributes": {
"chatParticipants": [
{
Expand Down