cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r376592 - in /cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src: main/java/org/apache/cocoon/deployer/ main/java/org/apache/cocoon/deployer/applicationserver/ main/java/org/apache/cocoon/deployer/block/ main/java/org/apache/cocoon...
Date Fri, 10 Feb 2006 08:38:26 GMT
Author: reinhard
Date: Fri Feb 10 00:38:19 2006
New Revision: 376592

URL: http://svn.apache.org/viewcvs?rev=376592&view=rev
Log:
COCOON-1759

The deployer now supports relative locations and translates
them at deployment into paths that are relative to the Cocoon
install directory

 - added a second block type: LocalBlock
   This type only has a location and at deployment the 
   deployer does not installit
 - relative path calculation is covered by unit tests

Note: The block-fw needs some changes as it currently resolves all
block locations relative to the servlet context and if a
block is outside this results in an exception as 
servletContext.resolve("../foo") returns null

Added:
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/LocalBlock.java
      - copied, changed from r375302, cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/DevelopmentBlock.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/impl/LocalBlock10.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-06/
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-06/deploy.xml
Removed:
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/DevelopmentBlock.java
Modified:
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/BlockDeployer.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/applicationserver/CocoonServer22.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BinaryBlock.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/Block.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BlockFactory.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/util/ZipUtils.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/BlockDeployerTest.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/block/BlockFactoryTest.java
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-04/deploy.xml

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/BlockDeployer.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/BlockDeployer.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/BlockDeployer.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/BlockDeployer.java
Fri Feb 10 00:38:19 2006
@@ -82,9 +82,12 @@
 			String blockUrn = installBlock.getUrn();
 			File blockArchive = null;
 			if(installBlock.getLocation() == null) {
-				blockArchive = this.artifactProvider.getArtifact(blockUrn);				
+				blockArchive = this.artifactProvider.getArtifact(blockUrn);			
+				blockList.add(BlockFactory.createBinaryBlock(blockArchive, installBlock));				
+			} else {
+				blockList.add(BlockFactory.createLocalBlock(installBlock, 
+				    deploymentDescriptor.getCocoon().getTargetUrl()));
 			}
-			blockList.add(BlockFactory.createBinaryBlock(blockArchive, installBlock));
 		}
 		
 		// auto-wiring: if a connection is not specified, use the default implementation and

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/applicationserver/CocoonServer22.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/applicationserver/CocoonServer22.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/applicationserver/CocoonServer22.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/applicationserver/CocoonServer22.java
Fri Feb 10 00:38:19 2006
@@ -19,7 +19,6 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -36,6 +35,7 @@
 import org.apache.cocoon.deployer.DeploymentException;
 import org.apache.cocoon.deployer.block.BinaryBlock;
 import org.apache.cocoon.deployer.block.Block;
+import org.apache.cocoon.deployer.block.LocalBlock;
 import org.apache.cocoon.deployer.generated.block.x10.Property;
 import org.apache.cocoon.deployer.generated.wiring.x10.Mount;
 import org.apache.cocoon.deployer.generated.wiring.x10.Wiring;
@@ -141,6 +141,10 @@
 					} else {
 						wiringBlock.setLocation((String) installedBlocks.get(block.getId()));
 					}
+				} 
+				else if(block instanceof LocalBlock) {
+					LocalBlock localBlock = (LocalBlock) block;
+					wiringBlock.setLocation(localBlock.getBaseDirectory());
 				}
 				wiring.addBlock(wiringBlock);
 			}
@@ -152,9 +156,8 @@
 				
 				// check if a library is a block, if yes, don't add it to WEB_INF_LIBS_DIR
 				boolean isBlock = true;
