Skip to content
Snippets Groups Projects
Commit eb204e7a authored by Mark Prediger's avatar Mark Prediger
Browse files

uaal pax runner: support of different middleware versions through xml...

uaal pax runner: support of different middleware versions through xml configuration files implemented (update)
parent 916dfd5a
No related branches found
No related tags found
No related merge requests found
......@@ -37,12 +37,13 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.universaal.uaalpax.model.BundleEntry;
import org.universaal.uaalpax.model.BundleSet;
import org.universaal.uaalpax.model.LaunchURL;
import org.universaal.uaalpax.ui.dialogs.AddEditUrlDialog;
public class AllLibsBlock extends UIBlock implements ProjectTable.BundleDoubleClickListener {
public class AllBundlesBlock extends UIBlock implements ProjectTable.BundleDoubleClickListener {
private ProjectTable table;
public AllLibsBlock(UniversAALTab uAALTab, Composite parent, int style) {
public AllBundlesBlock(UniversAALTab uAALTab, Composite parent, int style) {
super(uAALTab, parent, style);
}
......@@ -134,7 +135,7 @@ public class AllLibsBlock extends UIBlock implements ProjectTable.BundleDoubleCl
getUAALTab().addBundle(be);
notifyChanged();
StructuredSelection selection = new StructuredSelection(new Object[] {be});
StructuredSelection selection = new StructuredSelection(new Object[] { be });
table.getViewer().setSelection(selection, true);
}
}
......@@ -147,13 +148,23 @@ public class AllLibsBlock extends UIBlock implements ProjectTable.BundleDoubleCl
int code = d.open();
if (code == Window.OK) {
getUAALTab().getModel().remove(be);
BundleEntry newBe = new BundleEntry(d.getURL(), be.isSelected(), be.isStart(), d.getLevel(), be.isUpdate());
getUAALTab().addBundle(newBe);
notifyChanged();
int level = be.getLevel();
LaunchURL url = be.getLaunchUrl();
if (!url.equals(d.getURL())) {
getUAALTab().removeBundle(be);
BundleEntry newBe = new BundleEntry(d.getURL(), be.isSelected(), be.isStart(), d.getLevel(), be.isUpdate());
getUAALTab().addBundle(newBe);
be = newBe;
} else { // url not changed
if (level != d.getLevel()) {
be.setLevel(d.getLevel());
getUAALTab().getModel().getBundles().updateBundleOptions(be);
getUAALTab().getModel().updatePresenters();
}
}
StructuredSelection selection = new StructuredSelection(new Object[] {newBe});
StructuredSelection selection = new StructuredSelection(new Object[] { be });
table.getViewer().setSelection(selection, true);
}
}
......@@ -184,8 +195,7 @@ public class AllLibsBlock extends UIBlock implements ProjectTable.BundleDoubleCl
table.setGrayed(grayOut);
table.getViewer().refresh(true);
return new BundleSet(); // return empty map since all projects which were passed to here are additional
// libraries
return new BundleSet(); // return empty map since all projects which were passed to here are additional libraries
}
public void onBundleClicked(BundleEntry be) {
......
......@@ -18,7 +18,7 @@
limitations under the License.
*/
package org.universaal.uaalpax.model;
package org.universaal.uaalpax.versionprovider;
import java.util.Collection;
import java.util.HashMap;
......@@ -26,6 +26,11 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.universaal.uaalpax.model.ArtifactURL;
import org.universaal.uaalpax.model.BundleEntry;
import org.universaal.uaalpax.model.BundleSet;
import org.universaal.uaalpax.model.LaunchURL;
public class HardcodedConfigProvider implements UAALVersionProvider {
private static Map<String, BundleSet> middlewares = new HashMap<String, BundleSet>();
private static Map<String, Map<String, BundleSet>> features = new HashMap<String, Map<String, BundleSet>>();
......@@ -43,7 +48,7 @@ public class HardcodedConfigProvider implements UAALVersionProvider {
new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.container.xfaces/1.1.1-SNAPSHOT"), "true@true@2@true"),
new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.data.representation/1.1.1-SNAPSHOT"), "true@true@4@false"),
new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.data.serialization/1.1.1-SNAPSHOT"), "true@true@4@false"),
new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui.osgi/1.1.1-SNAPSHOT"), "true@true@6@false"),
new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui/1.1.1-SNAPSHOT"), "true@true@6@false"),
new BundleEntry(new LaunchURL("wrap:mvn:java3d/j3d-core/1.3.1"), "true@true@2@false"),
new BundleEntry(new LaunchURL("wrap:mvn:java3d/vecmath/1.3.1"), "true@true@2@false"),
......@@ -56,8 +61,7 @@ public class HardcodedConfigProvider implements UAALVersionProvider {
private static final String[] vsu111_snapshot = new String[] { "org.universAAL.middleware/mw.acl.interfaces/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.context/1.1.1-SNAPSHOT", "org.universAAL.middleware/mw.bus.model/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.service/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.container.osgi/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.service/1.1.1-SNAPSHOT", "org.universAAL.middleware/mw.container.osgi/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.container.xfaces/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.data.representation/1.1.1-SNAPSHOT",
"org.universAAL.middleware/mw.data.serialization/1.1.1-SNAPSHOT", };
......@@ -120,11 +124,9 @@ public class HardcodedConfigProvider implements UAALVersionProvider {
private static final String[] vsu121_snapshot = new String[] { "org.universAAL.middleware/mw.container.xfaces.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.acl.interfaces.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.container.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.model.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.container.osgi/1.2.1-SNAPSHOT", "org.universAAL.middleware/mw.bus.model.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.data.representation.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.service.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.context.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.bus.service.osgi/1.2.1-SNAPSHOT", "org.universAAL.middleware/mw.bus.context.osgi/1.2.1-SNAPSHOT",
"org.universAAL.middleware/mw.data.serialization.osgi/1.2.1-SNAPSHOT" };
private static final BundleEntry[] m130 = new BundleEntry[] {
......@@ -194,25 +196,38 @@ public class HardcodedConfigProvider implements UAALVersionProvider {
ignoreSet.add("org.apache.felix/org.osgi.foundation");
ignoreSet.add("org.apache.felix/org.apache.felix.log");
ignoreSet.add("org.osgi/org.osgi.core");
ignoreSet.add("org.osgi/org.osgi.osgi");
ignoreSet.add("org.osgi/org.osgi.compendium");
Map<String, BundleSet> f111 = new HashMap<String, BundleSet>();
f111.put("UI Bus", new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui.osgi/1.1.1-SNAPSHOT"), "")));
f111.put("UI Bus",
new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui/1.1.1-SNAPSHOT"), "")));
f111.put("CHE",
new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.context/ctxt.che/1.1.1-SNAPSHOT"), "")).add(
new BundleEntry(new LaunchURL("mvn:org.universAAL.ontology/ont.che/1.1.1-SNAPSHOT"), "")));
features.put("1.1.1-SNAPSHOT", f111);
Map<String, BundleSet> f120 = new HashMap<String, BundleSet>();
f120.put("UI Bus", new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui.osgi/1.2.0"), "")));
f120.put("CHE",
new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.context/ctxt.che/1.2.0"), "")).add(
new BundleEntry(new LaunchURL("mvn:org.universAAL.ontology/ont.che/1.2.0"), "")));
features.put("1.2.0", f120);
Map<String, BundleSet> f121 = new HashMap<String, BundleSet>();
f121.put("UI Bus", new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui.osgi/1.2.1-SNAPSHOT"), "")));
f121.put("UI Bus",
new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui.osgi/1.2.1-SNAPSHOT"), "")));
f121.put("CHE",
new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.context/ctxt.che/1.2.1-SNAPSHOT"), "")).add(
new BundleEntry(new LaunchURL("mvn:org.universAAL.ontology/ont.che/1.2.1-SNAPSHOT"), "")));
features.put("1.2.1-SNAPSHOT", f121);
Map<String, BundleSet> f130 = new HashMap<String, BundleSet>();
f130.put("UI Bus", new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.middleware/mw.bus.ui.osgi/1.3.0"), "")));
f130.put("CHE",
new BundleSet().add(new BundleEntry(new LaunchURL("mvn:org.universAAL.context/ctxt.che/1.3.0"), "")).add(
new BundleEntry(new LaunchURL("mvn:org.universAAL.ontology/ont.che/1.3.0"), "")));
features.put("1.3.0", f130);
}
......
......@@ -18,11 +18,14 @@
limitations under the License.
*/
package org.universaal.uaalpax.model;
package org.universaal.uaalpax.versionprovider;
import java.util.Collection;
import java.util.Set;
import org.universaal.uaalpax.model.ArtifactURL;
import org.universaal.uaalpax.model.BundleSet;
/**
* Uses to determine available uAAL middleware versions and the needed bundles for those versions.
......@@ -69,11 +72,11 @@ public interface UAALVersionProvider {
/**
* Checks whether given bundle should be ignored (-> not added to the run config since it is not necessary) using given middleware version.
*
* @param launchUrl launch url
* @param artifactUrl launch url
* @param version middleware version
* @return true if bundle should be ignored, otherwise false
*/
public boolean isIgnoreArtifactOfVersion(String version, ArtifactURL launchUrl);
public boolean isIgnoreArtifactOfVersion(String version, ArtifactURL artifactUrl);
/**
* Computes how probably the given bundle urls represent a run config of a certain uaal version.
......
package org.universaal.uaalpax.versionprovider;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.universaal.uaalpax.model.ArtifactURL;
import org.universaal.uaalpax.model.BundleEntry;
import org.universaal.uaalpax.model.BundleSet;
import org.universaal.uaalpax.model.LaunchURL;
import org.universaal.uaalpax.model.UnknownBundleFormatException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class XMLVersionProvider implements UAALVersionProvider {
private static String PROP_VERSIONS = "versions";
private static final String TAG_VERSION = "version";
private static final String TAG_MIDDLEWARE = "middleware";
private static final String TAG_BUNDLESET = "bundleset";
private static final String TAG_BUNDLE = "bundle";
private static final String TAG_FEATURES = "features";
private static final String TAG_RELEVANT = "relevant";
private static final String TAG_INGNORE = "ignore";
private static final String TAG_ARTIFACTSET = "artifactset";
private static final String TAG_ARTIFACT = "artifact";
private static final String ATTR_LEVEL = "level";
private static final String ATTR_NAME = "name";
private Map<String, BundleSet> middlewares = new HashMap<String, BundleSet>();
private Map<String, Map<String, BundleSet>> features = new HashMap<String, Map<String, BundleSet>>();
private Map<String, Set<ArtifactURL>> versionSegnificantURLs = new HashMap<String, Set<ArtifactURL>>();
private Map<String, Set<ArtifactURL>> ignoreSet = new HashMap<String, Set<ArtifactURL>>();
public XMLVersionProvider() {
Bundle bundle = Platform.getBundle("org.universaal.igd.uaal.runner.ui");
URL fileURL = FileLocator.find(bundle, new Path("versions/versions.properties"), null);
try {
Properties props = new Properties();
InputStream in = fileURL.openStream();
props.load(in);
in.close();
String version_string = props.getProperty(PROP_VERSIONS);
if (version_string != null) {
String[] versions = version_string.split(" ");
for (String v : versions) {
if (!v.isEmpty()) {
try {
loadVersion(v, FileLocator.find(bundle, new Path("versions/" + v + ".xml"), null));
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassCastException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DOMException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void loadVersion(String version, URL url) throws IOException, SAXException, ParserConfigurationException {
if (url == null) {
System.err.println("could not find configuration file for middleware version " + version);
return;
}
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(url.openStream());
Element root = (Element) doc.getElementsByTagName(TAG_VERSION).item(0);
NodeList bundlesNodes = ((Element) ((Element) root.getElementsByTagName(TAG_MIDDLEWARE).item(0))
.getElementsByTagName(TAG_BUNDLESET).item(0)).getElementsByTagName(TAG_BUNDLE);
BundleSet bs = new BundleSet();
loadBundles(bundlesNodes, bs);
middlewares.put(version, bs);
final Map<String, BundleSet> featureSets = new HashMap<String, BundleSet>();
NodeList featureList = ((Element) root.getElementsByTagName(TAG_FEATURES).item(0)).getElementsByTagName(TAG_BUNDLESET);
traverseElements(featureList, new ElementTraverser() {
public void traverse(Element set) {
String featureName = set.getAttribute(ATTR_NAME);
if (featureName.isEmpty()) {
// TODO print warning message
return;
}
NodeList bundles = set.getElementsByTagName(TAG_BUNDLE);
BundleSet featureBundles = new BundleSet();
loadBundles(bundles, featureBundles);
featureSets.put(featureName, featureBundles);
}
});
features.put(version, featureSets);
final Set<ArtifactURL> relevant = new HashSet<ArtifactURL>();
NodeList relevantBundles = ((Element) ((Element) root.getElementsByTagName(TAG_RELEVANT).item(0)).getElementsByTagName(
TAG_ARTIFACTSET).item(0)).getElementsByTagName(TAG_ARTIFACT);
traverseElements(relevantBundles, new ElementTraverser() {
public void traverse(Element e) {
relevant.add(new ArtifactURL(e.getTextContent()));
}
});
versionSegnificantURLs.put(version, relevant);
final Set<ArtifactURL> ignore = new HashSet<ArtifactURL>();
NodeList irgnoreBundles = ((Element) ((Element) root.getElementsByTagName(TAG_INGNORE).item(0)).getElementsByTagName(
TAG_ARTIFACTSET).item(0)).getElementsByTagName(TAG_ARTIFACT);
traverseElements(irgnoreBundles, new ElementTraverser() {
public void traverse(Element e) {
ignore.add(new ArtifactURL(e.getTextContent()));
}
});
ignoreSet.put(version, ignore);
}
private void loadBundles(NodeList bundlesNodes, final BundleSet bs) {
traverseElements(bundlesNodes, new ElementTraverser() {
public void traverse(Element bundle) {
LaunchURL url = new LaunchURL(bundle.getTextContent());
int level = -1;
try {
level = Integer.parseInt(bundle.getAttribute(ATTR_LEVEL));
} catch (NumberFormatException e) {
}
bs.add(new BundleEntry(url, true, true, level, false));
}
});
}
public Set<String> getAvailableVersions() {
return middlewares.keySet();
}
public BundleSet getBundlesOfVersion(String version) {
return middlewares.get(version);
}
public Set<String> getAdditionalFeatures(String version) {
Map<String, BundleSet> f = features.get(version);
if (f == null)
return new HashSet<String>();
else
return f.keySet();
}
public BundleSet getBundlesOfFeature(String version, String feature) {
Map<String, BundleSet> f = features.get(version);
if (f == null)
return null;
else
return f.get(feature);
}
public boolean isIgnoreArtifactOfVersion(String version, ArtifactURL artifactUrl) {
Set<ArtifactURL> ignore = ignoreSet.get(version);
if (ignore == null)
return false;
for (ArtifactURL i : ignore)
if (artifactUrl.url.startsWith(i.url))
return true;
return false;
}
public float getVersionScore(String version, Collection<ArtifactURL> urls) {
Set<ArtifactURL> vsu = versionSegnificantURLs.get(version);
if (vsu == null)
return 0;
int hits = 0;
for (ArtifactURL url : vsu)
if (urls.contains(url))
hits++;
return (float) hits / vsu.size();
}
private void traverseElements(NodeList nodes, ElementTraverser traverser) {
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
traverser.traverse(e);
}
}
}
private interface ElementTraverser {
void traverse(Element e);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment