<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DkYGRXw_eCp7ImA9WhRUFUw.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179</id><updated>2012-01-25T09:55:24.240-08:00</updated><category term="mobile" /><category term="p2" /><category term="J2ME" /><category term="JPA" /><category term="GWT" /><category term="Microsoft" /><category term="Dynamic Faces" /><category term="javascript" /><category term="icons" /><category term="rsync" /><category term="unittest" /><category term="development" /><category term="AJAX" /><category term="boost" /><category term="skype" /><category term="temperature" /><category term="flock" /><category term="updates" /><category term="sensor data" /><category term="RPC" /><category term="remote service" /><category term="service" /><category term="adk" /><category term="protobuf" /><category term="HTTP" /><category term="sshfs" /><category term="audio" /><category term="tkdiff" /><category term="sdk" /><category term="source control" /><category term="eclipse" /><category term="hg" /><category term="kvm" /><category term="c++" /><category term="fstab" /><category term="javaagent" /><category term="zenity" /><category term="jmock" /><category term="POST" /><category term="cvs" /><category term="threads" /><category term="java" /><category term="tutorial" /><category term="hamcrest" /><category term="multithreading" /><category term="modules" /><category term="Rich Internet Application" /><category term="diff" /><category term="9-patch" /><category term="bash" /><category term="networking" /><category term="RMI" /><category term="gtest" /><category term="editor" /><category term="mbed" /><category term="android" /><category term="emulator" /><category term="persistence" /><category term="Linux" /><category term="JSF" /><category term="testing" /><category term="ubuntu" /><category term="weaving" /><category term="blogging" /><category term="shellscript" /><category term="mercurial" /><category term="google" /><title>Java Code Trips &amp; Tips</title><subtitle type="html">This blog was born as a means of annotating big and small discoveries in my use of Java, Ubuntu/Linux and Android that would be easy to access from anywhere, anytime. It does beat post-it's big time, and it also adds the benefit that others might, eventually, contribute with intelligent insights.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://codetrips.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>53</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/JavaCodeTripsTips" /><feedburner:info uri="javacodetripstips" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;AkYFRX48cSp7ImA9WhRVGU0.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-5154940359669817763</id><published>2012-01-18T09:35:00.000-08:00</published><updated>2012-01-18T09:35:14.079-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-18T09:35:14.079-08:00</app:edited><title>Adding a new sudoer in Ubuntu</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bCBQM8DY5znCp6fV0Urm1dZ8u7Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bCBQM8DY5znCp6fV0Urm1dZ8u7Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bCBQM8DY5znCp6fV0Urm1dZ8u7Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bCBQM8DY5znCp6fV0Urm1dZ8u7Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;
This is something I have to do from time to time, but not frequently enough that I manage to memorize it - but trivial enough that it annoys me to have to look it up every time.&lt;/div&gt;
&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;
Here's to future memory:&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;create a new user `bob`&lt;/span&gt;&lt;br /&gt;&lt;code style="color: #006000;"&gt;sudo adduser bob&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;check that the `admin` group is the one for the 'sudoers' on the machine&lt;/span&gt;&lt;br /&gt;&lt;code style="color: #006000;"&gt;sudo cat /etc/sudoers&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;add Bob to the admin group&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;code style="color: #006000;"&gt;sudo addgroup bob admin&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;
done!&lt;/div&gt;
&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;
&lt;h4 style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #b76401; font-family: arial, sans-serif; font-size: 1.1em; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
Disabling SSH root access&lt;/h4&gt;
&lt;/div&gt;
&lt;div style="font-family: Arial,Helvetica,sans-serif;"&gt;
Incidentally, always worth disabling SSH root access for the machine: it's the one account hackers know for a fact it must be there, and the one they'll try to crack - the additional positive side-effect is that, at the first attempt to ssh as root, they'll be left hanging waiting for a response from sshd, which is nice.&lt;/div&gt;
&lt;br /&gt;
&lt;div style="background-color: white; color: black; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
Unless you have already done so, you must first create your own personal account and add yourself to the sudoers, as shown above - then try that this all&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;i&gt;Works As Intended&lt;/i&gt;, by logging out from ssh, logging back in as `bob` and executing a harmless, but root-only-allowed command:&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;div class="sites-codeblock sites-codesnippet-block" style="background-color: #efefef; border-bottom-color: rgb(211, 211, 211); border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(211, 211, 211); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(211, 211, 211); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(211, 211, 211); border-top-style: solid; border-top-width: 1px; display: block; line-height: 1; padding-bottom: 0.5em; padding-left: 1em; padding-right: 0px; padding-top: 0.5em;"&gt;
&lt;code style="color: #006000;"&gt;ssh -l bob server&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;div class="sites-codeblock sites-codesnippet-block" style="background-color: #efefef; border-bottom-color: rgb(211, 211, 211); border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(211, 211, 211); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(211, 211, 211); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(211, 211, 211); border-top-style: solid; border-top-width: 1px; display: block; line-height: 1; padding-bottom: 0.5em; padding-left: 1em; padding-right: 0px; padding-top: 0.5em;"&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ whoami&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ sudo touch /etc/blah&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;Password: &amp;nbsp;&amp;nbsp; &amp;lt;------ NOTE: this is Bob's password, NOT root's&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ ls -l /etc/blah&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;-rw-r--r-- 1 root root 0 2011-11-12 13:28 /etc/blah&amp;nbsp; &amp;lt;-- NOTE `root` owner&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ sudo rm /etc/blah&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ ls -l /etc/blah&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;ls: cannot access /etc/blah: No such file or directory&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ groups&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob admin&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;br /&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
Now that we know we can manage our instance from the safety of a non-root account, we can disable SSH access to root: head straight for the sshd (SSH daemon) configuration file and find the line below, change it to "&lt;span style="font-family: 'courier new',monospace;"&gt;no&lt;/span&gt;":&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="sites-codeblock sites-codesnippet-block" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; border-bottom-color: rgb(211, 211, 211); border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(211, 211, 211); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(211, 211, 211); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(211, 211, 211); border-top-style: solid; border-top-width: 1px; color: #333333; display: block; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1; orphans: 2; padding-bottom: 0.5em; padding-left: 1em; padding-right: 0px; padding-top: 0.5em; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;bob@server:~$ sudo vim /etc/ssh/sshd_config&amp;nbsp;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;&amp;nbsp; &lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;PermitRootLogin no&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
save the file and you're done.&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
Try it out: logout, try&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: 'courier new',monospace;"&gt;ssh root@server&lt;/span&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;and you will see it just hangs there - enjoy that warm fuzzy feeling induced by the knowledge that the hacker's machine will be just equally sitting there, like a clueless idiot, just waiting for a response that'll never come.&lt;/div&gt;
&lt;h4 style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #b76401; font-family: arial, sans-serif; font-size: 1.1em; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;

&lt;a href="http://www.blogger.com/blogger.g?blogID=6167393459950006179" name="TOC-Sugarcoating:-passwordless-access-s" style="background-attachment: initial; background-clip: initial; background-color: initial; background-image: url(https://ssl.gstatic.com/sites/p/659986/system/app/themes/solitudespice/bg_link.gif); background-origin: initial; background-position: initial initial; background-repeat: repeat no-repeat; color: #b76401; font-weight: bold; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px; text-decoration: underline;"&gt;&lt;/a&gt;Sugarcoating: passwordless access &amp;amp; short-name resolving&lt;/h4&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
Your server may have a name such as bob.remote.server.blah.foobar.com - typing this every time you want to ssh into it may grow pretty thin after a few times: just add a line to your &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/etc/hosts&lt;/span&gt; file on your box (remember, you have to do this as root):&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="sites-codeblock sites-codesnippet-block" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; border-bottom-color: rgb(211, 211, 211); border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(211, 211, 211); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(211, 211, 211); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(211, 211, 211); border-top-style: solid; border-top-width: 1px; color: #333333; display: block; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 1; orphans: 2; padding-bottom: 0.5em; padding-left: 1em; padding-right: 0px; padding-top: 0.5em; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;$ sudo vim /etc/hosts&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;##&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;# Host Database&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;#&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;# localhost is used to configure the loopback interface&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;# when the system is booting. &amp;nbsp;Do not change this entry.&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;##&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;127.0.0.1&lt;/code&gt;&lt;span style="white-space: pre;"&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;code style="color: #006000;"&gt;&amp;nbsp; localhost&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;255.255.255.255&lt;/code&gt;&lt;span style="white-space: pre;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;code style="color: #006000;"&gt;broadcasthost&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;::1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; localhost&amp;nbsp;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;fe80::1%lo0&lt;/code&gt;&lt;span style="white-space: pre;"&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;code style="color: #006000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; localhost&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;code style="color: #006000;"&gt;# This is the line to add, if the IP is assigned statically: &lt;/code&gt;&lt;br /&gt;
&lt;code style="color: #006000;"&gt;110.22.8.111&lt;/code&gt;&lt;span style="white-space: pre;"&gt;&lt;/span&gt;&lt;code style="color: #006000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bob.remote.server.blah.foobar.com&amp;nbsp; bob.remote&lt;/code&gt;&lt;br /&gt;
&lt;code style="color: #006000;"&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code style="color: #006000;"&gt;&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;This way, you can just log into your remote host using:&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;
&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;ssh -l bob bob.remote&lt;/span&gt;&lt;/div&gt;
&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;However, you still will be asked for your password every time you want to SSH into that instance: to avoid this, you will need to create a private/public key pair, and upload the&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;public&lt;/b&gt;&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;key to your RS instance's&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: white; color: #333333; font-family: 'courier new',monospace; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;authorized_keys&lt;/span&gt;&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;file (more details&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://www.google.com/url?q=http%3A%2F%2Flinuxproblem.org%2Fart_9.html&amp;amp;sa=D&amp;amp;sntz=1&amp;amp;usg=AFrqEzcpP0K37LxkwQwTjT02ZEYLAtNU1w" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: initial; background-clip: initial; background-color: white; background-image: url(https://ssl.gstatic.com/sites/p/659986/system/app/themes/solitudespice/bg_link.gif); background-origin: initial; background-position: initial initial; background-repeat: repeat no-repeat; color: #666666; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: bold; letter-spacing: normal; line-height: 24px; orphans: 2; padding-bottom: 2px; padding-left: 2px; padding-right: 2px; padding-top: 2px; text-align: left; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;here&lt;/a&gt;&lt;span style="background-color: white; color: #333333; display: inline ! important; float: none; font-family: arial,sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;).&lt;/span&gt;&lt;br /&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-family: arial, sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;
&lt;div class="sites-codeblock sites-codesnippet-block" style="background-color: #efefef; border-bottom-color: rgb(211, 211, 211); border-bottom-style: solid; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(211, 211, 211); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(211, 211, 211); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(211, 211, 211); border-top-style: solid; border-top-width: 1px; display: block; line-height: 1; padding-bottom: 0.5em; padding-left: 1em; padding-right: 0px; padding-top: 0.5em;"&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;On your box:&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;code style="color: #006000;"&gt;$ ssh-keygen -t rsa&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;DO NOT ENTER a passphrase, but protect the private key:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;$ chmod 600 .ssh/id_rsa&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;$ ls ~/.ssh&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;total 32&lt;/span&gt;&lt;/div&gt;
&lt;span style="color: #006000; font-family: monospace;"&gt;
&lt;div&gt;
drwx------ &amp;nbsp; 5 marco &amp;nbsp;staff &amp;nbsp; 170B Oct 26 13:26 .&lt;/div&gt;
&lt;div&gt;
drwxr-xr-x+ 39 marco &amp;nbsp;staff &amp;nbsp; 1.3K Nov 11 16:30 ..&lt;/div&gt;
&lt;div&gt;
-rw------- &amp;nbsp; 1 marco &amp;nbsp;staff &amp;nbsp; 1.6K Oct 26 13:24 id_rsa&lt;/div&gt;
&lt;div&gt;
-rw-------@ &amp;nbsp;1 marco &amp;nbsp;staff &amp;nbsp; 401B Oct 26 13:24 id_rsa.pub&lt;/div&gt;
&lt;div&gt;
-rw-r--r-- &amp;nbsp; 1 marco &amp;nbsp;staff &amp;nbsp; 4.4K Nov 10 15:55 known_hosts&lt;/div&gt;
&lt;div&gt;
$ cat ~/.ssh/id_rsa.pub&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVJ1+T1erKLiZKxsc5g9qEoeSS5T+3JSYS8NgCEACXxDWOUSw92SkFI32YsKcL7f8MFUHQhgyT8eMY8v2Eaz91/3l3IeGPOHmUgTLvoNaWNOmEC95Jj7pmx+qOHrK/4DbS2WLiJ4PmQ5kPsV/lzlfzcvY2FfOa71/1bch5izXzDRTDMi0spe7S1wUMO+rsLPf59jKiQ66l8Jof+b4F5A1eMFBjENFOdZBD5jUnu9dcGNn00ykDLmGUq3y3L9w8AOwOe9Ig0dZlLw5URU7jW8yut7sJUHlUJEoZt0q0xpMfwDeUt63Blrf2sJgte4Tw2HSofAs1W1xpE+oyed6lXQHH marco@snaplogic.com&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
NOTE -- this is a PUBLIC key, I don't care if you post it on lulz.com :)&lt;/div&gt;
&lt;div&gt;
Copy this (Command-C)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
$ ssh -l bob bob.remote&lt;/div&gt;
&lt;div&gt;
Password:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;-- You WILL be asked for the password&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
[user@bob.eng.snaplogic.com:~]$ vim .ssh/authorized_keys &amp;nbsp; # this may be empty, that's ok&lt;/div&gt;
&lt;div&gt;
Paste the key (Command-V) and save the file; if this creates the file, make sure it's only writeable by you&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
[user@bob.eng.snaplogic.com:~]$ chmod 600 .ssh/authorized_keys&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
[user@bob.eng.snaplogic.com:~]$ exit&lt;/div&gt;
&lt;div&gt;
$&amp;nbsp;ssh -l bob bob.remote&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.35.4-rscloud x86_64)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;* Documentation: &amp;nbsp;https://help.ubuntu.com/&lt;/div&gt;
&lt;div&gt;
Last login: Sat Nov 12 16:21:51 2011 from 12.90.36.218&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
Look, ma, no password!&lt;/div&gt;
&lt;/div&gt;
&lt;div style="color: black; font-family: Arial,Helvetica,sans-serif;"&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-5154940359669817763?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/hrlRdv3LTNc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/5154940359669817763/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2012/01/adding-new-sudoer-in-ubuntu.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5154940359669817763?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5154940359669817763?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/hrlRdv3LTNc/adding-new-sudoer-in-ubuntu.html" title="Adding a new sudoer in Ubuntu" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2012/01/adding-new-sudoer-in-ubuntu.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMFR346fip7ImA9WhdWGEQ.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-6289623121423122752</id><published>2011-09-13T00:03:00.000-07:00</published><updated>2011-09-13T00:03:36.016-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-13T00:03:36.016-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="c++" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="testing" /><category scheme="http://www.blogger.com/atom/ns#" term="google" /><category scheme="http://www.blogger.com/atom/ns#" term="gtest" /><title>CDT Indexer &amp; Google gtest framework</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZYWAR4yEhMaSc2Ou0yM5OcSKRxg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZYWAR4yEhMaSc2Ou0yM5OcSKRxg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZYWAR4yEhMaSc2Ou0yM5OcSKRxg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZYWAR4yEhMaSc2Ou0yM5OcSKRxg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;As I mentioned in a &lt;a href="http://codetrips.blogspot.com/2011/04/eclipse-cdt-and-google-gtest.html"&gt;previous post&lt;/a&gt; of mine, &lt;span class="Apple-style-span" style="color: #990000;"&gt;&lt;b&gt;Eclipse's CDT&lt;/b&gt;&lt;/span&gt; (C++ Development Tools) has a few issues when used with &lt;a href="http://code.google.com/p/googletest/"&gt;Google C++ Unit Testing framework&lt;/a&gt;, but it generally works.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Where CDT really gets confused is around the 'exclusion' of the unit tests for the non-test build configurations: as mentioned in my other post, one needs to add the G-Test's &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;include/ &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;directory to include search path (&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-I&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-LgmYmwVLfUA/Tm7643EneMI/AAAAAAAAYIw/EoFCL2WHEMg/s1600/CDT-Indexer_Default-Preferences+.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-LgmYmwVLfUA/Tm7643EneMI/AAAAAAAAYIw/EoFCL2WHEMg/s320/CDT-Indexer_Default-Preferences+.png" width="246" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Default Preferences&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;However, I recently found out that the indexer gets confused too, if one uses the default preferences in &lt;i&gt;&lt;span class="Apple-style-span" style="color: #38761d;"&gt;Window &amp;gt; Preferences &amp;gt; C/C++ &amp;gt; Indexer&lt;/span&gt;&lt;/i&gt; (see screenshot on the left): the critical item is the "&lt;span class="Apple-style-span" style="color: #38761d;"&gt;Index unused headers&lt;/span&gt;" which leads to a bunch of syntax errors on the unit tests, due to the fact that the entire testing:: namespace is not indexed, when the Active Build Configuration is not the Test one.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Whilst this may (possibly) be a "feature," it annoys the hell out of me, nor did I find it particularly useful (as it's very difficult to tell the genuine errors from the artifacts).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;I have found that by enabling the indexing of unused headers, causes the syntax errors to disappear from the&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; *_test.cc&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt; files and makes for an altogheter more pleasant working environment (see below for my settings).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;One other thing worth noting is that the "&lt;span class="Apple-style-span" style="color: #38761d;"&gt;Build configuration for the indexer&lt;/span&gt;" preference is best left alone: choosing the one that would intuitively make the most sense (&lt;i&gt;&lt;span class="Apple-style-span" style="color: #38761d;"&gt;Use active build configuration&lt;/span&gt;&lt;/i&gt;) causes again a whole bunch of (spurious) syntax errors to appear in your test sources.&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #990000; font-family: 'Trebuchet MS', sans-serif; font-size: x-small;"&gt;&lt;b&gt;[1]&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;I've personally not experimented enough with the "&lt;span class="Apple-style-span" style="color: #38761d;"&gt;&lt;i&gt;Index source and header opened in the editor&lt;/i&gt;&lt;/span&gt;," but if anyone can figure out what the best choice would be, I'd love to hear your comments.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="clear: right; float: right; margin-bottom: 1em; text-align: right;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-RoYvS49yYOM/Tm79vOsrfeI/AAAAAAAAYI0/Pjz6hRTEC1c/s1600/CDT-MyPreferences+.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/-RoYvS49yYOM/Tm79vOsrfeI/AAAAAAAAYI0/Pjz6hRTEC1c/s320/CDT-MyPreferences+.png" width="246" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Recommended Preferences&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Finally, it's worth noting that, if you have recently updated your install (or even, moved from Helios to Indigo) it is possibly that the configuration, indexer, etc. of your projects got seriously hosed: what got me into the quest for the "perfect indexer settings" was a bunch of mysterious syntax errors in my unit tests, which I was totally unable to resolve (although the code itself build just fine with g++).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;If you do come across a similar situation (a project that used to build, and where you get unreasonable and unexplained syntax errors in Eclipse's editor) try and change the Preferences for the C++ Indexer (even just opening the page, changing a few random settings, hitting '&lt;i&gt;Apply&lt;/i&gt;' and then '&lt;i&gt;Restore Defaults&lt;/i&gt;' and '&lt;i&gt;Ok&lt;/i&gt;' should work).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #990000; font-size: x-small;"&gt;&lt;b&gt;[1]&lt;/b&gt;&lt;/span&gt; Worth noting that the (default) setting is a bit 'circular' as it delegates to the "&lt;i&gt;&lt;span class="Apple-style-span" style="color: #38761d;"&gt;build configuration specified in the project's indexer settings&lt;/span&gt;&lt;/i&gt;;" however, the latter (unless otherwise specified) seems to defer to the Workspace settings: which must be different from just using the 'active build configuration' as choosing the latter causes a whole bunch of errors to appear in the test sources: hence, there must be a default, non-obvious setting which makes it all work, but no indication as to what &lt;i&gt;that&lt;/i&gt; is.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-6289623121423122752?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/IeyEze_g5GU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/6289623121423122752/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/09/cdt-indexer-google-gtest-framework.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/6289623121423122752?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/6289623121423122752?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/IeyEze_g5GU/cdt-indexer-google-gtest-framework.html" title="CDT Indexer &amp; Google gtest framework" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-LgmYmwVLfUA/Tm7643EneMI/AAAAAAAAYIw/EoFCL2WHEMg/s72-c/CDT-Indexer_Default-Preferences+.png" height="72" width="72" /><thr:total>0</thr:total><georss:featurename>Sunnyvale, CA, USA</georss:featurename><georss:point>37.36883 -122.0363496</georss:point><georss:box>37.3183525 -122.1153136 37.4193075 -121.9573856</georss:box><feedburner:origLink>http://codetrips.blogspot.com/2011/09/cdt-indexer-google-gtest-framework.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04GRHk7eyp7ImA9WhdWE0U.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-1588546160062678943</id><published>2011-09-06T23:42:00.000-07:00</published><updated>2011-09-07T00:52:05.703-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-07T00:52:05.703-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="adk" /><category scheme="http://www.blogger.com/atom/ns#" term="mbed" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Android ADK and mbed.org</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vF94Zc0G5dv9mUrEu0T8gE6SQNU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vF94Zc0G5dv9mUrEu0T8gE6SQNU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vF94Zc0G5dv9mUrEu0T8gE6SQNU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vF94Zc0G5dv9mUrEu0T8gE6SQNU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://goo.gl/photos/IZY7DMhzQW" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="238" src="https://lh3.googleusercontent.com/-smPZcs66g-o/TmcNv1fQGGI/AAAAAAAASRI/9MnGewnhKq4/s400/IMAG0219.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;The 'mbed kit' just landed on my doorstep, sent courtesy of the good guys at ARM (Cambridge, UK).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;This gadget supports the Android ADK (&lt;a href="http://mbed.org/cookbook/mbed-with-Android-ADK" style="color: #1155cc;" target="_blank"&gt;http://mbed.org/cookbook/mbed-&lt;wbr&gt;&lt;/wbr&gt;with-Android-ADK&lt;/a&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt; which is fully documented &lt;a href="http://developer.android.com/guide/topics/usb/adk.html"&gt;here&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;and, to have an idea of the geeky-fun that can be had with these gizmos, I suggest you check out &lt;a href="http://mbed.org/handbook/Tour"&gt;this video&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;I fear that my weekends are likely gone for quite a while now....&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;Just as an example of what is possible, the following snippet will make the LEDs flash, as well as connect to a terminal on the host PC to use as stdout; this is a very basic adaption of the &lt;a href="http://mbed.org/handbook/Creating-a-program"&gt;HelloWorld.cpp app&lt;/a&gt;, and some &lt;a href="http://mbed.org/handbook/SerialPC"&gt;tutorials&lt;/a&gt; from mbed.org: the point being that it took me less than 30min to get going!&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre&gt;// AlertAvert.com (c) 2011. All rights reserved
//
// The code below has been adapted from tutorials on
// mbed.org - credits should go to ARM Ltd.
//
// Author: M. Massenzio (m.massenzio@gmail.com)

