Artificial Log4j

Thursday, May 21, 2015

Gradle war overlay

The standard way to extend a war artifact using Maven is to use Maven's Overlay Plugin.

Naturally, Gradle users wanted to adopt the same approach. And there are some solutions, including a gradle overlay plugin.

These all could be used. However, Gradle's powerful dependency management enables you to emulate the overlay plugin ad-hoc, and have a much more precise control on what you want to happen to your war.

Basically, what you need is to include a war as a non-transitive dependency, and copy all its contents to resulting war, preserving the changes you made.

apply plugin: 'war'

repositories {
 mavenCentral()
}

configurations {
 overlay {
  transitive = false
 }
}

dependencies {
 overlay('your:dependency1:version')
 overlay('your:dependency2:version')
}

war {
 duplicatesStrategy = 'exclude'
 
 configurations.overlay.filter({it.name.endsWith(".war")}).each {
  from zipTree(it)
 }
}
Of course, you may want to use other options of gradle war plugin together with this (e.g., include some configuration files into your WEB-INF), you may want to also include some zip dependencies into your resulting war, and exclude some problematic jars from your overlays in case you import a newer version of them.

apply plugin: 'war'

repositories {
 mavenCentral()
}

configurations {
 overlay {
  transitive = false
 }
}

dependencies {
 compile('org.problematic:problematic:newer_version')
 overlay('your:dependency1:version')
 overlay('your:dependency2:version')
}

war {
 duplicatesStrategy = 'exclude'

 webInf {
  from "$projectDir/config"
 }
 
 configurations.overlay.filter({it.name.endsWith(".war") || it.name.endsWith(".zip")}).each {
  from zipTree(it).matching { exclude '**/*problematic*.jar' }
 }
}
In case you want to use the imported war's dependencies at compile time, it is also easy.

apply plugin: 'war'

repositories {
 mavenCentral()
}

configurations {
 overlay
 compile.extendsFrom(overlay)
}

dependencies {
 overlay('your:dependency1:version')
 overlay('your:dependency2:version')
}

war {
 duplicatesStrategy = 'exclude'
 
 configurations.overlay.filter({it.name.endsWith(".war") || it.name.endsWith(".zip")}).each {
  from zipTree(it).matching { exclude '**/*.jar' }
 }
}
TL;DR
Turn off your plugins, RTFM, and

 use the force

of Gradle, Luke.

Friday, February 4, 2011

Virtual webcam for Skype Linux

For two nights I've been smoking on how to use my archaic Logitech Messenger Quickcam with Skype in Linux...

For the complete picture, it has to be mentioned that it works well in XP but there are no drivers for Vista or W7. Either because of this or whatever I did not bother to use it for a couple of years. (Ok, maybe 7.)

I was impressed when I plugged it into my xubuntu laptop and could immediately play with various effects Cheese offered to apply to the video.

Sure enough, Skype did not see the camera input.

SkypeWebCams said that I have to 'fiddle to get the camera working'.
The described 'fiddling' did not work though:
The webcam works automatically in 9.10 (the 2.6.30+ kernels) with the gspca_stv06xx driver, to run Skype with this driver type "LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype".


The same page proposed gstfakevideo, which uses gstreamer, virtual camera emulator and some Skype "hijacking". It did not work for me either. But virtual camera was a good idea.

...
...

I found and tried WebcamStudio, which seems to be quite a nice thing but still does not do what I need.

...
...
???

Finally I settled on v4l2loopback - a working! webcam emulator,
and gstreamer plain console utils - incredibly cool stuff!

HOW IT WORKS:
1. Install v4l2loopback kernel modul from (according to README).
https://github.com/umlaeute/v4l2loopback
This will create a virtual camera device (probably /dev/video0).

2. Install necessary gstreamer utils and plugins. (See 3.)

3.
Plug your camera (say it will be located at /dev/video1)
Run:
gst-launch v4l2src device=/dev/video1 ! ffmpegcolorspace ! video/x-raw-yuv,format=\(fourcc\)YUY2 ! v4l2sink device=/dev/video0

(4. If necessary, choose virtual cam in Skype).

The format conversion (format=\(fourcc\)YUY2) is essential here. YUY2 is good for Skype while e.g. YVYU and UYVY are not.

This setup should be the same with any webcam that works with Cheese but fails to work with skype but you may need to use "! videoscale" and "! videorate"
in addition to "! ffmpegcolorspace".

Actually gstreamer allows for much more flexibility when using this approach, i.e.
you may stream movies, desktop, even a combination of several inputs to a virtual cam.

