Notes of the gvSIG 2.0 workshop

This are the notes that I took over gvSIG 2.0 on the latests Jornadas GvSIG.

Pre-requisites

  • Java
  • Eclipse
  • Ant (should)
  • Maven (should)
  • gvSIG (this is recursive :))

The main advantage of gvSIG 2.0 is that you can create a new plugin without knowing how does gvSIG work or having to compile it. We already have a gvSIG installation that deploys the binaries to the workspace. But we don’t have to change the source code. Unless, of course, something doesn’t work (bugs) or we have to add some new functionality to the core. Better if you don’t touch it, ask the developers and they will take care.

Creating the workspace

With the binary, there is a wizard which creates an Eclipse workspace with a default template. That leaves all set up but to compile our extension. It also includes a wizard to easily generate installables. These wizards are accessible through the application, at the application menu.

Org.gvsig.tools is the basic infrastructure library to develop plugins. The main functionality is focused on the registration of extension points, utilities to separate API, implementations, SPI (service provider), and monitoring tasks (which in version 1.0 used to freeze the application). This library also supports events, persistence, etc …

gvSIG Plugins

A library is a jar. When our application contains the jar, org.gvsig.tools prepares and initializes this library within the core. The classes in the library implement the interface Library (AbstractLibrary).

The managers (PluginsManager) is the entry point of the features. They are like factories (singletons) (at least one per library) that raises the request of the functionality included in the library. It also saves the configuration of the module.

The locators (PluginsLocator) allow to register implementations of managers.We can recover a specific manager API. “Give me the manager of this library.”

A Plugin is a piece that adds a functionality: buttons and toolbars, menu options, data providers and types of documents. Andami has not evolved much since version 1.x. Andami is the framework for the plugins.

The plugin will always have at least two files:

  • config.xml indicating the classes that implement the plug-in units and menus
  • package.info indicating the version, name, build, … of the plugin.

gvSIG Extensions

An extension (IExtension) is a set of tools associated with a plugin inside a toolbar or menu and they work together. A group of plugins, you may say. The extension that implements ExclusiveUIExtension specify what tools are or not visible, without touching the core code.

To create a new plugin, we make use of the tool menu generation of plugins available from the development version. This generates the workspace automatically and installs the plugin from which we generated the plugin. If you have no development release, you will have to compile the sources.

You should be starting a plugin with the wizard while reading this notes or you will be lost.

The plugin consists of two maven projects: org.gvsig.plugin and org.gvsig.plugin.app. org.gvsig.plugin provide the functionality of the library independently of gvSIG (business logic). May have library dependencies, but should be able to operate without having to open the application. That is, it requires nothing of Andami, for example. In org.gvsig.plugin.app.mainplugin (within org.gvsig.plugin.app) we will implement the functionality.

The “api” packages should contain interfaces and the “impl” packages should contain implementations.

Now the workspace is ready to work with Eclipse if we import the project with the maven plugin. If we took an appropriate template to generate the plugin sources, almost all the work is done (except for the exact business logic of our plugin).

Final Advices

It is important to have a java project to test our plugin with its own main, without having to start gvSIG. Also it is recommended that the library has unit tests. That is, we can make an application with the full power of gvSIG, but without using gvSIG itself, ie as if it was a powerful library GIS. Conclusion: if we do well, we could even use our plugin into another no application … as Gofleet.

Each plugin contains own installer, which created by a wizard inside the application.

How to compile gvSIG 2.0

I am proud to share with you the steps to compile gvSIG 2.0, which I discovered thanks to some fellows developers, whom I met thanks to the latests Jornadas GvSIG.

Although you can find a full guide on the official documentation, this simple steps will let you customize and compile your own gvSIG2.0 version without much trouble.

First, you have to install some basic dependencies:

#apt-get install maven2 subversion

Next, we create a folder in which we can work:

$mkdir gvSIG; cd gvSIG

Once we have the basic workspace, we download the source code:

