diff options
Diffstat (limited to 'sandbox/rfeng/tuscany-provisioning')
2 files changed, 117 insertions, 22 deletions
diff --git a/sandbox/rfeng/tuscany-provisioning/src/main/java/org/apache/tuscany/sca/provision/ExtensionIntrospector.java b/sandbox/rfeng/tuscany-provisioning/src/main/java/org/apache/tuscany/sca/provision/ExtensionIntrospector.java index f3cb381faf..b44c0e3089 100644 --- a/sandbox/rfeng/tuscany-provisioning/src/main/java/org/apache/tuscany/sca/provision/ExtensionIntrospector.java +++ b/sandbox/rfeng/tuscany-provisioning/src/main/java/org/apache/tuscany/sca/provision/ExtensionIntrospector.java @@ -20,13 +20,13 @@ package org.apache.tuscany.sca.provision; import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import javax.xml.namespace.QName; @@ -55,8 +55,22 @@ import org.codehaus.plexus.embed.Embedder; public class ExtensionIntrospector { private ExtensionPointRegistry registry; private boolean loaded; + private boolean offline; private MavenRuntime mavenRuntime = new DefaultMavenRuntime(); + + private MavenEmbedder embedder; + private ArtifactResolver resolver; + private Embedder internalEmbedder; + ArtifactMetadataSource artifactMetadataSource; + private ArtifactRepository remoteRepo; + + // Key: java model type private Map<String, MavenProject> modules = new HashMap<String, MavenProject>(); + + // Key: extension categories + private Map<String, Collection<String>> types = new HashMap<String, Collection<String>>(); + + // Key: java model type private Map<String, QName> qnames = new HashMap<String, QName>(); /** @@ -90,14 +104,18 @@ public class ExtensionIntrospector { this.qnames.putAll(mapJavaTypeToQName()); - List<ServiceDeclaration> factories = new ArrayList<ServiceDeclaration>(); - factories.addAll(discover("org.apache.tuscany.sca.provider.BindingProviderFactory")); - factories.addAll(discover("org.apache.tuscany.sca.provider.ImplementationProviderFactory")); - factories.addAll(discover("org.apache.tuscany.sca.provider.PolicyProviderFactory")); - factories.addAll(discover("org.apache.tuscany.sca.provider.WireFormatProviderFactory")); - factories.addAll(discover("org.apache.tuscany.sca.provider.OperationSelectorProviderFactory")); + addExtensions("Bindings", "org.apache.tuscany.sca.provider.BindingProviderFactory"); + addExtensions("Implementations", "org.apache.tuscany.sca.provider.ImplementationProviderFactory"); + addExtensions("Policies", "org.apache.tuscany.sca.provider.PolicyProviderFactory"); + addExtensions("Wire Formats", "org.apache.tuscany.sca.provider.WireFormatProviderFactory"); + addExtensions("Operation Selectors", "org.apache.tuscany.sca.provider.OperationSelectorProviderFactory"); + + loaded = true; + } - for (ServiceDeclaration sd : factories) { + private void addExtensions(String label, String name) { + Set<String> models = new HashSet<String>(); + for (ServiceDeclaration sd : discover(name)) { MavenProject project = null; try { project = mavenRuntime.getProject(sd.getLocation()); @@ -106,11 +124,11 @@ public class ExtensionIntrospector { } if (project != null) { String model = sd.getAttributes().get("model"); + models.add(model); modules.put(model, project); } } - - loaded = true; + types.put(label, models); } public Map<String, QName> mapJavaTypeToQName() { @@ -145,15 +163,10 @@ public class ExtensionIntrospector { return factoryDeclarations; } - private MavenEmbedder embedder; - private ArtifactResolver resolver; - private Embedder internalEmbedder; - ArtifactMetadataSource artifactMetadataSource; - private ArtifactRepository remoteRepo; - public void start() { try { embedder = new MavenEmbedder(); + embedder.setOffline(offline); embedder.setClassLoader(Thread.currentThread().getContextClassLoader()); embedder.start(); @@ -192,10 +205,7 @@ public class ExtensionIntrospector { for (Map.Entry<String, MavenProject> e : getModules().entrySet()) { String type = e.getKey(); - QName qname = qnames.get(e.getKey()); - if (qname != null) { - type = qname.toString(); - } + type = getType(type); boolean matched = (args.length == 0); for (String arg : args) { if (type.contains(arg)) { @@ -226,16 +236,94 @@ public class ExtensionIntrospector { return artifacts; } + private String getType(String type) { + QName qname = qnames.get(type); + if (qname != null) { + type = qname.toString(); + } + return type; + } + private static <T> T getField(Object object, String name) throws Exception { Field field = object.getClass().getDeclaredField(name); field.setAccessible(true); return (T)field.get(object); } + public String toJSON(Map<String, Collection<Artifact>> map) { + StringBuffer json = new StringBuffer("{\n"); + json.append(" label: \"name\",\n"); + json.append(" items: [\n"); + int i = 0; + for (Map.Entry<String, Collection<String>> category : types.entrySet()) { + json.append("{"); // { + json.append("name: ").append("\"").append(category.getKey()).append("\", \n"); // name: "category", + + json.append(" types: [\n"); + int j = 0; + for (String model : category.getValue()) { + String key = getType(model); + Collection<Artifact> artifacts = map.get(key); + json.append(" {"); // { + json.append("name: ").append("\"").append(key).append("\", \n"); // type: "type", + json.append(" artifacts: [\n"); + int k = 0; + for (Artifact a : artifacts) { + json.append(" {"); + json.append("name: \"").append(a.toString()).append("\", "); + json.append("groupId: \"").append(a.getGroupId()).append("\", "); + json.append("artifactId: \"").append(a.getArtifactId()).append("\", "); + json.append("version: \"").append(a.getVersion()).append("\", "); + json.append("scope: \"").append(a.getScope()).append("\""); + if (k == artifacts.size() - 1) { + json.append("}\n"); + } else { + json.append("}, \n"); + } + k++; + } + json.append(" ]\n"); // ] + + if (j == map.size() - 1) { + json.append(" }\n"); + } else { + json.append(" }, \n"); // }, + } + j++; + } + json.append("]\n"); + if (i == types.size() - 1) { + json.append("}"); + } else { + json.append("},"); + } + i++; + } + json.append("]\n"); + json.append("}\n"); + return json.toString(); + } + + public boolean isOffline() { + return offline; + } + + public void setOffline(boolean offline) { + this.offline = offline; + } + public static void main(String args[]) throws Exception { + String json = generateDojoData(args); + System.out.println(json); + } + + public static String generateDojoData(String[] args) throws Exception { ExtensionIntrospector introspector = new ExtensionIntrospector(null); + introspector.setOffline("true".equalsIgnoreCase(System.getProperty("offline"))); introspector.start(); - for (Map.Entry<String, Collection<Artifact>> entry : introspector.getDependencies(args).entrySet()) { + Map<String, Collection<Artifact>> map = introspector.getDependencies(args); + /* + for (Map.Entry<String, Collection<Artifact>> entry : map.entrySet()) { System.out.println("\n------------------------------------------------------------------------"); System.out.println(entry.getKey()); System.out.println("------------------------------------------------------------------------"); @@ -244,6 +332,10 @@ public class ExtensionIntrospector { } System.out.println("------------------------------------------------------------------------"); } + */ + String json = introspector.toJSON(map); introspector.stop(); + return json; } + } diff --git a/sandbox/rfeng/tuscany-provisioning/src/test/java/META-INF/MANIFEST.MF b/sandbox/rfeng/tuscany-provisioning/src/test/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5e9495128c --- /dev/null +++ b/sandbox/rfeng/tuscany-provisioning/src/test/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0
+Class-Path:
+
|