Created
August 17, 2016 15:34
-
-
Save Buggaboo/ca1bd465cd703a4b8fca239b0fcbd950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IosFrameworkSymlinkTask extends DefaultTask | |
{ | |
val log = LoggerFactory.getLogger(getClass) | |
static val runtime = Runtime.runtime | |
static def void symlinkFramework(String location, String name) | |
{ | |
var fileContent = ''' | |
#!/bin/sh | |
/bin/ln -sfh Versions/Current/Headers Headers | |
/bin/ln -sfh Versions/Current/«name» «name» | |
cd Versions ; /bin/ln -sfh A Current | |
''' | |
new File('''«location»/symlink.sh''').writeContentToFile(fileContent) | |
var p = runtime.exec('''/bin/chmod +x «location»/symlink.sh''') | |
p.waitFor | |
/* | |
p = runtime.exec("/bin/sh -c 'cd «location» ; ./symlink.sh'") | |
p.waitFor | |
*/ | |
p = runtime.exec("./symlink.sh", null, new File(location)) | |
p.waitFor | |
} | |
static def File writeContentToFile(File file, String content) | |
{ | |
try { | |
// if file doesnt exists, then create it | |
if (!file.exists) { | |
file.createNewFile | |
} | |
val fw = new FileWriter(file.getAbsoluteFile) | |
val bw = new BufferedWriter(fw) | |
bw.write(content) | |
bw.close | |
} catch (IOException e) { | |
e.printStackTrace | |
} | |
return file | |
} | |
@TaskAction | |
def void symlink() | |
{ | |
var ext = project.extensions.findByType(SymlinkExtension) | |
var name = ext.frameworkName | |
var debugLoc = ext.debugLocation | |
var releaseLoc = ext.releaseLocation | |
debugLoc.symlinkFramework(name) | |
releaseLoc.symlinkFramework(name) | |
} | |
} | |
class SymlinkExtension | |
{ | |
@Accessors | |
var String frameworkName | |
@Accessors | |
var String debugLocation | |
@Accessors | |
var String releaseLocation | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment