2014-04-21 Tweets

Gradle and the Groovy Shell

I wrote before that I prefer the groovy shell to the Groovy console. I found a way to print the classpath with Gradle to make a script to run code in your Gradle project from the Groovy shell. It was kind of cumbersome.

There is still no out-of-the-box way to run the Groovy shell from a Gradle project. The way I came up with was a bit cumbersome. I have found another way that might be a bit easier.

Gradle has a built-in application plugin. You tell it the name of your main class. For the purposes of this technique, you can pretty much put in anything you want; we really won’t be using it.

Then you run

gradle distZip

This will create a zip file in build/distributions. Unzip this file, and go into the bin/ directory. There you will find a shell script for your application. Copy it to another file.

Find the line for the classpath, and take out the groovy-all jar file. Then down at the bottom, change the line with the command. It will look something like this:

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH"  org.codehaus.groovy.tools.shell.Main "$@"

Change that line to this:

exec groovysh "${JVM_OPTS[@]}" -classpath "$CLASSPATH"

You need to take the groovy-all jar file out of the classpath since we are going to run groovysh. If there are two groovy-all jar files on the classpath, there will be problems.

Then take this file, and put it in src/dist/bin. If you put it there, then every time you run distZip, then the shell script you created will show up in the bin/ directory of the zip file.

There is a groovy-groovysh archive in the central Maven repository. I tried that, but then when I tried to run the shell script Gradle produced, it complained that it could not find some class in org.jansi. So I tried to add that, and then it complained about commons-cli. I had no idea when that would end, so I just decided to do it by hand.

I realize that every time I add a jar file I have to redo this process. But at least I have a process.

I will probably cover this when I give my talk on ActiveJDBC.



More Git Notes

Neo4J and Github trainer Peter Bell was at the Austin Groovy and Grails User Group a couple of weeks ago. He gave some git tips and tricks. I took notes. The guys at AGGUG said they would have something online. So far I have not seen anything, so I am posting my notes.

These are unedited, so you have to mentally parse it yourself. But there were a few things I did not know about.

start gitconfig
You can use the properties as setters and getters
git config –global user.name
git config –global user.name “Daffy Duck”
True for Windows
git config –global core.autocrlf true input
Colors for different status in git
git config –global color.ui true
Can be global, local
global is for every repo
local is the default, for a repo
system is not used too often. This is for all the users of that system.
It is in ~/.gitignore

To create a repo:
git init webgg1
cd webgg1
You might touch a file just to make a file
touch slslsls
git add .
git commit -m “Hello”
Status in silent mode: reduces the output
git status -s
git config –global alias.s “status -s”
Now you can type
git s
git log has bad default output
git log –oneline
git log –oneline –decorate
HEAD is the commit branch you currently have checked out
git log –oneline –decorate –all –graph
git config –global alias.lg “log –online –all –decorate –graph”
The alias is after the alias.
You want to commit to a different branch than master.
git checkout -b about_us
Any untracked files from master come with you
For a modified file (will not work for new files):
git commit -am “djdj”
git merge sjsjs
That is a fast forward merge.
He does not like that.
First he must undo the merge:
git reset –keep master@{1}
Go back one step in the ref log

git merge –no-ff $BRANCH -m “Hello”

git branch -d about_us
He likes to delete a branch when he commits
Merge other branches into master
I always thought you do the opposite: Never mess with master

TO remove a commit:
git reset –hard head~1

rebasing: a branch has a starting point from which it grew
Could we move the base to somewhere else
git rebase master
You might get a merge conflict.
git rebase –continue
If you delete branches and do not do fast forward commits, you still see the commits from those other branches

git reset will undo commits
–soft affects history
–mixed affects staging area as well
–hard affects working directory

We want the two new files, but undo the commits. This will undo 2 commits
git reset HEAD~2
git commit -m “jjs”

Make the last two commits into one commit
git reset –soft HEAD~2
git commit -m “hddh”

Once you push to a server, reset will be bad news
git revert $SHA_CODE

git reset –hard HEAD~2
That will delete history and the files

git ref log will track everything, it is local to each machine.
You can still reset

git commit -m “Logic stuff adofhdofh”
git commit –amend
that only affects the last commit

git rebase interactive will take commits and reorder them or concatenate them
git rebase -i HEAD~4
r = reword
f = fix up
Squash will add all the commit message. You just want to reword the first, fix the rest.

I Got a New Laptop Running Windows 8

Last week my older laptop running Windows XP died. So I got one running Windows 8. The only reason I run Windows is because my mp3 player will not connect to my Linux laptop.

So far, it is okay. I have not worked with the touch screen. I like the fact that if you hit Windows-X you can have the old XP interface. It is nice that Microsoft is actually giving people some degree of choice. I guess that the newer way of doing things might someday become the standard, so I should probably look at it at some point. Maybe it will be like Intel’s Itanium: Consumers will ignore it and it will just die.

When I was setting up my user account it tried to force me to get a Microsoft account. I did some googling on my other machine, and one of the results pointed out there was a link in fine print that would allow me to log in without a Microsoft account. One thing that I did not like was that Windows 8 tried to call the mothership. I have my router set up to only allow explicit ethernet addresses through. But I could not get the ethernet address without logging in, so I had to disable that on my router. I got the ethernet address, entered it, and re-enabled that feature. I am not a security expert. Maybe the Russians are using my WiFi to plan their next invasion of Estonia. But I do not like doing something that I know for sure will make me less secure.

I then downloaded Firefox, the JDK, and a few other apps that I use, like jEdit and aTunes. For one of those, I downloaded an installer from Sourceforge by mistake that installed a browser add-on called mysearchdial. I got id of it from Firefox. I was only able to disable it in IE. I have not figured out how to delete it. I was a bit surprised that Sourceforge was installing spyware on machines. It is not that hard to avoid doing it, you just have to be careful what you click on.

But so far Windows 8 seems nice.

2014-03-31 Tweets

2014-03-30 Update

I am still getting into Groovy.

I am on a new project at work, so getting used to that takes a lot of time and energy.

I did write something in Groovy to make a few tasks easier. I don’t know if other people will be using it. We shall see.

I spent some time going through Programming Concurrency on the JVM by Venkat Subramaniam again. I have a repo on github. I typed in a lot of the examples, and I refactored some of them. I went through and I added a README.md file to each directory giving a summary of that the apps do, and making some comments. I also added a few more classes. I learned some more by going through it. I might give a presentation on it someday.

I also might be giving a presentation on ActiveJDBC, an ORM framework for Java. I got it working with Gradle. It uses instrumentation for a lot of its magic under the hood. I had honestly never heard of instrumentation before. I think it is when you compile a Java class, and add some more bytecode to your compiled class. Anyway, I will work on something to present to the Austin Groovy and Grails group in a few months.