-
Notifications
You must be signed in to change notification settings - Fork 14
POM validator #1183
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
+464
−18
Merged
POM validator #1183
Changes from 47 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
4dac044
WIP: adding pom.xml validator to the extension
rodinaarssen 8de5482
Launch REPL for open Rascal project.
toinehartman 2d0f50d
Work around nullability analysis.
toinehartman 2b9a392
Fix Maven resolution.
toinehartman 8a99601
Merge branch 'feature/remove-std-scheme' into feature/add-pomxml-vali…
toinehartman 0024640
Merge remote-tracking branch 'origin/feature/remove-std-scheme' into …
toinehartman 3dbbc5e
WIP: Add pom analyzer in Rascal.
toinehartman 37968f2
Improvements.
toinehartman a755a31
Merge remote-tracking branch 'origin/main' into feature/add-pomxml-va…
rodinaarssen 55fca31
Merge remote-tracking branch 'refs/remotes/origin/feature/add-pomxml-…
rodinaarssen b3a8714
PomValidator progress
rodinaarssen e62939f
Added cache for pom.xml files
rodinaarssen b4ec870
Added missing license
rodinaarssen 6754d06
Added keyword parameters for the versions
rodinaarssen 39ada87
Made pom analyzer more robust
rodinaarssen d03ec97
Added support for exclusions
rodinaarssen 30026f5
Wired up pom analyzer in the global analyzer
rodinaarssen bf82636
Added Rascal dependency check to analyzer
rodinaarssen bf215fd
Improved rascal-lsp dependency check
rodinaarssen dbb6033
Removed TS implementation of the pom.xml analyzer
rodinaarssen a49f1b9
Added comment
rodinaarssen dc4c458
Removed reference to removed file
rodinaarssen a61a968
Removed code action that no longer exists
rodinaarssen faaa5d7
Merge remote-tracking branch 'origin/main' into feature/add-pomxml-va…
rodinaarssen 2c651a8
Newline detection is now robust against single-line pom.xml files
rodinaarssen 386eaf9
Added Java functions to obtain Maven dependencies
rodinaarssen 25250ed
Rewrote addDependency TextEdit generation to work on plain nodes
rodinaarssen 65793a5
Cleanup of PomAnalyzer.rsc
rodinaarssen 8c82320
Analyzer now uses proper PomAnalyzer functions
rodinaarssen 65e98dd
Merge branch 'main' into feature/add-pomxml-validator
rodinaarssen 4ef3048
Using SpecificationVersion first to find the active rascal-lsp version
rodinaarssen 9415c2d
Added Rascal commands in favor of plain text edits
rodinaarssen 7b7ba65
Removed pom.xml check for a Rascal dependency; this is moved to Rascal
rodinaarssen 4848d6f
Added custom code action provider for xml files to be able to provide…
rodinaarssen f7fd701
Made Rascal version check robust against running from a target folder
rodinaarssen 4285706
Always read full pom.xml files
rodinaarssen f19683d
Correctly added argument to command
rodinaarssen c62b360
RascalTextDocumentService also handles xml files now
rodinaarssen 73ad8d5
Fixed typo
rodinaarssen 01aafa0
Extracted code action conversion function
rodinaarssen 1d4f791
Prevent RascalTextDocumentService from trying to parse pom.xml files …
rodinaarssen d5701cb
Fixed ShellEvaluatorFactory call after a formal argument got removed …
rodinaarssen 9a72d44
Fixed off-by-one error and added an overload for inferNewline in the …
rodinaarssen bc37a5b
Added tests for the pom.xml analyzer
rodinaarssen 44ca5de
Slightly simplified inferIndentation
rodinaarssen e933c47
Removed unused code
rodinaarssen 75f44a8
Unexported a variable
rodinaarssen 5fc6530
Only provide code actions for pom.xml files instead of for all xml files
rodinaarssen b5c0cba
Using latest RC of Rascal
rodinaarssen 6e2ec42
Removed unused imports
rodinaarssen f8ad534
Fixed CF error
rodinaarssen 71c59be
Incorporated feedback by @DavyLandman
rodinaarssen b549a59
Moved code action provider for pom.xml files to a discrete class
rodinaarssen 828b681
Got rid of fixed back-up versions for rascal and rascal-lsp in the code
rodinaarssen 6dcdf51
Unused import removed
rodinaarssen 0dac9f0
Changed log level
rodinaarssen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/xml/PomAnalyzer.java
This file contains hidden or 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,96 @@ | ||
| /* | ||
| * Copyright (c) 2018-2025, NWO-I CWI and Swat.engineering | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * | ||
| * 1. Redistributions of source code must retain the above copyright notice, | ||
| * this list of conditions and the following disclaimer. | ||
| * | ||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| * this list of conditions and the following disclaimer in the documentation | ||
| * and/or other materials provided with the distribution. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package org.rascalmpl.vscode.lsp.xml; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.file.Path; | ||
| import java.util.Properties; | ||
|
|
||
| import org.rascalmpl.util.maven.Artifact; | ||
| import org.rascalmpl.util.maven.MavenParser; | ||
| import org.rascalmpl.util.maven.ModelResolutionError; | ||
| import org.rascalmpl.util.maven.Scope; | ||
|
|
||
| import io.usethesource.vallang.IBool; | ||
| import io.usethesource.vallang.ISourceLocation; | ||
| import io.usethesource.vallang.IString; | ||
| import io.usethesource.vallang.IValueFactory; | ||
|
|
||
| public class PomAnalyzer { | ||
| private IValueFactory vf; | ||
|
|
||
| public PomAnalyzer(IValueFactory vf) { | ||
| this.vf = vf; | ||
| } | ||
|
|
||
| IBool hasDependency(ISourceLocation pomLoc, String groupId, String artifactId) { | ||
| try { | ||
| var mavenParser = new MavenParser(Path.of(pomLoc.getURI())); | ||
| var rootProject = mavenParser.parseProject(); | ||
| var resolvedDependencies = rootProject.resolveDependencies(Scope.COMPILE, mavenParser); | ||
| return vf.bool(resolvedDependencies.stream() | ||
| .map(Artifact::getCoordinate) | ||
| .filter(a -> a.getGroupId().equals(groupId) && a.getArtifactId().equals(artifactId)) | ||
| .findAny() | ||
| .isPresent()); | ||
| } catch (ModelResolutionError e) { | ||
| return vf.bool(false); | ||
| } | ||
| } | ||
|
|
||
| public IBool hasRascalDependency(ISourceLocation pomLoc) { | ||
| return hasDependency(pomLoc, "org.rascalmpl", "rascal"); | ||
| } | ||
|
|
||
| public IBool hasRascalLspDependency(ISourceLocation pomLoc) { | ||
| return hasDependency(pomLoc, "org.rascalmpl", "rascal-lsp"); | ||
| } | ||
|
|
||
| public IString getCurrentRascalLspVersion() { | ||
| var specificationVersion = PomAnalyzer.class.getPackage().getSpecificationVersion(); | ||
| if (specificationVersion != null) { | ||
| return vf.string(specificationVersion); | ||
| } | ||
|
|
||
| try (InputStream prop = PomAnalyzer.class.getClassLoader().getResourceAsStream("project.properties")) { | ||
| if (prop != null) { | ||
| Properties properties = new Properties(); | ||
| properties.load(prop); | ||
| var version = properties.getProperty("rascal.lsp.version"); | ||
| if (version != null) { | ||
| return vf.string(version); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| // Fall through | ||
| } | ||
|
|
||
| var fallbackVersion = "2.22.5"; | ||
| return vf.string(fallbackVersion); | ||
|
rodinaarssen marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
145 changes: 145 additions & 0 deletions
145
rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/pom/PomAnalyzerTests.rsc
This file contains hidden or 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,145 @@ | ||
| @license{ | ||
| Copyright (c) 2018-2025, NWO-I CWI and Swat.engineering | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright notice, | ||
| this list of conditions and the following disclaimer. | ||
|
|
||
| 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| this list of conditions and the following disclaimer in the documentation | ||
| and/or other materials provided with the distribution. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| POSSIBILITY OF SUCH DAMAGE. | ||
| } | ||
| module lang::rascal::tests::pom::PomAnalyzerTests | ||
|
|
||
| import IO; | ||
| import String; | ||
| import analysis::diff::edits::TextEdits; | ||
| import lang::xml::PomAnalyzer; | ||
|
|
||
| public str pomWithRascal = "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\> | ||
| '\<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" | ||
| 'xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\> | ||
| ' \<modelVersion\>4.0.0\</modelVersion\> | ||
| ' | ||
| ' \<groupId\>org.rascalmpl\</groupId\> | ||
| ' \<artifactId\>test-lib\</artifactId\> | ||
| ' \<version\>0.1.0-SNAPSHOT\</version\> | ||
| ' | ||
| ' \<dependencies\> | ||
| ' \<dependency\> | ||
| ' \<groupId\>org.rascalmpl\</groupId\> | ||
| ' \<artifactId\>rascal\</artifactId\> | ||
| ' \<version\>0.43.0-RC14\</version\> | ||
| ' \</dependency\> | ||
| ' \</dependencies\> | ||
| '\</project\>"; | ||
|
|
||
| public str pomWithoutDependencies = "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\> | ||
| '\<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" | ||
| 'xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\> | ||
| ' \<modelVersion\>4.0.0\</modelVersion\> | ||
| ' | ||
| ' \<groupId\>org.rascalmpl\</groupId\> | ||
| ' \<artifactId\>test-lib\</artifactId\> | ||
| ' \<version\>0.1.0-SNAPSHOT\</version\> | ||
| ' | ||
| '\</project\>"; | ||
|
|
||
| public str pomWithEmptyDependenciesBlock = "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\> | ||
| '\<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" | ||
| 'xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\> | ||
| ' \<modelVersion\>4.0.0\</modelVersion\> | ||
| ' | ||
| ' \<groupId\>org.rascalmpl\</groupId\> | ||
| ' \<artifactId\>test-lib\</artifactId\> | ||
| ' \<version\>0.1.0-SNAPSHOT\</version\> | ||
| ' | ||
| ' \<dependencies\> | ||
| ' \</dependencies\> | ||
| '\</project\>"; | ||
|
|
||
| public str pomWithNonEmptyDependenciesBlock = "\<?xml version=\"1.0\" encoding=\"UTF-8\"?\> | ||
| '\<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" | ||
| 'xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\> | ||
| ' \<modelVersion\>4.0.0\</modelVersion\> | ||
| ' | ||
| ' \<groupId\>org.rascalmpl\</groupId\> | ||
| ' \<artifactId\>test-lib\</artifactId\> | ||
| ' \<version\>0.1.0-SNAPSHOT\</version\> | ||
| ' | ||
| ' \<dependencies\> | ||
| ' \<dependency\> | ||
| ' \<groupId\>org.rascalmpl\<groupId\> | ||
| ' \<artifactId\>vallang\</artifactId\> | ||
| ' \<version\>0.15.1\</version\> | ||
| ' \</dependency\> | ||
| ' \</dependencies\> | ||
| '\</project\>"; | ||
|
|
||
| // `Path.of` does not like `memory` or plain `tmp` locations | ||
| public loc pomLoc = resolveLocation(|tmp:///rascal-pomxml-test/pom.xml|); | ||
|
|
||
| test bool testPomWithRascal() { | ||
| writeFile(pomLoc, pomWithRascal); | ||
| return hasRascalDependency(pomLoc); | ||
| } | ||
|
|
||
| test bool testPomWithoutDependencies() { | ||
| writeFile(pomLoc, pomWithoutDependencies); | ||
| if (hasRascalDependency(pomLoc)) { | ||
| return false; | ||
| } | ||
| edit = addRascalDependency(pomLoc); | ||
| newline = inferNewline(pomLoc); | ||
| expectedLoc = pomLoc(381 + 7 * size(newline),0,<8,35>,<8,35>); | ||
| return replace(expectedLoc, / <newline><newline> \<dependencies\><newline> \<dependency\><newline> \<groupId\>org.rascalmpl\<\/groupId\><newline> \<artifactId\>rascal\<\/artifactId\><newline> \<version\>[^\<]*\<\/version\><newline> \<\/dependency\><newline> \<\/dependencies\>/) := edit; | ||
| } | ||
|
|
||
| test bool testPomWithEmptyDependenciesBlock() { | ||
| writeFile(pomLoc, pomWithEmptyDependenciesBlock); | ||
| if (hasRascalDependency(pomLoc)) { | ||
| return false; | ||
| } | ||
| edit = addRascalDependency(pomLoc); | ||
| newline = inferNewline(pomLoc); | ||
| expectedLoc = pomLoc(383 + 9 * size(newline),31 + size(newline),<10,2>,<11,17>); | ||
| return replace(expectedLoc, /\<dependencies\><newline> \<dependency\><newline> \<groupId\>org.rascalmpl\<\/groupId\><newline> \<artifactId\>rascal\<\/artifactId\><newline> \<version\>[^\<]*\<\/version\><newline> \<\/dependency\><newline> \<\/dependencies\>/) := edit; | ||
| } | ||
|
|
||
| test bool testPomWithNonEmptyDependenciesBlock() { | ||
| writeFile(pomLoc, pomWithNonEmptyDependenciesBlock); | ||
| if (hasRascalDependency(pomLoc)) { | ||
| return false; | ||
| } | ||
| edit = addRascalDependency(pomLoc); | ||
| newline = inferNewline(pomLoc); | ||
| expectedLoc = pomLoc(397 + 10 * size(newline),0,<11,0>,<11,0>); | ||
| return replace(expectedLoc, / \<dependency\><newline> \<groupId\>org.rascalmpl\<\/groupId\><newline> \<artifactId\>rascal\<\/artifactId\><newline> \<version\>[^\<]*\<\/version\><newline> \<\/dependency\><newline>/) := edit; | ||
| } | ||
|
|
||
| test bool testAddRascalLspDependency() { | ||
| writeFile(pomLoc, pomWithNonEmptyDependenciesBlock); | ||
| if (hasRascalLspDependency(pomLoc)) { | ||
| return false; | ||
| } | ||
| edit = addRascalLspDependency(pomLoc); | ||
| newline = inferNewline(pomLoc); | ||
| expectedLoc = pomLoc(397 + 10 * size(newline),0,<11,0>,<11,0>); | ||
| return replace(expectedLoc, / \<dependency\><newline> \<groupId\>org.rascalmpl\<\/groupId\><newline> \<artifactId\>rascal-lsp\<\/artifactId\><newline> \<version\>[^\<]*\<\/version\><newline> \<\/dependency\><newline>/) := edit; | ||
| } | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.