From: <jef...@us...> - 2002-08-12 04:16:39
|
Update of /cvsroot/aft/Anteater/src/org/apache/anteater/test In directory usw-pr-cvs1:/tmp/cvs-serv27479 Modified Files: Deploy.java Log Message: Resolve docbase relative to the project, and add some error checking for nonexistent files Index: Deploy.java =================================================================== RCS file: /cvsroot/aft/Anteater/src/org/apache/anteater/test/Deploy.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Deploy.java 10 Aug 2002 09:09:16 -0000 1.5 +++ Deploy.java 12 Aug 2002 04:16:36 -0000 1.6 @@ -15,7 +15,7 @@ public class Deploy extends BaseTask { protected String path; - protected String docBase; + protected File docBase; /** * Context path to map to the webapp. @@ -30,7 +30,7 @@ * Path to the directory containing the unpacked webapp, or to a war file. * Relative to the Ant basedir directory. */ - public void setWebapp(String docBase) + public void setWebapp(File docBase) { this.docBase = docBase; } @@ -38,10 +38,13 @@ public void execute() throws BuildException { - - if (docBase.endsWith(".war")) { + if (! docBase.exists()) { + throw new BuildException(getLocation()+" No webapp at '"+docBase.getPath()); + } + if (docBase.getName().endsWith(".war")) { + if ( !docBase.isFile() || !docBase.canRead() ) throw new BuildException("'"+docBase.getPath()+"' is not a readable file"); String fs = System.getProperty("file.separator"); - String warName = docBase.substring(0, docBase.lastIndexOf(".")); + String warName = docBase.getName().substring(0, docBase.getName().lastIndexOf(".")); int lastSlash = warName.lastIndexOf(fs)+1; if (lastSlash == -1) { lastSlash = 0; } warName = warName.substring( lastSlash ); @@ -50,18 +53,18 @@ tmpFile.delete(); tmpFile.mkdir(); tmpFile.deleteOnExit(); - File docFile = getProject().resolveFile(docBase); - println("Unpacking war file "+docFile.getPath()+" to "+tmpDir); + println("Unpacking war file "+docBase.getPath()+" to "+tmpDir); try { - JarUtil.unjar( docFile, tmpFile ); + JarUtil.unjar( docBase, tmpFile ); } catch (Exception e) { - throw new BuildException("Could not unpack war file '"+docFile.getAbsolutePath()+"'", e); + throw new BuildException("Could not unpack war file '"+docBase.getAbsolutePath()+"'", e); } - docBase = tmpDir; + docBase = tmpFile; } ServletContainer container = ServletContainer.getServletContainer(); - container.addContext(path, docBase, this); + System.out.println("Deploying "+docBase.getPath()+" to "+path); + container.addContext(path, docBase.getPath(), this); } private void unpackWar( File warFile, File tmpDir ) { |