[jboss-cvs] JBossAS SVN: r100156 - in branches/JBPAPP_5_0: testsuite/src/main/org/jboss/test/deployers and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 29 21:40:00 EST 2010
Author: miclark
Date: 2010-01-29 21:40:00 -0500 (Fri, 29 Jan 2010)
New Revision: 100156
Added:
branches/JBPAPP_5_0/system/src/main/org/jboss/system/deployers/LegacyPrefixDeploymentContextComparator.java
branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/LegacyPrefixDeploymentContextComparatorTestCase.java
Log:
JBPAPP-3496: Added LegacyPrefixDeployerContextComparator and test case to re-introduce the old PrefixDeploymentSorter functionality.
Added: branches/JBPAPP_5_0/system/src/main/org/jboss/system/deployers/LegacyPrefixDeploymentContextComparator.java
===================================================================
--- branches/JBPAPP_5_0/system/src/main/org/jboss/system/deployers/LegacyPrefixDeploymentContextComparator.java (rev 0)
+++ branches/JBPAPP_5_0/system/src/main/org/jboss/system/deployers/LegacyPrefixDeploymentContextComparator.java 2010-01-30 02:40:00 UTC (rev 100156)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. 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.system.deployers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.helpers.DefaultDeploymentContextComparator;
+
+/**
+ * Orders deployments based on numeric prefixes.
+ *
+ * <p>This class is a comparator to sort deployment s based on the existence
+ * of a numeric prefix. The name portion of the URL is evaluated for any
+ * leading digits. If they exist, then they will define a numerical ordering
+ * for this comparator. If there is no leading digits, then they will
+ * compare as less than any name with leading digits. In the case of a
+ * tie, the order is determined by the behavior of the
+ * {@link LegacyDeploymentContextComparator} superclass.
+ *
+ * <p>The behavior of this comparator is to reproduce the behavior of the
+ * PrefixDeploymentSorter in JBoss 4.x.
+ *
+ * <p>For example, these names are in ascending order:
+ * <ul>
+ * <li>test.sar</li>
+ * <li>component.ear</li>
+ * <li>001test.jar</li>
+ * <li>5test.rar</li>
+ * <li>5foo.jar</li>
+ * <li>120bar.jar</li>
+ * </ul>
+ *
+ * @author <a href="mailto:miclark at redhat.com">Mike M. Clark</a>
+ *
+ * @version $Revision: $
+ */
+public class LegacyPrefixDeploymentContextComparator extends LegacyDeploymentContextComparator
+{
+ /** The instance */
+ public static final LegacyPrefixDeploymentContextComparator INSTANCE = new LegacyPrefixDeploymentContextComparator();
+
+
+ /**
+ * Get the instance.
+ *
+ * @return the instance
+ */
+ public static LegacyPrefixDeploymentContextComparator getInstance()
+ {
+ return INSTANCE;
+ }
+
+ @Override
+ public int compare(DeploymentContext first, DeploymentContext second)
+ {
+ int firstPrefixValue = getPrefixValue(first);
+ int secondPrefixValue = getPrefixValue(second);
+ int diff = firstPrefixValue - secondPrefixValue;
+ if (diff != 0)
+ {
+ return diff;
+ }
+ else
+ {
+ return super.compare(first, second);
+ }
+ }
+
+ private int getPrefixValue(DeploymentContext deploymentContext)
+ {
+ String name = deploymentContext.getSimpleName();
+
+ // calculate where the digit-prefix ends
+ int prefixEnd = 0;
+ int nameEnd = name.length() - 1;
+
+ while (prefixEnd <= nameEnd && Character.isDigit(name.charAt(prefixEnd)))
+ {
+ ++prefixEnd;
+ }
+
+ // If zero length prefix, return -1
+ if (prefixEnd == 0)
+ {
+ return -1;
+ }
+
+ // Strip leading zeros
+ int nameStart = 0;
+ while (nameStart < prefixEnd && name.charAt(nameStart) == '0')
+ {
+ ++nameStart;
+ }
+
+ return (nameStart == prefixEnd) ? 0 : Integer.parseInt(name.substring(nameStart, prefixEnd));
+ }
+}
Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/LegacyPrefixDeploymentContextComparatorTestCase.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/LegacyPrefixDeploymentContextComparatorTestCase.java (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/LegacyPrefixDeploymentContextComparatorTestCase.java 2010-01-30 02:40:00 UTC (rev 100156)
@@ -0,0 +1,508 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.deployers;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.MutableMetaData;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.system.deployers.LegacyPrefixDeploymentContextComparator;
+import org.jboss.test.JBossTestCase;
+
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
+import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Tests for the {@link org.jboss.system.deployers.LegacyPrefixDeploymentContextComparator}.
+ * (Test for JBPAPP-3496.)
+ *
+ * @author <a href="mailto:miclark at redhat.com">Mike M. Clark</a>
+ *
+ * @version $Revision: $
+ */
+public class LegacyPrefixDeploymentContextComparatorTestCase extends JBossTestCase
+{
+ private Comparator<DeploymentContext> comparator = null;
+
+ public LegacyPrefixDeploymentContextComparatorTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp()
+ {
+ LegacyPrefixDeploymentContextComparator prefixComparator = new LegacyPrefixDeploymentContextComparator();
+ prefixComparator.create();
+ comparator = prefixComparator;
+ }
+
+ /**
+ * Verifies leading zeros are ignored.
+ */
+ public void testLeadingZerosIgnored()
+ {
+ DeploymentContext first = new TestDeploymentContext("001test.ear");
+ DeploymentContext second = new TestDeploymentContext("21test.ear");
+ DeploymentContext third = new TestDeploymentContext("0132test.ear");
+
+
+ }
+
+ /**
+ * Verifies straight-forward ordering.
+ */
+ public void testPrefixOrdering()
+ {
+ DeploymentContext first = new TestDeploymentContext("1test.ear");
+ DeploymentContext second = new TestDeploymentContext("21test.ear");
+ DeploymentContext third = new TestDeploymentContext("132test.ear");
+
+ ValidateFirstSecondThird(first, second, third);
+ }
+
+ /**
+ * Verifies that a prefix tie is ordered based on the suffix.
+ */
+ public void testSuffixFallback()
+ {
+ DeploymentContext first = new TestDeploymentContext("123test.sar");
+ DeploymentContext second = new TestDeploymentContext("123test.ear");
+
+ assertTrue("Second comes before first", comparator.compare(first, second) < 0);
+ assertTrue("First comes after second", comparator.compare(second, first) > 0);
+ }
+
+ /**
+ * Verifies suffix configuration.
+ */
+ public void testSuffixOrderChange()
+ {
+ Map<String, Integer> suffixOrder = new HashMap<String, Integer>();
+ suffixOrder.put(".sar", 700);
+ LegacyPrefixDeploymentContextComparator prefixComparator = new LegacyPrefixDeploymentContextComparator();
+ prefixComparator.setSuffixOrder(suffixOrder);
+ prefixComparator.create();
+
+ Comparator<DeploymentContext> changedSuffix = prefixComparator;
+
+ DeploymentContext first = new TestDeploymentContext("test.ear");
+ DeploymentContext second = new TestDeploymentContext("test.sar");
+
+ assertTrue("Second comes before first", changedSuffix.compare(first, second) < 0);
+ assertTrue("First comes after second", changedSuffix.compare(second, first) > 0);
+ }
+
+ /**
+ * Verifies order indicated in
+ * {@link org.jboss.system.deployers.LegacyPrefixDeploymentContextComparator}
+ * javadoc.
+ */
+ public void testJavaDocExample()
+ {
+ DeploymentContext first = new TestDeploymentContext("test.sar");
+ DeploymentContext second = new TestDeploymentContext("component.ear");
+ DeploymentContext third = new TestDeploymentContext("001test.jar");
+ DeploymentContext fourth = new TestDeploymentContext("5test.rar");
+ DeploymentContext fifth = new TestDeploymentContext("5foo.jar");
+ DeploymentContext sixth = new TestDeploymentContext("120bar.jar");
+
+ assertTrue("Second comes before first", comparator.compare(first, second) < 0);
+ assertTrue("Third comes before second", comparator.compare(second, third) < 0);
+ assertTrue("Fourth comes before third", comparator.compare(third, fourth) < 0);
+ assertTrue("Fifth comes before fourth", comparator.compare(fourth, fifth) < 0);
+ assertTrue("Sixth comes before fifth", comparator.compare(fifth, sixth) < 0);
+ }
+
+ /**
+ * Verifies non-prefixed deployments occur before prefixed deployments
+ */
+ public void testNonPrefixPrefixOrdering()
+ {
+ DeploymentContext first = new TestDeploymentContext("test.sar");
+ DeploymentContext second = new TestDeploymentContext("test.ear");
+ DeploymentContext third = new TestDeploymentContext("132test.ear");
+
+ ValidateFirstSecondThird(first, second, third);
+ }
+
+ private void ValidateFirstSecondThird(DeploymentContext first, DeploymentContext second, DeploymentContext third)
+ {
+ assertTrue("Second comes before first", comparator.compare(first, second) < 0);
+ assertTrue("Third comes before first", comparator.compare(first, third) < 0);
+ assertTrue("Third comes before second", comparator.compare(second, third) < 0);
+ assertTrue("First comes after second", comparator.compare(second, first) > 0);
+ assertTrue("First comes after third", comparator.compare(third, first) > 0);
+ assertTrue("Second comes after third", comparator.compare(third, second) > 0);
+ assertTrue("First does not tie itself", comparator.compare(first, first) == 0);
+ }
+
+ private class TestDeploymentContext implements DeploymentContext
+ {
+ private int relativeOrder = 0;
+ private String simpleName = null;
+
+ public TestDeploymentContext(String simpleName)
+ {
+ this.simpleName = simpleName;
+ }
+
+ @Override
+ public void addChild(DeploymentContext child)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addComponent(DeploymentContext component)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addControllerContextName(Object name)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void cleanup()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void deployed()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<DeploymentContext> getChildren()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ClassLoader getClassLoader()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Comparator<DeploymentContext> getComparator()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<DeploymentContext> getComponents()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getControllerContextName()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<Object> getControllerContextNames()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DependencyInfo getDependencyInfo()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Deployment getDeployment()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DeploymentUnit getDeploymentUnit()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public MetaData getMetaData()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public MutableMetaData getMutableMetaData()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ScopeKey getMutableScope()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getName()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DeploymentContext getParent()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Throwable getProblem()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getRelativeOrder()
+ {
+ return relativeOrder;
+ }
+
+ @Override
+ public String getRelativePath()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DeploymentStage getRequiredStage()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ClassLoader getResourceClassLoader()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DeploymentResourceLoader getResourceLoader()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ScopeKey getScope()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getSimpleName()
+ {
+ return simpleName;
+ }
+
+ @Override
+ public DeploymentState getState()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DeploymentContext getTopLevel()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isComponent()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isDeployed()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isTopLevel()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean removeChild(DeploymentContext child)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeClassLoader()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeClassLoader(ClassLoaderFactory factory)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean removeComponent(DeploymentContext component)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeControllerContextName(Object name)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setClassLoader(ClassLoader classLoader)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setComparator(Comparator<DeploymentContext> comparator)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setDeployment(Deployment deployment)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setDeploymentUnit(DeploymentUnit unit)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setMutableScope(ScopeKey key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setParent(DeploymentContext parent)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setProblem(Throwable problem)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setRelativeOrder(int relativeOrder)
+ {
+ this.relativeOrder = relativeOrder;
+ }
+
+ @Override
+ public void setRequiredStage(DeploymentStage stage)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setScope(ScopeKey key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setState(DeploymentState state)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void visit(DeploymentContextVisitor visitor) throws DeploymentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public MutableAttachments getTransientAttachments()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public MutableAttachments getTransientManagedObjects()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Attachments getPredeterminedManagedObjects()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setPredeterminedManagedObjects(Attachments predetermined)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list