Thursday, October 6, 2011

Curso de Tecnología Java (Java Technology Course)

Java en Castellano
Aquí les brindo un modesto curso de la Tecnología Java, casi el 100% del contenido esta en español.

Espero que lo disfruten.

Wednesday, October 5, 2011

The apt keys, importing keys in batch mode

Why?
Sometimes a fresh Ubuntu or Debian install is mandatory or commanded, but we forget to export all GPG apt keys before the wipe. Once we made the installation we start to add our previously sources lists entries (hope you don't forget to save them first). In my case I use several entries many referencing some useful PPAs on Launchpad, this an excerpt:

deb http://archive.ubuntu.com/ubuntu natty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu natty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu natty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu natty main restricted universe multiverse

deb http://archive.canonical.com/ubuntu natty partner
deb http://archive.canonical.com/ubuntu natty-backports partner

deb http://extras.ubuntu.com/ubuntu natty main

deb http://ppa.launchpad.net/stebbins/handbrake-releases/ubuntu natty main
deb-src http://ppa.launchpad.net/stebbins/handbrake-releases/ubuntu natty main

deb http://ppa.launchpad.net/tualatrix/ppa/ubuntu natty main 
deb http://ppa.launchpad.net/kiwixteam/ppa/ubuntu natty main
deb http://ppa.launchpad.net/pidgin-developers/ppa/ubuntu natty main

deb http://ppa.launchpad.net/rabbitvcs/ppa/ubuntu natty main
deb-src http://ppa.launchpad.net/rabbitvcs/ppa/ubuntu natty main

deb http://archive.cloudera.com/debian natty-cdh3 contrib
deb-src http://archive.cloudera.com/debian natty-cdh3 contrib

deb http://ppa.launchpad.net/ubuntu-x-swat/x-updates/ubuntu natty main
When we run then apt-get update in our fresh install we end with this annoying warning message:

W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used.GPG error: ... Release: The following signatures were invalid: BADSIG 40976EAF437D05B5 Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>

W: Failed to fetch ... 
W: Some index files failed to download, they have been ignored, or old ones used instead.


To avoid these warnings you shall to explicit import the public keys (40976EAF437D05B5) via Synaptic Package Manager or apt-key command.

How?
In my case, I keep a file (~/Sandbox/aptkeys/aptkeys) with a list of keys on my profile, one per line. Then, when a /etc/apt/sources.list archive get modified and the command apt-get update emits this kind of warning message, I append this key (40976EAF437D05B5) to the end of the file  ~/Sandbox/aptkeys/aptkeys using a text editor or cat command. Here is an excerpt of my aptkeys file:
DB141E2302FDF932
7FB8BEE0A1F196A8
5A9BF3BB4E5E17B5
2EBC26B60C5A2783
BE79FA4B705B7C13
E43D207C62D38753
C0B56813051D8B58
3B22AB97AF1CDFA9

The I use this script to make a batch import of all my approved keys:


$  cat ~/Sandbox/aptkeys/aptkeys  | importaptkeys


Hope that it will be useful for you.

Tuesday, October 4, 2011

Various Java VM on my Debian / Ubuntu. What can I do?

The situation
Many of us prefer Sun JVM (Oracle now) for historical or non-historical reasons. Many of us also prefer Debian, Ubuntu and/or even Red Hat. But when we go and install LibreOffice (for example), via apt-get other powerful player arrives: openjdk. I don't want to discuss which JVM implementation is the most "appropriate" for us, you or them. There is a fact, many JVM can and should coexists pacifically.

But the question persists
- After installing various Java-dependant packages on my GNU/Linux OS preferred distribution, and I issue the javac command, which JVM compiler is invoked? 
- How can I set my preferred Java implementation per command basis?

The solution
The Debian alternatives system is devoted to solve the problem of choosing the default preferred implementation of various kinds of programs: text editors, mail agents, JVM, etc.

The options are settled via update-alternatives in a terminal and there is also a graphical version called galternatives.


The Example
This script sets various' Sun JVM (Oracle now) commands as the default alternatives for: java packaging, java VM, java compiler, javadoc, etc. It runs update-alternatives command several times, one per java command.

Composing XML is easy

Intro
Sometimes we want to "modularize" some XML archive in some independent parts for a matter of clearness and manageability of simple documents instead of huge ones, lets say XHTML pages, XSLT, XSD, etc.

Many people don't know how to compose, in a generic manner, multiple XML (a no XML also) documents into a big one. It's easier to do, and the answer is XInclude.  Many XInclude examples reflect what I said: Its easy to use!

XInclude It's not a new invention at all, but surprisingly a bunch colleagues of mine don't know about its existence.

Example
Lets stop talking. I going to show you how you can freely merge varios XML (or text) documents into a more complex XML document with XInclude during a XSLT transformation. The example is very straightforward:

- input file: demoxi.html

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
  <head>Some title</head>
  <body>
    <p><xi:include href="license.txt" parse="text"/></p>
  </body>
</html>


- XSLT transformation: identity.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:xi="http://www.w3.org/2001/XInclude">
   
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
 
  <xi:include href="copy_template.xml" parse="xml" />

</xsl:stylesheet>

- a text file to include: license.txt

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation Version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See GNU General Public License <http://www.gnu.org/licenses/>.
- a XML file to include in the XSLT: copy_template.xml

<xsl:template match="*" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:element name="{fn:name(.)}" namespace="{fn:namespace-uri(.)}">
        <!-- copy attributes -->
        <xsl:for-each select="@*">
            <xsl:attribute name="{fn:node-name(.)}" select="." />
        </xsl:for-each>
        <xsl:apply-templates select="child::node()" />
    </xsl:element>
</xsl:template>

What's next?


Call an XSLT processor like Saxon in a XInclude aware manner.

$ exec java \
    -classpath saxon.jar \
    -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration \
    net.sf.saxon.Transform \
    -xi:on \

    -s:demoxi.html \
    -xsl:indentity.xsl

I provide this script to make things more easy. Enjoy it!

References:

Tiny: Extract all dependencies from Maven's POM recursively

A friend recently ask me: how can I extract all artifact dependencies from multiple POM files recursively into a single POM file?

Here is a simple answer using bash, libxml-xpath-perl and tidy.

What users can add?
- more XML processing instead of concatenating.
- extract properties values of non hardcoded dependencies.
- ensure uniqueness of dependencies.