Gitignore like file convention - java

I'm developing a script with (Groovy/Java) which compare two folders and generate a diff patch file in zip format. The thing now is i have to ignore some file within the iteration because they should not be included in the patch file.
Requirement:
Create a configuration file (like gitignore file) which list the path of ignored files in the comparison process.
The problem:
I like to stick at convention/codestyle guidelines but now i cannot find any reference on how should this be done (not the code, i know how to do it) in terms of:
the name, the extention and/or location of the file.
the codestyle, how files should be listed (maybe i should copy gitignore pattern).
Other things to consider.
I hope i've been clear and my question is within SO's topic scope.
Thanks in advance

1 and 2 are addressed in gitignore man page: the .gitignore file would be part of the source files you are scanning and would apply to files from the .gitignore folder and below.
It uses a glob pattern, like fnmatch does (meaning: no regexes).
If it was an actual git repo, git check-ignore -v -- afile could tell you if that file is ignored or not.

Related

Git: Comparing two files in two branches [duplicate]

Is it possible to open a file in a git branch without checking out that branch? How?
Essentially I want to be able to open a file in my github pages branch without switching branches all the time. I don't want to modify it, just want to view it.
This should work:
git show branch:file
Where branch can be any ref (branch, tag, HEAD, ...) and file is the full path of the file. To export it you could use
git show branch:file > exported_file
You should also look at VonC's answers to some related questions:
How to retrieve a single file from specific revision in Git?
How to get just one file from another branch
UPDATE 2015-01-19:
Nowadays you can use relative paths with git show a1b35:./file.txt.
git show somebranch:path/to/your/file
you can also do multiple files and have them concatenated:
git show branchA~10:fileA branchB^^:fileB
You do not have to provide the full path to the file, relative paths are acceptable e.g.:
git show branchA~10:../src/hello.c
If you want to get the file in the local directory (revert just one file) you can checkout:
git checkout somebranch^^^ -- path/to/file
A simple, newbie friendly way for looking into a file:
git gui browser <branch> which lets you explore the contents of any file.
It's also there in the File menu of git gui. Most other -more advanced- GUI wrappers (Qgit, Egit, etc..) offer browsing/opening files as well.
If you're using Emacs, you can type C-x v ~ or M-x vc-revision-other-window to see a different revision of the file you're currently editing (tags, branches and hashes all work).
Add the following to your ~/.gitconfig file
[alias]
cat = "!git show \"$1:$2\" #"
And then try this
git cat BRANCHNAME FILEPATH
Personally I prefer separate parameters without a colon. Why? This choice mirrors the parameters of the checkout command, which I tend to use rather frequently and I find it thus much easier to remember than the bizarro colon-separated parameter of the show command.

How to make class files into a JAR file

I have a JAR file that I wanted to edit a string inside on of it's classes . So I extracted it using Winrar , done the changes I wanted and saved it . Now I have a folder with subfolders inside that contains class files (about 30 one) .My question here is how can I recreate the Jar file from those folders&files ? Like it's it's doing the reverse action of extracting the Jar file .. ?
You could create a .zip file, rename it (with WinRAR) to something.jar so it becomes a .jar archive and then copy the folders in there.
But what you are doing is not really recommended to be done
You shouldn't extract and re-archive it like that.
And DON'T I repeat DON'T edit .class files!
Jar file is basically a zip file - however the best way to edit jars is to use a file manager (like Total Commander). You can delete, copy, rename, ... whatever, transparently inside the archive.
http://en.wikipedia.org/wiki/JAR_%28file_format%29
May be only one tip for the Total Commander - to enter the archive just use Ctrl-Pagedown. And I don't think that is something wrong on jar editing (in some circumstances you have no other option). However class files editing... it is a different game ...

Maven-war-plugin - remove files

I am developing maven plagin that obfuscates js files. It does the following -:
takes *.js files from target,
obfuscates them using google closure,
creates *.min.js files in target,
if it's necessary removes sources (unobfuscated files) from target.
In order to get point between package phase and prepare-package phase I use the following solution: https://stackoverflow.com/a/27566620/2022068
Everything is ok. Plugin is ready. However I have the following problem - if I remove source file, maven-war-plugin copies it again. Maybe it has some mechanism of checking - I don't know. The only thing that I can do now is to delete and create empty file. Than the source file exists but it's empty.
My qeustion - can I somehow remove files from target finally, forever...?
You probably need to teach this to the maven-war-plugin. I have no example that does the same thing but there are packageExcludes (see: http://maven.apache.org/plugins/maven-war-plugin/examples/including-excluding-files-from-war.html) which seems not exactly what you need but also warSourceExcludes: http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#warSourceExcludes
The war plugin has its own mechanism of copying files (aside from the resources plugin). That may be the issue here. There are some examples on filtering as well: http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
Maybe treating the files you don't want to see as excludes will work (if warSourceExcludes is something different than what you plan to do).

Use Ruby to copy files into an jar file

my problem is that I want to add some .class files from a normal directory into an .jar file. Do I have to extract it before or can I add the files "on the fly"?
Although I agree with Jordan and suggest using the system command, that was not an option for the team I work on.
If you have to use his second solution, it is extremely important to note that Zip::ZipOutputStream will override any existing jars; i.e., you won't be adding to an existing jar, you will be creating a new one. This code will add a file to an existing jar:
require 'zip/zip'
Zip::ZipFile::open 'path/to/jar' do |jar|
jar.add 'filename_in_jar', 'path/to/file/you/want/to/add'
end
If it was me I would almost certainly just call the jar command within Ruby to do this:
system 'jar uf jar_file.jar input_file(s).class'
# or
%x[ 'jar uf jar_file.jar input_file(s).class' ]
Reference here.
If you still want to do this without calling jar you should be able to do it with rubyzip, since JAR files are just ZIP files with a particular structure. Something like this:
require 'zip/zip'
filename = 'class_file.class'
Zip::ZipOutputStream::open "jar_file.jar" do |zip|
zip.put_next_entry 'dest/path/in/jar/' + filename # don't forget the path
File.open filename, 'rb' {|f| zip.write f.read }
end
There are also a few Ruby wrappers for libarchive that could do this. E.g.

what are those files with "~" in java projects?

I've never seen that,internally generated?How does it work?
Can check what I meen here:
http://issues.apache.org/jira/secure/attachment/12401970/nutch_0.9_OR.patch
search "java~"
and you can see "java.old" there,what's that again?
It's probably some cruft leftover from emacs. With emacs, whenever you save a file, it saves a backup of the previous version of the file, and the backup is named with the original filename with a tilde appended to it. If this is the case (which you can easily verify by comparing file with file~), then you can safely ignore all of the files named with tildes.
Are you sure its generated from some java process? ~ in files typically means a temporary file created by editors, such as vim when you modify something.

Categories

Resources