com.github.ksoichiro.eclipse.aar.generator.ParentClasspathFileGenerator.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-eclipse-aar-plugin Show documentation
Show all versions of gradle-eclipse-aar-plugin Show documentation
Gradle plugin to use Android AAR libraries on Eclipse
package com.github.ksoichiro.eclipse.aar.generator
import org.gradle.api.Project
class ParentClasspathFileGenerator extends MetaDataFileGenerator {
Project project
@Override
String generateContent(File file) {
String result
def classpathFile = file
// Use srcDirs definition for classpath entry
def androidSrcDirs = []
project.android?.sourceSets?.findAll { it.name in ['main', 'debug'] }?.each {
if (it.java?.srcDirs) {
it.java.srcDirs.each { srcDir ->
if (srcDir.exists()) {
androidSrcDirs << srcDir
}
}
}
}
if (0 == androidSrcDirs.size()) {
androidSrcDirs = ['src/main/java']
}
if (!androidSrcDirs.contains('gen')) {
androidSrcDirs << 'gen'
}
def androidSrcPaths = []
androidSrcDirs.each {
androidSrcPaths << (it.toString() - project.projectDir.path).replaceFirst("^[/\\\\]", '')
}
List srcPaths = []
if (classpathFile.exists()) {
// Aggregate src paths and dependencies
def classPaths = new XmlSlurper().parseText(classpathFile.text)
def srcPathEntries = classPaths.classpathentry?.findAll { it.@kind?.text() == 'src' }
srcPaths = srcPathEntries.collect { [email protected]() }
result = classpathFile.text
} else {
// Create minimum classpath file
srcPaths = androidSrcPaths
def srcPathEntries = androidSrcPaths.collect {
"""
|\t """.stripMargin()
}.join('')
result = """\
|
|${srcPathEntries}
|\t
|\t
|\t
|\t
|
|""".stripMargin()
}
androidSrcPaths = androidSrcPaths.findAll { srcPaths.find { path -> path == it } == null }
if (androidSrcPaths) {
def entriesToAdd = androidSrcPaths.collect { it -> "\t" }
def lines = result.readLines()?.findAll { it != '' }
lines += entriesToAdd
lines += "${System.getProperty('line.separator')}"
result = lines.join(System.getProperty('line.separator'))
}
result
}
}