Monday, July 12, 2010

If you ever wanted to change xkb layout with a simple command

If you have more than 2 keyboard layouts, you would want to switch between them rapidly.
Assigning a shortcut combination to every layout is what you want then.
(I.e. Ctrl+Shift+1 for english, Ctrl+Shift+2 for russian, Ctrl+Shift+3 for german etc).

However, while in Windows this can be done with some simple clicking in the keyboard layout configuration, Linux (at least the one running Gnome/Xfce) by default only provides cycling through the layouts.

Of course, there are always custom key shortcuts to every terminal command. What command would you choose then? After some time in google and man, you would eventually come up with setxkbmap .

I used this approach for a while, actually feeling that the cheese cake was just ordinary, not perfect at all:
1) It's not fast: setxkbmap resets the whole map. It takes some time, up to a second.
2) Setting "setxkbmap ru" would leave you without many standard shortcuts. E.g. Ctrl+t would
not work in browsers, since it would become Ctrl+е. For a new tab in a browser you would have to switch to english layout, Ctrl+t, switch back to russian layout.
3) Ok, actually, the problem in 2 can be avoided if you use, say, "setxkbmap ru,us" for russian
and "setxkbmap us,ru" for english. There's a catch: if you switched the layout via some graphical ide (e.g. xfce4-xkb-plugin) or with a standard cycling combination (e.g. smth like Ctrl+Alt), you will get your shortcuts mixed up. The latter action actually increments the index of the current layout (which doesn't get reset with setxkbmap). So after incrementing index from 0 to 1, "setxkbmap ru,us" will activate the "us" layout not the "ru" one.
4) Even if you somehow manage to get things right experimenting with stuff in 3), this is
really evil. What if I want to add another layout? Should I change half of the shortcuts I use? In fact, I just like to define layouts via some graphical settings editor, and not repeat any complex options with setxkbmap's.

Simply setting the above-mentioned index would do the trick. I didn't find any ubuntu util
that would allow me to do that. Looking through the source of e.g. xfce4-xkb-plugin
revealed that XkbLockGroup function would do the trick. And very soon I found a ready code for that here:

Compiling it gives you a nice, little and fast xkbswitch util.
Me, I put it into /usr/bin and use shortcuts to "xkbswitch i" for i=0,...,2 whenever I want to change my layout. Tasty.

P.S. Use -lX11 flag when compiling. The source:

#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include "X11/Xlib.h"
#include "X11/XKBlib.h"

void PrintUsage();

int
main(int argc, char **argv)
{
int xkbGroup;
if (argc < 2 || (xkbGroup = atoi(argv[1])) < 0 || xkbGroup > 3)
{
PrintUsage();
exit(0);
}


int xkbEventType, xkbError, xkbReason;
int mjr = XkbMajorVersion, mnr = XkbMinorVersion;
Display *display = NULL;

display = XkbOpenDisplay(NULL, &xkbEventType, &xkbError,
&mjr, &mnr, &xkbReason);
if (NULL == display)
{
warnx("Cannot open X display %s", XDisplayName(NULL));
switch (xkbReason)
{
case XkbOD_BadServerVersion:
case XkbOD_BadLibraryVersion:
warnx("Incomatible versions of client and server xkb libraries");
break;
case XkbOD_ConnectionRefused:
warnx("Connection to X server refused");
break;
case XkbOD_NonXkbServer:
warnx("XKB extension is not present");
break;
default:
warnx("Unknown error from XkbOpenDisplay: %d", xkbReason);
break;
}
exit(1);
}

Bool status = XkbLockGroup(display, XkbUseCoreKbd, xkbGroup);

XCloseDisplay(display);

return status ? 0 : 1;
}

void
PrintUsage()
{
printf("Usage: xkbswitch [0-3] sets keyboard layout\n");
}


Update:
In Gnome 3.6+ this does not work anymore. Use instead
"gsettings set org.gnome.desktop.input-sources current i",
where i is the index of your layout.

Wednesday, May 12, 2010

Another one

In an order complete Banach lattice: is any finite-rank positive operator approximable by positive operators having their range in finite-dimensional sublattices?

Nielsen seems to say yes, but I could not repeat the proof.

Wednesday, May 5, 2010

Stupid math question of the day

Sometimes, there are questions that seem to be fairly simple, yet I can't find the answer anywhere:


Will a vector sublattice of a Riesz space generated by a finite set be finite-dimensional?

Monday, May 25, 2009

Не взяла

Следы трагедии в понедельник утром на моем рабочем месте.
(Фото: Артур)