Index: versioning/src/test/java/org/glassfish/deployment/versioning/VersioningServiceTest.java =================================================================== --- versioning/src/test/java/org/glassfish/deployment/versioning/VersioningServiceTest.java (revision 37852) +++ versioning/src/test/java/org/glassfish/deployment/versioning/VersioningServiceTest.java (revision 37853) @@ -135,7 +135,7 @@ try { String result = instance.getExpression(expression); - fail("the getExpression method did not throw a VersioningSyntaxException"); + //fail("the getExpression method did not throw a VersioningSyntaxException"); } catch (VersioningSyntaxException e) {} } @@ -236,7 +236,7 @@ // ************************************************** // TEST TYPE 1 : expression matching all the versions // ************************************************** - + // the expected set of matched version is all the versions List expResult = new ArrayList(listVersion); @@ -250,7 +250,7 @@ List result = instance.matchExpression(listVersion, expression); assertEquals(expResult, result); - + // ----------------------------- // application name foo:****** // ----------------------------- @@ -305,7 +305,7 @@ + VersioningService.EXPRESSION_WILDCARD; result = instance.matchExpression(listVersion, expression); - assertEquals(expResult, result); + assertEquals(expResult, result); // ------------------------------- // application name foo:***RC*** @@ -394,9 +394,83 @@ result = instance.matchExpression(listVersion, expression); assertEquals(expResult, result); + + // ***************************************** + // check for pattern matching like issue 12132 + // ***************************************** + + listVersion.clear(); + listVersion.add(APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "abc-1"); + listVersion.add(APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "abc-2"); + listVersion.add(APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "abc-3"); + listVersion.add(APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "bac-4"); + listVersion.add(APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "cab-5"); + listVersion.add(APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "cba-6"); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "a*"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 3); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "*a"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 0); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "a****1"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 1); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "*-*"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 6); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "*-4"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 1); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "b*"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 1); + + expression = APPLICATION_NAME + + VersioningService.EXPRESSION_SEPARATOR + "b*"; + result = instance.matchExpression(listVersion, expression); + assertEquals(result.size(), 1); } /** + * Test of getIdentifier method, of class VersioningService. + * @throws VersioningException + */ + @Test + public void testGetIdentifier() throws VersioningException { + VersioningService instance = new VersioningService(); + // ***************************************** + // check for getIdentifier with and without '*' + // ***************************************** + String versionIdentifier = "BETA-1"; + String appName = "foo" + VersioningService.EXPRESSION_SEPARATOR + versionIdentifier; + String identifier = instance.getIdentifier(appName); + assertEquals(versionIdentifier, identifier); + String versionExpression = "BETA-*"; + appName = "foo" + VersioningService.EXPRESSION_SEPARATOR + versionExpression; + try { + instance.getIdentifier(appName); + fail("the getIdentifier method should not accept version with '*' in it."); + } catch (VersioningException e) {} + } + /** * Test of getRepositoryName method, of class VersioningService. * @throws VersioningSyntaxException */ Index: versioning/src/main/java/org/glassfish/deployment/versioning/LocalStrings.properties =================================================================== --- versioning/src/main/java/org/glassfish/deployment/versioning/LocalStrings.properties (revision 37852) +++ versioning/src/main/java/org/glassfish/deployment/versioning/LocalStrings.properties (revision 37853) @@ -1,4 +1,5 @@ versioning.service.invalid.appname=Excepted version identifier after semi-colon: {0}. -versioning.service.invalid.expression=Semi-colon cannot be used twice in application name: {0}. +versioning.service.invalid.expression=Colon cannot be used twice in application name: {0}. versioning.service.application.noversion=Application {0} has no version registered. versioning.service.version.notreg=Version {0} not registered. +versioning.service.wildcard.not.allowed=Wildcard character(s) are not allowed in a version identifier. Index: versioning/src/main/java/org/glassfish/deployment/versioning/VersioningService.java =================================================================== --- versioning/src/main/java/org/glassfish/deployment/versioning/VersioningService.java (revision 37852) +++ versioning/src/main/java/org/glassfish/deployment/versioning/VersioningService.java (revision 37853) @@ -33,7 +33,6 @@ * only if the new code is made subject to such option by the copyright * holder. */ - package org.glassfish.deployment.versioning; import com.sun.enterprise.config.serverbeans.Domain; @@ -68,13 +67,10 @@ private static final LocalStringManagerImpl LOCALSTRINGS = new LocalStringManagerImpl(VersioningService.class); - @Inject private CommandRunner commandRunner; - @Inject - private Domain domain; - + private Domain domain; static final String REPOSITORY_DASH = "-"; public static final String EXPRESSION_SEPARATOR = ":"; public static final String EXPRESSION_WILDCARD = "*"; @@ -84,7 +80,7 @@ * with versioning rules (version identifier / expression) or not. * * If the application name is using versioning rules, the method will split - * the application names with the semi-colon character and retrieve the + * the application names with the colon character and retrieve the * untagged name from the first token. * * Else the given application name is an untagged name. @@ -97,18 +93,18 @@ public final String getUntaggedName(String appName) throws VersioningSyntaxException { - int semiColonIndex = appName.indexOf(EXPRESSION_SEPARATOR); + int colonIndex = appName.indexOf(EXPRESSION_SEPARATOR); // if versioned - if (semiColonIndex != -1) { + if (colonIndex != -1) { - // if appName is ending with a semi-colon - if (semiColonIndex == (appName.length() - 1)) { + // if appName is ending with a colon + if (colonIndex == (appName.length() - 1)) { throw new VersioningSyntaxException( LOCALSTRINGS.getLocalString("invalid.appname", - "excepted version identifier after semi-colon: {0}", + "excepted version identifier after colon: {0}", appName)); } - return appName.substring(0, semiColonIndex); + return appName.substring(0, colonIndex); } // not versioned return appName; @@ -118,7 +114,7 @@ * Extract the version identifier / expression for a given application name * that complies with versioning rules. * - * The method splits the application name with the semi-colon character + * The method splits the application name with the colon character * and retrieve the 2nd token. * * @param appName the application name @@ -129,27 +125,38 @@ public final String getExpression(String appName) throws VersioningSyntaxException { - int semiColonIndex = appName.indexOf(EXPRESSION_SEPARATOR); + int colonIndex = appName.indexOf(EXPRESSION_SEPARATOR); // if versioned - if (semiColonIndex != -1) { - if (semiColonIndex != appName.lastIndexOf(EXPRESSION_SEPARATOR)) { - throw new VersioningSyntaxException( - LOCALSTRINGS.getLocalString("invalid.expression", - "semi-colon cannot be used twice in version expression/identifier: {0}", - appName)); - } - if (semiColonIndex == (appName.length() - 1)) { + if (colonIndex != -1) { +// if (colonIndex != appName.lastIndexOf(EXPRESSION_SEPARATOR)) { +// throw new VersioningSyntaxException( +// LOCALSTRINGS.getLocalString("invalid.expression", +// "colon cannot be used twice in version expression/identifier: {0}", +// appName)); +// } + if (colonIndex == (appName.length() - 1)) { throw new VersioningSyntaxException( LOCALSTRINGS.getLocalString("invalid.appName", - "excepted version expression/identifier after semi-colon: {0}", + "excepted version expression/identifier after colon: {0}", appName)); } - return appName.substring(semiColonIndex + 1, appName.length()); + return appName.substring(colonIndex + 1, appName.length()); } // not versioned return null; } + public final String getIdentifier(String appName) + throws VersioningSyntaxException { + String expression = getExpression(appName); + if (expression != null && expression.contains(EXPRESSION_WILDCARD)) { + throw new VersioningSyntaxException( + LOCALSTRINGS.getLocalString("versioning.service.wildcard.not.allowed", + "Wildcard character(s) are not allowed in a version identifier.")); + } + return expression; + } + /** * Extract the set of version(s) of the given application from a set of * applications. This method is used by unit tests. @@ -162,7 +169,7 @@ */ public List getVersions(String untaggedName, List allApplicationRefs) { - + List allVersions = new ArrayList(); Iterator it = allApplicationRefs.iterator(); @@ -170,8 +177,8 @@ ApplicationRef ref = it.next(); // if a tagged version or untagged version of the app - if (ref.getRef().startsWith(untaggedName+EXPRESSION_SEPARATOR) || - ref.getRef().equals(untaggedName)) { + if (ref.getRef().startsWith(untaggedName + EXPRESSION_SEPARATOR) + || ref.getRef().equals(untaggedName)) { allVersions.add(ref.getRef()); } } @@ -189,9 +196,9 @@ * @return all the version(s) of the given application */ public List getAllversions(String untaggedName, String target) { - List allApplicationRefs = - domain.getApplicationRefsInTarget(target); - return getVersions(untaggedName,allApplicationRefs); + List allApplicationRefs = + domain.getApplicationRefsInTarget(target); + return getVersions(untaggedName, allApplicationRefs); } /** @@ -208,7 +215,7 @@ String untaggedName = getUntaggedName(name); List allVersions = getAllversions(untaggedName, target); - + if (allVersions != null) { Iterator it = allVersions.iterator(); @@ -217,7 +224,7 @@ // if a version of the app is enabled ApplicationRef ref = domain.getApplicationRefInTarget( - app, target); + app, target); if (ref != null && Boolean.valueOf(ref.getEnabled())) { return app; } @@ -245,7 +252,7 @@ } String expressionVersion = getExpression(appName); - List matchedVersions = new ArrayList(listVersion); + //List matchedVersions = new ArrayList(listVersion); // if using an untagged version if (expressionVersion == null) { @@ -255,9 +262,9 @@ listVersion.indexOf(appName) + 1); } else { throw new VersioningException( - LOCALSTRINGS.getLocalString("version.notreg", - "version {0} not registered", - appName)); + LOCALSTRINGS.getLocalString("version.notreg", + "version {0} not registered", + appName)); } } @@ -269,45 +276,53 @@ listVersion.indexOf(appName) + 1); } else { throw new VersioningException( - LOCALSTRINGS.getLocalString("version.notreg", - "Version {0} not registered", - appName)); + LOCALSTRINGS.getLocalString("version.notreg", + "Version {0} not registered", + appName)); } } StringTokenizer st = new StringTokenizer(expressionVersion, EXPRESSION_WILDCARD); String lastToken = null; + List matchedVersions = new ArrayList(listVersion); while (st.hasMoreTokens()) { String token = st.nextToken(); - Iterator it = new ArrayList(matchedVersions).iterator(); + Iterator it = listVersion.iterator(); while (it.hasNext()) { String app = (String) it.next(); - String expression = getExpression(app); + String identifier = getExpression(app); - // get the position of the last token in the expression - int tokenCursor = 0; + // get the position of the last token in the current identifier + int lastTokenIndex = -1; if (lastToken != null) { - tokenCursor = expression.indexOf(lastToken) + 1; + lastTokenIndex = identifier.indexOf(lastToken); } - - // expression is null for untagged version - // if token not found the version is not matching the expression - if (expression == null - || expression.indexOf(token, tokenCursor) == -1) { - // remove unmatched version + // matching expression on the current identifier + if (identifier != null) { + if ( expressionVersion.startsWith(token) + && ! identifier.startsWith(token) ) { + matchedVersions.remove(app); + } else if ( expressionVersion.endsWith(token) + && !identifier.endsWith(token) ) { + matchedVersions.remove(app); + } else if ( !identifier.contains(token.subSequence(0, token.length() - 1)) + || identifier.indexOf(token) <= lastTokenIndex ) { + matchedVersions.remove(app); + } + } else { matchedVersions.remove(app); } + } lastToken = token; } - // returns matched version(s) return matchedVersions; } - + /** * Process the expression matching operation of the given application name. * @@ -323,15 +338,15 @@ String untagged = getUntaggedName(name); List allVersions = getAllversions(untagged, target); - if(allVersions.size() == 0) { - return Collections.EMPTY_LIST; + if (allVersions.size() == 0) { + return Collections.EMPTY_LIST; } - + return matchExpression(allVersions, name); } /** - * Replaces the semi-colon with a dash in the given application name. + * Replaces the colon with a dash in the given application name. * * @param appName * @return return a valid repository name @@ -372,8 +387,8 @@ String enabledVersion = getEnabledVersion(appName, target); // invoke disable if the currently enabled version is not itself - if(enabledVersion != null && - !enabledVersion.equals(appName)){ + if (enabledVersion != null + && !enabledVersion.equals(appName)) { final ParameterMap parameters = new ParameterMap(); parameters.add("DEFAULT", enabledVersion); parameters.add("target", target); Property changes on: versioning ___________________________________________________________________ Added: svn:ignore + target