Index: deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ModuleDescriptor.java =================================================================== --- deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ModuleDescriptor.java (revision 37960) +++ deployment/dol/src/main/java/com/sun/enterprise/deployment/util/ModuleDescriptor.java (working copy) @@ -45,6 +45,10 @@ import java.util.Iterator; import java.util.Vector; import java.util.jar.Manifest; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.glassfish.deployment.versioning.VersioningService; +import org.glassfish.deployment.versioning.VersioningSyntaxException; /** * This class describes a module information for an applicaiton module @@ -185,10 +189,17 @@ * @return the module of this application */ public String getModuleName() { + String name = moduleName; + try{ if (moduleName == null) { - return DeploymentUtils.getDefaultEEName(path); + name = VersioningService.getUntaggedName(DeploymentUtils.getDefaultEEName(path)); + } else{ + name = VersioningService.getUntaggedName(moduleName); } - return moduleName; + } catch (VersioningSyntaxException ex) { + Logger.getLogger(ModuleDescriptor.class.getName()).log(Level.SEVERE, null, ex); + } + return name; } /** Index: deployment/dol/src/main/java/com/sun/enterprise/deployment/Application.java =================================================================== --- deployment/dol/src/main/java/com/sun/enterprise/deployment/Application.java (revision 37960) +++ deployment/dol/src/main/java/com/sun/enterprise/deployment/Application.java (working copy) @@ -67,6 +67,8 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.deployment.versioning.VersioningService; +import org.glassfish.deployment.versioning.VersioningSyntaxException; /** * Objects of this type encapsulate the data and behaviour of a J2EE @@ -660,6 +662,11 @@ * @return the EE app name of this application */ public String getAppName() { + try { + return VersioningService.getUntaggedName(appName); + } catch (VersioningSyntaxException ex) { + Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); + } return appName; } Index: deployment/dol/pom.xml =================================================================== --- deployment/dol/pom.xml (revision 37960) +++ deployment/dol/pom.xml (working copy) @@ -195,5 +195,10 @@ annotation-framework ${project.version} + + org.glassfish.deployment + deployment-versioning + ${project.version} + Index: deployment/versioning/src/test/java/org/glassfish/deployment/versioning/VersioningServiceTest.java =================================================================== --- deployment/versioning/src/test/java/org/glassfish/deployment/versioning/VersioningServiceTest.java (revision 37960) +++ deployment/versioning/src/test/java/org/glassfish/deployment/versioning/VersioningServiceTest.java (working copy) @@ -65,7 +65,6 @@ */ @Test public void testGetUntaggedName() throws VersioningSyntaxException { - VersioningService instance = new VersioningService(); // test an application name that contains a version expression // application name : foo:RC-* @@ -73,7 +72,7 @@ + VersioningService.EXPRESSION_SEPARATOR + "RC-" + VersioningService.EXPRESSION_WILDCARD; - String result = instance.getUntaggedName(expression); + String result = VersioningService.getUntaggedName(expression); assertEquals(APPLICATION_NAME, result); // test an application name that contains a version identifier @@ -81,14 +80,14 @@ expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "RC-1.0.0"; - result = instance.getUntaggedName(expression); + result = VersioningService.getUntaggedName(expression); assertEquals(APPLICATION_NAME, result); // test an application name that is an untagged version name // application name : foo expression = APPLICATION_NAME; - result = instance.getUntaggedName(expression); + result = VersioningService.getUntaggedName(expression); assertEquals(APPLICATION_NAME, result); // test an application name containing a critical pattern @@ -96,7 +95,7 @@ expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR; try { - result = instance.getUntaggedName(expression); + result = VersioningService.getUntaggedName(expression); fail("the getUntagged method did not throw a VersioningSyntaxException"); } catch(VersioningSyntaxException e){} @@ -113,7 +112,6 @@ */ @Test public void testGetExpression() throws VersioningSyntaxException { - VersioningService instance = new VersioningService(); // test an application name containing a critical pattern // application name : foo: @@ -121,7 +119,7 @@ + VersioningService.EXPRESSION_SEPARATOR; try { - String result = instance.getExpression(expression); + String result = VersioningService.getExpression(expression); fail("the getExpression method did not throw a VersioningSyntaxException"); } catch (VersioningSyntaxException e) {} @@ -134,7 +132,7 @@ + "0.0"; try { - String result = instance.getExpression(expression); + String result = VersioningService.getExpression(expression); //fail("the getExpression method did not throw a VersioningSyntaxException"); } catch (VersioningSyntaxException e) {} } @@ -145,9 +143,7 @@ * Check the extraction of a set of version(s) from a set of applications. */ @Test - public void testGetVersions() { - VersioningService instance = new VersioningService(); - + public void testGetVersions() throws VersioningException { // the set of applications List listApplications = new ArrayList(); listApplications.add(new ApplicationRefTest(APPLICATION_NAME)); @@ -174,7 +170,7 @@ expResult.add(APPLICATION_NAME+ VersioningService.EXPRESSION_SEPARATOR+"RC-1.0.0"); - List result = instance.getVersions(APPLICATION_NAME, listApplications); + List result = VersioningService.getVersions(APPLICATION_NAME, listApplications); assertEquals(expResult, result); } @@ -189,8 +185,6 @@ */ @Test public void testMatchExpression() throws VersioningException { - VersioningService instance = new VersioningService(); - // the set of all foo versions List listVersion = new ArrayList(); // ALPHA versions @@ -248,7 +242,7 @@ + VersioningService.EXPRESSION_SEPARATOR + VersioningService.EXPRESSION_WILDCARD; - List result = instance.matchExpression(listVersion, expression); + List result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ----------------------------- @@ -264,7 +258,7 @@ + VersioningService.EXPRESSION_WILDCARD + VersioningService.EXPRESSION_WILDCARD; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ***************************************************** @@ -292,7 +286,7 @@ + VersioningService.EXPRESSION_SEPARATOR + "RC" + VersioningService.EXPRESSION_WILDCARD; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // -------------------------- @@ -304,7 +298,7 @@ + VersioningService.EXPRESSION_WILDCARD + "RC" + VersioningService.EXPRESSION_WILDCARD; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ------------------------------- @@ -320,7 +314,7 @@ + VersioningService.EXPRESSION_WILDCARD + VersioningService.EXPRESSION_WILDCARD; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ******************************************************** @@ -342,7 +336,7 @@ + VersioningService.EXPRESSION_SEPARATOR + VersioningService.EXPRESSION_WILDCARD + "-1.0.2"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ---------------------------------- @@ -357,7 +351,7 @@ + VersioningService.EXPRESSION_WILDCARD + VersioningService.EXPRESSION_WILDCARD; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ---------------------------------- @@ -375,7 +369,7 @@ + VersioningService.EXPRESSION_WILDCARD + VersioningService.EXPRESSION_WILDCARD; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ************************************** @@ -392,7 +386,7 @@ expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "ALPHA-1.0.2"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(expResult, result); // ***************************************** @@ -415,37 +409,37 @@ expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "a*"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 3); expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "*a"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 0); expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "a****1"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 1); expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "*-*"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 6); expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "*-4"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 1); expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "b*"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 1); expression = APPLICATION_NAME + VersioningService.EXPRESSION_SEPARATOR + "b*"; - result = instance.matchExpression(listVersion, expression); + result = VersioningService.matchExpression(listVersion, expression); assertEquals(result.size(), 1); } @@ -455,18 +449,21 @@ */ @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); + try{ + VersioningService.checkIdentifier(appName); + } catch (VersioningSyntaxException e){ + fail(e.getMessage()); + } + String versionExpression = "BETA-*"; appName = "foo" + VersioningService.EXPRESSION_SEPARATOR + versionExpression; try { - instance.getIdentifier(appName); + VersioningService.checkIdentifier(appName); fail("the getIdentifier method should not accept version with '*' in it."); } catch (VersioningException e) {} } @@ -476,7 +473,6 @@ */ @Test public void testGetRepositoryName() throws VersioningSyntaxException { - VersioningService instance = new VersioningService(); String versionIdentifier = "RC-1.0.0"; // application name foo:RC-1.0.0 @@ -488,7 +484,7 @@ + VersioningService.REPOSITORY_DASH + versionIdentifier; - String result = instance.getRepositoryName(appName); + String result = VersioningService.getRepositoryName(appName); assertEquals(expectedResult, result); } Index: deployment/versioning/src/main/java/org/glassfish/deployment/versioning/VersioningService.java =================================================================== --- deployment/versioning/src/main/java/org/glassfish/deployment/versioning/VersioningService.java (revision 37960) +++ deployment/versioning/src/main/java/org/glassfish/deployment/versioning/VersioningService.java (working copy) @@ -37,7 +37,6 @@ import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.config.serverbeans.ApplicationRef; -import com.sun.enterprise.config.serverbeans.ConfigBeansUtilities; import com.sun.enterprise.util.LocalStringManagerImpl; import java.util.ArrayList; import java.util.Collections; @@ -48,7 +47,6 @@ import org.glassfish.api.I18n; import org.glassfish.api.admin.CommandRunner; import org.glassfish.api.admin.ParameterMap; -import org.glassfish.api.deployment.OpsParams.Origin; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Scoped; import org.jvnet.hk2.annotations.Service; @@ -90,21 +88,23 @@ * @throws VersioningSyntaxException if the given application name had some * critical patterns. */ - public final String getUntaggedName(String appName) + public static final String getUntaggedName(String appName) throws VersioningSyntaxException { - int colonIndex = appName.indexOf(EXPRESSION_SEPARATOR); - // if versioned - if (colonIndex != -1) { + if(appName != null && !appName.isEmpty()){ + int colonIndex = appName.indexOf(EXPRESSION_SEPARATOR); + // if versioned + if (colonIndex != -1) { - // if appName is ending with a colon - if (colonIndex == (appName.length() - 1)) { - throw new VersioningSyntaxException( - LOCALSTRINGS.getLocalString("invalid.appname", - "excepted version identifier after colon: {0}", - appName)); + // if appName is ending with a colon + if (colonIndex == (appName.length() - 1)) { + throw new VersioningSyntaxException( + LOCALSTRINGS.getLocalString("invalid.appname", + "excepted version identifier after colon: {0}", + appName)); + } + return appName.substring(0, colonIndex); } - return appName.substring(0, colonIndex); } // not versioned return appName; @@ -122,18 +122,12 @@ * @throws VersioningSyntaxException if the given application name had some * critical patterns. */ - public final String getExpression(String appName) + public static final String getExpression(String appName) throws VersioningSyntaxException { int colonIndex = appName.indexOf(EXPRESSION_SEPARATOR); // if versioned 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", @@ -146,15 +140,24 @@ return null; } - public final String getIdentifier(String appName) + /** + * Check a versionned application name. + * + * This method is used to provide consistant error messages for identifier + * aware operations. + * + * @param appName the application name + * @throws VersioningSyntaxException if the given application name had some + * critical patterns. + */ + public static final void checkIdentifier(String appName) throws VersioningSyntaxException { - String expression = getExpression(appName); - if (expression != null && expression.contains(EXPRESSION_WILDCARD)) { + String identifier = getExpression(appName); + if (identifier != null && identifier.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; } /** @@ -167,7 +170,7 @@ * @return all the version(s) of the given application in the given set of * applications */ - public List getVersions(String untaggedName, + public static final List getVersions(String untaggedName, List allApplicationRefs) { List allVersions = new ArrayList(); @@ -182,7 +185,6 @@ allVersions.add(ref.getRef()); } } - return allVersions; } @@ -195,7 +197,7 @@ * @param target the target where we want to get all the versions * @return all the version(s) of the given application */ - public List getAllversions(String untaggedName, String target) { + public final List getAllversions(String untaggedName, String target) { List allApplicationRefs = domain.getApplicationRefsInTarget(target); return getVersions(untaggedName, allApplicationRefs); @@ -244,7 +246,7 @@ * @throws VersioningException if the expression is an identifier matching * a version not registered, or if getExpression throws an exception */ - public final List matchExpression(List listVersion, String appName) + public static final List matchExpression(List listVersion, String appName) throws VersioningException { if (listVersion.size() == 0) { @@ -339,6 +341,13 @@ List allVersions = getAllversions(untagged, target); if (allVersions.size() == 0) { + // if versionned + if(!name.equals(untagged)){ + throw new VersioningException( + LOCALSTRINGS.getLocalString("application.noversion", + "Application {0} has no version registered", + untagged)); + } return Collections.EMPTY_LIST; } @@ -353,7 +362,7 @@ * @throws VersioningSyntaxException if getEpression and getUntaggedName * throws exception */ - public final String getRepositoryName(String appName) + public static final String getRepositoryName(String appName) throws VersioningSyntaxException { String expression = getExpression(appName); Index: deployment/admin/src/main/java/org/glassfish/deployment/admin/UndeployCommand.java =================================================================== --- deployment/admin/src/main/java/org/glassfish/deployment/admin/UndeployCommand.java (revision 37960) +++ deployment/admin/src/main/java/org/glassfish/deployment/admin/UndeployCommand.java (working copy) @@ -128,6 +128,14 @@ return; } + // if matched list is empty and no VersioningException thrown, + // this is an unversioned behavior and the given application is not registered + if(matchedVersions.isEmpty()){ + report.setMessage(localStrings.getLocalString("application.notreg","Application {0} not registered", name)); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + return; + } + // for each matched version Iterator it = matchedVersions.iterator(); while (it.hasNext()) { Index: deployment/admin/src/main/java/org/glassfish/deployment/admin/ShowComponentStatusCommand.java =================================================================== --- deployment/admin/src/main/java/org/glassfish/deployment/admin/ShowComponentStatusCommand.java (revision 37960) +++ deployment/admin/src/main/java/org/glassfish/deployment/admin/ShowComponentStatusCommand.java (working copy) @@ -103,19 +103,20 @@ return; } + // if matched list is empty and no VersioningException thrown, + // this is an unversioned behavior and the given application is not registered + if(matchedVersions.isEmpty()){ + report.setMessage(localStrings.getLocalString("application.notreg","Application {0} not registered", name)); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + return; + } + // for each matched version Iterator it = matchedVersions.iterator(); - while(it.hasNext()){ String appName = (String)it.next(); Application app = applications.getApplication(appName); - if (app == null) { - report.setMessage(localStrings.getLocalString("application.notreg","Application {0} not registered", appName)); - report.setActionExitCode(ActionReport.ExitCode.FAILURE); - return; - } - String status = "disabled"; // special target domain Index: core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java =================================================================== --- core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java (revision 37960) +++ core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java (working copy) @@ -142,9 +142,6 @@ Events events; @Inject - VersioningService versioningService; - - @Inject ConfigSupport configSupport; protected Logger logger = LogDomains.getLogger(AppServerStartup.class, LogDomains.CORE_LOGGER); @@ -1228,7 +1225,7 @@ String repositoryBitName = copy.params().name(); try { - repositoryBitName = versioningService.getRepositoryName(repositoryBitName); + repositoryBitName = VersioningService.getRepositoryName(repositoryBitName); } catch (VersioningSyntaxException e) { ActionReport report = copy.report(); report.setMessage(e.getMessage()); Index: appclient/server/core/src/main/java/org/glassfish/appclient/server/core/GetClientStubsCommand.java =================================================================== --- appclient/server/core/src/main/java/org/glassfish/appclient/server/core/GetClientStubsCommand.java (revision 37960) +++ appclient/server/core/src/main/java/org/glassfish/appclient/server/core/GetClientStubsCommand.java (working copy) @@ -85,18 +85,14 @@ @Param(primary=true) private String localDir; - @Inject - VersioningService versioningService; - public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); final Logger logger = context.getLogger(); try { - versioningService.getIdentifier(appname); + VersioningService.checkIdentifier(appname); } catch (VersioningSyntaxException ex) { - report.setMessage(ex.getLocalizedMessage()); - report.setActionExitCode(ActionReport.ExitCode.FAILURE); + report.failure(logger,ex.getMessage()); return; }