1 package org.codehaus.mojo.jboss.packaging;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.execution.MavenSession;
29 import org.apache.maven.model.Resource;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.shared.filtering.MavenFilteringException;
32 import org.apache.maven.shared.filtering.MavenResourcesExecution;
33 import org.apache.maven.shared.filtering.MavenResourcesFiltering;
34 import org.codehaus.plexus.archiver.UnArchiver;
35 import org.codehaus.plexus.archiver.manager.ArchiverManager;
36 import org.codehaus.plexus.util.FileUtils;
37
38 /**
39 * Builds a deployable JBoss Process Archive.
40 *
41 * @goal par
42 * @phase package
43 * @requiresDependencyResolution runtime
44 * @threadSafe
45 * @since 2.1
46 */
47 public class ParMojo
48 extends AbstractPackagingMojo
49 {
50
51 /**
52 * The artifact type.
53 */
54 private static final String ARTIFACT_TYPE = "jboss-par";
55
56 /**
57 * Component that determines how to extract archive files.
58 *
59 * @component
60 */
61 private ArchiverManager archiverManager;
62
63 /**
64 * @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default"
65 * @required
66 */
67 private MavenResourcesFiltering mavenResourcesFiltering;
68
69 /**
70 * The resources to include in the packaged archive. Specifying this overrides using jbpmDirectory and
71 * jpdlDirectory.
72 *
73 * @parameter
74 */
75 private List resources;
76
77 /**
78 * The character encoding of the resource files.
79 *
80 * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
81 */
82 private String encoding;
83
84 /**
85 * @parameter expression="${session}"
86 * @readonly
87 * @required
88 */
89 private MavenSession session;
90
91 /**
92 * The filters used when copying the resource files. By default this
93 * will use the resource filters specified in the POM.
94 *
95 * @parameter default-value="${project.build.filters}"
96 */
97 private List filters;
98
99 /**
100 * The location of the jbpm deployment descriptor file (processdefinition.xml) If it is present in
101 * src/main/resources then it will automatically be included. Otherwise this parameter must be set.
102 *
103 * @parameter default-value="${project.build.directory}/${project.build.finalName}/processdefinition.xml"
104 * expression="${deploymentDescriptorFile}"
105 */
106 private File deploymentDescriptorFile;
107
108 /**
109 * The directory where compiled classes and resources are placed.
110 *
111 * @parameter default-value="${project.build.directory}/${project.build.finalName}/classes"
112 */
113 private File packagingClassesDirectory;
114
115 /**
116 * The destination of the deployment descriptor file.
117 *
118 * @parameter default-value="${project.build.directory}/${project.build.finalName}"
119 */
120 private File deploymentDescriptorDest;
121
122 /**
123 * The directory where JBoss JBPM resources are located.
124 *
125 * @parameter default-value="src/main/jbpm"
126 */
127 private File jbpmDirectory;
128
129 /**
130 * The directory where JBoss JPDL resources are located.
131 *
132 * @parameter default-value="src/main/jpdl/${project.artifactId}"
133 */
134 private File jpdlDirectory;
135
136 /**
137 * Get the type of the artifact.
138 *
139 * @return The type of the generated artifact.
140 */
141 public String getArtifactType()
142 {
143 return ARTIFACT_TYPE;
144 }
145
146 public File getDeploymentDescriptor()
147 {
148 return deploymentDescriptorFile;
149 }
150
151 public File getDeploymentDescriptorDest() {
152 return deploymentDescriptorDest;
153 }
154
155 /**
156 * Packages the par-specific resources.
157 */
158 protected void packageResources()
159 throws Exception
160 {
161 // If resources weren't specified, add defaults
162 if ( resources == null )
163 {
164 resources = new ArrayList();
165
166 if ( jbpmDirectory.exists() )
167 {
168 getLog().info( "Configuring jbpm directory: " + jbpmDirectory.getPath() );
169 Resource resource = new Resource();
170 resource.setDirectory( jbpmDirectory.getPath() );
171 resource.addInclude( "**/*" );
172 resource.setFiltering( false );
173 resources.add( resource );
174 }
175
176 if ( jpdlDirectory.exists() )
177 {
178 getLog().info( "Configuring jpdl directory: " + jpdlDirectory.getPath() );
179 Resource resource = new Resource();
180 resource.setDirectory( jpdlDirectory.getPath() );
181 resource.addInclude( "**/*" );
182 resource.setFiltering( false );
183 resources.add( resource );
184 }
185 }
186
187 MavenResourcesExecution resourcesExec =
188 new MavenResourcesExecution( resources, getPackagingDirectory(), getProject(), encoding, filters,
189 Collections.EMPTY_LIST, session );
190 try
191 {
192 mavenResourcesFiltering.filterResources( resourcesExec );
193 }
194 catch ( MavenFilteringException e )
195 {
196 throw new MojoExecutionException( e.getMessage(), e );
197 }
198 }
199
200 /**
201 * Overrides the default implementation so classes are packaged under a subdirectory.
202 */
203 protected void packageClasses()
204 throws Exception
205 {
206 FileUtils.copyDirectoryStructure( getClassesDirectory(), packagingClassesDirectory );
207 }
208
209 /**
210 * Overrides the default implementation to explode the depdencies into the classes directory.
211 */
212 protected void packageLib( Artifact artifact, String name )
213 throws Exception
214 {
215 UnArchiver unArchiver = archiverManager.getUnArchiver( artifact.getFile() );
216 unArchiver.setSourceFile( artifact.getFile() );
217 unArchiver.setDestDirectory( packagingClassesDirectory );
218 unArchiver.extract();
219 }
220 }