KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > maven > plugin > jbi > GenerateServiceAssemblyMojo


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.maven.plugin.jbi;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
26 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
27 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugin.MojoFailureException;
30 import org.apache.maven.project.MavenProject;
31 import org.apache.maven.project.ProjectBuildingException;
32 import org.codehaus.plexus.util.FileUtils;
33
34 /**
35  * A Mojo used to build the jbi service assembly zip file
36  *
37  * @author <a HREF="pdodds@apache.org">Philip Dodds</a>
38  * @version $Id: GenerateApplicationXmlMojo.java 314956 2005-10-12 16:27:15Z
39  * brett $
40  * @goal jbi-service-assembly
41  * @phase package
42  * @requiresDependencyResolution runtime
43  * @description injects additional libraries into service assembly
44  */

45 public class GenerateServiceAssemblyMojo extends AbstractJbiMojo {
46
47     /**
48      * Directory where the application.xml file will be auto-generated.
49      *
50      * @parameter expression="${project.build.directory}/classes"
51      * @required
52      */

53     private File JavaDoc workDirectory;
54
55     public void execute() throws MojoExecutionException, MojoFailureException {
56         try {
57             injectDependentServiceUnits();
58         } catch (Exception JavaDoc e) {
59             throw new MojoExecutionException("Failed to inject dependencies", e);
60         }
61     }
62
63     private void injectDependentServiceUnits() throws JbiPluginException,
64             ArtifactResolutionException, ArtifactNotFoundException {
65         Set JavaDoc artifacts = project.getArtifacts();
66         for (Iterator JavaDoc iter = artifacts.iterator(); iter.hasNext();) {
67             Artifact artifact = (Artifact) iter.next();
68
69             // TODO: utilise appropriate methods from project builder
70
ScopeArtifactFilter filter = new ScopeArtifactFilter(
71                     Artifact.SCOPE_RUNTIME);
72             if (!artifact.isOptional() && filter.include(artifact)
73                     && (artifact.getDependencyTrail().size() == 2)) {
74                 MavenProject project = null;
75                 try {
76                     project = projectBuilder.buildFromRepository(artifact,
77                             remoteRepos, localRepo);
78                 } catch (ProjectBuildingException e) {
79                     getLog().warn(
80                             "Unable to determine packaging for dependency : "
81                                     + artifact.getArtifactId()
82                                     + " assuming jar");
83                 }
84                 if ((project != null)
85                         && (project.getPackaging().equals("jbi-service-unit"))) {
86                     try {
87                         String JavaDoc path = artifact.getFile().getAbsolutePath();
88                         path = path.substring(0, path.lastIndexOf('.')) + ".zip";
89                         FileUtils.copyFileToDirectory(new File JavaDoc(path),
90                                 workDirectory);
91                     } catch (IOException JavaDoc e) {
92                         throw new JbiPluginException(e);
93                     }
94                 }
95             }
96         }
97     }
98
99 }
100
Popular Tags