Skip to content

Commit

Permalink
fix problems with sitemap mounts of blocks; refactor AbstractDeployMo…
Browse files Browse the repository at this point in the history
…jo: move web.xml rewritting code into a method

git-svn-id: https://svn.apache.org/repos/asf/cocoon/trunk/tools@418080 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
reinhard committed Jun 29, 2006
1 parent 5fde214 commit ad70ad8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 49 deletions.
Expand Up @@ -179,52 +179,9 @@ protected void deployMonolithicCocoonAppAsWebapp(final String blocksdir) throws

// take care of paranoid classloading
if ( this.useShieldingClassloader ) {
String webXmlLocation = this.getWebXml();
if ( webXmlLocation == null ) {
webXmlLocation = getWarSourceDirectory().getAbsolutePath() + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml";
}
this.getLog().info("Adding shielded classloader configuration to webapp configuration.");
this.getLog().debug("Reading web.xml: " + webXmlLocation);
try {
final Document webAppDoc = XMLUtils.parseXml(new FileInputStream(new File(webXmlLocation)));
WebApplicationRewriter.rewrite(webAppDoc);
final String dest = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml";
this.getLog().debug("Writing web.xml: " + dest);
XMLUtils.write(webAppDoc, new FileOutputStream(dest));
} catch (Exception e) {
throw new MojoExecutionException("Unable to read web.xml from " + webXmlLocation, e);
}
if ( this.useShieldingRepository ) {
this.getLog().info("Moving classes and libs to shielded location.");
final String webInfDir = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF";
this.move(webInfDir, "lib", "cocoon-lib");
this.move(webInfDir, "classes", "cocoon-classes");
}
}
}

protected void move(String parentDir, String srcDir, String destDir) {
final File srcDirectory = new File(parentDir, srcDir);
if ( srcDirectory.exists() && srcDirectory.isDirectory() ) {
File destDirectory = new File(parentDir, destDir);
destDirectory.delete();
destDirectory = new File(parentDir, destDir);
destDirectory.mkdir();
final File[] files = srcDirectory.listFiles();
if ( files != null && files.length > 0 ) {
for(int i=0; i<files.length; i++) {
// TODO - replace this hard-coded exlclude with something configurable
boolean exclude = false;
if ( "lib".equals(srcDir) && files[i].getName().startsWith("cocoon-bootstrap") ) {
exclude = true;
}
if ( !exclude ) {
files[i].renameTo(new File(destDirectory, files[i].getName()));
}
}
}
rewriteWebXml();
}
}
}

/**
* Deploy a particular block at development time.
Expand Down Expand Up @@ -296,4 +253,54 @@ private boolean containsArtifact(DevelopmentBlock[] blocks, String artifactId, S
return false;
}

// ~~~~~~~~~~ utility methods ~~~~~~~~~~~

private void rewriteWebXml() throws MojoExecutionException {
File webappDirectory_ = getWebappDirectory();
String webXmlLocation = this.getWebXml();
if ( webXmlLocation == null ) {
webXmlLocation = getWarSourceDirectory().getAbsolutePath() + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml";
}
this.getLog().info("Adding shielded classloader configuration to webapp configuration.");
this.getLog().debug("Reading web.xml: " + webXmlLocation);
try {
final Document webAppDoc = XMLUtils.parseXml(new FileInputStream(new File(webXmlLocation)));
WebApplicationRewriter.rewrite(webAppDoc);
final String dest = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml";
this.getLog().debug("Writing web.xml: " + dest);
XMLUtils.write(webAppDoc, new FileOutputStream(dest));
} catch (Exception e) {
throw new MojoExecutionException("Unable to read web.xml from " + webXmlLocation, e);
}
if ( this.useShieldingRepository ) {
this.getLog().info("Moving classes and libs to shielded location.");
final String webInfDir = webappDirectory_.getAbsolutePath() + File.separatorChar + "WEB-INF";
this.move(webInfDir, "lib", "cocoon-lib");
this.move(webInfDir, "classes", "cocoon-classes");
}
}

private void move(String parentDir, String srcDir, String destDir) {
final File srcDirectory = new File(parentDir, srcDir);
if ( srcDirectory.exists() && srcDirectory.isDirectory() ) {
File destDirectory = new File(parentDir, destDir);
destDirectory.delete();
destDirectory = new File(parentDir, destDir);
destDirectory.mkdir();
final File[] files = srcDirectory.listFiles();
if ( files != null && files.length > 0 ) {
for(int i=0; i<files.length; i++) {
// TODO - replace this hard-coded exlclude with something configurable
boolean exclude = false;
if ( "lib".equals(srcDir) && files[i].getName().startsWith("cocoon-bootstrap") ) {
exclude = true;
}
if ( !exclude ) {
files[i].renameTo(new File(destDirectory, files[i].getName()));
}
}
}
}
}

}
Expand Up @@ -79,6 +79,7 @@ public void deploy(final Map libraries, final File basedir, final String blocksd
writeStringTemplateToFile(basedir, "sitemap.xmap", templateObjects);
writeStringTemplateToFile(basedir, "WEB-INF/cocoon.xconf", templateObjects);

copyFile(basedir, "blocks/sitemap.xmap");
copyFile(basedir, "WEB-INF/log4j.xconf");
copyFile(basedir, "WEB-INF/web.xml");
copyFile(basedir, "WEB-INF/properties/core.properties");
Expand Down
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2006 The Apache Software Foundation
Licensed 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.
-->
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:pipelines>
<map:pipeline>
<map:match pattern="*/**">
<map:mount uri-prefix="{1}/" src="{1}/"/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
Expand Up @@ -26,15 +26,17 @@

<map:pipelines>
<map:pipeline>

$devblocks:{ devblock |
$if(devblock.cobInfPath)$
<map:match pattern="$devblock.artifactId$/**">
<map:mount uri-prefix="$devblock.artifactId$" src="$devblock.cobInfPath$"/>
<map:match pattern="blocks/$devblock.artifactId$/**">
<map:mount uri-prefix="blocks/$devblock.artifactId$" src="$devblock.cobInfPath$"/>
</map:match>
$endif$
}$

<map:match pattern="*/**">
<map:mount src="{1}/" uri-prefix="{1}"/>
</map:match>
</map:pipeline>

</map:pipelines>
</map:sitemap>

0 comments on commit ad70ad8

Please sign in to comment.