$svn co https://joinup.ec.europa.eu/svn/gvsig-desktop/branches/v2_0_0_prep/build/

Before compiling anything, we prepare a basic configuration file:

$ cat > ~/.gvsig.platform.properties << EOF
native_platform=linux
native_distribution=all
native_compiler=gcc4
native_arch=i386
native_libraryType=dynamic
export native_classifier=${native_platform}-${native_distribution}-${native_compiler}-${native_arch}-${native_libraryType}
EOF

The next code can be written on the .bashrc file of your /home folder, but we can also execute it on the console we are working with.

$if [ -f "${HOME}/.gvsig.platform.properties" ]
then
. ${HOME}/.gvsig.platform.properties
export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m -Dnative-classifier=${native_classifier} -Dnative-platform=${native_platform}"
else
export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m"
fi

Once we have the environment ready, we do the first compilation with maven. Patience, it may take long.

$mvn install

Now that we have our first maven compilation, we proceed to use ant to end up setting up the environment. This command will access to the online repository of gvSIG to download the rest of the source code and will compile and generate gvSIG.

$ant svn.checkout.all

Once we have the environment ready, we proceed to prepare the flavor of gvSIG we are going to use. On his post we will use the standard version of gvSIG:

$cd projects/gvsig-standard
$ant svn.checkout.all

Patience, much more patience.

$mvn install

And it’s done. The application is on the products folder. To execute it, we execute the script gvSIG.sh.

If at the start we get the “command java not found” error, we have to specify the environment variable JAVA_HOME:

$export JAVA_HOME=/usr/lib/jvm...

Now you can use your own customized version.

Soon, I will post about how to create plugins.

DNIe: Dealing with the electronic ID card

Although this has already been discussed previously , I wanted to give another lap to the issue DNIe under Linux. And what the hell! After spending one day and a half on the subject, I wanted to leave the tutorial available somewhere, if I have to do it again.

When I started I was recommended that I tried on Windows first and then if it works, I should try again on Linux. And although I followed the advice, it turns out I am definitely worse in Windows than in Linux (I ended up having to reinstall Windows again), so I tried again where I felt comfortable and understood what I do.

Basically I have been following this three blog posts:
* DNIe on Ubuntu
*
Linux DNIe Squeeze
*
DNIe on Ubuntu

Check your base libraries

The first thing I discovered is that one should not rely on the libraries from the repositories (I use Debian Squeeze). So I installed bare hands OpenSC and its dependencies.

First thing to do is to download the latest libraries available on the website of dnielectronico, in my case:

$ wget https://www.dnielectronico.es/descargas/PKCS11_para_Sistemas_Unix/opensc-dnie_1.4.8_amd64_lenny.tar 
 $ tar xvf opensc-dnie_1.4.8_amd64_lenny.tar
 $ cd opensc-dnie_1.4.8_amd64_lenny 

And also download the dependencies that are no longer available for Debian Squeeze:

$ wget https://ftp.es.debian.org/debian/pool/main/libt/libtool/libltdl3_1.5.26-4+lenny1_amd64.deb

$ wget https://ftp.es.debian.org/debian/pool/main/o/openct/libopenct1_0.6.14-3_amd64.deb 

Installing the dnie drivers

When this is done, we can begin to install the dnie drivers:

 # dpkg-i *. deb libltdl3

# dpkg-i *. deb libopenct

# dpkg-i *. deb libopensc2

# dpkg-i *. deb opensc_

# apt-get install pinentry-qt4

# dpkg-i *. deb opensc-dnie 

And then we make sure not to screw it in future updates, blocking the libraries:

 # echo libopenct1 hold | dpkg - set-selections

# echo opensc hold | dpkg - set-selections

# echo libopensc2 hold | dpkg - set-selections 

Now comes the nice part, where we see that everything works … or not:

 $ sudo apt-get install pcscd pcsc-tools

$ pcsc_scan

PC / SC device scanner

