Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate code snippets from idea-plugin with Ank #542

Closed
rachelcarmena opened this issue Apr 15, 2020 · 9 comments
Closed

Validate code snippets from idea-plugin with Ank #542

rachelcarmena opened this issue Apr 15, 2020 · 9 comments
Assignees

Comments

@rachelcarmena
Copy link
Member

Code snippets from idea-plugin are using classes that are provided by Intellij IDEA Gradle plugin and Kotlin IDEA Plugin.

Figure out how to provide those classes to Ank.

P.D.: I'm creating this issue to explain how I'm solving the errors with documentation check in #414 (API doc creation and validation).

@rachelcarmena rachelcarmena self-assigned this Apr 15, 2020
@rachelcarmena
Copy link
Member Author

rachelcarmena commented Apr 15, 2020

In order to validate code snippets from IDEA plugin is necessary to include:

plugins {
    id "org.jetbrains.intellij" version "$INTELLIJ_GRADLE_PLUGIN_VERSION"
}

intellij {
    version = "$INTELLIJ_IDEA_VERSION"
    plugins = ["org.jetbrains.kotlin:${KOTLIN_IDEA_VERSION}"]
}

and

ank { 
   ...
  classpath = sourceSets.main.runtimeClasspath + sourceSets.main.compileClasspath
}

Just with:

intellij {
    version = "$INTELLIJ_IDEA_VERSION"
}

some compilation errors are solved. To solve the rest of unresolved reference errors is also necessary to add kotlin-plugin.jar which is provided by Kotlin IDEA Plugin.

However, if we add all the JARs provided by Intellij IDEA Gradle plugin and Kotlin IDEA Plugin:

ApplicationManager.getApplication() must not be null

@rachelcarmena
Copy link
Member Author

Let's see which JARs are needed:

  • List all the provided JARs:
 task printcp {
    doLast {
        println sourceSets.main.compileClasspath.each { println it }
        println sourceSets.main.runtimeClasspath.each { println it }
    }
}
  • List the content with jar tvf and find the required classes:
    • org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors
    • org.jetbrains.kotlin.idea.highlighter.KotlinHighlighter
    • org.jetbrains.kotlin.caches.resolve.KotlinCacheService
    • com.intellij.psi.codeStyle.DisplayPriority
    • ...

So the necessary libraries are:

  • ideaIC-2019.3.4/lib/platform-api.jar
  • org.jetbrains.kotlin-1.3.61-release-IJ2019.3-1/Kotlin/lib/kotlin-plugin.jar

If those JARs are provided with local paths to Ank:

classpath = sourceSets.main.runtimeClasspath 
  + layout.files("<full path of kotlin-plugin.jar>", "<full path of platform-api.jar>")

all the unresolved reference compilation errors are solved.

@rachelcarmena
Copy link
Member Author

And then other pending compilation errors appear (hidden by a general ApplicationManager.getApplication() must not be null error).

@rachelcarmena
Copy link
Member Author

I also tried to remove some provided JARs by Intellij IDEA Gradle plugin and Kotlin IDEA Plugin (it seems idea.jar could raise ApplicationManager.getApplication() must not be null error). However, when doing something like:

classpath = sourceSets.main.runtimeClasspath 
  + layout.files(sourceSets.main.compileClasspath.findAll { it.name != 'idea.jar' })

I got:

Cannot change dependencies of configuration ':docs:idea' after it has been included 
in dependency resolution

So let's continue with the solution about adding just platform-api.jar and kotlin-plugin.jar.

@rachelcarmena
Copy link
Member Author

It's also necessary:

  • ideaIC-2019.3.4/lib/platform-impl.jar

for:

  • com.intellij.openapi.editor.ex.util.EditorUtil

@rachelcarmena
Copy link
Member Author

It's also necessary:

  • ideaIC-2019.3.4/lib/idea.jar

for:

  • com.intellij.testFramework.fixtures.CodeInsightTestFixture

@rachelcarmena
Copy link
Member Author

Solved all the hidden compilation errors by the previous ApplicationManager.getApplication() must not be null error . Let's improve the local solution to add platform-api.jar, kotlin-plugin.jar, platform-impl.jar and idea.jar without hard-coded local paths.

@rachelcarmena
Copy link
Member Author

Summary:

  • If all the libraries that are provided by Intellij IDEA Gradle plugin and Kotlin IDEA Plugin are included for Ank validation, this error raises:
ApplicationManager.getApplication() must not be null
  • It's necessary to provide just the required libraries for Ank validation.
  • According to the current code snippets in idea-plugin, it's just necessary to provide platform-api.jar, platform-impl.jar, idea.jar and kotlin-plugin.jar.

@rachelcarmena
Copy link
Member Author

Solved via #414 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant