As my application grows I have to add new directories for CppCheck to check. Why is my CppCheck able to find all files in subdirectories for the src/ folder but not for the include folder? I have to add each include folder manually.
stage('CppCheck') {
steps {
dir("${env.WORKSPACE}/${FOLDERS_TO_SCAN}"){
sh label: '', returnStatus: true, script: 'cppcheck --check-config --inline-suppr -itest/ -Iinclude/utilities -Iinclude/ src/ cppcheck --enable=all --suppress=missingIncludeSystem . --inconclusive --xml --xml-version=2 graphal 2> cppcheck-result.xml'
}
}
}
Related
I have a huge maven project, lot of people are using it. I'm currently working on converting it to gradle. One of the last steps will be that I merge the gradle files, and delete the pom.xml files. But I'd like to add a gradle task to clean the maven target directories (of all the sub-projects). In shell I would do something like:
find . -type d -name target -exec rm -rf "{}" \;
But I prefer this to be a gradle task. How do I add it? This is what I tried but it doesn't delete anything:
task cleanMaven(type: Delete) {
delete fileTree('.').matching { include '**/target/**' }
}
below will handle all modules of root project and prints true if a target dir existed and is deleted
allprojects {
task mvnClean {
doFirst {
def targetPath = project.projectDir.toString() + '/target'
println "target dir exists: ${Files.deleteIfExists(Paths.get(targetPath))}"
}
}
}
Based on #PrasadU's answer, but this also deletes all the contents of the target/ directories:
allprojects {
task mvnClean {
doFirst {
def targetPath = project.projectDir.toString() + '/target'
project.delete(files("${targetPath}"))
}
}
}
I have a folder with a lot of projects inside it (too much to manually write build files for them)
The projects are mostly in a flat layout:
root
-project 1
-project 2
-project 3
-project 4
-project 5
( -project 5.1)
But can be nested as shown above, and I need to account for this.
Ideally the following should happen:
I can run user#user:/root gradle build and every project in the directory shoudl be built as long as it contains a gradle build file
if a build fails just continue with the next one
How can I make this possible ?
How about this one-liner (not tested):
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && gradle build || true" \;
Or, more verbose:
dirs=($(find . -type d))
for dir in "${dirs[#]}"; do
cd "$dir"
gradle build || true
done
I came up with a working solution:
def flist = []
// change to you workspace name
new File('./Workspace').eachDir {
//blacklist any folders you want
if (it.name !='.gradle' && it.name != 'master' && it.name!= 'Build-All') {
flist << it.name
}
}
// build task objects
flist.each { folder ->
task "${folder}"(type: GradleBuild) {
buildFile = "./Workspace/"+ folder + "/build.gradle"
dir = './' + folder
tasks = ['build']
}
}
// create super task
task (all, dependsOn: flist) {
}
You need to invoke it as such in the root directory: gradle :all --continue this has the benefit that any failing project builds will not halt the other builds.
Another bonus is that gradle gives a neat report about all failing builds.
I want to create a task that will zip up all the files in a directory, ignoring all subdirectories. At the same time, I want to iterate through all the subdirectories and create zips that include the files in those directories (and ignoring any further subdirectories).
Thus, for this directory structure, I want the following zips:
$ls build/dirA
fileA
dirB
$ls build/dirA/dirB
fileB
I should get zip/zipA containing fileA, zip/zipB containing fileB.
I am using code based on the answer here: gradle task to zip multiple directories independently Essentially, I create a zip task for each zip artifact to be created, with a dependency on the top level task.
task myZip() {
file('build').eachDir { dir ->
dir.eachDir { sub ->
dependsOn tasks.create("zip$sub.name", Zip) {
from sub
baseName sub.name
destinationDir file('zip')
}
}
dependsOn tasks.create("zip$dir.name", Zip) {
from dir
baseName dir.name
excludes ['*/**']
destinationDir file('zip')
}
}
}
The problem seems to be in the exclude pattern. I get the correct zips for the sub directories, but the parent directory includes fileA and dirB/fileB.
What is the correct way to do this please?
*Note I have not put an exclude for the iteration through the subdirectories, as I figure this pattern needs to be the same as for the parent directory, which I haven't figured out yet.
You can try below script, it would resolve your issue:
import static groovy.io.FileType.DIRECTORIES
task myZip {
file('folder').traverse(type: DIRECTORIES) {
def path = it.path
def zipFile = it.name + '.zip'
ant.zip(destfile: zipFile){
fileset(dir: path) {
include (name: "*")
type (type: "file")
}
}
}
doLast {
copy {
from "."
include "*.zip"
into file("zip")
}
}
}
Here is some example test:
$ tree folder
folder
└── dirA
├── dirB
│ ├── dirC
│ │ ├── dirD
│ │ └── fileC
│ └── fileB
└── fileA
4 directories, 3 files
And it generate the three zip files into zip folder as well as root folder.
$ ls -1 zip/
dirA.zip
dirB.zip
dirC.zip
I just observed a very weird behaviour from a Gradle Tar task.
Let's take a simple example, 2 files :
/tmp/test$ ls
test1.txt ##test2##
Here is a simple Tar task :
task('testHash', type: Tar) {
from "/tmp/test"
extension = 'tar.gz'
compression = Compression.GZIP
}
The file ##test2## is skipped for some reason, after running gradle testHash :
/path/to/gradle/project/foo$ tar tvf build/distributions/foo-1.0.tar.gz
test1.txt
It seems to happen when the filename is containing # character both at the beginning and the end.
A regular tar is working well :
/tmp/test$ tar czvf test.tar.gz *
test1.txt
##test2##
/tmp/test$ tar tf test.tar.gz
test1.txt
##test2##
I am using Gradle 4.1. Any explanation ?
Thanks to Opal's comments, I adjusted my searches and found a workaround. There is maybe a cleaner way but this one works for me
task('testHash', type: Tar) {
doFirst {
org.apache.tools.ant.DirectoryScanner.defaultExcludes.each {
DirectoryScanner.removeDefaultExclude it
}
}
from "/tmp/test"
extension = 'tar.gz'
compression = Compression.GZIP
}
FYI, here are default excludes
There are a set of definitions that are excluded by default from all
directory-based tasks. As of Ant 1.8.1 they are:
**/*~
**/#*#
**/.#*
**/%*%
**/._*
**/CVS
**/CVS/**
**/.cvsignore
**/SCCS
**/SCCS/**
**/vssver.scc
**/.svn
**/.svn/**
**/.DS_Store
Ant 1.8.2 adds the following default excludes:
**/.git
**/.git/**
**/.gitattributes
**/.gitignore
**/.gitmodules
**/.hg
**/.hg/**
**/.hgignore
**/.hgsub
**/.hgsubstate
**/.hgtags
**/.bzr
**/.bzr/**
**/.bzrignore
I have a directory structure like this:
file1.txt
file2.txt
dir1/
file3.txt
file4.txt
I want to use Gradle to copy that entire structure into another directory. I tried this:
task mytest << {
copy {
from "file1.txt"
from "file2.txt"
from "dir1"
into "mytest"
}
}
But this results in the following:
mytest/
file1.txt
file2.txt
file3.txt
file4.txt
See, the copy from dir1 copied the files in dir1, whereas I want to copy dir1 itself.
Is it possible to do this directly with Gradle copy?
So far, I have only been able to come up with this solution:
task mytest << {
copy {
from "file1.txt"
from "file2.txt"
into "mytest"
}
copy {
from "dir1"
into "mytest/dir1"
}
}
For my simple example there's not much to it, but in my actual case there are many directories I want to copy, and I'd like to not have to repeat so much.
You can use . as the directory path and include to specify, which files and directories you want to copy:
copy {
from '.'
into 'mytest'
include 'file*.txt'
include 'dir1/**'
}
If both from and into are directories, you'll end up with the full copy of the source directory in the destination directory.
I know this is a bit late, but I tried #Andrew solution above and it copied everything inside the directory.
"." is not required nowadays to represent a direct in gradle.
So I did some research
and found this
and created the following code (with Up-to-date check) based on it:
task resourcesCopy() {
doLast {
copy {
from "src/main/resources"
into "./target/dist/WEB-INF/classes"
}
copy {
from "GeoIP2.conf"
into "./target/dist/WEB-INF"
}
}
}
I don't know how long this syntax has been around, but it seems a little clearer.
task copyToRelease(dependsOn: [deletePreviousRelease], type: Copy) {
from('build/dist') {
include '**/*.*'
}
destinationDir(new File('../htmlrelease/src/main/webapp/canvas'))
}
Maybe also helpful: Usage of fileTree to copy an entire directory recursively, e.g.,
task mytest << {
copy {
from fileTree('.')
into "mytest"
}
}