Author: pdodds
Date: Wed Sep 13 11:19:22 2006
New Revision: 443058
URL: http://svn.apache.org/viewvc?view=rev&rev=443058
Log:
Implemented new feature that allows you to specify a jbiServicesFile (default
location src/main/resources/jbi-services.xml) that can be used to inject the
services definition into the jbi.xml for a service unit - this can also be used
to override the services generated by a ServiceUnitAnalyzer
Added:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
Modified:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
Modified:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java?view=diff&rev=443058&r1=443057&r2=443058
==============================================================================
---
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
(original)
+++
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
Wed Sep 13 11:19:22 2006
@@ -66,6 +66,14 @@
private Boolean useServiceUnitAnalyzer = Boolean.TRUE;
/**
+ * Single directory for extra files to include in the JBI component.
+ *
+ * @parameter
expression="${basedir}/src/main/resources/jbi-services.xml"
+ * @required
+ */
+ private File jbiServicesFile;
+
+ /**
* The component name.
*
* @parameter expression="${project.artifactId}"
@@ -177,7 +185,7 @@
}
ClassLoader old =
Thread.currentThread().getContextClassLoader();
-
+
try {
URLClassLoader newClassLoader = getClassLoader();
Thread.currentThread().setContextClassLoader(newClassLoader);
@@ -189,28 +197,29 @@
List consumes = new ArrayList();
List provides = new ArrayList();
- if (useServiceUnitAnalyzer.booleanValue()) {
- String serviceUnitAnalyzerClazzName =
getServiceUnitAnalyzer();
-
- // The ServiceUnitAnalyzer should give us the
consumes and
- // provides
- if (serviceUnitAnalyzerClazzName != null) {
- ServiceUnitAnalyzer serviceUnitAnalyzer
= (ServiceUnitAnalyzer) newClassLoader
-
.loadClass(serviceUnitAnalyzerClazzName)
- .newInstance();
- getLog().info(
- "Created Service Unit
Analyzer "
- +
serviceUnitAnalyzer);
-
serviceUnitAnalyzer.init(serviceUnitArtifactsDir);
-
consumes.addAll(serviceUnitAnalyzer.getConsumes());
-
provides.addAll(serviceUnitAnalyzer.getProvides());
+ String serviceUnitAnalyzerClazzName =
getServiceUnitAnalyzer();
+ // The ServiceUnitAnalyzer should give us the consumes
and
+ // provides
+ if (serviceUnitAnalyzerClazzName != null) {
+ ServiceUnitAnalyzer serviceUnitAnalyzer =
(ServiceUnitAnalyzer) newClassLoader
+
.loadClass(serviceUnitAnalyzerClazzName).newInstance();
+ getLog().info(
+ "Created Service Unit Analyzer
" + serviceUnitAnalyzer);
+
serviceUnitAnalyzer.init(serviceUnitArtifactsDir);
+
+ // Need to determine whether we are using the
dummy analyzer
+ // if so we need to give it the services file
+ if (serviceUnitAnalyzer instanceof
JbiServiceFileAnalyzer) {
+
((JbiServiceFileAnalyzer)serviceUnitAnalyzer).setJbiServicesFile(jbiServicesFile);
}
+
consumes.addAll(serviceUnitAnalyzer.getConsumes());
+
provides.addAll(serviceUnitAnalyzer.getProvides());
+ }
- getLog().info(
- "generated : consumes " +
consumes + " provides "
- + provides);
+ getLog().info(
+ "generated : consumes " + consumes + "
provides "
+ + provides);
- }
writer.write(descriptor, name, description, uris,
consumes,
provides);
} catch (Exception e) {
@@ -222,18 +231,29 @@
}
private String getServiceUnitAnalyzer() {
- MavenProject project = getComponentProject();
- if (project != null) {
- List plugins = project.getBuild().getPlugins();
- for (Iterator iterator = plugins.iterator();
iterator.hasNext();) {
- Plugin plugin = (Plugin) iterator.next();
- if
("org.apache.servicemix.tooling".equals(plugin.getGroupId())
- &&
"jbi-maven-plugin".equals(plugin.getArtifactId())) {
- Xpp3Dom o = (Xpp3Dom)
plugin.getConfiguration();
- if (o != null &&
o.getChild("serviceUnitAnalyzer") != null) {
- String clazzName =
o.getChild("serviceUnitAnalyzer")
- .getValue();
- return clazzName;
+ // We need to work out here whether we should use a dummy
service unit
+ // analyzer that will examine a local services file or whether
+ // to look for the service unit analyzer from the component
+ if (jbiServicesFile.exists()) {
+ return JbiServiceFileAnalyzer.class.getCanonicalName();
+ }
+ if (useServiceUnitAnalyzer.booleanValue()) {
+ MavenProject project = getComponentProject();
+ if (project != null) {
+ List plugins = project.getBuild().getPlugins();
+ for (Iterator iterator = plugins.iterator();
iterator.hasNext();) {
+ Plugin plugin = (Plugin)
iterator.next();
+ if
("org.apache.servicemix.tooling".equals(plugin
+ .getGroupId())
+ && "jbi-maven-plugin"
+
.equals(plugin.getArtifactId())) {
+ Xpp3Dom o = (Xpp3Dom)
plugin.getConfiguration();
+ if (o != null
+ &&
o.getChild("serviceUnitAnalyzer") != null) {
+ String clazzName = o
+
.getChild("serviceUnitAnalyzer").getValue();
+ return clazzName;
+ }
}
}
}
@@ -253,8 +273,8 @@
&&
(artifact.getDependencyTrail().size() == 2)) {
MavenProject project = null;
try {
- project =
projectBuilder.buildFromRepository(artifact, remoteRepos,
- localRepo);
+ project =
projectBuilder.buildFromRepository(artifact,
+ remoteRepos, localRepo);
} catch (ProjectBuildingException e) {
getLog().warn(
"Unable to determine
packaging for dependency : "
Added:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java?view=auto&rev=443058
==============================================================================
---
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
(added)
+++
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
Wed Sep 13 11:19:22 2006
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.maven.plugin.jbi;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.common.packaging.Provides;
+import org.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A dummy implementation of the ServiceUnitAnalyzer that allows you to
generate
+ * the consumes and provides from a simple XML file
+ *
+ */
+public class JbiServiceFileAnalyzer implements ServiceUnitAnalyzer {
+
+ List consumes = new ArrayList();
+
+ List provides = new ArrayList();
+
+ public List getConsumes() {
+ return consumes;
+ }
+
+ public List getProvides() {
+ return provides;
+ }
+
+ public void init(File explodedServiceUnitRoot) {
+
+ }
+
+ public void setJbiServicesFile(File jbiServicesFile)
+ throws MojoExecutionException {
+ parseXml(jbiServicesFile);
+ }
+
+ private void parseXml(File jbiServicesFile) throws
MojoExecutionException {
+ try {
+ DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(jbiServicesFile);
+
+ Node servicesNode = doc.getFirstChild();
+ if (servicesNode instanceof Element) {
+ if (((Element)
servicesNode).getNodeName().equals("services")) {
+ // We will process the children
+ Element servicesElement = (Element)
servicesNode;
+ NodeList children =
servicesElement.getChildNodes();
+ for (int i = 0; i <
children.getLength(); i++) {
+ if (children.item(i) instanceof
Element) {
+ Element childElement =
(Element) children.item(i);
+ if
(childElement.getNodeName().equals("consumes")) {
+ Consumes
newConsumes = new Consumes();
+ newConsumes
+
.setEndpointName(getEndpointName(childElement));
+ newConsumes
+
.setInterfaceName(getInterfaceName(childElement));
+ newConsumes
+
.setServiceName(getServiceName(childElement));
+
consumes.add(newConsumes);
+ } else if
(childElement.getNodeName().equals(
+
"provides")) {
+ Provides
newProvides = new Provides();
+ newProvides
+
.setEndpointName(getEndpointName(childElement));
+ newProvides
+
.setInterfaceName(getInterfaceName(childElement));
+ newProvides
+
.setServiceName(getServiceName(childElement));
+
provides.add(newProvides);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new MojoExecutionException("Unable to parse "
+ + jbiServicesFile.getAbsolutePath());
+ }
+
+ }
+
+ private QName getServiceName(Element childElement) {
+ if (childElement.hasAttribute("service-name")) {
+ String prefixAndLocalPart = childElement
+ .getAttribute("service-name");
+ String prefix = prefixAndLocalPart.substring(0,
prefixAndLocalPart
+ .indexOf(':'));
+ String localPart =
prefixAndLocalPart.substring(prefixAndLocalPart
+ .indexOf(':'));
+ return new
QName(childElement.lookupNamespaceURI(prefix), localPart);
+ }
+ return null;
+ }
+
+ private QName getInterfaceName(Element childElement) {
+ if (childElement.hasAttribute("interface-name")) {
+ String prefixAndLocalPart = childElement
+ .getAttribute("interface-name");
+ String prefix = prefixAndLocalPart.substring(0,
prefixAndLocalPart
+ .indexOf(':'));
+ String localPart =
prefixAndLocalPart.substring(prefixAndLocalPart
+ .indexOf(':'));
+ return new
QName(childElement.lookupNamespaceURI(prefix), localPart);
+ }
+ return null;
+ }
+
+ private String getEndpointName(Element childElement) {
+ if (childElement.hasAttribute("endpoint-name")) {
+ return childElement.getAttribute("endpoint-name");
+ }
+ return null;
+ }
+}