You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/06/22 13:34:32 UTC
svn commit: r416334 [2/2] - in /incubator/servicemix/trunk:
apache-servicemix/ apache-servicemix/src/main/assembly/
samples/wsdl-first/sa/
servicemix-bpe/src/main/java/org/apache/servicemix/bpe/ servicemix-common/
servicemix-core/ servicemix-core/src/m...
Added: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java?rev=416334&view=auto
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java (added)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java Thu Jun 22 04:34:29 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * A Mojo used to build the jbi component installer file.
+ *
+ * @author <a href="gnodet@apache.org">Guillaume Nodet</a>
+ * @version $Id: GenerateApplicationXmlMojo.java 314956 2005-10-12 16:27:15Z brett $
+ * @goal jbi-component
+ * @phase package
+ * @requiresDependencyResolution runtime
+ * @description generates the component installer
+ */
+public class GenerateComponentMojo extends AbstractJbiMojo {
+
+ /**
+ * The directory for the generated JBI component.
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ private File outputDirectory;
+
+ /**
+ * The name of the generated war.
+ *
+ * @parameter expression="${project.artifactId}-${project.version}-installer.zip"
+ * @required
+ */
+ private String installerName;
+
+ /**
+ * The Zip archiver.
+ *
+ * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
+ * @required
+ */
+ private JarArchiver jarArchiver;
+
+ /**
+ * Single directory for extra files to include in the JBI component.
+ *
+ * @parameter expression="${basedir}/src/main/jbi"
+ * @required
+ */
+ private File jbiSourceDirectory;
+
+ /**
+ * The maven archive configuration to use.
+ *
+ * @parameter
+ */
+ private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ getLog().debug(" ======= GenerateInstallerMojo settings =======");
+ getLog().debug("workDirectory[" + workDirectory + "]");
+ getLog().debug("installerName[" + installerName + "]");
+ getLog().debug("jbiSourceDirectory[" + jbiSourceDirectory + "]");
+
+ try {
+
+ createUnpackedInstaller();
+
+ File installerFile = new File(outputDirectory, installerName);
+ createArchive(installerFile);
+
+ projectHelper.attachArtifact(project, "zip", "installer", new File(outputDirectory, installerName));
+
+ } catch (JbiPluginException e) {
+ throw new MojoExecutionException("Failed to create installer", e);
+ }
+ }
+
+ private void createArchive(File installerFile) throws JbiPluginException {
+ try {
+
+ // generate war file
+ getLog().info("Generating installer " + installerFile.getAbsolutePath());
+ MavenArchiver archiver = new MavenArchiver();
+ archiver.setArchiver(jarArchiver);
+ archiver.setOutputFile(installerFile);
+ jarArchiver.addDirectory(workDirectory);
+ if (jbiSourceDirectory.isDirectory()) {
+ jarArchiver.addDirectory(jbiSourceDirectory, null, DirectoryScanner.DEFAULTEXCLUDES);
+ }
+ // create archive
+ archiver.createArchive(getProject(), archive);
+
+ } catch (ArchiverException e) {
+ throw new JbiPluginException("Error creating assembly: " + e.getMessage(), e);
+ } catch (ManifestException e) {
+ throw new JbiPluginException("Error creating assembly: " + e.getMessage(), e);
+ } catch (IOException e) {
+ throw new JbiPluginException("Error creating assembly: " + e.getMessage(), e);
+ } catch (DependencyResolutionRequiredException e) {
+ throw new JbiPluginException("Error creating assembly: " + e.getMessage(), e);
+ }
+
+ }
+
+ private void createUnpackedInstaller() throws JbiPluginException {
+
+ if (!workDirectory.isDirectory()) {
+ if (!workDirectory.mkdirs()) {
+ throw new JbiPluginException("Unable to create work directory: " + workDirectory);
+ }
+ }
+
+ File projectArtifact = new File(outputDirectory, project.getArtifactId() + "-" + project.getVersion() + ".jar");
+ try {
+ FileUtils.copyFileToDirectory(projectArtifact, new File(workDirectory, LIB_DIRECTORY));
+ } catch (IOException e) {
+ throw new JbiPluginException("Unable to copy file " + projectArtifact, e);
+ }
+
+ ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+
+ JbiResolutionListener listener = resolveProject();
+ //print(listener.getRootNode(), "");
+
+ Set sharedLibraries = new HashSet();
+ Set includes = new HashSet();
+ for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
+ Artifact artifact = (Artifact) iter.next();
+ if (!artifact.isOptional() && filter.include(artifact)) {
+ MavenProject project = null;
+ try {
+ project = projectBuilder.buildFromRepository(artifact, remoteRepos, localRepo);
+ } catch (ProjectBuildingException e) {
+ getLog().warn(
+ "Unable to determine packaging for dependency : "
+ + artifact.getArtifactId()
+ + " assuming jar");
+ }
+ String type = project != null ? project.getPackaging() : artifact.getType();
+ if ("jbi-shared-library".equals(type)) {
+ removeBranch(listener, artifact);
+ } else if ("jar".equals(type)) {
+ includes.add(artifact);
+ }
+ }
+ }
+ //print(listener.getRootNode(), "");
+ includes.retainAll(getArtifacts(listener.getRootNode(), new HashSet()));
+
+ for (Iterator iter = includes.iterator(); iter.hasNext();) {
+ Artifact artifact = (Artifact) iter.next();
+ try {
+ getLog().info("Including: " + artifact);
+ FileUtils.copyFileToDirectory(artifact.getFile(), new File(workDirectory, LIB_DIRECTORY));
+ } catch (IOException e) {
+ throw new JbiPluginException("Unable to copy file " + artifact.getFile(), e);
+ }
+ }
+ }
+
+}
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java?rev=416334&r1=416333&r2=416334&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java Thu Jun 22 04:34:29 2006
@@ -119,9 +119,8 @@
getLog().debug("name[" + name + "]");
getLog().debug("description[" + description + "]");
getLog().debug("encoding[" + encoding + "]");
- getLog().debug(
- "generatedDescriptorLocation[" + generatedDescriptorLocation
- + "]");
+ getLog().debug("generatedDescriptorLocation[" + generatedDescriptorLocation + "]");
+ getLog().debug("version[" + version + "]");
if (!generateJbiDescriptor.booleanValue()) {
getLog().debug("Generation of jbi.xml is disabled");
@@ -188,4 +187,4 @@
writer.write(descriptor, name, description, version,
classLoaderDelegate, embeddedLibraries);
}
-}
\ No newline at end of file
+}
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java?rev=416334&r1=416333&r2=416334&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiComponentDescriptorWriter.java Thu Jun 22 04:34:29 2006
@@ -89,7 +89,6 @@
}
writer.endElement();
- writer.startElement("shared-library-list");
for (Iterator it = uris.iterator(); it.hasNext();) {
DependencyInformation info = (DependencyInformation) it.next();
if ("jbi-shared-library".equals(info.getType())) {
@@ -99,7 +98,6 @@
writer.endElement();
}
}
- writer.endElement();
writer.endElement();
Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=416334&r1=416333&r2=416334&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml Thu Jun 22 04:34:29 2006
@@ -43,7 +43,7 @@
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jbi-service-unit</type>
- <extension>zip</extension>
+ <extension>jar</extension>
<language>java</language>
</configuration>
</component>
@@ -72,7 +72,7 @@
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jbi-service-assembly</type>
- <extension>zip</extension>
+ <extension>jar</extension>
<language>java</language>
</configuration>
</component>
@@ -97,7 +97,7 @@
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
- <role-hint>jbi-service-assembly</role-hint>
+ <role-hint>jbi-shared-library</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jbi-shared-library</type>
Modified: incubator/servicemix/trunk/tooling/servicemix-service-engine/src/main/resources/archetype-resources/src/main/java/MyBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/servicemix-service-engine/src/main/resources/archetype-resources/src/main/java/MyBootstrap.java?rev=416334&r1=416333&r2=416334&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/servicemix-service-engine/src/main/resources/archetype-resources/src/main/java/MyBootstrap.java (original)
+++ incubator/servicemix/trunk/tooling/servicemix-service-engine/src/main/resources/archetype-resources/src/main/java/MyBootstrap.java Thu Jun 22 04:34:29 2006
@@ -1,32 +1,149 @@
package ${packageName};
-import org.apache.servicemix.common.BaseBootstrap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.Bootstrap;
+import javax.jbi.component.InstallationContext;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
/**
* Bootstrap class.
* This class is usefull to perform tasks at installation / uninstallation time
*/
-public class MyBootstrap extends BaseBootstrap
+public class MyBootstrap implements Bootstrap
{
+ protected final transient Log logger = LogFactory.getLog(getClass());
+
+ protected InstallationContext context;
+ protected ObjectName mbeanName;
+
+ public MyBootstrap() {
+ }
+
+ public ObjectName getExtensionMBeanName() {
+ return mbeanName;
+ }
+
+ protected Object getExtensionMBean() throws Exception {
+ return null;
+ }
+
+ protected ObjectName createExtensionMBeanName() throws Exception {
+ return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
+ */
+ public void init(InstallationContext installContext) throws JBIException {
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Initializing bootstrap");
+ }
+ this.context = installContext;
+ doInit();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Bootstrap initialized");
+ }
+ } catch (JBIException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JBIException("Error calling init", e);
+ }
+ }
+
protected void doInit() throws Exception {
- super.doInit();
+ Object mbean = getExtensionMBean();
+ if (mbean != null) {
+ this.mbeanName = createExtensionMBeanName();
+ MBeanServer server = this.context.getContext().getMBeanServer();
+ if (server == null) {
+ throw new JBIException("null mBeanServer");
+ }
+ if (server.isRegistered(this.mbeanName)) {
+ server.unregisterMBean(this.mbeanName);
+ }
+ server.registerMBean(mbean, this.mbeanName);
+ }
}
+ /* (non-Javadoc)
+ * @see javax.jbi.component.Bootstrap#cleanUp()
+ */
+ public void cleanUp() throws JBIException {
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Cleaning up bootstrap");
+ }
+ doCleanUp();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Bootstrap cleaned up");
+ }
+ } catch (JBIException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JBIException("Error calling cleanUp", e);
+ }
+ }
+
protected void doCleanUp() throws Exception {
- super.doCleanUp();
+ if (this.mbeanName != null) {
+ MBeanServer server = this.context.getContext().getMBeanServer();
+ if (server == null) {
+ throw new JBIException("null mBeanServer");
+ }
+ if (server.isRegistered(this.mbeanName)) {
+ server.unregisterMBean(this.mbeanName);
+ }
+ }
}
-
+
+ /* (non-Javadoc)
+ * @see javax.jbi.component.Bootstrap#onInstall()
+ */
+ public void onInstall() throws JBIException {
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Bootstrap onInstall");
+ }
+ doOnInstall();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Bootstrap onInstall done");
+ }
+ } catch (JBIException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JBIException("Error calling onInstall", e);
+ }
+ }
+
protected void doOnInstall() throws Exception {
- super.doOnInstall();
}
-
- protected void doOnUninstall() throws Exception {
- super.doOnUninstall();
+
+ /* (non-Javadoc)
+ * @see javax.jbi.component.Bootstrap#onUninstall()
+ */
+ public void onUninstall() throws JBIException {
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Bootstrap onUninstall");
+ }
+ doOnUninstall();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Bootstrap onUninstall done");
+ }
+ } catch (JBIException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JBIException("Error calling onUninstall", e);
+ }
}
-
- protected Object getExtensionMBean() throws Exception {
- return null;
+
+ protected void doOnUninstall() throws Exception {
}
}