-				InputStream blockIs = null;
 				try {
-					blockIs = ZipUtils.getBlockDescriptorIs(lib);
+					ZipUtils.getBlockDescriptorIs(lib);
 				} catch(FileNotFoundException fnfe) {
 					isBlock = false;
 				}

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BinaryBlock.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BinaryBlock.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BinaryBlock.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BinaryBlock.java
Fri Feb 10 00:38:19 2006
@@ -24,8 +24,6 @@
  */
 public interface BinaryBlock extends Block {
 	
-	String BLOCK_DESCRIPTOR_LOCATION = "META-INF/block.xml";
-
 	/**
 	 * @return the InputStream to get access to the blocks binaries
 	 */

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/Block.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/Block.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/Block.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/Block.java
Fri Feb 10 00:38:19 2006
@@ -22,6 +22,7 @@
 public interface Block {
 
 	public static final String BLOCK_NS_10 = "http://apache.org/cocoon/blocks/cob/1.0";
+	String BLOCK_DESCRIPTOR_LOCATION = "META-INF/block.xml";
 	
 	/**
 	 * @return the block namespace

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BlockFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BlockFactory.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BlockFactory.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/BlockFactory.java
Fri Feb 10 00:38:19 2006
@@ -18,11 +18,14 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.StringTokenizer;
 
 import org.apache.cocoon.deployer.DeploymentException;
 import org.apache.cocoon.deployer.block.impl.Block10;
+import org.apache.cocoon.deployer.block.impl.LocalBlock10;
 import org.apache.cocoon.deployer.generated.block.x10.Block;
 import org.apache.cocoon.deployer.util.XMLUtils;
 import org.apache.cocoon.deployer.util.ZipUtils;
@@ -50,10 +53,12 @@
 			Unmarshaller unmarshaller = new Unmarshaller(Block.class);
 			// unmarshaller.setDebug(true);
 			blockDescriptor = (Block) unmarshaller.unmarshal(new InputStreamReader(ZipUtils.getBlockDescriptorIs(blockArchive)));
+			
 			block.setBlockDescriptor(blockDescriptor);
 			block.setInputStream(new FileInputStream(blockArchive));
 			block.setNameSpace(XMLUtils.getDocumentNamespace(ZipUtils.getBlockDescriptorIs(blockArchive)));
 			block.setId(blockDescriptor.getId());
+		
 		} catch (FileNotFoundException e) {
 			throw new DeploymentException("The block archive file can't be found.");
 		} catch (IOException e) {
@@ -79,6 +84,103 @@
 		deployBlock.setUrn(block.getBlockDescriptor().getId());
 		
 		return block;
+	}
+
+	public static LocalBlock createLocalBlock(org.apache.cocoon.deployer.generated.deploy.x10.Block
installBlock, 
+			String cocoonTargetUrl) {
+		
+		Validate.notNull(installBlock, "You have to pass a block deployment configuration.");	
+		
+		LocalBlock10 localBlock = new LocalBlock10();
+		localBlock.setDeployDescriptor(installBlock);
+		
+		// get and set the descriptor
+		Block blockDescriptor = null;
+		
+		try {
+			String location = installBlock.getLocation();
+			Validate.notNull(location, "The location (attribute 'location' of the element 'block')
of the block mustn't be null");
+			
+			File blockDescriptorFile = new File(location + File.separator + 
+			    org.apache.cocoon.deployer.block.Block.BLOCK_DESCRIPTOR_LOCATION);
+			
+			System.out.println("blockDescriptorFile: " + blockDescriptorFile.getAbsolutePath());
+			
+			if(!blockDescriptorFile.exists()) {
+			    throw new DeploymentException("The block descriptor file can't be found: " + 
+			        blockDescriptorFile.getAbsolutePath());
+			}
+			
+			Unmarshaller unmarshaller = new Unmarshaller(Block.class);
+			// unmarshaller.setDebug(true);			
+			blockDescriptor = (Block) unmarshaller.unmarshal(new FileReader(blockDescriptorFile));
+			
+			localBlock.setBlockDescriptor(blockDescriptor);
+			localBlock.setId(blockDescriptor.getId());
+			localBlock.setNameSpace(XMLUtils.getDocumentNamespace(new FileInputStream(blockDescriptorFile)));
+			
+			// calculate the location relative to the server root directory in the case that the
+			// location is relative itself
+			String blockPath = new File(location).getCanonicalPath();
+			String cocoonPath = new File(cocoonTargetUrl).getCanonicalPath();
+			localBlock.setBaseDirectory(createRelativeLocation(cocoonPath, blockPath));
+
+		} catch (MarshalException e) {
+			throw new DeploymentException("The block descriptor can't be read correctly.");
+		} catch (ValidationException e) {
+			throw new DeploymentException("The block descriptor can't be read correctly because of
validation problems (XML schema).");
+		} catch (FileNotFoundException e) {
+			throw new DeploymentException("The block descriptor file can't be found.");
+		} catch (SAXException e) {
+			throw new DeploymentException("The block descriptor can't be read correctly.");
+		} catch (IOException e) {
+			throw new DeploymentException("The block descriptor can't be read correctly.");
+		}		
+
+		return localBlock;
+	}
+	
+	protected static String createRelativeLocation(final String cocoonLocation, final String
blockLocation) {
+
+		String cleanedCocoonLocation = cocoonLocation.replaceAll("\\\\", "/");
+		String cleanedBlockLocation = blockLocation.replaceAll("\\\\", "/");		
+		String commonBaseDir = "";
+		
+		for(int i = 0; i < cleanedBlockLocation.length(); i++) {
+			String reducedBlockLocation = cleanedBlockLocation.substring(0, cleanedBlockLocation.length()
- i);
+			if(cleanedCocoonLocation.indexOf(reducedBlockLocation) > -1) {
+				commonBaseDir = reducedBlockLocation.substring(0, reducedBlockLocation.lastIndexOf("/")
+ 1);
+				break;
+			}
+		}
+		
+		String relativeCocoonLocation = cleanedCocoonLocation.substring(commonBaseDir.length());
+		relativeCocoonLocation = relativeCocoonLocation.endsWith("/") ? relativeCocoonLocation
: relativeCocoonLocation + "/";
+		
+		String relativeBlockLocation = cleanedBlockLocation.substring(commonBaseDir.length());
+		relativeBlockLocation = relativeBlockLocation.endsWith("/") ? relativeBlockLocation : relativeBlockLocation
+ "/";
+		
+		// if there is no common basedir, the relativeBlockLocation has to be absolute
+		if(commonBaseDir.equals("")) {
+			return relativeBlockLocation;
+		}
+		return relativizePath(relativeCocoonLocation) + relativeBlockLocation;
+	}
+	
+	/**
+	 * Use it to get ../../ out of e.g. x/y/
+	 * 
+	 * @param path The path to be relativized
+	 * @return the relativzed path
+	 */
+	protected static String relativizePath(final String path) {
+		StringTokenizer tokenizer = new StringTokenizer(path, "/");
+		StringBuffer relativizedPathSb = new StringBuffer();
+		while(tokenizer.hasMoreElements()) {
+			tokenizer.nextElement();
+			relativizedPathSb.append("../");
+		}
+		return relativizedPathSb.toString();
 	}
 	
 }

Copied: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/LocalBlock.java
(from r375302, cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/DevelopmentBlock.java)
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/LocalBlock.java?p2=cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/LocalBlock.java&p1=cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/DevelopmentBlock.java&r1=375302&r2=376592&rev=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/DevelopmentBlock.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/LocalBlock.java
Fri Feb 10 00:38:19 2006
@@ -15,28 +15,15 @@
  */
 package org.apache.cocoon.deployer.block;
 
-import java.io.File;
-
-
 /**
  * A block that is under development and available from within the filesystem
  * of the server it is deployed to.
  */
-public interface DevelopmentBlock extends Block {
+public interface LocalBlock extends Block {
 
 	/**
 	 * @return the root directory of the block
 	 */
-	public File getRootDirectory();
-	
-	/**
-	 * @return the root sitemap of the block
-	 */
-	public File getSitemap();
-	
-	/**
-	 * @return the directory where all Java classes are compiled to
-	 */
-	public File getClassesDirectory();
+	public String getBaseDirectory();
 	
 }

Added: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/impl/LocalBlock10.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/impl/LocalBlock10.java?rev=376592&view=auto
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/impl/LocalBlock10.java
(added)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/block/impl/LocalBlock10.java
Fri Feb 10 00:38:19 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 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.
+ */
+/**
+ * 
+ */
+package org.apache.cocoon.deployer.block.impl;
+
+import org.apache.cocoon.deployer.block.LocalBlock;
+import org.apache.cocoon.deployer.generated.block.x10.Block;
+
+public class LocalBlock10 implements LocalBlock {
+
+	private String id;
+	private String namespace;
+	private String baseDirectory;
+	private Block blockDescriptor;
+	private org.apache.cocoon.deployer.generated.deploy.x10.Block deployDescriptor;
+	
+	public void setNameSpace(String namespace) {
+		this.namespace = namespace;
+	}
+	
+	public String getNamespace() {
+		return this.namespace;
+	}
+
+	public void setBlockDescriptor(Block blockDescriptor) {
+		this.blockDescriptor = blockDescriptor;
+	}
+	
+	public Block getBlockDescriptor() {
+		return this.blockDescriptor;
+	}
+
+	public void setDeployDescriptor(org.apache.cocoon.deployer.generated.deploy.x10.Block deployDescriptor)
{
+		this.deployDescriptor = deployDescriptor;
+	}
+	
+	public org.apache.cocoon.deployer.generated.deploy.x10.Block getDeployDescriptor() {
+		return this.deployDescriptor;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+	
+	public String getId() {
+		return this.id;
+	}
+
+	public void setBaseDirectory(String baseDirectory) {
+		this.baseDirectory = baseDirectory;
+	}
+	
+	public String getBaseDirectory() {
+		return baseDirectory;
+	}
+
+}

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/util/ZipUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/util/ZipUtils.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/util/ZipUtils.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/main/java/org/apache/cocoon/deployer/util/ZipUtils.java
Fri Feb 10 00:38:19 2006
@@ -26,7 +26,7 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
-import org.apache.cocoon.deployer.block.BinaryBlock;
+import org.apache.cocoon.deployer.block.Block;
 import org.apache.commons.transaction.file.FileResourceManager;
 import org.apache.commons.transaction.file.ResourceManagerException;
 
@@ -51,7 +51,7 @@
 	    do {
 	        document = blockStream.getNextEntry();
 	        if (document != null) {
-	            if (document.getName().equals(BinaryBlock.BLOCK_DESCRIPTOR_LOCATION)) {
+	            if (document.getName().equals(Block.BLOCK_DESCRIPTOR_LOCATION)) {
 	                found = true;
 	            } else {
 	                // go to next entry
@@ -61,7 +61,7 @@
 	    } while (document != null && found == false);        
 	    
 	    if(found == false) {
-	        String debugMsg = "The ZIP file doesn't contain " + BinaryBlock.BLOCK_DESCRIPTOR_LOCATION;
+	        String debugMsg = "The ZIP file doesn't contain " + Block.BLOCK_DESCRIPTOR_LOCATION;
 	        throw new FileNotFoundException(debugMsg);
 	    }
 	    

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/BlockDeployerTest.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/BlockDeployerTest.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/BlockDeployerTest.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/BlockDeployerTest.java
Fri Feb 10 00:38:19 2006
@@ -60,6 +60,15 @@
 		aProviderCtrl.setReturnValue(this.getMockArtefact("validBlock-06/valid-block-1.0.jar"));
	
 		
 		aProvider.getArtifact("anyblock:anyblock-07:1.0");
+		aProviderCtrl.setReturnValue(this.getMockArtefact("validBlock-07/valid-block-1.0.jar"));
	
+		
+		aProvider.getArtifact("anyblock:anyblock-05:1.0");
+		aProviderCtrl.setReturnValue(this.getMockArtefact("validBlock-05/valid-block-1.0.jar"));
+		
+		aProvider.getArtifact("anyblock:anyblock-06:1.0");
+		aProviderCtrl.setReturnValue(this.getMockArtefact("validBlock-06/valid-block-1.0.jar"));
	
+		
+		aProvider.getArtifact("anyblock:anyblock-07:1.0");
 		aProviderCtrl.setReturnValue(this.getMockArtefact("validBlock-07/valid-block-1.0.jar"));
		
 		
 		aProvider.getArtifact((String[]) null);

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/block/BlockFactoryTest.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/block/BlockFactoryTest.java?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/block/BlockFactoryTest.java
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/java/org/apache/cocoon/deployer/block/BlockFactoryTest.java
Fri Feb 10 00:38:19 2006
@@ -23,6 +23,7 @@
 	
 	private static final String VALID_BLOCK_01_JAR = "validBlock-01/valid-block-1.0.jar";
 	private static final String VALID_DEPLOY_01 = "validDeploy-01/deploy.xml";
+	private static final String VALID_DEPLOY_06 = "validDeploy-06/deploy.xml";;
 
 	/**
 	 * Test if the passed block is a file and not a directory
@@ -67,7 +68,7 @@
 		
 	}
 	
-	public void testBlockCreation() throws Exception {
+	public void testBinaryBlockCreation() throws Exception {
 		File blockAsFile = this.getMockArtefact(VALID_BLOCK_01_JAR);
 		BinaryBlock block = BlockFactory.createBinaryBlock(blockAsFile, this.getDeploy(VALID_DEPLOY_01).getBlock(0));
 		assertNotNull(block);
@@ -81,4 +82,49 @@
 		assertEquals("http://cocoon.apache.org/blocks/anyblock/1.0", block.getId());
 	}
 
+	public void testLocalBlockCreation() throws Exception {
+		LocalBlock block = BlockFactory.createLocalBlock(this.getDeploy(VALID_DEPLOY_06).getBlock(0),
".");
+		assertNotNull(block);
+		assertNotNull(block.getBlockDescriptor());
+		assertEquals( Block.BLOCK_NS_10, block.getNamespace());
+		assertEquals("anyblock:anyblock-06:1.0", block.getId());	
+		assertTrue(new File(block.getBaseDirectory()).exists());
+	}
+	
+	
+	// -------------- test the algorithm that gets calculates the local path
+	
+	public void testRelativeDirectoryCreationAlgForSameDriverWin() {
+		String relDir = BlockFactory.createRelativeLocation("C:\\test\\ax\\server", "C:\\test\\ay\\blockRoot");
+		assertEquals("../../ay/blockRoot/", relDir);
+	}	
+	
+	public void testRelativeDirectoryCreationAlgForSameDriverWin1() {
+		String relDir = BlockFactory.createRelativeLocation("C:\\test\\ax\\server\\", "C:\\test\\ay\\blockRoot\\");
+		assertEquals("../../ay/blockRoot/", relDir);
+	}
+	
+	public void testRelativeDirectoryCreationAlgForSameDriveNix() {
+		String relDir = BlockFactory.createRelativeLocation("/home/test/ax/server", "/home/test/ay/blockRoot");
+		assertEquals("../../ay/blockRoot/", relDir);
+	}	
+	
+	public void testRelativeDirectoryCreationAlgForSameDriveNix1() {
+		String relDir = BlockFactory.createRelativeLocation("/home/test/ax/server/", "/home/test/ay/blockRoot/");
+		assertEquals("../../ay/blockRoot/", relDir);
+	}		
+	
+	public void testRelativeDirectoryCreationAlgForDifferent() {
+		String relDir = BlockFactory.createRelativeLocation("D:\\server\\", "C:\\test\\ay\\blockRoot\\");
+		assertEquals("C:/test/ay/blockRoot/", relDir);
+	}	
+	
+	// ---------------- test relatizing of a path
+	 
+	public void testPathRelativizing() {
+		String relPath = BlockFactory.relativizePath("blah/foo/bar/");
+		assertEquals("../../../", relPath);
+	}
+	
+	
 }

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-04/deploy.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-04/deploy.xml?rev=376592&r1=376591&r2=376592&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-04/deploy.xml
(original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-04/deploy.xml
Fri Feb 10 00:38:19 2006
@@ -30,4 +30,7 @@
   
   <block id="db" urn="validBlock-04:validBlock-04:1.0"/>  
   
+  <block id="db1" urn="validBlock-04:validBlock-04:1.0" 
+    location="src/test/mocks/validBlock-04/blockRoot"/>    
+  
 </deploy>

Added: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-06/deploy.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-06/deploy.xml?rev=376592&view=auto
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-06/deploy.xml
(added)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-core/src/test/mocks/validDeploy-06/deploy.xml
Fri Feb 10 00:38:19 2006
@@ -0,0 +1,24 @@
+<?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. 
+-->
+<deploy xmlns="http://apache.org/cocoon/blocks/deploy/1.0">
+  
+  <cocoon target-url=".target/test/validDeploy-02/myServer" 
+    urn="org.apache.cocoon:cocoon-minimal-webapp:1.0-SNAPSHOT:war" exclusive="true"/>
   
+  
+  <block id="db" urn="validBlock-04:validBlock-04:1.0" location="src/test/mocks/validBlock-06/blockRoot"/>
 
+  
+</deploy>
\ No newline at end of file



Mime
View raw message