Hi,

I have working for some time with eclipseWtp support of gradle and
didn't find work smooth enuff in a multi project build.
I have 5 project to separate the different parts of my application. I
define project dependencies to link project so that
the project get linked in Eclipse. Only eclipseWtp doesn't work nice,
project dependencies are added as a dependended module
but the jars don't get deployed. A solution could be to define my
projects a normal dependencies but they I have to upload them
first to a local repository but I don't like that, I want to use the
jars that are generated in my project.
I was able to get this woking, I now can simply change some files in a
project, build it and then refresh the web project in Eclipse
and the new jar get deployed. I include my fix below. I am not a
Gradle expert so I guess there is lots of room to improve the code
and may contain bugs but for me atleast I works fine. Some parts of it
are based on code from
org.gradle.plugins.eclipse.model.internal.WtpFactory.

Evert

/*
 * Copyright 2010 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
 *
 *      http://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.
 */
eclipseWtp.withXml { files ->
       def xml = files.'org.eclipse.wst.commons.component'
       xml['wb-module'][0].appendNode('property', [name: 'context-root',
value: eclipseWtp.deployName])

       Iterator iterator = xml['wb-module'][0].iterator();

       while (iterator.hasNext()) {
               Node node = iterator.next()

               if (node.name() == 'dependent-module') {
                       iterator.remove()
               }
       }

       List runtimeDeps = new ArrayList();
       resolveDependencies(configurations['runtime'], runtimeDeps)

       List providedRuntime = new ArrayList();
       resolveDependencies(configurations['providedRuntime'], providedRuntime)

       List dependencies = runtimeDeps - providedRuntime

       dependencies.each{file ->
               Map variables = eclipseWtp.variables

               def usedVariableEntry = variables.find { name, value ->
                       file.canonicalPath.startsWith(new
File(value).canonicalPath)
               }

               String handleSnippet = null;
               if (usedVariableEntry) {
                       handleSnippet =
"var/$usedVariableEntry.key/${file.canonicalPath.substring(new
File(usedVariableEntry.value).canonicalPath.length())}"
               } else {
                       handleSnippet = "lib/${file.canonicalPath}"
               }

               xml['wb-module'][0].appendNode('dependent-module',
                       [ archiveName: file.name, 'deploy-path':
'/WEB-INF/lib', handle:
'module:/classpath/' + handleSnippet])
                          .appendNode('dependency-type', 'uses')
       }
}

void resolveDependencies(config, list) {

       config.allDependencies.each{dep ->
               if (dep instanceof ProjectDependency) {

                       dep.projectConfiguration.allArtifacts.each{art ->

//Prevent that source and javadoc jars get added
                               if ("".equals(art.classifier)) {
                                       if (!list.contains(art.file)) {
                                               list.add(art.file)
                                       }
                               }
                       }

                       resolveDependencies(dep.projectConfiguration, list)
               } else {
                       Set files = config.files(dep)

                       files.each{file ->
                               if (!list.contains(file)) {
                                       list.add(file)
                               }
                       }
               }
       }
}

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to