Showing posts with label debian/sid. Show all posts
Showing posts with label debian/sid. Show all posts

Sunday, August 16, 2015

First time learning gradle

It is difficult to jump start into software development if you are new to introduction of many sub technologies. Today, I'm gonna put aside of my project and start to learn another technology. Gradle, a build system but there are much more than just build. If you are also new to gradle, you might want to find out what actually is gradle.

Gradle on wikipedia

Gradle is a build automation tool that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the more traditional XML form of declaring the project configuration. Gradle uses a directed acyclic graph ("DAG") to determine the order in which tasks can be run.
Gradle was designed for multi-project builds which can grow to be quite large, and supports incremental builds by intelligently determining which parts of the build tree are up-to-date, so that any task dependent upon those parts will not need to be re-executed.

If you have many projects that depend on a project, gradle will solve your problems. We will look into the basic of gradle build automation tool today. I love to code java and so I will use java as this demo. First, let's install gradle. If you are using deb based distribution like debian or ubuntu, to install gradle, it is as easy as $ sudo apt-get install gradle. Otherwise, you can download gradle from and install in your system. Now let's create a gradle build file. See below.

 user@localhost:~/gradle$ cat build.gradle   
 apply plugin: 'java'  
 user@localhost:~/gradle$ ls -a  
 total 36K  
 -rw-r--r--  1 user user  21 Aug 6 17:15 build.gradle  
 drwxr-xr-x 214 user user 28K Aug 6 17:15 ..  
 drwxr-xr-x  2 user user 4.0K Aug 6 17:15 .  
 user@localhost:~/gradle$ gradle build  
 :compileJava UP-TO-DATE  
 :processResources UP-TO-DATE  
 :classes UP-TO-DATE  
 :compileTestJava UP-TO-DATE  
 :processTestResources UP-TO-DATE  
 :testClasses UP-TO-DATE  
 Total time: 13.304 secs  
 user@localhost:~/gradle$ ls -a  
 total 44K  
 -rw-r--r--  1 user user  21 Aug 6 17:15 build.gradle  
 drwxr-xr-x 214 user user 28K Aug 6 17:15 ..  
 drwxr-xr-x  3 user user 4.0K Aug 6 17:15 .gradle  
 drwxr-xr-x  4 user user 4.0K Aug 6 17:15 .  
 drwxr-xr-x  6 user user 4.0K Aug 6 17:15 build  
 user@localhost:~/gradle$ find .gradle/  
 user@localhost:~/gradle$ find build  

one liner of input produce so many output files. Amazing! Why so many files that were generated, read the output of the command output, it compile, process resource, jar, assemble, test check and build. What are all these means, I will not explain to you one by one, you learn better if you read this definition yourself which is documented very well here. You might say, hey , I have different java source path can gradle handle this? Yes of cause! In the build path you created, you can add another line.

 // set the source java folder to another non maven standard path = ['src/java']  

Most of us coming from java has ant build file. If that is the case, gradle integrate nicely with ant too, you just need to import ant build file and then call ant target from gradle. See code snippet below.

 user@localhost:~/gradle$ cat build.xml   
  <target name="helloAnt">  
   <echo message="hello this is ant."/>  
 user@localhost:~/gradle$ cat build.gradle  
 apply plugin: 'java'  
 // set the source java folder to another non maven standard path = ['src/java']  
 // import ant build file.  
 ant.importBuild 'build.xml'  
 user@localhost:~/gradle$ gradle helloAnt   
 [ant:echo] hello this is ant.  
 Total time: 5.573 secs  

That looks pretty good! If you curious about what gradle parameter that you can use during figuring out if the build went wrong, you should really read into this link. Also, if read on the environment variable as you can specify other jdk for gradle or even java parameter during compile big projects.

You might want to ask also, what if I only want to compile, I don't want to go through all the automatic builds above. No problem, since this is a java project, you specify compileJava.

 user@localhost:~/gradle$ gradle compileJava  
 :compileJava UP-TO-DATE  
 Total time: 4.976 secs  

