From a963f9bf444ab9b6d3af2a267727283819acd69b Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Wed, 29 Jan 2025 16:36:31 +0100 Subject: [PATCH] chore/add-linter (#254) * chore: add pmd to build definition * chore: add github linting step * chore: move pmd checks to plugin dir * chore: change configuration to point to ruleset * fix: ruleset location * fix: only run PMD on linux * fix: fail build if violations are found * fix: build failure * fix: build failure * chore: use pmd 2.0.0 * fix: linting error --- .github/workflows/ci.yml | 19 + .project | 6 + feature/pom.xml | 81 ++--- plugin/.project | 6 + plugin/plugin.xml | 20 +- plugin/pom.xml | 246 +++++++------ .../eclipse/plugin/html/OssHtmlProvider.java | 33 +- .../eclipse/plugin/wizards/SnykWizard.java | 2 +- plugin/src/main/resources/pmd-ruleset.xml | 26 ++ pom.xml | 331 +++++++++--------- tests/pom.xml | 1 + update-site/pom.xml | 95 +++-- 12 files changed, 473 insertions(+), 393 deletions(-) create mode 100644 plugin/src/main/resources/pmd-ruleset.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18141ea4..200c1f13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,25 @@ jobs: echo "$sha $fileName" > sha256.txt sha256sum -c sha256.txt + - uses: pmd/pmd-github-action@v2 + name: Lint + id: pmd + if: ${{ matrix.os == 'ubuntu-latest' }} + with: + rulesets: 'plugin/src/main/resources/pmd-ruleset.xml' + sourcePath: 'plugin/src/main/java' + analyzeModifiedFilesOnly: true + + - name: Upload SARIF file + if: ${{ matrix.os == 'ubuntu-latest' && steps.pmd.outputs.violations != 0 }} + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: pmd-report.sarif + + - name: Fail build if violations found + if: steps.pmd.outputs.violations != 0 + run: exit 1 + - name: Build with Maven if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.os == 'ubuntu-latest' }} run: ./mvnw clean verify -P sign -DtrimStackTrace=false diff --git a/.project b/.project index a7f3007f..5da59e4c 100644 --- a/.project +++ b/.project @@ -35,6 +35,11 @@ + + net.sourceforge.pmd.eclipse.plugin.pmdBuilder + + + org.eclipse.m2e.core.maven2Nature @@ -42,5 +47,6 @@ org.eclipse.jdt.core.javanature org.eclipse.pde.FeatureNature org.eclipse.pde.UpdateSiteNature + net.sourceforge.pmd.eclipse.plugin.pmdNature diff --git a/feature/pom.xml b/feature/pom.xml index 05a7b3dd..7f074381 100644 --- a/feature/pom.xml +++ b/feature/pom.xml @@ -1,45 +1,48 @@ - 4.0.0 - - io.snyk - parent - 3.0.0-SNAPSHOT - + 4.0.0 + + io.snyk + parent + 3.0.0-SNAPSHOT + - io.snyk.scanner + io.snyk.scanner + + ${project.parent.basedir} + - eclipse-feature + eclipse-feature - - - - org.eclipse.tycho - tycho-source-plugin - ${tycho-version} - - - feature-source - package - - feature-source - - - - - - org.eclipse.tycho - tycho-p2-plugin - - - attach-p2-metadata - package - - p2-metadata - - - - - - + + + + org.eclipse.tycho + tycho-source-plugin + ${tycho-version} + + + feature-source + package + + feature-source + + + + + + org.eclipse.tycho + tycho-p2-plugin + + + attach-p2-metadata + package + + p2-metadata + + + + + + diff --git a/plugin/.project b/plugin/.project index 8b0bb059..8ccae640 100644 --- a/plugin/.project +++ b/plugin/.project @@ -25,10 +25,16 @@ + + net.sourceforge.pmd.eclipse.plugin.pmdBuilder + + + org.eclipse.m2e.core.maven2Nature org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + net.sourceforge.pmd.eclipse.plugin.pmdNature diff --git a/plugin/plugin.xml b/plugin/plugin.xml index 31d0ff78..1cb1fa09 100644 --- a/plugin/plugin.xml +++ b/plugin/plugin.xml @@ -20,9 +20,9 @@ - @@ -412,13 +412,13 @@ + class="io.snyk.languageserver.SnykLanguageServer" + clientImpl="io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient" + id="io.snyk.languageserver" + label="Snyk Language Server" + lastDocumentDisconnectedTimeout="3000000" + markerType="io.snyk.languageserver.marker" + singleton="true"> - 4.0.0 + 4.0.0 - - io.snyk - parent - 3.0.0-SNAPSHOT - + + io.snyk + parent + 3.0.0-SNAPSHOT + - io.snyk.eclipse.plugin - https://snyk.io/ide-plugins/ - eclipse-plugin + io.snyk.eclipse.plugin + https://snyk.io/ide-plugins/ + eclipse-plugin - - - com.fasterxml.jackson.core - jackson-annotations - 2.16.2 - jar - - - com.fasterxml.jackson.core - jackson-core - 2.16.2 - jar - - - com.fasterxml.jackson.core - jackson-databind - 2.16.2 - jar - - - org.apache.commons - commons-lang3 - 3.12.0 - jar - - - org.apache.httpcomponents - httpcore - 4.4.16 - - - org.apache.httpcomponents - httpclient - 4.5.14 - - - - commons-codec - commons-codec - - - - - commons-codec - commons-codec - 1.17.0 - - - javax.inject - javax.inject - 1 - - + + + com.fasterxml.jackson.core + jackson-annotations + 2.16.2 + jar + + + com.fasterxml.jackson.core + jackson-core + 2.16.2 + jar + + + com.fasterxml.jackson.core + jackson-databind + 2.16.2 + jar + + + org.apache.commons + commons-lang3 + 3.12.0 + jar + + + org.apache.httpcomponents + httpcore + 4.4.16 + + + org.apache.httpcomponents + httpclient + 4.5.14 + + + + commons-codec + commons-codec + + + + + commons-codec + commons-codec + 1.17.0 + + + javax.inject + javax.inject + 1 + + - - src/main/java - - - - org.eclipse.tycho - tycho-p2-director-plugin - ${tycho.version} - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.2.0 - - - copy-dependencies - - copy-dependencies - - - org.eclipse - runtime - false - - - - - - org.eclipse.tycho - target-platform-configuration - ${tycho-version} - - - - - p2-installable-unit - org.eclipse.platform.ide - 0.0.0 - - - - - - - + + src/main/java + + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho.version} + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.2.0 + + + copy-dependencies + + copy-dependencies + + + org.eclipse + runtime + false + + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + p2-installable-unit + org.eclipse.platform.ide + 0.0.0 + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.26.0 + + 4 + false + true + + src/main/resources/pmd-ruleset.xml + + + + + + check + cpd-check + + verify + + + + + diff --git a/plugin/src/main/java/io/snyk/eclipse/plugin/html/OssHtmlProvider.java b/plugin/src/main/java/io/snyk/eclipse/plugin/html/OssHtmlProvider.java index e056b245..6a745f6e 100644 --- a/plugin/src/main/java/io/snyk/eclipse/plugin/html/OssHtmlProvider.java +++ b/plugin/src/main/java/io/snyk/eclipse/plugin/html/OssHtmlProvider.java @@ -1,24 +1,21 @@ package io.snyk.eclipse.plugin.html; public class OssHtmlProvider extends BaseHtmlProvider { - private static OssHtmlProvider instance = new OssHtmlProvider(); + private static OssHtmlProvider instance = new OssHtmlProvider(); - public static OssHtmlProvider getInstance() { - synchronized (OssHtmlProvider.class) { - if (instance == null) { - if (instance == null) { - instance = new OssHtmlProvider(); - } - } - } - return instance; - } + public static OssHtmlProvider getInstance() { + synchronized (OssHtmlProvider.class) { + if (instance == null) { + instance = new OssHtmlProvider(); + } + } + return instance; + } - @Override - public String replaceCssVariables(String html) { - html = super.replaceCssVariables(html); - html = html.replace("var(--container-background-color)", - super.getColorAsHex("org.eclipse.ui.workbench.DARK_BACKGROUND", "#F0F0F0")); - return html; - } + @Override + public String replaceCssVariables(String html) { + var returnValue = super.replaceCssVariables(html); + return returnValue.replace("var(--container-background-color)", + super.getColorAsHex("org.eclipse.ui.workbench.DARK_BACKGROUND", "#F0F0F0")); + } } diff --git a/plugin/src/main/java/io/snyk/eclipse/plugin/wizards/SnykWizard.java b/plugin/src/main/java/io/snyk/eclipse/plugin/wizards/SnykWizard.java index 3f37edb7..b1e98eba 100644 --- a/plugin/src/main/java/io/snyk/eclipse/plugin/wizards/SnykWizard.java +++ b/plugin/src/main/java/io/snyk/eclipse/plugin/wizards/SnykWizard.java @@ -27,7 +27,6 @@ public class SnykWizard extends Wizard implements INewWizard { public SnykWizard() { super(); model = new SnykWizardModel(); - setNeedsProgressMonitor(true); } @Override @@ -42,6 +41,7 @@ public void addPages() { authenticatePage = new SnykWizardAuthenticatePage(); addPage(authenticatePage); + setNeedsProgressMonitor(true); } public void init(IWorkbench workbench, IStructuredSelection selection) { diff --git a/plugin/src/main/resources/pmd-ruleset.xml b/plugin/src/main/resources/pmd-ruleset.xml new file mode 100644 index 00000000..8a0becde --- /dev/null +++ b/plugin/src/main/resources/pmd-ruleset.xml @@ -0,0 +1,26 @@ + + + + Sensible PMD rules focusing on important code quality issues + + + + + + + + + + + + + + + + + .*/generated/.* + .*/target/.* + diff --git a/pom.xml b/pom.xml index 658d99d5..b8bc4458 100644 --- a/pom.xml +++ b/pom.xml @@ -1,173 +1,174 @@ - 4.0.0 - io.snyk - parent - 3.0.0-SNAPSHOT - pom + 4.0.0 + io.snyk + parent + 3.0.0-SNAPSHOT + pom - - 4.0.9 - scm:git:https://github.com/snyk/snyk-eclipse-plugin.git - target-platform - UTF-8 - 17 - 17 - + + 4.0.9 + scm:git:https://github.com/snyk/snyk-eclipse-plugin.git + target-platform + UTF-8 + 17 + 17 + ${project.basedir} + - - target-platform - plugin - feature - tests - update-site - + + target-platform + plugin + feature + tests + update-site + - - - - org.eclipse.tycho - tycho-maven-plugin - ${tycho-version} - true - - - org.eclipse.tycho - target-platform-configuration - ${tycho-version} - - - - ${project.groupId} - ${target-config} - ${project.version} - - - - - win32 - win32 - x86_64 - - - linux - gtk - x86_64 - - - linux - gtk - aarch64 - - - macosx - cocoa - x86_64 - - - macosx - cocoa - aarch64 - - - - - - org.eclipse.tycho - tycho-source-plugin - ${tycho-version} - - - plugin-source - - plugin-source - - - - - - org.eclipse.tycho - tycho-packaging-plugin - - - true - - - - - org.eclipse.tycho.extras - tycho-sourceref-jgit - ${tycho-version} - - - - - - - - org.eclipse.tycho - tycho-packaging-plugin - ${tycho-version} - - - org.eclipse.tycho - tycho-p2-plugin - ${tycho-version} - - - - https://download.eclipse.org/lsp4e/snapshots - - - - - - - - - - - sign - + - - org.apache.maven.plugins - maven-jarsigner-plugin - 3.0.0 - - - sign - package - - sign - - - - - ${project.basedir}/../keystore.jks - snyk - ${env.KEYSTORE_PASS} - - - - org.eclipse.tycho - tycho-p2-plugin - ${tycho-version} - - - p2-metadata - package - - p2-metadata - - - - - false - - + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + ${project.groupId} + ${target-config} + ${project.version} + + + + + win32 + win32 + x86_64 + + + linux + gtk + x86_64 + + + linux + gtk + aarch64 + + + macosx + cocoa + x86_64 + + + macosx + cocoa + aarch64 + + + + + + org.eclipse.tycho + tycho-source-plugin + ${tycho-version} + + + plugin-source + + plugin-source + + + + + + org.eclipse.tycho + tycho-packaging-plugin + + + true + + + + + org.eclipse.tycho.extras + tycho-sourceref-jgit + ${tycho-version} + + + - - - + + + + org.eclipse.tycho + tycho-packaging-plugin + ${tycho-version} + + + org.eclipse.tycho + tycho-p2-plugin + ${tycho-version} + + + + https://download.eclipse.org/lsp4e/snapshots + + + + + + + + + + + sign + + + + org.apache.maven.plugins + maven-jarsigner-plugin + 3.0.0 + + + sign + package + + sign + + + + + ${project.basedir}/../keystore.jks + snyk + ${env.KEYSTORE_PASS} + + + + org.eclipse.tycho + tycho-p2-plugin + ${tycho-version} + + + p2-metadata + package + + p2-metadata + + + + + false + + + + + + diff --git a/tests/pom.xml b/tests/pom.xml index dd7687eb..fa57ca65 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -6,6 +6,7 @@ parent 3.0.0-SNAPSHOT + io.snyk.eclipse.plugin.tests eclipse-test-plugin diff --git a/update-site/pom.xml b/update-site/pom.xml index 4a01acba..b01631fd 100644 --- a/update-site/pom.xml +++ b/update-site/pom.xml @@ -1,52 +1,51 @@ - 4.0.0 - update-site - - io.snyk - parent - 3.0.0-SNAPSHOT - - eclipse-repository - - - - - org.eclipse.tycho - target-platform-configuration - - none - - - - p2-installable-unit - org.eclipse.platform.ide - 0.0.0 - - - - - - - org.eclipse.tycho - tycho-p2-director-plugin - ${tycho-version} - - - create-product-distributions - - materialize-products - archive-products - - - - - - org.eclipse.tycho - tycho-p2-repository-plugin - ${tycho-version} - - - + 4.0.0 + update-site + + io.snyk + parent + 3.0.0-SNAPSHOT + + eclipse-repository + + + + org.eclipse.tycho + target-platform-configuration + + none + + + + p2-installable-unit + org.eclipse.platform.ide + 0.0.0 + + + + + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho-version} + + + create-product-distributions + + materialize-products + archive-products + + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + +