Generate p2 composite repository metadata from Jenkins (Hudson) jobs on the fly

Serving p2 build artifacts from Jenkins is complicated if builds from multiple Jenkins jobs should be aggregated into a master p2 composite repository. A rather simple approach to this problem is listed below, that uses Apache to generate compositeArtifacts.xml and compositeContent.xml on the fly.
We (vogella) uses this to generate repos for our various Jenkins jobs (e.g the content of compositeArtifacts.xml is generated).
  • Install Apache and point DocumentRoot to Jenkin’s jobs/ directory
    • Enable cgi scripts in Apache
      • On Debian or Ubuntu this is `a2enmod cgid`
    • AllowOverride all for the jobs/ directory (needed in order for .htaccess to work)
  • Clone https://github.com/lemmy/p2CompositeRepoGeneratorinto jobs/ and fix file ownership/permissions
    • Cloning into a non-empty directory isn’t allowed, thus move the content of p2CompositeRepoGenerator/ into jobs/ (including .git)
    • `chmod +x composite*.xml`
    • `chown jenkins:nogroup composite*.xml .htaccess p2.index`
  • Symlinking composite*.xml from individual jobs generates a p2 composite repository for all builds of that Jenkins jobs (contrary to all builds of all jobs)
  • Open a browser on the corresponding DocumentRoot url and check the content of compositeArtifacts.xml and compositeContent.xml
    • If no repositories show up, check that Jenkins even archives non-zipped p2 repository artifacts during the post build action
    • An internal server errors can best be diagnosed by opening the Apache error log
  • The final directory structure should look similar to (the second part lists the structure for our I-build of the eclipse.platform.releng.aggregator) :
jenkins@build:~$ ls -lA jobs/
total 72
drwxr-xr-x  8 jenkins nogroup 4096 Mar 27 10:18 .git
-rw-r--r--  1 jenkins nogroup   28 Mar 27 09:06 .gitignore
-rw-r--r--  1 jenkins nogroup  402 Mar 27 09:02 .htaccess
drwxr-xr-x  5 jenkins nogroup 4096 Mar 27 10:42 C-MASTER-e4tools-0.14
drwxr-xr-x  5 jenkins nogroup 4096 Mar 27 10:42 I-MASTER-eclipse.platform.releng.aggregator
-rwxr-xr-x  1 jenkins nogroup 3192 Mar 27 10:18 compositeArtifacts.xml
lrwxrwxrwx  1 jenkins nogroup   22 Mar 27 09:02 compositeContent.xml
	-> compositeArtifacts.xml
-rw-r--r--  1 jenkins nogroup  129 Mar 27 09:02 p2.index

jenkins@build:~$ ls -lA jobs/I-MASTER-eclipse.platform.releng.aggregator/
total 68
drwxr-xr-x   5 jenkins nogroup  4096 Mar 27 10:32 builds
lrwxrwxrwx   1 jenkins nogroup    44 Mar 26 13:14 compositeArtifacts.xml
	-> /var/lib/jenkins/jobs/compositeArtifacts.xml
lrwxrwxrwx   1 jenkins nogroup    42 Mar 26 13:16 compositeContent.xml
	-> /var/lib/jenkins/jobs/compositeContent.xml
-rw-r--r--   1 jenkins nogroup  6458 Mar 26 11:57 config.xml
-rw-r--r--   1 jenkins nogroup     3 Mar 26 11:57 nextBuildNumber
lrwxrwxrwx   1 jenkins nogroup    11 Mar 27 10:42 p2.index -> ../p2.index

Disclaimer: This is probably not the best idea for busy p2 repositories. The script a) scans the directory tree for every invocation and b) sets the timestamp to $now (messing up caches). b3aggr is a much better tool for frequently used repositories.
Posted in Markus Kuppe | Leave a comment

Want to try out NatTable 1.0.0? by Dirk Fauth

First of all: No NatTable 1.0.0 is not yet released!

But EclipseCon starts today. Unfortunately there is no NatTable talk at EclipseCon, but we also want to participate in some kind of way. So we thought of celebrating this with announcing that you are finally able to install NatTable 1.0.0 Snapshots via p2 Update site!