#include "mbed.h"

// USB out to the host PC - from a terminal window access
// using: screen /dev/ttyACM0
Serial pc(USBTX, USBRX); // tx, rx

// Board LEDs
DigitalOut myled(LED1);
DigitalOut yourled(LED2);

bool on = true;
void quit() {
  on = false;
}

void toggle(DigitalOut d1, DigitalOut d2) {
  d1 = !d1;
  d2 = !d2;
}

int main() {
  pc.printf("Starting LED flashing...\r\n");
  Timeout to;
  myled = !(yourled = 1);
  to.attach(&amp;amp;quit, 5);
  while(on) {
    toggle(myled, yourled);
    wait(0.2);
  }
  myled = yourled = 0;
  pc.printf("Exiting now\r\n");
}&lt;/pre&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222; font-family: 'Trebuchet MS', sans-serif;"&gt;And this is what came out of it:&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;object width="320" height="266" class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://1.gvt0.com/vi/81lIG4EV_nU/0.jpg"&gt;&lt;param name="movie" value="http://www.youtube.com/v/81lIG4EV_nU&amp;fs=1&amp;source=uds" /&gt;&lt;param name="bgcolor" value="#FFFFFF" /&gt;&lt;embed width="320" height="266"  src="http://www.youtube.com/v/81lIG4EV_nU&amp;fs=1&amp;source=uds" type="application/x-shockwave-flash"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-1588546160062678943?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/UcXuDkL1o5o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/1588546160062678943/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/09/android-adk-and-mbedorg.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1588546160062678943?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1588546160062678943?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/UcXuDkL1o5o/android-adk-and-mbedorg.html" title="Android ADK and mbed.org" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh3.googleusercontent.com/-smPZcs66g-o/TmcNv1fQGGI/AAAAAAAASRI/9MnGewnhKq4/s72-c/IMAG0219.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/09/android-adk-and-mbedorg.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQBSH0yfip7ImA9WhdQGUQ.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-2478567391433149675</id><published>2011-08-22T00:12:00.000-07:00</published><updated>2011-08-22T00:15:59.396-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-22T00:15:59.396-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Use a common Tag for all your activities' logging</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-mwtSqbxSRa1CTT_RzY4R7p8v9o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-mwtSqbxSRa1CTT_RzY4R7p8v9o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-mwtSqbxSRa1CTT_RzY4R7p8v9o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-mwtSqbxSRa1CTT_RzY4R7p8v9o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-TnXFW7rjjKI/TlICCsvgyHI/AAAAAAAASQ8/F7LrPE0dYyc/s1600/Screenshot.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="106" src="http://3.bp.blogspot.com/-TnXFW7rjjKI/TlICCsvgyHI/AAAAAAAASQ8/F7LrPE0dYyc/s200/Screenshot.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It is pretty common for any non-trivial Android app to be composed of several Activities which together interact with the user for the furtherance of whatever is the objective of the app itself.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It is also pretty common, especially during the development phase, to have a need to emit logs so that one can check certain events happen when they are supposed to, and invariants, for example, are satisfied.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The Android ADT (Eclipse plugin) has a very nice feature in the form of the &lt;span class="Apple-style-span" style="color: #38761d;"&gt;&lt;b&gt;LogCat View&lt;/b&gt;&lt;/span&gt; that shows all the system logs, including those coming from your applications: as there may well be tens of apps running (and logging) at the same time (especially on a live device -- as to why you should use a device for your testing and debugging, you may want to &lt;a href="http://codetrips.blogspot.com/2011/01/run-android-tests-in-connected-device.html"&gt;read this&lt;/a&gt;) the LogCat enables one to 'filter in' a subset, based on a 'tag'.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The tag used by the LogCat is the value of the string used for the tag parameter in the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Log.x() &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;calls:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;Log.d("myApp.tag", "All is going well");&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It is pretty obvious that, in any given Activity, we would want a constant to use as the tag:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;private static final String TAG = "myApp.tag";&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;but this has the drawback that we would have to either duplicate that same statment across all Activities (and, even worse, keep them all in sync if we decide, for whatever reason to change them) or resign ourselves to use different tags for different activities.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Alternatively, we could use a common 'Constants' class to keep, amongst others, a constant Tag:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;public interface Constants {
  public static final String TAG = "myApp.tag";
  // other constants...
}&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This is not very friendly, however, as every log statement (and there may well be hundreds in your code) would look something like:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;Log(Constants.TAG, "All is going well");&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;it's only 10 extra characters, but multiply that for several hundrends, and you've a veritable case of carpal tunnel syndrome on your hands (well, ok...).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;A much better option is to use Android's mechanism to store common application strings, which also gives the additional benefit that it's dead easy to change the tag in one full swoop, should that ever be necessary: in one of the XML files in the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;res/values/ &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;directory, have a line of the form&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;item name="TAG" type="string"&gt;myApp.tag&lt;/item&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;and in your code, you can do something like:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;public class MyActivity extends Activity {
  public static String TAG; // note no 'final' here

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TAG = getResources().getString(R.string.TAG);
    Log.d(TAG, "Starting User Preferences activity...");
    // other initialization follows...
  }
}&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This can be done in each and every of your App's activities, and then you can easily create a new filtered view in LogCat so that you can see only your App's logs, from all the activities, also with the reassurance that, should ever want to change that, it's just a one minute edit of the XML file&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-2478567391433149675?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/khyhWj5dymg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/2478567391433149675/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/08/use-common-tag-for-all-your-activities.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/2478567391433149675?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/2478567391433149675?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/khyhWj5dymg/use-common-tag-for-all-your-activities.html" title="Use a common Tag for all your activities' logging" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-TnXFW7rjjKI/TlICCsvgyHI/AAAAAAAASQ8/F7LrPE0dYyc/s72-c/Screenshot.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/08/use-common-tag-for-all-your-activities.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMCQ3g4cCp7ImA9WhdQEkU.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-7766623964669418656</id><published>2011-08-13T18:15:00.000-07:00</published><updated>2011-08-13T18:47:42.638-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-13T18:47:42.638-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="protobuf" /><category scheme="http://www.blogger.com/atom/ns#" term="HTTP" /><category scheme="http://www.blogger.com/atom/ns#" term="POST" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>HTTP POST for Android (with a twist: Protocol Buffers)</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QuxkRU890o_sAIv7onNeTgjs0VM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QuxkRU890o_sAIv7onNeTgjs0VM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QuxkRU890o_sAIv7onNeTgjs0VM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QuxkRU890o_sAIv7onNeTgjs0VM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-X7VLXszMyvU/TkcnZu5dmQI/AAAAAAAASQM/7GAj_X3qWwE/s1600/New+%2527settings%2527+button+nobg.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-X7VLXszMyvU/TkcnZu5dmQI/AAAAAAAASQM/7GAj_X3qWwE/s200/New+%2527settings%2527+button+nobg.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;One of this blog's &lt;a href="http://codetrips.blogspot.com/2007/04/http-post-from-j2me-midlet.html"&gt;most visited entries&lt;/a&gt; (ranking always around the Top 5 Google results for "HTTP POST" too) elaborated on how to send data across to a server from a J2ME Midlet.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I thought it was high time for bringing this into the new Century, and provide an update as to how to do this from an Android smartphone.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It turns out that (a) the code is relatively straightforward and (b) that there is not so much difference after all from writing the same code for a desktop client: credit for this ought to go to the Android Google team who have done such a superb job of adapting the J2SE API to the Android platform.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;As usual, I will not elaborate on the basics of how to set-up your Android development environment (I strongly recommend &lt;a href="http://developer.android.com/guide/topics/fundamentals.html"&gt;the excellent tutorials&lt;/a&gt; on &lt;a href="http://android.com/"&gt;Android.com&lt;/a&gt;) or about the basics of an HTTP POST (please refer to the &lt;a href="http://codetrips.blogspot.com/2007/04/http-post-from-j2me-midlet.html"&gt;original article&lt;/a&gt;).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Also, whilst not explicitly noted in the code below, it should be obvious that this may be a long-running request and/or anything could go wrong and block, and you should never run a network action from within the UI thread, as it would otherwise make your application unresponsive (this is even more critical in Android, where the system wisely detects such cases of kiddie-programming and pops a request to the user to the effect that they may want to terminate the offending slouching app... yet another reason to love the Android platform!): more details can be found in &lt;a href="http://codetrips.blogspot.com/2007/04/multi-threading-mon-amour.html"&gt;this post&lt;/a&gt;, which is still very much up-to-date.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Given that the code to send an HTTP POST request requires some data to be sent in the first place, and so as to make it all a bit more interesting, I decided to add a twist to the tale, by providing an example of how you could use &lt;a href="http://code.google.com/p/protobuf/"&gt;Protocol Buffers&lt;/a&gt; in you communication between your mobile app and the server back-end.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Protocol Buffers are a massively useful technology developed (and open-sourced) by Google and we use them all over the place both as data payloads for our RPC infrastructure, as well as ways to encapsulate our domain model objects in our Bigtable persistence store (very often, PB's are the model objects and are used as first class objects).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Elaborating on their usefulness is outside the scope of this post, and I would strongly encourage you to experiment with them, especially if your application needs advanced serialization capabilities and/or is based on (or would benefit from) mixed-language (Java / C++) code.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Please download the source code from&amp;nbsp;&lt;a href="http://code.google.com/p/protobuf/downloads/list"&gt;here&lt;/a&gt;, and then use the source code to build a protobuf-2.4.x.jar library that you will need to add to both the Android and Server projects (note &lt;a href="http://codetrips.blogspot.com/2010/04/jmock-on-android.html"&gt;this warning&lt;/a&gt; when adding the JAR to the Android'd build path: do not add it as a User Library in Eclipse, but rather as a single "external" JAR, or it won't be added to the APK and the application will fail at runtime).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If you are using Eclipse for your development (and I can't honestly see why not) it's worth noting that my team just released &lt;a href="http://code.google.com/p/protobuf-dt/"&gt;a new protobuf editor&lt;/a&gt; that is freely available and it will eventually released as open-source; it is based on the awesome XText 2.0 framework for DSL development, go check it out (the latter only works for Eclipse 3.7).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-HR4CEHfCO-g/TkcnkKIkvmI/AAAAAAAASQQ/JAdOeJmuHfI/s1600/New+%2527camera%2527+button+nobg.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-HR4CEHfCO-g/TkcnkKIkvmI/AAAAAAAASQQ/JAdOeJmuHfI/s200/New+%2527camera%2527+button+nobg.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The following code is based on my &lt;a href="https://sites.google.com/site/androidreceipts/"&gt;Android Receipts&lt;/a&gt; applications (you can install it &lt;a href="https://market.android.com/details?id=com.alertavert.android.applications.receipts"&gt;from Android Market&lt;/a&gt; - the current version does not implement the server communication yet, but sends the receipts' images and data to your email account).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Alright, having done intros and niceties, here we go!&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;As the starting point, here is the code for the protobuf messages:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;// receipts.proto   created 2011-08-10, M. Massenzio
// Copyright AlertAvert.com (c) 2011.  All rights reserved.

package receipts;
option java_package = "com.alertavert.receiptscan.model.proto";
option java_outer_classname = "ReceiptsProtos";

message ReceiptProto {
  // The unique ID associated with the receipt, 
  // may be left unassigned until persisted
  optional string id = 99;
  
  // A name associated with this receipt, it should be unique for the user
  required string name = 1;
  
  required string merchant = 2;
  required float amount = 3;
  
  // The currency for the amount, if not present assumed to be
  // the default for the locale
  optional string currency = 4;
  optional string notes = 5;
  
  // The scanned image of the receipt, may not be there 
  // (as its URI may be retrieved from the persistence layer).
  optional bytes image = 6;
}

/*
 * A server request payload, contains enough information to 
 * uniquely associate the request with
 * an ongoing user session and one or more receipts.
 */
message ReceiptsPayload {
  required string token = 1;
  repeated ReceiptProto receipts = 2;
  optional string username = 3;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Fairly straightforward as you can see, this will compile to both C++ (.h / .cc) and Java source code, which one can then use in one's own code - the serialization is implemented by the protoc libraries (you'll see an example below) and the framework takes care of all the rest.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The command line to compile this is:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;protoc --cpp_out=../src-gen/cpp --java_out=../src-gen/java receipts.proto&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;assuming that your code is in the receipts.proto file.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I use normally a Makefile to automate all this, which looks something like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;# Makefile for protobufs
#
# Created by M. Massenzio, 2011-04-16
# Updated 2011-08-10
#
# Assumes the following structure (works best with Eclipse):
#
# Project
#   src           --&amp;gt; contains all java packages
#   src-gen/java  --&amp;gt; contains generated Java files in their packages
#   src-gen/cpp   --&amp;gt; contains generated C++ files in their namespaces
#   proto         --&amp;gt; all source .proto files
#
# In general, Protocol Buffer libraries are expected to be found
# in /usr/local/lib (see also below).

all: build

