From 12da3807ee534627f7a99ea12b19fed1975fd8dd Mon Sep 17 00:00:00 2001 From: Ludovic Pourrat <52542520+ludovic-pourrat@users.noreply.github.com> Date: Fri, 20 Oct 2023 15:04:33 +0200 Subject: [PATCH] Fix pattern detection in relative path condition (#89) (#106) * Fix pattern detection in relative path condition (#89) * Run Build pipeline on ubuntu and windows --------- Co-authored-by: Mark Brockhoff --- .github/workflows/build.yml | 60 ++++++++++++++++--- CHANGELOG.md | 4 ++ gradle.properties | 2 +- .../SpectralExternalAnnotator.kt | 30 ++++++---- 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad22e32..d9ba1ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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<> $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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7321fb7..202c91a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ ## [Unreleased] +### Fixed + +- Fix pattern detection in relative path condition + ## [3.0.0] - 2023-10-04 ### Added diff --git a/gradle.properties b/gradle.properties index f076aa4..f64aae8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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.* diff --git a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralExternalAnnotator.kt b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralExternalAnnotator.kt index 7059c8c..9e66cde 100644 --- a/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralExternalAnnotator.kt +++ b/src/main/kotlin/com/schwarzit/spectralIntellijPlugin/SpectralExternalAnnotator.kt @@ -49,25 +49,33 @@ class SpectralExternalAnnotator : ExternalAnnotator, List< return Pair(file, editor) } - fun isFileIncluded( - basePath: Path, - path: Path, - includedFiles: List, - separator: String = File.separator - ): Boolean { + fun isFileIncluded(basePath: Path, path: Path, includedFiles: List, 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): List { val progressManager = ProgressManager.getInstance() val computable = Computable { lintFile(info.second) }