Skip to content

Commit

Permalink
Fix pattern detection in relative path condition (#89) (#106)
Browse files Browse the repository at this point in the history
* Fix pattern detection in relative path condition (#89)

* Run Build pipeline on ubuntu and windows

---------

Co-authored-by: Mark Brockhoff <mark.brockhoff@mail.schwarz>
  • Loading branch information
ludovic-pourrat and markbrockhoff committed Oct 20, 2023
1 parent f80a20c commit 12da380
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 21 deletions.
60 changes: 51 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ jobs:
# Build plugin and provide the artifact for the next workflow jobs
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
outputs:
version: ${{ steps.properties.outputs.version }}
changelog: ${{ steps.properties.outputs.changelog }}
steps:

# Free GitHub Actions Environment Disk Space
- name: Maximize Build Space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
# Check out current repository
- name: Fetch Sources
uses: actions/checkout@v4
Expand Down Expand Up @@ -93,6 +88,53 @@ jobs:
with:
files: ${{ github.workspace }}/build/reports/kover/xml/report.xml

verifyPlugin:
name: "Run Plugin Verifier"
runs-on: ubuntu-latest
steps:
# Free GitHub Actions Environment Disk Space
- name: Maximize Build Space
shell: bash
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
# Check out current repository
- name: Fetch Sources
uses: actions/checkout@v4

# Validate wrapper
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1.1.0

# Setup Java 17 environment for the next steps
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17

# Set environment variables
- name: Export Properties
id: properties
shell: bash
run: |
PROPERTIES="$(./gradlew properties --console=plain -q)"
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')"
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
# Cache Plugin Verifier IDEs
- name: Setup Plugin Verifier IDEs Cache
uses: actions/cache@v3
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

## [Unreleased]

### Fixed

- Fix pattern detection in relative path condition

## [3.0.0] - 2023-10-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pluginGroup=com.schwarzit.spectral-intellij-plugin
pluginName=Spectral
pluginRepositoryUrl=https://github.com/SchwarzIT/spectral-intellij-plugin
# SemVer format -> https://semver.org
pluginVersion=3.0.0
pluginVersion=3.0.1
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=222
#pluginUntilBuild=231.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,33 @@ class SpectralExternalAnnotator : ExternalAnnotator<Pair<PsiFile, Editor>, List<
return Pair(file, editor)
}

fun isFileIncluded(
basePath: Path,
path: Path,
includedFiles: List<String>,
separator: String = File.separator
): Boolean {
fun isFileIncluded(basePath: Path, path: Path, includedFiles: List<String>, separator: String = File.separator): Boolean {
val pathMatcher = AntPathMatcher(separator)
val finalPath = normalizedStringPath(path.toString(), separator);

return includedFiles.any { s ->
var globPattern = s
if (!Paths.get(s).isAbsolute) {
var base = basePath.toString()
if (s.isEmpty()) return false;

var finalGlobPattern = normalizedStringPath(s, separator);

if (pathStartWithPattern(finalGlobPattern) || !Paths.get(finalGlobPattern).isAbsolute) {
var base = normalizedStringPath(basePath.toString(), separator);
if (!base.endsWith(separator)) base += separator
globPattern = base + s
finalGlobPattern = base + finalGlobPattern
}
return pathMatcher.match(globPattern, path.toString())

return pathMatcher.match(finalGlobPattern, finalPath)
}
}

private fun pathStartWithPattern(path: String): Boolean {
return path.isNotEmpty() && path[0] == '*';
}

private fun normalizedStringPath(path: String, separator: String): String {
return path.replace('\\', separator[0]).replace('/', separator[0]);
}

override fun doAnnotate(info: Pair<PsiFile, Editor>): List<SpectralIssue> {
val progressManager = ProgressManager.getInstance()
val computable = Computable { lintFile(info.second) }
Expand Down

0 comments on commit 12da380

Please sign in to comment.