[jboss-cvs] JBossAS SVN: r102274 - in projects/profileservice/trunk: core/src/main/java/org/jboss/profileservice/dependency and 22 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 11 05:59:22 EST 2010
Author: emuckenhuber
Date: 2010-03-11 05:59:19 -0500 (Thu, 11 Mar 2010)
New Revision: 102274
Added:
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/HDScanningProfile.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyDeploymentRepository.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyHDScanningRepository.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/FileDeploymentTarget.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/spi/
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/spi/DeploymentTarget.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/managmenet/
projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepositoryExt.java
Removed:
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractDeploymentRepository.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractImmutableProfile.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractVFSProfileSource.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/BasicDeploymentRepository.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/DeploymentUtils.java
Modified:
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/TypedProfileFactory.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileDeployAction.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileServiceController.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployers/MainDeployerPlugin.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/ProfileDeployerPlugin.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/hotdeploy/HDScanner.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/AbstractScanningProfile.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/BasicProfileFactory.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/MutableScanningProfile.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/ScanningProfileFactory.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapDeployerPlugin.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileFactory.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ArtifactRepositoryManager.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/CopyStreamArtifactTransformer.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ExplodedArtifactTransformer.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/LocalFileArtifactRepository.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/MutableFileArtifactRepository.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyProfileFactory.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/AbstractVirtualProfileFactory.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/DelegatingDeploymentRepository.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/VirtualDeploymentProfile.java
projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/repository/test/ArtifactRepositoryBackupUnitTestCase.java
projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/support/NoopProfileFactory.java
projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/support/TestVirtualDeploymentRepository.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/AbstractDeployHandler.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/actions/DeploymentDistributeAction.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java
projects/profileservice/trunk/plugins/src/test/java/org/jboss/test/profileservice/plugins/mgt/support/NoopManagementProxyFactory.java
projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/ProfileFactory.java
projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepository.java
Log:
mock a legacy deployment repository and cleanup profiles when undeployed.
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/TypedProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/TypedProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/TypedProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -57,6 +57,9 @@
return new String[] { typeName };
}
+ /**
+ * {@inheritDoc}
+ */
public Profile createProfile(ProfileKey key, ProfileMetaData metaData) throws Exception
{
if(key == null)
@@ -76,6 +79,19 @@
}
/**
+ * {@inheritDoc}
+ */
+ public void destroyProfile(ProfileMetaData metaData, Profile profile)
+ {
+ String profileType = metaData.getClass().getName();
+ ProfileFactory<ProfileMetaData, Profile> factory = this.factories.get(profileType);
+ if(factory != null && factory != this)
+ {
+ factory.destroyProfile(metaData, profile);
+ }
+ }
+
+ /**
* Delegate the creation of a profile to a registered factory.
*
* @param profileType the profile type
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileDeployAction.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileDeployAction.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileDeployAction.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -32,6 +32,7 @@
import org.jboss.profileservice.spi.NoSuchProfileException;
import org.jboss.profileservice.spi.Profile;
import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.deployment.ProfileDeploymentFlag;
/**
@@ -126,13 +127,14 @@
Collection<? extends ProfileDeployment> deployments = profile.getDeployments();
if (deployments != null && !deployments.isEmpty())
{
+ final ProfileKey key = profile.getKey();
// Add deployments
for (ProfileDeployment deployment : profile.getDeployments())
{
try
{
// Add deployment
- deployer.addDeployment(deployment);
+ deployer.addDeployment(key, deployment);
// mark as deployed
deployment.getDeploymentInfo().setFlag(ProfileDeploymentFlag.DEPLOYED);
}
@@ -151,13 +153,14 @@
Collection<ProfileDeployment> deployments = profile.getDeployments();
if (deployments != null && !deployments.isEmpty())
{
+ final ProfileKey key = profile.getKey();
// remove deployments
for (ProfileDeployment deployment : profile.getDeployments())
{
try
{
// remove deployment
- deployer.removeDeployment(deployment);
+ deployer.removeDeployment(key, deployment);
}
catch(Throwable t)
{
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileServiceController.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileServiceController.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/dependency/ProfileServiceController.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -27,6 +27,7 @@
import org.jboss.beans.metadata.api.model.AutowireType;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.beans.metadata.spi.builder.ParameterMetaDataBuilder;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerMode;
import org.jboss.dependency.spi.ControllerState;
@@ -202,9 +203,14 @@
builder.setFactoryMethod("createProfile");
builder.addConstructorParameter(ProfileKey.class.getName(), context.getKey());
builder.addConstructorParameter(ProfileMetaData.class.getName(), context.getProfileMetaData());
+ // Uninstall
+ // TODO remove name to TypedProfileFactory
+ ParameterMetaDataBuilder parameters = builder.addUninstallWithParameters("destroyProfile", "TypedProfileFactory");
+ parameters.addParameterMetaData(ProfileMetaData.class.getName(), context.getProfileMetaData());
+ parameters.addParameterMetaData(Profile.class.getName(), builder.createThis());
// No autowire
builder.setAutowireType(AutowireType.NONE);
-
+
// Create the ControllerContext
final ProfileControllerContext kCtx = new ProfileControllerContext(builder.getBeanMetaData(), profile);
// Set the correct context name, since BMDB just accepts a string
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployers/MainDeployerPlugin.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployers/MainDeployerPlugin.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployers/MainDeployerPlugin.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -27,6 +27,7 @@
import org.jboss.profileservice.deployment.ProfileDeployerPlugin;
import org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry;
import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
/**
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
@@ -65,7 +66,7 @@
}
@Override
- public void addDeployment(ProfileDeployment deployment) throws Exception
+ public void addDeployment(ProfileKey key, ProfileDeployment deployment) throws Exception
{
if(deployment == null)
{
@@ -110,7 +111,7 @@
}
@Override
- public void removeDeployment(ProfileDeployment deployment) throws Exception
+ public void removeDeployment(ProfileKey key, ProfileDeployment deployment) throws Exception
{
if(deployment == null)
{
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/ProfileDeployerPlugin.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/ProfileDeployerPlugin.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/ProfileDeployerPlugin.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -23,8 +23,11 @@
import org.jboss.managed.api.ManagedDeployment;
import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
/**
+ * The deployer plugin.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
@@ -34,18 +37,20 @@
/**
* Add a deployment.
*
+ * @key the profile key
* @param deployment the profile deployment.
* @throws Exception
*/
- void addDeployment(ProfileDeployment deployment) throws Exception;
+ void addDeployment(ProfileKey key, ProfileDeployment deployment) throws Exception;
/**
* Remove a deployment.
*
+ * @param key the profile key
* @param deployment the profile deployment
* @throws Exception
*/
- void removeDeployment(ProfileDeployment deployment) throws Exception;
+ void removeDeployment(ProfileKey key, ProfileDeployment deployment) throws Exception;
/**
* Process ...
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/hotdeploy/HDScanner.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/hotdeploy/HDScanner.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/deployment/hotdeploy/HDScanner.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -135,11 +135,11 @@
{
case ADDED:
case MODIFIED:
- deployer.addDeployment(ctx);
+ deployer.addDeployment(getKey(), ctx);
modifiedDeploymentNames.add(ctx.getName());
break;
case REMOVED:
- deployer.removeDeployment(ctx);
+ deployer.removeDeployment(getKey(), ctx);
modified = true;
break;
}
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/AbstractScanningProfile.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/AbstractScanningProfile.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/AbstractScanningProfile.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -66,8 +67,8 @@
/** The deployments. */
private Map<String, ProfileDeployment> deployments = new ConcurrentHashMap<String, ProfileDeployment>();
- /** Repository name, deployment name mapping. */
- private Map<String, String> repositoryNames = new ConcurrentHashMap<String, String>();
+ /** The repository names, containing all files we recognized as deployments */
+ private Set<String> repositoryNames = new HashSet<String>();
/** The last modified. */
private volatile long lastModified;
@@ -102,7 +103,7 @@
{
// Resolve our file artifact repository
// for scanning we need to have direct access
- this.artifactRepository = getRepository().resolveArtifactRepository(FileArtifactId.EMPTY_ARTIFACT);
+ this.artifactRepository = getDeploymentRepository().resolveArtifactRepository(FileArtifactId.EMPTY_ARTIFACT);
if(this.artifactRepository == null)
{
throw new IllegalStateException("failed to resolve artifact repository");
@@ -241,7 +242,7 @@
public boolean accepts(final Artifact<FileArtifactId> artifact)
{
final FileArtifactId id = artifact.getIdentifier();
- boolean exists = repositoryNames.keySet().contains(id.getPath());
+ boolean exists = repositoryNames.contains(id.getPath());
if(exists)
{
return false;
@@ -310,7 +311,7 @@
protected void internalAddDeployment(final ProfileDeployment deployment, final FileArtifactId artifactId)
{
this.deployments.put(deployment.getName(), deployment);
- this.repositoryNames.put(artifactId.getPath(), deployment.getName());
+ this.repositoryNames.add(artifactId.getPath());
// Mark as modified if it already exists ?
}
@@ -380,7 +381,7 @@
*/
protected ProfileDeployment createDeployment(VirtualDeploymentMetaData virtual) throws IOException
{
- return getRepository().createDeployment(virtual);
+ return getDeploymentRepository().createDeployment(virtual);
}
/**
@@ -419,7 +420,7 @@
*
* @return the virtual deployment repository
*/
- protected VirtualDeploymentRepository getRepository()
+ public VirtualDeploymentRepository getDeploymentRepository()
{
return this.deploymentRepository;
}
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/BasicProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/BasicProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/BasicProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -75,5 +75,10 @@
return new VirtualDeploymentProfile(key, virtual, createRepository(source));
}
+ public void destroyProfile(BasicProfileMetaData metaData, VirtualDeploymentProfile profile)
+ {
+ super.cleanupRepository(profile.getRepository());
+ }
+
}
Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/HDScanningProfile.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/HDScanningProfile.java (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/HDScanningProfile.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -0,0 +1,142 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.profileservice.profile;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.profileservice.deployment.ProfileDeploymentModificationChecker;
+import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
+import org.jboss.profileservice.spi.ModificationInfo;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.VirtualDeploymentRepository;
+import org.jboss.profileservice.spi.deployment.ProfileDeploymentFlag;
+import org.jboss.profileservice.spi.deployment.ProfileDeploymentInfo;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * A hot-deployment scanning profile implementation.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class HDScanningProfile extends MutableScanningProfile
+{
+
+ /** The modification checker delegate. */
+ private ProfileDeploymentModificationChecker modificationChecker;
+
+ public HDScanningProfile(ProfileKey key, VirtualDeploymentRepository repository)
+ {
+ super(key, repository);
+ }
+
+ public ProfileDeploymentModificationChecker getModificationChecker()
+ {
+ return modificationChecker;
+ }
+
+ public void setModificationChecker(ProfileDeploymentModificationChecker modificationChecker)
+ {
+ this.modificationChecker = modificationChecker;
+ }
+
+ /**
+ * Check if a deployment is modified. This needs the {@code ProfileDeployment} and the repository file.
+ *
+ * NOTE: the repository file is NOT supposed the one passed to the deployers. Since in case it is mounted
+ * it will point to temp location.
+ *
+ * @param deployment the deployment
+ * @param repositoryFile the repository file
+ * @return true if the deployment was modified since the last check
+ */
+ protected boolean isModified(ProfileDeployment deployment, VirtualFile repositoryFile)
+ {
+ return modificationChecker != null && modificationChecker.isDeploymentModified(deployment, repositoryFile);
+ }
+
+ /**
+ * Check the deployments for modifications and scan for new deployments.
+ */
+ public Collection<ModificationInfo> getModifiedDeployments() throws Exception
+ {
+ if(isModificationCheckEnabled() == false)
+ {
+ return Collections.emptySet();
+ }
+ final Map<String, ModificationInfo> modifications = new HashMap<String, ModificationInfo>();
+ lockRead();
+ try
+ {
+ final long lastModified = System.currentTimeMillis();
+ for(final ProfileDeployment deployment : getDeployments())
+ {
+ final ProfileDeploymentInfo info = deployment.getDeploymentInfo();
+ // Ignore locked deployments
+ if(info.isLocked())
+ {
+ continue;
+ }
+ final String deploymentName = deployment.getName();
+ // Resolve the repository VirtualFile, which has to point to a backup location
+ final FileArtifactId artifactId = getArtifactMetaData(deployment);
+ final VirtualFile repositoryFile = getArtifactRepository().getArtifactFile(artifactId);
+ if(repositoryFile.exists() == false)
+ {
+ internalRemoveDeployment(deploymentName);
+ final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.REMOVED);
+ modifications.put(deploymentName, modification);
+ }
+ else if(info.hasFlag(ProfileDeploymentFlag.MODIFIED) || isModified(deployment, repositoryFile))
+ {
+ final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.MODIFIED);
+ modifications.put(deploymentName, modification);
+ }
+ }
+ // Scan the repository
+ final Collection<ProfileDeployment> additions = scanRepository();
+ if(additions != null && additions.isEmpty() == false)
+ {
+ for(final ProfileDeployment deployment : additions)
+ {
+ final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.ADDED);
+ modifications.put(deployment.getName(), modification);
+ }
+ }
+ if(modifications.size() > 0)
+ {
+ updateLastModified();
+ }
+ }
+ finally
+ {
+ unlockRead();
+ }
+ return modifications.values();
+ }
+
+}
+
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/MutableScanningProfile.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/MutableScanningProfile.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/MutableScanningProfile.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -23,12 +23,9 @@
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jboss.logging.Logger;
-import org.jboss.profileservice.deployment.ProfileDeploymentModificationChecker;
import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
import org.jboss.profileservice.spi.ModificationInfo;
import org.jboss.profileservice.spi.MutableProfile;
@@ -36,9 +33,7 @@
import org.jboss.profileservice.spi.ProfileDeployment;
import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.VirtualDeploymentRepository;
-import org.jboss.profileservice.spi.deployment.ProfileDeploymentFlag;
-import org.jboss.profileservice.spi.deployment.ProfileDeploymentInfo;
-import org.jboss.vfs.VirtualFile;
+import org.jboss.profileservice.spi.VirtualDeploymentRepositoryExt;
/**
* A mutable scanning profile.
@@ -46,7 +41,7 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class MutableScanningProfile extends AbstractScanningProfile implements MutableProfile
+public class MutableScanningProfile extends AbstractScanningProfile implements MutableProfile, VirtualDeploymentRepositoryExt
{
/** The logger. */
@@ -55,9 +50,6 @@
/** enable modification checks. */
private volatile boolean enableChecks;
- /** The modification checker delegate. */
- private ProfileDeploymentModificationChecker modificationChecker;
-
/** The lock. */
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
@@ -65,33 +57,8 @@
{
super(key, repository);
}
-
- public ProfileDeploymentModificationChecker getModificationChecker()
- {
- return modificationChecker;
- }
- public void setModificationChecker(ProfileDeploymentModificationChecker modificationChecker)
- {
- this.modificationChecker = modificationChecker;
- }
-
/**
- * Check if a deployment is modified. This needs the {@code ProfileDeployment} and the repository file.
- *
- * NOTE: the repository file is supposed to be the real file, not the one passed to the deployers. Since
- * the one passed to the deployers could point to temp files.
- *
- * @param deployment the deployment
- * @param repositoryFile the repository file
- * @return true if the deployment was modified since the last check
- */
- protected boolean isModified(ProfileDeployment deployment, VirtualFile repositoryFile)
- {
- return modificationChecker != null && modificationChecker.isDeploymentModified(deployment, repositoryFile);
- }
-
- /**
* Is modification checks enabled. This can be used by implementing classes
* to override the default behavior. E.g. always disable content modification
* checking, but allowing distributing content using the DeploymentManager.
@@ -115,9 +82,13 @@
lockWrite();
try
{
- // Check if the artifact exists
final FileArtifactId artifactId = getArtifactMetaData(deployment);
- getArtifactRepository().getArtifact(artifactId);
+ if(deployment.getDeploymentInfo().isLocked() == false)
+ {
+ // In case the deployment is not locked check if it exists
+ // Since HDScanning could pick it up
+ getArtifactRepository().getArtifact(artifactId);
+ }
//
internalAddDeployment(deployment, artifactId);
}
@@ -136,63 +107,15 @@
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
+ *
+ * This specific implementation allows content modifications through the deployment
+ * API, however it does not do modification checks itself.
+ *
*/
public Collection<ModificationInfo> getModifiedDeployments() throws Exception
{
- if(isModificationCheckEnabled() == false)
- {
- return Collections.emptySet();
- }
- lockRead();
- final Map<String, ModificationInfo> modifications = new HashMap<String, ModificationInfo>();
- try
- {
- final long lastModified = System.currentTimeMillis();
- for(final ProfileDeployment deployment : getDeployments())
- {
- final ProfileDeploymentInfo info = deployment.getDeploymentInfo();
- // Ignore locked deployments
- if(info.isLocked())
- {
- continue;
- }
- final String deploymentName = deployment.getName();
- // Resolve the repository VirtualFile, which has to point to a backup location
- final FileArtifactId artifactId = getArtifactMetaData(deployment);
- final VirtualFile repositoryFile = getArtifactRepository().getArtifactFile(artifactId);
- if(repositoryFile.exists() == false)
- {
- internalRemoveDeployment(deploymentName);
- final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.REMOVED);
- modifications.put(deploymentName, modification);
- }
- else if(info.hasFlag(ProfileDeploymentFlag.MODIFIED) || isModified(deployment, repositoryFile))
- {
- final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.MODIFIED);
- modifications.put(deploymentName, modification);
- }
- }
- // Scan the repository
- final Collection<ProfileDeployment> additions = scanRepository();
- if(additions != null && additions.isEmpty() == false)
- {
- for(final ProfileDeployment deployment : additions)
- {
- final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.ADDED);
- modifications.put(deployment.getName(), modification);
- }
- }
- if(modifications.size() > 0)
- {
- updateLastModified();
- }
- }
- finally
- {
- unlockRead();
- }
- return modifications.values();
+ return Collections.emptyList();
}
/**
@@ -229,20 +152,20 @@
return log;
}
- void lockRead()
+ protected void lockRead()
{
lock.readLock().lock();
}
- void unlockRead()
+ protected void unlockRead()
{
lock.readLock().unlock();
}
- void lockWrite()
+ protected void lockWrite()
{
lock.writeLock().lock();
}
- void unlockWrite()
+ protected void unlockWrite()
{
lock.writeLock().unlock();
}
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/ScanningProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/ScanningProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/ScanningProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -24,8 +24,10 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Collection;
import org.jboss.profileservice.config.ProfileServiceConfig;
+import org.jboss.profileservice.deployment.ProfileDeploymentModificationChecker;
import org.jboss.profileservice.profile.metadata.plugin.HotDeploymentProfileMetaData;
import org.jboss.profileservice.profile.metadata.plugin.PropertyProfileMetaData;
import org.jboss.profileservice.profile.metadata.plugin.PropertyProfileSourceMetaData;
@@ -57,6 +59,9 @@
/** The artifact repository manager. */
private ArtifactRepositoryManager repositoryManager;
+ /** The modification checker. */
+ private ProfileDeploymentModificationChecker modificationChecker;
+
static
{
types = new String[] {
@@ -89,19 +94,32 @@
this.repositoryManager = repositoryManager;
}
+ public ProfileDeploymentModificationChecker getModificationChecker()
+ {
+ return modificationChecker;
+ }
+
+ public void setModificationChecker(ProfileDeploymentModificationChecker modificationChecker)
+ {
+ this.modificationChecker = modificationChecker;
+ }
+
public AbstractScanningProfile createProfile(ProfileKey key, PropertyProfileMetaData metaData) throws Exception
{
- boolean isMutable = metaData.isHotDeploymentEnabled();
PropertyProfileSourceMetaData source = metaData.getSource();
- //
- VirtualDeploymentRepository repository = createDeploymentRepository(Integer.toString(key.hashCode()), source, isMutable);
- if(isMutable)
+ // We always create mutable artifact repositories for scanning profiles, since we can easily add new contents to it
+ VirtualDeploymentRepository repository = createDeploymentRepository(Integer.toString(key.hashCode()), source, true);
+ if(metaData.isHotDeploymentEnabled())
{
- return new MutableScanningProfile(key, repository);
+ // HDScanning profile, performing modification checks
+ HDScanningProfile mutable = new HDScanningProfile(key, repository);
+ mutable.setModificationChecker(modificationChecker);
+ return mutable;
}
else
{
- return new ImmutableScanningProfile(key, repository);
+ // A mutable scanning profile, which does not do modification checks
+ return new MutableScanningProfile(key, repository);
}
}
@@ -117,6 +135,23 @@
fileRepository.getIdentifier());
}
+ public void destroyProfile(PropertyProfileMetaData metaData, AbstractScanningProfile profile)
+ {
+ VirtualDeploymentRepository repository = profile.getDeploymentRepository();
+ if(repository instanceof DelegatingDeploymentRepository)
+ {
+ DelegatingDeploymentRepository created = (DelegatingDeploymentRepository) repository;
+ Collection<ArtifactRepository<ArtifactId>> repositories = created.getArtifactRepositories();
+ if(repositories != null && repositories.isEmpty() == false)
+ {
+ for(ArtifactRepository<ArtifactId> artifactRepository : repositories)
+ {
+ repositoryManager.removeRepository(artifactRepository.getIdentifier());
+ }
+ }
+ }
+ }
+
protected AbstractRepositoryId createFileRepositoryId(String group)
{
return new AbstractRepositoryId(group, FileArtifactId.TYPE);
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapDeployerPlugin.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapDeployerPlugin.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapDeployerPlugin.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -42,8 +42,8 @@
import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
import org.jboss.metadata.spi.MetaData;
import org.jboss.profileservice.deployment.ProfileDeployerPlugin;
-import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
/**
* The bootstrap profile deployer pluging, delegating work to the
@@ -81,7 +81,7 @@
}
@Override
- public void addDeployment(ProfileDeployment deployment) throws Exception
+ public void addDeployment(ProfileKey key, ProfileDeployment deployment) throws Exception
{
checkShutdown();
try
@@ -116,7 +116,10 @@
KernelDeployment deployment = this.deployments.get(name);
if(deployment == null)
{
- throw new NoSuchDeploymentException(name);
+ // it can also happen that xml parsing did not succeed, so
+ // we just ignore non existing deployments
+ return;
+ // throw new NoSuchDeploymentException(name);
}
try
{
@@ -158,7 +161,7 @@
}
@Override
- public void removeDeployment(ProfileDeployment deployment) throws Exception
+ public void removeDeployment(ProfileKey key, ProfileDeployment deployment) throws Exception
{
if(deployment == null)
throw new IllegalArgumentException("null deployment");
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/profile/bootstrap/BootstrapProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -69,5 +69,10 @@
return new VirtualDeploymentProfile(key, virtual, createRepository(source));
}
+ public void destroyProfile(BootstrapProfileMetaData metaData, VirtualDeploymentProfile profile)
+ {
+ super.cleanupRepository(profile.getRepository());
+ }
+
}
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ArtifactRepositoryManager.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ArtifactRepositoryManager.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ArtifactRepositoryManager.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -21,18 +21,21 @@
*/
package org.jboss.profileservice.repository.artifact;
+import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.profileservice.spi.repository.ArtifactId;
import org.jboss.profileservice.spi.repository.ArtifactRepository;
import org.jboss.profileservice.spi.repository.ArtifactRepositoryConfiguration;
import org.jboss.profileservice.spi.repository.ArtifactRepositoryFactory;
import org.jboss.profileservice.spi.repository.ArtifactRepositoryId;
+import org.jboss.vfs.VFSUtils;
/**
* The artifact repository manager.
@@ -45,13 +48,16 @@
/** The default name. */
private static final String DEFAULT_NAME = "###DEFAULT####";
+
+ /** The artifact repository factories. */
+ private Map<String, ArtifactRepositoryFactory<ArtifactId>> factories = new ConcurrentHashMap<String, ArtifactRepositoryFactory<ArtifactId>>();
/** The artifact repositories. */
private ConcurrentMap<ArtifactRepositoryId, ArtifactRepository<ArtifactId>> repositories = new ConcurrentHashMap<ArtifactRepositoryId, ArtifactRepository<ArtifactId>>();
-
- /** The artifact repository factories. */
- private Map<String, ArtifactRepositoryFactory<ArtifactId>> factories = new ConcurrentHashMap<String, ArtifactRepositoryFactory<ArtifactId>>();
-
+
+ /** Track the usage of repositories/ */
+ private ConcurrentMap<ArtifactRepositoryId, AtomicInteger> repositoryTacking = new ConcurrentHashMap<ArtifactRepositoryId, AtomicInteger>();
+
/**
* Get all registered repositories.
*
@@ -95,13 +101,13 @@
if(repository == null)
{
// Resolve repository type
- String repositoryType = repositoryId.getType();
+ final String repositoryType = repositoryId.getType();
if(repositoryType == null)
{
throw new IllegalArgumentException("null repository type");
}
// Get repository factory
- ArtifactRepositoryFactory<ArtifactId> factory = factories.get(repositoryType);
+ final ArtifactRepositoryFactory<ArtifactId> factory = factories.get(repositoryType);
if(factory == null)
{
throw new IllegalStateException("no registered factory for type " + repositoryType);
@@ -115,6 +121,8 @@
// Add repository
addRepository(repository);
}
+ // Track usage
+ incrementUsage(repositoryId);
return repository;
}
@@ -127,6 +135,11 @@
return DEFAULT_NAME;
}
+ /**
+ * Add a repository.
+ *
+ * @param repository
+ */
public void addRepository(ArtifactRepository<ArtifactId> repository)
{
if(repository == null)
@@ -139,15 +152,45 @@
throw new IllegalStateException("duplicate repository " + repository);
}
+ /**
+ * Remove a repository. This should be only used for install callbacks. In
+ * case the repository manager was used to create the artifact repository
+ * {@see #removeRepository(ArtifactRepositoryId)} should be used.
+ *
+ * @param repository the repository to remove
+ */
public void removeRepository(ArtifactRepository<ArtifactId> repository)
{
if(repository == null)
throw new IllegalArgumentException("null repository");
if(repository.getIdentifier() == null)
- throw new IllegalArgumentException("null repository configuration");
+ throw new IllegalArgumentException("null repository configuration");
repositories.remove(repository.getIdentifier());
}
+ /**
+ * Remove a artifact repository.
+ *
+ * @param repositoryId the artifact repository id
+ */
+ public void removeRepository(ArtifactRepositoryId repositoryId)
+ {
+ // only remove repositories which were created through createArtifactRepository
+ if(decrementUsage(repositoryId) == 0)
+ {
+ ArtifactRepository<ArtifactId> repository = repositories.remove(repositoryId);
+ if(repository instanceof Closeable)
+ {
+ VFSUtils.safeClose(Closeable.class.cast(repository));
+ }
+ }
+ }
+
+ /**
+ * Add repository factory.
+ *
+ * @param factory the repository factory
+ */
public void addRepositoryFactory(ArtifactRepositoryFactory<ArtifactId> factory)
{
if(factory == null)
@@ -157,6 +200,11 @@
factories.put(factory.getRepositoryType(), factory);
}
+ /**
+ * Remove a repository factory.
+ *
+ * @param factory the repository factory to remove
+ */
public void removeRepositoryFactory(ArtifactRepositoryFactory<ArtifactId> factory)
{
if(factory == null)
@@ -164,6 +212,38 @@
if(factory.getRepositoryType() == null)
throw new IllegalArgumentException("null factory type");
factories.remove(factory.getRepositoryType());
+ if(factory instanceof Closeable)
+ {
+ VFSUtils.safeClose(Closeable.class.cast(factory));
+ }
}
+
+ /**
+ * Increment the usage of a artifact.
+ *
+ * @param id the artifact id
+ */
+ protected void incrementUsage(ArtifactRepositoryId id)
+ {
+ this.repositoryTacking.putIfAbsent(id, new AtomicInteger(0));
+ this.repositoryTacking.get(id).incrementAndGet();
+ }
+
+ /**
+ * Decrement and get usage of a artifact repository.
+ *
+ * @param id the artifact id
+ * @return the current count, -1 if the usage is not tracked
+ */
+ protected int decrementUsage(ArtifactRepositoryId id)
+ {
+ AtomicInteger i = this.repositoryTacking.get(id);
+ if(i != null)
+ {
+ return i.decrementAndGet();
+ }
+ return -1;
+ }
+
}
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/CopyStreamArtifactTransformer.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/CopyStreamArtifactTransformer.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/CopyStreamArtifactTransformer.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -43,9 +43,10 @@
/** The instance. */
private static final CopyStreamArtifactTransformer INSTANCE = new CopyStreamArtifactTransformer();
- public static CopyStreamArtifactTransformer getInstance()
+ @SuppressWarnings("unchecked")
+ public static <T extends ArtifactId> ArtifactTransformer<T> getInstance()
{
- return INSTANCE;
+ return (ArtifactTransformer<T>) INSTANCE;
}
public void transform(ArtifactId artifactId, InputStream is, VirtualFile target)
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ExplodedArtifactTransformer.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ExplodedArtifactTransformer.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/ExplodedArtifactTransformer.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -47,9 +47,9 @@
/** The instance. */
private static final ExplodedArtifactTransformer INSTANCE = new ExplodedArtifactTransformer();
- public static ExplodedArtifactTransformer getInstance()
+ public static <T extends ArtifactId> ArtifactTransformer<T> getInstance()
{
- return INSTANCE;
+ return (ArtifactTransformer<T>) INSTANCE;
}
/** The buffer size. */
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/LocalFileArtifactRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/LocalFileArtifactRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/LocalFileArtifactRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -45,7 +45,7 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class LocalFileArtifactRepository implements ArtifactRepository<FileArtifactId>
+public class LocalFileArtifactRepository implements ArtifactRepository<FileArtifactId>, Closeable
{
/** The repository id. */
@@ -114,6 +114,11 @@
public void destroy()
{
+ close();
+ }
+
+ public void close()
+ {
VFSUtils.safeClose(this.mount);
}
@@ -234,14 +239,7 @@
*/
public VirtualFile getArtifactFile(FileArtifactId artifact) throws IOException
{
- validateArtifactID(artifact);
- VirtualFile vf = getRepositoryRoot().getChild(artifact.getPath());
- if(vf.exists() == false)
- {
- if(Hack.checkHack())
- getConfiguration().getNotFoundHandler().handleArtifactNotFound(this, artifact);
- }
- return vf;
+ return getArtifactFile(artifact, true);
}
/**
@@ -266,6 +264,18 @@
}
}
+ protected VirtualFile getArtifactFile(FileArtifactId artifact, boolean checkExist) throws IOException
+ {
+ validateArtifactID(artifact);
+ VirtualFile vf = getRepositoryRoot().getChild(artifact.getPath());
+ if(checkExist && vf.exists() == false)
+ {
+ if(Hack.checkHack())
+ getConfiguration().getNotFoundHandler().handleArtifactNotFound(this, artifact);
+ }
+ return vf;
+ }
+
/**
* Validate the artifactId. this checks for not null and that it does not
* contain reverse tokens.
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/MutableFileArtifactRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/MutableFileArtifactRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/artifact/file/MutableFileArtifactRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -85,10 +85,10 @@
{
throw new IllegalArgumentException("null artifact transformer");
}
- VirtualFile target = getArtifactFile(artifactId);
lockWrite();
try
{
+ VirtualFile target = getArtifactFile(artifactId, false);
transformer.transform(artifactId, is, target);
}
finally
Deleted: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractDeploymentRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractDeploymentRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractDeploymentRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -1,239 +0,0 @@
-/*
- * 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.profileservice.repository.legacy;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.logging.Logger;
-import org.jboss.profileservice.spi.DeploymentContentFlags;
-import org.jboss.profileservice.spi.DeploymentRepository;
-import org.jboss.profileservice.spi.NoSuchDeploymentException;
-import org.jboss.profileservice.spi.ProfileDeployment;
-import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.vfs.VirtualFile;
-
-/**
- * A abstract VFS based deployment repository.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public abstract class AbstractDeploymentRepository extends AbstractVFSProfileSource implements DeploymentRepository
-{
-
- /** The ignore flags. */
- protected final static int ignoreFlags = DeploymentContentFlags.LOCKED | DeploymentContentFlags.DISABLED;
-
- /** The associated profile key. */
- private ProfileKey key;
-
- /** The content flags. */
- private Map<String, Integer> contentFlags = new ConcurrentHashMap<String, Integer>();
-
- /** The logger. */
- private static final Logger log = Logger.getLogger(AbstractDeploymentRepository.class);
-
- public AbstractDeploymentRepository(ProfileKey key, URI[] uris)
- {
- super(uris);
- if(key == null)
- throw new IllegalArgumentException("Null profile key.");
-
- this.key = key;
- }
-
- public ProfileKey getProfileKey()
- {
- return this.key;
- }
-
- public void create() throws Exception
- {
- //
- }
-
- public void unload()
- {
- super.destroy();
- // Unload
- this.contentFlags.clear();
- }
-
- @Override
- public void addDeployment(String vfsPath, ProfileDeployment d) throws Exception
- {
- super.addDeployment(d);
- }
-
- @Override
- public ProfileDeployment removeDeployment(String vfsPath) throws Exception
- {
- if(vfsPath == null)
- throw new IllegalArgumentException("Null vfsPath");
-
- // Get the deployment
- ProfileDeployment deployment = super.removeDeployment(vfsPath);
- // Remove the entries
- this.contentFlags.remove(deployment.getName());
- // Return
- return deployment;
- }
-
- @Override
- public ProfileDeployment getDeployment(String vfsPath) throws NoSuchDeploymentException
- {
- if(vfsPath == null)
- throw new IllegalArgumentException("Null vfsPath");
-
- ProfileDeployment ctx = super.getDeployment(vfsPath);
- if(ctx == null)
- {
- List<String> names = findDeploymentContent(vfsPath);
- if(names.size() == 1)
- {
- ctx = super.getDeployment(names.get(0));
- }
- else if(names.size() > 1)
- {
- throw new NoSuchDeploymentException("Multiple deployments found for: "+ vfsPath +", available: " + names);
- }
- }
- if(ctx == null)
- {
- log.debug("Failed to find application for: "+vfsPath+", available: " + getDeploymentNames());
- throw new NoSuchDeploymentException("Failed to find deployment in file: " + vfsPath);
- }
- return ctx;
- }
-
- public VirtualFile getDeploymentContent(String name) throws IOException
- {
- if(name == null)
- throw new IllegalArgumentException("Null name");
-
- // A deploy content needs to be added over addDeployContent
- VirtualFile vf = getCachedVirtualFile(name);
- if(vf == null)
- {
- List<String> matchingNames = findDeploymentContent(name);
- if(matchingNames.size() == 1)
- {
- vf = getCachedVirtualFile(matchingNames.get(0));
- }
- else if(matchingNames.size() > 1)
- {
- throw new FileNotFoundException("Multiple names found for name: " + name + ", profile: "+ key + ", available: " + matchingNames);
- }
- }
- if(vf == null)
- throw new FileNotFoundException("Failed to find content in profile: "+ key + " filename: " + name);
-
- return vf;
- }
-
- public String[] getRepositoryNames(String... names) throws IOException
- {
- if(names == null)
- throw new IllegalArgumentException("Null names[]");
-
- Collection<String> tmp = new HashSet<String>();
- for(String name : names)
- {
- if(getCachedVirtualFile(name) != null)
- {
- tmp.add(name);
- }
- else
- {
- // Try to find the name
- List<String> deploymentNames = findDeploymentContent(name);
- if(deploymentNames != null)
- tmp.addAll(deploymentNames);
- }
- }
- return tmp.toArray(new String[tmp.size()]);
- }
-
- public int lockDeploymentContent(String vfsPath)
- {
- if( log.isTraceEnabled() )
- log.trace("lockDeploymentContent, "+vfsPath);
- return setDeploymentContentFlags(vfsPath, DeploymentContentFlags.LOCKED);
- }
-
- public int unlockDeploymentContent(String vfsPath)
- {
- if( log.isTraceEnabled() )
- log.trace("unlockDeploymentContent, "+vfsPath);
- return clearDeploymentContentFlags(vfsPath, DeploymentContentFlags.LOCKED);
- }
-
- public int getDeploymentContentFlags(String vfsPath)
- {
- Integer flags = contentFlags.get(vfsPath);
- return flags != null ? flags : 0;
- }
- public synchronized int clearDeploymentContentFlags(String vfsPath, int flags)
- {
- Integer dflags = contentFlags.get(vfsPath);
- if(dflags != null)
- {
- dflags &= ~flags;
- contentFlags.put(vfsPath, dflags);
- }
- return dflags != null ? dflags : 0;
- }
- public boolean hasDeploymentContentFlags(String vfsPath, int flag)
- {
- Integer flags = contentFlags.get(vfsPath);
- boolean hasFlag = false;
- if(flags != null )
- hasFlag = (flags & flag) != 0;
- return hasFlag;
- }
- public int setDeploymentContentFlags(String vfsPath, int flags)
- {
- contentFlags.put(vfsPath, flags);
- return flags;
- }
-
- @Override
- protected boolean acceptsDeployment(String name)
- {
- if(hasDeploymentContentFlags(name, ignoreFlags))
- {
- if(log.isTraceEnabled())
- log.trace("Ignoring locked application: " + name);
-
- return false;
- }
- return super.acceptsDeployment(name);
- }
-
-}
Deleted: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractImmutableProfile.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractImmutableProfile.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractImmutableProfile.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -1,142 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.profileservice.repository.legacy;
-
-import java.net.URI;
-import java.util.List;
-
-import org.jboss.logging.Logger;
-import org.jboss.profileservice.spi.NoSuchDeploymentException;
-import org.jboss.profileservice.spi.Profile;
-import org.jboss.profileservice.spi.ProfileDeployment;
-import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.vfs.VirtualFile;
-
-/**
- * A immutable vfs based profile.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class AbstractImmutableProfile extends AbstractVFSProfileSource implements Profile
-{
-
- /** The profile key. */
- private ProfileKey key;
-
- /** The logger. */
- private static final Logger log = Logger.getLogger(AbstractImmutableProfile.class);
-
- public AbstractImmutableProfile(ProfileKey key, URI[] uris)
- {
- super(uris);
- //
- if(key == null)
- throw new IllegalArgumentException("Null profile key.");
-
- this.key = key;
- }
-
- public void create() throws Exception
- {
- for(URI uri : getRepositoryURIs())
- {
- VirtualFile root = getCachedVirtualFile(uri);
- loadApplications(root);
- }
- updateLastModfied();
- }
-
- public ProfileKey getKey()
- {
- return this.key;
- }
-
- @Override
- public ProfileDeployment getDeployment(String vfsPath) throws NoSuchDeploymentException
- {
- if(vfsPath == null)
- throw new IllegalArgumentException("Null name");
-
- ProfileDeployment ctx = super.getDeployment(vfsPath);
- if(ctx == null)
- {
- List<String> names = findDeploymentContent(vfsPath);
- if(names.size() == 1)
- {
- ctx = super.getDeployment(names.get(0));
- }
- else if(names.size() > 1)
- {
- throw new NoSuchDeploymentException("Multiple deployments found for: "+ vfsPath +", available: " + names);
- }
- }
- if(ctx == null)
- {
- log.debug("Failed to find application for: "+vfsPath+", available: " + getDeploymentNames());
- throw new NoSuchDeploymentException("Failed to find deployment in file: " + vfsPath);
- }
- return ctx;
- }
-
- public boolean hasDeployment(String name)
- {
- if(name == null)
- throw new IllegalArgumentException("Null name.");
-
- try
- {
- return super.getDeployment(name) != null;
- }
- catch(Exception e)
- {
- return false;
- }
- }
-
- public boolean isMutable()
- {
- return false;
- }
-
- public String toString()
- {
- StringBuilder builder = new StringBuilder();
- builder.append(getClass().getSimpleName());
- builder.append('@').append(Integer.toHexString(System.identityHashCode(this)));
- builder.append("{key = ").append(getKey());
- toString(builder);
- builder.append("}");
- return builder.toString();
- }
-
- /**
- * Additional information for toString().
- *
- * @param builder the builder.
- */
- protected void toString(StringBuilder builder)
- {
- //
- }
-
-}
Deleted: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractVFSProfileSource.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractVFSProfileSource.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/AbstractVFSProfileSource.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -1,380 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.profileservice.repository.legacy;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.logging.Logger;
-import org.jboss.profileservice.repository.ProfileDeploymentFactory;
-import org.jboss.profileservice.spi.NoSuchDeploymentException;
-import org.jboss.profileservice.spi.NoSuchProfileException;
-import org.jboss.profileservice.spi.ProfileDeployment;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.VirtualFileFilter;
-
-/**
- * A abstract VFS based source for profile deployments.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public abstract class AbstractVFSProfileSource
-{
-
- /** The repository uris. */
- protected final Collection<URI> uris;
-
- /** The VFSDeployments. */
- private Map<String, ProfileDeployment> applicationCtxs = new ConcurrentHashMap<String, ProfileDeployment>();
-
- /** Allowed deployments filter. */
- private VirtualFileFilter deploymentFilter;
-
- /** The application files keyed by VirtualFile URI string. */
- private final Map<String, VirtualFile> applicationVFCache = new ConcurrentHashMap<String, VirtualFile>();
-
- /** Do a recursive search - default == true. */
- private boolean recursiveScan = true;
-
- /** The last time the profile was modified. */
- private volatile long lastModified;
-
- /** The logger. */
- private final static Logger log = Logger.getLogger(AbstractVFSProfileSource.class);
-
- /** The deployment factory. */
- private final static ProfileDeploymentFactory deploymentFactory = ProfileDeploymentFactory.getInstance();
-
- public AbstractVFSProfileSource(URI[] uris)
- {
- if(uris == null)
- throw new IllegalArgumentException("Null uris");
-
- this.uris = new ArrayList<URI>();
- for(URI uri : uris)
- {
- this.uris.add(uri);
- }
- }
-
- public VirtualFileFilter getDeploymentFilter()
- {
- return deploymentFilter;
- }
-
- public void setDeploymentFilter(VirtualFileFilter deploymentFilter)
- {
- this.deploymentFilter = deploymentFilter;
- }
-
- public boolean isRecursiveScan()
- {
- return recursiveScan;
- }
-
- public void setRecursiveScan(boolean recursiveScan)
- {
- this.recursiveScan = recursiveScan;
- }
-
- public URI[] getRepositoryURIs()
- {
- return uris.toArray(new URI[uris.size()]);
- }
-
- public Set<String> getDeploymentNames()
- {
- return this.applicationCtxs.keySet();
- }
-
- public Collection<ProfileDeployment> getDeployments()
- {
- return this.applicationCtxs.values();
- }
-
- public long getLastModified()
- {
- return this.lastModified;
- }
-
- public void destroy()
- {
- // Unload
- this.applicationCtxs.clear();
- this.applicationVFCache.clear();
- updateLastModfied();
- }
-
- /**
- * Add a deployment to this profile source.
- *
- * @param d the deployment
- * @throws IllegalArgumentException for a null deployment
- */
- protected void addDeployment(ProfileDeployment d)
- {
- if(d == null)
- throw new IllegalArgumentException("null deployment");
-
- // Add deployment and vfs
- this.applicationCtxs.put(d.getName(), d);
- if(d.getRoot() != null)
- this.applicationVFCache.put(d.getName(), d.getRoot());
- updateLastModfied();
- }
-
- /**
- * Get the deployment
- *
- * @param vfsPath the deployment
- * @return the deployment or null if it does not exist
- */
- protected ProfileDeployment getDeployment(String vfsPath) throws NoSuchDeploymentException
- {
- if(vfsPath == null)
- throw new IllegalArgumentException("Null vfsPath");
-
- return this.applicationCtxs.get(vfsPath);
- }
-
- /**
- * Remove a deployment from this source.
- *
- * @param vfsPath the deployment name
- * @return the deployment
- * @throws NoSuchProfileException if the deployment does not exist
- */
- public ProfileDeployment removeDeployment(String vfsPath) throws Exception
- {
- if(vfsPath == null)
- throw new IllegalArgumentException("Null vfsPath");
-
- // Get the deployment
- ProfileDeployment deployment = getDeployment(vfsPath);
- // Remove the entries
- this.applicationCtxs.remove(deployment.getName());
- this.applicationVFCache.remove(deployment.getName());
- // Update last modified
- updateLastModfied();
- // Return
- return deployment;
- }
-
- /**
- * Load all the applications under the applicationDir.
- *
- * @param applicationDir the application directory
- * @throws IOException
- */
- protected void loadApplications(VirtualFile applicationDir) throws Exception
- {
- ArrayList<VirtualFile> added = new ArrayList<VirtualFile>();
- addedDeployment(added, applicationDir);
- for (VirtualFile vf : added)
- {
- ProfileDeployment vfCtx = createDeployment(vf);
- addDeployment(vfCtx);
- }
- }
-
- /**
- * Scan the children of the root for deployments.
- *
- * @param list a list of virtual files, where new deployments are added to
- * @param root the root to scan
- * @throws IOException
- * @throws URISyntaxException
- */
- protected void addedDeployments(List<VirtualFile> list, VirtualFile root) throws IOException, URISyntaxException
- {
- if(root.isFile())
- {
- addedDeployment(list, root);
- }
- else
- {
- List<VirtualFile> components = root.getChildren();
- for (VirtualFile component : components)
- {
- addedDeployment(list, component);
- }
- }
- }
-
- /**
- * Scan a given virtualFile for deployments.
- *
- * @param list a list of virtual files, where new deployments are added to
- * @param component the root file
- * @throws IOException
- * @throws URISyntaxException
- */
- protected void addedDeployment(List<VirtualFile> list, VirtualFile component) throws IOException, URISyntaxException
- {
- // Excluding files from scanning
- if(deploymentFilter != null && this.deploymentFilter.accepts(component) == false)
- {
- if(log.isTraceEnabled())
- log.trace("ignoring "+ component);
- return;
- }
-
- // Check if we accept this deployment
- String key = component.asFileURI().toString();
- if(acceptsDeployment(key) == false)
- return;
-
- // If it's a directory or exploded deployment
- if(component.isFile() == false)
- {
- // Check the name
- if(isRecursiveScan() && component.getName().indexOf('.') == -1)
- {
- // recurse if not '.' in name and recursive search is enabled
- addedDeployments(list, component);
- }
- else
- {
- list.add(component);
- }
- }
- else
- {
- list.add(component);
- }
- }
-
- /**
- * Check if the deployment should be added.
- *
- * @param name the deployment name
- * @return
- */
- protected boolean acceptsDeployment(String name)
- {
- return applicationCtxs.containsKey(name) == false;
- }
-
- /**
- * Try to find a deployment, based on the cached
- * virtual roots of deployments we have.
- *
- * @param name the deployment name
- * @return a collection of matching names
- */
- protected List<String> findDeploymentContent(String name)
- {
- if(this.applicationVFCache.containsKey(name))
- {
- return Collections.singletonList(name);
- }
-
- List<String> contents = new ArrayList<String>();
- for(String cacheName : this.applicationVFCache.keySet())
- {
- String fixedName = cacheName;
- if(cacheName.endsWith("/"))
- fixedName = cacheName.substring(0, cacheName.length() -1);
-
- if(fixedName.endsWith(name))
- {
- contents.add(cacheName);
- }
- }
- return contents;
- }
-
- /**
- * Add a virtualFile to the local virtualFileCache
- *
- * @param vf the virtual file
- * @return the name
- * @throws MalformedURLException
- * @throws URISyntaxException
- */
- protected String addVirtualFileCache(VirtualFile vf) throws MalformedURLException, URISyntaxException
- {
- String uri = vf.asFileURI().toString();
- this.applicationVFCache.put(uri, vf);
- return uri;
- }
-
- /**
- * Get a cached virtual file.
- *
- * @param name the name
- * @return the virtual file or null, if it does not exist
- */
- protected VirtualFile getCachedVirtualFile(String name)
- {
- return this.applicationVFCache.get(name);
- }
-
- /**
- * Get a cached virtual file. This will add the uri to the
- * virtualFile if it does not exist.
- *
- * @param uri the uri
- * @return the virtual file
- * @throws IOException
- */
- protected VirtualFile getCachedVirtualFile(URI uri) throws IOException
- {
- VirtualFile vf = getCachedVirtualFile(uri.toString());
- if(vf == null)
- {
- vf = VFS.getChild(uri);
- this.applicationVFCache.put(uri.toString(), vf);
- }
- return vf;
- }
-
- /**
- * Create a ProfileDeployment, based on the virtual file.
- *
- * @param vf the deployment root
- * @return the profile deployment
- */
- protected static ProfileDeployment createDeployment(VirtualFile vf)
- {
- return deploymentFactory.createDeployment(vf, null);
- }
-
- /**
- * Internally update the lastModified timestamp.
- */
- protected void updateLastModfied()
- {
- this.lastModified = System.currentTimeMillis();
- }
-}
Deleted: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/BasicDeploymentRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/BasicDeploymentRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/BasicDeploymentRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -1,352 +0,0 @@
-/*
- * 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.profileservice.repository.legacy;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-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.List;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.zip.ZipInputStream;
-
-import org.jboss.logging.Logger;
-import org.jboss.profileservice.spi.DeploymentContentFlags;
-import org.jboss.profileservice.spi.DeploymentOption;
-import org.jboss.profileservice.spi.ModificationInfo;
-import org.jboss.profileservice.spi.ProfileDeployment;
-import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VirtualFile;
-
-/**
- * A basic deployment repository.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class BasicDeploymentRepository extends AbstractDeploymentRepository
-{
-
- /** 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);
-
- /** The Logger. */
- private static final Logger log = Logger.getLogger(BasicDeploymentRepository.class);
-
- public BasicDeploymentRepository(ProfileKey key, URI[] uris)
- {
- super(key, uris);
- }
-
- public boolean isFailIfAlreadyExists()
- {
- return failIfAlreadyExists;
- }
-
- public void setFailIfAlreadyExists(boolean failIfAlreadyExists)
- {
- 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())
- {
- VirtualFile root = getCachedVirtualFile(uri);
- loadApplications(root);
- }
- updateLastModfied();
- }
-
- @Override
- public void addDeployment(String vfsPath, ProfileDeployment d) throws Exception
- {
- // Suspend hot deployment checking
- if( log.isTraceEnabled() )
- log.trace("Aquiring content write lock");
- lockWrite();
- try
- {
- internalAddDeployment(vfsPath, d);
- }
- finally
- {
- // Allow hot deployment checking
- unlockWrite();
- if(log.isTraceEnabled())
- log.trace("Released content write lock");
- }
- }
-
- public Collection<ModificationInfo> getModifiedDeployments() throws Exception
- {
- return Collections.emptySet();
- }
-
- public String addDeploymentContent(String vfsPath, InputStream contentIS) throws IOException
- {
- return addDeploymentContent(vfsPath, contentIS, new DeploymentOption[0]);
- }
-
- public String addDeploymentContent(String vfsPath, InputStream contentIS, DeploymentOption... options)
- throws IOException
- {
- boolean trace = log.isTraceEnabled();
- // Suspend hot deployment checking
- if( trace )
- log.trace("Aquiring content write lock");
- lockWrite();
- String repositoryName = null;
- try
- {
- // Write the content out
- 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();
- // Get the content options
- List<DeploymentOption> deploymentOptions = Arrays.asList(options);
- boolean failIfAlreadyExsists = isFailIfAlreadyExists()
- || deploymentOptions.contains(DeploymentOption.FailIfExists);
- if(exists && failIfAlreadyExsists)
- throw new SyncFailedException("Deployment content already exists: "+ contentFile.getAbsolutePath());
-
- // Check if we need unpack this deployment
- if(deploymentOptions.contains(DeploymentOption.Explode))
- {
- // Unjar
- DeploymentUtils.unjar(contentIS, contentFile);
- }
- else
- {
- // Copy stream
- FileOutputStream fos = new FileOutputStream(contentFile);
- try
- {
- byte[] tmp = new byte[4096];
- int read;
- while((read = contentIS.read(tmp)) > 0)
- {
- if (trace)
- log.trace("write, " + read);
- fos.write(tmp, 0, read);
- }
- fos.flush();
- }
- finally
- {
- try
- {
- fos.close();
- }
- catch (IOException ignored)
- {
- }
- }
- }
-
- // Get the vfs uri and add the VFS uri to the cached VFS uris
- VirtualFile contentVF = VFS.getChild(contentFile.toURI());
- try
- {
- // Add the new virtual file to the cache
- repositoryName = addVirtualFileCache(contentVF);
-
- // Cleanup
- if(exists)
- cleanUpRoot(contentVF);
- }
- catch(URISyntaxException e)
- {
- throw new RuntimeException(e); // This should not happen anyway
- }
-
- // Lock the content
- setDeploymentContentFlags(repositoryName, DeploymentContentFlags.LOCKED);
- }
- finally
- {
- // Allow hot deployment checking
- unlockWrite();
- if(trace)
- log.trace("Released content write lock");
- }
- return repositoryName;
- }
-
- public ProfileDeployment removeDeployment(String vfsPath) throws Exception
- {
- return removeDeployment(vfsPath, true);
- }
-
- /**
- * Internal add the deployment, without locking the repository.
- *
- * @param vfsPath - the name of the deployment
- * @param deployment - the deployment
- * @throws Exception
- */
- protected void internalAddDeployment(String vfsPath, ProfileDeployment deployment) throws Exception
- {
- super.addDeployment(vfsPath, deployment);
- }
-
- /**
- * Remove deployment.
- *
- * @param vfsPath the vfs path
- * @param deleteFile do we delete the file
- * @return found profile deployment
- * @throws Exception for any error
- */
- protected ProfileDeployment removeDeployment(String vfsPath, boolean deleteFile) throws Exception
- {
- // Suspend hot deployment checking
- if( log.isTraceEnabled() )
- log.trace("Aquiring content write lock");
- lockWrite();
- try
- {
- // Remove the deployment from the filesystem
- ProfileDeployment deployment = getDeployment(vfsPath);
- VirtualFile root = deployment.getRoot();
-
- if(deleteFile && root != null)
- {
- // Delete the file and check if the delete was successful
- if(root.delete() == false && root.exists())
- throw new IOException("Failed to delete: " + root);
-
- cleanUpRoot(root);
- }
-
- // Cleanup
- return super.removeDeployment(deployment.getName());
- }
- finally
- {
- unlockWrite();
- if (log.isTraceEnabled())
- log.trace("Released content write lock");
- }
- }
-
- /**
- * A way for the hot-deployment repository to cleanup
- * the root (modification checker).
- *
- * @param vf the deployment root
- */
- protected void cleanUpRoot(VirtualFile vf)
- {
- //
- }
-
- public void remove() throws Exception
- {
- // FIXME remove
- }
-
- /**
- * Lock for read
- */
- protected void lockRead()
- {
- lock.readLock().lock();
- }
-
- /**
- * Unlock for read
- */
- protected void unlockRead()
- {
- lock.readLock().unlock();
- }
-
- /**
- * Lock for write
- */
- protected void lockWrite()
- {
- lock.writeLock().lock();
- }
-
- /**
- * Unlock for write
- */
- protected void unlockWrite()
- {
- lock.writeLock().unlock();
- }
-
-}
-
Deleted: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/DeploymentUtils.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/DeploymentUtils.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/DeploymentUtils.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -1,139 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.profileservice.repository.legacy;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.jar.JarInputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-
-import org.jboss.util.file.JarUtils;
-
-/**
- * Deployment Utils.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-class DeploymentUtils
-{
- /** The buffer size. */
- static final int BUFFER_SIZE = 1024;
-
- protected DeploymentUtils()
- {
- //
- }
-
- /**
- * Try to unpack an inputStream.
- * This is a fork of {@link JarUtils#unjar}, but does not close the
- * InputStream itself, as this is done by the remote deploymentTarget.
- *
- * @param in the InputStream
- * @param dest the destination file
- * @throws IOException
- */
- public static void unjar(InputStream in, File dest) throws IOException
- {
- if (!dest.exists())
- {
- dest.mkdirs();
- }
- if (!dest.isDirectory())
- {
- throw new IOException("Destination must be a directory.");
- }
- JarInputStream jin = new JarInputStream(in);
- byte[] buffer = new byte[BUFFER_SIZE];
-
- ZipEntry entry = jin.getNextEntry();
- while (entry != null)
- {
- String fileName = entry.getName();
- if (fileName.charAt(fileName.length() - 1) == '/')
- {
- fileName = fileName.substring(0, fileName.length() - 1);
- }
- if (fileName.charAt(0) == '/')
- {
- fileName = fileName.substring(1);
- }
- if (File.separatorChar != '/')
- {
- fileName = fileName.replace('/', File.separatorChar);
- }
- File file = new File(dest, fileName);
- if (entry.isDirectory())
- {
- // make sure the directory exists
- file.mkdirs();
- jin.closeEntry();
- }
- else
- {
- // make sure the directory exists
- File parent = file.getParentFile();
- if (parent != null && !parent.exists())
- {
- parent.mkdirs();
- }
-
- // dump the file
- OutputStream out = new FileOutputStream(file);
- int len = 0;
- while ((len = jin.read(buffer, 0, buffer.length)) != -1)
- {
- out.write(buffer, 0, len);
- }
- out.flush();
- out.close();
- jin.closeEntry();
- file.setLastModified(entry.getTime());
- }
- entry = jin.getNextEntry();
- }
- /* Explicity write out the META-INF/MANIFEST.MF so that any headers such
- as the Class-Path are see for the unpackaged jar
- */
- Manifest mf = jin.getManifest();
- if (mf != null)
- {
- File file = new File(dest, "META-INF/MANIFEST.MF");
- File parent = file.getParentFile();
- if( parent.exists() == false )
- {
- parent.mkdirs();
- }
- OutputStream out = new FileOutputStream(file);
- mf.write(out);
- out.flush();
- out.close();
- }
- }
-
-}
-
Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyDeploymentRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyDeploymentRepository.java (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyDeploymentRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -0,0 +1,238 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.profileservice.repository.legacy;
+
+import java.io.IOException;
+import java.io.InputStream;
+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.HashSet;
+import java.util.List;
+
+import org.jboss.profileservice.profile.MutableScanningProfile;
+import org.jboss.profileservice.repository.artifact.CopyStreamArtifactTransformer;
+import org.jboss.profileservice.repository.artifact.ExplodedArtifactTransformer;
+import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
+import org.jboss.profileservice.spi.DeploymentOption;
+import org.jboss.profileservice.spi.DeploymentRepository;
+import org.jboss.profileservice.spi.ModificationInfo;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.VirtualDeploymentRepository;
+import org.jboss.profileservice.spi.deployment.ProfileDeploymentFlag;
+import org.jboss.profileservice.spi.repository.ArtifactId;
+import org.jboss.profileservice.spi.repository.ArtifactTransformer;
+import org.jboss.profileservice.spi.repository.MutableArtifactRepository;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class LegacyDeploymentRepository extends MutableScanningProfile implements DeploymentRepository
+{
+
+ public LegacyDeploymentRepository(ProfileKey key, VirtualDeploymentRepository deploymentRepository)
+ {
+ super(key, deploymentRepository);
+ }
+
+ public void load() throws Exception
+ {
+ super.start();
+ }
+
+ public void unload()
+ {
+ super.stop();
+ }
+
+ public void addDeployment(String name, ProfileDeployment deployment) throws Exception
+ {
+ super.addDeployment(deployment);
+ }
+
+ public String addDeploymentContent(String name, InputStream contentIS) throws IOException
+ {
+ return addDeploymentContent(name, contentIS, new DeploymentOption[0]);
+ }
+
+ public String addDeploymentContent(String name, InputStream contentIS, DeploymentOption... options)
+ throws IOException
+ {
+ if(name == null)
+ {
+ throw new IllegalArgumentException("null deployment name");
+ }
+ if(contentIS == null)
+ {
+ throw new IllegalArgumentException("null content input stream");
+ }
+ if(options == null)
+ {
+ options = new DeploymentOption[0];
+ }
+ lockWrite();
+ try
+ {
+ // Get the mutable artifact repository
+ MutableArtifactRepository<FileArtifactId> mutable = getMutableArtifactRepository();
+ FileArtifactId artifactId = new FileArtifactId(name);
+ // Get the content options
+ List<DeploymentOption> deploymentOptions = Arrays.asList(options);
+ boolean failIfAlreadyExsists = deploymentOptions.contains(DeploymentOption.FailIfExists);
+ if(mutable.containsArtifact(artifactId) && failIfAlreadyExsists)
+ {
+ throw new SyncFailedException("Deployment content already exists: "+ name);
+ }
+ // Check if we need unpack this deployment
+ ArtifactTransformer<FileArtifactId> transformer = null;
+ if(deploymentOptions.contains(DeploymentOption.Explode))
+ {
+ transformer = ExplodedArtifactTransformer.getInstance();
+ }
+ else
+ {
+ transformer = CopyStreamArtifactTransformer.getInstance();
+ }
+ // Add the deployment
+ mutable.addArtifact(artifactId, contentIS, transformer);
+ String repositoryName = name;
+ try
+ {
+ VirtualFile original = mutable.getOriginalFile(artifactId);
+ repositoryName = original.asFileURI().toString();
+ }
+ catch (URISyntaxException ignore)
+ {
+ //
+ }
+ return repositoryName;
+ }
+ finally
+ {
+ unlockWrite();
+ }
+
+ }
+
+ public Collection<ModificationInfo> getModifiedDeployments() throws Exception
+ {
+ return Collections.emptyList();
+ }
+
+ public String[] getRepositoryNames(String... names) throws Exception
+ {
+ Collection<String> repositoryNames = new HashSet<String>();
+ for(String name : names)
+ {
+ ProfileDeployment deployment = resolveDeployment(name);
+ if(deployment != null)
+ {
+ repositoryNames.add(deployment.getName());
+ }
+ }
+ return repositoryNames.toArray(new String[repositoryNames.size()]);
+ }
+
+ public URI[] getRepositoryURIs()
+ {
+ return new URI[] { super.getArtifactRepository().getRepositoryURI() };
+ }
+
+ public ProfileDeployment removeDeployment(String name) throws Exception
+ {
+ lockWrite();
+ try
+ {
+ ProfileDeployment deployment = resolveDeployment(name);
+ // Delete artifact
+ getMutableArtifactRepository().removeArtifact(getArtifactMetaData(deployment));
+ super.internalRemoveDeployment(deployment.getName());
+ return deployment;
+ }
+ finally
+ {
+ unlockWrite();
+ }
+ }
+
+ public boolean hasDeploymentContentFlags(String name, int flag)
+ {
+ return false;
+ }
+
+ public int lockDeploymentContent(String name)
+ {
+ ProfileDeployment deployment = resolveDeployment(name);
+ deployment.getDeploymentInfo().setFlag(ProfileDeploymentFlag.LOCKED);
+ return 0;
+ }
+
+ public int unlockDeploymentContent(String name)
+ {
+ ProfileDeployment deployment = resolveDeployment(name);
+ deployment.getDeploymentInfo().clearFlag(ProfileDeploymentFlag.LOCKED);
+ return 0;
+ }
+
+ public void remove() throws Exception
+ {
+ throw new UnsupportedOperationException("getDeploymentContent");
+ }
+
+ public int clearDeploymentContentFlags(String name, int flags)
+ {
+ throw new UnsupportedOperationException("clearDeploymentContentFlags");
+ }
+
+ public VirtualFile getDeploymentContent(String name) throws IOException, URISyntaxException
+ {
+ throw new UnsupportedOperationException("getDeploymentContent");
+ }
+
+ public int getDeploymentContentFlags(String name)
+ {
+ throw new UnsupportedOperationException("getDeploymentContentFlags");
+ }
+
+ public int setDeploymentContentFlags(String name, int flags)
+ {
+ throw new UnsupportedOperationException("setDeploymentContentFlags");
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T extends ArtifactId> MutableArtifactRepository<T> getMutableArtifactRepository()
+ {
+ if(getArtifactRepository() instanceof MutableArtifactRepository<?> == false)
+ {
+ throw new IllegalStateException("failed to add deployment content to immutable repository");
+ }
+ return MutableArtifactRepository.class.cast(getArtifactRepository());
+ }
+
+}
+
Added: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyHDScanningRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyHDScanningRepository.java (rev 0)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyHDScanningRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -0,0 +1,140 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.profileservice.repository.legacy;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.profileservice.deployment.ProfileDeploymentModificationChecker;
+import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
+import org.jboss.profileservice.spi.ModificationInfo;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.VirtualDeploymentRepository;
+import org.jboss.profileservice.spi.deployment.ProfileDeploymentFlag;
+import org.jboss.profileservice.spi.deployment.ProfileDeploymentInfo;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class LegacyHDScanningRepository extends LegacyDeploymentRepository
+{
+
+ /** The modification checker delegate. */
+ private ProfileDeploymentModificationChecker modificationChecker;
+
+ public LegacyHDScanningRepository(ProfileKey key, VirtualDeploymentRepository repository)
+ {
+ super(key, repository);
+ }
+
+ public ProfileDeploymentModificationChecker getModificationChecker()
+ {
+ return modificationChecker;
+ }
+
+ public void setModificationChecker(ProfileDeploymentModificationChecker modificationChecker)
+ {
+ this.modificationChecker = modificationChecker;
+ }
+
+ /**
+ * Check if a deployment is modified. This needs the {@code ProfileDeployment} and the repository file.
+ *
+ * NOTE: the repository file is NOT supposed the one passed to the deployers. Since in case it is mounted
+ * it will point to temp location.
+ *
+ * @param deployment the deployment
+ * @param repositoryFile the repository file
+ * @return true if the deployment was modified since the last check
+ */
+ protected boolean isModified(ProfileDeployment deployment, VirtualFile repositoryFile)
+ {
+ return modificationChecker != null && modificationChecker.isDeploymentModified(deployment, repositoryFile);
+ }
+
+ /**
+ * Check the deployments for modifications and scan for new deployments.
+ */
+ public Collection<ModificationInfo> getModifiedDeployments() throws Exception
+ {
+ if(isModificationCheckEnabled() == false)
+ {
+ return Collections.emptySet();
+ }
+ final Map<String, ModificationInfo> modifications = new HashMap<String, ModificationInfo>();
+ lockRead();
+ try
+ {
+ final long lastModified = System.currentTimeMillis();
+ for(final ProfileDeployment deployment : getDeployments())
+ {
+ final ProfileDeploymentInfo info = deployment.getDeploymentInfo();
+ // Ignore locked deployments
+ if(info.isLocked())
+ {
+ continue;
+ }
+ final String deploymentName = deployment.getName();
+ // Resolve the repository VirtualFile, which has to point to a backup location
+ final FileArtifactId artifactId = getArtifactMetaData(deployment);
+ final VirtualFile repositoryFile = getArtifactRepository().getArtifactFile(artifactId);
+ if(repositoryFile.exists() == false)
+ {
+ internalRemoveDeployment(deploymentName);
+ final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.REMOVED);
+ modifications.put(deploymentName, modification);
+ }
+ else if(info.hasFlag(ProfileDeploymentFlag.MODIFIED) || isModified(deployment, repositoryFile))
+ {
+ final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.MODIFIED);
+ modifications.put(deploymentName, modification);
+ }
+ }
+ // Scan the repository
+ final Collection<ProfileDeployment> additions = scanRepository();
+ if(additions != null && additions.isEmpty() == false)
+ {
+ for(final ProfileDeployment deployment : additions)
+ {
+ final ModificationInfo modification = new ModificationInfo(deployment, lastModified, ModificationInfo.ModifyStatus.ADDED);
+ modifications.put(deployment.getName(), modification);
+ }
+ }
+ if(modifications.size() > 0)
+ {
+ updateLastModified();
+ }
+ }
+ finally
+ {
+ unlockRead();
+ }
+ return modifications.values();
+ }
+
+}
+
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/legacy/LegacyProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -83,6 +83,11 @@
return new NoopProfile(key);
}
+ public void destroyProfile(PropertyProfileMetaData metaData, Profile profile)
+ {
+
+ }
+
public DeploymentRepositoryFactory getRepositoryFactory()
{
return repositoryFactory;
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/AbstractVirtualProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/AbstractVirtualProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/AbstractVirtualProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -92,7 +92,14 @@
}
}
- protected VirtualDeploymentRepository createRepository(FileRepositorySourceConfiguration source) throws Exception
+ /**
+ * Create a {@code VirtualDeploymentRepository}.
+ *
+ * @param source the file source configuration.
+ * @return the deployment repository
+ * @throws IOException for any error
+ */
+ protected VirtualDeploymentRepository createRepository(FileRepositorySourceConfiguration source) throws IOException
{
if(source != null && source.getGroup() != null)
{
@@ -106,6 +113,23 @@
return UNCONFIGURED;
}
+ /**
+ * Cleanup the created repositories.
+ *
+ * @param repository the virtual deployment repository
+ */
+ protected void cleanupRepository(VirtualDeploymentRepository repository)
+ {
+ Collection<ArtifactRepositoryId> repositories = repository.getRepositoryIDs();
+ if(repositories != null && repositories.isEmpty() == false)
+ {
+ for(ArtifactRepositoryId artifactRepository : repositories)
+ {
+ repositoryManager.removeRepository(artifactRepository);
+ }
+ }
+ }
+
protected AbstractRepositoryId createFileRepositoryId(String group)
{
return new AbstractRepositoryId(group, FileArtifactId.TYPE);
@@ -113,7 +137,8 @@
static class UnconfiguredVirtualDeploymentRepository implements VirtualDeploymentRepository
{
- public Collection<ArtifactRepository<ArtifactId>> getArtifactRepositories()
+
+ public Collection<ArtifactRepositoryId> getRepositoryIDs()
{
return Collections.emptySet();
}
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/DelegatingDeploymentRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/DelegatingDeploymentRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/DelegatingDeploymentRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -74,6 +74,14 @@
/**
* {@inheritDoc}
*/
+ public Collection<ArtifactRepositoryId> getRepositoryIDs()
+ {
+ return repositoryRefs.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Collection<ArtifactRepository<ArtifactId>> getArtifactRepositories()
{
Set<ArtifactRepository<ArtifactId>> repositories = new HashSet<ArtifactRepository<ArtifactId>>();
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/VirtualDeploymentProfile.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/VirtualDeploymentProfile.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/repository/virtual/VirtualDeploymentProfile.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -30,6 +30,7 @@
import java.util.Set;
import org.jboss.logging.Logger;
+import org.jboss.profileservice.Hack;
import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.jboss.profileservice.spi.Profile;
import org.jboss.profileservice.spi.ProfileDeployment;
@@ -109,8 +110,15 @@
}
catch(Exception e)
{
- // FIXME for testing purpose only
- log.error("failed to create deployment " + virtual.getName());
+ // FIXME
+ if(Hack.checkHack())
+ {
+ throw e;
+ }
+ else
+ {
+ log.error("failed to create deployment " + virtual.getName());
+ }
}
}
}
@@ -215,7 +223,7 @@
*
* @return the virtual deployment repository
*/
- protected VirtualDeploymentRepository getRepository()
+ public VirtualDeploymentRepository getRepository()
{
return this.repository;
}
Modified: projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/repository/test/ArtifactRepositoryBackupUnitTestCase.java
===================================================================
--- projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/repository/test/ArtifactRepositoryBackupUnitTestCase.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/repository/test/ArtifactRepositoryBackupUnitTestCase.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -187,7 +187,8 @@
assertEquals(artifact.getIdentifier().getPath(), realFile.getPathNameRelativeTo(repoRoot));
// the real and the artifact files don't match
assertFalse(realFile.equals(repositoryFile));
- getLog().debug(repositoryFile);
+ assertTrue(realFile.getPhysicalFile().equals(repositoryFile.getPhysicalFile()));
+ getLog().debug(repositoryFile.toURL());
try
{
String relative = realFile.getPathNameRelativeTo(backupRoot);
Modified: projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/support/NoopProfileFactory.java
===================================================================
--- projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/support/NoopProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/support/NoopProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -41,6 +41,11 @@
return profile;
}
+ public void destroyProfile(ProfileMetaData metaData, Profile profile)
+ {
+ // nada
+ }
+
public String[] getTypes()
{
return null;
Modified: projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/support/TestVirtualDeploymentRepository.java
===================================================================
--- projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/support/TestVirtualDeploymentRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/virtual/support/TestVirtualDeploymentRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -32,6 +32,7 @@
import org.jboss.profileservice.spi.VirtualDeploymentRepository;
import org.jboss.profileservice.spi.repository.ArtifactId;
import org.jboss.profileservice.spi.repository.ArtifactRepository;
+import org.jboss.profileservice.spi.repository.ArtifactRepositoryId;
import org.jboss.profileservice.spi.virtual.VirtualDeploymentMetaData;
import org.jboss.profileservice.spi.virtual.assembly.VirtualDeploymentAssemblyContext;
import org.jboss.profileservice.virtual.assembly.AbstractVirtualDeploymentAssembly;
@@ -57,10 +58,9 @@
{
return assemblyConfiguration.getVirtualAssemblyRoot();
}
-
- public Collection<ArtifactRepository<ArtifactId>> getArtifactRepositories()
+
+ public Collection<ArtifactRepositoryId> getRepositoryIDs()
{
- // FIXME getArtifactRepositories
return null;
}
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/AbstractDeployHandler.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/AbstractDeployHandler.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/AbstractDeployHandler.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -21,11 +21,17 @@
*/
package org.jboss.profileservice.plugins.deploy;
+import java.io.InputStream;
import java.util.Collection;
import org.jboss.deployers.spi.management.deploy.DeploymentID;
import org.jboss.profileservice.deployment.ProfileDeploymentRegistry;
+import org.jboss.profileservice.plugins.deploy.spi.DeploymentTarget;
+import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
+import org.jboss.profileservice.spi.DeploymentOption;
import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileDeployment;
import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.ProfileService;
@@ -42,11 +48,40 @@
/** The ProfileService. */
private ProfileService ps;
+ protected Profile getProfile(ProfileKey key)
+ {
+ return null;
+ }
+
protected void distribute(DeploymentID id)
{
+ if(id.isCopyContent())
+ {
+ ///
+ }
+ else
+ {
+
+
+
+
+ }
+ }
+
+ protected String copyContent(InputStream contentIS, DeploymentID id) throws Exception
+ {
+ ProfileKey key = id.getProfile();
+ DeploymentTarget<FileArtifactId> deploymentTarget = FileDeploymentTarget.createDeploymentTarget(getProfile(key));
+
+ // We only distribute one deployment
+ String name = id.getNames()[0];
+ DeploymentOption[] options = id.getDeploymentOptions();
+ ProfileDeployment deployment = deploymentTarget.distributeContent(name, contentIS, options);
+ return deployment.getName();
}
+
protected void startDeployment(String deploymentName) throws Exception
{
ProfileKey key = checkProfileForDeployment(deploymentName);
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/FileDeploymentTarget.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/FileDeploymentTarget.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/FileDeploymentTarget.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -0,0 +1,199 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.profileservice.plugins.deploy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.SyncFailedException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.profileservice.plugins.deploy.spi.DeploymentTarget;
+import org.jboss.profileservice.profile.metadata.BasicProfileDeploymentMetaData;
+import org.jboss.profileservice.repository.artifact.CopyStreamArtifactTransformer;
+import org.jboss.profileservice.repository.artifact.ExplodedArtifactTransformer;
+import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
+import org.jboss.profileservice.spi.DeploymentOption;
+import org.jboss.profileservice.spi.MutableProfile;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.VirtualDeploymentRepository;
+import org.jboss.profileservice.spi.VirtualDeploymentRepositoryExt;
+import org.jboss.profileservice.spi.deployment.ProfileDeploymentFlag;
+import org.jboss.profileservice.spi.repository.ArtifactId;
+import org.jboss.profileservice.spi.repository.ArtifactRepository;
+import org.jboss.profileservice.spi.repository.ArtifactTransformer;
+import org.jboss.profileservice.spi.repository.MutableArtifactRepository;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class FileDeploymentTarget implements DeploymentTarget<FileArtifactId>
+{
+
+ private MutableProfile profile;
+ private VirtualDeploymentRepository deploymentRepository;
+ private MutableArtifactRepository<FileArtifactId> artifactRepository;
+
+ public FileDeploymentTarget(MutableProfile profile, VirtualDeploymentRepository deploymentRepository,
+ MutableArtifactRepository<FileArtifactId> artifactRepository)
+ {
+ this.profile = profile;
+ this.deploymentRepository = deploymentRepository;
+ this.artifactRepository = artifactRepository;
+ }
+
+ public ProfileDeployment distributeContent(String name, InputStream contentIS, DeploymentOption[] options) throws Exception
+ {
+ // Get the content options
+ List<DeploymentOption> deploymentOptions = Arrays.asList(options);
+
+ // Create the file artifact id
+ FileArtifactId artifactId = new FileArtifactId(name);
+
+ // Check if the artifact is already there
+ boolean failIfAlreadyExsists = deploymentOptions.contains(DeploymentOption.FailIfExists);
+ if(failIfAlreadyExsists && artifactRepository.containsArtifact(artifactId))
+ {
+ throw new SyncFailedException("Deployment content already exists: "+ name);
+ }
+
+ // Check if we need unpack this deployment
+ ArtifactTransformer<FileArtifactId> transformer = null;
+ if(deploymentOptions.contains(DeploymentOption.Explode))
+ {
+ transformer = ExplodedArtifactTransformer.getInstance();
+ }
+ else
+ {
+ transformer = CopyStreamArtifactTransformer.getInstance();
+ }
+
+ // Create the deployment
+ ProfileDeployment deployment = deploymentRepository.createDeployment(new BasicProfileDeploymentMetaData(name));
+ // Mark it as locked, so we can add contents after
+ deployment.getDeploymentInfo().setFlag(ProfileDeploymentFlag.LOCKED);
+ // Add the deployment
+ profile.addDeployment(deployment);
+ // Add the content
+ artifactRepository.addArtifact(artifactId, contentIS, transformer);
+
+ return deployment;
+ }
+
+
+ public ProfileDeployment removeDeployment(String deploymentName) throws NoSuchDeploymentException, IOException, Exception
+ {
+ ProfileDeployment deployment = profile.getDeployment(deploymentName);
+ deployment.getDeploymentInfo().setFlag(ProfileDeploymentFlag.LOCKED);
+
+ FileArtifactId artifactId = getArtifactId(deployment);
+ artifactRepository.removeArtifact(artifactId);
+ profile.removeDeployment(deploymentName);
+
+ return deployment;
+ }
+
+ //
+
+ /**
+ * Create the deployment target based on a profile.
+ *
+ * This will require the profile to be mutable, implement VirtualDeploymentRepsoitoryExt
+ * and contain a MutableArtifactRepository<FileArtifactId>
+ *
+ * @return the deployment target
+ */
+ static FileDeploymentTarget createDeploymentTarget(Profile profile)
+ {
+ MutableProfile mutable = getMutableProfile(profile);
+ VirtualDeploymentRepository vdr = getDeploymentRepository(mutable);
+ MutableArtifactRepository<FileArtifactId> artifactRepository = resolveRepository(vdr);
+ return new FileDeploymentTarget(mutable, vdr, artifactRepository);
+ }
+
+ /**
+ * Cast to a mutable profile
+ *
+ * @param profile the profile
+ * @return the mutable profile
+ */
+ static MutableProfile getMutableProfile(Profile profile)
+ {
+ if(profile.isMutable() == false || profile instanceof MutableProfile)
+ {
+ throw new IllegalStateException("failed to create deployment target for and immutable profile " + profile.getKey());
+ }
+ return MutableProfile.class.cast(profile);
+ }
+
+ /**
+ * Cast to VirtualDeploymentRepositoryExt
+ *
+ * @param profile the mutable profile
+ * @return the virtual deployment repository
+ */
+ static VirtualDeploymentRepository getDeploymentRepository(MutableProfile profile)
+ {
+ if(profile instanceof VirtualDeploymentRepositoryExt == false)
+ {
+ throw new IllegalStateException("");
+ }
+ return VirtualDeploymentRepositoryExt.class.cast(profile).getDeploymentRepository();
+ }
+
+ /**
+ * Resolve and cast to mutable artifact repository
+ *
+ * @param deploymentRepository the virtual deployment repository
+ * @return the mutable artifact repository
+ */
+ static MutableArtifactRepository<FileArtifactId> resolveRepository(VirtualDeploymentRepository deploymentRepository)
+ {
+ ArtifactRepository<FileArtifactId> repo = deploymentRepository.resolveArtifactRepository(FileArtifactId.EMPTY_ARTIFACT);
+ if(repo instanceof MutableArtifactRepository<?> == false)
+ {
+ throw new IllegalStateException("no mutable artifact repository");
+ }
+ return MutableArtifactRepository.class.cast(repo);
+ }
+
+ /**
+ * Get the FileArtifactId from a profile deployment
+ *
+ * @param deployment the profile deployment
+ * @return the file artifact id
+ */
+ static FileArtifactId getArtifactId(ProfileDeployment deployment)
+ {
+ ArtifactId id =deployment.getDeploymentInfo().getMetaData().getArtifact();
+ if(id instanceof FileArtifactId == false)
+ {
+ throw new IllegalStateException("failed to resolve artifact");
+ }
+ return FileArtifactId.class.cast(id);
+ }
+
+}
+
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/actions/DeploymentDistributeAction.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/actions/DeploymentDistributeAction.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/actions/DeploymentDistributeAction.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -24,6 +24,7 @@
import java.io.InputStream;
import org.jboss.logging.Logger;
+import org.jboss.profileservice.profile.metadata.BasicProfileDeploymentMetaData;
import org.jboss.profileservice.repository.artifact.CopyStreamArtifactTransformer;
import org.jboss.profileservice.repository.artifact.file.FileArtifactId;
import org.jboss.profileservice.spi.MutableProfile;
@@ -65,6 +66,7 @@
return false;
}
// Create the artifact based on the deployment name
+ String artifactName = getDeploymentName();
FileArtifactId artifactId = new FileArtifactId(getDeploymentName());
// We need a mutable repository
MutableArtifactRepository<ArtifactId> mutable = MutableArtifactRepository.class.cast(artifactRepository);
@@ -76,7 +78,7 @@
// Add IS
mutable.addArtifact(artifactId, getDeploymentInputStream(), transformer);
// Assemble
- ProfileDeployment deployment = getVirtualDeploymentRepository().createDeployment(null);
+ ProfileDeployment deployment = getVirtualDeploymentRepository().createDeployment(new BasicProfileDeploymentMetaData(artifactName));
// Lock hd-scanning
deployment.getDeploymentInfo().setFlag(ProfileDeploymentFlag.LOCKED);
// Add deployment
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/spi/DeploymentTarget.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/spi/DeploymentTarget.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/deploy/spi/DeploymentTarget.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -0,0 +1,60 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.profileservice.plugins.deploy.spi;
+
+import java.io.InputStream;
+
+import org.jboss.profileservice.spi.DeploymentOption;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.repository.ArtifactId;
+
+/**
+ * The deployment target.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface DeploymentTarget<T extends ArtifactId>
+{
+
+ /**
+ * Distribute content to a deployment target.
+ *
+ * @param name the relative deployment name
+ * @param contentIS the content input stream
+ * @param options the client deployment options
+ * @return the profile deployment
+ * @throws Exception for any error
+ */
+ ProfileDeployment distributeContent(String name, InputStream contentIS, DeploymentOption[] options) throws Exception;
+
+ /**
+ * Remove the contents of a deployment.
+ *
+ * @param deploymentName the deployment name
+ * @return the profile deployment
+ * @throws Exception for any error
+ */
+ ProfileDeployment removeDeployment(String deploymentName) throws Exception;
+
+}
+
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -38,13 +38,20 @@
import org.jboss.logging.Logger;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ActivationPolicy;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.values.MetaValue;
import org.jboss.profileservice.plugins.management.util.AbstractManagementProxyFactory;
import org.jboss.profileservice.plugins.management.util.ManagedDeploymentProcessorHelper;
import org.jboss.profileservice.plugins.spi.ProfileView;
import org.jboss.profileservice.plugins.spi.ProfileViewWrapper;
import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.profileservice.spi.ProfileKey;
/**
* The aggregating management view. This represents the local view of
@@ -492,7 +499,21 @@
{
throw new IllegalArgumentException("null managed component");
}
- // TODO
+ ManagedComponent serverComponent = getComponent(comp.getName(), comp.getType());
+ if(serverComponent == null)
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidComponentName")); //$NON-NLS-1$
+ Object[] args = {comp.getName(), comp.getType()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+ ProfileKey target = resolveProfile(serverComponent.getDeployment().getName());
+ if(target == null)
+ {
+ throw new IllegalStateException("failed to resolve target profile for component " + serverComponent);
+ }
+
+ // TODO 1) finish implementation 2) create ModificationAction
}
/**
@@ -504,8 +525,114 @@
{
throw new IllegalArgumentException("null managed component");
}
- // TODO
+ ManagedComponent serverComponent = getComponent(comp.getName(), comp.getType());
+ if(serverComponent == null)
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidComponentName")); //$NON-NLS-1$
+ Object[] args = {comp.getName(), comp.getType()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+ ProfileKey target = resolveProfile(serverComponent.getDeployment().getName());
+ if(target == null)
+ {
+ throw new IllegalStateException("failed to resolve target profile for component " + serverComponent);
+ }
+
+ // Dispatch any runtime component property values
+ for(ManagedProperty prop : comp.getProperties().values())
+ {
+ // Skip null values && non-CONFIGURATION values, unmodified values, and removed values
+ boolean skip = prop.getValue() == null
+ || prop.isReadOnly()
+ || prop.hasViewUse(ViewUse.CONFIGURATION) == false
+// || prop.isModified() == false
+ || prop.isRemoved() == true;
+ if( skip )
+ {
+ if(log.isTraceEnabled())
+ log.trace("Skipping component property: "+prop);
+ continue;
+ }
+
+ ManagedProperty ctxProp = serverComponent.getProperties().get(prop.getName());
+ // Check for a mapped name
+ if( ctxProp == null )
+ {
+ String mappedName = prop.getMappedName();
+ if( mappedName != null )
+ ctxProp = serverComponent.getProperties().get(mappedName);
+ }
+ if( ctxProp == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplateProperty")); //$NON-NLS-1$
+ Object[] args = {prop.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+ // The property value must be a MetaValue
+ Object value = prop.getValue();
+ if ((value instanceof MetaValue) == false)
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidPropertyValue")); //$NON-NLS-1$
+ Object[] args = {prop.getName(), value.getClass()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+ // Update the serverComp
+ MetaValue metaValue = (MetaValue)value;
+ ctxProp.setField(Fields.META_TYPE, metaValue.getMetaType());
+ ctxProp.setValue(metaValue);
+
+ // Dispatch any runtime component property values
+ Object componentName = getComponentName(ctxProp);
+ ActivationPolicy policy = ctxProp.getActivationPolicy();
+
+ if (componentName != null && policy.equals(ActivationPolicy.IMMEDIATE))
+ {
+ getProxyFactory().getDispatcher().set(componentName, ctxProp.getName(), metaValue);
+ }
+ }
+
+ // TODO 1) finish implementation 2) just create ModificationAction
}
+
+ /**
+ * Get the component name from managed property.
+ *
+ * @param property the managed property
+ * @return component name or null if no coresponding component
+ */
+ protected Object getComponentName(ManagedProperty property)
+ {
+ // first check target
+ ManagedObject targetObject = property.getTargetManagedObject();
+ if (targetObject != null)
+ return targetObject.getComponentName();
+
+ // check owner
+ targetObject = property.getManagedObject();
+ return targetObject != null ? targetObject.getComponentName() : null;
+ }
+ /**
+ * Try to resolve the target profile.
+ *
+ * @param deploymentName the deployment name
+ * @return the profile
+ */
+ protected ProfileKey resolveProfile(String deploymentName)
+ {
+ for(ProfileViewWrapper view : views)
+ {
+ ProfileKey resolved = view.resolveProfile(deploymentName);
+ if(resolved != null)
+ {
+ return resolved;
+ }
+ }
+ return null;
+ }
+
}
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -285,8 +285,20 @@
*/
public void notify(ModificationEvent event)
{
- // nothing
+ // nothing here
}
+
+ public ProfileKey resolveProfile(String deploymentName)
+ {
+ for(RegisteredProfileView view : getViews())
+ {
+ if(view.getDeploymentNames().contains(deploymentName))
+ {
+ return view.getKey();
+ }
+ }
+ return null;
+ }
}
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -42,7 +42,7 @@
*
* @return the runtime component dispatcher
*/
- protected abstract RuntimeComponentDispatcher getDispatcher();
+ public abstract RuntimeComponentDispatcher getDispatcher();
/**
* Create a proxy component.
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -28,6 +28,7 @@
import org.jboss.managed.api.factory.ManagedObjectFactory;
import org.jboss.managed.plugins.jmx.ManagementFactoryUtils;
import org.jboss.profileservice.plugins.spi.ProfileView;
+import org.jboss.profileservice.spi.ProfileKey;
/**
* A ProfileView exposing the Platform MBeans as <code>ManagedComponents</code>.
@@ -98,5 +99,10 @@
}
}
+ public ProfileKey resolveProfile(String deploymentName)
+ {
+ return null;
+ }
+
}
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -22,6 +22,7 @@
package org.jboss.profileservice.plugins.spi;
import org.jboss.profileservice.plugins.management.util.ManagedDeploymentProcessorHelper;
+import org.jboss.profileservice.spi.ProfileKey;
/**
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
@@ -32,6 +33,14 @@
// FIXME
void setProcessorHelper(ManagedDeploymentProcessorHelper processorHelper);
+
+ /**
+ * Try to resolve the {@code Profile} for a given deployment.
+ *
+ * @param deploymentName the deployment
+ * @return the profile key, null if not resolvable
+ */
+ ProfileKey resolveProfile(String deploymentName);
}
Modified: projects/profileservice/trunk/plugins/src/test/java/org/jboss/test/profileservice/plugins/mgt/support/NoopManagementProxyFactory.java
===================================================================
--- projects/profileservice/trunk/plugins/src/test/java/org/jboss/test/profileservice/plugins/mgt/support/NoopManagementProxyFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/plugins/src/test/java/org/jboss/test/profileservice/plugins/mgt/support/NoopManagementProxyFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -58,7 +58,7 @@
}
@Override
- protected RuntimeComponentDispatcher getDispatcher()
+ public RuntimeComponentDispatcher getDispatcher()
{
return dispatcher;
}
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/ProfileFactory.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/ProfileFactory.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/ProfileFactory.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -40,7 +40,9 @@
String[] getTypes();
/**
- * Create a profile based on the meta data.
+ * Instantiate a profile based on the meta data. This does not need
+ * to call lifecycle methods, but should populate all values needed
+ * for Profile to run.
*
* @param key the profile key
* @param metaData the profile meta data
@@ -49,5 +51,13 @@
*/
X createProfile(ProfileKey key, T metaData) throws Exception;
+ /**
+ * Destroy a profile. This should cleanup all references which were
+ * needed for the creation.
+ *
+ * @param profile the profile to destroy
+ */
+ void destroyProfile(T metaData, X profile);
+
}
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepository.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepository.java 2010-03-11 10:38:57 UTC (rev 102273)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepository.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -22,9 +22,11 @@
package org.jboss.profileservice.spi;
import java.io.IOException;
+import java.util.Collection;
import org.jboss.profileservice.spi.repository.ArtifactId;
import org.jboss.profileservice.spi.repository.ArtifactRepository;
+import org.jboss.profileservice.spi.repository.ArtifactRepositoryId;
import org.jboss.profileservice.spi.virtual.VirtualDeploymentMetaData;
/**
@@ -35,6 +37,13 @@
*/
public interface VirtualDeploymentRepository
{
+
+ /**
+ * Get the associated repository ids.
+ *
+ * @return the artifact repository ids.
+ */
+ Collection<ArtifactRepositoryId> getRepositoryIDs();
/**
* Resolve a artifact repository for a given {@code ArtifactId}. For the resolution
Added: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepositoryExt.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepositoryExt.java (rev 0)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/VirtualDeploymentRepositoryExt.java 2010-03-11 10:59:19 UTC (rev 102274)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.profileservice.spi;
+
+/**
+ * mixin interface for virtual deployment repository holders.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface VirtualDeploymentRepositoryExt
+{
+
+ /**
+ * Get the virtual deployment repository.
+ *
+ * @return the virtual deployment repository
+ */
+ VirtualDeploymentRepository getDeploymentRepository();
+
+}
+
More information about the jboss-cvs-commits
mailing list