[jboss-cvs] JBossAS SVN: r86176 - in branches/Branch_5_x/system/src: tests/org/jboss/test/server/profileservice/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Mar 21 17:48:43 EDT 2009
Author: emuckenhuber
Date: 2009-03-21 17:48:43 -0400 (Sat, 21 Mar 2009)
New Revision: 86176
Added:
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/test/DeploymentRepositoryUnitTestCase.java
Modified:
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java
Log:
[JBAS-6650] add a upload dir property
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-03-21 20:40:25 UTC (rev 86175)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-03-21 21:48:43 UTC (rev 86176)
@@ -29,6 +29,7 @@
import java.io.SyncFailedException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -52,6 +53,9 @@
/** Should an attempt to overwrite existing content fail in {@link #addDeploymentContent(String, ZipInputStream)}*/
private boolean failIfAlreadyExists = false;
+ /** A optional upload uri. */
+ private URI uploadUri;
+
/** A lock for the hot deployment/{@link #getModifiedDeployments()} */
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
@@ -69,7 +73,37 @@
{
this.failIfAlreadyExists = failIfAlreadyExists;
}
+
+ public URI getUploadUri()
+ {
+ if(uploadUri != null)
+ return uploadUri;
+ if(getRepositoryURIs() != null && getRepositoryURIs().length > 0)
+ return getRepositoryURIs()[0];
+
+ throw new IllegalArgumentException("No upload uri available.");
+ }
+
+ public void setUploadUri(URI uploadUri)
+ {
+ if(uploadUri == null)
+ {
+ this.uploadUri = null;
+ return;
+ }
+ // Validate
+ if(getRepositoryURIs() != null && getRepositoryURIs().length > 0)
+ {
+ if(Arrays.asList(getRepositoryURIs()).contains(uploadUri))
+ {
+ this.uploadUri = uploadUri;
+ return;
+ }
+ }
+ throw new IllegalArgumentException("Upload uri is not managed by this repository: "+ uploadUri);
+ }
+
public void load() throws Exception
{
for(URI uri : getRepositoryURIs())
@@ -95,20 +129,19 @@
String repositoryName = null;
try
{
- if(getRepositoryURIs().length == 0)
- throw new IllegalStateException("No uris associated with this repository.");
-
- // FIXME, this is writing the content to the first URI
// Write the content out
- File contentRoot = new File(getRepositoryURIs()[0]);
+ File contentRoot = new File(getUploadUri());
if(contentRoot == null)
throw new FileNotFoundException("Failed to obtain content dir for phase: "+vfsPath);
+ if(contentRoot.isDirectory() == false)
+ throw new FileNotFoundException("The content root is not a directory." + contentRoot.getAbsolutePath());
+ // The content file
File contentFile = new File(contentRoot, vfsPath);
// Check if it already exists
boolean exists = contentFile.exists();
if(exists && isFailIfAlreadyExists())
- throw new SyncFailedException("Deployment content already exists: "+contentFile.getAbsolutePath());
+ throw new SyncFailedException("Deployment content already exists: "+ contentFile.getAbsolutePath());
// Copy streams
FileOutputStream fos = new FileOutputStream(contentFile);
@@ -130,6 +163,7 @@
// Add the new virtual file to the cache
repositoryName = addVirtualFileCache(contentVF);
+ // Cleanup
if(exists)
cleanUpRoot(contentVF);
}
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java 2009-03-21 20:40:25 UTC (rev 86175)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/DefaultDeploymentRepositoryFactory.java 2009-03-21 21:48:43 UTC (rev 86176)
@@ -53,6 +53,12 @@
/** The repository types. */
public final static Collection<String> types;
+
+ /** A list of uploadURIs. */
+ private List<URI> uploadURIs;
+
+ /** The isFailIfAlreadyExists property. */
+ private boolean failIfAlreadyExists = false;
/** The deployment filter. */
private VirtualFileFilter deploymentFilter;
@@ -79,6 +85,26 @@
{
this.deploymentFilter = deploymentFilter;
}
+
+ public boolean isFailIfAlreadyExists()
+ {
+ return failIfAlreadyExists;
+ }
+
+ public void setFailIfAlreadyExists(boolean failIfAlreadyExists)
+ {
+ this.failIfAlreadyExists = failIfAlreadyExists;
+ }
+
+ public List<URI> getUploadURIs()
+ {
+ return uploadURIs;
+ }
+
+ public void setUploadURIs(List<URI> uploadURIs)
+ {
+ this.uploadURIs = uploadURIs;
+ }
public StructureModificationChecker getChecker()
{
@@ -118,25 +144,51 @@
throw new IllegalArgumentException("Null profile key.");
if(uris == null)
throw new IllegalArgumentException("Null uris");
-
+
+ BasicDeploymentRepository repository;
if(mutable)
{
- HotDeploymentRepository repository = new HotDeploymentRepository(key, uris);
- // Manually inject beans :)
- repository.setDeploymentFilter(deploymentFilter);
- repository.setChecker(checker);
-
- return repository;
+ repository = new HotDeploymentRepository(key, uris);
+ // Set modification checker
+ ((HotDeploymentRepository)repository).setChecker(checker);
}
else
{
- BasicDeploymentRepository repository = new BasicDeploymentRepository(key, uris);
- repository.setDeploymentFilter(deploymentFilter);
-
- return repository;
+ repository = new BasicDeploymentRepository(key, uris);
}
+ // Set a optional upload dir
+ setUploadURI(repository);
+ // Set the deployment filter
+ repository.setDeploymentFilter(deploymentFilter);
+ // Set if the repository should override existing content
+ repository.setFailIfAlreadyExists(isFailIfAlreadyExists());
+
+ return repository;
}
+ /**
+ * Define a upload uri for a deployment repository.
+ *
+ * @param repository the deployment repository
+ */
+ protected void setUploadURI(BasicDeploymentRepository repository)
+ {
+ if(this.uploadURIs != null && this.uploadURIs.isEmpty() == false)
+ {
+ URI[] repositoryURIs = repository.getRepositoryURIs();
+ if(repositoryURIs != null && repositoryURIs.length > 0)
+ {
+ for(URI repositoryURI : repositoryURIs)
+ {
+ if(this.uploadURIs.contains(repositoryURI))
+ {
+ repository.setUploadUri(repositoryURI);
+ }
+ }
+ }
+ }
+ }
+
protected URI[] createUris(ProfileSourceMetaData metaData) throws URISyntaxException
{
List<URI> uris = new ArrayList<URI>();
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/test/DeploymentRepositoryUnitTestCase.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/test/DeploymentRepositoryUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/test/DeploymentRepositoryUnitTestCase.java 2009-03-21 21:48:43 UTC (rev 86176)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.test;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.system.server.profile.repository.metadata.ImmutableProfileSourceMetaData;
+import org.jboss.system.server.profileservice.repository.BasicDeploymentRepository;
+import org.jboss.system.server.profileservice.repository.DefaultDeploymentRepositoryFactory;
+import org.jboss.test.BaseTestCase;
+
+/**
+ * Test the basic deployment repository.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DeploymentRepositoryUnitTestCase extends BaseTestCase
+{
+
+ /** The default key. */
+ private static final ProfileKey defaultKey = new ProfileKey(ProfileKey.DEFAULT);
+
+ public DeploymentRepositoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSetUploadDir() throws Exception
+ {
+ File uri = new File("test1");
+
+ BasicDeploymentRepository repository = new BasicDeploymentRepository(defaultKey, new URI[] {uri.toURI()});
+ assertEquals(uri.toURI(), repository.getUploadUri());
+
+ // Set a available uri
+ repository.setUploadUri(uri.toURI());
+ assertEquals(uri.toURI(), repository.getUploadUri());
+
+ File uri2 = new File("test2");
+ try
+ {
+ repository.setUploadUri(uri2.toURI());
+ fail("should not be able to set a not managed uri as upload dir.");
+ }
+ catch(Exception ok)
+ {
+ log.debug("saw exception", ok);
+ }
+ assertEquals(uri.toURI(), repository.getUploadUri());
+ }
+
+ public void testDefaultRepositoryFactory() throws Exception
+ {
+ File uri1 = new File("test1");
+ File uri2 = new File("test2");
+ File upload = new File("upload");
+
+ List<URI> uris = Collections.singletonList(upload.toURI());
+
+ DefaultDeploymentRepositoryFactory f = new DefaultDeploymentRepositoryFactory();
+ f.setUploadURIs(uris);
+
+ List<String> sourceNames = Arrays.asList(uri1.toURI().toString(), upload.toURI().toString());
+ ImmutableProfileSourceMetaData source = new ImmutableProfileSourceMetaData(sourceNames);
+
+ // See if the upload directory is set correctly
+ BasicDeploymentRepository repository = (BasicDeploymentRepository) f.createDeploymentRepository(defaultKey, source);
+ assertEquals(upload.toURI(), repository.getUploadUri());
+
+ // Change the factory upload uris
+ f.setUploadURIs(Collections.singletonList(uri2.toURI()));
+ repository = (BasicDeploymentRepository) f.createDeploymentRepository(defaultKey, source);
+ assertEquals(uri1.toURI(), repository.getUploadUri());
+ }
+
+}
More information about the jboss-cvs-commits
mailing list