Skip to content

Latest commit

 

History

History
115 lines (84 loc) · 5.34 KB

setup_development_env.md

File metadata and controls

115 lines (84 loc) · 5.34 KB

Table of Content

to update toc, please read this page.

Requirements

To build the project, you will need the following requirement

  • JDK 1.8
  • OPA binary (must be in the path, check version in the readme)
  • IntelliJ (community or ultimate version)

It's optional but we recommend you to install the following IntelliJ plugin:

  • Grammar-Kit to get highlighting of the grammar file.
  • PsiViewer to view the AST of Rust files right in the IDE.

Setup

Just clone the project and execute the tests to ensure everything is ok.

# clone the project 
$ git clone git@github.com:open-policy-agent/opa-idea-plugin.git
$ cd opa-idea-plugin

# run tests
$ ./gradlew :test 
  
> Task :compileKotlin
w: /Users/vince/workspace/perso/final/opa-idea-plugin/src/main/kotlin/org/openpolicyagent/ideaplugin/ide/actions/CheckAction.kt: (21, 13): Variable 'editor' is never used
w: /Users/vince/workspace/perso/final/opa-idea-plugin/src/main/kotlin/org/openpolicyagent/ideaplugin/openapiext/CommandLineExt.kt: (86, 29): Unnecessary safe call on a non-null receiver of type OutputStream

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 20s
15 actionable tasks: 13 executed,2 up-to-date

Main Gradle tasks

  • ./gradlew :plugin:buildPlugin -- fully build the plugin and create an archive at plugin/build/distributions which can be installed into your IDE via Install plugin from disk... action found in Settings > Plugins menu.
  • ./gradlew :plugin:runIde -- run a development IDE with the plugin installed.
  • ./gradlew :test
  • ./gradlew clean :plugin:verifyPlugin -- verify the plugin binary compatibility. More information here.

note: The : in front of the task name is important because now there are several Gradle modules.

Configuring the sandbox IDE

You can use the Gradle task :plugin:runIde to run sandbox IDE of your choice (IntelliJ or PyCharm) with these plugins installed:

  • opa
  • psi viewer

Once the sandbox IDE has started, you will have to create or open an existing project to test the plugin.

In most of the case, we will only need to run IntelliJ as a sandbox IDE. But it may be useful to run another IDE to test interoperability. For example, even if other IDE than IntelliJ can not create a rego project, it can open it.

You can choose which sandbox IDE to run, by setting the property baseIDE in gradle.properties

Note: Sometime you may need to reset your sandbox, you can use the task clean to do it.

Configuring the platform

For compatibility issue, one plugin archive is only compatible with one platform version(check architecture for more information)

You can choose which platform version to use by setting the platformVersion property in gradle.properties.
This version will be used for compiling and sandbox IDE.

Build the plugin archive

Run the task :plugin:runIde, the plugin distribution (ie thezip) will be generated in build/distributions/opa-idea-plugin-<version>-<platform_version>-<chanel>.zip

Once again because one plugin distribution in only compatible with on platform version, you have to run this command as many times as supported platform version. Don't forget to change the targeting platform version between each run.

Other important tasks

The lexer and parser code which are generated by tools are not committed in git. They can respectively be generated by the tasks :generateRegoLexer and :generateRegoParser.

These tasks are linked to the KotlinCompile task so if you try to build, test or run the sandbox ide, the lexer and the parser will be automatically generated.

The code is generated in the gen folder. If you want to reset the generated, just delete the content of the gen folder and launch tasks :generateRegoLexer and :generateRegoParser.

Configure IDE to automatically add license header

If it's not already done, please install the copyright plugin. This plugin will automatically add the license header when you create a file.

To configure it , open the Settings / Preferences dialog and select Editor | Copyright. Create a new profile with this license header:

Use of this source code is governed by the MIT license that can be
found in the LICENSE file.

To check if project file contains the license header, run the script hack/check-license.sh

$ hack/check-license.sh
  Checking files contains license header...
  Check OK