Buildr - exclude directory from resources - buildr

In Buildr you can exclude all files in a directory by doing the following:
resources.exclude 'scratch/*'
Is it possible to exclude the directory as well? The Buildr documentation mentions:
The filter always excludes the CVS and .svn directories, and all files
ending with .bak or ~, so no need to worry about these.
My company uses Dimensions as its source control, it creates a .metadata folder in every directory much like subversion does with the .svn folder.

These exclusions are actually inherited from Rake (rake/file_list.rb)
module Rake
...
class FileList
...
DEFAULT_IGNORE_PATTERNS = [
/(^|[\/\\])CVS([\/\\]|$)/,
/(^|[\/\\])\.svn([\/\\]|$)/,
/\.bak$/,
/~$/
]
...
end
end
so it's possible to monkey-patch the defaults, if that's what you want.
Alternatively, you can also add exclusions directly on a FileList by passing a block and calling the exclude method,
pkg_files = FileList.new('lib/**/*') do |fl|
fl.exclude(/\bCVS\b/)
end
Since Buildr filters (http://buildr.apache.org/rdoc/classes/Buildr/Filter.html) expose their underlying FileList, you can simply do:
resources.sources do |fl|
fl.exclude(/\.metadata/)
end

Related

SonarQube: Ignore files in current (root) directory

The documentation of the project, instructs on how to e.g. exclude (or include) in an analysis process, say all files under a directory:
mydir/**/*
or all files with a specific extension (say .js) under a directory:
mydir/**/*.js
But what is the way to exclude all *.js files in the current (the root) directory.
I have tried the following patterns. do not seem to work:
sonar.coverage.exclusions=./*.js
sonar.coverage.exclusions=*.js
The multi-directory pattern, **, can be used at any point in the regex.
To exclude all .js files, you would use: **/*.js
To exclude .js files only in the current directory: *.js
However
You should not try to set these values in your analysis properties. Doing so correctly is tricky. Use the UI to set these values instead.

rake - how does the "directory" keyword work?

It's been stated in several places that "directory" keyword can be used as a shorthand. Apparently, it can be indicated as a dependency, so that it will be created if not already present.
http://onestepback.org/articles/buildingwithrake/directorydependencies.html
The idea is to specify destination directory as a dependency, not to attempt to create it manually each time, which can be achieved by using mkdir_p. Downside of using mkdir_p is that it displays output regardless of whether the directory was already present. An alternative solution is to silence this command -- and even better if the output is displayed only when the directory is created.
I've tried using "directory" keyword as follows:
file "destFile" => ["srcFile", directory "myOutputDir"] do
FileUtils.cp "srcFile" "myOutputDir/destFile"
end
file "destFile" => ["srcFile"] + [directory "myOutputDir"] do
FileUtils.cp "srcFile" "myOutputDir/destFile"
end
file "destFile" => ["srcFile"] do
directory "myOutputDir"
FileUtils.cp "srcFile" "myOutputDir/destFile"
end
How about this:
directory "myOutputDir"
file "myOutputDir/destFile" => ["srcFile", "myOutputDir"] do
FileUtils.cp "srcFile" "myOutputDir/destFile"
end
I believe it's supposed to be used as a separate task and specified as a dependency like any other task. It's basically the same as specifying a file task that runs mkdir, but the action is implicit. The syntax is otherwise the same.
directory will also make all layers of subdirectories like so: http://onestepback.org/articles/buildingwithrake/directorydependencies.html

How do I write an Albacore zip task that includes only certain folders and the folders themselves?

I'm trying to zip up the artifacts of a rake build, using Albacore's ZipTask. The solution I'm building has three projects that have artifacts that need to be zipped up individually, but only the ASP.NET MVC project will be mentioned here. Here's the directory structure of the solution:
rakefile.rb
solution.sln
src/
(other projects that are not relevant)
website/
(various folders I don't want included in the artifacts)
bin/
Content/
Scripts/
Views/
Default.aspx
Global.asax
web.config
At first I wrote this task:
website_directory = File.join '.', 'src', 'website'
website_project_name = 'website'
zip :zip => [ :run_unit_tests, :less ] do |zip|
zip.directories_to_zip = [ 'bin', 'Content', 'Scripts', 'Views' ].map{ |folder| File.join website_directory, folder }
zip.additional_files = [ 'Default.aspx', 'favicon.ico', 'Global.asax', 'web.config'].map{ |file| File.join website_directory, file }
zip.output_file = get_output_file_name
zip.output_path = get_artifacts_output_path website_project_name
end
Problem is, the output of this task is a zip file containing the contents of those folders, not the folders themselves, which is obviously undesirable.
Next, I tried flipping the flatten_zip field to false (which is not a documented field but you can find it in the source). This produced a zip that contained the above folders, but at the bottom of the whole ./src/website/ folder hierarchy. I want the above folders at the root of the zip, so that's not working either.
So my next shot was this, using exclusions, which is also not documented:
zip :zip => [ :run_unit_tests, :less ] do |zip|
zip.directories_to_zip website_directory
zip.exclusions = [ /.git/, /.+\.cs/, /App_Data/, /Attributes/, /AutoMapper/, /Controllers/, /Diagrams/, /Extensions/, /Filters/, /Helpers/, /Models/, /obj/, /Properties/, /StructureMap/, /Templates/, /CompTracker.Web.csproj/, /Default.aspx.cs/, /Global.asax.cs/, /Publish.xml/, /pdb/ ]
zip.output_file = get_output_file_name
zip.output_path = get_artifacts_output_path website_project_name
end
This worked for me, but when I recently added /AutoMapper/ and /StructureMap/ to the exclusions array, it also caused AutoMapper.dll and StructureMap.dll to (of course) also be excluded from the bin folder.
How should I edit any of the above tasks to have only the folders and files I want at the root of my zip?
You can copy all the files and folders you need into a temp directory and then zip that up. In other words, set the property directories_to_zip to one folder which has all the correct files already copied in - where the copying code is what does all the filtering for you. I think that's the unspecified expected usage (and the way I use it). I'll just contrast the two ideas to make it clear.
Strategy A: Copy the folder structure
Copy what you need into a temp directory. This way, you set the 'directories_to_zip' property to one folder eg:
directories_to_zip = 'ziptemp/all.my.stuff.copied.here/'
Strategy B: Use a filter
(This is your current strategy)
Use the directories_to_zip property as a filter on an original directory (it is an array that takes multiple directories, so you couldn't be blamed for assuming it should work this way). You then use various properties to filter the files/folders you need.
Possible Resolution
To solve your issue, then, you could adopt Strategy A. Actually, unless there's any extraordinary issues with this (slow PC, amazingly low on disk space), I would have thought this would be a slightly more robust way of going about it because you can be sure that what you are zipping is exactly what you are copying, which can be verified by checking the ziptemp directory.
Incidentally, I can be sure Strategy A works because I use it (with Albacore) to zip files for our installers.
I had the same problem using 'albacore', I wanted to zip a folder called 'tools' (not just the contents), store it in a folder called 'out' and name the zip 'tools.zip ... so instead I used this;
require 'zip/zipfilesystem'
Zip::ZipFile::open("out/tools.zip", Zip::ZipFile::CREATE) { |z|
Dir['{tools}/**/*'].each { |f|
z.add(f, f)
}
}
I know its late but I hope this helps someone.

Directory dependencies with rake

I'm using rake to copy a directory as so:
file copied_directory => original_directory do
#copy directory
end
This works fine, except when something inside of original_directory changes. The problem is that the mod date doesn't change on the enclosing directory, so rake doesn't know to copy the directory again. Is there any way to handle this? Unfortunately my current setup does not allow me to set up individual dependencies for each individual file inside of original_directory.
You could use rsync to keep the 2 directories in sync as shown here: http://asciicasts.com/episodes/149-rails-engines
You don't need to know the files to depend on them:
file copied_directory => FileList[original_directory, original_directory + "/**/*"]

RubyZip - files from different directories have path in zip

I'm trying to use RubyZip to package up some files. At the moment I have a method which happily zips on particular directory and sub-directories.
def zip_directory(zipfile)
Dir["#{#directory_to_zip}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path.sub(#directory_to_zip+'/','');
zipfile.add(file_name, file_path)
end
end
However, I want to include a file from a completely different folder. I have a the following method to solve this:
def zip_additional(zipfile)
additional_files.reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path.split('\\').last
zipfile.add(file_name, file_path)
end
end
While the file is added, it also copies the directory structure instead of placing the file at the root of the folder. This is really annoying and makes it more difficult to work with.
How can I get around this?
Thanks
Ben
there is setting to include (or exclude) the full path for zip libraries, check that setting
Turns out it was because the filename had the pull path in. My split didn't work as the path used a / instead of a . With the path removed from the filename it just worked.

Resources