Skip to content

Commit

Permalink
Merge pull request #1319 from BladeRunnerJS/v0.15.4-release
Browse files Browse the repository at this point in the history
V0.15.4 release
  • Loading branch information
thanhc committed Apr 7, 2015
2 parents bc73b5c + 1d89e81 commit bd82eac
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,23 @@ public void allTestDirectoriesAreCorrectlyReNamespacedWhenImported() throws Exce
@Test
public void oldAppNamePrefixedAndFollowedByASlashIsReplacedInJettyEnv() throws Exception {
given(app).hasBeenCreated()
.and(app).containsFileWithContents("WEB-INF/jetty-env.xml", "/app/some-url" )
.and(app).containsFileWithContents("WEB-INF/jetty-env.xml", "/app/some-url" )
.and(brjs).commandHasBeenRun("export-app", "app")
.and(appJars).containsFile("brjs-lib1.jar");
when(brjs).runCommand("import-app", "../generated/exported-apps/app.zip", "imported-app", "importedns");
then(importedApp).fileContentsContains("WEB-INF/jetty-env.xml", "/imported-app/some-url");
}

@Test
public void jndiConfigUrlIsRenamespaced() throws Exception {
given( brjs.app("myapp") ).hasBeenCreated()
.and( brjs.app("myapp") ).containsFileWithContents("WEB-INF/jetty-env.xml", "jdbc:h2:../generated/app/myapp/somedb/myapp;someDB=config" )
.and(brjs).commandHasBeenRun("export-app", "myapp")
.and(appJars).containsFile("brjs-lib1.jar");
when(brjs).runCommand("import-app", "../generated/exported-apps/myapp.zip", "imported-app", "importedns");
then(importedApp).fileContentsEquals("WEB-INF/jetty-env.xml", "jdbc:h2:../generated/app/imported-app/somedb/imported-app;someDB=config");
}

@Test
public void oldAppNamePrefixedByASlashAndFollowedByASemicolonIsReplacedInJettyEnv() throws Exception {
given(app).hasBeenCreated()
Expand Down Expand Up @@ -260,4 +270,43 @@ public void oldAppNameIsReplacedInABladesetlessBladeAliasesXml() throws Exceptio
"<alias name=\"bar.user-prompt-service\" class=\"importedns.myblade.MyUserPromptService\"/>");
}

@Test // test to replicate bugs from https://github.com/BladeRunnerJS/brjs/issues/1315
public void contentIsCorrectlyRenamespacedWhenOldNamespacesArePrecededWithASlash() throws Exception {
given(app).hasBeenCreated()
.and(app.defaultBladeset().blade("myblade")).containsFileWithContents("resources/aliases.xml",
"<appns.myblade.SomeTag>tag content</appns.myblade.SomeTag>")
.and(brjs).commandHasBeenRun("export-app", "app")
.and(appJars).containsFile("brjs-lib1.jar");
when(brjs).runCommand("import-app", "../generated/exported-apps/app.zip", "imported-app", "importedns");
then(importedApp.defaultBladeset().blade("myblade")).fileContentsContains("resources/aliases.xml",
"<importedns.myblade.SomeTag>tag content</importedns.myblade.SomeTag>");
}

@Test // test to replicate bugs from https://github.com/BladeRunnerJS/brjs/issues/1315
public void contentIsCorrectlyRenamespacedWhenTheFileContainsAPoundSign() throws Exception {
given(app).hasBeenCreated()
.and(app.defaultBladeset().blade("myblade")).containsFileWithContents("resources/aliases.xml",
"<appns.myblade.SomeTag>tag £££ content</appns.myblade.SomeTag>")
.and(app.defaultBladeset().blade("myblade").testType("unit").defaultTestTech()).containsFileWithContents("tests/Test.js", "££££ appns.myblade.SomeClass")
.and(brjs).commandHasBeenRun("export-app", "app")
.and(appJars).containsFile("brjs-lib1.jar");
when(brjs).runCommand("import-app", "../generated/exported-apps/app.zip", "imported-app", "importedns");
then(importedApp.defaultBladeset().blade("myblade")).fileContentsContains("resources/aliases.xml",
"<importedns.myblade.SomeTag>tag £££ content</importedns.myblade.SomeTag>")
.and(importedApp.defaultBladeset().blade("myblade")).fileContentsContains("test-unit/tests/Test.js",
"££££ importedns.myblade.SomeClass");

}