The last months there was a lot of work going on about the third-party-dependencies and the build process of NatTable. With the release of GlazedLists 1.9 and a lot of work around Apache POI, the Eclipse Orbit Project now contains both of them. This means GlazedLists and Apache POI can be added to Eclipse projects via p2 Update Site. They are added to the latest stable Orbit build and can be installed to your Eclipse installation or added to your target platform by using the following Update Site URL:

http://download.eclipse.org/tools/orbit/downloads/drops/S20130308121626/repository/

With this we were able to modify the NatTable build process and get rid of the local JAR dependencies. NatTable core and the extensions can now be build in Hudson, and therefore we are now also able to provide a fully working p2 Update Site for NatTable. As we are not finished with the final release of NatTable 1.0.0, there are currently only the SNAPSHOT builds available. From our point of view these are still great news!

If you want to try out the new NatTable 1.0.0 you can give the latest SNAPSHOT build a try. For this have a look at http://download.eclipse.org/nattable/snapshots/ and get the URL or the zipped p2 repository of the latest SNAPSHOT.

It is not perfect yet, but you are able to install and use NatTable without downloading and adding JARs to your installations dropins folder. This also gives the opportunity to have a look at the new installation and the new version prior final release. So don’t hesitate to give us feedback soon.

Now have fun with the NatTable 1.0.0 SNAPSHOTS and attending interesting talks and people at EclipseCon. If you want to meet with guys from the NatTable team, lookout for Edwin Park our project lead.

Posted in Dirk Fauth, Eclipse | 7 Comments

Dynamic menu contributions in Eclipse 4 – Guest blog by Marco Descher

While with the Juno Release, Eclipse 4 has become the new standard, there is still some functionality from Eclipse 3.x which is missing, at least when it comes to the developers view of things. With the upcoming Kepler release, however, this list is less one item, namely dynamic menu contributions.

In Eclipse 3 it was possible to add “dynamic” as an element to the org.eclipse.ui.menus contribution extension point for a given menu. This provided the capability to programmatically modify the entries offered within a menu, which is quite handy if one wants, for example, to alter the menu according to the given application context.

Eclipse bug 389063 brought the basic support and now with M6 some, but not all children’s diseases to the port are fixed (Bug 403083 and Bug 403081 did not make it in time for M6) and tooling support is provided as of 0.13. So it’s about time for a wrap up on the usage.

There are generally only three entities required to know:

  • the new model UI element DynamicMenuContribution
  • the new annotation @AboutToShow
  • the new annotation @AboutToHide

Let’s implement a simple dynamic menu contribution using the current Eclipse 4 tools for Kepler to demonstrate the usage.
 

We start of by declaring a menu contribution for a menu located in the application main menu.

1_e4ToolingDynamic

Subsequently we use the provided wizard to generate a template for our dynamic menu contribution class.

2_newClassWizard

where we amend the existing @AboutToShow provided method with the following code.

@AboutToShow
public void aboutToShow(List<MMenuElement> items) {
	MDirectMenuItem dynamicItem = MMenuFactory.INSTANCE
			.createDirectMenuItem();
	dynamicItem.setLabel("Dynamic Menu Item (" + new Date() + ")");
	dynamicItem.setContributorURI("platform:/plugin/at.descher.test");
	dynamicItem
			.setContributionURI("bundleclass://at.descher.test/at.descher.test.DirectMenuItem");	
        items.add(dynamicItem);
}

The dynamicItem.setContributionURI(*) provides a simple handler which, on click of the menu element, outputs some random code.

package at.descher.test;

import org.eclipse.e4.core.di.annotations.Execute;

public class DirectMenuItem {
	@Execute
	public void execute() {
		System.err.println("Direct Menu Item selected");
	}
}

For the usage of @Execute check the following link.

If we now start the application, each time we open the respective menu we will see the current date.

