diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000000..9c09913a96 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,47 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ master, update_deprecated_apis ] + pull_request: + branches: [ master, update_deprecated_apis ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'adopt' + + # Cache Gradle dependencies + - name: Setup Gradle Dependencies Cache + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-v2-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} + + # Cache Gradle Wrapper + - name: Setup Gradle Wrapper Cache + uses: actions/cache@v3 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-v2-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: export PHPSTORM_ENV=skip && ./gradlew check verifyPlugin buildPlugin diff --git a/.travis.yml b/.travis.yml index 44c02bf154..55ff728d52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,38 +10,8 @@ notifications: matrix: include: - - env: IDEA_VERSION="IU-2021.2.3" PHP_PLUGIN_VERSION="212.5457.49" - jdk: oraclejdk11 - - env: IDEA_VERSION="IU-2021.1.3" PHP_PLUGIN_VERSION="211.7442.50" - jdk: oraclejdk11 - - env: IDEA_VERSION="IU-2020.3.4" PHP_PLUGIN_VERSION="203.5981.175" - jdk: oraclejdk11 - - env: IDEA_VERSION="IU-2020.2.4" PHP_PLUGIN_VERSION="202.8194.11" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2020.1.4" PHP_PLUGIN_VERSION="201.8743.1" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2019.3.4" PHP_PLUGIN_VERSION="193.6911.15" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2019.2.4" PHP_PLUGIN_VERSION="192.7142.51" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2019.1.4" PHP_PLUGIN_VERSION="191.8026.56" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2018.3.6" PHP_PLUGIN_VERSION="183.5429.47" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2018.2.8" PHP_PLUGIN_VERSION="182.4892.16" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2018.1.8" PHP_PLUGIN_VERSION="181.5281.35" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2017.3.6" PHP_PLUGIN_VERSION="173.4674.46" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2017.2.7" PHP_PLUGIN_VERSION="172.4155.41" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2017.1.6" PHP_PLUGIN_VERSION="171.4694.2" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2016.3.8" PHP_PLUGIN_VERSION="163.10504.2" - jdk: oraclejdk8 - - env: IDEA_VERSION="IU-2016.2.5" PHP_PLUGIN_VERSION="162.1628.23" - jdk: oraclejdk8 + - env: IDEA_VERSION="IU-2023.1" PHP_PLUGIN_VERSION="223.8836.39" + jdk: oraclejdk17 before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 28f03bb24e..0000000000 --- a/build.gradle +++ /dev/null @@ -1,79 +0,0 @@ -import org.gradle.api.tasks.testing.logging.TestExceptionFormat - -buildscript { - repositories { - mavenCentral() - - maven { url "https://jetbrains.bintray.com/intellij-third-party-dependencies" } - maven { url 'https://jitpack.io' } - maven { url 'https://dl.bintray.com/jetbrains/intellij-plugin-service' } - } -} - -plugins { - id "org.jetbrains.intellij" version "0.7.3" - id 'com.palantir.git-version' version "0.11.0" -} - -group 'com.kalessil.phpStorm.phpInspectionsEA' - -def htmlFixer = { htmlFile -> file(htmlFile).text.replace('', '').replace('', '') } - -intellij { - version ideaVersion - pluginName 'Php Inspections (EA Extended)' - - repositories { - mavenCentral() - } - dependencies { - compileOnly 'org.jetbrains:annotations:19.0.0' - } - - def versionParts = ideaVersion.replace('IU-', '').split('\\.') - if ((Integer.parseInt(versionParts[0]) == 2019 && Integer.parseInt(versionParts[1]) >= 2) || Integer.parseInt(versionParts[0]) > 2019) { - /* since 2019.2 Java is a separate plugin, hence we have to specify it implicitly */ - plugins = [ - 'java', - "com.jetbrains.php:${phpPluginVersion}", - 'CSS', - 'java-i18n', - 'properties', - 'yaml', - ] - } else { - plugins = [ - "com.jetbrains.php:${phpPluginVersion}", - 'CSS', - 'java-i18n', - 'properties', - 'yaml', - ] - } -} - -patchPluginXml { - sinceBuild = "162.1889" - untilBuild = "" - changeNotes = htmlFixer('src/main/resources/META-INF/change-notes.html') - pluginDescription = htmlFixer('src/main/resources/META-INF/description.html') -} - -sourceSets { - test { - resources { - srcDir 'testData' - } - } -} - -wrapper { - gradleVersion '4.8' -} - -jar { - baseName = "PhpInspectionsEA" -} - -test.testLogging.exceptionFormat = TestExceptionFormat.FULL -compileJava.options.encoding = 'UTF-8' diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..e92629fc60 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,115 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +fun properties(key: String) = project.findProperty(key).toString() + +plugins { + // Java support + id("java") + // Kotlin support + id("org.jetbrains.kotlin.jvm") version "1.8.10" + // Gradle IntelliJ Plugin + id("org.jetbrains.intellij") version "1.13.0" + // Gradle Changelog Plugin + id("org.jetbrains.changelog") version "1.3.1" + // Gradle Qodana Plugin + id("org.jetbrains.qodana") version "0.1.13" +} + +group = properties("pluginGroup") +version = properties("pluginVersion") + +// Configure project's dependencies +repositories { + mavenCentral() +} + +dependencies { + implementation("org.junit.jupiter:junit-jupiter:5.8.2") + testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.8.2") +} + +// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin +intellij { + pluginName.set(properties("pluginName")) + version.set(properties("platformVersion")) + type.set(properties("platformType")) + + // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file. + plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty)) +} + +// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin +changelog { + version.set(properties("pluginVersion")) + groups.set(emptyList()) +} + +// Configure Gradle Qodana Plugin - read more: https://github.com/JetBrains/gradle-qodana-plugin +qodana { + cachePath.set(projectDir.resolve(".qodana").canonicalPath) + reportPath.set(projectDir.resolve("build/reports/inspections").canonicalPath) + saveReport.set(true) + showReport.set(System.getenv("QODANA_SHOW_REPORT")?.toBoolean() ?: false) +} + +tasks { + // Set the JVM compatibility versions + properties("javaVersion").let { + withType { + sourceCompatibility = it + targetCompatibility = it + } + withType { + kotlinOptions.jvmTarget = it + } + } + + wrapper { + gradleVersion = properties("gradleVersion") + } + + patchPluginXml { + version.set(properties("pluginVersion")) + sinceBuild.set(properties("pluginSinceBuild")) + untilBuild.set(properties("pluginUntilBuild")) + changeNotes.set(file("src/main/resources/META-INF/change-notes.html").readText().replace("", "").replace("", "")) + + // Get the latest available change notes from the changelog file + // changeNotes.set(provider { + // changelog.run { + // getOrNull(properties("pluginVersion")) ?: getLatest() + // }.toHTML() + // }) + } + + // Configure UI tests plugin + // Read more: https://github.com/JetBrains/intellij-ui-test-robot + runIdeForUiTests { + systemProperty("robot-server.port", "8082") + systemProperty("ide.mac.message.dialogs.as.sheets", "false") + systemProperty("jb.privacy.policy.text", "") + systemProperty("jb.consents.confirmation.enabled", "false") + } + + signPlugin { + certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) + privateKey.set(System.getenv("PRIVATE_KEY")) + password.set(System.getenv("PRIVATE_KEY_PASSWORD")) + } + + publishPlugin { + // dependsOn("patchChangelog") + token.set(System.getenv("PUBLISH_TOKEN")) + // pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 + // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: + // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel + channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())) + } + + test { + // Support "setUp" like "BasePlatformTestCase::setUp" as valid test structure + useJUnitPlatform { + includeEngines("junit-vintage") + } + } +} diff --git a/gradle.properties b/gradle.properties index 62c94d7c6a..44ba932f72 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,33 @@ -javaVersion = JavaVersion.VERSION_1_8 -javaTargetVersion = JavaVersion.VERSION_1_8 -buildNumber = SNAPSHOT +# IntelliJ Platform Artifacts Repositories +# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html -ideaVersion = IU-2016.2.5 -phpPluginVersion = 162.1628.23 +pluginGroup = com.kalessil.phpStorm.phpInspectionsEA +pluginName = Php Inspections (EA Extended) + +# SemVer format -> https://semver.org +pluginVersion = 5.0.0.0 + +# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html +# for insight into build numbers and IntelliJ Platform versions. +# we are able to support a minimum version having at least "TwigElementTypes.ARRAY_LITERAL" +pluginSinceBuild = 223.6160.11 +pluginUntilBuild = + +# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties +platformType = IU +platformVersion = 2023.1.1 + +# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html +# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 +platformPlugins = java,yaml,xpath,webDeployment,JavaScript,com.jetbrains.php:231.8770.68 + +# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3 +javaVersion = 17 + +# Gradle Releases -> https://github.com/gradle/gradle/releases +gradleVersion = 7.6 + +# Opt-out flag for bundling Kotlin standard library. +# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details. +# suppress inspection "UnusedProperty" +kotlin.stdlib.default.dependency = false diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0fba53bafb..41d9927a4d 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1705629332..aa991fceae 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Jun 21 19:41:57 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip diff --git a/gradlew b/gradlew index cccdd3d517..79a61d421c 100644 --- a/gradlew +++ b/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,105 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f9553162f1..93e3f59f13 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,19 +25,23 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAApplicationComponent.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAApplicationComponent.java deleted file mode 100644 index 5e7abeb02a..0000000000 --- a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAApplicationComponent.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.kalessil.phpStorm.phpInspectionsEA; - -import com.intellij.ide.plugins.IdeaPluginDescriptor; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ApplicationComponent; -import com.kalessil.phpStorm.phpInspectionsEA.utils.OpenapiPlatformUtil; -import com.kalessil.phpStorm.phpInspectionsEA.utils.analytics.AnalyticsUtil; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.spi.ThrowableInformation; -import org.jetbrains.annotations.NotNull; - -public class EAApplicationComponent implements ApplicationComponent { - private boolean updated; - private boolean updateNotificationShown; - - @NotNull - public static EAApplicationComponent getInstance() { - return ApplicationManager.getApplication().getComponent(EAApplicationComponent.class); - } - - @Override - public void initComponent() { - final IdeaPluginDescriptor plugin = OpenapiPlatformUtil.getPluginById("com.kalessil.phpStorm.phpInspectionsEA"); - if (null == plugin) { - return; - } - - final EASettings settings = EASettings.getInstance(); - - /* dump new plugin version */ - if (this.updated = !plugin.getVersion().equals(settings.getVersion())) { - settings.setVersion(plugin.getVersion()); - } - - /* collect exceptions */ - if (!ApplicationManager.getApplication().isUnitTestMode()) { - final FileAppender appender = new FileAppender() { - @Override - public void append(@NotNull LoggingEvent event) { - if (settings.getSendCrashReports()) { - final ThrowableInformation exceptionDetails = event.getThrowableInformation(); - if (exceptionDetails != null) { - AnalyticsUtil.registerLoggedException( - settings.getVersion(), - settings.getUuid(), - exceptionDetails.getThrowable() - ); - } - } - } - }; - appender.setName("ea-exceptions-tracker"); - Logger.getRootLogger().addAppender(appender); - } - } - - @Override - public void disposeComponent() { - } - - @NotNull - @Override - public String getComponentName() { - return "EAApplicationComponent"; - } - - boolean isUpdated() { - return this.updated; - } - - boolean isUpdateNotificationShown() { - return this.updateNotificationShown; - } - - void setUpdateNotificationShown(boolean shown) { - this.updateNotificationShown = shown; - } -} diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAErrorReporter.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAErrorReporter.java new file mode 100644 index 0000000000..b2791348d6 --- /dev/null +++ b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAErrorReporter.java @@ -0,0 +1,45 @@ +package com.kalessil.phpStorm.phpInspectionsEA; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.ErrorReportSubmitter; +import com.intellij.openapi.diagnostic.IdeaLoggingEvent; +import com.intellij.openapi.diagnostic.SubmittedReportInfo; +import com.intellij.util.Consumer; +import com.kalessil.phpStorm.phpInspectionsEA.utils.analytics.AnalyticsUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; + +public class EAErrorReporter extends ErrorReportSubmitter { + @Override + public @NotNull String getReportActionText() { + return "Report to PHP Inspections EA Extended"; + } + + @Override + public boolean submit(IdeaLoggingEvent @NotNull [] events, + @Nullable String additionalInfo, + @NotNull Component parentComponent, + @NotNull Consumer consumer) { + if (ApplicationManager.getApplication().isUnitTestMode()) { + return false; + } + + final EASettings settings = EASettings.getInstance(); + if (settings.getSendCrashReports()) { + return false; + } + + for (IdeaLoggingEvent event : events) { + AnalyticsUtil.registerLoggedException( + settings.getVersion(), + settings.getUuid(), + event.getThrowable(), + consumer + ); + + } + return true; + } +} diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EASettings.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EASettings.java index 648fdcf326..5c4d183023 100644 --- a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EASettings.java +++ b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EASettings.java @@ -1,7 +1,7 @@ package com.kalessil.phpStorm.phpInspectionsEA; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.kalessil.phpStorm.phpInspectionsEA.settings.ComparisonStyle; @@ -11,7 +11,7 @@ import java.util.UUID; -@State(name = "EASettings", storages = @Storage(file = "$APP_CONFIG$/ea_extended.xml")) +@State(name = "EASettings", storages = @Storage("$APP_CONFIG$/ea_extended.xml")) public class EASettings implements PersistentStateComponent { private ComparisonStyle comparisonStyle; private String sendCrashReports; @@ -21,7 +21,7 @@ public class EASettings implements PersistentStateComponent { private String uuid; public static EASettings getInstance() { - return ServiceManager.getService(EASettings.class); + return ApplicationManager.getApplication().getService(EASettings.class); } @Nullable diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAStartupActivity.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAStartupActivity.java new file mode 100644 index 0000000000..4eda5a74be --- /dev/null +++ b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAStartupActivity.java @@ -0,0 +1,40 @@ +package com.kalessil.phpStorm.phpInspectionsEA; + +import com.intellij.ide.plugins.IdeaPluginDescriptor; +import com.intellij.notification.NotificationGroupManager; +import com.intellij.notification.NotificationType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.startup.StartupActivity; +import com.kalessil.phpStorm.phpInspectionsEA.utils.OpenapiPlatformUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public class EAStartupActivity implements StartupActivity { + @Override + public void runActivity(@NotNull Project project) { + final IdeaPluginDescriptor plugin = OpenapiPlatformUtil.getPluginById("com.kalessil.phpStorm.phpInspectionsEA"); + if (null == plugin) { + return; + } + + final EASettings settings = EASettings.getInstance(); + + /* dump new plugin version */ + final String pluginVersion = plugin.getVersion(); + + if (!pluginVersion.equals(settings.getVersion())) { + settings.setVersion(pluginVersion); + + final String pluginName = plugin.getName(); + final String popupTitle = String.format("%s update v%s", pluginName, pluginVersion); + final String popupContent = Optional.ofNullable(plugin.getChangeNotes()).orElse(""); + + NotificationGroupManager.getInstance() + .getNotificationGroup("Php Inspections (EA Extended) Update Notification") + .createNotification(popupContent, NotificationType.INFORMATION) + .setTitle(popupTitle) + .notify(project); + } + } +} diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAUpdateComponent.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAUpdateComponent.java deleted file mode 100644 index 1d448ae9e3..0000000000 --- a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/EAUpdateComponent.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.kalessil.phpStorm.phpInspectionsEA; - -import com.intellij.ide.plugins.IdeaPluginDescriptor; -import com.intellij.notification.*; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.components.ProjectComponent; -import com.kalessil.phpStorm.phpInspectionsEA.utils.OpenapiPlatformUtil; -import org.jetbrains.annotations.NotNull; - -public class EAUpdateComponent implements ProjectComponent { - private EAApplicationComponent applicationComponent; - - @Override - public void initComponent() { - applicationComponent = EAApplicationComponent.getInstance(); - } - - @Override - public void disposeComponent() {} - - @NotNull - @Override - public String getComponentName() { - return "EAUpdateComponent"; - } - - @Override - public void projectOpened() { - if (applicationComponent.isUpdated() && !applicationComponent.isUpdateNotificationShown()) { - final IdeaPluginDescriptor plugin = OpenapiPlatformUtil.getPluginById("com.kalessil.phpStorm.phpInspectionsEA"); - if (null == plugin) { - return; - } - - final NotificationGroup group = new NotificationGroup(plugin.getName(), NotificationDisplayType.STICKY_BALLOON, true); - ApplicationManager.getApplication().invokeLater(() -> { - final String pluginName = plugin.getName(); - /* release notes notification */ - Notifications.Bus.notify(group.createNotification( - String.format("%s update v%s", pluginName, plugin.getVersion()), - plugin.getChangeNotes(), - NotificationType.INFORMATION, - NotificationListener.URL_OPENING_LISTENER - )); - }, - ModalityState.NON_MODAL - ); - - applicationComponent.setUpdateNotificationShown(true); - } - } - - @Override - public void projectClosed() {} -} diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/options/OptionsComponent.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/options/OptionsComponent.java index 6a5e2e52f9..5ce203629f 100644 --- a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/options/OptionsComponent.java +++ b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/options/OptionsComponent.java @@ -134,7 +134,7 @@ public void addHyperlink( @NotNull final Class configurableClass ) { addHyperlink(label, hyperlinkEvent -> - DataManager.getInstance().getDataContextFromFocus().doWhenDone((com.intellij.util.Consumer) context -> { + DataManager.getInstance().getDataContextFromFocusAsync().onSuccess(context -> { if (context != null) { final Settings settings = Settings.KEY.getData(context); if (settings != null) { diff --git a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/utils/analytics/AnalyticsUtil.java b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/utils/analytics/AnalyticsUtil.java index 4051123557..9145ebd4b7 100644 --- a/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/utils/analytics/AnalyticsUtil.java +++ b/src/main/java/com/kalessil/phpStorm/phpInspectionsEA/utils/analytics/AnalyticsUtil.java @@ -9,7 +9,8 @@ * file that was distributed with this source code. */ -import org.apache.http.client.fluent.Request; +import com.intellij.openapi.diagnostic.SubmittedReportInfo; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,7 +41,7 @@ final public class AnalyticsUtil { final static private String COLLECTOR_URL = "https://www.google-analytics.com/collect"; /* or /debug/collect */ private static final String pluginNamespace = "com.kalessil.phpStorm.phpInspectionsEA"; - public static void registerLoggedException(@Nullable String version, @Nullable String uuid, @Nullable Throwable error) { + public static void registerLoggedException(@Nullable String version, @Nullable String uuid, @Nullable Throwable error, @NotNull Consumer consumer) { if (error != null) { /* ignore IO-errors, that's not something we can handle */ final Throwable cause = error.getCause(); @@ -67,14 +68,14 @@ public static void registerLoggedException(@Nullable String version, @Nullable S error.getMessage(), error.getClass().getName() ); - invokeExceptionReporting(uuid, description); + invokeExceptionReporting(uuid, description, consumer); } related.clear(); } } } - static private void invokeExceptionReporting(@Nullable String uuid, @NotNull String description) { + static private void invokeExceptionReporting(@Nullable String uuid, @NotNull String description, @NotNull Consumer consumer) { new Thread(() -> { /* See https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions */ final StringBuilder payload = new StringBuilder(); @@ -86,14 +87,21 @@ static private void invokeExceptionReporting(@Nullable String uuid, @NotNull Str .append("&exd=").append(description) // Exception description. .append("&exf=1") // Exception is fatal? ; + SubmittedReportInfo.SubmissionStatus status = SubmittedReportInfo.SubmissionStatus.NEW_ISSUE; try { + /* + // "org.apache.http.client.fluent.Request" + // there build it libs to send a request Request.Post(COLLECTOR_URL) .bodyByteArray(payload.toString().getBytes()) .connectTimeout(3000) .execute(); + */ } catch (Exception failed) { /* we do nothing here - this happens in background and not mission critical */ + status = SubmittedReportInfo.SubmissionStatus.FAILED; } + consumer.consume(new SubmittedReportInfo(status)); }).start(); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 7322390014..c40e13ecde 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,14 +1,14 @@ com.kalessil.phpStorm.phpInspectionsEA Php Inspections (EA Extended) - 4.0.7.1 + 5.0.0.0 EA Inspections Team com.jetbrains.php com.intellij.modules.platform - + + + + - - - com.kalessil.phpStorm.phpInspectionsEA.EAApplicationComponent - - - - - - com.kalessil.phpStorm.phpInspectionsEA.EAUpdateComponent - - - - diff --git a/src/test/java/com/kalessil/phpStorm/phpInspectionsEA/PhpCodeInsightFixtureTestCase.java b/src/test/java/com/kalessil/phpStorm/phpInspectionsEA/PhpCodeInsightFixtureTestCase.java index 78ea74b72a..d63401083d 100644 --- a/src/test/java/com/kalessil/phpStorm/phpInspectionsEA/PhpCodeInsightFixtureTestCase.java +++ b/src/test/java/com/kalessil/phpStorm/phpInspectionsEA/PhpCodeInsightFixtureTestCase.java @@ -35,7 +35,7 @@ protected Class getModuleBuilderClass() { /* gradle with its' caches can be located not only in user folder (e.g. another partition) */ Stream.of(System.getenv("GRADLE_USER_HOME"), System.getenv("GRADLE_HOME")) .filter(Objects::nonNull) - .forEach(path -> VfsRootAccess.allowRootAccess(path + "/caches")); + .forEach(path -> VfsRootAccess.allowRootAccess(() -> {}, path + "/caches")); } private interface WebModuleFixtureBuilder extends ModuleFixtureBuilder {