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

Adding the capability to base the "exported" attribute of Eclipse classpath entries on what configuration(s) they came from #38

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bb7e8f6
Updated to gradle/master, added support for generating
dgileadi May 25, 2011
f740c1a
Removed some accidentally-committed files.
dgileadi May 25, 2011
4c0aa32
Removing accidentally-committed files.
dgileadi May 25, 2011
0587718
Merge github.com:dgileadi/gradle
dgileadi May 25, 2011
28c1786
Merge github.com:dgileadi/gradle
dgileadi May 31, 2011
2107da8
Added backwards-compatibility methods/constructors for WTP component
dgileadi May 31, 2011
27eb979
Merge branch 'master' of https://github.com/gradle/gradle
dgileadi Jun 3, 2011
b375eb4
Merge remote branch 'upstream/master'
dgileadi Jun 6, 2011
d9cd187
Merge remote branch 'upstream/master'
dgileadi Jun 9, 2011
d423c32
Merge https://github.com/gradle/gradle
dgileadi Jun 10, 2011
5daf472
Added ability to set the "exported" attribute on Eclipse classpath
dgileadi Jun 14, 2011
97da752
Merge https://github.com/gradle/gradle
dgileadi Jun 14, 2011
aca260e
Fixed calls to isExported.
dgileadi Jun 14, 2011
4028242
Fixed the ear plugin to not put <library-directory> into the generated
dgileadi Jun 16, 2011
dc367b7
Merge remote branch 'upstream/master'
dgileadi Jun 16, 2011
3a57c4c
Updated to use config names rather than configs for excluding.
dgileadi Jun 17, 2011
17cad3e
Merge remote branch 'upstream/master'
dgileadi Jun 17, 2011
1257547
Made the new property be 'noExportConfigNames' and refactored
dgileadi Jun 20, 2011
e37999d
Merge remote branch 'upstream/master'
dgileadi Jun 20, 2011
7b315ef
Removing skinnyDeploy changes.
dgileadi Jun 20, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class EclipsePlugin extends IdePlugin {

project.plugins.withType(JavaPlugin) {
classpath.plusConfigurations = [project.configurations.testRuntime]
classpath.noExportConfigNames += [project.configurations.testCompile.name, project.configurations.testRuntime.name]
classpath.conventionMapping.classFolders = {
def dirs = project.sourceSets.main.output.dirs + project.sourceSets.test.output.dirs
dirs.collect { project.relativePath(it)} .findAll { !it.contains('..') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ abstract class AbstractClasspathEntry implements ClasspathEntry {

AbstractClasspathEntry that = (AbstractClasspathEntry) o;

if (exported != that.exported) { return false }
if (accessRules != that.accessRules) { return false }
if (nativeLibraryLocation != that.nativeLibraryLocation) { return false }
if (path != that.path) { return false }
Expand All @@ -132,7 +131,6 @@ abstract class AbstractClasspathEntry implements ClasspathEntry {

result = path.hashCode();
result = 31 * result + (nativeLibraryLocation != null ? nativeLibraryLocation.hashCode() : 0);
result = 31 * result + (exported ? 1 : 0);
result = 31 * result + accessRules.hashCode();
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ abstract class AbstractLibrary extends AbstractClasspathEntry {

AbstractLibrary that = (AbstractLibrary) o;

if (exported != that.exported) { return false }
if (accessRules != that.accessRules) { return false }
if (javadocPath != that.javadocPath) { return false }
if (nativeLibraryLocation != that.nativeLibraryLocation) { return false }
Expand All @@ -67,7 +66,6 @@ abstract class AbstractLibrary extends AbstractClasspathEntry {

result = path.hashCode();
result = 31 * result + (nativeLibraryLocation != null ? nativeLibraryLocation.hashCode() : 0);
result = 31 * result + (exported ? 1 : 0);
result = 31 * result + accessRules.hashCode();
result = 31 * result + (sourcePath != null ? sourcePath.hashCode() : 0);
result = 31 * result + (javadocPath != null ? javadocPath.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import org.gradle.util.ConfigureUtil
* //you can also remove configurations from the classpath:
* minusConfigurations += configurations.someBoringConfig
*
* //you can make some classpath entries not be exported by Eclipse by choosing configuration names:
* noExportConfigNames += 'provided'
*
* //if you want to append extra containers:
* containers 'someFriendlyContainer', 'andYetAnotherContainer'
*
Expand Down Expand Up @@ -123,6 +126,17 @@ class EclipseClasspath {
*/
Collection<Configuration> minusConfigurations = []

/**
* The names of configurations whose classpath entries should not be exported to other Eclipse
* projects. By default this collection contains 'testCompile' and 'testRuntime'.
* <p>
* Note that if a class path entry comes from two or more configurations, any of which is
* exported, then the entry is exported.
* <p>
* For example see docs for {@link EclipseClasspath}
*/
Collection<String> noExportConfigNames = []

/**
* Containers to be added to the classpath
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class SourceFolder extends AbstractClasspathEntry {

SourceFolder that = (SourceFolder) o;

if (exported != that.exported) { return false }
if (accessRules != that.accessRules) { return false }
if (excludes != that.excludes) { return false }
if (includes != that.includes) { return false }
Expand All @@ -86,7 +85,6 @@ class SourceFolder extends AbstractClasspathEntry {

result = path.hashCode();
result = 31 * result + (nativeLibraryLocation != null ? nativeLibraryLocation.hashCode() : 0);
result = 31 * result + (exported ? 1 : 0);
result = 31 * result + accessRules.hashCode();
result = 31 * result + (output != null ? output.hashCode() : 0);
result = 31 * result + excludes.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ClasspathFactory {

protected List getModules(EclipseClasspath classpath) {
return getDependencies(classpath.plusConfigurations, classpath.minusConfigurations, { it instanceof org.gradle.api.artifacts.ProjectDependency })
.collect { projectDependency -> new ProjectDependencyBuilder().build(projectDependency.dependencyProject) }
.collect { projectDependency -> new ProjectDependencyBuilder().build(projectDependency.dependencyProject, isExported(projectDependency, classpath)) }
}

protected Set getLibraries(EclipseClasspath classpath) {
Expand All @@ -69,35 +69,35 @@ class ClasspathFactory {
}
Map javadocFiles = classpath.downloadJavadoc ? getFiles(classpath.project, javadocDependencies, "javadoc") : [:]

List moduleLibraries = resolveFiles(classpath.plusConfigurations, classpath.minusConfigurations).collect { File binaryFile ->
Set moduleLibraries = resolveFromFiles(classpath.plusConfigurations, classpath.minusConfigurations, { File binaryFile, Dependency dependency ->
File sourceFile = sourceFiles[binaryFile.name]
File javadocFile = javadocFiles[binaryFile.name]
createLibraryEntry(binaryFile, sourceFile, javadocFile, classpath.pathVariables)
}
createLibraryEntry(binaryFile, sourceFile, javadocFile, classpath.pathVariables, isExported(dependency, classpath))
})
moduleLibraries.addAll(getSelfResolvingFiles(getDependencies(classpath.plusConfigurations, classpath.minusConfigurations,
{ it instanceof SelfResolvingDependency && !(it instanceof org.gradle.api.artifacts.ProjectDependency)}), classpath.pathVariables))
{ it instanceof SelfResolvingDependency && !(it instanceof org.gradle.api.artifacts.ProjectDependency)}), classpath))
moduleLibraries
}

private getSelfResolvingFiles(Collection dependencies, Map<String, File> pathVariables) {
private getSelfResolvingFiles(Collection dependencies, EclipseClasspath classpath) {
dependencies.collect { SelfResolvingDependency dependency ->
dependency.resolve().collect { File file ->
createLibraryEntry(file, null, null, pathVariables)
createLibraryEntry(file, null, null, classpath.pathVariables, isExported(dependency, classpath))
}
}.flatten()
}

AbstractLibrary createLibraryEntry(File binary, File source, File javadoc, Map<String, File> pathVariables) {
AbstractLibrary createLibraryEntry(File binary, File source, File javadoc, Map<String, File> pathVariables, boolean exported) {
def usedVariableEntry = pathVariables.find { String name, File value -> binary.canonicalPath.startsWith(value.canonicalPath) }
if (usedVariableEntry) {
String name = usedVariableEntry.key
String value = usedVariableEntry.value.canonicalPath
String binaryPath = name + binary.canonicalPath.substring(value.length())
String sourcePath = source ? name + source.canonicalPath.substring(value.length()) : null
String javadocPath = javadoc ? name + javadoc.canonicalPath.substring(value.length()) : null
return new Variable(binaryPath, true, null, [] as Set, sourcePath, javadocPath)
return new Variable(binaryPath, exported, null, [] as Set, sourcePath, javadocPath)
}
new Library(binary.canonicalPath, true, null, [] as Set, source ? source.canonicalPath : null, javadoc ? javadoc.canonicalPath : null)
new Library(binary.canonicalPath, exported, null, [] as Set, source ? source.canonicalPath : null, javadoc ? javadoc.canonicalPath : null)
}

private Set<Dependency> getDependencies(Collection<Configuration> plusConfigurations, Collection<Configuration> minusConfigurations, Closure filter) {
Expand All @@ -122,17 +122,35 @@ class ClasspathFactory {
result
}

private Set<File> resolveFiles(Collection<Configuration> plusConfigurations, Collection<Configuration> minusConfigurations) {
private Set<AbstractLibrary> resolveFromFiles(Collection<Configuration> plusConfigurations, Collection<Configuration> minusConfigurations, Closure generator) {
def result = new LinkedHashSet()
def dependencies = getDependencies(plusConfigurations, minusConfigurations, { it instanceof ExternalDependency })
for (plusConfiguration in plusConfigurations) {
result.addAll(plusConfiguration.files { it instanceof ExternalDependency })
}
for (minusConfiguration in minusConfigurations) {
result.removeAll(minusConfiguration.files { it instanceof ExternalDependency })
for (dependency in dependencies) {
def files = plusConfiguration.files(dependency)
for (file in files) {
result.add(generator(file, dependency))
}
}
}
result
}

private boolean isExported(Dependency dependency, EclipseClasspath classpath) {
// a dependency is exported if it is introduced by an exported configuration
for (Configuration plusConfiguration : classpath.plusConfigurations) {
for (Configuration config : plusConfiguration.hierarchy) {
if (classpath.noExportConfigNames.contains(config.name)) {
continue
}
if (config.allDependencies.contains(dependency)) {
return true
}
}
}
false
}

private getFiles(org.gradle.api.Project project, Set dependencies, String classifier) {
return project.configurations.detachedConfiguration((dependencies as Dependency[])).files.inject([:]) { result, sourceFile ->
String key = sourceFile.name.replace("-${classifier}.jar", '.jar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import org.gradle.plugins.ide.eclipse.model.ProjectDependency
* @author Szczepan Faber, @date: 11.03.11
*/
class ProjectDependencyBuilder {
ProjectDependency build(Project project) {
ProjectDependency build(Project project, exported) {
def name
if (project.plugins.hasPlugin(EclipsePlugin)) {
name = project.eclipse.project.name
} else {
name = project.name
}
new ProjectDependency('/' + name, true, null, [] as Set, project.path)
new ProjectDependency('/' + name, exported, null, [] as Set, project.path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProjectDependencyBuilderTest extends Specification {

def "should create dependency using project name"() {
when:
def dependency = builder.build(project)
def dependency = builder.build(project, true)

then:
dependency.path == "/$project.name"
Expand All @@ -41,7 +41,7 @@ class ProjectDependencyBuilderTest extends Specification {
project.eclipse.project.name = 'foo'

when:
def dependency = builder.build(project)
def dependency = builder.build(project, true)

then:
dependency.path == '/foo'
Expand Down