Skip to content

Commit

Permalink
Moved some more WTP stuff from eclipse plugin into the eclipseWtp plu…
Browse files Browse the repository at this point in the history
…gin. Simplified the code a bit. Removed some outstanding duplication.
  • Loading branch information
mockitoguy committed Jun 28, 2011
1 parent 45b4d49 commit 569a125
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
package org.gradle.plugins.ide.eclipse

import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.internal.ClassGenerator
import org.gradle.api.plugins.EarPlugin
import org.gradle.api.plugins.GroovyBasePlugin
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.scala.ScalaBasePlugin
import org.gradle.plugins.ide.api.XmlFileContentMerger
import org.gradle.plugins.ide.eclipse.internal.EclipseNameDeduper
import org.gradle.plugins.ide.eclipse.internal.LinkedResourcesCreator
import org.gradle.plugins.ide.eclipse.model.BuildCommand
import org.gradle.plugins.ide.eclipse.model.EclipseClasspath
import org.gradle.plugins.ide.eclipse.model.EclipseModel
import org.gradle.plugins.ide.internal.IdePlugin
import org.gradle.api.plugins.*
import org.gradle.plugins.ide.eclipse.model.*

/**
* <p>A plugin which generates Eclipse files.</p>
Expand Down Expand Up @@ -132,21 +136,6 @@ class EclipsePlugin extends IdePlugin {
project.sourceSets.main.output.dirs + project.sourceSets.test.output.dirs
}
}

project.plugins.withType(WarPlugin) {
doLaterWithEachDependedUponEclipseProject(project) { Project otherProject ->
configureTask(otherProject, ECLIPSE_CP_TASK_NAME) {
whenConfigured { Classpath classpath ->
for (entry in classpath.entries) {
if (entry instanceof Library) {
// '../' and '/WEB-INF/lib' both seem to be correct (and equivalent) values here
entry.entryAttributes['org.eclipse.jst.component.dependency'] = '../'
}
}
}
}
}
}
}
}
}
Expand All @@ -166,36 +155,7 @@ class EclipsePlugin extends IdePlugin {
}
}

// TODO: might have to search all class paths of all source sets for project dependendencies, not just runtime configuration
private void doLaterWithEachDependedUponEclipseProject(Project project, Closure action) {
project.gradle.projectsEvaluated {
eachDependedUponEclipseProject(project, action)
}
}

private void eachDependedUponEclipseProject(Project project, Closure action) {
def runtimeConfig = project.configurations.findByName("runtime")
if (runtimeConfig) {
def projectDeps = runtimeConfig.getAllDependencies(ProjectDependency)
def dependedUponProjects = projectDeps*.dependencyProject
for (dependedUponProject in dependedUponProjects) {
dependedUponProject.plugins.withType(EclipsePlugin) { action(dependedUponProject) }
eachDependedUponEclipseProject(dependedUponProject, action)
}
}
}

private void withTask(Project project, String taskName, Closure action) {
project.tasks.matching { it.name == taskName }.all(action)
}

private void configureTask(Project project, String taskName, Closure action) {
withTask(project, taskName) { task ->
project.configure(task, action)
}
}

private void maybeAddTask(Project project, EclipsePlugin plugin, String taskName, Class taskType, Closure action) {
private void maybeAddTask(Project project, IdePlugin plugin, String taskName, Class taskType, Closure action) {
if (project.tasks.findByName(taskName)) { return }
def task = project.tasks.add(taskName, taskType)
project.configure(task, action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.plugins.EarPlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.WarPlugin
import org.gradle.plugins.ide.eclipse.model.EclipseWtp
import org.gradle.plugins.ide.eclipse.model.Facet
import org.gradle.plugins.ide.eclipse.model.Facet.FacetType
import org.gradle.plugins.ide.eclipse.model.WbResource
import org.gradle.plugins.ide.internal.IdePlugin
import org.gradle.plugins.ide.eclipse.model.*

/**
* @author: Szczepan Faber, created at: 6/28/11
Expand All @@ -52,13 +50,31 @@ class EclipseWtpPlugin extends IdePlugin {
delegatePlugin.getLifecycleTask().dependsOn(getLifecycleTask())
delegatePlugin.getCleanTask().dependsOn(getCleanTask())

configureEclipseProjectWithType(project, WarPlugin)
configureEclipseProjectWithType(project, EarPlugin)
configureEclipseProjectForPlugin(project, WarPlugin)
configureEclipseProjectForPlugin(project, EarPlugin)
configureEclipseClasspathForWarPlugin(project)

configureEclipseWtpComponent(project)
configureEclipseWtpFacet(project)
}

private void configureEclipseClasspathForWarPlugin(Project project) {
project.plugins.withType(WarPlugin) {
doLaterWithEachDependedUponEclipseProject(project) { Project otherProject ->
otherProject.tasks.withType(GenerateEclipseClasspath) {
classpath.file.whenMerged { Classpath classpath ->
for (entry in classpath.entries) {
if (entry instanceof Library) {
// '../' and '/WEB-INF/lib' both seem to be correct (and equivalent) values here
entry.entryAttributes['org.eclipse.jst.component.dependency'] = '../'
}
}
}
}
}
}
}

private void configureEclipseWtpComponent(Project project) {
configureEclipseWtpComponentWithType(project, WarPlugin)
configureEclipseWtpComponentWithType(project, EarPlugin)
Expand Down Expand Up @@ -166,7 +182,6 @@ class EclipseWtpPlugin extends IdePlugin {
}
}

//TODO SF - duplicated (also some duplication in the test)
private void maybeAddTask(Project project, IdePlugin plugin, String taskName, Class taskType, Closure action) {
if (project.tasks.findByName(taskName)) { return }
def task = project.tasks.add(taskName, taskType)
Expand All @@ -191,9 +206,8 @@ class EclipseWtpPlugin extends IdePlugin {
}
}
}
//TODO SF - end

private void configureEclipseProjectWithType(Project project, Class<?> type) {
private void configureEclipseProjectForPlugin(Project project, Class<?> type) {
project.plugins.withType(type) {
project.tasks.withType(GenerateEclipseProject) {
projectModel.buildCommand 'org.eclipse.wst.common.project.facet.core.builder'
Expand Down

0 comments on commit 569a125

Please sign in to comment.