cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r439768 - in /cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer: ./ monolithic/ utils/
Date Sun, 03 Sep 2006 12:42:02 GMT
Author: lgawron
Date: Sun Sep  3 05:42:02 2006
New Revision: 439768

URL: http://svn.apache.org/viewvc?rev=439768&view=rev
Log:
refactoring
using buildWebappDirectory and deleting WEB-INF/classes afterwards instead of plugin's own
copying logic
shrink and refactor FileUtils (duplicated features)

Modified:
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployWarMojo.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicServer22.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/FileUtils.java

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
Sun Sep  3 05:42:02 2006
@@ -175,18 +175,14 @@
      * features that the blocks-fw offers.
      */
     protected void deployMonolithicCocoonAppAsWebapp(final String blocksdir) throws MojoExecutionException
{
-        File webappDirectory_ = getWebappDirectory();
-
-        // build the web application
-        this.buildExplodedWebapp(webappDirectory_);
+        this.buildExplodedWebapp(getWebappDirectory());
         MonolithicCocoonDeployer deployer = new MonolithicCocoonDeployer(this.getLog());
-        deployer.deploy(getBlockArtifactsAsMap(null), webappDirectory_, blocksdir, new DevelopmentBlock[0],
-                new DevelopmentProperty[0]);
+        deployer.deploy(getBlockArtifactsAsMap(null), getWebappDirectory(), blocksdir);
 
         // make sure that all configuration files available in the webapp
         // override block configuration files
         try {
-            copyResources(getWarSourceDirectory(), webappDirectory_, getWebXml());
+            copyResources(getWarSourceDirectory(), getWebappDirectory(), getWebXml());
         } catch (IOException e) {
             throw new MojoExecutionException("A problem occurred while copying webapp resources.",
e);
         }
@@ -204,10 +200,14 @@
      */
     protected void blockDeploymentMonolithicCocoon(final String blocksdir, final DevelopmentBlock[]
blocks,
             final DevelopmentProperty[] properties) throws MojoExecutionException {
-        File webappDirectory_ = getWebappDirectory();
-
-        File webinfDir = new File(webappDirectory_, WEB_INF);
-        webinfDir.mkdirs();
+        this.buildExplodedWebapp(getWebappDirectory());
+        // remove WEB-INF/classes as they are loaded by ReloadingClassloader
+        // from a dirrerent location
+        try {
+            FileUtils.deleteDirectory(new File(webappDirectory, "WEB-INF/classes"));
+        } catch (IOException e) {
+            throw new MojoExecutionException("unable to delete WEB-INF/classes directory",
e);
+        }
 
         // add current block to the development blocks
         // it is important that the current block is put at the end of the array
@@ -226,9 +226,7 @@
 
         // deploy all blocks
         MonolithicCocoonDeployer deployer = new MonolithicCocoonDeployer(this.getLog());
-        deployer.deploy(getBlockArtifactsAsMap(blocks), webappDirectory_, blocksdir, extBlocks,
properties);
-
-        copyLibs();
+        deployer.deploy(getBlockArtifactsAsMap(blocks), getWebappDirectory(), blocksdir,
extBlocks, properties);
 
         if (useShieldingClassloader)
             shieldCocoonWebapp();
@@ -323,8 +321,8 @@
             getLog().debug("no web.xml in source location. checking for generated web.xml
in target location.");
             if (!new File(targetWebXmlLocation).exists()) {
                 this.getLog().info("No web.xml supplied. Will install default web.xml");
-                File outFile = org.apache.cocoon.maven.deployer.utils.FileUtils.createDirectory(new
File(
-                        webappDirectory_, webInfSlashWebXml));
+                File outFile = org.apache.cocoon.maven.deployer.utils.FileUtils.createPath(new
File(webappDirectory_,
+                        webInfSlashWebXml));
 
                 try {
                     CopyUtils.copy(readResourceFromClassloader("WEB-INF/web.xml"), new FileOutputStream(outFile));
@@ -352,18 +350,22 @@
 
         WebApplicationRewriter.rewrite(webAppDoc);
         this.getLog().debug("Writing web.xml: " + targetWebXmlLocation);
-        
+
         try {
             XMLUtils.write(webAppDoc, new FileOutputStream(targetWebXmlLocation));
         } catch (Exception e) {
             throw new MojoExecutionException("Unable to write web.xml to " + targetWebXmlLocation,
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);
+            try {
+                this.move(webInfDir, "lib", COCOON_LIB);
+                this.move(webInfDir, "classes", COCOON_CLASSES);
+            } catch (IOException e) {
+                throw new MojoExecutionException("unable to shield classes/libs", e);
+            }
         }
     }
 
@@ -372,42 +374,14 @@
                 "org/apache/cocoon/maven/deployer/monolithic/" + fileName);
     }
 
-    /**
-     * Copy all libs that don't have the scope provided or system to
-     * WEB-INF/cocoon/lib, except cocoon-bootstrap, which is copied to
-     * WEB-INF/lib
-     */
-    private void copyLibs() throws MojoExecutionException {
-        File webappDirectory_ = this.getWebappDirectory();
-        for (Iterator iter = this.getProject().getArtifacts().iterator(); iter.hasNext();)
{
-            Artifact artifact = (Artifact) iter.next();
-            // Include runtime and compile time libraries
-            if (!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
-                    && !Artifact.SCOPE_TEST.equals(artifact.getScope())
-                    && !Artifact.SCOPE_SYSTEM.equals(artifact.getScope()) &&
"jar".equals(artifact.getType())) {
-                try {
-                    FileUtils.copyFileToDirectory(artifact.getFile(), new File(webappDirectory_,
"WEB-INF/lib"));
-                    this.getLog().info("Deploying artifact to WEB-INF/lib/" + artifact.getFile().getName());
-                } catch (IOException e) {
-                    throw new MojoExecutionException("Can't copy artifact '" + artifact.getArtifactId()
-                            + "' to WEB-INF/" + COCOON_LIB);
-                }
-            }
-        }
-    }
-
-    /**
-     * Move all libs from one directory (WEB-INF/lib) to another
-     * (WEB-INF/cocoon/lib).
-     */
-    private void move(String parentDir, String srcDir, String destDir) {
+    private void move(String parentDir, String srcDir, String destDir) throws IOException
{
         final File srcDirectory = new File(parentDir, srcDir);
         if (srcDirectory.exists() && srcDirectory.isDirectory()) {
             File destDirectory = new File(parentDir, destDir);
             if (this.getLog().isDebugEnabled()) {
                 this.getLog().debug("Deleting directory " + destDirectory);
             }
-            org.apache.cocoon.maven.deployer.utils.FileUtils.deleteDirRecursivly(destDirectory);
+            FileUtils.deleteDirectory(destDirectory);
             destDirectory = new File(parentDir, destDir);
             if (this.getLog().isDebugEnabled()) {
                 this.getLog().debug("Recreating directory " + destDirectory);

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployWarMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployWarMojo.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployWarMojo.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployWarMojo.java
Sun Sep  3 05:42:02 2006
@@ -38,88 +38,77 @@
  */
 public class DeployWarMojo extends AbstractDeployMojo {
 
-    /** 
-     * @parameter expression="${blocksDirectory}" default-value="blocks"  
+    /**
+     * @parameter expression="${blocksDirectory}" default-value="blocks"
      */
-    private String blocksdir;       
-    
-	/**
-	 * The directory for the generated WAR.
-	 * 
-	 * @parameter expression="${project.build.directory}"
-	 * @required
-	 */
-	private String outputDirectory;
-
-	/**
-	 * The name of the generated war.
-	 * 
-	 * @parameter expression="${project.build.finalName}"
-	 * @required
-	 */
-	private String warName;
-
-	/**
-	 * The Jar archiver.
-	 * 
-	 * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#war}"
-	 * @required
-	 */
-	private WarArchiver warArchiver;
-
-	/**
-	 * The maven archive configuration to use.
-	 * 
-	 * @parameter
-	 */
-	private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+    private String blocksdir;
 
-	public void execute() throws MojoExecutionException {
+    /**
+     * The directory for the generated WAR.
+     * 
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    private String outputDirectory;
 
-		File warFile = new File(outputDirectory, warName + ".war");
-		
-        this.deployMonolithicCocoonAppAsWebapp(this.blocksdir);
-        
-		try {
-			performPackaging(warFile);
-		} catch (Exception e) {
-			// TODO: improve error handling
-			throw new MojoExecutionException("Error assembling WAR", e);
-		}
-
-	}
-
-	/**
-	 * Generates the webapp according to the <tt>mode</tt> attribute.
-	 * 
-	 * @param warFile
-	 *            the target war file
-	 * @throws IOException
-	 * @throws ArchiverException
-	 * @throws ManifestException
-	 * @throws DependencyResolutionRequiredException
-	 */
-	private void performPackaging(File warFile) throws IOException,
-			ArchiverException, ManifestException,
-			DependencyResolutionRequiredException, MojoExecutionException {
-		getLog().info("Generating war " + warFile.getAbsolutePath());
-
-		MavenArchiver archiver = new MavenArchiver();
-
-		archiver.setArchiver(warArchiver);
-
-		archiver.setOutputFile(warFile);
-
-		warArchiver.addDirectory(getWebappDirectory(), getIncludes(),
-				getExcludes());
+    /**
+     * The name of the generated war.
+     * 
+     * @parameter expression="${project.build.finalName}"
+     * @required
+     */
+    private String warName;
+
+    /**
+     * The Jar archiver.
+     * 
+     * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#war}"
+     * @required
+     */
+    private WarArchiver warArchiver;
 
-		warArchiver
-				.setWebxml(new File(getWebappDirectory(), "WEB-INF/web.xml"));
+    /**
+     * The maven archive configuration to use.
+     * 
+     * @parameter
+     */
+    private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
 
-		// create archive
-		archiver.createArchive(getProject(), archive);
+    public void execute() throws MojoExecutionException {
+        File warFile = new File(outputDirectory, warName + ".war");
+        this.deployMonolithicCocoonAppAsWebapp(this.blocksdir);
 
-		getProject().getArtifact().setFile(warFile);
-	}
+        try {
+            performPackaging(warFile);
+        } catch (Exception e) {
+            // TODO: improve error handling
+            throw new MojoExecutionException("Error assembling WAR", e);
+        }
+    }
+
+    /**
+     * Generates the webapp according to the <tt>mode</tt> attribute.
+     * 
+     * @param warFile
+     *            the target war file
+     * @throws IOException
+     * @throws ArchiverException
+     * @throws ManifestException
+     * @throws DependencyResolutionRequiredException
+     */
+    private void performPackaging(File warFile) throws IOException, ArchiverException, ManifestException,
+            DependencyResolutionRequiredException, MojoExecutionException {
+        getLog().info("Generating war " + warFile.getAbsolutePath());
+
+        MavenArchiver archiver = new MavenArchiver();
+        archiver.setArchiver(warArchiver);
+        archiver.setOutputFile(warFile);
+        warArchiver.addDirectory(getWebappDirectory(), getIncludes(), getExcludes());
+        warArchiver.setWebxml(new File(getWebappDirectory(), "WEB-INF/web.xml"));
+
+        // create archive
+        archiver.createArchive(getProject(), archive);
+        getProject().getArtifact().setFile(warFile);
+    }
 
 }

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
Sun Sep  3 05:42:02 2006
@@ -50,6 +50,11 @@
         this.logger = logger;
     }
 
+    public void deploy(final Map libraries, final File basedir, final String blocksdir)
+            throws DeploymentException {
+        deploy(libraries, basedir, blocksdir, new DevelopmentBlock[0], new DevelopmentProperty[0]);
+    }
+    
     public void deploy(final Map libraries, final File basedir, final String blocksdir,
             final DevelopmentBlock[] developmentBlocks, DevelopmentProperty[] developmentProperties)
             throws DeploymentException {
@@ -148,7 +153,8 @@
     private void writeProperties(final File basedir, final String propertiesFile, final Properties
properties) {
         try {
             File outFile = new File(basedir, propertiesFile);
-            properties.store(new FileOutputStream(FileUtils.createDirectory(outFile)), null);
+            //TODO close stream!
+            properties.store(new FileOutputStream(FileUtils.createPath(outFile)), null);
             this.logger.info("Deploying dev properties to " + propertiesFile);
         } catch (IOException e) {
             throw new DeploymentException("Can't save properties to " + propertiesFile, e);
@@ -157,7 +163,7 @@
 
     private void copyFile(final File basedir, final String fileName) {
         try {
-            File outFile = FileUtils.createDirectory(new File(basedir, fileName));
+            File outFile = FileUtils.createPath(new File(basedir, fileName));
             CopyUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
             this.logger.info("Deploying resource file to " + fileName);
         } catch (FileNotFoundException e) {
@@ -170,7 +176,8 @@
     private void writeStringTemplateToFile(final File basedir, final String fileName, final
Map templateObjects) {
         FileOutputStream fos = null;
         try {
-            File outFile = FileUtils.createDirectory(new File(basedir, fileName));
+            File outFile = FileUtils.createPath(new File(basedir, fileName));
+            // TODO buffered stream!
             fos = new FileOutputStream(outFile);
             InputStream fileIs = readResourceFromClassloader(fileName);
             StringTemplate stringTemplate = new StringTemplate(IOUtils.toString(fileIs));

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicServer22.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicServer22.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicServer22.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicServer22.java
Sun Sep  3 05:42:02 2006
@@ -30,6 +30,7 @@
 import java.util.zip.ZipInputStream;
 
 import org.apache.cocoon.maven.deployer.utils.WildcardHelper;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.Validate;
 import org.apache.maven.plugin.logging.Log;
 
@@ -41,7 +42,6 @@
  * @version $Id$
  */
 public class MonolithicServer22 {
-
 	private Log logger;
 	private File basedir;
 	private List rules = new ArrayList();
@@ -82,10 +82,7 @@
                         }
 
                         out = new BufferedOutputStream(fileDeployer.writeResource(document.getName()));
-                        byte[] buffer = new byte[8192];
-                        int length;
-                        while ((length = zipStream.read(buffer)) > 0)
-                            out.write(buffer, 0, length);
+                        IOUtils.copy(zipStream, out);
                     } finally {
                         if (out != null) {
                             out.close();

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/SingleFileDeployer.java
Sun Sep  3 05:42:02 2006
@@ -94,17 +94,15 @@
             outputDocumentName = this.getFileName(documentName);
         }
 
-        File targetFile = FileUtils.createDirectory(new File(outDir, outputDocumentName));
-
+        File targetFile = FileUtils.createPath(new File(outDir, outputDocumentName));
         if (this.alreadyDeployedFilesSet.contains(targetFile.getCanonicalFile())) {
             throw new FileAlreadyDeployedException("File '" + targetFile + "' already exists!");
         }
 
         this.alreadyDeployedFilesSet.add(targetFile.getCanonicalFile());
-
         this.logger.debug("Deploying block resource to " + getOutputDir() + "/" + outputDocumentName);
 
-        return new FileOutputStream(FileUtils.createDirectory(targetFile));
+        return new FileOutputStream(FileUtils.createPath(targetFile));
     }
 
     protected String removeRootDirectory(final String documentName) {

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
Sun Sep  3 05:42:02 2006
@@ -77,7 +77,7 @@
         }
         try {
             getLogger().info("Applying patches to: " + fileName);
-            File outFile = FileUtils.createDirectory(new File(getBasedir(), fileName));
+            File outFile = FileUtils.createPath(new File(getBasedir(), fileName));
             Document original = XMLUtils.parseXml(source);
 
             Iterator it = patches.iterator();

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/FileUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/FileUtils.java?rev=439768&r1=439767&r2=439768&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/FileUtils.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/FileUtils.java
Sun Sep  3 05:42:02 2006
@@ -16,9 +16,6 @@
 package org.apache.cocoon.maven.deployer.utils;
 
 import java.io.File;
-import java.io.IOException;
-
-import org.apache.cocoon.maven.deployer.monolithic.DeploymentException;
 
 /**
  * Utitily class to handle ZIP archives.
@@ -26,47 +23,13 @@
  * @version $Id$
  */
 public class FileUtils {
-
-	/**
-	 * Delete a directory recursivly
-	 * @param directory
-	 * @return true if deletation went okay
-	 */
-    public static boolean deleteDirRecursivly(File directory) {
-        if (directory.isDirectory()) {
-            String[] children = directory.list();
-            for (int i=0; i < children.length; i++) {
-                boolean success = deleteDirRecursivly(new File(directory, children[i]));
-                if (!success) {
-                    return false;
-                }
-            }
-        }
-        return directory.delete();
-    }	
-
 	/**
-	 * Create the directories of a non-exisiting file.
+	 * Prepare directory structure for non-existing file
 	 */
-	public static File createDirectory(File file) {
-		if(file.isDirectory() || file.exists()) {
-			return file;
-		}
-		String absolutePath;
-        try {
-            absolutePath = file.getCanonicalPath();
-        } catch (IOException e) {
-            throw new DeploymentException("A problem occured while reading the canonical
path of '" + file.getAbsolutePath() + "'");
-        }
-		String absolutePathDir = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
-		File absolutePathDirFile = new File(absolutePathDir);
-		if(absolutePathDirFile.exists()) {
-			return file;
-		}
-		if(!new File(absolutePathDir).mkdirs()) {
-			throw new DeploymentException("Can't create directory '" + absolutePathDir + "'");
-		}
-		return file;
+	public static File createPath(File file) {
+        if ( file.getParentFile() != null && !file.getParentFile().exists())
+            file.getParentFile().mkdirs();
+        return file;
 	}
 
 



Mime
View raw message