So, the dynamic menu contribution hooks into the menus process of opening (AboutToShow) and closing (AboutToHide), and dynamically queries the method in order to populate the menu. It is important not to put any expensive code into the @AboutToShow annotated method, as this directly blocks the opening of the menu the dynamic contribution is child of.

Although the usage of @AboutToHide is optional, at the current M6 one has to provide such a method due to bug 403083. After 403081 is fixed it will be also possible to refactor the code presented above to this:

@AboutToShow
public void aboutToShow(List<MMenuElement> items, EModelService modelService) {
	MDirectMenuItem dynamicItem = modelService
				.createModelElement(MDirectMenuItem.class);
	dynamicItem.setLabel("Dynamic Menu Item (" + new Date() + ")");
	dynamicItem.setContributorURI("platform:/plugin/at.descher.test");
	dynamicItem
			.setContributionURI("bundleclass://at.descher.test/at.descher.test.CommandHandler");	items.add(dynamicItem);
}

Thanks to Paul Webster for helping me to get this feature done! :)

Author: Marco Descher develops, and teaches students at the Fachhochschule Vorarlberg to develop, Eclipse based applications. If you want to know more about me just check out my homepage.

marco

Posted in Eclipse, Lars Vogel | Tagged | Comments Off

Git auto-completion for the bash shell

You can enable auto-completion for Git commands in the bash shell. For this copy the following file to your home directory under the name “.git-completion.bash”.

git-completion.bash in the main Git repository.

Afterwards add the following lines to your .bashrc file and restart the bash.

if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi

Now you have code completion, e.g. if you type git c and press tag you see the possible values.

Posted in Lars Vogel, Other | Tagged | 4 Comments

Context functions in Eclipse RCP

Context functions in Eclipse RCP are powerful tools. They allow you to register for certain keys in the context and create objects for these keys lazily. I created a separate tutorial for them.
See Context functions in Eclipse for details on them.

Posted in Eclipse, Lars Vogel | Tagged , , | Comments Off

Eclipse 4 tools update sites available from vogella

Markus is currently busy with Tycho to setup several builds incuding a vogella Eclipse IDE build.

As the first result we have now running builds for the Eclipse 4 tools specific for Juno and Kepler.

http://download.vogella.com/kepler/e4tools – p2 update site for Kepler
http://download.vogella.com/juno/e4tools – p2 update site for Juno

Use the Eclipse update manager to install them.

These update site are supposed to stay stable and are based on the official Eclipse e4 tools repository in Git. The idea is that you don’t have to search for the latest and greatest official update site which is changing regulary.

We have also created a branch for Kepler specific development which allow you use Eclipse 4.3 without any additional tweak to create Eclipse 4 RCP application.

I hope this helps.

Posted in Eclipse | Tagged , | Comments Off

Android – Why not to use static for View fields in your Activity or Fragments by Lars Vogel

Your should not use static for defining fields for Views in your Android application.

Then creating a View, the LayoutInflater (used in setContentView(R.layout.ID)) uses the current Context (of the Activity) and pass it to the inflated Views. A reference to the given Context is always kept by the View class and can be retrieved via the getContext() method.

As a consequence, keeping a static reference on a View means that your Activity keeps a reference on your View which keeps a reference on the activity instance. This is what leads to the leak.

Thanks to Cyril Mottier for explaining that in G+.

Posted in Android | Comments Off

Determine the active Android framework maintainer by Lars Vogel

If you want to know the current Android maintainer you can use the following link:

Android framework maintainer

Thanks to Arvid Gerstmann for pointing me to that URL on Google+.

Posted in Android | Tagged | Comments Off

Cross/weak validation in NatTable by Dirk Fauth

Sometimes it is necessary to implement logic that validates one value against another in the same object. Having a fromDate and a toDate in your model object, where the toDate can’t be before the fromDate, is a good example for that. This is also called “cross validation”. As in NatTable values will not be committed to the model if the validation fails, a mechanism for “weak validation” is needed. This means that the value will be committed to the model, even if the validation fails.

To implement such a “cross/weak validation” in NatTable, you should first consider to not use an IDataValidator. Instead move the validation logic to some static class/method, so it can be used in various places. For an example let’s use the following EventData class and static isEventDataValid(EventData) method.

