* trying to allow manual trigger for publishing vscode pre-releases * remove usage of proposed chat variable resolver api for now * remove maven-model dependency and clean up code --------- Co-authored-by: Udayani Vaka <79973862+vudayani@users.noreply.github.com> Co-authored-by: Martin Lippert <martin.lippert@broadcom.com>
This commit is contained in:
@@ -63,8 +63,7 @@ public class CopilotAgentCommandHandler {
|
||||
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);
|
||||
|
||||
@@ -19,15 +19,12 @@ import java.util.regex.Matcher;
|
||||
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;
|
||||
@@ -40,12 +37,6 @@ 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,
|
||||
@@ -53,9 +44,6 @@ public class ProjectArtifactEditGenerator {
|
||||
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 {
|
||||
@@ -136,24 +124,19 @@ public class ProjectArtifactEditGenerator {
|
||||
|
||||
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();
|
||||
@@ -164,23 +147,6 @@ public class ProjectArtifactEditGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package org.springframework.ide.vscode.boot.java.copilot.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
public class PomReader {
|
||||
|
||||
/**
|
||||
* Returns a parsed POM.
|
||||
*/
|
||||
public Model readPom(File file) {
|
||||
File pom = file;
|
||||
if (file.isDirectory()) {
|
||||
pom = new File(file, "pom.xml");
|
||||
}
|
||||
if (!pom.exists()) {
|
||||
return null;
|
||||
}
|
||||
String fileText = "";
|
||||
try (Reader reader = new FileReader(pom)) {
|
||||
if (file.isFile()) {
|
||||
fileText = new String(Files.readAllBytes(file.toPath()));
|
||||
}
|
||||
MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
|
||||
return xpp3Reader.read(reader);
|
||||
}
|
||||
catch (XmlPullParserException | IOException ex) {
|
||||
if (file.isFile() && fileText.length() == 0) {
|
||||
throw new IllegalStateException("File [" + pom.getAbsolutePath() + "] is empty", ex);
|
||||
}
|
||||
throw new IllegalStateException("Failed to read file: " + pom.getAbsolutePath(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,7 +56,6 @@ import org.openrewrite.config.RecipeDescriptor;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user