I know that when using Ant from Groovy, you can do something like the following to copy files:
copy(todir:myDir) {
fileset(dir:"src/test") {
include(name:"**/*.groovy")
}
}
Is there a more efficient, and elegant way to copy a single file?
How about:
new AntBuilder().copy( file:"$sourceFile.canonicalPath",
tofile:"$destFile.canonicalPath")
Related
I have this case. I need to grep a file for some RegEx and the result string (or array of strings) I need to save to variable for later use. And this has to be achieved using Gulp.
It should look like this in my idea:
var line;
gulp.task('grep', function(callback) {
line = someCoolSyncFunction('/needle/', './haystack.txt');
callback();
});
gulp.task('useIt', ['grep'], function() {
console.log(line);
});
Important is this someCoolSyncFunction to be synchronous and to handle file on physical/virtual file system, not the Vinyl file.
Is there a way to do this using Gulp? Or any other approach to achieve similar effect?
PS: to explain the reason, I need to extract version number from Debian package changelog and insert it to configuration file inside the package during the build process.
Thanks a lot.
Vit
I'm presently making a build flow using DSL.
After searching for I while I've been able to find how to read from a text file, but not how to write to one.
Is there a command for it in DSL?
And also I'd take the opportunity to ask where I can find a tutorial or command list for DSL?
Since the DSL is Groovy based I guess you can write any Groovy code and it should work, refer http://grails.asia/groovy-file-examples to get an example of how to write to a file. The DSL commands are provided at https://jenkinsci.github.io/job-dsl-plugin/ and you can try them out at the playground at http://job-dsl.herokuapp.com/.
By default, you cannot use new File(...).text for security reasons. You can use writefile instead:
writeFile file: "myfile.txt", text: "File content."
This is the best I've been able to come up with, it uses writeFile:
def readEscape(String file) {
return readFileFromWorkspace(file).replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r").replace("\$", '\\$')
}
def Dockerfile = readEscape('./Dockerfile')
pipelineJob('sample-write-file') {
definition {
cps {
script('''
pipeline {
agent any
stages {
stage("prep-files") {
steps {
writeFile file: './Dockerfile', text: "''' + Dockerfile + '''"
}
}
}
}
''')
}
}
}
The question is unclear about whether the file needs to be written during the processing of the job dsl or during the generated job's execution. Since I needed this for the job execution, that is what my example shows. The file will be read while creating the job and embedded in the created job definition.
I am trying to add a post-build step which runs an executable on the project after it compiles. To do this, the compiler needs to know if it an .exe or a .dll before hand. How can I find the extension of a project (or premake 'kind') during the premake step? I am using premake 4.3 and visual studio 2010. Thanks!
In Premake4 there is no great way to do that. Your best bet will probably be duplicating the commands with configuration filters.
configuration { "ConsoleApp or WindowedApp" }
postbuildcommands { "thecmd --kind=exe" }
configuration { "StaticLib or SharedLib" }
postbuildcommands { "thecmd --kind=lib" }
In Premake5 you could use tokens.
postbuildcommands {
"thecmd --kind=%{iif(cfg.kind:endswith("App"), "exe", "lib")}"
}
I have multiple bindings(xjb files) in the gradle project. When generating JAXB classes for a xsd(C.xsd). I want to use the previously generated binding files for A.xjb & B.xjb since C.xsd refers to A.xsd & B.xsd
The below ant xjc task works if I don't have anyother bindings in same path but I want specify explicity A.xjb & B.xjb bindings. How to go about same, I tried various options but nothing seems working. Any help greatly appreciated.
ant.xjc(destdir : '${jaxbDest}', removeOldOutput:'yes', extension:'true') {
arg(line:'-Xequals -XhashCode -XtoString -Xcopyable')
schema(dir:'src/main/schema', includes:'C.xsd')
binding(dir:'src/main/schema', includes:'*.xjb)
}
Thanks
Ravi
According to this documentation for the ant xjc task -
"To specify more than one external binding file at the same time, use a nested element, which has the same syntax as fileset."
In gradle it would look like this:
binding(dir:'src/main/schema'){
include(name:'A.xjb')
include(name:'B.xjb')
}
I think this would also work:
binding(dir:'src/main/schema', includes:'A.xjb,B.xjb')
I am trying to zip files and directories in Groovy using AntBuilder. I have the following code:
def ant = new AntBuilder()
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:file.name)
This zips the file "blah.txt", but not the file "New Text Document.txt". I think the issue is the spaces. I've tried the following:
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"${file.name}")
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"\"${file.name}\"")
Neither of the above resolved the issue. I'm using Ant because it will zip directories, and I don't have access to org.apache.commons.io.compression at work.
If you look at the docs for the ant zip task, the includes parameter is described as:
comma- or space-separated list of patterns of files that must be included
So you're right, that it is the space separator that's breaking it...
You need to use the longer route to get this to work:
new AntBuilder().zip( destFile: "${file}.zip" ) {
fileset( dir: './Testing' ) {
include( name:file.name )
}
}