Skip to content

Commit

Permalink
Setup project plugin dependency for an already evaluated project (#238)…
Browse files Browse the repository at this point in the history
… (#266)

Gradle's project.afterEvaluate won't get executed if project is already
executed, so we have to check for this manually.

(cherry picked from commit 38f7376)
  • Loading branch information
Undin authored and zolotov committed Mar 9, 2018
1 parent 2ed0787 commit fccf103
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/main/groovy/org/jetbrains/intellij/IntelliJPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class IntelliJPlugin implements Plugin<Project> {
configurePublishPluginTask(project, extension)
configureProcessResources(project)
configureInstrumentation(project, extension)
assert !project.state.executed : "afterEvaluate is a no-op for an executed project"
project.afterEvaluate { configureProjectAfterEvaluate(it, extension) }
}

Expand Down Expand Up @@ -129,16 +130,11 @@ class IntelliJPlugin implements Plugin<Project> {
LOG.info("Configuring IntelliJ plugin $it")
if (it instanceof Project) {
project.dependencies.add(IDEA_PLUGINS_CONFIGURATION_NAME, it)
it.afterEvaluate {
if (it.plugins.findPlugin(IntelliJPlugin) == null) {
throw new BuildException("Cannot use $it as a plugin dependency. IntelliJ Plugin is not found." + it.plugins, null)
}
def dependency = new PluginProjectDependency(it)
extension.pluginDependencies.add(dependency)
def dependencySandboxTask = it.tasks.findByName(PREPARE_SANDBOX_TASK_NAME)
project.tasks.withType(PrepareSandboxTask).each {
it.dependsOn(dependencySandboxTask)
it.configureCompositePlugin(dependency)
if (it.state.executed) {
configureProjectPluginDependency(project, it, extension)
} else {
it.afterEvaluate {
configureProjectPluginDependency(project, it, extension)
}
}
} else {
Expand All @@ -162,6 +158,21 @@ class IntelliJPlugin implements Plugin<Project> {
}
}

private static void configureProjectPluginDependency(@NotNull Project project,
@NotNull Project dependency,
@NotNull IntelliJPluginExtension extension) {
if (dependency.plugins.findPlugin(IntelliJPlugin) == null) {
throw new BuildException("Cannot use $dependency as a plugin dependency. IntelliJ Plugin is not found." + dependency.plugins, null)
}
def pluginDependency = new PluginProjectDependency(dependency)
extension.pluginDependencies.add(pluginDependency)
def dependencySandboxTask = dependency.tasks.findByName(PREPARE_SANDBOX_TASK_NAME)
project.tasks.withType(PrepareSandboxTask).each {
it.dependsOn(dependencySandboxTask)
it.configureCompositePlugin(pluginDependency)
}
}

private static void configurePatchPluginXmlTask(@NotNull Project project,
@NotNull IntelliJPluginExtension extension) {
LOG.info("Configuring patch plugin.xml task")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,53 @@ class PrepareSandboxTaskSpec extends IntelliJPluginSpecBase {
'META-INF/plugin.xml'] as Set
}

def 'prepare sandbox for two plugins with evaluated project'() {
given:
writeJavaFile()
pluginXml << """\
<idea-plugin>
<id>org.intellij.test.plugin</id>
<name>Test Plugin</name>
<version>1.0</version>
<vendor url="https://jetbrains.com">JetBrains</vendor>
<description>test plugin</description>
<change-notes/>
</idea-plugin>""".stripIndent()

buildFile << """\
allprojects {
version='0.42.123'
apply plugin: 'org.jetbrains.intellij'
intellij { downloadSources = false }
}
project(':') {
intellij.pluginName = 'myPluginName'
intellij.plugins = [project(':nestedProject')]
}
project(':nestedProject') {
intellij.pluginName = 'myNestedPluginName'
}
""".stripIndent()
file('settings.gradle') << "include 'nestedProject'"
file('nestedProject/src/main/java/NestedAppFile.java') << "class NestedAppFile{}"
file('nestedProject/src/main/resources/META-INF/plugin.xml') << pluginXml.text

when:
build(":$IntelliJPlugin.PREPARE_SANDBOX_TASK_NAME")

then:
collectPaths(sandbox) == ['/plugins/myPluginName/lib/projectName-0.42.123.jar',
'/plugins/myNestedPluginName/lib/nestedProject-0.42.123.jar',
'/config/options/updates.xml'] as Set

def jar = new File(sandbox, '/plugins/myPluginName/lib/projectName-0.42.123.jar')
collectPaths(new ZipFile(jar)) == ['META-INF/', 'META-INF/MANIFEST.MF', 'App.class', 'META-INF/plugin.xml'] as Set

def nestedProjectJar = new File(sandbox, '/plugins/myNestedPluginName/lib/nestedProject-0.42.123.jar')
collectPaths(new ZipFile(nestedProjectJar)) == ['META-INF/', 'META-INF/MANIFEST.MF', 'NestedAppFile.class',
'META-INF/plugin.xml'] as Set
}

def 'prepare sandbox task without plugin_xml'() {
given:
writeJavaFile()
Expand Down

0 comments on commit fccf103

Please sign in to comment.