Gradle processResources - file contains $ character - gradle

How can you execute gradle processResources on files that contain $ characters without escaping the $ in the files?
I have some static html files located the /resources/static folder as suggested by the Spring Boot reference docs. However, when I try to execute gradle processResources, Gradle throws an exception
Caused by: org.gradle.api.GradleException:
Could not copy file '[...]/src/main/resources/static/dollar.html'
to '[...]/build/resources/main/static/dollar.html'.
[...]
Caused by: groovy.lang.GroovyRuntimeException:
Failed to parse template script (your template may contain an error
or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript7.groovy: 1: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5"
or bracket the value expression "${5}" # line 1, column 10.
out.print("""<!DOCTYPE html>
As far as I understand, the problem occurs because there is a $ character in one of the static files and $ is a reserved character for expressions when processing resources.
Proposed solutions:
Yes, escaping the $ with \$ (as suggested in the stacktrace) works, but I rather not change the html file if other options are available.
Trying to exclude the file from process resources causes the problem to disappear, but has the side effect of also excluding the file from being copied:
configure(tasks.processResources) {
exclude 'static/dollar.html'
}
I have also seen that you can filter processed resources. I guess that this is what I would like to do but I have not found a "ignore $ filter", is there any?
configure(tasks.processResources) {
filesMatching('static/dollar.html') {
filter = ???
}
}
Other suggestions?
The dollar.html file that causes the problem can be simplified to:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div>Dollar $</div>
</body>

JB Nizet's comment provided valuable insight. The problem was indeed due to the usage of expand() (although not immediately visible since it was located in an allProjects() script in the parent project). The reason why expand() was added in the first place was the desire to populate the info.build.* properties in the application.properties file (so that they are available through Spring Boot's info endpoint).
Solution: Use filesMatching() to only expand() selected files. The following snippet solved the specific problem related to Spring Boot:
processResources {
filesMatching('application.properties') {
expand(project.properties)
}
}

Just for future reference:
You could write the $ also as HTML entity: &dollar;

Related

NXlog will not start - AlienVault Config

I am trying to configure NXlog to work with AlienVault based on the guide here
I installed the custom config file from AlienVault and modified the destination IP only. When I did this I could not get the NXlog service to start - Then I reinstalled the default config but I still cannot get it to open.
I edited the file in notepad which I thing should be safe, however I have read here that it is possibly the UTF-8 BOM - I am not sure how to check if there is one but I do not believe there is because I only used notepad.
The first line in the config file looks like so:
define ROOT C:\Program Files (x86)\nxlog
The NXlog Log file with the errors is only displaying this error:
nxlog failed to start: Invalid keyword: define at C:\Program Files (x86)\nxlog\conf\nxlog.conf:1
Not very helpful - Seems to be choking on the very first word - Anyone seen this before???
I'm pretty sure that's caused by the UTF-8 BOM in your config file. I suggest using and checking with an editor that can handle this. In HEX mode you can confirm whether the file has a BOM or not.
The NXLog EE v4.0 can cope with the BOM properly BTW.
As B0ti mentioned, my problem was caused by the BOM - I couldn't figure out how to fix this on windows so I downloaded the file into a Linux environment and fixed it there. To do so follow these steps -
First I verified there was a BOM in place with the file command:
ex: file filename.txt -This will print information about the file - if there is a BOM you will see that.
Next I followed the answer here for removing the BOM:
Basically just do this in the Linux box - sed '1s/^\xEF\xBB\xBF//' < orig.txt > new.txt
Then I transferred the new file back to the Windows box and all was right with the world!

HTML encoding happening with Gulp on Windows

I have created a Gulp plugin called php-include-html, which scans php files in Gulp and processes include and require statements to inline HTML snippets.
The snippet of the gulpfile looks like this...
var gulp = require("gulp");
var pump = require("pump");
var phpinc = require("php-include-html");
gulp.task("php",function(cb) {
pump([
gulp.src("*.php"),
phpinc({verbose:true}),
gulp.dest("build")
],cb);
});
This is a snippet from the php file before processing...
<!DOCTYPE html>
<html lang="en-gb">
<head>
<title>Emma Malik's Official Website - Legal</title>
And here's the same snippet after processing...
<!DOCTYPE html>
<html lang="en-gb">
<head>
<title>Emma Malik&s Official Website - Legal</title>
As you can see, the apostrophe has been HTML encoded. However, it doesn't seem to be all ampersands, just some of them, and some other characters as well, such as > to > but again, not all of them.
All the way through my plugin, this remains an apostrophe, it seems to be the gulp.dest rewriting the file which somehow converts it.
Things I've tried...
Stripping the UTF-8 BOM from the source file (strip-bom and
strip-bom-buf)
Adding the UTF-8 BOM to the destination file (gulp-header)
Using string manipulation instead of String.replace
Converting the destination contents to UTF-8 (gulp-convert-encoding)
Decoding after my plugin before gulp.dest (gulp-html-entities)
Using vinyl-file
Has anyone seen anything like this before, or know how to fix it?
False alarm, it turns out that it is actually the "gulp-sri-hash" plugin, which runs after mine, which is doing this. I need to investigate further as to what exactly is causing this, but at least I've figured out it's not me!

Downloading all files from a FTP directory, running into problems with escaping spaces

I have my camel configured to download all files from a specific FTP directory. Now this is all easy enough and everything seems to be working fine. However, I am running into errors when the files contain a space in their names such as File 123.csv. I know I could specifically target the files with an escape character. The only difficulty is that these files are dynamic in nature and change daily, so I will not know which files may or may not have spaces.
I figure I can just read all the file URI and make adjustments from there. But I was wondering if there is any Camel specific way to handle this.
Errors: java.lang.IllegalArgumentException: Illegal character in path at index 60: hdfs://test.net/user/CamelTests/File Layout.csv
GenericFileOnCompletion - Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy#fe8d1b for file: RemoteFile[File Layout.csv]
Camel Code
from("{{ftp.serverLP}}/Memo/Loss?username=ftp&password=pass")
.to("hdfs2://Test.net/user/CamelTests/?fileSystemType=HDFS")
.log("Downloaded file ${file:name} complete.");
Try changing the .to(..) to use a non-HDFS file system.
The error posted seems to indicate a problem with the destination to which the files are being copied (HDFS), not the FTP source.

Using sbt-native-packager, how can I simply prepend a directory to my bash script's ${app_classpath}?

My project uses sbt-native-packager with packageArchetype.java_application.
During sbt stage I have a task that generates some final Typesafe style configuration file that I then copy to:
target/universal/stage/conf/application.conf
I'd like to prepend this directory to the runtime classpath in the bash script, and am looking for the simplest way to do that. I'd hate to maintain a separate src/main/templates/bash-template for something so simple, and am not seeing exactly how to go about it otherwise.
Thanks!
Short Answer
Define a package mapping
mappings in Universal <+= (packageBin in Compile, sourceDirectory ) map {
(_, src) =>
// we are using the reference.conf as default application.conf
// the user can override settings here
val conf = src / "main" / "resources" / "reference.conf"
conf -> "conf/application.conf"
}
Create a jvmopts in src/universal/conf with
-Dconfig.file=/<installation-path>/conf/application.conf
Add to build.sbt
bashScriptConfigLocation := Some("${app_home}/../conf/jvmopts")
Example for server_archetype:
Follow the example application. A bit of description can be found here.
Long answer
Changing the classpath is not supported directly by the sbt-native-packager, because it can cause problems like
classpath ordering
security issues
Like Typesafe Config, most libraries which use config files, provide a parameter to define the location of the configuration file. Use the parameters describe in the documentation.
It seems your are trying to run a server, which means you can use the
packageArchetype.java_server
which is designed to read external configurations. Take a look at the example application how to use it.
The following setting:
scriptClasspath in bashScriptDefines ~= (cp => "../conf" +: cp),
Allows you to do exactly what you need.
In this specific example I prepend the "../conf" directory to the classpath entries.
Also, you need to import the following configuration keys to your build SBT:
import com.typesafe.sbt.packager.Keys.bashScriptDefines
import com.typesafe.sbt.packager.Keys.scriptClasspath
The question you asked in the title is a bit different from the description. I am answering the question in the title here - i.e. how can you prepend a directory into the classpath:
This is very hacky and brittle in that it will probably break if/when the sbt-native-packager makes changes to how the script is generated, but for now it works for me:
private lazy val ClasspathPattern = "declare -r app_classpath=\"(.*)\"\n".r
bashScriptDefines := bashScriptDefines.value.map {
case ClasspathPattern(classpath) => "declare -r app_classpath=\"/path/to/some/external/lib/*:" + classpath + "\"\n"
case _#entry => entry
},

Joomla! 2.5 language file - cannot translate description into xml-File

I checked out the question here: Joomla! 2.5 language file - translate description
It is exact the problem I have but unfourtunately I cannot answer the commen from Valentin. So here is my Problem again:
In my xml-File I have this line:
<description>COM_MYCOMPONENT_DESCRIPTION</description>
And in the file en-GB.com_mycomponent.sys.ini I have this:
COM_MYCOMPONENT="MyComponent"
COM_MYCOMPONENT_DESCRIPTION="This is the myComponent description"
COM_MYCOMPONENT_SUMMARY="Summary"
But in Debug-Mode for Languages I have every time this result:
??COM_MYCOMPONENT_DESCRIPTION??
Any Ideas?
Björn
You are using the language file correctly, therefore I am under the impression that it's due to the location of the file. Make sure you have the following in your XML file:
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.com_mycomponent.ini</language>
<language tag="en-GB">en-GB/en-GB.com_mycomponent.sys.ini</language>
</languages>
Also take note of the location:
I have used folder="language" then used en-GB before the file name so the folder structure will be like so:
root(where the XML is)/language/en-GB/en-GB.com_mycomponent.sys.ini
You don't have to put your language files in both places.
Your first configuration is actually correct and is working on Joomla 3.3 for sure.
In your manifest file you should have the language files declares as
<administration>
....
<folder>language</folder>
.....
</administration>
and dont make use of
<languages>....</languages>
Also on your package the folder structure should be
admin/language/en-GB/en-GB.yourcomponent.sys.ini.
If you have this configuration already, you are correct.
In that case from the message of the language debug mode, I assume that you either have mispeled something or there is an error inside your language file.
The latter is what usually happens with me. For example many times I have this error:
COM_MYCOMPONENT_TRA="A translation string"
COM_MYCOMPONENT_ANOTHER_ONE="Another one"
COM_MYCOMPONENT_SOMEOTHER=Some othen translation string"
COM_MYCOMPONENT_MORE="One more "
COM_MYCOMPONENT_LAST_ONE="E translation string"
(Missing the first double quote on the third line).

Resources