V 1.4.16 (c) 2001-2009, Ludovic Rousseau

Compiled with PC / SC lite version: 1.5.5

Scanning present readers ...

0: Gemplus GemPC Twin 00 00 
Mon Sep 5 20:01:11 2011
Reader 0: Gemplus GemPC Twin 00 00
Card state: Card inserted,
[...]
Electronic DNI (Spanish electronic ID card)
https://www.dnielectronico.es
$ opensc-tool-l
 [opensc-tool] ctx.c: 367: load_dynamic_driver: dynamic library '/ usr/lib64/libopensc-dnie.so': invalid module version
[Opensc-tool] ctx.c: 467: load_card_drivers: Unable to load 'dnie'.
Readers Known about:
Driver Name Nr
Pcsc 0 00 00 Gemplus Twin GemPC
$ opensc-tool-a
 [opensc-tool] ctx.c: 367: load_dynamic_driver: dynamic library '/ usr/lib64/libopensc-dnie.so': invalid module version
[Opensc-tool] ctx.c: 467: load_card_drivers: Unable to load 'dnie'.
Using With A card reader: Gemplus GemPC Twin 00 00
[Opensc-tool] reader-pcsc.c: 239: pcsc_transmit: unable to transmit
[Opensc-tool] apdu.c: 394: do_single_transmit: unable to transmit APDU
3b: 7f: 38:00:00:00:6 a: 44:4 e: 49:65:10:02:4 c: 34:01:13:03:90:00
Delawar @ FZ18E: ~ $ opensc-tool-n
 [opensc-tool] ctx.c: 367: load_dynamic_driver: dynamic library '/ usr/lib64/libopensc-dnie.so': invalid module version
[Opensc-tool] ctx.c: 467: load_card_drivers: Unable to load 'dnie'.
Using With A card reader: Gemplus GemPC Twin 00 00
[Opensc-tool] reader-pcsc.c: 239: pcsc_transmit: unable to transmit
[Opensc-tool] apdu.c: 394: do_single_transmit: unable to transmit APDU
Unidentified card

Not that easy

At this point, we learn that we have screwed up somewhere in the installation. Now OpenSC is waiting for a version of the module that is not what we have installed. Do not panic, there is a solution . We “only” have to create a module that uses the module installed. But deceiving OpenSC by saying it is another version.

My module version is 1.0.4 and opensc the 0.11.13-1.1, you must change this numbers with yours:

 $ mkdir / tmp / dnie
 $ cd / tmp / dnie
 $ cp / usr/lib/libopensc-dnie.so.1.0.4 libopensc-dnie.so.1.0.4_orig

Edit a file:

 $ vi patch.c
 char * version_maligna = "0.11.13-1.1";
 sc_driver_version char * () {
 version_maligna return;
 }

Patching the library and place it where it belongs:

$ gcc-fpic -g-c-Wall patch.c

$ objcopy - redefine-sym-libopensc sc_driver_version = orig_sc_driver_version libopensc-dnie.so.1.0.4 dnie.so.1.0.4_orig

$ chmod + x libopensc-dnie.so.1.0.4

$ gcc-shared-Wl,-soname, libwrapper-dnie.so libopensc-dnie.so.1.0.4 patch.o-o-dnie.so.1.0.0 libwrapper

$ sudo cp-dnie.so.1.0.0 libwrapper libopensc-dnie.so.1.0.4 / usr / lib

$ sudo ldconfig

Now that we have the library, we make opensc to use it in the file / etc / opensc / opensc.conf, replacing module = / usr / lib / libopensc-dnie.so, by < em> module = / usr / lib / libwrapper-dnie.so, .

Now opensc recognizes our electronic ID:

$ opensc-tool -l Known Readers about: Driver Name Nr Pcsc 0 00 00 Gemplus Twin GemPC

How to use the browser or an application to sign has already been extensively described in other manuals, including the official pages of the electronic ID.

en_GBEnglish (UK)