You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ks...@apache.org on 2015/10/29 21:35:14 UTC
[09/13] servicemix-maven-plugins git commit: Deprecated plugins
removed
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
deleted file mode 100644
index 2b5b022..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentDescriptorMojo.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * 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.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-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.util.FileUtils;
-
-import static org.apache.servicemix.maven.plugin.jbi.DependencyInformation.*;
-
-/**
- * A Mojo used to build the jbi.xml file.
- *
- * @author <a href="gnodet@apache.org">Guillaume Nodet</a>
- * @version $Id: GenerateComponentDescriptorMojo 314956 2005-10-12 16:27:15Z
- * brett $
- * @goal generate-jbi-component-descriptor
- * @phase generate-resources
- * @requiresDependencyResolution runtime
- * @description generates the jbi.xml deployment descriptor
- */
-public class GenerateComponentDescriptorMojo extends AbstractJbiMojo {
-
- public static final String UTF_8 = "UTF-8";
-
- /**
- * Whether the application.xml should be generated or not.
- *
- * @parameter
- */
- private Boolean generateJbiDescriptor = Boolean.TRUE;
-
- /**
- * The component class name.
- *
- * @parameter
- * @required
- */
- private String component;
-
- /**
- * The bootstrap class name.
- *
- * @parameter
- */
- private String bootstrap;
-
- /**
- * The component type.
- *
- * @parameter
- * @required
- */
- private String type;
-
- /**
- * The component name.
- *
- * @parameter expression="${project.artifactId}"
- */
- private String name;
-
- /**
- * The destination of the default bootstrap.
- *
- * @parameter expression="${project.build.directory}/classes/org/apache/servicemix/common/DefaultBootstrap.class"
- */
- private File defaultBootstrapFile;
-
- /**
- * The component description.
- *
- * @parameter expression="${project.name}"
- */
- private String description;
-
- /**
- * Character encoding for the auto-generated application.xml file.
- *
- * @parameter
- */
- private String encoding = UTF_8;
-
- /**
- * Directory where the application.xml file will be auto-generated.
- *
- * @parameter expression="${project.build.directory}"
- */
- private String generatedDescriptorLocation;
-
- /**
- * The component class loader delegation
- *
- * @parameter expression="parent-first"
- */
- private String componentClassLoaderDelegation;
-
- /**
- * The bootstrap class loader delegation
- *
- * @parameter expression="parent-first"
- */
- private String bootstrapClassLoaderDelegation;
-
- /**
- * A list of dependency types to include in component classpath.
- * Default: jar, bundle, jbi-component
- *
- * @parameter
- */
- private List componentTypes = new ArrayList(Arrays.asList(new Object[]{"jar", "bundle", "jbi-component"}));
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- getLog().debug(
- " ======= GenerateComponentDescriptorMojo settings =======");
- getLog().debug("workDirectory[" + workDirectory + "]");
- getLog().debug("generateJbiDescriptor[" + generateJbiDescriptor + "]");
- getLog().debug("type[" + type + "]");
- getLog().debug("component[" + component + "]");
- getLog().debug("bootstrap[" + bootstrap + "]");
- getLog().debug("name[" + name + "]");
- getLog().debug("description[" + description + "]");
- getLog().debug("encoding[" + encoding + "]");
- getLog().debug(
- "generatedDescriptorLocation[" + generatedDescriptorLocation
- + "]");
-
- if (!generateJbiDescriptor.booleanValue()) {
- getLog().debug("Generation of jbi.xml is disabled");
- return;
- }
-
- if (bootstrap == null) {
- injectBootStrap();
- }
-
- // Generate jbi descriptor and copy it to the build directory
- getLog().info("Generating jbi.xml");
- try {
- generateJbiDescriptor();
- } catch (JbiPluginException e) {
- throw new MojoExecutionException("Failed to generate jbi.xml", e);
- }
-
- try {
- FileUtils.copyFileToDirectory(new File(generatedDescriptorLocation,
- JBI_DESCRIPTOR), new File(getWorkDirectory(), META_INF));
- } catch (IOException e) {
- throw new MojoExecutionException(
- "Unable to copy jbi.xml to final destination", e);
- }
- }
-
- /**
- * Helper method used to inject the BaseBootstrap from servicemix-commons
- * into the component this allows to you bypass actually having to create a
- * bootstrap
- *
- * @throws MojoExecutionException
- *
- */
- private void injectBootStrap() throws MojoExecutionException {
-
- try {
- URL defaultBootStrap = getClassLoader().getResource(
- "org/apache/servicemix/common/DefaultBootstrap.class");
- FileUtils.copyURLToFile(defaultBootStrap, defaultBootstrapFile);
- bootstrap = "org.apache.servicemix.common.DefaultBootstrap";
- } catch (IOException e) {
- throw new MojoExecutionException(
- "Unable to copy DefaultBootstrap.class to "
- + defaultBootstrapFile.getAbsolutePath(), e);
- }
- }
-
- /**
- * Generates the deployment descriptor if necessary.
- */
- protected void generateJbiDescriptor() throws JbiPluginException {
- File outputDir = new File(generatedDescriptorLocation);
- if (!outputDir.exists()) {
- outputDir.mkdirs();
- }
-
- File descriptor = new File(outputDir, JBI_DESCRIPTOR);
-
- List uris = new ArrayList();
- DependencyInformation info = new DependencyInformation();
- info.setFilename(LIB_DIRECTORY + "/" + project.getBuild().getFinalName() + ".jar");
- info.setVersion(project.getVersion());
- info.setName(project.getArtifactId());
- info.setType("jar");
- uris.add(info);
-
- ArtifactFilter filter = new ArtifactFilter() {
- public boolean include(Artifact artifact) {
- return !artifact.isOptional() &&
- (artifact.getScope() == Artifact.SCOPE_RUNTIME || artifact.getScope() == Artifact.SCOPE_COMPILE);
- }
- };
-
-
- JbiResolutionListener listener = resolveProject();
- Set<Artifact> includes = new HashSet<Artifact>();
- Set<Artifact> excludes = new HashSet<Artifact>();
- for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
- if (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 (SHARED_LIBRARY_TYPE.equals(type)) {
- // exclude children, but not the shared library itself
- excludeBranch(listener.getNode(artifact), excludes);
- excludes.remove(artifact);
- includes.add(artifact);
- } else if (componentTypes.contains(type)) {
- includes.add(artifact);
- }
- }
- }
- pruneTree(listener.getRootNode(), excludes);
- // print(listener.getRootNode(), "");
- for (Artifact artifact : retainArtifacts(includes, listener)) {
- 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();
- info = new DependencyInformation();
- info.setFilename(LIB_DIRECTORY + "/" + artifact.getFile().getName());
- info.setVersion(artifact.getVersion());
- info.setName(artifact.getArtifactId());
- info.setType(type);
- uris.add(info);
- }
-
- JbiComponentDescriptorWriter writer = new JbiComponentDescriptorWriter(encoding);
- writer.write(descriptor, component, bootstrap, type, name, description,
- componentClassLoaderDelegation, bootstrapClassLoaderDelegation,
- uris);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
deleted file mode 100644
index 2364ba2..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateComponentMojo.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-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.artifact.resolver.filter.ArtifactFilter;
-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.Manifest;
-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.build.finalName}"
- * @required
- */
- private String finalName;
-
- /**
- * The name of the generated war.
- *
- * @parameter expression="${project.build.finalName}-installer.zip"
- * @required
- */
- private String installerName;
-
- /**
- * The Zip archiver.
- *
- * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="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();
-
- /**
- * A list of dependency types to include in component classpath.
- * Default: jar, bundle, jbi-component
- *
- * @parameter
- */
- private List componentTypes = new ArrayList(Arrays.asList(new Object[]{"jar", "bundle", "jbi-component"}));
-
- 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);
- Manifest manifest = createManifest();
- jarArchiver.addConfiguredManifest(manifest);
- 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() && !workDirectory.mkdirs()) {
- throw new JbiPluginException("Unable to create work directory: " + workDirectory);
- }
-
- File projectArtifact = new File(outputDirectory, finalName + ".jar");
- try {
- FileUtils.copyFileToDirectory(projectArtifact, new File(workDirectory, LIB_DIRECTORY));
- } catch (IOException e) {
- throw new JbiPluginException("Unable to copy file "
- + projectArtifact, e);
- }
-
- ArtifactFilter filter = new ArtifactFilter() {
- public boolean include(Artifact artifact) {
- return !artifact.isOptional() &&
- (artifact.getScope() == Artifact.SCOPE_RUNTIME || artifact.getScope() == Artifact.SCOPE_COMPILE);
- }
- };
-
- JbiResolutionListener listener = resolveProject();
- if (getLog().isDebugEnabled()) {
- print(listener.getRootNode(), " ");
- }
-
- Set<Artifact> includes = new HashSet<Artifact>();
- Set<Artifact> excludes = new HashSet<Artifact>();
- for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
- if (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)) {
- excludeBranch(listener.getNode(artifact), excludes);
- } else if (componentTypes.contains(type)) {
- includes.add(artifact);
- }
- }
- }
- pruneTree(listener.getRootNode(), excludes);
- if (getLog().isDebugEnabled()) {
- getLog().info("Excludes: " + excludes);
- print(listener.getRootNode(), " ");
- }
-
- for (Artifact artifact : retainArtifacts(includes, listener)) {
- 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);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
deleted file mode 100644
index ac0fc44..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.Date;
-import java.util.Iterator;
-
-import org.apache.maven.model.Dependency;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-
-/**
- * Generates the dependencies properties file
- *
- * @version $Id: $
- * @goal generate-depends-file
- * @phase generate-resources
- * @requiresDependencyResolution runtime
- * @description Generates the dependencies properties file
- */
-public class GenerateDependsFileMojo extends AbstractJbiMojo {
-
- protected static final String SEPARATOR = "/";
-
- /**
- * The file to generate
- *
- * @parameter default-value="${project.build.directory}/classes/META-INF/maven/dependencies.properties"
- */
-
- private File outputFile;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
- OutputStream out = null;
- try {
- outputFile.getParentFile().mkdirs();
- out = new FileOutputStream(outputFile);
- PrintStream printer = new PrintStream(out);
- populateProperties(printer);
- getLog().info("Created: " + outputFile);
-
- } catch (Exception e) {
- throw new MojoExecutionException(
- "Unable to create dependencies file: " + e, e);
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- getLog().info("Failed to close: " + outputFile + ". Reason: " + e, e);
- }
- }
- }
- }
-
- protected void populateProperties(PrintStream out) {
- out.println("# Project dependencies generated by the Apache ServiceMix Maven Plugin");
- out.println("# Generated at: " + new Date());
- out.println();
-
- out.println("groupId = " + project.getGroupId());
- out.println("artifactId = " + project.getArtifactId());
- out.println("version = " + project.getVersion());
- out.println(project.getGroupId() + SEPARATOR + project.getArtifactId() + SEPARATOR + "version = " + project.getVersion());
- out.println();
- out.println("# dependencies");
- out.println();
-
- Iterator iterator = project.getDependencies().iterator();
- while (iterator.hasNext()) {
- Dependency dependency = (Dependency) iterator.next();
- String prefix = dependency.getGroupId() + SEPARATOR + dependency.getArtifactId() + SEPARATOR;
- out.println(prefix + "version = " + dependency.getVersion());
- String classifier = dependency.getClassifier();
- if (classifier != null) {
- out.println(prefix + "classifier = " + classifier);
- }
- out.println(prefix + "type = " + dependency.getType());
- out.println(prefix + "scope = " + dependency.getScope());
- out.println();
-
- getLog().debug("Dependency: " + dependency + " classifier: " + classifier + " type: " + dependency.getType());
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
deleted file mode 100644
index ef07ba9..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * 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.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Profile;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-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.apache.servicemix.common.packaging.Consumes;
-import org.apache.servicemix.common.packaging.Provides;
-import org.codehaus.plexus.util.FileUtils;
-
-/**
- * A Mojo used to build the jbi.xml file for a service unit.
- *
- * @author <a href="pdodds@apache.org">Philip Dodds</a>
- * @version $Id: GenerateComponentDescriptorMojo 314956 2005-10-12 16:27:15Z
- * brett $
- * @goal generate-jbi-service-assembly-descriptor
- * @phase generate-resources
- * @requiresDependencyResolution runtime
- * @description generates the jbi.xml deployment descriptor for a service unit
- */
-public class GenerateServiceAssemblyDescriptorMojo extends AbstractJbiMojo {
-
- public static final String JBI_NAMESPACE = "http://java.sun.com/xml/ns/jbi";
-
- public static final String UTF_8 = "UTF-8";
-
- public class Connection {
- private Consumes consumes;
-
- private Provides provides;
-
- public Consumes getConsumes() {
- return consumes;
- }
-
- public void setConsumes(Consumes consumes) {
- this.consumes = consumes;
- }
-
- public Provides getProvides() {
- return provides;
- }
-
- public void setProvides(Provides provides) {
- this.provides = provides;
- }
- }
-
- /**
- * Whether the jbi.xml should be generated or not.
- *
- * @parameter
- */
- private Boolean generateJbiDescriptor = Boolean.TRUE;
-
- /**
- * The component name.
- *
- * @parameter expression="${project.artifactId}"
- */
- private String name;
-
- /**
- * The component description.
- *
- * @parameter expression="${project.name}"
- */
- private String description;
-
- /**
- * Character encoding for the auto-generated application.xml file.
- *
- * @parameter
- */
- private String encoding = UTF_8;
-
- /**
- * Directory where the application.xml file will be auto-generated.
- *
- * @parameter expression="${project.build.directory}/classes/META-INF"
- */
- private String generatedDescriptorLocation;
-
- /**
- * The location of a file containing the connections elements that can be
- * merged into the jbi.xml
- *
- * @parameter expression="${basedir}/src/main/resources/jbi-connections.xml"
- */
- private File jbiConnectionsFile;
-
- /**
- * Dependency graph
- */
- private JbiResolutionListener listener;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- getLog()
- .debug(
- " ======= GenerateServiceAssemlbyDescriptorMojo settings =======");
- getLog().debug("workDirectory[" + workDirectory + "]");
- getLog().debug("generateJbiDescriptor[" + generateJbiDescriptor + "]");
- getLog().debug("name[" + name + "]");
- getLog().debug("description[" + description + "]");
- getLog().debug("encoding[" + encoding + "]");
- getLog().debug(
- "generatedDescriptorLocation[" + generatedDescriptorLocation
- + "]");
-
- if (!generateJbiDescriptor.booleanValue()) {
- getLog().debug("Generation of jbi.xml is disabled");
- return;
- }
-
- // Generate jbi descriptor and copy it to the build directory
- getLog().info("Generating jbi.xml");
- try {
- listener = resolveProject();
- generateJbiDescriptor();
- } catch (JbiPluginException e) {
- throw new MojoExecutionException("Failed to generate jbi.xml", e);
- }
-
- try {
- FileUtils.copyFileToDirectory(new File(generatedDescriptorLocation,
- JBI_DESCRIPTOR), new File(getWorkDirectory(), META_INF));
- } catch (IOException e) {
- throw new MojoExecutionException(
- "Unable to copy jbi.xml to final destination", e);
- }
- }
-
- /**
- * Generates the deployment descriptor if necessary.
- *
- * @throws MojoExecutionException
- */
- protected void generateJbiDescriptor() throws JbiPluginException,
- MojoExecutionException {
- File outputDir = new File(generatedDescriptorLocation);
- if (!outputDir.exists()) {
- outputDir.mkdirs();
- }
-
- File descriptor = new File(outputDir, JBI_DESCRIPTOR);
-
- List serviceUnits = new ArrayList();
-
- Set artifacts = project.getArtifacts();
- for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
-
- Artifact artifact = (Artifact) iter.next();
- // TODO: utilise appropriate methods from project builder
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
- if (!artifact.isOptional() && filter.include(artifact)
- && (artifact.getDependencyTrail().size() == 2)) {
- 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");
- }
- if ((project != null)
- && (project.getPackaging().equals("jbi-service-unit"))) {
- DependencyInformation info = new DependencyInformation();
- info.setName(artifact.getArtifactId());
- String fileName = artifact.getFile().getName();
- if (fileName == null) {
- // the name is not defined in the POM
- // try to use the artifactId
- // as the artifactId is mandatory by maven, we don't
- // need any additional test
- fileName = artifact.getArtifactId();
- }
- if (fileName.equals("classes")) {
- fileName = artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar";
- }
- String suName = getServiceUnitName(project);
- if (suName != null && suName.length() > 0) {
- fileName = suName;
- } else {
- fileName = fileName.substring(0, fileName.lastIndexOf('.')) + ".zip";
- }
- info.setFilename(fileName);
- info.setComponent(getComponentName(project, artifacts, artifact));
- info.setDescription(project.getDescription());
- serviceUnits.add(info);
- }
-
- }
- }
-
- List orderedServiceUnits = reorderServiceUnits(serviceUnits);
-
- List connections = getConnections();
-
- JbiServiceAssemblyDescriptorWriter writer = new JbiServiceAssemblyDescriptorWriter(
- encoding);
- writer.write(descriptor, name, description, orderedServiceUnits,
- connections);
- }
-
- /**
- * Used to return a list of connections if they have been found in the
- * jbiConnectionsFile
- *
- * @return A list of connections
- * @throws MojoExecutionException
- */
- private List getConnections() throws MojoExecutionException {
-
- if (jbiConnectionsFile.exists()) {
- return parseConnectionsXml();
- } else {
- return new ArrayList();
- }
- }
-
- /**
- * Parse the jbiConnectionsFile
- *
- * @return
- * @throws MojoExecutionException
- */
- private List parseConnectionsXml() throws MojoExecutionException {
- getLog().info(
- "Picking up connections from "
- + jbiConnectionsFile.getAbsolutePath());
- List connections = new ArrayList();
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(jbiConnectionsFile);
-
- Node servicesNode = doc.getFirstChild();
- if (servicesNode instanceof Element
- && XmlDescriptorHelper.isElement(servicesNode, JBI_NAMESPACE, "connections")) {
- // We will process the children
- Element servicesElement = (Element) servicesNode;
- NodeList children = servicesElement.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- if (XmlDescriptorHelper.isElement(children.item(i), JBI_NAMESPACE, "connection")) {
- Connection connection = new Connection();
- NodeList connectionChildren = children.item(i).getChildNodes();
- for (int x = 0; x < connectionChildren.getLength(); x++) {
- if (connectionChildren.item(x) instanceof Element) {
- Element childElement = (Element) connectionChildren.item(x);
- if (XmlDescriptorHelper.isElement(
- childElement, JBI_NAMESPACE, "consumer")) {
- Consumes newConsumes = new Consumes();
- newConsumes.setEndpointName(XmlDescriptorHelper
- .getEndpointName(childElement));
- newConsumes.setInterfaceName(XmlDescriptorHelper
- .getInterfaceName(childElement));
- newConsumes.setServiceName(XmlDescriptorHelper
- .getServiceName(childElement));
- connection.setConsumes(newConsumes);
- } else if (XmlDescriptorHelper.isElement(
- childElement, JBI_NAMESPACE, "provider")) {
- Provides newProvides = new Provides();
- newProvides.setEndpointName(XmlDescriptorHelper
- .getEndpointName(childElement));
- newProvides.setInterfaceName(XmlDescriptorHelper
- .getInterfaceName(childElement));
- newProvides.setServiceName(XmlDescriptorHelper
- .getServiceName(childElement));
- connection.setProvides(newProvides);
- }
- }
- }
- connections.add(connection);
- }
- }
- }
- getLog().info("Found " + connections.size() + " connections");
- return connections;
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to parse "
- + jbiConnectionsFile.getAbsolutePath());
- }
- }
-
- /**
- * Re-orders the service units to match order in the dependencies section of
- * the pom
- *
- * @param serviceUnits
- * @throws MojoExecutionException
- */
- private List reorderServiceUnits(List serviceUnits) throws MojoExecutionException {
-
- // TODO Currently we get the model back by re-parsing it however in the
- // future we should be able to use the getModel() - there should be a
- // fix post 2.0.4
-
- // Iterator dependencies =
- // project.getModel().getDependencies().iterator();
-
- // For now we will need to reparse the pom without processing
- Iterator dependencies = getReparsedDependencies();
-
- List orderedServiceUnits = new ArrayList();
- parseDependencies(serviceUnits, dependencies, orderedServiceUnits);
-
- //get chance the go through the active profile dependencies so that the SU dependency
- //from active profile can also be taken into account
-
- List activeProfileList = project.getActiveProfiles();
- for (Iterator iter = activeProfileList.iterator(); iter.hasNext();) {
- Profile activeProfile = (Profile) iter.next();
- parseDependencies(serviceUnits, activeProfile.getDependencies().iterator(), orderedServiceUnits);
-
- }
-
- return orderedServiceUnits;
- }
-
- private void parseDependencies(List serviceUnits, Iterator dependencies,
- List orderedServiceUnits) throws MojoExecutionException {
- while (dependencies.hasNext()) {
- Dependency dependency = (Dependency) dependencies.next();
- if (dependency.getArtifactId().contains("${")) {
- int first = dependency.getArtifactId().indexOf("${");
- int last = dependency.getArtifactId().indexOf("}");
- String property = dependency.getArtifactId().substring(first + 2, last);
- Object propValue = project.getProperties().get(property);
- if (propValue == null) {
- throw new MojoExecutionException("The value for the property " + property + "is not set."
- + "Jbi descriptor may not be generated properly");
- }
- String propString = (String) propValue;
- String artifactID = dependency.getArtifactId().replace("${" + property + "}", propString);
- dependency.setArtifactId(artifactID);
- }
- for (Iterator it = serviceUnits.iterator(); it.hasNext();) {
- DependencyInformation serviceUnitInfo = (DependencyInformation) it
- .next();
- if (dependency.getArtifactId()
- .equals(serviceUnitInfo.getName())) {
- //check if this su already added to descriptor
- boolean addedSu = false;
- for (Iterator innerIt = orderedServiceUnits.iterator();innerIt.hasNext();) {
- DependencyInformation addedServiceUnitInfo = (DependencyInformation) innerIt.next();
- if (addedServiceUnitInfo.getName().equals(serviceUnitInfo.getName())) {
- addedSu = true;
- }
- }
- if (!addedSu) {
- getLog().debug("Adding " + serviceUnitInfo.getFilename());
- orderedServiceUnits.add(serviceUnitInfo);
- }
- }
-
- }
- }
- }
-
- private Iterator getReparsedDependencies() throws MojoExecutionException {
- MavenXpp3Reader mavenXpp3Reader = new MavenXpp3Reader();
- try {
- Model model = mavenXpp3Reader.read(new FileReader(new File(project
- .getBasedir(), "pom.xml")), false);
- return model.getDependencies().iterator();
- } catch (Exception e) {
- throw new MojoExecutionException("Unable to reparse the pom.xml");
- }
- }
-
- private String getComponentName(MavenProject project, Set artifacts,
- Artifact suArtifact) throws MojoExecutionException {
-
- getLog().info(
- "Determining component name for service unit "
- + project.getArtifactId());
- if (project.getProperties().getProperty("componentName") != null) {
- return project.getProperties().getProperty("componentName");
- }
-
- JbiResolutionListener.Node n = listener.getNode(suArtifact);
- for (Iterator it = n.getChildren().iterator(); it.hasNext();) {
- JbiResolutionListener.Node child = (JbiResolutionListener.Node) it
- .next();
- MavenProject artifactProject = null;
- try {
- getLog().info(child.getArtifact().toString());
-
- artifactProject = projectBuilder
- .buildFromRepository(child.getArtifact(),
- remoteRepos, localRepo);
- } catch (ProjectBuildingException e) {
- getLog().warn(
- "Unable to determine packaging for dependency : "
- + child.getArtifact().getArtifactId()
- + " assuming jar");
- getLog().debug(e);
- }
- if (artifactProject != null) {
- getLog().info(
- "Project " + artifactProject + " packaged "
- + artifactProject.getPackaging());
- }
- if ((artifactProject != null)
- && (artifactProject.getPackaging().equals("jbi-component"))) {
- return child.getArtifact().getArtifactId();
- }
- }
-
- //as the jbi-component packaged dependency may already have been pruned
- //in case of multiple sus which belong to same jbi-component exist in one sa, so we
- //just check the dependencies from this su maven project to find the jbi-component name
-
- for (Iterator it = project.getArtifacts().iterator(); it.hasNext();) {
- Artifact artifactInSUPom = (Artifact) it
- .next();
- MavenProject artifactProject = null;
- try {
- artifactProject = projectBuilder.buildFromRepository(artifactInSUPom
- , remoteRepos, localRepo);
- } catch (ProjectBuildingException e) {
- getLog().warn(
- "Unable to determine packaging for dependency : "
- + artifactInSUPom.getArtifactId()
- + " assuming jar");
- getLog().debug(e);
- }
- if (artifactProject != null) {
- getLog().info(
- "Project " + artifactProject + " packaged "
- + artifactProject.getPackaging());
- }
- if ((artifactProject != null)
- && (artifactProject.getPackaging().equals("jbi-component"))) {
- return artifactInSUPom.getArtifactId();
- }
- }
-
- throw new MojoExecutionException(
- "The service unit "
- + project.getArtifactId()
- + " does not have a dependency which is packaged as a jbi-component or a project property 'componentName'");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
deleted file mode 100644
index cdbfc6b..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyMojo.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * 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 org.apache.maven.archiver.MavenArchiveConfiguration;
-import org.apache.maven.archiver.MavenArchiver;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.model.Plugin;
-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.jar.JarArchiver;
-import org.codehaus.plexus.archiver.jar.Manifest;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A Mojo used to build the jbi service assembly zip file
- *
- * @goal jbi-service-assembly
- * @phase package
- * @requiresDependencyResolution runtime
- * @description injects additional libraries into service assembly
- */
-public class GenerateServiceAssemblyMojo extends AbstractJbiMojo {
-
- /**
- * The Zip archiver.
- *
- * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
- * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="jar"
- * @required
- */
- private JarArchiver jarArchiver;
-
- /**
- * 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.build.finalName}.zip"
- * @required
- */
- private String finalName;
-
- /**
- * The maven archive configuration to use.
- *
- * @parameter
- */
- private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
-
- public void execute() throws MojoExecutionException, MojoFailureException {
- try {
- injectDependentServiceUnits();
- File sa = new File(outputDirectory, finalName);
- createArchive(sa);
- project.getArtifact().setFile(sa);
- } catch (Exception e) {
- throw new MojoExecutionException("Failed to inject dependencies", e);
- }
- }
-
- private void createArchive(File installerFile) throws JbiPluginException {
- try {
- getLog().info("Generating service assembly " + installerFile.getAbsolutePath());
- MavenArchiver archiver = new MavenArchiver();
- archiver.setArchiver(jarArchiver);
- archiver.setOutputFile(installerFile);
- Manifest m = createManifest();
- String version = getProject().getArtifact().getVersion();
- // add Implementation-Version attribute in the MANIFEST
- m.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Implementation-Version", version));
-
- getLog().info("Add Implementation-Version: " + version);
-
- jarArchiver.addConfiguredManifest(m);
-
- File classesDir = new File(getProject().getBuild().getOutputDirectory());
- if ( classesDir.exists() )
- jarArchiver.addDirectory(classesDir, null, DirectoryScanner.DEFAULTEXCLUDES);
-
- jarArchiver.addDirectory(workDirectory, null, DirectoryScanner.DEFAULTEXCLUDES);
- archiver.createArchive(getProject(), archive);
- } catch (Exception e) {
- throw new JbiPluginException("Error creating shared library: "
- + e.getMessage(), e);
- }
- }
-
- private void injectDependentServiceUnits() throws JbiPluginException, ArtifactResolutionException, ArtifactNotFoundException {
- Set artifacts = project.getArtifacts();
- for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
- // TODO: utilise appropriate methods from project builder
- ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
- if (!artifact.isOptional() && filter.include(artifact) && (artifact.getDependencyTrail().size() == 2)) {
- 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");
- }
- if (project != null && project.getPackaging().equals("jbi-service-unit")) {
- try {
- String suName = getServiceUnitName(project);
- String path = artifact.getFile().getAbsolutePath();
- if (suName != null && suName.length() > 0) {
- path = path.substring(0, path.lastIndexOf(File.separator)) + File.separator + suName;
- } else {
- path = path.substring(0, path.lastIndexOf('.')) + ".zip";
- }
- FileUtils.copyFileToDirectory(new File(path), workDirectory);
- } catch (IOException e) {
- throw new JbiPluginException(e);
- }
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
deleted file mode 100644
index b8e2301..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * 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.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.model.Plugin;
-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.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-
-/**
- * A Mojo used to build the jbi.xml file for a service unit.
- *
- * @author <a href="pdodds@apache.org">Philip Dodds</a>
- * @version $Id: GenerateComponentDescriptorMojo 314956 2005-10-12 16:27:15Z
- * brett $
- * @goal generate-jbi-service-unit-descriptor
- * @phase process-classes
- * @requiresDependencyResolution runtime
- * @description generates the jbi.xml deployment descriptor for a service unit
- */
-public class GenerateServiceUnitDescriptorMojo extends AbstractJbiMojo {
-
- public static final String UTF_8 = "UTF-8";
-
- /**
- * Whether the jbi.xml should be generated or not.
- *
- * @parameter
- */
- private Boolean generateJbiDescriptor = Boolean.TRUE;
-
- /**
- * Determines whether to use the service unit analyzer
- *
- * @parameter
- */
- private Boolean useServiceUnitAnalyzer = Boolean.TRUE;
-
- /**
- * Specifies a serviceUnitAnalyzer class name (optional)
- *
- * @parameter
- */
- private String serviceUnitAnalyzerClass;
-
- /**
- * Fail if the descriptor generation fails
- *
- * @parameter
- */
- private Boolean failOnJbiDescriptorFailure = Boolean.FALSE;
-
- /**
- * 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}"
- */
- private String name;
-
- /**
- * The component description.
- *
- * @parameter expression="${project.name}"
- */
- private String description;
-
- /**
- * Character encoding for the auto-generated application.xml file.
- *
- * @parameter
- */
- private String encoding = UTF_8;
-
- /**
- * Directory where the application.xml file will be auto-generated.
- *
- * @parameter expression="${project.build.directory}/classes/META-INF"
- */
- private String generatedDescriptorLocation;
-
- /**
- * Directory where artifacts for the service unit are held
- *
- * @parameter expression="${basedir}/src/main/resources"
- */
- private File serviceUnitArtifactsDir;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- getLog().debug(
- " ======= GenerateServiceUnitDescriptorMojo settings =======");
- getLog().debug("workDirectory[" + workDirectory + "]");
- getLog().debug("generateDescriptor[" + generateJbiDescriptor + "]");
- getLog().debug("name[" + name + "]");
- getLog().debug("description[" + description + "]");
- getLog().debug("encoding[" + encoding + "]");
- getLog().debug(
- "generatedDescriptorLocation[" + generatedDescriptorLocation
- + "]");
-
- if (!generateJbiDescriptor.booleanValue()) {
- getLog().debug("Generation of jbi.xml is disabled");
- return;
- }
-
- // Generate jbi descriptor and copy it to the build directory
- getLog().info("Generating jbi.xml");
- try {
- generateJbiDescriptor();
- } catch (JbiPluginException e) {
- if (failOnJbiDescriptorFailure.booleanValue()) {
- throw new MojoExecutionException("Failed to generate jbi.xml",
- e);
- } else {
- getLog().warn("Failed to generate jbi.xml: " + e, e);
- }
- }
-
- }
-
- /**
- * Generates the deployment descriptor if necessary.
- */
- protected void generateJbiDescriptor() throws JbiPluginException {
- File outputDir = new File(generatedDescriptorLocation);
- if (!outputDir.exists()) {
- outputDir.mkdirs();
- }
-
- ClassLoader old = Thread.currentThread().getContextClassLoader();
-
- try {
- URLClassLoader newClassLoader = getClassLoader();
- Thread.currentThread().setContextClassLoader(newClassLoader);
- File descriptor = new File(outputDir, JBI_DESCRIPTOR);
- List uris = new ArrayList();
- JbiServiceUnitDescriptorWriter writer = new JbiServiceUnitDescriptorWriter(
- encoding);
-
- List consumes = new ArrayList();
- List provides = new ArrayList();
-
- 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);
-
- boolean bc = false;
- // TODO: find if the component target is a BC ?
- writer.write(descriptor, bc, name, description, uris, consumes,
- provides);
- } catch (Exception e) {
- throw new JbiPluginException(
- "Unable to generate service unit descriptor!", e);
- } finally {
- Thread.currentThread().setContextClassLoader(old);
- }
- }
-
- private String getServiceUnitAnalyzer() {
- // 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()) {
- if (serviceUnitAnalyzerClass != null) {
- return serviceUnitAnalyzerClass;
- }
- 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;
- }
- }
- }
- }
- }
- return null;
- }
-
- private MavenProject getComponentProject() {
- Set artifacts = project.getArtifacts();
- for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
-
- // TODO: utilise appropriate methods from project builder
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
- if (!artifact.isOptional() && filter.include(artifact)
- && (artifact.getDependencyTrail().size() == 2)) {
- 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");
- }
- if ((project != null)
- && (project.getPackaging().equals("jbi-component"))) {
- return project;
- }
-
- }
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java
deleted file mode 100644
index 3b2c7e0..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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.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.handler.ArtifactHandler;
-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.FileUtils;
-
-/**
- * A Mojo used to build the jbi service unit zip file
- *
- * @author <a href="pdodds@apache.org">Philip Dodds</a>
- * @version $Id: GenerateApplicationXmlMojo.java 314956 2005-10-12 16:27:15Z
- * brett $
- * @goal jbi-service-unit
- * @phase package
- * @requiresDependencyResolution runtime
- * @description injects additional libraries into service unit
- */
-public class GenerateServiceUnitMojo extends AbstractJbiMojo {
-
- /**
- * The name of the generated war.
- *
- * @parameter expression="${project.build.finalName}.zip"
- * @required
- */
- private String serviceUnitName;
-
- /**
- * The directory for the generated JBI component.
- *
- * @parameter expression="${project.build.directory}"
- * @required
- */
- private File outputDirectory;
-
- /**
- * The Zip archiver.
- *
- * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
- * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="jar"
- * @required
- */
- private JarArchiver jarArchiver;
-
- /**
- * The maven archive configuration to use.
- *
- * @parameter
- */
- private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
-
- /**
- * Directory where the application.xml file will be auto-generated.
- *
- * @parameter expression="${project.build.directory}/classes"
- */
- private File serviceUnitLocation;
-
- /**
- * ArtifactHandler to handle jbi-service-unit artifacts
- *
- * @component role="org.apache.maven.artifact.handler.ArtifactHandler" roleHint="jbi-service-unit"
- */
- private ArtifactHandler handler;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
- try {
-
- project.getArtifact().setArtifactHandler(handler);
- createUnpackedInstaller();
-
- File serviceUnitFile = new File(outputDirectory, serviceUnitName);
- createArchive(serviceUnitFile);
-
- projectHelper.attachArtifact(project, "zip", "", new File(
- outputDirectory, serviceUnitName));
-
- } catch (JbiPluginException e) {
- throw new MojoExecutionException("Failed to create service unit", e);
- }
-
- }
-
- private void createArchive(File installerFile) throws JbiPluginException {
- try {
-
- // generate war file
- getLog().info(
- "Generating service unit "
- + installerFile.getAbsolutePath());
- MavenArchiver archiver = new MavenArchiver();
- archiver.setArchiver(jarArchiver);
- archiver.setOutputFile(installerFile);
- jarArchiver.addDirectory(workDirectory);
-
- // create archive
- archiver.createArchive(getProject(), archive);
-
- } catch (ArchiverException e) {
- throw new JbiPluginException("Error creating service unit: "
- + e.getMessage(), e);
- } catch (ManifestException e) {
- throw new JbiPluginException("Error creating service unit: "
- + e.getMessage(), e);
- } catch (IOException e) {
- throw new JbiPluginException("Error creating service unit: "
- + e.getMessage(), e);
- } catch (DependencyResolutionRequiredException e) {
- throw new JbiPluginException("Error creating service unit: "
- + e.getMessage(), e);
- }
-
- }
-
- private void createUnpackedInstaller() throws JbiPluginException {
-
- if (!workDirectory.isDirectory() && !workDirectory.mkdirs()) {
- throw new JbiPluginException("Unable to create work directory: " + workDirectory);
- }
-
- try {
- FileUtils.copyDirectoryStructure(serviceUnitLocation, workDirectory);
- } catch (IOException e) {
- throw new JbiPluginException("Unable to copy directory "
- + serviceUnitLocation, e);
- }
-
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
-
- JbiResolutionListener listener = resolveProject();
- // print(listener.getRootNode(), "");
-
- 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;
- getLog().info("Resolving " + artifact);
- 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-component".equals(type)) {
- removeBranch(listener, artifact);
- } else if ("jbi-shared-library".equals(type)) {
- removeBranch(listener, artifact);
- } else {
- includes.add(artifact);
- }
- }
- }
- // print(listener.getRootNode(), "");
-
- for (Iterator iter = retainArtifacts(includes, listener).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);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java
deleted file mode 100644
index 1e8bb2d..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryDescriptorMojo.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.FileUtils;
-
-/**
- * A Mojo used to build the jbi.xml file for a shared library
- *
- * @author <a href="pdodds@apache.org">Philip Dodds</a>
- * @version $Id: GenerateComponentDescriptorMojo 314956 2005-10-12 16:27:15Z
- * brett $
- * @goal generate-jbi-shared-library-descriptor
- * @phase generate-resources
- * @requiresDependencyResolution runtime
- * @description generates the jbi.xml deployment descriptor for a shared library
- */
-public class GenerateSharedLibraryDescriptorMojo extends AbstractJbiMojo {
-
- public static final String UTF_8 = "UTF-8";
-
- /**
- * Whether the jbi.xml should be generated or not.
- *
- * @parameter
- */
- private Boolean generateJbiDescriptor = Boolean.TRUE;
-
- /**
- * The shared library name.
- *
- * @parameter expression="${project.artifactId}"
- */
- private String name;
-
- /**
- * The shared library description.
- *
- * @parameter expression="${project.name}"
- */
- private String description;
-
- /**
- * The shared library version.
- *
- * @parameter expression="${project.version}"
- */
- private String version;
-
- /**
- * The shared library class loader delegation
- *
- * @parameter expression="parent-first"
- */
- private String classLoaderDelegation;
-
- /**
- * Character encoding for the auto-generated application.xml file.
- *
- * @parameter
- */
- private String encoding = UTF_8;
-
- /**
- * Directory where the application.xml file will be auto-generated.
- *
- * @parameter expression="${project.build.directory}"
- */
- private String generatedDescriptorLocation;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- getLog()
- .debug(
- " ======= GenerateSharedLibraryDescriptorMojo settings =======");
- getLog().debug("workDirectory[" + workDirectory + "]");
- getLog().debug("generateJbiDescriptor[" + generateJbiDescriptor + "]");
- getLog().debug("name[" + name + "]");
- getLog().debug("description[" + description + "]");
- getLog().debug("encoding[" + encoding + "]");
- getLog().debug(
- "generatedDescriptorLocation[" + generatedDescriptorLocation
- + "]");
- getLog().debug("version[" + version + "]");
-
- if (!generateJbiDescriptor.booleanValue()) {
- getLog().debug("Generation of jbi.xml is disabled");
- return;
- }
-
- // Generate jbi descriptor and copy it to the build directory
- getLog().info("Generating jbi.xml");
- try {
- generateJbiDescriptor();
- } catch (JbiPluginException e) {
- throw new MojoExecutionException("Failed to generate jbi.xml", e);
- }
-
- try {
- FileUtils.copyFileToDirectory(new File(generatedDescriptorLocation,
- JBI_DESCRIPTOR), new File(getWorkDirectory(), META_INF));
- } catch (IOException e) {
- throw new MojoExecutionException(
- "Unable to copy jbi.xml to final destination", e);
- }
- }
-
- /**
- * Generates the deployment descriptor if necessary.
- */
- protected void generateJbiDescriptor() throws JbiPluginException {
- File outputDir = new File(generatedDescriptorLocation);
- if (!outputDir.exists()) {
- outputDir.mkdirs();
- }
-
- File descriptor = new File(outputDir, JBI_DESCRIPTOR);
-
- List embeddedLibraries = new ArrayList();
-
- DependencyInformation info = new DependencyInformation();
- info.setFilename(LIB_DIRECTORY + "/" + project.getArtifactId() + "-"
- + project.getVersion() + ".jar");
- info.setVersion(project.getVersion());
- info.setName(project.getArtifactId());
- info.setType("jar");
- embeddedLibraries.add(info);
-
- Set artifacts = project.getArtifacts();
- for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
-
- // TODO: utilise appropriate methods from project builder
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
- if (!artifact.isOptional() && filter.include(artifact)) {
- String type = artifact.getType();
- if ("jar".equals(type)) {
- info = new DependencyInformation();
- info.setFilename(LIB_DIRECTORY + "/"
- + artifact.getFile().getName());
- embeddedLibraries.add(info);
- }
- }
- }
-
- JbiSharedLibraryDescriptorWriter writer = new JbiSharedLibraryDescriptorWriter(
- encoding);
- writer.write(descriptor, name, description, version,
- classLoaderDelegation, embeddedLibraries);
- }
-}
http://git-wip-us.apache.org/repos/asf/servicemix-maven-plugins/blob/681882ee/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
----------------------------------------------------------------------
diff --git a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java b/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
deleted file mode 100644
index cff991d..0000000
--- a/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateSharedLibraryMojo.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * 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.io.IOException;
-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.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.archiver.jar.JarArchiver;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
-
-/**
- * A Mojo used to build the jbi shared library zip file
- *
- * @author <a href="pdodds@apache.org">Philip Dodds</a>
- * @version $Id: GenerateApplicationXmlMojo.java 314956 2005-10-12 16:27:15Z
- * brett $
- * @goal jbi-shared-library
- * @phase package
- * @requiresDependencyResolution runtime
- * @description injects additional libraries into shared library
- */
-public class GenerateSharedLibraryMojo 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.build.finalName}.zip"
- * @required
- */
- private String sharedLibraryName;
-
- /**
- * The name of the generated war.
- *
- * @parameter expression="${project.build.finalName}.jar"
- * @required
- */
- private String jarName;
-
- /**
- * The Zip archiver.
- *
- * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="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[" + sharedLibraryName + "]");
- getLog().debug("jbiSourceDirectory[" + jbiSourceDirectory + "]");
-
- try {
-
- createUnpackedSharedLibrary();
-
- File installerFile = new File(outputDirectory, sharedLibraryName);
- createArchive(installerFile);
-
- projectHelper.attachArtifact(project, "jar", "", new File(
- outputDirectory, jarName));
-
- projectHelper.attachArtifact(project, "zip", "installer", new File(
- outputDirectory, sharedLibraryName));
-
- } catch (JbiPluginException e) {
- throw new MojoExecutionException("Failed to create shared library",
- e);
- }
- }
-
- private void createArchive(File installerFile) throws JbiPluginException {
- try {
-
- // generate war file
- getLog().info(
- "Generating shared library "
- + installerFile.getAbsolutePath());
- MavenArchiver archiver = new MavenArchiver();
- archiver.setArchiver(jarArchiver);
- archiver.setOutputFile(installerFile);
- jarArchiver.addDirectory(workDirectory);
- jarArchiver.addConfiguredManifest(createManifest());
- if (jbiSourceDirectory.isDirectory()) {
- jarArchiver.addDirectory(jbiSourceDirectory, null,
- DirectoryScanner.DEFAULTEXCLUDES);
- }
- // create archive
- archiver.createArchive(getProject(), archive);
-
- } catch (Exception e) {
- throw new JbiPluginException("Error creating shared library: "
- + e.getMessage(), e);
- }
- }
-
- private void createUnpackedSharedLibrary() throws JbiPluginException {
-
- if (!workDirectory.isDirectory() && !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);
- }
-
- Set artifacts = project.getArtifacts();
- for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
- Artifact artifact = (Artifact) iter.next();
-
- // TODO: utilise appropriate methods from project builder
- ScopeArtifactFilter filter = new ScopeArtifactFilter(
- Artifact.SCOPE_RUNTIME);
- if (!artifact.isOptional() && filter.include(artifact)) {
- String type = artifact.getType();
- if ("jar".equals(type)) {
- try {
- FileUtils.copyFileToDirectory(artifact.getFile(),
- new File(workDirectory, LIB_DIRECTORY));
- } catch (IOException e) {
- throw new JbiPluginException("Unable to copy file "
- + artifact.getFile(), e);
- }
- }
- }
- }
- }
-
-}