Skip to content

Commit

Permalink
Update plugin to be compatible with 2021.3 (#119)
Browse files Browse the repository at this point in the history
* update gradle to version 7.2
* update to idea 213
         the update of the gradle plugin comes with breaking changes see https://lp.jetbrains.com/gradle-intellij-plugin/ for more information

* update kokin and idea sdk call to be compatible with 213
       some of the change are not compatible with 211, so code is splitted into platform version code
       update kotlin code:
             * Type mismatch: value of a nullable type T is used where non-nullable type is expected. This warning will become an error soon. See https://youtrack.jetbrains.com/issue/KT-36770 for details
             * 'toLong(): Long' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.

        update idea skd call:
             * 'getVirtualFilesByName(Project!, String, GlobalSearchScope): (Mutable)Collection<VirtualFile!>' is deprecated. Deprecated in Java

Signed-off-by: Vincent Gramer <vgramer@gmail.com>
  • Loading branch information
vgramer authored Dec 9, 2021
1 parent 4c0b308 commit 7504457
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release_and_pulbish_plugin_on_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
needs: [check-gradle-wrapper]
strategy:
matrix:
platform-version: [ 203, 211 ]
platform-version: [ 211, 212 ]
env:
ORG_GRADLE_PROJECT_platformVersion: ${{ matrix.platform-version }}
ORG_GRADLE_PROJECT_publishChannel: stable
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform-version: [ 203, 211 ]
platform-version: [ 211, 212 ]
timeout-minutes: 60
env:
ORG_GRADLE_PROJECT_platformVersion: ${{ matrix.platform-version }}
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform-version: [ 203, 211 ]
platform-version: [ 211, 212 ]
timeout-minutes: 60
env:
ORG_GRADLE_PROJECT_platformVersion: ${{ matrix.platform-version }}
Expand Down
55 changes: 26 additions & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* found in the LICENSE file.
*/

import org.gradle.api.JavaVersion.VERSION_1_8
import org.gradle.api.JavaVersion.VERSION_11
import org.gradle.api.internal.HasConvention
import org.intellij.markdown.ast.getTextInNode
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
import org.jetbrains.intellij.tasks.RunIdeTask
import org.jetbrains.intellij.tasks.PublishTask
import org.jetbrains.intellij.tasks.PublishPluginTask
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand Down Expand Up @@ -40,15 +40,15 @@ buildscript {
idea {
module {
// https://github.com/gradle/kotlin-dsl/issues/537/
excludeDirs = excludeDirs + file("testData") + file("deps")
excludeDirs = excludeDirs + file("testData")
}
}

plugins {
idea
kotlin("jvm") version "1.4.32"
id("org.jetbrains.intellij") version "0.7.3"
id("org.jetbrains.grammarkit") version "2021.1.2"
kotlin("jvm") version "1.6.0"
id("org.jetbrains.intellij") version "1.2.1"
id("org.jetbrains.grammarkit") version "2021.1.3"
id("net.saliman.properties") version "1.5.1"
}

Expand All @@ -63,7 +63,6 @@ allprojects {

repositories {
mavenCentral()
jcenter()
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
}

Expand All @@ -87,8 +86,8 @@ allprojects {
}

intellij {
version = baseVersion
sandboxDirectory = "$buildDir/$baseIDE-sandbox-$platformVersion"
version.set(baseVersion)
sandboxDir.set("$buildDir/$baseIDE-sandbox-$platformVersion")
}

sourceSets {
Expand All @@ -103,25 +102,23 @@ allprojects {
}
}

configure<JavaPluginConvention> {
sourceCompatibility = VERSION_1_8
targetCompatibility = VERSION_1_8
configure<JavaPluginExtension> {
sourceCompatibility = VERSION_11
targetCompatibility = VERSION_11
}

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.3"
apiVersion = "1.3"
jvmTarget = "11"
freeCompilerArgs = listOf("-Xjvm-default=enable")
}
}

withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
sinceBuild(prop("sinceBuild"))
untilBuild(prop("untilBuild"))
changeNotes(getLastReleaseNotes())
sinceBuild.set(prop("sinceBuild"))
untilBuild.set(prop("untilBuild"))
changeNotes.set(provider {getLastReleaseNotes()}) // to check
}

withType<RunIdeTask> {
Expand Down Expand Up @@ -152,16 +149,16 @@ val pluginVersion = prop("pluginVersion")
project(":plugin"){
version = "$pluginVersion$versionSuffix"
intellij {
pluginName = "opa-idea-plugin"
val plugins = mutableListOf(
pluginName.set("opa-idea-plugin")
val pluginList = mutableListOf(
"PsiViewer:$psiViewerPluginVersion"
)
if (baseIDE == "idea") {
plugins += listOf(
pluginList += listOf(
"java"
)
}
setPlugins(*plugins.toTypedArray())
plugins.set(pluginList)
}

dependencies{
Expand All @@ -178,12 +175,12 @@ project(":plugin"){
withType<RunIdeTask> {
jvmArgs("--add-exports", "java.base/jdk.internal.vm=ALL-UNNAMED")
}
withType<PublishTask> {
token(prop("publishToken"))
channels(channel)
withType<PublishPluginTask> {
token.set(prop("publishToken"))
channels.set(listOf(channel))
}
runPluginVerifier {
ideVersions(prop("pluginVerifierIdeVersions"))
ideVersions.set(prop("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty))
}
buildSearchableOptions {
// buildSearchableOptions task doesn't make sense for non-root subprojects
Expand Down Expand Up @@ -225,8 +222,8 @@ project(":") {
doLast {
rootProject.allprojects
.map { it.configurations }
.flatMap { listOf(it.compile, it.testCompile) }
.forEach { it.get().resolve() }
.flatMap { it.filter { c -> c.isCanBeResolved } }
.forEach { it.resolve() }
}
}
}
Expand Down Expand Up @@ -286,4 +283,4 @@ fun getLastReleaseNotes(changLogPath: String = "CHANGELOG.md"): String {
releaseNotesChildren
)
return org.intellij.markdown.html.HtmlGenerator(src, root, flavour).generateHtml()
}
}
2 changes: 1 addition & 1 deletion gradle-211.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ psiViewerPluginVersion=211-SNAPSHOT

# see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for more information
sinceBuild=211.6693
untilBuild=212.*
untilBuild=211.*

# check the binary compatibility of the plugin against these idea versions ( more info at https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl)
pluginVerifierIdeVersions= IC-2021.1
14 changes: 7 additions & 7 deletions gradle-203.properties → gradle-212.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#

# if you change the version of ide, also change psiViewerPluginVersion accordingly (cf https://plugins.jetbrains.com/plugin/227-psiviewer/versions)
ideaVersion=IC-2020.3.4
pycharmCommunityVersion=PC-2020.3.4
psiViewerPluginVersion=203-SNAPSHOT
ideaVersion=IC-2021.2.3
pycharmCommunityVersion=PC-2021.2.3
psiViewerPluginVersion=212-SNAPSHOT

# see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for more information
sinceBuild=203.7148
untilBuild=203.*
sinceBuild=212.4746
untilBuild=213.*

# # check the binary compatibility of the plugin against these idea versions ( more info at https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl)
pluginVerifierIdeVersions= IC-2020.3.4
# check the binary compatibility of the plugin against these idea versions ( more info at https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl)
pluginVerifierIdeVersions= IC-2021.2, IC-2021.3
9 changes: 7 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ kotlin.code.style=official
# gradle property file named gradle-${environmentName}.properties
propertiesPluginEnvironmentNameProperty=platformVersion

# Supported platforms: 203, 211
platformVersion=211
# Supported platforms: 211, 212
platformVersion=212


# Version of the ide used for the sandbox( possible value are 'idea' or 'pycharmCommunity')
Expand All @@ -25,3 +25,8 @@ publishChannel=dev
pluginVersion=nextVersion

enableBuildSearchableOptions=false

# 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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
10 changes: 2 additions & 8 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#
# Use of this source code is governed by the MIT license that can be
# found in the LICENSE file.
#

#Wed Mar 11 22:19:20 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
51 changes: 31 additions & 20 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or 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
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down Expand Up @@ -138,19 +154,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
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" ;;
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

Expand All @@ -159,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
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")"
fi

exec "$JAVACMD" "$@"
21 changes: 20 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@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
Expand All @@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
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="-Xmx64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
36 changes: 36 additions & 0 deletions src/211/test/kotlin/org/openpolicyagent/ideaplugin/OpaTestBase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/

package org.openpolicyagent.ideaplugin

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import org.openpolicyagent.ideaplugin.FileTree
import org.openpolicyagent.ideaplugin.OpaTestCase
import org.openpolicyagent.ideaplugin.TestProject

abstract class OpaTestBase : BasePlatformTestCase(), OpaTestCase {

open val dataPath: String = ""

override fun getTestDataPath(): String = "${OpaTestCase.testResourcesPath}/${dataPath}"

protected val fileName: String
get() = "$testName.rego"

protected val testName: String
get() = camelOrWordsToSnake(getTestName(true))

companion object {
@JvmStatic
fun camelOrWordsToSnake(name: String): String {
if (' ' in name) return name.trim().replace(" ", "_")

return name.split("(?=[A-Z])".toRegex()).joinToString("_", transform = String::toLowerCase)
}
}

protected fun FileTree.create(): TestProject =
create(myFixture.project, myFixture.findFileInTempDir("."))
}
Loading

0 comments on commit 7504457

Please sign in to comment.