Skip to content

Commit

Permalink
Fix eclipse-cbi#28: Add support for b3aggrcon and b3aggr files
Browse files Browse the repository at this point in the history
With this commit it gets possible to includes b3aggr files
directly in a target platform definition.
This allow to express things like :
"I rely on what the amalgam project contributes to Luna"
by using :

include
"http://git.eclipse.org/c/simrel/org.eclipse.simrel.build.git/plain/amalgam.b3aggrcon"

or :
"I want the cdo version contributed for Kepler SR1"
with :
include
"http://git.eclipse.org/c/simrel/org.eclipse.simrel.build.git/plain/emf-cdo.b3aggrcon?id=KeplerSR1"

The b3aggrcon resource content is parsed on the fly
to produces instances of TargetPlatformDSL.

Known limitations :
- only the "repositories" and their children are used
( no platform filters..)
- only features and bundles are used
(no category mapping or exclusion list.)
- references within a b3aggr file are not resolved.

https://git.eclipse.org/c/simrel/org.eclipse.simrel.build.git/plain/simrel.b3aggr

Gives you nothing as all the actual contributions are in the included
*b3aggrcon files.
  • Loading branch information
cbrun committed Jul 11, 2014
1 parent 177df00 commit 02835f0
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,56 @@
*/
package fr.obeo.releng.targetplatform;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.xtext.conversion.IValueConverterService;
import org.eclipse.xtext.conversion.impl.AbstractIDValueConverter;
import org.eclipse.xtext.resource.XtextResourceSet;

import com.google.inject.Provider;

import fr.obeo.releng.targetplatform.conversion.TargetPlatformConverter;
import fr.obeo.releng.targetplatform.conversion.TargetPlatformIDValueConverter;
import fr.obeo.releng.targetplatform.resource.XtextResourceSetWithB3aggrSupport;
import fr.obeo.releng.targetplatform.util.LocationIndexBuilder;

