| 1 | |
package org.apache.maven.plugin.ear; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 23 | |
import org.apache.maven.plugin.MojoFailureException; |
| 24 | |
import org.codehaus.plexus.configuration.PlexusConfiguration; |
| 25 | |
import org.codehaus.plexus.configuration.PlexusConfigurationException; |
| 26 | |
import org.codehaus.plexus.util.FileUtils; |
| 27 | |
|
| 28 | |
import java.io.File; |
| 29 | |
import java.io.IOException; |
| 30 | |
import java.util.ArrayList; |
| 31 | |
import java.util.List; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | public class GenerateApplicationXmlMojo |
| 44 | |
extends AbstractEarMojo |
| 45 | |
{ |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | 0 | private Boolean generateApplicationXml = Boolean.TRUE; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
private String displayName; |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
private String description; |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
private PlexusConfiguration security; |
| 79 | |
|
| 80 | |
|
| 81 | |
public void execute() |
| 82 | |
throws MojoExecutionException, MojoFailureException |
| 83 | |
{ |
| 84 | |
|
| 85 | 0 | super.execute(); |
| 86 | |
|
| 87 | |
|
| 88 | 0 | if ( !generateApplicationXml.booleanValue() ) |
| 89 | |
{ |
| 90 | 0 | getLog().debug( "Generation of application.xml is disabled" ); |
| 91 | |
} |
| 92 | |
else |
| 93 | |
{ |
| 94 | |
|
| 95 | 0 | if ( !version.equals( VERSION_1_3 ) && !version.equals( VERSION_1_4 ) && |
| 96 | |
!version.equals( VERSION_5 ) && !version.equals( VERSION_6 ) ) |
| 97 | |
{ |
| 98 | 0 | throw new MojoExecutionException( "Invalid version[" + version + "]" ); |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | 0 | getLog().info( "Generating application.xml" ); |
| 103 | |
try |
| 104 | |
{ |
| 105 | 0 | generateStandardDeploymentDescriptor(); |
| 106 | |
} |
| 107 | 0 | catch ( EarPluginException e ) |
| 108 | |
{ |
| 109 | 0 | throw new MojoExecutionException( "Failed to generate application.xml", e ); |
| 110 | 0 | } |
| 111 | |
|
| 112 | |
try |
| 113 | |
{ |
| 114 | 0 | FileUtils.copyFileToDirectory( new File( generatedDescriptorLocation, "application.xml" ), |
| 115 | |
new File( getWorkDirectory(), "META-INF" ) ); |
| 116 | |
} |
| 117 | 0 | catch ( IOException e ) |
| 118 | |
{ |
| 119 | 0 | throw new MojoExecutionException( "Unable to copy application.xml to final destination", e ); |
| 120 | 0 | } |
| 121 | |
} |
| 122 | |
|
| 123 | |
|
| 124 | 0 | if ( getJbossConfiguration() == null ) |
| 125 | |
{ |
| 126 | 0 | getLog().debug( "Generation of jboss-app.xml is disabled" ); |
| 127 | 0 | return; |
| 128 | |
} |
| 129 | |
else |
| 130 | |
{ |
| 131 | |
|
| 132 | 0 | getLog().info( "Generating jboss-app.xml" ); |
| 133 | |
try |
| 134 | |
{ |
| 135 | 0 | generateJbossDeploymentDescriptor(); |
| 136 | |
} |
| 137 | 0 | catch ( EarPluginException e ) |
| 138 | |
{ |
| 139 | 0 | throw new MojoExecutionException( "Failed to generate jboss-app.xml", e ); |
| 140 | 0 | } |
| 141 | |
|
| 142 | |
try |
| 143 | |
{ |
| 144 | 0 | FileUtils.copyFileToDirectory( new File( generatedDescriptorLocation, "jboss-app.xml" ), |
| 145 | |
new File( getWorkDirectory(), "META-INF" ) ); |
| 146 | |
} |
| 147 | 0 | catch ( IOException e ) |
| 148 | |
{ |
| 149 | 0 | throw new MojoExecutionException( "Unable to copy jboss-app.xml to final destination", e ); |
| 150 | 0 | } |
| 151 | |
} |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
protected void generateStandardDeploymentDescriptor() |
| 158 | |
throws EarPluginException |
| 159 | |
{ |
| 160 | 0 | File outputDir = new File( generatedDescriptorLocation ); |
| 161 | 0 | if ( !outputDir.exists() ) |
| 162 | |
{ |
| 163 | 0 | outputDir.mkdirs(); |
| 164 | |
} |
| 165 | |
|
| 166 | 0 | File descriptor = new File( outputDir, "application.xml" ); |
| 167 | |
|
| 168 | 0 | final ApplicationXmlWriter writer = new ApplicationXmlWriter( version, encoding ); |
| 169 | 0 | final ApplicationXmlWriterContext context = new ApplicationXmlWriterContext(descriptor, getModules(), |
| 170 | |
buildSecurityRoles(), displayName, description, defaultLibBundleDir); |
| 171 | 0 | writer.write( context ); |
| 172 | 0 | } |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
protected void generateJbossDeploymentDescriptor() |
| 178 | |
throws EarPluginException |
| 179 | |
{ |
| 180 | 0 | File outputDir = new File( generatedDescriptorLocation ); |
| 181 | 0 | if ( !outputDir.exists() ) |
| 182 | |
{ |
| 183 | 0 | outputDir.mkdirs(); |
| 184 | |
} |
| 185 | |
|
| 186 | 0 | File descriptor = new File( outputDir, "jboss-app.xml" ); |
| 187 | |
|
| 188 | 0 | JbossAppXmlWriter writer = new JbossAppXmlWriter( encoding ); |
| 189 | 0 | writer.write( descriptor, getJbossConfiguration(), getModules() ); |
| 190 | 0 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
private List buildSecurityRoles() |
| 199 | |
throws EarPluginException |
| 200 | |
{ |
| 201 | 0 | final List result = new ArrayList(); |
| 202 | 0 | if ( security == null ) |
| 203 | |
{ |
| 204 | 0 | return result; |
| 205 | |
} |
| 206 | |
try |
| 207 | |
{ |
| 208 | 0 | final PlexusConfiguration[] securityRoles = security.getChildren( SecurityRole.SECURITY_ROLE ); |
| 209 | |
|
| 210 | 0 | for ( int i = 0; i < securityRoles.length; i++ ) |
| 211 | |
{ |
| 212 | 0 | PlexusConfiguration securityRole = securityRoles[i]; |
| 213 | 0 | final String id = securityRole.getAttribute( SecurityRole.ID_ATTRIBUTE ); |
| 214 | 0 | final String roleName = securityRole.getChild( SecurityRole.ROLE_NAME ).getValue(); |
| 215 | 0 | final String roleNameId = |
| 216 | |
securityRole.getChild( SecurityRole.ROLE_NAME ).getAttribute( SecurityRole.ID_ATTRIBUTE ); |
| 217 | 0 | final String description = securityRole.getChild( SecurityRole.DESCRIPTION ).getValue(); |
| 218 | 0 | final String descriptionId = |
| 219 | |
securityRole.getChild( SecurityRole.DESCRIPTION ).getAttribute( SecurityRole.ID_ATTRIBUTE ); |
| 220 | |
|
| 221 | 0 | if ( roleName == null ) |
| 222 | |
{ |
| 223 | 0 | throw new EarPluginException( "Invalid security-role configuration, role-name could not be null." ); |
| 224 | |
} |
| 225 | |
else |
| 226 | |
{ |
| 227 | 0 | result.add( new SecurityRole( roleName, roleNameId, id, description, descriptionId ) ); |
| 228 | |
} |
| 229 | |
} |
| 230 | 0 | return result; |
| 231 | |
} |
| 232 | 0 | catch ( PlexusConfigurationException e ) |
| 233 | |
{ |
| 234 | 0 | throw new EarPluginException( "Invalid security-role configuration", e ); |
| 235 | |
} |
| 236 | |
|
| 237 | |
} |
| 238 | |
} |