Skip to content

Commit

Permalink
Merge pull request #1118 from BladeRunnerJS/v0.14.2-patch-release2
Browse files Browse the repository at this point in the history
V0.14.2 patch release #2
  • Loading branch information
thecapdan committed Dec 3, 2014
2 parents be9711f + 98f68f5 commit a4b6b2c
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 28 deletions.
3 changes: 2 additions & 1 deletion brjs-core/src/main/java/org/bladerunnerjs/model/AppConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public AppConf(App app) throws ConfigException {
}

public String getRequirePrefix() throws ConfigException {
return getConf().requirePrefix;
return getConf().requirePrefix();
}

public void setRequirePrefix(String requirePrefix) throws ConfigException {
getConf().requirePrefix = requirePrefix;
getConf().appNamespace = null;
verifyAndAutoWrite();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ public String getPrimaryRequirePath() {
public Map<String,String> getLocaleProperties() throws IOException, RequirePathException, NamespaceException
{
Map<String, String> propertiesMap = new HashMap<String,String>();

Properties i18nProperties = new Properties();
i18nProperties.load( new UnicodeReader(assetFile, defaultFileCharacterEncoding) );

for (String property : i18nProperties.stringPropertyNames())
{
assetLocation().assertIdentifierCorrectlyNamespaced(property);
String value = i18nProperties.getProperty(property);
propertiesMap.put(property, value.replaceAll("\n", "\\\\n"));
try(Reader propertiesReader = new UnicodeReader(assetFile, defaultFileCharacterEncoding)) {
i18nProperties.load( propertiesReader );

for (String property : i18nProperties.stringPropertyNames())
{
assetLocation().assertIdentifierCorrectlyNamespaced(property);
String value = i18nProperties.getProperty(property);
propertiesMap.put(property, value.replaceAll("\n", "\\\\n"));
}
}

return propertiesMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public void writeBundle(List<Asset> xmlAssets, final Writer writer) throws Conte
{
for(XmlSiblingReader siblingReader : siblingReaders)
{
siblingReader.close();
try {
siblingReader.close();
}
catch(XMLStreamException e) {
// do nothing: we want to close as many readers as possible
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ public void call() throws Exception {

return commanderChainer;
}

public CommanderChainer appConfHasBeenRead() {
call(new Command() {
public void call() throws Exception {
app.appConf();
}
});

return commanderChainer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AppConfCommander(SpecTest modelTest, AppConf appConf) {
this.appConf = appConf;
}

public AppConfCommander setAppNamespace(final String requirePrefix) throws Exception {
public AppConfCommander setRequirePrefix(final String requirePrefix) throws Exception {
call(new Command() {
public void call() throws Exception {
appConf.setRequirePrefix(requirePrefix);
Expand Down
27 changes: 23 additions & 4 deletions brjs-core/src/main/java/org/bladerunnerjs/yaml/YamlAppConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.validation.constraints.NotNull;

import org.apache.bval.constraints.NotEmpty;
import org.bladerunnerjs.logging.Logger;
import org.bladerunnerjs.model.BRJSNode;
import org.bladerunnerjs.model.exception.ConfigException;
import org.bladerunnerjs.model.exception.name.InvalidPackageNameException;
Expand All @@ -12,8 +13,11 @@


public class YamlAppConf extends AbstractYamlConfFile {
@NotNull
@NotEmpty
public class Messages {
public static final String APP_NAMESPACE_PROPERTY_DEPRECATED = "The 'appNamespace' property within 'app.conf' is deprecated, and it should be renamed to 'requirePrefix' instead.";
}

public String appNamespace;
public String requirePrefix;

@NotNull
Expand All @@ -24,22 +28,37 @@ public class YamlAppConf extends AbstractYamlConfFile {

@Override
public void initialize(BRJSNode node) {
requirePrefix = getDefault(requirePrefix, "appns");
if((appNamespace == null) && (requirePrefix == null)) {
requirePrefix = "appns";
}
else if(appNamespace != null) {
Logger logger = node.root().getLoggerFactory().getLogger(YamlAppConf.class);
logger.warn(Messages.APP_NAMESPACE_PROPERTY_DEPRECATED);
}

locales = getDefault(locales, "en");
localeCookieName = getDefault(localeCookieName, "BRJS.LOCALE");
}

@Override
public void verify() throws ConfigException {
try {
if((appNamespace != null) && (requirePrefix != null)) throw new ConfigException("The 'appNamespace' and 'requirePrefix' properties within 'app.conf' should not both be defined.");
if(requirePrefix() == null) throw new ConfigException("The 'requirePrefix' property within 'app.conf' must be defined.");
if(requirePrefix().equals("")) throw new ConfigException("'requirePrefix' may not be empty");

ConfigValidationChecker.validate(this);
NameValidator.assertValidPackageName(node, requirePrefix);
NameValidator.assertValidPackageName(node, requirePrefix());
verifyLocales(locales);
}
catch(InvalidPackageNameException e) {
throw new ConfigException(e);
}
}

public String requirePrefix() {
return (requirePrefix != null) ? requirePrefix : appNamespace;
}

private void verifyLocales(String locales) throws ConfigException {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.bladerunnerjs.spec.app;

import static org.bladerunnerjs.yaml.YamlAppConf.Messages.*;

import org.bladerunnerjs.model.App;
import org.bladerunnerjs.model.exception.ConfigException;
import org.bladerunnerjs.model.exception.name.InvalidPackageNameException;
Expand Down Expand Up @@ -34,6 +36,24 @@ public void appConfWillHaveSensibleDefaultsIfItDoesntAlreadyExist() throws Excep
then(app).fileHasContents("app.conf", "localeCookieName: BRJS.LOCALE\nlocales: en\nrequirePrefix: appns");
}

@Test
public void requirePrefixCanAlsoBeSetUsingLegacyAppNamespaceProperty() throws Exception {
given(app).hasBeenCreated()
.and(logging).enabled()
.and(app).containsFileWithContents("app.conf", "appNamespace: requireprefix");
when(app).appConfHasBeenRead();
then(app.appConf().getRequirePrefix().toString()).textEquals("requireprefix")
.and(logging).warnMessageReceived(APP_NAMESPACE_PROPERTY_DEPRECATED);
}

@Test
public void havingBothARequirePrefixAndAnAppNamespacePropertyCausesAnException() throws Exception {
given(app).hasBeenCreated()
.and(app).containsFileWithContents("app.conf", "appNamespace: requireprefix\nrequirePrefix: requireprefix");
when(app).appConfHasBeenRead();
then(exceptions).verifyException(ConfigException.class, "appNamespace", "requirePrefix");
}

@Ignore
@Test
public void exceptionThrownWhenSettingInvalidAppNameAsDefaultNamespace() throws Exception {
Expand All @@ -50,21 +70,21 @@ public void updateLocaleInAppConf() throws Exception {
}

@Test
public void updateAppNamespaceInAppConf() throws Exception {
public void updateRequirePrefixInAppConf() throws Exception {
given(app).hasBeenPopulated("appx");
when(app).appConf().setAppNamespace("newns").write();
when(app).appConf().setRequirePrefix("newns").write();
then(app).fileHasContents("app.conf", "localeCookieName: BRJS.LOCALE\nlocales: en\nrequirePrefix: newns");
}

@Test
public void settingAppNamespaceToJSKeywordCausesException() throws Exception {
when(app).appConf().setAppNamespace("try");
public void settingRequirePrefixToJSKeywordCausesException() throws Exception {
when(app).appConf().setRequirePrefix("try");
then(exceptions).verifyException(InvalidPackageNameException.class, "try", app.dir().getPath());
}

@Test
public void settingAppNamespaceToReservedWordIsAllowedInConf() throws Exception {
when(app).appConf().setAppNamespace("caplin");
public void settingRequirePrefixToReservedWordIsAllowedInConf() throws Exception {
when(app).appConf().setRequirePrefix("caplin");
then(exceptions).verifyNoOutstandingExceptions();
}

Expand All @@ -76,7 +96,7 @@ public void readingAnAppConfFileWithMissingLocaleWillUseADefault() throws Except
}

@Test
public void readingAnAppConfFileWithMissingAppNamespaceWillUseADefault() throws Exception{
public void readingAnAppConfFileWithMissingRequirePrefixWillUseADefault() throws Exception{
given(app).hasBeenCreated()
.and(app).containsFileWithContents("app.conf", "\nlocales: en");
then(app.appConf().getRequirePrefix()).textEquals("appns");
Expand All @@ -91,11 +111,11 @@ public void readingAnAppConfFileWithEmptyLocaleWillCauseAnException() throws Exc
}

@Test
public void readingAnAppConfFileWithEmptyAppNamespaceWillCauseAnException() throws Exception {
public void readingAnAppConfFileWithEmptyRequirePrefixWillCauseAnException() throws Exception {
given(app).hasBeenCreated()
.and(app).containsFileWithContents("app.conf", "requirePrefix: \nlocales: en");
when(app).appConf();
then(exceptions).verifyException(ConfigException.class, app.file("app.conf").getPath(), unquoted("'requirePrefix' may not be empty"));
then(exceptions).verifyException(ConfigException.class, unquoted("'requirePrefix' may not be empty"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/


/*
* NOTE: This class is used by the code generated in AppRequestHandler.java.
/*
* NOTE: This class is used by the code generated in AppRequestHandler.java.
* If this class changes then the code generated by AppRequestHandler needs to change.
*/

Expand All @@ -26,7 +26,16 @@ LocaleUtility.getBrowserAcceptedLocales = function() {
userAcceptedLocales = [navigator.language];
}
else {
userAcceptedLocales = [navigator.userLanguage];
var parts = navigator.userLanguage.split('-');
var locale = (parts.length == 1) ? parts[0] : parts[0] + '-' + parts[1].toUpperCase()

userAcceptedLocales = [locale];
}

// convert locale codes to use underscores like we do on the server
for(var i = 0, l = userAcceptedLocales.length; i < l; ++i) {
var userAcceptedLocale = userAcceptedLocales[i];
userAcceptedLocales[i] = userAcceptedLocale.replace('-', '_');
}

return userAcceptedLocales;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ br.presenter.validator.ValidSelectionValidator.prototype.validate = function(vVa
bIsValid = true;
sValidationMessage = i18n("br.presenter.validator.invalidSelectionsAllowed");
}
else if(vValue !== null)
else if(vValue !== null && typeof(vValue) !== 'undefined')
{
var pOptions = this.m_oOptions.getOptions();
for(var i = 0; i < pOptions.length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ ValidSelectionValidatorTest.prototype.test_nonExistentOptionValuesFailValidation
assertFalse("1a", oValidationResult.isValid());
};

ValidSelectionValidatorTest.prototype.test_canCorrectlyValidateWhenValueIsUndefined = function()
{
var oValidationResult = new br.presenter.validator.ValidationResult();
this.oValidSelectionValidator.validate(undefined, {}, oValidationResult);
assertFalse("1a", oValidationResult.isValid());
};

ValidSelectionValidatorTest.prototype.test_weCanAllowInvalidSelectionsToPassValidations = function()
{
var oValidationResult = new br.presenter.validator.ValidationResult();
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions releases/v0.14.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"milestone": "0.14.2",
"name": "BladeRunnerJS @tagVersion@",
"prerelease": "false"
}
14 changes: 14 additions & 0 deletions releases/v0.14.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## BladeRunnerJS @tagVersion@

### @tagVersion@ Features and Improvements

The following changes were made in 0.14.2:

* We no longer leave open read-locks on XML and I18N configuration files.
* We've added backwards compatibility support for the `appNamespace` property within 'app.conf', so that existing motif zips can continue to be imported into BladeRunnerJS.
* We fixed a couple of bugs within our client-side locale switching code, so that it now works as best as it can in all browsers.
* We fixed a regression that was introduced into the `ValidSelectionValidator` class in 0.14.1.

### Known Issues

When switching between a workbench and an app, the alias blob will occasionally point at an incorrect class. Refreshing the page usually corrects the problem.

0 comments on commit a4b6b2c

Please sign in to comment.