clean:
	@echo "Removing all generated code and recreating directories"
	@rm -rf ../src-gen/*
	@mkdir -p ../src-gen/cpp
	@mkdir -p ../src-gen/java

# WARNING: ../src-gen/cpp and ../src-gen/java-gen MUST be already present,&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;#          use make clean
build: receipts.proto
    # fails if protobuf is not installed
	@pkg-config --cflags protobuf &amp;gt;/dev/null
	@protoc --cpp_out=../src-gen/cpp --java_out=../src-gen/java receipts.proto
	@echo "Code successfully generated.\nRemember to include these flags in the compilation:\n" `pkg-config --cflags --libs protobuf`

#
# Flags for the compilation:
# compiler: -pthread -I/usr/local/include
# linker:   -pthread -L/usr/local/lib -lprotobuf -lz
#
# In Eclipse, use Project &amp;gt; Properties &amp;gt; C/C++ Build &amp;gt; Settings
#
# C++ Compiler: Miscellaneous --&amp;gt; add -pthread in "Other flags"
#               Directories   --&amp;gt; add a 'workspace linked' /gen directory
# Linker: Libraries  (-l) protobuf (-L) /usr/local/lib
#         Miscellaneous --&amp;gt; Linker flags: -pthread
#
# For Java projects, remember to add protobuf-java-2.4.0a.jar
# (on this system, under /opt/google/protobuf-2.4.0a/java/target)
#
&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If all went according to plan, you should have, in src-gen/java/com/alertavert/receiptscan/model/proto a ReceiptsProtos.java file, which you can open to have a look at (I strongly discourage editing it - nothing good can come of it, and it will be overwritten anyway once one regenerates the protobufs).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Time to go back to the Android project, add the protobuf-2.4.x.jar to the build path, add src-gen/java to the build path as a source folder (if src-gen is not already part of the project's folder, add it as a "linked folder," then right-click on the 'java' folder and select Build path &amp;gt; Add as source folder).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Verify that Eclipse can build the project without syntax errors on the ReceiptsProtos.java class, and then create (or update) an existing class that will send the receipts objects to the server.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Mine looks something like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;// Copyright AlertAvert.com (c) 2011.  All rights reserved.
// Created by M. Massenzio
package com.alertavert.android.applications.receipts.connectivity;

// imports omitted
// ...

public class HttpSender implements Sender {
  /** Use a custom user-agent to distinguish the sender and for logging purposes */
  private static final String USERAGENT = 
      "AndroidReceipts-server-alertavert_1.0.0;android/receipts";
  URL destination;
  private String reason;
  
  @Override
  public boolean send(Collection&lt;receipt&gt; receipts) {
    if (receipts.isEmpty()) {
      return false;
    }
    BufferedOutputStream os = null;
    HttpURLConnection connection = null;
    try {
      connection = (HttpURLConnection) destination.openConnection();
      if (connection == null) {
        reason = "Could connect to server " + destination;
        return false;
      }
      // Uses POST
      connection.setDoOutput(true);
      // get the default chunk length
      connection.setChunkedStreamingMode(0);
      // set a custom user agent, so the server can choose the best way 
      // to handle the request
      connection.setRequestProperty("User-Agent", USERAGENT);
      os = new BufferedOutputStream(connection.getOutputStream());
      byte[] data = wrapIntoProtoPayload(receipts).toByteArray();
      Log.d(ControllerActivity.TAG, "Proto serialized into "
          + data.length + " bytes");
      os.write(data);
      if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        // TODO notify the listener of a successful send
        Log.d(ControllerActivity.TAG, "Receipts successfully uploaded");
        return true;
      } else {
        // TODO call the listener and return the error code and message
        Log.e(ControllerActivity.TAG, "Error uploading receipts: " +
            connection.getResponseMessage());
        reason = connection.getResponseMessage();
        return false;
      }
      return true;
    } catch (IOException ex) {
      ex.printStackTrace();
      return false;
    } finally {
      try {
        if (os != null) os.close();
        if (connection != null) connection.disconnect();
      } catch (IOException stupidestExceptionEver) {
        // just ignore this idiocy and praise JDK7's Try-With-Resources
        // ... not one day too soon!
      }
    }
  }
  
  private ReceiptsProtos.ReceiptsPayload wrapIntoProtoPayload(
      Collection&lt;receipt&gt; receipts)
      throws IOException {
    ReceiptsProtos.ReceiptsPayload.Builder builder =
       ReceiptsProtos.ReceiptsPayload.newBuilder();
    // TODO obtain these values from the SessionManager or a SecAuth layer
    builder.setToken("123456abcdef");
    builder.setUsername("anuser");
    for (Receipt r : receipts) {
      builder.addReceipts(wrapIntoReceiptProto(r));
      Log.d(ControllerActivity.TAG, "Adding receipt " + r.getName());
    }
    return builder.build();
  }
  
  private ReceiptProto wrapIntoReceiptProto(Receipt r) throws IOException {
    ReceiptProto.Builder builder = ReceiptProto.newBuilder();
    if (r.getId() != 0) {
      builder.setId("" + r.getId());
    }
    builder.setName(r.getName());
    builder.setAmount(r.getAmount().getFloatValue());
    if (r.getAmount().getCurrency().length() == 0) {
      // TODO(marco) extract the default currency for the locale 
    } else {
      builder.setCurrency(r.getAmount().getCurrency());
    }
    builder.setMerchant(r.getMerchant());
    if (r.getNotes().length() &amp;gt; 0 ) {
      builder.setNotes(r.getNotes());
    }
    // Extract the image data and wrap into the protocol buffer
    byte[] buf = new byte[1024];
    InputStream is = new BufferedInputStream(new FileInputStream(
        r.getImageUri().getPath()));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    int numBytesRead;
    while ((numBytesRead = is.read(buf)) != -1) {
      bos.write(buf, 0, numBytesRead);
    }
    is.close();
    ByteString image = ByteString.copyFrom(bos.toByteArray());
    builder.setImage(image);
    return builder.build();
  }
  ////////////////////////
  // Lots of other stuff here omitted, in particular Listeners that will be
  // notified when this method completes, etc.
  // ...
}
&lt;/receipt&gt;&lt;/receipt&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;As you can see, the core of sending an HTTP POST request is pretty straightforward: 5-6 lines of code at most, with all the rest necessary to wrap the data around (note that in the sample code above I do virtually no error checking on the returned response code, nor use any data that the server may be sending back - maybe in a later post...).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-7AS908iUyOY/Tkcnv6ENxvI/AAAAAAAASQU/Zq20-T034FE/s1600/android_receipts_ui.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-7AS908iUyOY/Tkcnv6ENxvI/AAAAAAAASQU/Zq20-T034FE/s200/android_receipts_ui.png" width="141" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The all-important line is&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;connection = (HttpURLConnection) destination.openConnection();&lt;/span&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;with destination the URL of the server (something like: &lt;i&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;https://receipts.alertavert.com/Receipts/upload&lt;/span&gt;&lt;/i&gt;); when testing it from your Android device, you have essentially two options:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;emulator&lt;/i&gt; - slow and painful, I discourage it;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;a real Android device connected via USB to your development box (highly recommended).&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Depending on which option you use, and if #2 is being use with WiFi active (and possibly connected to your internal A/P) you will have to use different URLs.  Assuming that your server (more about that in a second) is running on the same box as your development environment, and that you use either the emulator or the phone with WiFi OFF, &lt;a href="http://developer.android.com/resources/faq/commontasks.html#localhostalias"&gt;use 10.0.2.2 as the address to get to your machine&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If you are using a device, with WiFi on, you can just use the PC's IP internal address (say, 192.168.0.3, or whatever it is you have set it up at on your LAN - or even an externally facing IP if your router/LAN allows you to do so).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Remember that if you are running a plain vanilla Tomcat instance, that one will be listening on port 8080, so the full URL will be something like:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;http://10.0.2.2:8080/ReceiptsServer/upload&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Which brings us finally to the server-side code, a pretty run-of-the-mill Servlet class:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;public class UploadServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  private static final Logger log = Logger.getLogger(UploadServlet.class.getCanonicalName());
  private static final String JPEG = ".jpg";
  private static final String FILE_SCHEME = "file";

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
   *      response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    BufferedInputStream bis = new BufferedInputStream(request.getInputStream());
    try {
      int numBytesRead;
      byte[] buf = new byte[256];
      while ((numBytesRead = bis.read(buf)) != -1) {
        bos.write(buf, 0, numBytesRead);
      }
      log.info("Received " + bos.size() + " bytes");
      ReceiptsProtos.ReceiptsPayload payload = ReceiptsProtos.ReceiptsPayload
          .parseFrom(bos.toByteArray());
      if (payload != null) {
        // TODO(marco): validate token with a SessionManager
        log.info("Got a valid payload: " + payload.getToken() + ", with "
            + payload.getReceiptsCount() + " receipts enclosed, from user "
            + payload.getUsername());
        if (payload.getReceiptsCount() &amp;gt; 0) {
          List&lt;receipt&gt; receipts = new ArrayList&lt;receipt&gt;();
          for (ReceiptsProtos.ReceiptProto proto : payload.getReceiptsList()) {
            // simple proto -&amp;gt; object model adapter method
            Receipt receipt = protoReceiptAdapter(proto);
            // extract the image data, save to a file and set receipt.setImageUri() 
            // to point to it
            extractImage(proto.getImage(), receipt);
            log.info("Received a receipt: " + receipt.toString());
            receipts.add(receipt);
          }
          // TODO pass receipts to a DAO for persistence
        } else {
          log.severe("No receipts received");
        }
      } else {
        log.severe("Could not parse payload into a valid ReceiptsProto object");
      }
    } finally {
      bos.close();
      bis.close();
    }
  }

  /**
   * A simple implementation of an Adapter, this would most likely be 
   * delegated off-servlet too.
   * 
   * @param proto
   * @return
   */
  private Receipt protoReceiptAdapter(ReceiptsProtos.ReceiptProto proto) {
    Receipt receipt = new Receipt();
    receipt.setName(proto.getName());
    receipt.setMerchant(proto.getMerchant());
    int intVal = (int) Math.floor(proto.getAmount());
    int decVal = (int) (proto.getAmount() - intVal);
    receipt.setAmount(new Money(intVal, decVal, proto.getCurrency()));
    receipt.setNotes(proto.getNotes());
    return receipt;
  }

  /**
   * Saves the image data to a temporary file - obviously this is just for demonstration
   * purposes, the actual persistence would be delegated elsewhere,
   * away from servlet processing.
   * 
   * @param image
   * @param receipt
   * @throws IOException
   */
  private void extractImage(ByteString image, Receipt receipt) throws IOException {
    File imageFile = File.createTempFile(receipt.getName(), JPEG);
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(imageFile));
    bos.write(image.toByteArray());
    bos.close();
    try {
      receipt.setImageUri(new URI(FILE_SCHEME, imageFile.getAbsolutePath(), ""));
      log.info("Image file saved in " + imageFile.getAbsolutePath());
    } catch (URISyntaxException e) {
      log.severe("Could not create URI for " + imageFile.getAbsolutePath()
          + ", original error was "
          + e.getLocalizedMessage());
    }
  }
}
&lt;/receipt&gt;&lt;/receipt&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Again, there is virtually no error processing here, nor any error codes are returned to the client - definitely not production-class, but at least gives you an idea of how to get data from a mobile Android client and save it someplace server-side.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-zeIWD4rd_ps/Tkcn4n5Is5I/AAAAAAAASQY/ZCSeXGIhX1o/s1600/New+%2527receipts%2527+button+nobg.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-zeIWD4rd_ps/Tkcn4n5Is5I/AAAAAAAASQY/ZCSeXGIhX1o/s1600/New+%2527receipts%2527+button+nobg.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Remember to add to your&lt;/span&gt; &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;web.xml&lt;/span&gt; &lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;the following&lt;/span&gt;:&lt;br /&gt;
&lt;pre&gt;&amp;lt;servlet&amp;gt;
    &amp;lt;description&amp;gt;&amp;lt;/description&amp;gt;
    &amp;lt;display-name&amp;gt;UploadServlet&amp;lt;/display-name&amp;gt;
    &amp;lt;servlet-name&amp;gt;UploadServlet&amp;lt;/servlet-name&amp;gt;
    &amp;lt;servlet-class&amp;gt;
        com.alertavert.receipts.server.servlets.UploadServlet
    &amp;lt;/servlet-class&amp;gt;
  &amp;lt;/servlet&amp;gt;
  &amp;lt;servlet-mapping&amp;gt;
    &amp;lt;servlet-name&amp;gt;UploadServlet&amp;lt;/servlet-name&amp;gt;
    &amp;lt;url-pattern&amp;gt;/upload&amp;lt;/url-pattern&amp;gt;
  &amp;lt;/servlet-mapping&amp;gt;
&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;so that it knows how to direct the request.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Hope this becomes as popular as the other, please feel free to link to this page from your blog and / or forum posts (I'd love to hear from you if you do so, but you don't need any special permission) and let me know what you think of it.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #990000; font-family: Verdana, sans-serif;"&gt;&lt;i&gt;(Images courtesy of E. Massenzio (c) 2011 - see her other work &lt;a href="http://marvellous.smugmug.com/"&gt;here&lt;/a&gt;)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-7766623964669418656?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/76zOhPgzgDI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/7766623964669418656/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/08/http-post-for-android-with-twist.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7766623964669418656?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7766623964669418656?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/76zOhPgzgDI/http-post-for-android-with-twist.html" title="HTTP POST for Android (with a twist: Protocol Buffers)" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-X7VLXszMyvU/TkcnZu5dmQI/AAAAAAAASQM/7GAj_X3qWwE/s72-c/New+%2527settings%2527+button+nobg.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/08/http-post-for-android-with-twist.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEMQXg_fSp7ImA9WhdRGUg.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-1359348416798891241</id><published>2011-08-09T23:26:00.000-07:00</published><updated>2011-08-09T23:28:00.645-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-09T23:28:00.645-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="bash" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu" /><title>Automating Eclipse launch</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1BVqg1F1duxBKfLGtKgjNv2ANLA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1BVqg1F1duxBKfLGtKgjNv2ANLA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1BVqg1F1duxBKfLGtKgjNv2ANLA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1BVqg1F1duxBKfLGtKgjNv2ANLA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I've recently taken up the &lt;b&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;Eclipse&lt;/span&gt;&lt;/b&gt; team at Google (we integrate Google's internal build tools and distributed development environment with the Eclipse Platform) and we are constantly faced with the challenge of maintaining several distributions in a multi-user environment.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I thought I'd use some of the goodness we've come up with in my home environment too, so have put together a much-scaled-down version of our launch script, for my personal use - and thought I'd share this more broadly, as I'm sure other folks will find this useful too.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I generally have multiple installation and user configuration profiles, and even from the desktop launcher, I much prefer to use launch scripts than just pointing the shortcut to the binary executable.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Here is my generic configuration script:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;#!/bin/bash
#
# Runs the stable version of Eclipse.
# By default, it will launch Indigo, installed in /opt/eclipse; different
# versions can be launched by invoking this script and setting the
# ECLIPSE_INSTALL and CONFIG variables to point to the correct places.
#
# The default configuration directory is set to '/home/$USER/.eclipse/eclipse37'
# but this can be changed exporting a different value for CONFIG.
# See /home/marco/bin/eclipse-helios for an example of how to do this.

##############################
# Globals (default value):
#
#   LD_LIBRARY_PATH           (/usr/local/lib:/usr/lib)
#     library search path for C++ dynamic libraries
#
#   ECLIPSE_INSTALL           ()
#     installation directory
#
#   CONFIG                    ()
#     user's configuration directory
#
#   MEM_ALLOC_POOL, PERM_SIZE (2,048MB, 256MB)
#     Memory allocation and PermGen size
#
#   JVM                       (/usr/local/java/bin/java)
#     Java VM executable (java)
#
# By setting any of the variables above after source`ing this script
# and before invoking launch_eclipse() the default value(s) can be changed
##############################
declare ECLIPSE_INSTALL
declare CONFIG
declare MEM_ALLOC_POOL
declare PERM_SIZE
declare JVM="/usr/local/java/bin/java"

##############################
# Concatenates input paramters to LD_LIBRARY_PATH, if not already present
##############################
munge_library_path() {
  for dir in $@; do
    if [ -n "${dir}" ]; then
      local is_present=`echo $LD_LIBRARY_PATH | grep ${dir} | wc -l`
      if [ ${is_present} -eq 0 ]; then
        export LD_LIBRARY_PATH=${dir}:$LD_LIBRARY_PATH
      fi
    fi
  done
}

##############################
# Sets up global variables with default values if not already set
##############################
check_dirs() {
  # Installation directory
  if [ -z "${ECLIPSE_INSTALL}" ]; then
    echo "You must set ECLIPSE_INSTALL to the Eclipse installation directory"
    exit -1
  fi
  if [ ! -d ${ECLIPSE_INSTALL} ]; then
    echo "Cannot find Eclipse installation directory (${ECLIPSE_INSTALL})"
    exit -1
  fi

  # Configuration directory, user-specific
  if [ ! -d "${CONFIG}" ]; then
    mkdir -p ${CONFIG}
  fi
}


##############################
# The location of the JVM, currently the default (OpenJDK 6)
##############################
locate_jvm() {
  if [ ! -e "${JVM}" ]; then
    echo "Could not locate a valid JVM at ${JVM}"
    echo "Trying to locate a valid java installation"
    JVM=`which java`
    if [ -z "${JVM}" ]; then
      echo "Could not find a valid JRE, giving up"
      return -1
    fi
    echo "Found a JRE at ${JVM}"
  fi
}

##############################
# Runs a few checks, sets up the LD library path and then launches Eclipse
#
# Param:
#   clean   will set the '-clean' Eclipse option that will clear the plugins cache
##############################
launch_eclipse() {
  check_dirs
  locate_jvm
  munge_library_path /usr/local/lib /usr/lib

  if [ "$1" == "clean" ]; then
    CLEAN="-clean"
  fi

  $ECLIPSE_INSTALL/eclipse $CLEAN -vm $JVM -configuration $CONFIG \
      -bundlepool $CONFIG/plugins \
      -vmargs -Xmx${MEM_ALLOC_POOL:-"2048M"} -XX:MaxPermSize=${PERM_SIZE:-"256M"}
}&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This is used in the actual shell script (called, unimaginatively, eclipse):&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;#!/bin/bash
#
# Runs the stable version of Eclipse.
# By default, it will launch Indigo, installed in /opt/eclipse; different
# versions can be launched by invoking this script and setting the
# ECLIPSE_INSTALL and CONFIG variables to point to the correct places.
#
# See eclipse_config.sh for more details

source /home/marco/bin/eclipse_config.sh

ECLIPSE_INSTALL="/opt/eclipse"
CONFIG="/home/${USER}/.eclipse/eclipse37"

