Skip to content

Commit

Permalink
Copying to target folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mendhak committed May 3, 2015
1 parent a7d13cb commit 81613a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
1 change: 0 additions & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repositories {
}

dependencies {
//compile 'net.lingala.zip4j:zip4j:1.3.2'
compile gradleApi()
compile localGroovy()
testCompile 'junit:junit:4.11'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mendhak.gradlecrowdin

import groovy.io.FileType
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

Expand All @@ -12,16 +13,12 @@ class DownloadTranslationsTask extends DefaultTask {
def apiKey
def projectId

File getDestination() {
project.file(destination)
}

@TaskAction
def downloadTranslations() {

// println(apiKey)
// println(projectId)
println(destination)
// println(destination)

def buildSubDir = new File(project.buildDir.getPath() , "/crowdin-plugin")
buildSubDir.mkdirs()
Expand All @@ -37,7 +34,22 @@ class DownloadTranslationsTask extends DefaultTask {
file << new URL(url).openStream()
file.close()

unzipFile(translationZip, buildSubDir)
//Extract to build dir/res
unzipFile(translationZip, new File(buildSubDir, "res"))

def list = []
def extractedDir = new File(buildSubDir, "res")
extractedDir.eachFileRecurse (FileType.FILES) { f ->
list << f
}

//Copy to values-XYZ in the destination folder
list.each {
def copyTo = new File(destination, "values-"+ it.getParentFile().getName() + "/" + it.getName() )
println copyTo.getPath()
new AntBuilder().copy( file:it.getPath(),
tofile:copyTo.getPath())
}
}

def unzipFile(File zipFile, File outputFolder){
Expand All @@ -57,7 +69,7 @@ class DownloadTranslationsTask extends DefaultTask {
String fileName = ze.getName();
File newFile = new File(outputFolder, fileName);

println("Extracting : "+ newFile.getAbsoluteFile());
//println("Extracting : "+ newFile.getAbsoluteFile());

if(ze.isDirectory()){
newFile.mkdirs()
Expand Down

0 comments on commit 81613a5

Please sign in to comment.