@Test
public void imagesArentCorrupOnImport() throws Exception {
given(app).hasBeenCreated()
.and(aspect).hasBeenCreated()
.and(aspect).containsFileCopiedFrom("resources/br-logo.png", "src/test/resources/br-logo.png")
.and(brjs).commandHasBeenRun("export-app", "app")
.and(appJars).containsFile("brjs-lib1.jar");
when(brjs).runCommand("import-app", "../generated/exported-apps/app.zip", "imported-app", "importedns");
then(aspect.file("resources/br-logo.png")).contentsTheSameAsFile("src/test/resources/br-logo.png");
}

}
Binary file added brjs-core-tests/src/test/resources/br-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion brjs-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies {
compile dependency('utils')
compile dependency('jericho-html')
compile dependency('xalan')
compile dependency('jmimemagic')

/* woodstox deps */
compile dependency('woodstox-core-asl')
Expand Down
74 changes: 27 additions & 47 deletions brjs-core/src/main/java/org/bladerunnerjs/model/NodeImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
import java.util.regex.Pattern;
import java.util.zip.ZipFile;

import javax.imageio.ImageIO;

import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.NameFileFilter;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;

import org.apache.commons.lang3.StringUtils;
import org.bladerunnerjs.memoization.MemoizedFile;
import org.bladerunnerjs.model.exception.ConfigException;
import org.bladerunnerjs.model.exception.InvalidSdkDirectoryException;
import org.bladerunnerjs.plugin.AssetLocationPlugin;
import org.bladerunnerjs.plugin.AssetPlugin;

import org.bladerunnerjs.plugin.proxy.VirtualProxyAssetLocationPlugin;
import org.bladerunnerjs.plugin.proxy.VirtualProxyAssetPlugin;
import org.bladerunnerjs.plugin.utility.PluginLoader;
Expand All @@ -36,8 +37,6 @@

import com.google.common.collect.ImmutableMap;

import net.sf.jmimemagic.*;

@SuppressWarnings("unused")
public class NodeImporter {

Expand Down Expand Up @@ -91,14 +90,10 @@ public static void importApp(BRJS tempBrjs, String oldAppName, App sourceApp, Ap

File jettyEnv = tempBrjsApp.file("WEB-INF/jetty-env.xml");
if (jettyEnv.isFile()) {
String prefixAndSuffixRegex = "([ /;])";
String jettyEnvContent = org.apache.commons.io.FileUtils.readFileToString(jettyEnv);
Matcher matcher = Pattern.compile(prefixAndSuffixRegex+oldAppName+prefixAndSuffixRegex).matcher(jettyEnvContent);
if (matcher.find()) {
findAndReplaceInTextFile(tempBrjs, jettyEnv, prefixAndSuffixRegex+oldAppName+prefixAndSuffixRegex, matcher.group(1)+targetApp.getName()+matcher.group(2));
}
else {
//do nothing - we are still keeping the old file content
String jettyXmlContent = org.apache.commons.io.FileUtils.readFileToString(jettyEnv, targetApp.root().bladerunnerConf().getDefaultFileCharacterEncoding());
String newJettyXmlContent = StringUtils.replacePattern(jettyXmlContent, "([ /;])"+oldAppName+"([ /;])", "$1"+targetApp.getName()+"$2");
if (!jettyXmlContent.equals(newJettyXmlContent)) {
org.apache.commons.io.FileUtils.write(jettyEnv, newJettyXmlContent);
}
}

Expand Down Expand Up @@ -139,7 +134,7 @@ private static BRJS createTemporaryBRJSModel() throws InvalidSdkDirectoryExcepti
return brjs;
}

private static void renameBladeset(Bladeset bladeset, String sourceAppRequirePrefix, String sourceBladesetRequirePrefix) throws IOException {
private static void renameBladeset(Bladeset bladeset, String sourceAppRequirePrefix, String sourceBladesetRequirePrefix) throws IOException, ConfigException {
updateRequirePrefix(bladeset, sourceAppRequirePrefix, sourceBladesetRequirePrefix, bladeset.requirePrefix());

renameTestLocations(bladeset.testTypes(), sourceAppRequirePrefix, sourceBladesetRequirePrefix, bladeset.requirePrefix());
Expand All @@ -154,7 +149,7 @@ private static void renameBladeset(Bladeset bladeset, String sourceAppRequirePre
}
}

private static void renameTestLocations(List<TypedTestPack> testTypes, String sourceAppRequirePrefix, String sourceLocationRequirePrefix, String requirePrefix) throws IOException{
private static void renameTestLocations(List<TypedTestPack> testTypes, String sourceAppRequirePrefix, String sourceLocationRequirePrefix, String requirePrefix) throws IOException, ConfigException {

for(TypedTestPack typedTestPack : testTypes)
{
Expand All @@ -164,7 +159,7 @@ private static void renameTestLocations(List<TypedTestPack> testTypes, String so
}
}

private static void updateRequirePrefix(AssetContainer assetContainer, String sourceAppRequirePrefix, String sourceRequirePrefix, String targetRequirePrefix) throws IOException {
private static void updateRequirePrefix(AssetContainer assetContainer, String sourceAppRequirePrefix, String sourceRequirePrefix, String targetRequirePrefix) throws IOException, ConfigException {
if(!sourceRequirePrefix.equals(targetRequirePrefix)) {
for(AssetLocation assetLocation : assetContainer.assetLocations()) {
if(assetLocation.dir().exists()) {
Expand All @@ -185,51 +180,39 @@ private static void updateRequirePrefix(AssetContainer assetContainer, String so
}
}

private static void findAndReplaceInAllTextFiles(BRJS brjs, File rootRenameDirectory, String sourceRequirePrefix, String targetRequirePrefix) throws IOException
private static void findAndReplaceInAllTextFiles(BRJS brjs, File rootRenameDirectory, String sourceRequirePrefix, String targetRequirePrefix) throws IOException, ConfigException
{
IOFileFilter dontMatchWebInfDirFilter = new NotFileFilter( new NameFileFilter("WEB-INF") );
Collection<File> findAndReplaceFiles = FileUtils.listFiles(rootRenameDirectory, TrueFileFilter.INSTANCE, dontMatchWebInfDirFilter);
findAndReplaceInTextFiles(brjs, findAndReplaceFiles, sourceRequirePrefix, targetRequirePrefix);
}

private static void findAndReplaceInTextFiles(BRJS brjs, Collection<File> files, String sourceRequirePrefix, String targetRequirePrefix) throws IOException
private static void findAndReplaceInTextFiles(BRJS brjs, Collection<File> files, String sourceRequirePrefix, String targetRequirePrefix) throws IOException, ConfigException
{
for (File f : files) {
if (f.length() != 0) {
try {
if (checkFileMimeType(f).startsWith("text")) {
findAndReplaceInTextFile(brjs, f, sourceRequirePrefix, targetRequirePrefix);
}
}
catch (MagicMatchNotFoundException e) {
continue;
}
findAndReplaceInTextFile(brjs, f, sourceRequirePrefix, targetRequirePrefix);
}
}
}

private static String checkFileMimeType(File file) throws IOException, MagicMatchNotFoundException {
byte[] data = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
MagicMatch match = null;
try {
match = Magic.getMagicMatch(data);
}
catch (MagicParseException | MagicException e) {
throw new IOException(e);
}
catch (MagicMatchNotFoundException e) {
throw e;
}
return match.getMimeType();

private static boolean isTextFile(File file) {
return true;
}

private static void findAndReplaceInTextFile(BRJS brjs, File file, String oldRequirePrefix, String newRequirePrefix) throws IOException
private static void findAndReplaceInTextFile(BRJS brjs, File file, String oldRequirePrefix, String newRequirePrefix) throws IOException, ConfigException
{
String content = org.apache.commons.io.FileUtils.readFileToString(file);
for (String extension : ImageIO.getReaderFormatNames()) {
if (file.getName().endsWith(extension)) {
return; //image file
}
}

String content = org.apache.commons.io.FileUtils.readFileToString(file, brjs.bladerunnerConf().getDefaultFileCharacterEncoding());
String updatedContent = findAndReplaceInText(content, oldRequirePrefix, newRequirePrefix);

if(content != updatedContent) {
FileUtils.write(brjs, file, updatedContent);
if (!content.equals(updatedContent)) {
FileUtils.write(brjs, file, updatedContent, brjs.bladerunnerConf().getDefaultFileCharacterEncoding());
}
}

Expand All @@ -243,10 +226,7 @@ static String findAndReplaceInText(String content, String oldRequirePrefix, Stri
while(matcher.find(startPos)) {
String matchedStr = matcher.group();
newContent.append(content.substring(startPos, matcher.start()));
if (matchedStr.contains("/")) {
newContent.append(matcher.group(1) + newRequirePrefix);
}
else if (content.substring(matcher.end()).startsWith("/")) {
if ( (matchedStr.contains("/") || content.substring(matcher.end()).startsWith("/")) && !matchedStr.contains(".") ) {
newContent.append(matcher.group(1) + newRequirePrefix);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ public void libWithNameIs(String libName, JsLib appOverriddenNonBRLib)
appJsLib = (appJsLib instanceof AppSdkJsLib) ? ((AppSdkJsLib) appJsLib).getWrappedJsLib() : appJsLib;
assertSame(appJsLib, appOverriddenNonBRLib);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ public VerifierChainer isEmpty() {
assertTrue("The directory is empty", dir.isEmpty());
return verifierChainer;
}

public VerifierChainer contentsTheSameAsFile(String filePath) throws IOException
{
File checkAgainstFile = new File(filePath);

assertTrue( "file contents wasnt equal", org.apache.commons.io.FileUtils.contentEquals(dir, checkAgainstFile) );

return verifierChainer;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ public VerifierChainer fileContentsContains(String fileName, String fileContents

}

public VerifierChainer fileContentsEquals(String fileName, String fileContents) throws Exception {
assertTrue("The file '" + fileName + "' did not exist at: " + node.file(fileName).getAbsoluteFile(), node.file(fileName).exists());
String actualContents = fileUtil.readFileToString(node.file(fileName));
assertTrue("Expected file to equal " + fileContents + " but didnt. Content was:\n"+actualContents, actualContents.equals(fileContents) );

return verifierChainer;
}

public VerifierChainer firstFileIsLarger(String filePath1, String filePath2) {
File file1 = node.file(filePath1);
File file2 = node.file(filePath2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ public static Collection<File> listFiles(File directory, String[] extensions, bo
{
return org.apache.commons.io.FileUtils.listFiles(directory, extensions, recurse);
}


}
2 changes: 0 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ Dependencies.putAll([

'saxon-dom' : 'net.sf.saxon:saxon-dom:8.7',

'jmimemagic' : 'net.sf.jmimemagic:jmimemagic:0.1.3',

'curl-win32' : 'util:curl-win32:7.33.0'
]);

Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions releases/v0.15.4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"milestone": "0.15.4",
"name": "BladeRunnerJS @tagVersion@",
"prerelease": "false"
}
5 changes: 5 additions & 0 deletions releases/v0.15.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## BladeRunnerJS @tagVersion@

### @tagVersion@ Features and Improvements

- Fix for a bug introduced in v0.15.2 where some files weren't re-namespaced properly when an App was imported

0 comments on commit bd82eac

Please sign in to comment.