As you can see, gradle is very flexible and because of that, you might want to exploit it further. For example, customizing the task in build.gradle, listing projects, listing tasks and others. For that, read here as it explain and give a lot of example how all that can be done. So at this stage, you might want to add more feature into gradle build file. Okay, let's do just that.

 user@localhost:~/gradle$ cat build.gradle   
 apply plugin: 'java'  
 apply plugin: 'eclipse'  
 // set the source java folder to another non maven standard path  
 // default src/main/java = ['src/java']  
 // default src test   
 // default src resources.  
 // src/main/resources   
 // default src test resources.  
 // src/test/resources  
 // default build  
 // build  
 // default jar built  
 // build/libs  
 // dependencies of external jar, we reference the very good from maven.  
 repositories {  
 // actual libs dependencies  
 dependencies {  
   compile group: 'commons-collections', name: 'commons-collections', version: '3.2'  
   testCompile group: 'junit', name: 'junit', version: '4.+'  
 test {  
   testLogging {  
     // Show that tests are run in the command-line output  
     events 'started', 'passed'  
 sourceCompatibility = 1.5  
 version = '1.0'  
 jar {  
   manifest {  
     attributes 'Implementation-Title': 'Gradle Quickstart',  
           'Implementation-Version': version  
 // import ant build file.  
 ant.importBuild 'build.xml'  
 // common for subprojects  
 subprojects {  
   apply plugin: 'java'  
   repositories {  
   dependencies {  
     testCompile 'junit:junit:4.12'  
   version = '1.0'  
   jar {  
     manifest.attributes provider: 'gradle'  
 user@localhost:~/gradle$ cat settings.gradle   
 include ":nativeapp",":webapp"  

Now, if you want to generate eclipse configuration, just run gradle eclipse, all eclipse configuration and setting are created automatically. Of cause, you can customize settings even further.

 user@localhost:~/gradle$ gradle eclipse  
 Total time: 19.497 secs  
 user@localhost:~/gradle$ find .  

Now, I create a simple unit test class file, see below. Then only run a single unit test, that's very cool.

 user@localhost:~/gradle$ find src/  
 $ gradle -Dtest.single=Quick test  
 :compileJava UP-TO-DATE  
 :processResources UP-TO-DATE  
 :classes UP-TO-DATE  
 :compileTestJavawarning: [options] bootstrap class path not set in conjunction with -source 1.5  
 1 warning  
 :processTestResources UP-TO-DATE  
 org.just4fun.voc.file.QuickTest > test STARTED  
 org.just4fun.voc.file.QuickTest > test PASSED  
 Total time: 55.81 secs  
 user@localhost:~/gradle $  

There are two additional directories created , that is nativeapp and webapp, this is subprojects for this big project and it contain its own gradle build file. At the parent of the gradle build file, we see a subprojects configuration as this will applied to all the subprojects. You can create a settings.gradle to specify the subprojects.

That's all for today, as this is just an introduction to quicklyl dive into some of the cool features of gradle, with this shown, I hope it give you some idea where to head next. Good luck!

Sunday, February 15, 2015

Fix steam error libGL error: failed to load driver: swrast in debian

If you have steam client installed on debian sid, once a while, operating system is upgraded and then the upgraded break steam client. An example output of such error encountered.
user@localhost:~$ steam
Running Steam on debian 8 64-bit
STEAM_RUNTIME is enabled automatically
Installing breakpad exception handler for appid(steam)/version(1421694684)
libGL error: unable to load driver:
libGL error: driver pointer missing
libGL error: failed to load driver: r600
libGL error: unable to load driver:
libGL error: failed to load driver: swrast

So steam client fail to launch and this look like 3d graphic driver unable to load or not install. Don't bother to even install the package libgl1-mesa-swx11 that provide the file swrast because at this point of time, installation of this package will not work as conflict is clearly indicated. Conflicts: libgl1, libgl1-mesa-swrast, mesag3, mesag3+ggi, mesag3-glide, mesag3-glide2, nvidia-glx. Installation of this package will render debian gui not usable, had that path :( So don't do that.

So I have google and found a good solution and below is what I have taken. I hope it works for you too.
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu$ mv
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu$ ls*
lrwxrwxrwx 1 user user 19 Jul 19 2014 ->
-rw-r--r-- 1 user user 901K Jul 19 2014
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu$ rm
rm: remove symbolic link ‘’? y
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu$ pwd

user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu$ pwd
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu$ mv
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu$ rm
rm: remove symbolic link ‘’? y
user@localhost:~/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu$ pwd

As you can see above, the example shown two symbolic links in two different directory, i386 and amd64 were removed. Then again for the file that symlink pointed to is moved to another name and so it can be revert if something goes wrong after.

After these were removed, start again the steam client and steam will redownload the file and it should work again! :-)

Friday, June 6, 2014

How to prevent a package from upgrading in Debian

Often times, when you are having a server with a package installed, example database package and you want the rest of the packages in the system upgraded but not the database package. How can you do it?

With Debian, you can! You can set a package not to upgrade by setting flag to the package with dpkg. The followings are parameters that you need to be use.
--get-selections [package-name-pattern...]
Get list of package selections, and write it to stdout. Without a pattern, non-installed packages (i.e. those which have been previously
purged) will not be shown.

Set package selections using file read from stdin. This file should be in the format 'package state', where state is one of install, hold,
deinstall or purge. Blank lines and comment lines beginning with '#' are also permitted.

The available file needs to be up-to-date for this command to be useful, otherwise unknown packages will be ignored with a warning. See the
--update-avail and --merge-avail commands for more information.

Let's check what is the state of a current package. To narrate better, I will use mongodb.
jason@localhost:~$ dpkg --get-selections mongodb-org
mongodb-org install

If you decided to stop this package from the next upgrade, you should set flag hold to this package.
jason@localhost:~$ echo "mongodb-org hold" | sudo dpkg --set-selections
jason@localhost:~$ $ dpkg --get-selections mongodb-org
mongodb-org hold

Notice that the package state has transitioned into hold. Okay, let's say we want the package to be upgrade in the next upgrade, then we can set install flag to this package.
jason@localhost:~$ echo "mongodb-org install" | sudo dpkg --set-selections
jason@localhost:~$ dpkg --get-selections mongodb-org
mongodb-org install

So, that's it, simple and quick.