public class EventData {
	private String title;
	private String description;
	private String where;
	private Date fromDate;
	private Date toDate;
	...
	//getters and setters
}
public static boolean isEventDataValid(EventData event) {
	return (event.getFromDate().before(event.getToDate()));
}

This validation method will be called by a custom IConfigLabelAccumulator that should apply a special label in case the validation of the cell content fails.

public class CrossValidationLabelAccumulator 
				extends AbstractOverrider {

	private IRowDataProvider bodyDataProvider;

	public CrossValidationLabelAccumulator(
			IRowDataProvider bodyDataProvider) {
		this.bodyDataProvider = bodyDataProvider;
	}

	@Override
	public void accumulateConfigLabels(
			LabelStack configLabels, 
			int columnPosition, 
			int rowPosition) {

		//get the row object out of the dataprovider
		EventData rowObject = this.bodyDataProvider
					.getRowObject(rowPosition);

		//in column 3 and 4 there are the values that 
		//are cross validated
		if (columnPosition == 3 || columnPosition == 4) {
			if (!isEventDataValid(rowObject)) {
				configLabels.addLabel(“INVALID”);
			}
		}
	}
}

To render the cell accordingly register a style against that label, so invalid data is visible to the user.

IStyle validationErrorStyle = new Style();
validationErrorStyle.setAttributeValue(
		CellStyleAttributes.BACKGROUND_COLOR, 
		GUIHelper.COLOR_RED);
validationErrorStyle.setAttributeValue(
		CellStyleAttributes.FOREGROUND_COLOR, 
		GUIHelper.COLOR_WHITE);

configRegistry.registerConfigAttribute(
		CellConfigAttributes.CELL_STYLE, 
		validationErrorStyle,
		DisplayMode.NORMAL,
		“INVALID”);

cross_validation_example

Doing the above steps, invalid data will be rendered differently, while the model is updated with that invalid data. As the model now contains invalid data you need to do additional checks, if the model data needs to be used afterwards. That’s why it is useful to extract the validation logic to a static class/method.

The approach described above has of course the downsite that you can’t tell the user why the current entered value is not valid. With NatTable 1.0.0 you will be able to work around this. One possible solution will be to keep the validator configuration or create an IDataValidator that uses the validation logic from the static class/method created before and register it against the cross validation cell labels.

class EventDataValidator extends DataValidator {
	private IRowDataProvider bodyDataProvider;

	EventDataValidator(
		IRowDataProvider bodyDataProvider) {
		this.bodyDataProvider = bodyDataProvider;
	}

	@Override
	public boolean validate(
		int columnIndex, int rowIndex, Object newValue) {

		//get the row object out of the dataprovider
		EventData rowObject = this.bodyDataProvider
					.getRowObject(rowIndex);
		if (!isEventDataValid(rowObject)) {
			throw new ValidationFailedException(
				"fromDate is not before toDate");
		}
		return true;
	}

}

Then register a DialogErrorHandling that is configured to support cross validation.

configRegistry.registerConfigAttribute(
	EditConfigAttributes.VALIDATION_ERROR_HANDLER, 
	new DialogErrorHandling(true),
	DisplayMode.EDIT,
	CrossValidationGridExample.DATE_LABEL);

If a validation error occurs, this will open a dialog showing the validation error message, giving the opportunity to changing, discarding or committing the value.cross_validation_error_dialog

You can find the complete example named CrossValidationGridExample in the current master branch of the NatTable. For more information on how to clone the Git repository and setup the development environment, have a look here.

Posted in Dirk Fauth, Eclipse | Comments Off

Eclipse 4.2.2. is out – Includes several performance enhancements – Get your update

Eclipse 4.2.2 fixes several memory leaks and contains many critical performance improvements.

If you are using Eclipse 4.2.0 or Eclipse 4.2.1. I highly recommend to run Help -> Check for updates and to install the latest version.

Or get the full version Eclipse download area.

Posted in Eclipse, Lars Vogel | Comments Off