forked from eclipse-cbi/targetplatform-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix eclipse-cbi#28: Add support for b3aggrcon and b3aggr files
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
Showing
6 changed files
with
220 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...g.targetplatform/src/fr/obeo/releng/targetplatform/resource/B3AggrConResourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...eo.releng.targetplatform/src/fr/obeo/releng/targetplatform/resource/B3AggrSaxHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...platform/src/fr/obeo/releng/targetplatform/resource/B3AggrTargetPlatformResourceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...latform/src/fr/obeo/releng/targetplatform/resource/XtextResourceSetWithB3aggrSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |