|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| EarParser.java | 83.3% | 87.5% | 100% | 87.2% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2003 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 20 |
package org.apache.cactus.integration.ant.deployment;
|
|
| 21 |
|
|
| 22 |
import java.io.File;
|
|
| 23 |
import java.io.IOException;
|
|
| 24 |
import java.util.Iterator;
|
|
| 25 |
|
|
| 26 |
import javax.xml.parsers.ParserConfigurationException;
|
|
| 27 |
|
|
| 28 |
import org.apache.cactus.integration.ant.deployment.application.ApplicationXml;
|
|
| 29 |
import org.apache.cactus.integration.ant.deployment.application.DefaultEarArchive;
|
|
| 30 |
import org.apache.cactus.integration.ant.deployment.application.EarArchive;
|
|
| 31 |
import org.apache.cactus.integration.ant.deployment.webapp.WarArchive;
|
|
| 32 |
import org.apache.tools.ant.BuildException;
|
|
| 33 |
import org.xml.sax.SAXException;
|
|
| 34 |
|
|
| 35 |
/**
|
|
| 36 |
* Parse an EAR descriptor to extract meaninful information for Cactus,
|
|
| 37 |
* the results being stored in a {@link EarDeployableFile} object.
|
|
| 38 |
*
|
|
| 39 |
* @since Cactus 1.5
|
|
| 40 |
* @version $Id: EarParser.java 239003 2004-05-31 20:05:27Z vmassol $
|
|
| 41 |
*/
|
|
| 42 |
public class EarParser |
|
| 43 |
{
|
|
| 44 |
/**
|
|
| 45 |
* Parse an EAR descriptor to extract meaninful information for Cactus.
|
|
| 46 |
*
|
|
| 47 |
* @param theDeployableFile the file to parse and deploy
|
|
| 48 |
* @return the parse results as a {@link EarDeployableFile} object
|
|
| 49 |
*/
|
|
| 50 | 4 |
public static final EarDeployableFile parse(File theDeployableFile) |
| 51 |
{
|
|
| 52 | 4 |
EarDeployableFile deployable = new EarDeployableFile();
|
| 53 |
|
|
| 54 | 4 |
try
|
| 55 |
{
|
|
| 56 | 4 |
deployable.setFile(theDeployableFile); |
| 57 |
|
|
| 58 | 4 |
EarArchive earArchive = new DefaultEarArchive(theDeployableFile);
|
| 59 | 4 |
String webUri = getUriOfCactifiedWebModule(earArchive); |
| 60 | 4 |
if (webUri == null) |
| 61 |
{
|
|
| 62 | 2 |
throw new BuildException("Could not find cactified web " |
| 63 |
+ "module in the [" + theDeployableFile + "] EAR."); |
|
| 64 |
} |
|
| 65 |
|
|
| 66 | 2 |
WarArchive warArchive = earArchive.getWebModule(webUri); |
| 67 | 2 |
if (warArchive == null) |
| 68 |
{
|
|
| 69 | 0 |
throw new BuildException("Could not find the WAR [" + webUri |
| 70 |
+ "] in the [" + theDeployableFile + "] EAR."); |
|
| 71 |
} |
|
| 72 |
|
|
| 73 | 2 |
deployable.setWarArchive(warArchive); |
| 74 | 2 |
deployable.setTestContext(parseTestContext(earArchive, webUri)); |
| 75 | 2 |
deployable.setServletRedirectorMapping( |
| 76 |
WarParser.parseServletRedirectorMapping( |
|
| 77 |
deployable.getWarArchive())); |
|
| 78 | 2 |
deployable.setFilterRedirectorMapping( |
| 79 |
WarParser.parseFilterRedirectorMapping( |
|
| 80 |
deployable.getWarArchive())); |
|
| 81 | 2 |
deployable.setJspRedirectorMapping( |
| 82 |
WarParser.parseJspRedirectorMapping( |
|
| 83 |
deployable.getWarArchive())); |
|
| 84 |
} |
|
| 85 |
catch (IOException e)
|
|
| 86 |
{
|
|
| 87 | 0 |
throw new BuildException("Failed to parse deployment descriptor " |
| 88 |
+ "for EAR file [" + theDeployableFile + "].", e); |
|
| 89 |
} |
|
| 90 |
catch (ParserConfigurationException e)
|
|
| 91 |
{
|
|
| 92 | 0 |
throw new BuildException("Failed to parse deployment descriptor " |
| 93 |
+ "for EAR file [" + theDeployableFile + "].", e); |
|
| 94 |
} |
|
| 95 |
catch (SAXException e)
|
|
| 96 |
{
|
|
| 97 | 0 |
throw new BuildException("Failed to parse deployment descriptor " |
| 98 |
+ "for EAR file [" + theDeployableFile + "].", e); |
|
| 99 |
} |
|
| 100 |
|
|
| 101 | 2 |
return deployable;
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
/**
|
|
| 105 |
* Find the test context from the EAR archive.
|
|
| 106 |
*
|
|
| 107 |
* @return the test context
|
|
| 108 |
* @param theEar the EAR archive from which to extract the test context
|
|
| 109 |
* @param theWebUri the WAR URI of the WAR file in the EAR from which to
|
|
| 110 |
* extract the test context
|
|
| 111 |
* @throws IOException If there was a problem reading the deployment
|
|
| 112 |
* descriptor in the WAR
|
|
| 113 |
* @throws SAXException If the deployment descriptor of the WAR could not
|
|
| 114 |
* be parsed
|
|
| 115 |
* @throws ParserConfigurationException If there is an XML parser
|
|
| 116 |
* configration problem
|
|
| 117 |
*/
|
|
| 118 | 4 |
protected static final String parseTestContext(EarArchive theEar, |
| 119 |
String theWebUri) |
|
| 120 |
throws ParserConfigurationException, IOException, SAXException
|
|
| 121 |
{
|
|
| 122 | 4 |
String context = theEar.getApplicationXml() |
| 123 |
.getWebModuleContextRoot(theWebUri); |
|
| 124 | 4 |
if (context == null) |
| 125 |
{
|
|
| 126 |
// The application.xml does not define a <context-root> element.
|
|
| 127 |
// This is wrong!
|
|
| 128 | 1 |
throw new BuildException("Your application.xml must define a " |
| 129 |
+ "<context-root> element in the <web> module definition.");
|
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
// Remove leading "/" if there is one.
|
|
| 133 | 3 |
if (context.startsWith("/")) |
| 134 |
{
|
|
| 135 | 3 |
context = context.substring(1); |
| 136 |
} |
|
| 137 |
|
|
| 138 | 3 |
return context;
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
/**
|
|
| 142 |
* Finds the web module in the EAR that contains the servlet test
|
|
| 143 |
* redirector, and returns the web-uri of the module found.
|
|
| 144 |
*
|
|
| 145 |
* <em>A web-app is considered cactified when it contains at least a
|
|
| 146 |
* mapping for the Cactus servlet test redirector</em>
|
|
| 147 |
*
|
|
| 148 |
* @return The URI of the cactified web-module, or <code>null</code> if no
|
|
| 149 |
* cactified web-app could be found
|
|
| 150 |
* @param theEar the EAR archive from which to extract the web URI
|
|
| 151 |
* @throws IOException If there was a problem reading the deployment
|
|
| 152 |
* descriptor in the WAR
|
|
| 153 |
* @throws SAXException If the deployment descriptor of the WAR could not
|
|
| 154 |
* be parsed
|
|
| 155 |
* @throws ParserConfigurationException If there is an XML parser
|
|
| 156 |
* configration problem
|
|
| 157 |
*/
|
|
| 158 | 4 |
protected static final String getUriOfCactifiedWebModule(EarArchive theEar) |
| 159 |
throws SAXException, IOException, ParserConfigurationException
|
|
| 160 |
{
|
|
| 161 | 4 |
ApplicationXml applicationXml = theEar.getApplicationXml(); |
| 162 | 4 |
for (Iterator i = applicationXml.getWebModuleUris(); i.hasNext();)
|
| 163 |
{
|
|
| 164 | 3 |
String webUri = (String) i.next(); |
| 165 | 3 |
WarArchive war = theEar.getWebModule(webUri); |
| 166 | 3 |
if ((war != null) |
| 167 |
&& (WarParser.parseServletRedirectorMapping(war) != null))
|
|
| 168 |
{
|
|
| 169 | 2 |
return webUri;
|
| 170 |
} |
|
| 171 |
} |
|
| 172 | 2 |
return null; |
| 173 |
} |
|
| 174 |
} |
|
| 175 |
|
|
||||||||||