cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r160843 - in cocoon/whiteboard/block-deployer: ./ src/api/org/apache/cocoon/blockdeployer/repository/ src/impl/org/apache/cocoon/blockdeployer/repository/ test/junit/org/apache/cocoon/blockdeployer/ test/junit/org/apache/cocoon/blockdeployer/repository/
Date Mon, 11 Apr 2005 07:51:15 GMT
Author: reinhard
Date: Mon Apr 11 00:51:12 2005
New Revision: 160843

URL: http://svn.apache.org/viewcvs?view=rev&rev=160843
Log:
work on actual block deployment (wiring.xml)

Modified:
    cocoon/whiteboard/block-deployer/.classpath
    cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
    cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java
    cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java
    cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java

Modified: cocoon/whiteboard/block-deployer/.classpath
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/.classpath?view=diff&r1=160842&r2=160843
==============================================================================
--- cocoon/whiteboard/block-deployer/.classpath (original)
+++ cocoon/whiteboard/block-deployer/.classpath Mon Apr 11 00:51:12 2005
@@ -1,26 +1,92 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src/api"/>
-	<classpathentry kind="src" path="src/client"/>
-	<classpathentry kind="src" path="test/junit"/>
-	<classpathentry kind="src" path="src/impl"/>
-	<classpathentry kind="lib" path="tools/lib/asm-1.4.3.jar"/>
-	<classpathentry kind="lib" path="tools/lib/cglib-2.0.1.jar"/>
-	<classpathentry kind="lib" path="lib/xercesImpl-2.6.2.jar"/>
-	<classpathentry kind="lib" path="lib/xml-apis.jar"/>
-	<classpathentry kind="lib" path="tools/lib/junit-3.8.1.jar"/>
-	<classpathentry kind="lib" path="tools/lib/easymock-1.1.jar"/>
-	<classpathentry kind="lib" path="tools/lib/easymockclassextension-1.1.jar"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="lib" path="lib/commons-codec-1.2.jar"/>
-	<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
-	<classpathentry kind="lib" path="lib/geronimo-spec-j2ee-1.0-M1.jar"/>
-	<classpathentry kind="lib" path="tools/lib/jodd-fileutils-0.29.jar"/>
-	<classpathentry kind="lib" path="lib/commons-cli-1.0.jar"/>
-	<classpathentry kind="lib" path="lib/castor-0.9.6-xml.jar"/>
-	<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
-	<classpathentry kind="lib" path="build/CocoonBlockDeployer-generated-0.1dev.jar"/>
-	<classpathentry kind="lib" path="lib/jakarta-oro-2.0.8.jar"/>
-	<classpathentry kind="lib" path="lib/commons-transaction-1.0.1.jar"/>
+	<classpathentry kind="src" path="src/api">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="src/client">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="test/junit">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="src/impl">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="tools/lib/asm-1.4.3.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="tools/lib/cglib-2.0.1.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/xercesImpl-2.6.2.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/xml-apis.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="tools/lib/junit-3.8.1.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="tools/lib/easymock-1.1.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="tools/lib/easymockclassextension-1.1.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/commons-codec-1.2.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/log4j-1.2.8.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/geronimo-spec-j2ee-1.0-M1.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="tools/lib/jodd-fileutils-0.29.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/commons-cli-1.0.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/castor-0.9.6-xml.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/jakarta-oro-2.0.8.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="lib/commons-transaction-1.0.1.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="build/CocoonBlockDeployer-generated-0.1dev.jar">
+		<attributes>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="output" path="build/eclipse"/>
 </classpath>

Modified: cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java?view=diff&r1=160842&r2=160843
==============================================================================
--- cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
(original)
+++ cocoon/whiteboard/block-deployer/src/api/org/apache/cocoon/blockdeployer/repository/Deployable.java
Mon Apr 11 00:51:12 2005
@@ -39,5 +39,6 @@
     	throws UnsupportedBlockException, DeploymentException;
     
     