/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
* Use this class to register components to be used at runtime / without the
* Equinox extension registry.
*/
public class TargetPlatformRuntimeModule extends fr.obeo.releng.targetplatform.AbstractTargetPlatformRuntimeModule {
public class TargetPlatformRuntimeModule extends
fr.obeo.releng.targetplatform.AbstractTargetPlatformRuntimeModule {

@Override
public Class<? extends IValueConverterService> bindIValueConverterService() {
return TargetPlatformConverter.class;
}

public Class<? extends AbstractIDValueConverter> bindAbstractIDValueConverter() {
return TargetPlatformIDValueConverter.class;
}

public Class<? extends LocationIndexBuilder> bindLocationIndexBuilder() {
return LocationIndexBuilder.class;
}

public Provider<IProvisioningAgent> provideIProvisioningAgent() {
return new Provider<IProvisioningAgent>() {
public IProvisioningAgent get() {
return TargetPlatformBundleActivator.getInstance().getProvisioningAgent();
return TargetPlatformBundleActivator.getInstance()
.getProvisioningAgent();
}
};
}

@Override
public Class<? extends ResourceSet> bindResourceSet() {
return XtextResourceSetWithB3aggrSupport.class;
}

@Override
public Class<? extends XtextResourceSet> bindXtextResourceSet() {
return XtextResourceSetWithB3aggrSupport.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
package fr.obeo.releng.targetplatform;

import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;

import com.google.inject.Injector;

import fr.obeo.releng.targetplatform.resource.B3AggrConResourceFactory;

/**
* Initialization support for running Xtext languages
* without equinox extension registry
Expand All @@ -13,6 +16,11 @@ public class TargetPlatformStandaloneSetup extends TargetPlatformStandaloneSetup

public static void doSetup() {
new TargetPlatformStandaloneSetup().createInjectorAndDoEMFRegistration();
/*
* add support for b3aggr models
*/
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("b3aggrcon", new B3AggrConResourceFactory());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("b3aggr", new B3AggrConResourceFactory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package fr.obeo.releng.targetplatform.resource;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Factory;

public class B3AggrConResourceFactory implements Factory {

public B3AggrConResourceFactory() {


}

@Override
public Resource createResource(URI uri) {
return new B3AggrTargetPlatformResourceImpl(uri);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package fr.obeo.releng.targetplatform.resource;

import java.util.Collection;
import java.util.Set;
import java.util.Stack;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.google.common.collect.Sets;

import fr.obeo.releng.targetplatform.IU;
import fr.obeo.releng.targetplatform.Location;
import fr.obeo.releng.targetplatform.TargetPlatformFactory;

public class B3AggrSaxHandler extends DefaultHandler {

private Stack<Location> locations = new Stack<Location>();

private Set<Location> popedLocations = Sets.newLinkedHashSet();

@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
super.startElement(uri, localName, qName, attributes);
if ("repositories".equals(qName)) {
String locationURI = attributes.getValue("location");
if (locationURI != null) {
Location newLocation = TargetPlatformFactory.eINSTANCE
.createLocation();
newLocation.setUri(locationURI);
locations.push(newLocation);
}
} else if (locations.size() > 0
&& ("features".equals(qName) || "bundles".equals(qName))) {
String name = attributes.getValue("name");
String versionRange = attributes.getValue("versionRange");
if (name != null) {
IU newIU = TargetPlatformFactory.eINSTANCE.createIU();
newIU.setID(name);
locations.peek().getIus().add(newIU);
if (versionRange != null) {
newIU.setVersion(versionRange);
}

}
}
}

@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
super.endElement(uri, localName, qName);
if ("repositories".equals(qName) && !locations.isEmpty()) {
popedLocations.add(locations.pop());
}
}

public Collection<Location> getLocations() {
return popedLocations;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package fr.obeo.releng.targetplatform.resource;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.xtext.diagnostics.ExceptionDiagnostic;
import org.xml.sax.SAXException;

import fr.obeo.releng.targetplatform.Location;
import fr.obeo.releng.targetplatform.TargetPlatform;
import fr.obeo.releng.targetplatform.TargetPlatformFactory;

public class B3AggrTargetPlatformResourceImpl extends ResourceImpl {

public B3AggrTargetPlatformResourceImpl(URI uri) {
super(uri);
}

@Override
protected void doLoad(InputStream inputStream, Map<?, ?> options)
throws IOException {
getContents().clear();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
try {
SAXParser parser = saxFactory.newSAXParser();
B3AggrSaxHandler saxHandler = new B3AggrSaxHandler();
parser.parse(inputStream, saxHandler);
TargetPlatform b3aggrTP = TargetPlatformFactory.eINSTANCE
.createTargetPlatform();
b3aggrTP.setName(getURI().toString());
Collection<Location> locations = saxHandler.getLocations();
b3aggrTP.getContents().addAll(locations);
getContents().add(b3aggrTP);
} catch (ParserConfigurationException e) {

this.getErrors().add(new ExceptionDiagnostic(e));
} catch (SAXException e) {
this.getErrors().add(new ExceptionDiagnostic(e));
}
}

@Override
protected void doSave(OutputStream outputStream, Map<?, ?> options)
throws IOException {
/*
* we are not able to save here.
*/
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.obeo.releng.targetplatform.resource;

import org.eclipse.xtext.resource.XtextResourceSet;

public class XtextResourceSetWithB3aggrSupport extends XtextResourceSet {

public XtextResourceSetWithB3aggrSupport() {
super();
/*
* add support for b3aggr models
*/
getResourceFactoryRegistry().getExtensionToFactoryMap().put(
"b3aggrcon", new B3AggrConResourceFactory());
getResourceFactoryRegistry().getExtensionToFactoryMap().put("b3aggr",
new B3AggrConResourceFactory());
}
}

0 comments on commit 02835f0

Please sign in to comment.