Skip to content

Commit

Permalink
Hotfix for aemCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian.panek committed Aug 29, 2017
1 parent 56bcb27 commit ce262d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class CollectTask : Zip() {

@get:Internal
val satisfiedPackages: List<File>
get() = satisfy.packageProvider.allFiles(satisfy.groupFilter, false)
get() = satisfy.packageProvider.outputDirs(satisfy.groupFilter)

@get:Internal
val builtPackages: List<File>
Expand All @@ -52,7 +52,7 @@ open class CollectTask : Zip() {
}

private fun resolvePackages() {
satisfy.packageProvider.allFiles(satisfy.groupFilter, true)
satisfy.packageProvider.allFiles(satisfy.groupFilter)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cognifide.gradle.aem.internal.file

import com.cognifide.gradle.aem.AemException
import com.cognifide.gradle.aem.internal.Formats
import com.google.common.hash.HashCode
import groovy.lang.Closure
Expand All @@ -24,8 +23,10 @@ class FileResolver(val project: Project, val downloadDir: File) {
val DOWNLOAD_LOCK = "download.lock"
}

private inner class Resolver(val id: String, val group: String, val action: (Resolver) -> Unit) {
private inner class Resolver(val id: String, val group: String, val action: (Resolver) -> File) {
val dir = File("$downloadDir/$id")

val file: File by lazy { action(this) }
}

private val resolvers = mutableListOf<Resolver>()
Expand All @@ -50,30 +51,22 @@ class FileResolver(val project: Project, val downloadDir: File) {
}
}

fun allFiles(filter: (String) -> Boolean = { true }, resolve: Boolean = true): List<File> {
return resolveFiles(filter, resolve).map { it.dir }
fun outputDirs(filter: (String) -> Boolean = { true }): List<File> {
return filterResolvers(filter).map { it.dir }
}

fun groupedFiles(filter: (String) -> Boolean = { true }, resolve: Boolean = true): Map<String, List<File>> {
return resolveFiles(filter, resolve).fold(mutableMapOf<String, MutableList<File>>(), { files, resolver ->
files.getOrPut(resolver.group, { mutableListOf() }).add(resolver.dir); files
})
fun allFiles(filter: (String) -> Boolean = { true }): List<File> {
return filterResolvers(filter).map { it.file }
}

private fun resolveFiles(filter: (String) -> Boolean, resolve: Boolean): List<Resolver> {
val resolvers = resolvers.filter { filter(it.group) }
if (resolve) {
resolvers.onEach(this::resolveFile)
}

return resolvers
fun groupedFiles(filter: (String) -> Boolean = { true }): Map<String, List<File>> {
return filterResolvers(filter).fold(mutableMapOf<String, MutableList<File>>(), { files, resolver ->
files.getOrPut(resolver.group, { mutableListOf() }).add(resolver.file); files
})
}

private fun resolveFile(resolver: Resolver) {
resolver.action(resolver)
if (FileOperations.isDirEmpty(resolver.dir)) {
throw AemException("Cannot resolve file(s) from group '${resolver.group}' to path: ${resolver.dir}")
}
private fun filterResolvers(filter: (String) -> Boolean): List<Resolver> {
return resolvers.filter { filter(it.group) }
}

fun url(url: String) {
Expand Down Expand Up @@ -187,10 +180,10 @@ class FileResolver(val project: Project, val downloadDir: File) {
}

fun local(sourceFile: File) {
resolve(sourceFile.absolutePath, { })
resolve(sourceFile.absolutePath, { sourceFile })
}

private fun resolve(hash: Any, resolver: (Resolver) -> Unit) {
private fun resolve(hash: Any, resolver: (Resolver) -> File) {
val id = HashCode.fromInt(HashCodeBuilder().append(hash).toHashCode()).toString()
resolvers += Resolver(id, group, resolver)
}
Expand Down

0 comments on commit ce262d6

Please sign in to comment.