+    public void undeploy(String blockId) throws BlockNotFoundException;
     
 }

Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java?view=diff&r1=160842&r2=160843
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java
(original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java
Mon Apr 11 00:51:12 2005
@@ -28,6 +28,7 @@
 import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
 import org.apache.cocoon.blockdeployer.utils.CommonsTransactionLogger;
 import org.apache.cocoon.blockdeployer.utils.LocatorUtils;
+import org.apache.cocoon.blockdeployer.wiring.wiring10.Mount;
 import org.apache.cocoon.blockdeployer.wiring.wiring10.Wiring;
 import org.apache.commons.transaction.file.FileResourceManager;
 import org.apache.commons.transaction.file.ResourceManagerException;
@@ -46,24 +47,36 @@
 
     public final static String WIRING_XML = "wiring.xml";
     protected final static String WORK_DIR = "work";
+    protected final static String RELATIVE_DEPLOYMENT_DIR = "WEB-INF/blocks";
+    
+    protected File deploymentDir;
+    protected LoggerFacade logger;
     
-    private File basedir;
-    private LoggerFacade logger;
-
     /**
-     * Provide the basedir and the wiring.
+     * Provide the deploymentDir and the wiring.
      * 
-     * @param basedir
+     * @param deploymentDir
      *            is a <code>File</code> object pointing to the directory
      *            where blocks can be deployed
      */
-    public ApplicationServer22Locator(File basedir, LoggerFacade logger ) {
+    public ApplicationServer22Locator(final File basedir, LoggerFacade logger ) throws Exception
{
         if(logger == null) {
             throw new NullPointerException("You have to set a logger!");
         }        
-        LocatorUtils.checkBasedir(basedir, logger, ApplicationServer22Locator.class);
-        this.basedir = basedir;
-        this.logger = logger;
+        this.logger = logger;      
+        this.deploymentDir = new File(basedir, RELATIVE_DEPLOYMENT_DIR);                
+        LocatorUtils.checkBasedir(deploymentDir, logger, ApplicationServer22Locator.class);
+        this.logger.debug(ApplicationServer22Locator.class, "Using deploymentDir: " + deploymentDir);
+        
+        // read in wiring.xml
+        try {
+            this.wiring10 = readWiring(new File(this.deploymentDir, WIRING_XML), this.logger);
+        } catch (Exception ex) {
+            String msg = "The application server's wiring.xml can't be read.";
+            logger.error(ApplicationServer22Locator.class, msg);
+            throw new NullPointerException(msg);
+        }        
+
     }
 
     public Block getBlock(String blockUri) {
@@ -85,12 +98,12 @@
         if(false) {
             throw new UnsupportedBlockException("Deploying a block of this type is not supported!");
         }
-
+        
         // deploy block into next available directory and update wiring.xml accordingly
         try {
             if(!this.blockExists(this.wiring10, block.getBlockId())) {
-                String nextDir = LocatorUtils.getNextDirectory(this.basedir);
-                this.logger.debug(this.getClass(), "Block to be deployed in " + nextDir);
+                String nextDir = LocatorUtils.getNextDirectory(this.deploymentDir);
+                this.logger.debug(this.getClass(), "Block [" + block.getBlockId() + "] to
be deployed in " + nextDir);
                 LocatorUtils.writeZip(new ZipInputStream(block.getStream()), this.frm, this.txId,
nextDir);
             }
             this.updateWiring(block);            
@@ -99,24 +112,16 @@
         }
     }
     
-    protected void updateWiring(Block block) {
-
 
-    }
-    
-    protected boolean blockExists(Wiring wiring10, String blockId) {
-        for(int i = 0; i < wiring10.getBlockCount(); i++) {
-            if(wiring10.getBlock(i).getId().equals(blockId)) {
-                return true;
-            }
-        }
-        return false;
-    }
+    public void undeploy(String blockId) throws BlockNotFoundException {
+        // TODO Auto-generated method stub
+        
+    }    
     
     
     public String getIdentifier() {
         try {
-            return this.basedir.toURL().toString();
+            return this.deploymentDir.toURL().toString();
         } catch (MalformedURLException e) {
             throw new IllegalStateException(this.getClass().getName() + ": The block doesn't
have a valid ID.");
         }
@@ -151,15 +156,6 @@
         if(frm != null) {
             throw new TransactionException("Transaction has already been started!");
         }
-
-        // read in wiring.xml
-        try {
-            readWiring();
-        } catch (Exception ex) {
-            String msg = "Transaction couldn't be started because problems when reading application
server's wiring.xml";
-            logger.error(ApplicationServer22Locator.class, msg);
-            throw new TransactionException(msg);
-        }
         
         // create and reset the workdir
         // FIXME workdir has to be a temporary directory
@@ -170,12 +166,12 @@
         // start the file resource manager
         if(this.logger.isDebugEnabled()) {
             this.logger.debug(this.getClass(), "Initializing FileResourceManager - workdir:"

-                + workDir + ", store:" + this.basedir.getAbsolutePath());
+                + workDir + ", store:" + this.deploymentDir.getAbsolutePath());
         }
         
         // initialize and start file resource manager and start transaction
         try {
-            this.frm = new FileResourceManager(this.basedir.getAbsolutePath(), 
+            this.frm = new FileResourceManager(this.deploymentDir.getAbsolutePath(), 
                     workDir, false, new CommonsTransactionLogger(this.logger), true);   
        
             this.frm.start();
             this.frm.startTransaction(txId);   
@@ -221,14 +217,21 @@
         }
     }
     
-    private void readWiring() throws MarshalException, ValidationException, IOException {
+    // ------- wiring and block helper methods ---------------------------------------
+    
+    private static Wiring readWiring(File wiringDescriptor, LoggerFacade logger) throws Exception
{
         // read the wiring information (currently we have to support only 
         // http://apache.org/cocoon/blocks/wiring/1.0)
-        File wiringDescriptor = new File(this.basedir, WIRING_XML);
+        Wiring wiring10 = null;
         if(wiringDescriptor.exists()) {
-            wiring10 = (Wiring) Wiring.unmarshal(new FileReader(wiringDescriptor));
-            logger.info("Using wiring descriptor at " + wiringDescriptor.getCanonicalPath().toString());
               
-
+            try {
+                wiring10 = (Wiring) Wiring.unmarshal(new FileReader(wiringDescriptor));
+                logger.info("Using wiring descriptor at " + wiringDescriptor.getCanonicalPath().toString());
                      
+            } catch (Exception ex) {
+                logger.info(ApplicationServer22Locator.class, "wiring.xml (" + wiringDescriptor
+ ") couldn't be used read: " + ex.getStackTrace());
+                throw new RuntimeException(ex);
+            } 
+         
             // log already deployed blocks
             if(logger.isDebugEnabled()) {
                 StringBuffer logInformation = new StringBuffer("Following blocks are already
installed: ");
@@ -240,11 +243,36 @@
         } else {
             wiring10 = new Wiring();
         }  
+        return wiring10;
     }
     
-    private void writeWiring()  throws MarshalException, ValidationException, IOException
{
+    private void writeWiring() throws MarshalException, ValidationException, IOException
{
         
     }
+    
+    protected void updateWiring(Block block) {
+        org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = 
+            new org.apache.cocoon.blockdeployer.wiring.wiring10.Block();
+        
+        // id
+        wiredBlock.setId(block.getBlockId());
+        // mount path
+        Mount mount = new Mount();
+        mount.setPath(block.getBlockDeploymentData().getMountPath());
+        wiredBlock.setMount(mount);
+
+        // add block to wiring        
+        this.wiring10.addBlock(wiredBlock);
+    }
+    
+    protected boolean blockExists(Wiring wiring10, String blockId) {
+        for(int i = 0; i < wiring10.getBlockCount(); i++) {
+            if(wiring10.getBlock(i).getId().equals(blockId)) {
+                return true;
+            }
+        }
+        return false;
+    }    
 
     private void stopResourceManager() {
         try {
@@ -256,6 +284,7 @@
             // null out FileResourceManager so that another transaction can start
             frm = null;
         }
-    }    
+    }
+
 
 }

Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java?view=diff&r1=160842&r2=160843
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java
(original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/Constants.java
Mon Apr 11 00:51:12 2005
@@ -25,9 +25,9 @@
 
     // basedirs for locators
     public static final String VALID_LOCATION_1 = "test/sample-repositories/rep1";
-    public static final String VALID_ASL_1 = "test/sample-repositories/application-server/WEB-INF/blocks";
+    public static final String VALID_ASL_1 = "test/sample-repositories/application-server";
     public static final String VALID_SBL_1 = "test/sample-repositories/single-block-repository";
-    public static final String TMP_VALID_ASL_1 = TMP_JUNIT + "/asf1/WEB-INF/blocks";
+    public static final String TMP_VALID_ASL_1 = TMP_JUNIT + "/asf1";
     public static final String INVALID_LOCATION = "bla";
     
     // available and valid block

Modified: cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java?view=diff&r1=160842&r2=160843
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java
(original)
+++ cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/repository/ApplicationServer22LocatorTest.java
Mon Apr 11 00:51:12 2005
@@ -26,6 +26,7 @@
 import org.apache.cocoon.blockdeployer.block.Block;
 import org.apache.cocoon.blockdeployer.block.BlockDeploymentData;
 import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor;
+import org.apache.cocoon.blockdeployer.wiring.wiring10.Wiring;
 import org.easymock.MockControl;
 
 /**
@@ -37,26 +38,29 @@
     
     private void setupExamples() {
         FileUtil.deleteDir(ASL);
+        if((new File(ASL).exists())) fail("Error: Directory mustn't exist (test isolation
not guaranteed!");
         FileUtil.mkdirs(ASL);
-        FileUtil.copyDir(ASL, Constants.TMP_VALID_ASL_1);
+        FileUtil.copyDir(Constants.VALID_ASL_1, ASL);
     }
     
-    public void testTransactionManagement() {
+    public void testTransactionManagement() throws Exception {
+        setupExamples();
         ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger);
+        // test committing a non-existing transaction
         try {
             asl.commitTransaction();
             fail("Calling commitTransaction() before calling start ransaction mustn't work.");
           
         } catch (TransactionException ex) {
             // expected behaviour
         }    
-        
+        // test rolling back a non-existing transaction
         try {
             asl.rollbackTransaction();
             fail("Calling rollbackTransaction() before calling start ransaction mustn't work.");
           
         } catch (TransactionException ex) {
             // expected behaviour
         }     
-        
+        // start a transaction
         try {
             asl.startTransaction();
             assertNotNull(asl.frm);
@@ -64,7 +68,7 @@
         } catch (TransactionException ex) {
             fail("startTransaction() on a new ApplicationServer22Locator should work.");
         }
-        
+        // calling start transaction twice
         try {
             asl.startTransaction();
             fail("Calling startTransaction() twice should not work.");            
@@ -73,27 +77,45 @@
         }  
         assertNotNull(asl.frm);
         assertNotNull(asl.wiring10);        
-        
     }
     
-    public void testDeploy() throws Exception {
-        // copy examples into tmp location
+    public void testDeploySingleBlock() throws Exception {
         setupExamples();
-        // deploy method             
+        // create locator, use transaction mgmt, deploy block
         ApplicationServer22Locator asl = new ApplicationServer22Locator(new File(ASL), this.logger);
-        
         asl.startTransaction();
         
-        Block b = createBlockMock("http://bla", null);
-        asl.deploy(b);
+        // create block metadata
+        MockControl bddCtrl = MockControl.createControl(BlockDeploymentData.class);
+        BlockDeploymentData bdd = (BlockDeploymentData) bddCtrl.getMock();
+        
+        String mountPath = "/mountPath";
+        bdd.getMountPath();
+        bddCtrl.setReturnValue(mountPath);
         
-        asl.commitTransaction();
+        bddCtrl.replay();
         
+        String blockId = "http://bla";
+        Block b = createBlockMock(blockId, bdd);
+        asl.deploy(b);
+        asl.commitTransaction();
         // test that the block is extracted correctly by checking whether the 
         // COB_INF and the block.xml are available
+        File descriptor = new File(ASL + "/WEB-INF/blocks/000001/block.xml");
+        assertTrue(descriptor.exists());
+        
+        Wiring wiring = asl.wiring10;
         
-        // clean up
-        // FileUtil.deleteDir(ASL);        
+        org.apache.cocoon.blockdeployer.wiring.wiring10.Block wiredBlock = null;
+        for(int i = 0; i < wiring.getBlockCount(); i++) {
+            org.apache.cocoon.blockdeployer.wiring.wiring10.Block locBlock = wiring.getBlock(i);
+            if(blockId.equals(locBlock.getId())) {
+                wiredBlock = locBlock;
+                break;
+            }
+        }
+        assertNotNull("The installed block must be added to the wiring.", wiredBlock);
+        assertEquals(mountPath, wiredBlock.getMount().getPath());
         
     }
     
@@ -123,7 +145,7 @@
 
     private Block createBlockMock(String id, BlockDeploymentData deployData) throws Exception
{
         // create the Block
-        MockControl blockControl = MockControl.createControl(Block.class);
+        MockControl blockControl = MockControl.createNiceControl(Block.class);
         Block block = (Block) blockControl.getMock();
         
         // create the block descriptor information
@@ -132,7 +154,7 @@
         
         // set the id
         block.getBlockId();
-        blockControl.setReturnValue(id);
+        blockControl.setReturnValue(id, MockControl.ONE_OR_MORE);
 
         // create the deployment meta information
         block.getBlockDeploymentData();



Mime
View raw message