launch_eclipse&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;What is left is to just point a desktop (or menu) launcher to this script and replace the generic icon with the one in the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;eclipse/ &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;folder (&lt;i&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;icon.xpm&lt;/span&gt;&lt;/i&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-YfQe8oUS1Ig/TkIjaQtPN3I/AAAAAAAASPk/eorkpYIGl2w/s1600/Indigo+Properties.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="295" src="http://3.bp.blogspot.com/-YfQe8oUS1Ig/TkIjaQtPN3I/AAAAAAAASPk/eorkpYIGl2w/s320/Indigo+Properties.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;CREDITS&lt;/span&gt;&lt;/b&gt; -- I would very much like to gratefully acknowledge&amp;nbsp;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Machtelt Garrels&lt;/span&gt;&lt;/b&gt; and his much-consulted "&lt;a href="http://tille.garrels.be/training/bash/index.html"&gt;Bash Guide for Beginners&lt;/a&gt;;" I never seem able to remember the bash conditional operators!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-1359348416798891241?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/upK7JBOQHLA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/1359348416798891241/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/08/automating-eclipse-launch.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1359348416798891241?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1359348416798891241?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/upK7JBOQHLA/automating-eclipse-launch.html" title="Automating Eclipse launch" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-YfQe8oUS1Ig/TkIjaQtPN3I/AAAAAAAASPk/eorkpYIGl2w/s72-c/Indigo+Properties.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/08/automating-eclipse-launch.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8EQX85cSp7ImA9WhdTEEw.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-6305739246379852766</id><published>2011-07-06T22:50:00.000-07:00</published><updated>2011-07-06T22:50:00.129-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-06T22:50:00.129-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="p2" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="updates" /><title>Eclipse (Indigo) Update site</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kZsGFJtOryed1eTbMho2rZ4kr1A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kZsGFJtOryed1eTbMho2rZ4kr1A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kZsGFJtOryed1eTbMho2rZ4kr1A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kZsGFJtOryed1eTbMho2rZ4kr1A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;When executing a "clean run" of Eclipse (typically, after p2 has completely messed up your installation and you've lost critical functionality / plugins -- the only reliable remedy I've found thus far, is to wipe ~/.eclipse, and restart from scratch) the 'Available Update Sites' is an empty list.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Googling the information proves every time a complete random shot in the dark, so I thought I'd collect the info once and for all in a place I'm likely to find again in the future.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;The wiki page (impossibly difficult to find in the maze that Eclipse documentation is):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;http://wiki.eclipse.org/Eclipse_Project_Update_Sites&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Gives this link for...&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;The Eclipse Project Updates&lt;/b&gt; - http://download.eclipse.org/eclipse/updates/3.7&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Executing an update of the Eclipse Platform, adds another 'update site' that provides a much&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;richer selection of available plugins:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Indigo&lt;/b&gt; - http://download.eclipse.org/releases/indigo&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;Hope this helps someone else too!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-6305739246379852766?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/8kc6MhCMoYQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/6305739246379852766/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/07/eclipse-indigo-update-site.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/6305739246379852766?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/6305739246379852766?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/8kc6MhCMoYQ/eclipse-indigo-update-site.html" title="Eclipse (Indigo) Update site" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/07/eclipse-indigo-update-site.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4GQXY9fCp7ImA9WhZVE00.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-2555470625064754794</id><published>2011-05-24T23:27:00.000-07:00</published><updated>2011-05-24T23:28:40.864-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-24T23:28:40.864-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="kvm" /><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu" /><category scheme="http://www.blogger.com/atom/ns#" term="networking" /><title>Ubuntu: Network Manager is evil</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UgmW2yiGMHAzdf66NLNvVjv3FW4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UgmW2yiGMHAzdf66NLNvVjv3FW4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UgmW2yiGMHAzdf66NLNvVjv3FW4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UgmW2yiGMHAzdf66NLNvVjv3FW4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;Warning&lt;/span&gt;&lt;/b&gt; - this post if filled with hatred, if you believe in forgiveness, you may want to look away now.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In my book, the only sin worse than uselessness, is actively causing damage and waste of time.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;What punishment ought to be meted then, to something that, having proven to be useless, causes untold waste of time.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Yes, &lt;b&gt;NetworkManager&lt;/b&gt;, and &lt;i&gt;nm-applet&lt;/i&gt;: I'm looking at you two.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Quite apart from never having quite understood what use one could have for either, I have found a number of situations in which NM has caused waste of time, only the last of which has been to&lt;span class="Apple-style-span" style="color: purple;"&gt; prevent a KVM virtual machine I just created to connect to the network&lt;/span&gt;, despite all my efforts, searching on the Web, trying out countless variations on configurations and, yes, several reboots.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I have been following along the instructions given &lt;a href="https://help.ubuntu.com/community/KVM/Networking"&gt;here&lt;/a&gt;, only to be unable to connect in UserMode, barely managing (via the Bridged interface) to connect to my host machine, and totally failing to obtain any connection to the outside world.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Enter&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;sudo apt-get purge network-manager network-manager-gnome&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;and, hey, presto, all is good and well, and I can happily connect from my guest OS to the Internet.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;(see also &lt;a href="http://ubuntuforums.org/showthread.php?t=527365"&gt;here&lt;/a&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Simply changed my &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;/etc/network/interfaces&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; file to reflect my settings (YMMV, adjust to your LAN settings) and all works just fine:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto br0
iface br0 inet static
        address 192.168.1.10
        network 192.168.1.0
        netmask 255.255.255.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Just remember to restart the network after you have made the changes:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;sudo /etc/init.d/networking restart&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Die in pain, Network Manager, and may the world be a better place without you.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-2555470625064754794?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/ktEQNO_EZV0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/2555470625064754794/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/05/ubuntu-network-manager-is-evil.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/2555470625064754794?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/2555470625064754794?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/ktEQNO_EZV0/ubuntu-network-manager-is-evil.html" title="Ubuntu: Network Manager is evil" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/05/ubuntu-network-manager-is-evil.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QNQnYyeyp7ImA9WhZVEEk.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-386236372220267091</id><published>2011-05-22T00:26:00.000-07:00</published><updated>2011-05-22T00:29:53.893-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-22T00:29:53.893-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="c++" /><category scheme="http://www.blogger.com/atom/ns#" term="multithreading" /><category scheme="http://www.blogger.com/atom/ns#" term="boost" /><title>Creating a C++ callback function from a class instance method</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/guVRPFpHxIM23GvfmAc0n1ryb54/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/guVRPFpHxIM23GvfmAc0n1ryb54/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/guVRPFpHxIM23GvfmAc0n1ryb54/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/guVRPFpHxIM23GvfmAc0n1ryb54/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
I have been playing around with the &lt;a href='http://boost.org'&gt;Boost library&lt;/a&gt; and, in particular,  the &lt;a href='http://www.boost.org/doc/libs/1_46_1/doc/html/thread.html'&gt;boost::thread&lt;/a&gt; multithreading library.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
There a thread is simply created by constructing an object of type &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;boost::thread&lt;/span&gt;, and passing in to the constructor a pointer to the function to be executed in the newly spawned thread.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
There is much more to it, and I encourage you to read the documentation, but that gave me an interesting opportunity to ponder the issue of how to create a thread by instead passing in a pointer to a class's method: the need typically arises when one does not want to use global variables (which need to be guarded against race conditions) or where parameters are necessary for the execution of the method and/or return values are expected.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
Granted, the boost::thread constructor allows you to pass in up to nine parameters, so that's rarely an issue, but I just wanted to find out a reasonably general way to achieve this; it turns out that this is far from trivial, and I thought I'd share my findings.  &lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
For the impatient, this is the solution:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;template&amp;lt;typename T, typename V, typename R&gt;
class MakeCallback {

  // Member method in T(ype), takes parameter V(alue),
  // and returns an object of type R(esult)
  // Note the parentheses around (T::*): without them, 
  // the compiler gets confused.
  typedef R(T::*func)(const V&amp;);
  func f_;
  T&amp; t_;
  V value_;
  R* res_;
public:
  MakeCallback(T&amp; type, func f, const V&amp; value, R* res = NULL) :
      f_(f), t_(type), value_(value), res_(res) { }
  virtual ~MakeCallback() { }
  void operator()() {
    if (res_)
      // Note here the parenthesis around t_.*f_ 
      // They are necessary, or a compiler error will be generated
      *res_ = (t_.*f_)(value_);
  }

  // This allows the pointer to the result value to
  // be set after the object has been created
  void set_res(R* res) { res_ = res; }
};&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
and this is how one uses it:&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;int main(int argc, char[}* argv) {
  A a(33);
  int res;
  // Generally, you don't need the &amp; operator to take a function's pointer.
  // But in this case it's mandatory, or the compiler will complain
  // about doSomething() not being static.
  // In any event, the use of &amp; makes your intent clearer (you are taking
  // the method's address,
  // not invoking it) and I encourage you to use it consistently, even where
  // this is not stricly necessary.
  MakeCallback&amp;lt&gt;A, int, int&gt; mc(a, &amp;A::doSomething, 22, &amp;res);
  boost::thread do_it(mc);
  do_it.join();
  std::cout &lt;&lt; "And the result is : " &lt;&lt; res &lt;&lt; std::endl;

  B b;
  boost::thread another(MakeCallback&amp;lt;A, std::string, B&gt;(a, &amp;A::doSomethingElse, "22.13", &amp;b));
  another.join();
  std::cout &lt;&lt; "..and B is " &lt;&lt; b.get() &lt;&lt; std::endl;
}&lt;/pre&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;
  given the following declarations for A and B:
&lt;/span&gt;
&lt;pre&gt;class B {
  float x;
public:
  B(float s = 0.0) : x(s) {}
  float get() { return x; }
};

class A {
  int num_;
public:
  A(int num) : num_(num) { }

  int doSomething(const int&amp; k) {
    return num_ + k;
  }

  B doSomethingElse(const std::string&amp; s) {
    double b = ::atof(s.c_str()) + num_;
    return B(b);
  }
};&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;
  A couple of points that have caused me much head-scratching and I thought it worth passing on:
  &lt;ul&gt;&lt;li&gt;you &lt;strong&gt;must&lt;/strong&gt; use the '&amp;amp;' operator in front of &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;A::doSomething&lt;/span&gt;, or the compiler will complain about it not being a static function;&lt;/li&gt;
&lt;li&gt;note we are, in fact, calling an &lt;strong&gt;instance&lt;/strong&gt; method: in other words, we expect to have instance-specific values stored in the class (A in this case) that our method (&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;doSomething()&lt;/span&gt;) will use&lt;/li&gt;
&lt;li&gt;note also the use of a pointer (&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;R* res_&lt;/span&gt;) to store the return value: &lt;strong&gt;this is important&lt;/strong&gt;; without it, the return value of the method call (&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;(t_.*f_)(value_)&lt;/span&gt;) will be lost!&lt;br /&gt;
&lt;br /&gt;
&lt;iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=codtriandtip-20&amp;o=1&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=0321334876" style="width:120px;height:240px;float:right;margin-left:10px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;br /&gt;
This is because, in the call to &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;boost::thread(mc)&lt;/span&gt; the compiler automatically created a copy of our object (using the compiler-generated copy constructor; see Scott Meyer's "Effective C++", Item 5)&lt;/li&gt;
&lt;li&gt;Note also the calls to &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;thread::join()&lt;/span&gt; - without them, you'd have a race on the returned values: possibly reading them, before the actual method (&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;doSomething()&lt;/span&gt;) had any chance of updating it;&lt;br /&gt;
&lt;/ul&gt;&lt;/span&gt; &lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;   Just to be clear, this rather trivial implementation is not meant to be used in real code (if you need something along these lines, &lt;a href='http://www.boost.org/doc/libs/1_46_1/libs/bind/bind.html'&gt;boost::bind&lt;/a&gt; is what you want) but it was an interesting exercise in how to deal with generics, functors and callbacks. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-386236372220267091?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/RcyY7Zoi8lE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/386236372220267091/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/05/creating-c-callback-function-from-class.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/386236372220267091?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/386236372220267091?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/RcyY7Zoi8lE/creating-c-callback-function-from-class.html" title="Creating a C++ callback function from a class instance method" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/05/creating-c-callback-function-from-class.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcAR3k4fSp7ImA9WhZXGEU.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-8057182091117944341</id><published>2011-05-08T11:36:00.000-07:00</published><updated>2011-05-08T11:40:46.735-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-08T11:40:46.735-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="skype" /><category scheme="http://www.blogger.com/atom/ns#" term="audio" /><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu" /><title>Skype on Ubuntu 10.04 - mic doesn't work</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/g1RhzcQLtTBTairYhbaXzQAh5ik/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g1RhzcQLtTBTairYhbaXzQAh5ik/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/g1RhzcQLtTBTairYhbaXzQAh5ik/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g1RhzcQLtTBTairYhbaXzQAh5ik/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I got the following fix from &lt;a href="http://forum.skype.com/index.php?showtopic=468941&amp;amp;st=40"&gt;here&lt;/a&gt;, but it does not tell the entire story:&lt;br /&gt;
(my setup: &lt;i&gt;Acer Aspire One AO751h&lt;/i&gt;, &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Ubuntu Lucid 10.04.2 LTS&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="author_info" style="float: left; font-size: 0.9em; margin-bottom: 25px; margin-left: 0px; margin-right: 0px; margin-top: 15px; padding-bottom: 0px; padding-left: 20px; padding-right: 10px; padding-top: 0px; text-align: left; width: 150px;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #7b7f81;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;ul class="user_details" style="color: #7b7f81; font-size: 0.95em; list-style-image: initial; list-style-position: initial; list-style-type: none; margin-bottom: 1.357em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;li class="title" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 4px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br class="Apple-interchange-newline" /&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="margin-bottom: 0px; margin-left: auto; margin-right: auto; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;ul class="user_controls clear" style="clear: both; color: #2c2c2c; list-style-image: initial; list-style-position: initial; list-style-type: none; margin-bottom: 6px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="post_body" style="line-height: 14px; margin-bottom: 0px; margin-left: 170px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;div class="post entry-content" id="" style="line-height: 21px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 3px; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 15px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;i&gt;I had the same problem on an Acer Timeline for a long time, but the balance trick works.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="bbc_underline" style="font-family: 'Trebuchet MS', sans-serif; text-decoration: underline !important;"&gt;&lt;strong class="bbc" style="font-weight: bold !important;"&gt;&lt;i&gt;Solution:&lt;/i&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;i&gt;A better way than changing the output balance is to use alsamixer or pavucontrol and mute one of the input channels. In alsamixer: F4 to change to recording, left/right to move to microphone, and z or c to mute one channel. In pavucontrol go to the "input devices" tab, unlock the channels, and mute one of the channels.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;i&gt;It seems the normal volume control uses one balance slider for all inputs and outputs together.&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The reality is that two poorly designed (and worse implemented) pieces of software interact in a way to make it virtually impossible for the average user to figure out what's going on:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Pulse Audio -- it still amazes me how a simple problem (enable audio on a PC) could be made so complicated and unusable;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Skype for Linux -- a real disgrace that a company of the might and power of Skype could let us down so badly: I just wish they had the decency of release the software open source, so we could fix it ourselves!&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Be that as it may, in addition to the 'fix' above,&lt;b&gt; you need to also disable the "Allow Skype to adjust mixer levels" in the Sound Options tab of Skype&lt;/b&gt; - otherwise you can see skype continually adjusting your microphone's gain down until it gets to the point of being unaudible.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Leaving it here for future reference: I don't expect Skype to fix this anytime soon!&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-8057182091117944341?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/VFP7eagWsd0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/8057182091117944341/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/05/skype-on-ubuntu-1004-mic-doesnt-work.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/8057182091117944341?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/8057182091117944341?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/VFP7eagWsd0/skype-on-ubuntu-1004-mic-doesnt-work.html" title="Skype on Ubuntu 10.04 - mic doesn't work" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/05/skype-on-ubuntu-1004-mic-doesnt-work.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQAQ3wzcCp7ImA9WhZRFE8.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-1374232657552179531</id><published>2011-04-10T00:25:00.000-07:00</published><updated>2011-04-10T00:25:42.288-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-10T00:25:42.288-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="c++" /><category scheme="http://www.blogger.com/atom/ns#" term="unittest" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="gtest" /><title>Eclipse CDT and Google GTest</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UOx6eQoNya_KwFsoJM8CNR6rGZc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UOx6eQoNya_KwFsoJM8CNR6rGZc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UOx6eQoNya_KwFsoJM8CNR6rGZc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UOx6eQoNya_KwFsoJM8CNR6rGZc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If you have read my &lt;a href="http://codetrips.blogspot.com/2010/05/tabularasa-interworking.html"&gt;previous post&lt;/a&gt; about adding the &lt;a href="http://code.google.com/p/googletest/"&gt;gTest framework&lt;/a&gt; to your C++ project, you are very likely to have spent quite some time scratching your head trying to figure out how to make it play nicely with Eclipse's CDT, and its (let's face it) not terribly well-developed concept of 'Build Configurations'.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Especially coming from Java and the extremely intuitive integration in Eclipse with JUnit, CDT's approach to unit testing leaves a lot to desire.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I will not go through the basic setup necessary to add gTest to your project: please read the &lt;i&gt;Get Started&lt;/i&gt; intro on Google Code, or my previous post; it's pretty trivial anyway.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;However, there are a couple of corrections (or perhaps, CDT 7.0 has fixed some of the limitations that required the workarounds I mentioned there).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Add gtest.a to the Test Configuration that you define for your project&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The best way to add the gTest libraries&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;would be to create a symbolic link from&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;/usr/local/lib &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;to&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;the &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;gtest-dir&gt;/make/gtest.a&lt;/gtest-dir&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;library,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;created by the default install process&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; &lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;$ sudo ln -s make/gtest.a /usr/local/lib/libgtest.a&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;and then add /usr/local/lib to the Linker's library search path (&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-L/usr/local/lib&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;) and&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;libgtest.a&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;to the list of included libraries (&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-lgtest&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;) using Project &amp;gt; Properties:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Mi7PFhN_O7o/TaFOgOb19VI/AAAAAAAAR-o/DZHQiIP2P1U/s1600/Screenshot-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="254" src="http://4.bp.blogspot.com/-Mi7PFhN_O7o/TaFOgOb19VI/AAAAAAAAR-o/DZHQiIP2P1U/s320/Screenshot-1.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Add the includes from gTest to ALL build configurations&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Do this by adding the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;gtest-dir&gt;&lt;/gtest-dir&gt;&lt;/span&gt;&lt;gtest-dir&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;/include/&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; folder to your project's include search path (Project &amp;gt; Properties);&lt;/span&gt;&lt;/gtest-dir&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-GUJkZ8oMcqY/TaFN12AA6hI/AAAAAAAAR-g/hA-pHuFfggA/s1600/Screenshot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="254" src="http://2.bp.blogspot.com/-GUJkZ8oMcqY/TaFN12AA6hI/AAAAAAAAR-g/hA-pHuFfggA/s320/Screenshot.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Now, to make the unit tests run, we need to add a fairly trivial &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;main() &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;method (taken from gTest's &lt;a href="http://code.google.com/p/googletest/wiki/Primer"&gt;Primer doc&lt;/a&gt;):&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;#include "gtest/gtest.h"

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&amp;amp;argc, argv);
  return RUN_ALL_TESTS();
}&lt;/pre&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;along with the normal test fixture(s) in either one or multiple .cc files, whichever way works best for you.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;(personally, I prefer the latter: one C++ class per .cc file, and the associated *_test.cc file alongside - keeps me sane! &amp;nbsp;This, obviously, requires that one just has one main() method in a separate source file, which will drive the entire test suite).&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;However, this will cause trouble when linking with a Debug/Release configuration, and obviously you don't want anyway to ship your code with the tests binaries to bloat it.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This is (in theory) where the 'Build configurations' come into play: just exclude the *_test.cc files from Debug/Release, and equally the file containing the main() method of your program (I like to call those Main.cc and have the bare minimum to get it all started, but nothing more) be excluded from your Test configuration.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;However, if you do that, and hence would not include the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;gtest-dir&gt;/include&lt;/gtest-dir&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; folder to all the Build Configurations (for which this would be rather pointless, as it would only be needed by the Test config) &lt;b&gt;you lose the syntax highlight in all the files that make up your test fixture(s)&lt;/b&gt;: for some reason, excluding a file from even ONE Build Configuration, confuses the hell out of CDT and the editor seems unable to cope even when the Active Configuration is the one (eg, Test) that you actually defined the file to be part of -- this is bizarre, because the various configurations still build correctly and run as expected.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;So here is the workaround (which is not pretty, but looks like it's the only way to keep one's sanity, and adds minimal hassle): just remember to add the gtest/include folder to all the build configurations settings.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;A screenshot of what happens when you go for the "wholesome" approach and exclude from build all the *_test files as well as the gTest includes from the settings for the Debug/Release configurations [note however how the compilation/build completes without errors for the Test config]:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-TujYACne0g4/TaFWKAgi3hI/AAAAAAAAR-s/xfFtdjC1IYA/s1600/Screenshot-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="268" src="http://4.bp.blogspot.com/-TujYACne0g4/TaFWKAgi3hI/AAAAAAAAR-s/xfFtdjC1IYA/s320/Screenshot-2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Let's hope CDT 8.0 comes out soon, alongside XText 2.0 -- all slated to be released along with Indigo (Eclipse 3.7) sometime in June 2011.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-1374232657552179531?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/5ixRKjgryYk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/1374232657552179531/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/04/eclipse-cdt-and-google-gtest.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1374232657552179531?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1374232657552179531?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/5ixRKjgryYk/eclipse-cdt-and-google-gtest.html" title="Eclipse CDT and Google GTest" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-Mi7PFhN_O7o/TaFOgOb19VI/AAAAAAAAR-o/DZHQiIP2P1U/s72-c/Screenshot-1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/04/eclipse-cdt-and-google-gtest.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQCSH4_fSp7ImA9WhZSEU8.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-7226063125073509656</id><published>2011-03-26T00:59:00.000-07:00</published><updated>2011-03-26T00:59:29.045-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-26T00:59:29.045-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mobile" /><title>Mobile templates</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2Ck7fn2cWuSLQCMPrUiW0dDrKXk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2Ck7fn2cWuSLQCMPrUiW0dDrKXk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2Ck7fn2cWuSLQCMPrUiW0dDrKXk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2Ck7fn2cWuSLQCMPrUiW0dDrKXk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;a href="http://chart.apis.google.com/chart?cht=qr&amp;amp;chs=120x120&amp;amp;chl=http%3A%2F%2Fcodetrips.blogspot.com%2F%3Fm%3D1" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="120" src="http://chart.apis.google.com/chart?cht=qr&amp;amp;chs=120x120&amp;amp;chl=http%3A%2F%2Fcodetrips.blogspot.com%2F%3Fm%3D1" width="120" /&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Just enabled "Mobile Templates" for this blog: check it out on your iPad, Android, iPhone, or mobile device: it looks really cool on my HTC Evo!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-7226063125073509656?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/867OSjNq_iQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/7226063125073509656/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/03/mobile-templates.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7226063125073509656?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7226063125073509656?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/867OSjNq_iQ/mobile-templates.html" title="Mobile templates" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/03/mobile-templates.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUIFRHgzcCp7ImA9Wx9WE04.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-5330608398028325659</id><published>2011-01-17T23:58:00.000-08:00</published><updated>2011-01-17T23:58:35.688-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-17T23:58:35.688-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="unittest" /><category scheme="http://www.blogger.com/atom/ns#" term="emulator" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Run Android tests in a connected device</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mEdCVXMny0zUU7nrqv1S04ekQyY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mEdCVXMny0zUU7nrqv1S04ekQyY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mEdCVXMny0zUU7nrqv1S04ekQyY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mEdCVXMny0zUU7nrqv1S04ekQyY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Not quite sure as to why it never occurred to me, but it is totally possible and legal to run unit tests inside a real device, connected to your dev box via a USB cable.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;An obvious advantage is that you are now running your tests in a more "realistic" environment; there are no drawbacks that I can think of (unless your device has some weird 'lockdown' imposed by the manufacturer / cell provider); and...&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;that's when you realize just how much faster than an emulator that is.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;So here's the day's top-tip: if you are in a hurry, and have a lot of unit test you want to run, get that USB cable out!&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-5330608398028325659?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/1NLBUlIAji8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/5330608398028325659/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/01/run-android-tests-in-connected-device.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5330608398028325659?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5330608398028325659?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/1NLBUlIAji8/run-android-tests-in-connected-device.html" title="Run Android tests in a connected device" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/01/run-android-tests-in-connected-device.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EDQ3g4eSp7ImA9Wx9WEEo.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-7735811420018386141</id><published>2011-01-15T00:20:00.000-08:00</published><updated>2011-01-15T00:21:12.631-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-15T00:21:12.631-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mobile" /><category scheme="http://www.blogger.com/atom/ns#" term="GWT" /><category scheme="http://www.blogger.com/atom/ns#" term="modules" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Using the same model classes in Android, GWT and JPA (Part II)</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A7PL5XR2fuJJC8MN6VuIX6ta2ME/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A7PL5XR2fuJJC8MN6VuIX6ta2ME/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A7PL5XR2fuJJC8MN6VuIX6ta2ME/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A7PL5XR2fuJJC8MN6VuIX6ta2ME/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;In a &lt;a href="http://codetrips.blogspot.com/2010/11/using-same-model-classes-in-android-gwt.html"&gt;recent post&lt;/a&gt;, I've demonstrated how one can use the same domain-specific (Model) classes end-to-end, from the Mobile layer, to the GWT Front-End, up to server-side and Persistence layer (JPA).&lt;br /&gt;
&lt;br /&gt;
Recently, I've done a serious refactoring of my &lt;a href="http://sites.google.com/site/androidreceipts/"&gt;Android Receipts&lt;/a&gt; mobile app, using java.net.URIs to keep track of the receipts' images location in the (local) filesystem on the mobile: whilst these are not used at all (and, in fact, have no meaning) on the GWT front-end (although, may "regain" semantics on the server side, where may be needed to track the location of the persisted images) they cause a bit of confusion, as the java.net.URI class is not supported by GWT.&lt;br /&gt;
&lt;br /&gt;
What I then decided to do, was to find out how one could overcome such a problem, and here is what I found.&lt;br /&gt;
&lt;br /&gt;
The key part in replacing a JRE class that GWT does not support is in using &amp;lt;super-source&amp;gt; that does a virtual `chroot` on the directory structure:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;# GwtPlayground/lib/src/com/alertavert/receiptscan/URI.gwt.xml
&amp;lt;module rename-to='ReceiptscanURI'&amp;gt;
  &amp;lt;inherits name='com.google.gwt.user.User'/&amp;gt;
  &amp;lt;!-- Specify the paths for translatable code, by redefining the super-source
       so that the class under jre/java/net/URI will be correctly identified by the
       compiler as java.net.URI
    --&amp;gt;
  &amp;lt;super-source path='jre'/&amp;gt;
&amp;lt;/module&amp;gt;&lt;/pre&gt;&lt;br /&gt;
The URI.java file goes under jre/java/net/ - the GWT compiler will take care of the rest.&lt;br /&gt;
Remember that in URI.java the package is java.net:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;# com/alertavert/receiptscan/jre/java/net/URI.java

// Copyright AlertAvert.com (c) 2011. All rights reserved.
// Created Jan 14, 2011, by M. Massenzio (marco@alertavert.com)

package java.net;

/**
 * Horrible hack to support Receipt's use of java.net.URI location for the
 * actual image file, which is however not supported in GWT code
 */
public interface URI {
  public abstract String getPath();
}&lt;/pre&gt;&lt;br /&gt;
This must be "kept hidden" from Eclipse, or it will flag it as a compilation error (the folder structure and the package declartion won't match).&lt;br /&gt;
&lt;br /&gt;
The GWT compiler only needs access to the source files (and, as far as URI.java is concerned, that's all that's needed too).&lt;br /&gt;
However, both Eclipse and the actual server-side code will need access to the model classes (eg, Receipt.java) and also you want them someplace where it's easy to edit them, and the updates be reflected reasonably quickly in the compiled code (as well as in the running web app).&lt;br /&gt;
&lt;br /&gt;
Keep them in a `linked folder` in your GWT project (to the Android project, where they belong) and add as well a symlink to the source folder:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;$ ls -lad src/com/alertavert/receiptscan/model
  lrwxrwxrwx src/com/alertavert/receiptscan/model -&amp;gt; 
      /workspaces/main/polaris/common/com/alertavert/receiptscan/model&lt;/pre&gt;&lt;br /&gt;
Here, you can place the ReceiptscanModel module:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;# GwtPlayground/lib/src/com/alertavert/receiptscan/ReceiptscanModel.gwt.xml
&amp;lt;module rename-to='ReceiptscanModel'&amp;gt;
  &amp;lt;inherits name='com.google.gwt.user.User'/&amp;gt;
  
  &amp;lt;!-- Mock implementation of java.net.URI which GWT does not support, and
       in fact, is not necessary server-side, but Receipts declares and would break
       GWT compilation.
       This enables the GWT module to compile, and will never be used at runtime.
    --&amp;gt;
  &amp;lt;inherits name='com.alertavert.receiptscan.URI'/&amp;gt;
  
  &amp;lt;!-- No need to specify the entry point class or anything else   --&amp;gt;
  &amp;lt;!-- for that matter: this is only needed so that classes in     --&amp;gt;
  &amp;lt;!-- the .model folder will be incluse in the transitive closure --&amp;gt;
  &amp;lt;!-- of GWT compiler.                                            --&amp;gt;
  &amp;lt;!-- Specify the paths for translatable code                     --&amp;gt;
  &amp;lt;source path='model'/&amp;gt;
&amp;lt;/module&amp;gt;&lt;/pre&gt;&lt;br /&gt;
Last step, is to create a JAR that the GWT compiler will use (needs to be in the classpath of the GWT Eclipse project):&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#!/bin/bash
#
# GwtPlayground/lib/create-jar.sh
#
# Simple script to create JAR file containing the java.net.URI replacement for GWT
# Uses the -C option to descend into the src/ dir before packaging the files.

USAGE="Please enter a version number for the JAR (eg, 1.0)"

if [ -z $1 ]; then
  echo $USAGE
  exit -1;
fi

echo "Creating jar file receiptscan_gwt_model_$1.jar"
jar -cvf receiptscan_gwt_model_$1.jar -C src com &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;/pre&gt;&lt;br /&gt;
Note that every time you edit any of the Java files in the `model` package, the server will need to be restarted (there is a button in Eclipse's GWT Development console that allows you to quickly do so) and the create-jar.sh needs to be re-run, so that the new code is made accessible to the GWT compiler.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-7735811420018386141?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/XTc1LiKrEBQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/7735811420018386141/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2011/01/using-same-model-classes-in-android-gwt.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7735811420018386141?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7735811420018386141?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/XTc1LiKrEBQ/using-same-model-classes-in-android-gwt.html" title="Using the same model classes in Android, GWT and JPA (Part II)" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2011/01/using-same-model-classes-in-android-gwt.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkINQX8zeyp7ImA9WhdWEUw.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-2500102923211265729</id><published>2010-12-23T17:03:00.000-08:00</published><updated>2011-09-03T22:36:30.183-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-03T22:36:30.183-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="icons" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="9-patch" /><title>Android Draw 9-patch seems broken too</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6AW_MGxkaTkaPtymiLg4e5fCuIY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6AW_MGxkaTkaPtymiLg4e5fCuIY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6AW_MGxkaTkaPtymiLg4e5fCuIY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6AW_MGxkaTkaPtymiLg4e5fCuIY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;As far as I can tell, the current release of the Android SDK (R08) ships without the Swing Desktop jar, and this causes &lt;a href="http://developer.android.com/guide/developing/tools/draw9patch.html"&gt;draw9patch&lt;/a&gt; to fail.&lt;/div&gt;&lt;pre&gt;~$ draw9patch &amp;amp;
[2] 52452
~$ Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError:
       org/jdesktop/swingworker/SwingWorker
 at com.android.draw9patch.Application$1.run(Application.java:48)
 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
 at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

[2]+  Done                    draw9patch&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_N9nc9mc5kNI/TRPw0EsRXOI/AAAAAAAARGM/P-0hB0hH1sw/s1600/d9p.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="205" src="http://3.bp.blogspot.com/_N9nc9mc5kNI/TRPw0EsRXOI/AAAAAAAARGM/P-0hB0hH1sw/s320/d9p.png" width="320" /&gt;&lt;/a&gt;The 'fix' is rather simple: just download the JAR for Swing Desktop from &lt;a href="http://download.java.net/javadesktop/swinglabs/releases/0.8/"&gt;here&lt;/a&gt;, and drop the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;swinglabs-0.8.0.jar&lt;/span&gt; file into the &lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;[sdk-install-dir]/tools/lib&lt;/span&gt; folder.&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;The Swing Desktop project can be found &lt;a href="https://javadesktop.dev.java.net/"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;b style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;Update&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; -- Richard just left a comment here and pointed me to &lt;/span&gt;&lt;a href="http://android9patch.blogspot.com/" style="font-family: Verdana, sans-serif;"&gt;his site&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;(&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #0b5394; font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;i&gt;Android 9 Patch&lt;/i&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;) who's got plenty of 9-patch icons that really look awesome, and I thought I'd share the goodness (especially, given he's so kind as to share them at no charge).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;Go check out &lt;a href="http://android9patch.blogspot.com/2011/09/android-9-patch-pack-15-glass-madness.html"&gt;Patch 15&lt;/a&gt;, it's pretty impressive!&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-2500102923211265729?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/2MQtKvsd32Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/2500102923211265729/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/12/android-draw-9-patch-seems-broken-too.html#comment-form" title="10 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/2500102923211265729?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/2500102923211265729?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/2MQtKvsd32Q/android-draw-9-patch-seems-broken-too.html" title="Android Draw 9-patch seems broken too" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_N9nc9mc5kNI/TRPw0EsRXOI/AAAAAAAARGM/P-0hB0hH1sw/s72-c/d9p.png" height="72" width="72" /><thr:total>10</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/12/android-draw-9-patch-seems-broken-too.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkYAR3oycSp7ImA9Wx9QEUk.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-7859025295479868309</id><published>2010-12-23T13:35:00.000-08:00</published><updated>2010-12-23T13:35:46.499-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-23T13:35:46.499-08:00</app:edited><title>Carrier BIlling comes to Android!</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zUwE-S7jMF1Gp0JAHIt1zac55QM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zUwE-S7jMF1Gp0JAHIt1zac55QM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zUwE-S7jMF1Gp0JAHIt1zac55QM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zUwE-S7jMF1Gp0JAHIt1zac55QM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Some of you folks may have recently noticed a little remark at the bottom of an email from the Android Market folks:&lt;/span&gt;&lt;/div&gt;&lt;blockquote style="font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;"&gt;&lt;i&gt;&lt;span style="font-size: small;"&gt;Finally, we wanted to bring to your attention that Android Market now offers a new form of payment for users on the AT&amp;amp;T network -- Direct Carrier Billing. This payment option lets Android users on the AT&amp;amp;T network purchase applications more easily.&lt;/span&gt;&lt;/i&gt;&lt;/blockquote&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;This is an awesome achievement on the part of the Google folks, which integrates payments made by users into their phone bills, if they are AT&amp;amp;T customers: in turn, this enables us (the developers) to receive our payments via fewer user clicks and in a more streamlined way, so as to smooth the path for the user to purchase our Apps.&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;And all that, at virtually no additional complexity for us, which is, I'd say, pretty awesome!&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;I would expect more integrations and more awesomeness in the next few months: stay tuned!&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-7859025295479868309?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/DELj29TtWVc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/7859025295479868309/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/12/carrier-billing-comes-to-android.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7859025295479868309?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7859025295479868309?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/DELj29TtWVc/carrier-billing-comes-to-android.html" title="Carrier BIlling comes to Android!" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/12/carrier-billing-comes-to-android.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck8DSXYzfip7ImA9Wx9REE8.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-5156576634897446216</id><published>2010-12-08T23:32:00.001-08:00</published><updated>2010-12-10T14:41:18.886-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-10T14:41:18.886-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sdk" /><category scheme="http://www.blogger.com/atom/ns#" term="emulator" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Latest update for Android SDK breaks for Ubuntu Karmic</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/O-lkCUGuUDuQu_Jw9smUrI4rkfI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O-lkCUGuUDuQu_Jw9smUrI4rkfI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/O-lkCUGuUDuQu_Jw9smUrI4rkfI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/O-lkCUGuUDuQu_Jw9smUrI4rkfI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;If you have recently updated your Android SDK to R08 (Gingerbread, 2.3) on Linux and are using Ubuntu Karmic, chances are that &lt;a href="http://ubuntuforums.org/showthread.php?t=1640029"&gt;you will not be able to run the emulator&lt;/a&gt;: It will simply die with the following error:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New',Courier,monospace;"&gt;$ ./emulator&lt;br /&gt;
./emulator: /lib32/libc.so.6: version `GLIBC_2.11' not found (required&amp;nbsp;by ./emulator)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;This is caused by an incompatibility with Karmic's installed GLIBC - the new SDK/Emulator works just fine on Lucid.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;The Android team is working on a fix - in the meantime, a workaround is to download the &lt;i&gt;_r07&lt;/i&gt; of the tools from &lt;a href="http://dl.google.com/android/repository/tools_r07-linux.zip"&gt;here&lt;/a&gt;, and replace &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New',Courier,monospace;"&gt;emulator&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt; in the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New',Courier,monospace;"&gt;tools/&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt; folder under the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New',Courier,monospace;"&gt;android_sdk&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt; installation folder.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana,sans-serif;"&gt;A bit hacky, but works.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-5156576634897446216?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/PG6cwHmxqt0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/5156576634897446216/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/12/latest-update-for-android-sdk-breaks.html#comment-form" title="20 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5156576634897446216?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5156576634897446216?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/PG6cwHmxqt0/latest-update-for-android-sdk-breaks.html" title="Latest update for Android SDK breaks for Ubuntu Karmic" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>20</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/12/latest-update-for-android-sdk-breaks.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04ARXwzcSp7ImA9Wx9SEUU.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-8009225103390951215</id><published>2010-11-30T22:38:00.001-08:00</published><updated>2010-11-30T22:45:44.289-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-30T22:45:44.289-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="c++" /><category scheme="http://www.blogger.com/atom/ns#" term="eclipse" /><category scheme="http://www.blogger.com/atom/ns#" term="boost" /><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu" /><title>Using Boost in Ubuntu with Eclipse</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_szGoGJvxFGr9M8WgejpApcJM20/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_szGoGJvxFGr9M8WgejpApcJM20/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_szGoGJvxFGr9M8WgejpApcJM20/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_szGoGJvxFGr9M8WgejpApcJM20/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;Boost&lt;/span&gt;&lt;/b&gt; is an open source library of extremely useful and carefully designed C++ classes and methods ranging from graph algorithms, to regular expressions matching, to multi-threading.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Part of the Boost library was also integrated into the C++ standard as the TR1 set of libraries.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You can learn more about Boost &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://boost.org/"&gt;here&lt;/a&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Using it with Eclipse in Ubuntu is definitely possible, but not straightforward; so I decided to post this simple tip here, to help folk spare some of the grief.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The first step in using Boost in your code is to download the header (.hpp) files and (optionally) source code - the latest release is 1.45 and is available from Boost's website.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In theory, you could compile it, and build the libraries' binaries yourself: by all means, go ahead and do it, but there is an easier way, if you can live with a slightly 'older' version.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Ubuntu 9.10 (Karmic Koala) comes with Boost 1.34 pre-configured (I think, this is, at any rate, the version that I had on my system):&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;$ ls /usr/lib/libboost*
/usr/lib/libboost_date_time-gcc41-1_34_1.so.1.34.1
/usr/lib/libboost_date_time-gcc41-mt-1_34_1.so.1.34.1
/usr/lib/libboost_date_time-gcc42-1_34_1.so.1.34.1
/usr/lib/libboost_date_time-gcc42-mt-1_34_1.so.1.34.1
/usr/lib/libboost_filesystem-gcc41-1_34_1.so.1.34.1
/usr/lib/libboost_filesystem-gcc41-mt-1_34_1.so.1.34.1
/usr/lib/libboost_filesystem-gcc42-1_34_1.so.1.34.1
/usr/lib/libboost_filesystem-gcc42-mt-1_34_1.so.1.34.1
/usr/lib/libboost_iostreams-gcc41-1_34_1.so.1.34.1
/usr/lib/libboost_iostreams-gcc41-mt-1_34_1.so.1.34.1
/usr/lib/libboost_iostreams-gcc42-1_34_1.so.1.34.1
/usr/lib/libboost_iostreams-gcc42-mt-1_34_1.so.1.34.1
/usr/lib/libboost_regex-gcc41-1_34_1.so.1.34.1
/usr/lib/libboost_regex-gcc41-mt-1_34_1.so.1.34.1
/usr/lib/libboost_regex-gcc42-1_34_1.so.1.34.1
/usr/lib/libboost_regex-gcc42-mt-1_34_1.so.1.34.1
/usr/lib/libboost_signals-gcc41-1_34_1.so.1.34.1
/usr/lib/libboost_signals-gcc41-mt-1_34_1.so.1.34.1
/usr/lib/libboost_signals-gcc42-1_34_1.so.1.34.1
/usr/lib/libboost_signals-gcc42-mt-1_34_1.so.1.34.1
/usr/lib/libboost_thread-gcc41-mt-1_34_1.so.1.34.1
/usr/lib/libboost_thread-gcc42-mt-1_34_1.so.1.34.1&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;However, by using Synaptic, you can actually install the more recent&amp;nbsp;1.40.0&amp;nbsp;version:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_N9nc9mc5kNI/TPXlOeoImaI/AAAAAAAAREw/93_PDgRbtV4/s1600/screenshot_001.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="265" src="http://4.bp.blogspot.com/_N9nc9mc5kNI/TPXlOeoImaI/AAAAAAAAREw/93_PDgRbtV4/s320/screenshot_001.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This will install a bunch of &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;libboost_*.so.1.40.0 &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;files into &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;/usr/lib&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;: in order to match the libraries with the header files (and avoid introducing incomprehensible compilation errors at best, and subtle bugs at worst) you should download the matching &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;boost_1_40_0.tar.bz2 &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;from Boost &lt;a href="http://www.boost.org/users/history/"&gt;download archives&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;We would be almost there, were it not for the fact that the&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: monospace; white-space: pre;"&gt;soname &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;does not really comply with the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-l&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; gcc linker option.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In gcc the &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;-L&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; option specifies a 'search directory' (this would not be needed, as /usr/lib is searched for libraries by default) and the -l specifies additional dynamic (.so) or static (.a) libraries: you specify the file to include during the link step by omitting the `lib` prefix and the .so or .a extension.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In other words, if your HelloBoost source uses code from Boost Regex (libboost_regex.so) you would specify it like thus:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;$ gcc -Wall hello_boost.cc -o HelloBoost -lboost_regex&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;You can see where I'm heading with all this: the last step will be to add symbolic links that do away with the soname suffixes of Boost libraries, and all will be well:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;$ ln -s /usr/lib/libboost_regex.so.1.40.0 /usr/lib/libboost_regex.so&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Given that there are in total 24 files for the whole of Boost 1.40, I've done a bit of find &amp;amp; replace magic, and have come up with the following&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;shell file (the other advantage being that, when a later version becomes available for Ubuntu, I will not have to change any of my Eclipse projects setting, but just change the VERSION value in the script):&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;#!/bin/bash
#
# Simple script to enable Boost with simple -l gcc option
# Use: gcc -Wall hello_world.cc -o HelloWorld -lboost_regex
#
# Created by M. Massenzio, 2010-11-30

VERSION=1.40.0

for libname in libboost_date_time \
            libboost_filesystem \
            libboost_graph_parallel  \
            libboost_graph      \
            libboost_iostreams  \
            libboost_math_c99f  \
            libboost_math_c99l  \
            libboost_math_c99   \
            libboost_math_tr1f  \
            libboost_math_tr1l  \
            libboost_math_tr1   \
            libboost_mpi        \
            libboost_prg_exec_monitor \
            libboost_program_options  \
            libboost_python-py25      \
            libboost_python-py26      \
            libboost_regex            \
            libboost_serialization    \
            libboost_signals          \
            libboost_system           \
            libboost_thread           \
            libboost_unit_test_framework \
            libboost_wave \
            libboost_wserialization 
do
  ln -s /usr/lib/$libname.so.$VERSION /usr/local/lib/$libname.so
done
&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The last and final step is to tell Eclipse what to look for when building your binary: right-click on your project's folder (in the C++ Perspective, Project Explorer) then Properties &amp;gt; C/C++ Build &amp;gt; Settings, select GCC C++ Linker &amp;gt; Libraries and add the 'stripped' library names in the option list:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_N9nc9mc5kNI/TPXsQYqpKhI/AAAAAAAARE0/laqqSnXe_mY/s1600/screenshot_001.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="241" src="http://1.bp.blogspot.com/_N9nc9mc5kNI/TPXsQYqpKhI/AAAAAAAARE0/laqqSnXe_mY/s320/screenshot_001.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: x-small;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="color: #990000;"&gt;Note for the curious&lt;/span&gt;: the additional libraries listed there are for Google C++ Unit testing framework, GUnit, available &lt;a href="http://code.google.com/p/googletest/"&gt;here&lt;/a&gt; - you will have to build it, but that's pretty straightforward, resulting in the two libgtest.a and libgtest_main.a libraries - be careful to add those only to your 'Test' configuration and exclude your unit tests from build in your Release/Debug configurations.&lt;/i&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-8009225103390951215?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/IKV-n_KoB30" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/8009225103390951215/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/12/using-boost-in-ubuntu-with-eclipse.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/8009225103390951215?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/8009225103390951215?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/IKV-n_KoB30/using-boost-in-ubuntu-with-eclipse.html" title="Using Boost in Ubuntu with Eclipse" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_N9nc9mc5kNI/TPXlOeoImaI/AAAAAAAAREw/93_PDgRbtV4/s72-c/screenshot_001.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/12/using-boost-in-ubuntu-with-eclipse.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4FQ344eyp7ImA9Wx9WFU0.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-5550377750007618276</id><published>2010-11-23T00:20:00.000-08:00</published><updated>2011-01-19T23:01:52.033-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-19T23:01:52.033-08:00</app:edited><title>Using the same model classes in Android, GWT and JPA</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jn2K5Z9IDYWTeF4P1UXVjmxPMi0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jn2K5Z9IDYWTeF4P1UXVjmxPMi0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jn2K5Z9IDYWTeF4P1UXVjmxPMi0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jn2K5Z9IDYWTeF4P1UXVjmxPMi0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;These days, it is rather common to have a mobile-enabled web service or application, where you essentially enable your users to access the service both via a browser-enable desktop application, as well as from their mobiles whilst on the go.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;It's usually the case that the main business logic, as well as the business Model, are shared between the browser components and your mobile app: however, it is not obvious how to re-use code (or even use the &lt;b&gt;same&lt;/b&gt;&amp;nbsp;source code) when you are essentially using two completely separate SDKs, and even different JREs!&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;In fact, if you are using Google Web Toolkit on the&amp;nbsp;front-end, there's not even a JRE involved: as your classes will be compiled in&amp;nbsp;JavaScript.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;This short video shows how you can actually use the very same source files in all three layers, so that when you make changes (fix bugs, add functionality) the improvements are immediately reflected everywhere - and even better, you avoid subtle bugs that may be caused by inadvertently the code going "out-of-sync" in one of the layer.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The example is based on my &lt;a href="http://sites.google.com/site/androidreceipts"&gt;&lt;b&gt;Android Receipts&lt;/b&gt;&lt;/a&gt; application, which can also be freely downloaded in Android Market.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;object height="344" width="425"&gt;&lt;param name="movie" value="http://www.youtube.com/v/6R9rkaotBHI?hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/6R9rkaotBHI?hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Please let me know what you think, and whether you are finding the videos useful - or you prefer the written word!&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #e06666;"&gt;Update&lt;/span&gt;&lt;/b&gt; &amp;nbsp; &amp;nbsp;Someone commented on the low resolution of the video (480p) as making it difficult to follow: I understand, and, in fact, the original video was at a higher res (&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;720x576, 25 fps)&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;: unfortunately, uploading to YouTube the resolution gets dropped during the transcoding.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Disappointing, I know, but hardly something I can do anything about.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I would suggest instead to see also &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;a href="http://codetrips.blogspot.com/2011/01/using-same-model-classes-in-android-gwt.html"&gt;Part II&lt;/a&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; of this tutorial, which further elaborates on the topic, and provides some code samples.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-5550377750007618276?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/e_3eqEBgJq8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/5550377750007618276/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/11/using-same-model-classes-in-android-gwt.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5550377750007618276?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/5550377750007618276?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/e_3eqEBgJq8/using-same-model-classes-in-android-gwt.html" title="Using the same model classes in Android, GWT and JPA" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/11/using-same-model-classes-in-android-gwt.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ENRnY8eSp7ImA9Wx9TFE0.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-1503185548662149709</id><published>2010-11-20T23:59:00.016-08:00</published><updated>2010-11-21T20:54:57.871-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-21T20:54:57.871-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="sensor data" /><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu" /><category scheme="http://www.blogger.com/atom/ns#" term="temperature" /><title>Dump CPU temperature data to a file in Ubuntu</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/o9KwhAvfWYARJafBJQoj10VdtW4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/o9KwhAvfWYARJafBJQoj10VdtW4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/o9KwhAvfWYARJafBJQoj10VdtW4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/o9KwhAvfWYARJafBJQoj10VdtW4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Update&lt;/span&gt;&lt;/b&gt;: I've figured out that it makes a lot more sense to have a reading of the CPU load to correlate with the temperature reading, so I've added that too using /usr/bin/uptime.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;I have written a very simple Java utility to take readings from the CPU temperature sensors utility (/usr/bin/sensor) and dump it to a CSV file.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Although of fairly limited utility, I just wanted to see how to run a binary from Java and capture its output - and, let's face it, it is a rainy Saturday in Silicon Valley this afternoon and I'd just installed &lt;a href="http://www.amazon.com/gp/product/B000JSFZPS/ref=oss_product"&gt;this new CPU cooler&lt;/a&gt; and just felt like doing some fuzzying around.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;All the code, javadocs and a full working jar are available from &lt;a href="http://www.alertavert.com/home/downloads"&gt;the usual place&lt;/a&gt;, just remember to create a &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;sensor.properties&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;file under a &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;.sensors&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; directory in your home dir.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #cc0000; font-family: Verdana, sans-serif;"&gt;&lt;i&gt;Configuring and Running the program&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The program itself can be run from the command line with:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;$ java -jar sensors_0.1alpha.jar&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;and a simple properties file looks something like:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;# Configuration file for the sensor data storage utility
#
# Created by M. Massenzio, 2010-11-20

sensors.data.file=/home/marco/tempdata/sensors.data.csv
sensors.data.timestamp.format=hh:mm:ss
sensors.cores=2
sensors.interval.msec=60000

# Default is /usr/bin/sensors, change it here if your installation is different
sensors.command=/usr/local/bin/sensors
&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The data is appended at the end of the CSV file, so it's ok to leave the property unchanged between runs, or even have this run regularly from a cron job (you'll have to do a bit of shell magic to find out it PID and have another job kill it after a given time).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Obviously, an improvement to be to have an additional property configuration to have it terminate after a given amount of time (or a set number of readings).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;If you have ideas how to improve this (the obvious next step would be to add a simple JDBC adapter and dump the data on a MySQL database) and/or make changes to the code, please let me know!&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #cc0000; font-family: Verdana, sans-serif;"&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The source code itself is packaged inside the JAR, and consists of a single class, where everything happens, to an extent, just inside the main() method (although, there's a &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Runnable&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; thrown in to be run as a &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;TimerTask&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;, so it's not as banal as it sounds!).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #cc0000; font-family: Verdana, sans-serif;"&gt;&lt;i&gt;Executing an external command&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Running a &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Process&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; from inside Java code, is a simple matter of executing:&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;String sensorProcessLocation = System.getProperty("sensors.command", 
    "/usr/bin/sensors");
Process p = Runtime.getRuntime().exec(sensorProcessLocation);
LineNumberReader reader = new LineNumberReader(
    new InputStreamReader(p.getInputStream()));&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;The last lines captures &lt;i&gt;the output&lt;/i&gt; from the process (I know, blatantly confusing) and you can then use to 'pipe' its output into your code for processing. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;The RegEx to parse the output&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;Although the output from sensors would be pretty easy to parse 'by hand' I thought it much more elegant to use a Regular Expression, and also throw in the concept 'capturing groups' to have an orderly output (although, it's a safe bet sensors will consistently output the temperature readings in 'sorted cores order'):&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;REGEX = "Core([01]).*\\+([0-9.]*).*"&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
will correctly parse output from the version of sensors installed on my distro (Ubuntu 9.10, Karmic Koala):&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;$ lsb_release -a
   No LSB modules are available.
   Distributor ID: Ubuntu
   Description: Ubuntu 9.10
   Release: 9.10
   Codename: karmic
 $ sensors
   k8temp-pci-00c3
   Adapter: PCI adapter
   Core0 Temp:  +42.0°C                                    
   Core1 Temp:  +39.0°C&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;
This is the code that parses the output from sensors, and puts the correct reading in the respective core's array slot:&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;Pattern p = Pattern.compile(System.getProperty("sensors.data.regex", 
             REGEX));
  Matcher m = p.matcher(reading);
  if (m.matches()) {
    int core = Integer.parseInt(m.group(1));
    if (core &amp;lt; coreTemps.length) {
       coreTemps[core] = Float.parseFloat(m.group(2));
     }
  }&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt; The rest of the code (available inside the Jar to download, alongside with the javadoc in the /apidocs folder) is pretty much simple housekeeping. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-1503185548662149709?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/_WUviUXjxh8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/1503185548662149709/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/11/dump-cpu-temperature-data-to-file-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1503185548662149709?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1503185548662149709?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/_WUviUXjxh8/dump-cpu-temperature-data-to-file-in.html" title="Dump CPU temperature data to a file in Ubuntu" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/11/dump-cpu-temperature-data-to-file-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUHRHY8eSp7ImA9Wx5aFUk.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-1739576460252156853</id><published>2010-11-11T23:17:00.000-08:00</published><updated>2010-11-11T23:17:15.871-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-11T23:17:15.871-08:00</app:edited><title>Changing the value returned by getModuleName</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yZ5jE2ohKkRf2M1uESv6Z5obCSs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yZ5jE2ohKkRf2M1uESv6Z5obCSs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yZ5jE2ohKkRf2M1uESv6Z5obCSs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yZ5jE2ohKkRf2M1uESv6Z5obCSs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;When refactoring the name of the GWT module (which typically involves changing the name of the Module.gwt.xml file, see this post) you also have to change the returned value from getModuleName() in every GWTTestCase:&lt;br /&gt;
&lt;p&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/qUgocP0rbdQ?hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/qUgocP0rbdQ?hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;This is way I usually factor the name of the module out into a utility class, and reference a static constant from every test case: saves a lot of pain and effort following some heavy refactoring.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;If you do want to watch the video, here's a few tips:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;if your connection is fast enough, choose 720p as the resolution, or the various menu items and text in general, will be very blurry;&lt;/li&gt;
&lt;li&gt;this is best viewed full-screen;&lt;/li&gt;
&lt;li&gt;a description as to how to create a reusable GWT Module can be found &lt;a href="http://codetrips.blogspot.com/2010/01/writing-gwt-module.html"&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-1739576460252156853?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/WXonC2Wj908" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/1739576460252156853/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/11/changing-value-returned-by.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1739576460252156853?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1739576460252156853?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/WXonC2Wj908/changing-value-returned-by.html" title="Changing the value returned by getModuleName" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/11/changing-value-returned-by.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUDQn8zcCp7ImA9Wx5aFUk.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-3392571120611225018</id><published>2010-11-11T22:27:00.005-08:00</published><updated>2010-11-11T23:17:53.188-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-11T23:17:53.188-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="java" /><category scheme="http://www.blogger.com/atom/ns#" term="GWT" /><title>Change a GWT Module name</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uVzseiAmTlUXRs4izTR6i-e92Ps/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uVzseiAmTlUXRs4izTR6i-e92Ps/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uVzseiAmTlUXRs4izTR6i-e92Ps/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uVzseiAmTlUXRs4izTR6i-e92Ps/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;This is really a trivial how-to, but wanted to try out how easy it was to capture Eclipse's window using xvidcap, and then upload to Youtube and embed the video here.&lt;br /&gt;
&lt;p&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/UW4WSYs1bKE?hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/UW4WSYs1bKE?hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;This was all relatively simple (from having the idea, to blog posted and tested, took around 15 minutes) so I plan to do a few more.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;If you do want to see the video, here's a few tips:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;if your connection is fast enough, choose 720p as the resolution, or the various menu items and text in general, will be very blurry;&lt;/li&gt;
&lt;li&gt;this is best viewed full-screen;&lt;/li&gt;
&lt;li&gt;do remember if you follow along, and you have unit tests, to change the module name there too (or see &lt;a href="http://codetrips.blogspot.com/2010/11/changing-value-returned-by.html"&gt;this video&lt;/a&gt;);&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-3392571120611225018?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/96A7X6n5Wqs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/3392571120611225018/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/11/change-gwt-module-name.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/3392571120611225018?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/3392571120611225018?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/96A7X6n5Wqs/change-gwt-module-name.html" title="Change a GWT Module name" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/11/change-gwt-module-name.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QAQnw4eSp7ImA9Wx5aEUs.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-1139920315243962214</id><published>2010-11-07T13:25:00.001-08:00</published><updated>2010-11-07T13:29:03.231-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-07T13:29:03.231-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="service" /><category scheme="http://www.blogger.com/atom/ns#" term="RPC" /><category scheme="http://www.blogger.com/atom/ns#" term="remote service" /><category scheme="http://www.blogger.com/atom/ns#" term="RMI" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Implementing a Remote Service in Android - Part I</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lGUca50DP5wNIvvLh7JYS99TlXY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lGUca50DP5wNIvvLh7JYS99TlXY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lGUca50DP5wNIvvLh7JYS99TlXY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lGUca50DP5wNIvvLh7JYS99TlXY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;When I decided that a particular idea of mine could be best implemented as an Android Service, running in the background, I found that there is not much information available on the web, beyond some very basic examples, android.com's &lt;a href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/RemoteService.html"&gt;API Demo sample&lt;/a&gt;, and the &lt;a href="http://developer.android.com/guide/developing/tools/aidl.html"&gt;AIDL tutorial page&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
However, those are rather "sparse" guidelines, and several gaps are left for oneself to fill out by trial and error: so I decided to post this brief how-to, along with &lt;a href="https://www.alertavert.com/home/downloads"&gt;the code&lt;/a&gt; itself.&lt;br /&gt;
&lt;br /&gt;
As &lt;a href="http://developer.android.com/guide/topics/fundamentals.html#appcomp"&gt;noted&lt;/a&gt; in the Android Developer's guide:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the &lt;b&gt;Service&lt;/b&gt; base class.&lt;/blockquote&gt;&lt;br /&gt;
There are actually &lt;b&gt;two&lt;/b&gt; ways of implementing a service: one is to just extend the &lt;a href="http://developer.android.com/reference/android/app/Service.html"&gt;Service&lt;/a&gt; class, implement the onBind() method and then implement the &lt;a href="http://developer.android.com/reference/android/os/Binder.html"&gt;Binder&lt;/a&gt; interface in your service implementation class (this is the approach described here); the other is to use AIDL (Android Interface Description Language), followed by the API Demo sample (and further described in Part II of this blog - coming soon).&lt;br /&gt;
&lt;br /&gt;
So, here we go: let's assume that we want to implement a simple service, which enables developers to add a simple UI element to their app to allow delighted users to make donations, but freeing them from having to implement all the machinery: our service will take a Developer Key and an Amount value ($ cents), and will credit the amount to the developer's account (we assume that the user's credentials can be retrieved from the system - how to do that is outside the scope of this blog); the app developer herself will only have to implement a simple UI (or a fancy complicated one: that's up to her) and connect to our service.&lt;br /&gt;
&lt;br /&gt;
The service class definition is pretty trivial:&lt;br /&gt;
&lt;pre&gt;public class DonateService extends Service {
  @Override
  public IBinder onBind(Intent intent) {
    return new DonateServiceImpl(getResources());
  }
}&lt;/pre&gt;&lt;br /&gt;
The service implementation itself is rather simple too:&lt;br /&gt;
&lt;pre&gt;public class DonateServiceImpl extends Binder { ... }&lt;/pre&gt;with all the 'action' being in its onTransact() method:&lt;br /&gt;
&lt;pre&gt;@Override
  protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) {
    if (code != res.getInteger(R.id.SERVICE_CODE)) {
      Log.e(getClass().getSimpleName(), "Transaction code should be " +
          res.getInteger(R.id.SERVICE_CODE) + ";" + " received instead " + code);
      return false;
    }
    Bundle values = data.readBundle();
    String devKey = values.getString(res.getString(R.string.DEV_KEY));
    int amountInCents = values.getInt(res.getString(R.string.AMT));
    Log.i(getClass().getSimpleName(), getUser() + " wants to donate " +
        amountInCents + " to " + devKey);
    if (amountInCents &amp;lt;= 0) {
      Log.e(getClass().getSimpleName(), "Amount should be a positive integer (" +
          amountInCents + " is not).");
      return false;
    }
    Log.d(getClass().getSimpleName(), "Sending request to server");
    // This is where we would implement our HTTPS connection service, most likely to
    // some RESTful service
    
    return true;
  }&lt;/pre&gt;&lt;br /&gt;
And this is pretty much all there is to it, as far as it concerns to handling a service call (please do read the description on the Service class, as well as the notes about a &lt;a href="http://developer.android.com/reference/android/app/Service.html#ServiceLifecycle"&gt;service's lifecycle&lt;/a&gt;: similar to an Activity, there is an onCreate(), onDestroy() etc.) and retrieving the data marshalled by the system, from the calling Activity.&lt;br /&gt;
&lt;br /&gt;
If you now try to 'test' it by using the Android Instrumentation framework from a 'sibling' test project (you create one typically at the same time as you create a new Android project in Eclipse), your code should look something like this:&lt;br /&gt;
&lt;pre&gt;public void testServiceRuns() {
    Resources myRes = getContext().getResources();
    assertNotNull("The test case resources are null", myRes);
    
    Intent i = new Intent(ACTION);
    IBinder binder = bindService(i);
    assertNotNull(binder);
    
    Bundle values = new Bundle();
    values.putString(myRes.getString(R.string.DEV_KEY), "12345ABCDE");
    values.putInt(myRes.getString(R.string.AMT), 99);
    Parcel data = Parcel.obtain();
    data.writeBundle(values);
    
    try {
      int serviceCode = myRes.getInteger(R.id.SERVICE_CODE);
      assertTrue(binder.transact(serviceCode, data, null, 0));
      Log.i("test", "Service executed successfully");
    } catch (Exception ex) {
      Log.e("test", "Could not transact service: " + ex.getLocalizedMessage(), ex);
      fail(ex.getLocalizedMessage());
    };
  }&lt;/pre&gt;&lt;br /&gt;
Funnily enough, this will work even if you mistype the name of the service's implementation class in the Android Manifest (AndroidManifest.xml):&lt;br /&gt;
&lt;pre&gt;&amp;lt;application android:label="@string/service_label" 
                     android:icon="@drawable/app_icon"&amp;gt;
   &amp;lt;service android:exported="true" 
            android:name=".DonateService"
            android:process=":remote"&amp;gt;
      &amp;lt;intent-filter&amp;gt;
         &amp;lt;action android:name="@string/ACTION_DONATE" /&amp;gt;
      &amp;lt;/intent-filter&amp;gt;
   &amp;lt;/service&amp;gt;
&amp;lt;/application&amp;gt;&lt;/pre&gt;&lt;br /&gt;
(try changing .DonateService to .blah and this will still work) -- all this to say: the mechanics of Android unit testing are different from a remote invocation, and may succeed even though your service may be unavailable to other applications.&lt;br /&gt;
&lt;br /&gt;
Notice in particular android:process=":remote" - this is what tells Android application manager to lookup your service's intent-filter too, when looking for possible targets, when another process invokes startService(Intent).&lt;br /&gt;
&lt;br /&gt;
Finally, your test case should extends ServiceTestCase&lt;donateservice&gt; - but make sure you change the constructor, from Eclipse's auto-generated one to something like this:&lt;br /&gt;
&lt;/donateservice&gt;&lt;br /&gt;
&lt;pre&gt;&lt;a href="http://1.bp.blogspot.com/_N9nc9mc5kNI/TNcYmYW8bsI/AAAAAAAAAnY/-RbzkKKovnM/s1600/screenshot_002.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/_N9nc9mc5kNI/TNcYmYW8bsI/AAAAAAAAAnY/-RbzkKKovnM/s320/screenshot_002.png" width="216" /&gt;&lt;/a&gt;public DonateServiceBinderTest(String name) {
    super(DonateService.class);
    setName(name);
  }&lt;/pre&gt;as explained &lt;a href="http://codetrips.blogspot.com/2010/06/unit-testing-android-activity.html"&gt;elsewhere&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;intent-filter&amp;gt; is the trick that does all the magic here: when matched against the Intent's 'action' will cause your service to be invoked.&lt;br /&gt;
Which brings us to the next topic: how do we invoke the service from a separately developed, completely independent application?&lt;br /&gt;
&lt;br /&gt;
I have created a very simple Activity (download &lt;a href="https://sites.google.com/a/alertavert.com/main/home/downloads"&gt;service_example_usage-0.2_beta&lt;/a&gt; from our site) that does exactly that.&lt;br /&gt;
&lt;br /&gt;
In the following, I will largely ignore the niceties of building an Android UI, as these are widely explained elsewhere and are largely outside the scope of this post, and will focus instead on the specifics of calling a Service.&lt;br /&gt;
&lt;br /&gt;
As a general rule, when invoking a Service, you must do it outside of your primary UI thread: for starters, you have no idea how long will it take to complete and, secondly, you want to give the users the ability to terminate it, should it take too long.&lt;br /&gt;
&lt;br /&gt;
Hence:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;Rule #1&lt;/b&gt; - execute a service invocation from within a Runnable that executes outside your main UI thread, and set up the service call, so that it has a &lt;i&gt;callback&lt;/i&gt; handler;&lt;/blockquote&gt;&lt;br /&gt;
Which neatly leads to &lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;&lt;b&gt;Rule #2&lt;/b&gt; - to handle the service outcome where this needs to influence changes in the UI (and it most likely will, even for the trivial task of notifying the user that the call succeeded/failed, whatever...) use a &lt;a href="http://developer.android.com/reference/android/os/Handler.html"&gt;&lt;span class="Apple-style-span" style="color: black;"&gt;Handler&lt;/span&gt;&lt;/a&gt;, or your app will crash unceremoniously.&lt;/blockquote&gt;&lt;br /&gt;
Let us dissect the code in &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;SimpleApplication.java&lt;/span&gt; (&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;activateService(final int amt)&lt;/span&gt;) one step at a time:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt; 1. Visually notify the user that we're engaging in something that will take time to complete&lt;/i&gt;, and we aren't quite sure how long:&lt;br /&gt;
&lt;pre&gt;LinearLayout panel = (LinearLayout) findViewById(R.id.ProgressPanel);
    panel.setVisibility(View.VISIBLE);&lt;/pre&gt;&lt;br /&gt;
the progress bar has been defined in the layout/main.xml file as 'indeterminate' and as a spinning wheel:&lt;br /&gt;
&lt;pre&gt;&amp;lt;ProgressBar android:id="@+id/ProgressBar" android:layout_height="wrap_content" 
                android:layout_marginLeft="15px" android:layout_width="wrap_content"
                android:indeterminate="true" android:indeterminateBehavior="repeat" 
                android:visibility="visible"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;i&gt; 2. Create an intent, whose action will match the service's action's &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;intent-filter&lt;/span&gt;&lt;/i&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; &lt;/span&gt;(see note below&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: #38761d;"&gt;[*]&lt;/span&gt;&lt;/span&gt;&lt;/b&gt; regarding sharing common strings between the service and its intended users):&lt;br /&gt;
&lt;pre&gt;Intent i = new Intent(getResources().getString(R.string.ACTION_DONATE));&lt;/pre&gt;&lt;br /&gt;
&lt;i&gt; 3. Using this Activity's Context, bind it to a service that can service this Intent&lt;/i&gt;, by providing an implementation of a ConnectionService interface:&lt;br /&gt;
&lt;pre&gt;boolean isConnected = bindService(i, new ServiceConnection() {
     @Override
     public void onServiceConnected(ComponentName name, IBinder service) {
       Bundle values = new Bundle();
       values.putString(getResources().getString(R.string.DEV_KEY),
           getResources().getString(R.string.DEVELOPER_KEY_VALUE));
       values.putInt(getResources().getString(R.string.AMT), amt);
       Parcel data = Parcel.obtain();
       data.writeBundle(values);
       boolean res = false;
       try {
         res = service.transact(serviceCode, data, null, 0);
       } catch (RemoteException ex) {
         Log.e("onServiceConnected", "Remote exception when calling service", ex);
         res = false;
       }
       Message msg = Message.obtain(h, serviceCode, amt, (res ? 1 : -1));
       msg.sendToTarget();
     }

     @Override
     public void onServiceDisconnected(ComponentName name) {
     }
   }, Context.BIND_AUTO_CREATE);&lt;/pre&gt;&lt;br /&gt;
&lt;i&gt; 4. Wrap the above into a Runnable&lt;/i&gt;, and then kick the Thread alive:&lt;br /&gt;
&lt;pre&gt;Thread serviceThread = new Thread(new Runnable() {
     @Override
     public void run() { //... }
   });
   serviceThread.start();&lt;/pre&gt;&lt;br /&gt;
&lt;i&gt; 5. To enable this newly created thread to 'callback' your activity and carry out tasks inside the UI thread, you need to implement a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Handler&lt;/span&gt; class&lt;/i&gt;, create a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Message&lt;/span&gt; to wrap your returned results and then configure your handler as the message's target:&lt;br /&gt;
&lt;pre&gt;// outside the Runnable:
  final Handler h = new ServiceCompleteHandler(result, panel, ctx);
// this will be invoked inside the UI thread when called
// at the end of onServiceConnected, in the service activation thread
  Message msg = Message.obtain(h, serviceCode, amt, (res ? 1 : -1));
  msg.sendToTarget();&lt;/pre&gt;&lt;br /&gt;
Your Handler needs to override the default &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;handleMessage() &lt;/span&gt;method (that does nothing otherwise) and will be run by the System inside your UI thread (and will thus have access to your Activity's widgets, without causing a &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;RuntimeException&lt;/span&gt;):&lt;br /&gt;
&lt;pre&gt;public static class ServiceCompleteHandler extends Handler {
  @Override
  public void handleMessage(Message msg) {
    int amt = msg.arg1;
    boolean outcome = msg.arg2 &amp;gt; 0;
    serviceComplete(amt, outcome);
  }

  void serviceComplete(int amt, boolean outcome) {
    panel.setVisibility(View.INVISIBLE);
    Rect r = new Rect(0, 0, 48, 48);
    Drawable icon;
    if (outcome) {
      icon = getResources().getDrawable(R.drawable.accepted_48);
    } else {
      icon = getResources().getDrawable(R.drawable.cancel_48);
    }
    icon.setBounds(r);
    result.setCompoundDrawables(icon, null, null, null);
    int dollars = amt / 100;
    int cents = amt % 100;
    result.setText(getResources().getString(outcome ? 
        R.string.thanks : R.string.sorry) + dollars +
        "." + cents + "\n" + getResources().getString(R.string.promo));
    result.setVisibility(View.VISIBLE);
  }
}&lt;/pre&gt;&lt;br /&gt;
And this is pretty much all there is to it: sure, it's a bit more convoluted than just invoking a method in class, but we're talking here inter-process communication (IPC) and remote invocation (RMI) and they ain't pretty in any of the other frameworks either (think J5EE or, God forbid, CORBA).&lt;br /&gt;
&lt;br /&gt;
In a subsequent post, I will show how to use AIDL to make invoking the service a more painless experience for the clients, but at the cost of having a slightly more convoluted development process on the service implementation's side.&lt;br /&gt;
---&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: #38761d;"&gt;[*]&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;A note about re-using common strings (see the file &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;res/values/donate_service_strings.xml&lt;/span&gt;): it is good practice &lt;b&gt;not&lt;/b&gt; to use hard-coded strings in your service calls and data maps, and even better to have them in a commonly shared file (instead of duplicated everywhere in each applications &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;strings.xml&lt;/span&gt; file).&lt;br /&gt;
&lt;br /&gt;
Ideally, if you publish a service, you should make such a file freely available to your service users (eg, downloadable from your API docs site's pages); equally, if you use a service, either use the available strings file (hopefully made available from your provider -- if they don't, question your desire to use their service...) or partition those service-specific strings in its ownd dedicated file.&lt;br /&gt;
&lt;bold&gt; &lt;/bold&gt;&lt;br /&gt;
&lt;bold&gt;&lt;b&gt;Eclipse users&lt;/b&gt;:&lt;/bold&gt; while developing your service, you will certainly want to test it out with a simple app (very much like I describe here).  The obvious way to heed the above advice would then be to add the 'strings' file as a "link" in Eclipse Package Explorer, so that any changes made during the service development, would be automatically picked up the 'testing' app.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;This won't work&lt;/b&gt; (Android's plug-in does not pick linked .&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;xml&lt;/span&gt; files in the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;res/...&lt;/span&gt; tree, to generate the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;R.java&lt;/span&gt; file).  A simple workaround would be to create a soft link to the one file in the &lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;res/values/&lt;/span&gt; directory: &lt;br /&gt;
&lt;pre&gt;$ ln -s ../DonateService/res/values/donate_service_strings.xml res/values/service_defs.xml&lt;/pre&gt;(you can give whatever name you wish to the link).&lt;br /&gt;
In the downloadable code, I've added a physical copy to the file in each package, to avoid people having troubles when re-using it: if you do use both to follow along and/or make changes, I recommend removing one copy and making a link as suggested here.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-1139920315243962214?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/tzITP-N278c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/1139920315243962214/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/11/implementing-remote-service-in-android.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1139920315243962214?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/1139920315243962214?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/tzITP-N278c/implementing-remote-service-in-android.html" title="Implementing a Remote Service in Android - Part I" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_N9nc9mc5kNI/TNcYmYW8bsI/AAAAAAAAAnY/-RbzkKKovnM/s72-c/screenshot_002.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/11/implementing-remote-service-in-android.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkEEQHw6fCp7ImA9WxFWGEs.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-7264992768521257523</id><published>2010-06-06T14:22:00.001-07:00</published><updated>2010-06-06T14:43:21.214-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-06-06T14:43:21.214-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="unittest" /><category scheme="http://www.blogger.com/atom/ns#" term="mobile" /><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Unit testing Android Activity</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gG-A3MMbNoQV_MOqf_MKuiMqUzU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gG-A3MMbNoQV_MOqf_MKuiMqUzU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gG-A3MMbNoQV_MOqf_MKuiMqUzU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gG-A3MMbNoQV_MOqf_MKuiMqUzU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;As I mentioned &lt;a href="http://codetrips.blogspot.com/2010/04/jmock-on-android.html"&gt;earlier&lt;/a&gt;, testing on Android is not for the faint-hearted (or the man-in-a-hurry) - documentation is very thin on the ground (although I've recently seen appear a &lt;a href="http://developer.android.com/guide/topics/testing/testing_android.html"&gt;few testing-related articles&lt;/a&gt; in the Developer documentation for the latest SDK - haven't checked them out yet, though) and the API is cumbersome at the best of times (and outright misleading, at the worst).&lt;br /&gt;&lt;br /&gt;The "master class" to test an &lt;span style="font-family: Courier;"&gt;Activity&lt;/span&gt; class &lt;span style="font-family: Courier;"&gt;MyActivity&lt;/span&gt;, is &lt;a style="font-family: Courier;" href="http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html"&gt;ActivityInstrumentationTestCase2&lt;/a&gt;&lt;span style="font-family: Courier;"&gt;&amp;lt;MyActivity&amp;gt;&lt;/span&gt; that instruments and initializes it.&lt;br /&gt;&lt;br /&gt;Its documentation is marginally better than that for &lt;a href="http://developer.android.com/reference/android/test/package-summary.html"&gt;android.test&lt;/a&gt; package:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-left: 40px;"&gt;&lt;span style="font-style: italic;"&gt;A framework for writing Android test cases and suites.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;but, hey, we haven't set the bar too high here.&lt;br /&gt;&lt;br /&gt;Here are a few 'top tips' as how to avoid some of the grief, that I've discovered whilst developing unit tests for my &lt;a style="color: rgb(255, 153, 0); font-weight: bold;" href="http://sites.google.com/site/androidreceipts"&gt;AndroidReceipts&lt;/a&gt; application:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Do not use the 'default' constructor, but the one that uses ActivityUnitTest(String)&lt;/span&gt;&lt;br /&gt;In Eclipse, you can right-click on a class in the project explores and then select &lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;New/Other...&lt;/span&gt; to create a new &lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;JUnit TestCase&lt;/span&gt;: in the ensuing dialog box, then select &lt;span style="font-family: Courier;"&gt;ActivityInstrumentationTestCase2&lt;/span&gt; as the 'super' class, the plugin will helpfully auto-generate the full class with the following constructor:&lt;br /&gt;&lt;pre&gt;// DON'T DO THIS - it won't compile&lt;br /&gt;public MyActivityTest(String name) {&lt;br /&gt;  super(name);&lt;br /&gt;}&lt;/pre&gt;Here, Eclipse will (correctly) complain that there is no such thing as a ActivityInstrumentationTestCase2(String name) and you will quickly figure out that a (possible) super call may be something like this:&lt;br /&gt;&lt;pre&gt;// DON'T DO THIS - it won't work&lt;br /&gt;public MyActivityTest(String name) {&lt;br /&gt;  super(PKG_NAME, MyActivity.class);&lt;br /&gt;}&lt;/pre&gt;This will, sadly, cause the test runner (&lt;a style="font-family: Courier;" href="http://developer.android.com/reference/android/test/InstrumentationTestRunner.html"&gt;android.test.InstrumentationTestRunner&lt;/a&gt;) to happily ignore your test class:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-left: 40px; color: rgb(255, 0, 0); font-family: Courier;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;[2010-06-06 22:33:20 - PolarisTest] Test run failed: Test run incomplete. Expected 51 tests, received 4&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;the trick is to add a call to &lt;span style="font-family: Courier; color: rgb(0, 0, 0);"&gt;setName(name)&lt;/span&gt; so that the test runner will find your tests (&lt;span style="font-family: Courier;"&gt;name&lt;/span&gt;, incidentally, is the name of the method being run).&lt;br /&gt;&lt;pre&gt;// Do this instead:&lt;br /&gt;public ScanActivityTest(String name) {&lt;br /&gt;  // NOTE -- API Level 8 have deprecated this constructor, and replaced with one that simply takes the Class&amp;lt;T&amp;gt; argument&lt;br /&gt;  super(PKG_NAME, MyActivity.class);&lt;br /&gt;  setName(name);&lt;br /&gt;}&lt;/pre&gt;If you are using the SDK 2.2 (L8) version, then there appears to be a new constructor that only takes the name of the Activity's Class under test (while the constructor shown above is deprecated): I have not tried it out, and targetting L8 devices, at the moment, rather severely &lt;a href="http://developer.android.com/resources/dashboard/platform-versions.html"&gt;restricts your target market&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Beware of Eclipse (ADB) missing a change in project source&lt;/span&gt;&lt;br /&gt;The typical cycle is to write some code, run the tests, make changes, run the tests again.&lt;br /&gt;&lt;br /&gt;This generally works, but, from time to time (I've been unable to discern a pattern) ADB misses a change in your source code and just re-runs the same tests as before.&lt;br /&gt;As this typically happens when you make changes to the 'main' project (as opposed to the 'test' one) I suspect this happens when you do not save the modified source file, this in turn does &lt;span style="font-weight: bold;"&gt;not&lt;/span&gt; trigger a re-build of the APK, which change would have been picked up by the deployer of the 'test' project.&lt;br /&gt;&lt;br /&gt;Be that as it may, keep an eye on the Console view and check that the a new version of the APK for the 'main' or 'test' (or both) projects gets installed on the emulator.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;If you 'remove' the app manually, you also must 'clean' the project&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;On the same token, at times it turns out that the only way to get ADT out of its own hole, is just to go into the Emulator's &lt;span style="color: rgb(102, 102, 102); font-style: italic; font-weight: bold;"&gt;Settings/Applications/Manage Applications&lt;/span&gt; and just remove either or both of the installed projects.&lt;br /&gt;&lt;br /&gt;This will make the test runner deeply unhappy, and it will manifest its unhappiness by refusing to deploy the APKs and giving out an &lt;br /&gt;&lt;br /&gt;&lt;div style="margin-left: 40px;"&gt;&lt;span style="font-family: Courier;"&gt;[2010-06-06 19:28:31 - PolarisTest] Application already deployed. No need to reinstall.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;  &lt;br /&gt;The one way to quickly 'fix' this is to go into &lt;span style="font-weight: bold; color: rgb(102, 102, 102);"&gt;Project/Clean...&lt;/span&gt; and clean one or both of the projects.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The default tearDown() calls on onPause() (but not onStop() and even less onDestroy())&lt;/span&gt;&lt;br /&gt;Well, I was surprised to find that out - it would have been reasonable to expect the test fix to run through the whole &lt;a href="http://developer.android.com/guide/topics/fundamentals.html#actlife"&gt;Activity lifecycle&lt;/a&gt;, and shut it down "gracefully.&lt;br /&gt;&lt;br /&gt;In case you have some 'session management' (and who doesn't these days, in a serious Android app? you want to preserve state so that the user can come back to your app and find it exactly the way she left it) this may cause some surprising results when testing.&lt;br /&gt;&lt;br /&gt;Considering that, in the Android process management system, there is no guarantee of a 'graceful shutdown' (essentially the scheduler wants to feel free to kill your proces without having to wait for your app to get itself sorted out -- and quite rightly so: we don't want a "Windows Experience" where some poorly-paid and even less-trained programmer can bring the whole system to its knees by sheer incompetence) this is just as well: in fact, the more I look into it, the more I find myself doing state management in the &lt;span style="font-style: italic; color: rgb(102, 102, 102);"&gt;onPause / onCreate / onRestart&lt;/span&gt; lifecycle methods, and essentially ignoring the &lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;onStop&lt;/span&gt; and &lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;onDestroy&lt;/span&gt; (in particular the latter, I wonder sometimes why it's there at all)&lt;br /&gt;&lt;br /&gt;Whatever, words to the wise: your Activity's &lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;onStop/onDestroy&lt;/span&gt; won't be called, unless you do it yourself.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Unit test run concurrently, but, apparently, &lt;span style="color: rgb(102, 102, 102);"&gt;@UiThreadTest &lt;/span&gt;prevents this for the UI thread&lt;/span&gt;&lt;br /&gt;I must confess I'm not entirely clear about the full implications of using the &lt;span style="color: rgb(102, 102, 102); font-weight: bold;"&gt;@UiThreadTest&lt;/span&gt; annotation (apart from ensuring that the tests will run sequentially in the UI thread, thus avoiding a predictable chaos if they were all allowed to try to access UI resources concurrently) but one fundamental implication of this is that &lt;a href="http://developer.android.com/reference/android/test/InstrumentationTestCase.html#sendKeys%28java.lang.String%29"&gt;&lt;span style="font-family: Courier;"&gt;sendKeys&lt;/span&gt;&lt;/a&gt; cannot be called from within a test that is annotated with the @UiThreadTest.&lt;br /&gt;&lt;br /&gt;Despite the documentation being conspicuosly silent about this &lt;span style="font-style: italic;"&gt;minor&lt;/span&gt; detail, it turns that it must &lt;span style="font-weight: bold;"&gt;not&lt;/span&gt; be run in the UI thread; all we know about this method is that&amp;nbsp; "&lt;span style="font-style: italic; color: rgb(102, 102, 102);"&gt;Sends a series of key events through instrumentation and waits for idle&lt;/span&gt;." - whatever that means, the bottom line is that it does not return and your test will eventually fail with a timeout exception.&lt;br /&gt;&lt;br /&gt;From my limited experimentation, the only workaround is to either use it only in tests thare are annotated with something such as &lt;span style="color: rgb(102, 102, 102);"&gt;@SmallTest&lt;/span&gt; or similar (but not &lt;span style="color: rgb(102, 102, 102);"&gt;@UiThreadTest&lt;/span&gt;) or to make it run in a separate thread (just create a Runnable that will execute once you are sure the UI elements have been initialized - critically, the layout has been 'inflated').&lt;br /&gt;&lt;br /&gt;And, on this topic...&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-family: Courier;"&gt;Activity.findViewById(id)&lt;/span&gt; - only use after you have 'inflated' the View (typically, by calling the setContentView() on an &lt;span style="font-family: Courier; color: rgb(102, 102, 102);"&gt;R.layout.my_layout&lt;/span&gt; resource)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Nothing much to add here, really, just be careful about how you sequence your asserts, if you need to verify conditions on UI elements (typically, &lt;span style="font-family: Courier;"&gt;Widgets&lt;/span&gt;) as the &lt;span style="font-family: Courier;"&gt;findViewById&lt;/span&gt; will invariably return &lt;span style="font-weight: bold;"&gt;null&lt;/span&gt; until the view is 'inflated' from the XML (if this is, indeed, the way you build your &lt;span style="font-family: Courier;"&gt;View&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;On a similar note, I've found the &lt;span style="font-family: Courier;"&gt;Window.getCurrentFocus()&lt;span style="font-family: Arial;"&gt; (&lt;/span&gt;&lt;/span&gt;and similarly, &lt;span style="font-family: Courier;"&gt;Activity.getCurrentFocus()&lt;/span&gt;) pretty much useless: naively, I thought that, once the Layout had been inflated, the 'focused window' would have been the main container (or some random widget therein: that would have worked for my tests): in fact, this call most invariably returns &lt;span style="font-weight: bold;"&gt;null&lt;/span&gt; (unless, I presume, you &lt;span style="font-style: italic;"&gt;sendKeys&lt;/span&gt; to move the focus where you want it to be: this is rather cumbersome, in my opinion, and makes the tests rather brittle and too tightly coupled with the UI layout, which, in my book anyway, is A Bad Thing).&lt;br /&gt;&lt;br /&gt;So, here is what I do instead:&lt;br /&gt;&lt;pre&gt;	@UiThreadTest&lt;br /&gt;	public void testOnDisplayReceipts() {&lt;br /&gt;  	  Receipt r = new Receipt();&lt;br /&gt;	  instance.accept(r);&lt;br /&gt;	  instance.onDisplayReceipts();&lt;br /&gt;	  assertNotNull(instance.mGallery);&lt;br /&gt;&lt;br /&gt;	  // verifies that the Gallery view has been 'inflated'&lt;br /&gt;	  View gallery = instance.findViewById(R.id.gallery_layout);&lt;br /&gt;	  assertNotNull(gallery);&lt;br /&gt;	}&lt;/pre&gt;&lt;br /&gt;Ok, it's not pretty, I'll give you that, but it works (and is rather independent of what I do in my Gallery view, what widgets are there and how they are arranged).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Beware of super.tearDown()&lt;/span&gt;&lt;br /&gt;Worth to feature in one of &lt;a href="http://www.amazon.co.uk/gp/product/032133678X?ie=UTF8&amp;amp;tag=cotrti-21&amp;amp;linkCode=as2&amp;amp;camp=1634&amp;amp;creative=19450&amp;amp;creativeASIN=032133678X"&gt;Bloch's Puzzlers&lt;/a&gt;&lt;img src="http://www.assoc-amazon.co.uk/e/ir?t=cotrti-21&amp;amp;l=as2&amp;amp;o=2&amp;amp;a=032133678X" alt="" style="border: medium none  ! important; margin: 0px ! important;" height="1" width="1" border="0" /&gt;, what does this code do, when run with an InstrumentationTestRunner?&lt;br /&gt;You may also want to know that the test passes, and, upon exiting from &lt;span style="font-family: Courier;"&gt;testOnCreateSQLiteDatabase&lt;/span&gt; the &lt;span style="font-style: italic; color: rgb(102, 102, 102);"&gt;stub&lt;/span&gt; field contains a valid&lt;br /&gt;reference to the &lt;a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html"&gt;SQLiteDatabase&lt;/a&gt; just created and opened in its &lt;span style="font-style: italic; color: rgb(102, 102, 102);"&gt;db&lt;/span&gt; package-visible field.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class ReceiptsDbOpenHelperTest extends ActivityInstrumentationTestCase2&lt;scanactivity&gt; {&lt;br /&gt;&lt;br /&gt;  public ReceiptsDbOpenHelperTest(String name) {&lt;br /&gt;    super("com.google.android.applications.receiptscan", ScanActivity.class);&lt;br /&gt;    setName(name);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static final String DB_NAME = "test_db";&lt;br /&gt;  ReceiptsDbOpenHelperStub stub;&lt;br /&gt;&lt;br /&gt;  protected void setUp() throws Exception {&lt;br /&gt;    super.setUp();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  protected void tearDown() throws Exception {&lt;br /&gt;    &lt;/scanactivity&gt;super.tearDown();&lt;br /&gt;  &lt;scanactivity&gt;&amp;nbsp; if (stub != null) {&lt;br /&gt;      String path = stub.db.getPath();&lt;br /&gt;      Log.d("test", "Cleaning up " + path);&lt;br /&gt;      if (path != null) {&lt;br /&gt;	File dbFile = new File(path);&lt;br /&gt;	boolean wasDeleted = dbFile.delete();&lt;br /&gt;	Log.d("test", "Database was " + (wasDeleted ? "" : "not ") + "deleted");&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * Ignore the details, but this does "work as intended," opens the database and returns a reference&lt;br /&gt;   * to it in the db variable.&lt;br /&gt;   * The {@code stub} is a class derived from &lt;/scanactivity&gt;{@link ReceiptsDbOpenHelper&lt;scanactivity&gt;} and simply gives us access to&lt;br /&gt;   * some protected / private fields&lt;br /&gt;   */&lt;br /&gt;  public void testOnCreateSQLiteDatabase() {&lt;br /&gt;    stub = new ReceiptsDbOpenHelperStub(getActivity(), DB_NAME, null, 1);&lt;br /&gt;    SQLiteDatabase db = stub.getReadableDatabase();&lt;br /&gt;    assertNotNull(db);&lt;br /&gt;    assertTrue(stub.wasCreated);&lt;br /&gt;    assertEquals(stub.db, db);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/scanactivity&gt;&lt;/pre&gt;&lt;br /&gt;Well, you'll be surprised to know that, our &lt;span style="font-family: Courier;"&gt;tearDown()&lt;/span&gt; does absolutely nothing: after the call to &lt;span style="font-family: Courier;"&gt;super.tearDown()&lt;/span&gt;, &lt;span style="font-family: Courier;"&gt;stub&lt;/span&gt; is &lt;span style="font-weight: bold;"&gt;null&lt;/span&gt; (one can check it out using a debugger session; at least, that's what I did: upon entering &lt;span style="font-family: Courier;"&gt;ReceiptsDbOpenHelperTest.tearDown()&lt;/span&gt; &lt;span style="font-family: Courier;"&gt;stub&lt;/span&gt; is a perfectly valid reference, just after the call to &lt;span style="font-family: Courier;"&gt;super.tearDown()&lt;/span&gt; it's a &lt;span style="font-weight: bold;"&gt;null&lt;/span&gt;: apparently a call to &lt;span style="font-family: Courier;"&gt;super.tearDown()&lt;/span&gt; on an &lt;span style="font-family: Courier;"&gt;ActivityInstrumentationTestCase2&amp;lt;MyActivity&amp;gt;&lt;/span&gt; wipes out all the 'context-related' instance variables. &lt;br /&gt;&lt;br /&gt;Yes, I was too.&lt;br /&gt;&lt;br /&gt;The fix is, obviously, trivial: move the call to &lt;span style="font-family: Courier;"&gt;super.tearDown()&lt;/span&gt; to the bottom of your &lt;span style="font-family: Courier;"&gt;tearDown&lt;/span&gt;() (luckily, this is not a constructor, so there's no reason why not to).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;There seems to be light at the end of the tunnel: some "official" documentation is starting to appear on Android.com, the SDK is (slowly) moving to be (marginally) more user-friendly, and writing (and running) unit tests is no longer as painful as it used to be in version 1.0.&lt;br /&gt;&lt;br /&gt;However, one would have wished that it wouldn't have taken until release 2.2 of the SDK (and version 8 of the API) to get where we are now: for one thing, it's rather likely that Android will be the first (or main) programming platform that many kids will take up when starting to explore computing and software development - and whilst programming in Android is fun, productive and gives an immediate sense of accomplishment, I am concerned that, having given testing (and unit testing, in particular) such a back seat, the wrong lesson may be learnt by young computer scientists: namely, that testing (and coding for testing) is something that can be done another day, when we'll get on the next release...&lt;br /&gt;&lt;br /&gt;It isn't - writing unit tests is &lt;span style="font-style: italic;"&gt;vital&lt;/span&gt; to write bug-free, solid and portable code; it also &lt;span style="font-style: italic;"&gt;encourages the design of clean APIs&lt;/span&gt;: there's nothing like writing a few tests to figure out that one's just written a cumbersome API that needs fixing: and the sooner one finds out, the better!&lt;br /&gt;  &lt;div class="flockcredit" style="text-align: right; color: #CCC; font-size: x-small;"&gt;Blogged with the &lt;a href="http://www.flock.com/blogged-with-flock" style="color: #999; font-weight: bold;" target="_new" title="Flock Browser"&gt;Flock Browser&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-7264992768521257523?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/di5U9fAEUAQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/7264992768521257523/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/06/unit-testing-android-activity.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7264992768521257523?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/7264992768521257523?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/di5U9fAEUAQ/unit-testing-android-activity.html" title="Unit testing Android Activity" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>5</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/06/unit-testing-android-activity.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMNQnkyfip7ImA9WxFRGE0.&quot;"><id>tag:blogger.com,1999:blog-6167393459950006179.post-6007522683228549563</id><published>2010-05-02T05:14:00.001-07:00</published><updated>2010-05-02T05:14:53.796-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-02T05:14:53.796-07:00</app:edited><title>Setting up a shared repository for Mercurial</title><content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gylPe0lov5H10LZuTA8_A8tbEUY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gylPe0lov5H10LZuTA8_A8tbEUY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gylPe0lov5H10LZuTA8_A8tbEUY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gylPe0lov5H10LZuTA8_A8tbEUY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&amp;nbsp; &lt;br&gt;&lt;h1 style="text-align:center"&gt;&lt;a id="Mercurial_Source_Versioning_Co_7438884410895381" name="Mercurial_Source_Versioning_Co_7438884410895381"&gt;&lt;/a&gt;&lt;font color="#741b47"&gt;Mercurial&lt;/font&gt;&lt;font color="#741b47"&gt; -- Source Versioning Control&lt;/font&gt;&lt;/h1&gt;&lt;br&gt;&lt;div style="text-align:center"&gt;&lt;i style="color:#741b47;font-family:Verdana"&gt;(this is also available as a &lt;a href="http://docs.google.com/View?id=dcccmbbx_116fzrrc3hm" id="s8rn" title="Google Doc"&gt;Google Doc&lt;/a&gt;)&lt;/i&gt;&lt;br&gt;&lt;/div&gt;&lt;div class="writely-toc" id="WritelyTableOfContents" toctype="none+none"&gt;&lt;ol class="writely-toc-none"&gt;&lt;li&gt;&lt;a href="#Mercurial_Source_Versioning_Co_7438884410895381" target="_self"&gt;Mercurial -- Source Versioning Control&lt;/a&gt;&lt;/li&gt;&lt;ol class="writely-toc-none writely-toc-subheading" style="margin-left:0pt"&gt;&lt;li&gt;&lt;a href="#Use_of_Mercurial_over_SSH_7277_8262274000054719" target="_self"&gt;Use of Mercurial over SSH&lt;/a&gt;&lt;/li&gt;&lt;ol class="writely-toc-none writely-toc-subheading" style="margin-left:0pt"&gt;&lt;li&gt;&lt;a href="#Creating_a_private_public_pair_6773417777876929" target="_self"&gt;Creating a private/public key pair&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#Setting_up_your_username_66049_3352185571707512" target="_self"&gt;Setting up your username&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#Pulling_a_changelist_from_the__5091395923007018" target="_self"&gt;Pulling a changelist from the remote repository&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#Making_changes_to_the_files_in_10175279728624498" target="_self"&gt;Making changes to the files in the (local) repository&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#Pushing_changes_to_the_remote__08230391525983771" target="_self"&gt;Pushing changes to the (remote) repository&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#Pulling_changes_from_the_remot_477879688898982" target="_self"&gt;Pulling changes from the (remote) repository&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#Pulling_Pushing_changes_in_Ecl_46936393244822094" target="_self"&gt;Pulling / Pushing changes in Eclipse&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;/div&gt;&lt;h2&gt;&lt;a id="Use_of_Mercurial_over_SSH_7277_8262274000054719" name="Use_of_Mercurial_over_SSH_7277_8262274000054719"&gt;&lt;/a&gt;Use of Mercurial over SSH&lt;/h2&gt;Please review the section named: &lt;a href="http://hgbook.red-bean.com/read/collaborating-with-other-people.html" id="s1e7" target="_blank" title="Chapter 6"&gt;Using the Secure Shell (ssh) protocol&lt;/a&gt; in Mercurial&amp;#39;s &amp;quot;&lt;b&gt;Definitive Guide&lt;/b&gt;&amp;quot; -- you may also find useful to review this blog entry (but there are differences with my &amp;#39;paranoid&amp;#39; settings....)&lt;br&gt;&lt;br&gt;I have configured my SSH port away from the standard sshd (22) and I&amp;#39;m using Dynamic DNS to use with my broadband connection (see &lt;a href="http://dyndns.org" id="vfaa" title="http://dyndns.org"&gt;http://dyndns.org&lt;/a&gt; for more info); further, I recommend only allowing SSH connections from a (limited) number of trusted IP (ranges) by editing &lt;font face="courier new"&gt;/etc/hosts.allow&lt;/font&gt;; if you can&amp;#39;t get this one to work, please figure out which IP address are you connecting from (&lt;a href="http://www.formyip.com" id="o1jf" title="http://www.formyip.com"&gt;http://www.formyip.com&lt;/a&gt;) and tweak your hosts.allow accordingly:&lt;br&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;ssh -p 666 -l [user] yourdomain.dyndns.org&lt;/font&gt;&lt;br&gt;&lt;br&gt;at this stage, you should be prompted for your password, that is to be expected.&lt;br&gt;If you can&amp;#39;t connect, make sure you can DNS-lookup the server (&lt;font face="courier new"&gt;nslookup &lt;font face="courier new"&gt;yourdomain&lt;/font&gt;.dyndns.org&lt;/font&gt; must return something meaningful -- this is achieved via &lt;a href="http://www.dyndns.com/support/kb/using_inadyn_with_dyndns_services.html" id="w9ip" title="inadyn"&gt;inadyn&lt;/a&gt;, so if you get an IP address, but still can&amp;#39;t connect, it is -marginally- possible that inadyn is down and the IP was changed by your ISP).&lt;br&gt;&lt;br&gt;&lt;h3&gt;&lt;a id="Creating_a_private_public_pair_6773417777876929" name="Creating_a_private_public_pair_6773417777876929"&gt;&lt;/a&gt;Creating a private/public key pair &lt;/h3&gt;On the local Linux&lt;sup&gt;[1]&lt;/sup&gt; box do the following:&lt;br&gt;&lt;br&gt;&lt;pre&gt;ssh-keygen -t rsa&lt;br&gt;&lt;font size="1"&gt;&lt;br style="font-family:Arial"&gt;&lt;/font&gt;&lt;font face="verdana"&gt;&lt;font size="1"&gt;[1] if are using Windoze, you&amp;#39;re too far down in the evolution chain for me to waste any time educating you, but you can do worse than Google  &amp;quot;putttygen key pairs&amp;quot; or some such thing.&lt;/font&gt;&lt;br&gt;&lt;br&gt;this will generate a private/public key pair in your &lt;font face="courier new"&gt;~/.ssh&lt;/font&gt; directory, one of which should be named something like &lt;b&gt;&lt;font face="courier new"&gt;id_rsa.pub&lt;/font&gt;&lt;/b&gt; -- copy that one (&lt;b&gt;not&lt;/b&gt; the id_rsa private key!) on the remote machine&amp;#39;s &lt;font face="courier new"&gt;~/.ssh&lt;/font&gt; directory (or in &lt;font face="courier new"&gt;/tmp&lt;/font&gt;, it doesn&amp;#39;t really matter). &lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;font face="verdana"&gt;You must then add this public key to your &lt;font face="courier new"&gt;~/.ssh/authorized_keys&lt;/font&gt; file (if it does not exist, you will need to &lt;font face="courier new"&gt;touch&lt;/font&gt; it, remember to chmod it to 500 -- only YOU must be able to &lt;font face="courier new"&gt;rw&lt;/font&gt; it);&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;touch ~/.ssh/authorized_keys&lt;/font&gt;&lt;br&gt;&lt;font face="courier new"&gt;&lt;font face="courier new"&gt;chmod &lt;/font&gt;&lt;font face="courier new"&gt;500 ~/.ssh/authorized_keys&lt;/font&gt;&lt;br&gt;cat /tmp/id_rsa.pub &amp;gt;&amp;gt; &lt;/font&gt;&lt;font face="courier new"&gt;~/.ssh/authorized_keys&lt;br&gt;&lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;font face="verdana"&gt;logout from the remote machine, then re-issue the ssh command above, you should then be logged in, without the remote SSH server asking for the password.&lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;br&gt;&lt;/pre&gt;&lt;h3&gt;&lt;a id="Setting_up_your_username_66049_3352185571707512" name="Setting_up_your_username_66049_3352185571707512"&gt;&lt;/a&gt;&lt;font face="verdana"&gt;Setting up your username&lt;/font&gt;&lt;/h3&gt;&lt;pre&gt;&lt;font face="arial"&gt;It&amp;#39;s always good practice to ensure that your changes can easily be tracked back to you: as an essential part of this, setting up a meaningful username for HG is critical: you can use the HGUSER environment variable (&lt;font face="courier new"&gt;export HGUSER=&amp;quot;Marco Massenzio &amp;lt;m.massenzio@gmail.com&amp;gt;&amp;quot;&lt;/font&gt;) or set it up in a more &amp;#39;permanent&amp;#39; way by editing the Mercurial configuration file (&lt;font face="courier new"&gt;~/.hgrc&lt;/font&gt;):&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;div style="margin-left:40px"&gt;&lt;font face="courier new"&gt;# This is a Mercurial configuration file.&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;[ui]&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;font face="courier new"&gt;username = Marco Massenzio &amp;lt;m.massenzio@gmail.com&amp;gt;&lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;/div&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br&gt;&lt;h3 style="font-family:Verdana"&gt;&lt;a id="Pulling_a_changelist_from_the__5091395923007018" name="Pulling_a_changelist_from_the__5091395923007018"&gt;&lt;/a&gt;Pulling a changelist from the remote repository&lt;/h3&gt;&lt;pre&gt;&lt;font face="verdana"&gt;The directory where we will place HG repositories is in &lt;font face="courier new"&gt;/usr/local/hgrepo&lt;/font&gt;, each directory will be a project&amp;#39;s repository -- a simple test repo is &amp;#39;hello&amp;#39; (/usr/local/hgrepo/hello) and you should be able to clone it onto your machine by issuing the following (from a local shell -- do not ssh into the remote server):&lt;br&gt;&lt;br&gt;&lt;/font&gt;hg clone ssh://user@yourdomain.dyndns.org:666//usr/local/hgrepo/hello&lt;br style="font-family:Verdana"&gt;&lt;br style="font-family:Verdana"&gt;&lt;font face="verdana"&gt;A couple of things worthy of note:&lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;br style="font-family:Verdana"&gt;&lt;/pre&gt;&lt;ol&gt;&lt;li&gt;note the &lt;font face="courier new"&gt;//&lt;/font&gt; after 666 (&lt;font face="courier new"&gt;//usr&lt;/font&gt;) this tells SSH to start at the root of the filesystem (/) instead of your homedir (~/)&lt;/li&gt;&lt;li&gt;replace the username in &lt;font face="courier new"&gt;user@&lt;/font&gt; with your actual username -- do &lt;b&gt;not&lt;/b&gt; send the password in cleartext, you should in fact &lt;b&gt;not&lt;/b&gt; be asked for a password (if you are, then something went wrong with the private/public key pair setup above)&lt;/li&gt;&lt;li&gt;you should now have a &lt;font face="courier new"&gt;hello&lt;/font&gt; directory, containing a few files on your local machine; if something went wrong, you should see an error message.&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;&lt;h3&gt;&lt;a id="Making_changes_to_the_files_in_10175279728624498" name="Making_changes_to_the_files_in_10175279728624498"&gt;&lt;/a&gt;&lt;font face="verdana"&gt;Making changes to the files in the (local) repository&lt;/font&gt;&lt;/h3&gt;&lt;pre&gt;&lt;font face="verdana"&gt;Follow the usual HG practices -- edit the file with your favourite editor, save it, and once you are happy with it, commit it to the (local) repository:&lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;br style="font-family:Verdana"&gt;hg ci -m &amp;quot;Did something astounding&amp;quot;&lt;br&gt;&lt;br&gt;&lt;/pre&gt;&lt;h3&gt;&lt;a id="Pushing_changes_to_the_remote__08230391525983771" name="Pushing_changes_to_the_remote__08230391525983771"&gt;&lt;/a&gt;&lt;font face="verdana"&gt;Pushing changes to the (remote) repository&lt;/font&gt;&lt;/h3&gt;&lt;pre&gt;&lt;font face="verdana"&gt;Once you are happy with the changes, and think it&amp;#39;s time for the other developers to see them,&lt;/font&gt; push &lt;font face="verdana"&gt;them back to&lt;/font&gt; the remote repository:&lt;br&gt;&lt;br&gt;hg push -v ssh://user@yourdomain.dyndns.org:666//usr/local/hgrepo/hello&lt;br style="font-family:Verdana"&gt;&lt;br style="font-family:Verdana"&gt;&lt;font face="verdana"&gt;By design, doing so, will not make the changes the &amp;#39;tip&amp;#39; (or head) of the remote repository -- see the book as for why -- you should run an &lt;b&gt;hg update&lt;/b&gt; command on the remote directory: the simplest way I found is to SSH into your remote machine and then run an hg update on the repo:&lt;/font&gt;&lt;br&gt;&lt;br&gt;ssh -p 666 -l user yourdomain.dyndns.org&lt;br&gt;cd /usr/local/hgrepo/hello&lt;br&gt;hg status&lt;br&gt;# this should be an empty line, no editing of files should happen on the remote machine&lt;br&gt;hg glog -l 6&lt;br&gt;# see the &amp;#39;graphic log&amp;#39; extension section in the hg manual&lt;br&gt;# this will show a list of the last 6 CLs, the &amp;#39;active&amp;#39; one marked with an @&lt;br&gt;hg update&lt;br&gt;# this will make &amp;#39;head&amp;#39; the &amp;#39;active&amp;#39; revision&lt;br&gt;&lt;br&gt;&lt;font face="verdana"&gt;if no conflicts arise then this should update head; if there are conflicts, you will have to run a merge command:&lt;/font&gt;&lt;br&gt;hg merge&lt;br&gt;# I discourage doing merges on the remote machine however: merges are best done using a visual&lt;br&gt;# editor, suck as tkdiff, or similar.&lt;br&gt;&lt;br&gt;&lt;font face="verdana"&gt;possibly resolving the merge conflicts as they arise.&lt;br&gt;&lt;/font&gt;&lt;br&gt;&lt;/pre&gt;&lt;h3&gt;&lt;a id="Pulling_changes_from_the_remot_477879688898982" name="Pulling_changes_from_the_remot_477879688898982"&gt;&lt;/a&gt;&lt;font face="verdana"&gt;Pulling changes from the (remote) repository&lt;/font&gt;&lt;/h3&gt;&lt;font face="verdana"&gt;Before starting any work, you should pull the latest version of the repository from ibw:&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font face="courier new"&gt;hg pull -v ssh://user@yourdomain.dyndns.org:666//usr/local/hgrepo/hello&lt;/font&gt;&lt;br style="font-family:Verdana"&gt;&lt;br style="font-family:Verdana"&gt;&lt;font face="verdana"&gt;By design, doing so will not make the changes the &amp;#39;tip&amp;#39; (or head) of the local repository -- see the book as for why -- you should run an hg update command on the local directory:&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;font face="courier new"&gt;hg up&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br&gt;&lt;font face="verdana"&gt;if no conflicts arise then this should update head; if there are conflicts, you will have to run a merge command:&lt;/font&gt;&lt;br&gt;&lt;font face="courier new"&gt;&lt;br&gt;hg merge&lt;/font&gt;&lt;br style="font-family:Courier New"&gt;&lt;br&gt;&lt;h3&gt;&lt;a id="Pulling_Pushing_changes_in_Ecl_46936393244822094" name="Pulling_Pushing_changes_in_Ecl_46936393244822094"&gt;&lt;/a&gt;&lt;font face="verdana"&gt;Pulling / Pushing changes in Eclipse&lt;/font&gt;&lt;/h3&gt;&lt;font face="verdana"&gt;Use the &lt;a href="http://www.vectrace.com/mercurialeclipse/" id="jopo" target="_blank" title="Mercurial Eclipse"&gt;Mercurial Eclipse&lt;/a&gt; plugin [follow instructions on the site to install -- update site:&lt;/font&gt; &lt;a href="http://www.vectrace.com/eclipse-update/" id="n3e." target="_blank" title="http://www.vectrace.com/eclipse-update/"&gt;http://www.vectrace.com/eclipse-update/&lt;/a&gt;&lt;font face="verdana"&gt;] then use the right-click context sensitive &lt;/font&gt;&lt;font face="verdana"&gt;Team &lt;/font&gt;&lt;font face="verdana"&gt;menu with the Project folder selected, and choose accordingly.&lt;br&gt;&lt;br&gt;The Repository URL to use is:&lt;br&gt;&lt;/font&gt;&lt;font face="courier new"&gt;ssh://user@yourdomain.dyndns.org:666//usr/local/hgrepo/hello&lt;/font&gt;&lt;br&gt;&lt;font face="verdana"&gt;&amp;nbsp;&lt;br&gt;but &lt;b&gt;do not enter username/password in the dialog box&lt;/b&gt;, SSH will pick up the private key and proceed to conduct the handshake (if the pub/priv keys setup does not work for any reason, Eclipse will still be able to connect to the repository, but you will be asked for the password a couple of times, or possibly more).&lt;br&gt;&lt;br&gt;Personally, I&amp;#39;m not using the Eclipse plugin (the initial delay in starting up at Eclipse launch is most irritating) and only use hg&amp;#39;s command-line interface.&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6167393459950006179-6007522683228549563?l=codetrips.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/JavaCodeTripsTips/~4/5SyJKJ7XYdY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://codetrips.blogspot.com/feeds/6007522683228549563/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://codetrips.blogspot.com/2010/05/setting-up-shared-repository-for.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/6007522683228549563?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6167393459950006179/posts/default/6007522683228549563?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavaCodeTripsTips/~3/5SyJKJ7XYdY/setting-up-shared-repository-for.html" title="Setting up a shared repository for Mercurial" /><author><name>Marco Massenzio</name><uri>http://www.blogger.com/profile/07909737351121376431</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="32" src="http://1.bp.blogspot.com/-k0oDjHP99no/TY2bHLulEMI/AAAAAAAAR90/JJCDfPh-gL0/s220/DSCF2220.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://codetrips.blogspot.com/2010/05/setting-up-shared-repository-for.html</feedburner:origLink></entry></feed>

