ANT build script CSSlint output xml - html5boilerplate

Is that any way to export CSSlint output to a valid XML format with ant build script?
I modified project.properties file in: tool.csslint.opts = --format=lint-xml section, but I think this is not enough, because csslint needs to specify output file like so:
csslint --format=lint-xml test.css > results.xml
How can I modify ant target to work?
Thank you.

Basics: Ant already has an output property. So you can just add the format option and output it to a file specified as an output property on the apply element. in an h5bp project this will output "output.xml" to the root of your project.
<apply dir="${dir.source}/${dir.css}"
executable="java" parallel="true"
failonerror="true" output="output.xml">
<fileset dir="./${dir.source}/">
<include name="**/${dir.css}/*.css"/>
<exclude name="**/*.min.css"/>
<exclude name="**/${dir.publish}/"/>
</fileset>
<arg value="-jar" />
<arg path="./${dir.build.tools}/${tool.rhino}" />
<arg path="./${dir.build.tools}/${tool.csslint}" />
<arg value="--format=lint-xml" />
<srcfile/>
</apply>

Related

Line numbers in dotnet-stack report

With dotnet-stack report -p <pid> I can see the stack traces, but I don't see the line numbers. Is it possible to display line numbers (like jstack does)? Is there an alternative?
Try adding the following properties to csproj files:
<PropertyGroup>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<!-- The following is to fix error line numbers mismatch -->
<Optimize>false</Optimize>
</PropertyGroup>

Remove CDATA from XML with regex in Windows CMD (powershell)

I am working with some XML data and I am stacked trying to remove CDATA in XML.
I tried many ways, and it seems the simplier is by replacing all patterns
hey <![CDATA[mate - number 1]]> what's up
by
hey mate - number 1 what's up
Regex, in order to get the whole expression is (\<\!\[CDATA\[)(.*)(\]\]\>), so when using PERL (PCRE), I just need to replace by \2.
By this, and taking advantage of Powershell, I am running in CMD:
powershell -Command "(gc Desktop\test_in.xml) -replace '(\<\!\[CDATA\[)(.*)(\]\]\>)', '\2' | Out-File Desktop\test_out.xml")
Although the result is everthing is replaced by string \2, instead of mate - number 1 in the example.
Instead of \2, I tried (?<=(\<\!\[CDATA\[))(.*?)(?=(\]\]\>)) since I am getting with this the inner part I am trying to keep, although the result is frustating, again literal replacing.
Any guess?
Thank you!
PS. If anyone know how to avoid this replacing in R, it is usefull as well.
Any XSLT that runs the Identity Transform (i.e., copies itself) will remove the <CData> tags. Consider running with R's xslt package or with PowerShell:
library(xml2)
library(xslt)
txt <- "<root>
<data>hey <![CDATA[mate - number 1]]> what's up</data>
</root>"
doc <- read_xml(txt)
txt <- '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>'
style <- read_xml(txt, package = "xslt")
new_xml <- xml_xslt(doc, style)
# Output
cat(as.character(new_xml))
# <?xml version="1.0" encoding="UTF-8"?>
# <root>
# <data>hey mate - number 1 what's up</data>
# </root>
Powershell
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load("C:\Path\To\Identity_Transform\Script.xsl");
$xslt.Transform("C:\Path\To\Input.xml", "C:\Path\To\Output.xml");
Powershell variables are $1 $2 etc, in powershell you always use the variables instead of traditional # notation implemented in most languages.
Now, I am on mobile at the moment or I wouldtest so I may be off, but I believe this will do the needful:
powershell -Command "(gc Desktop\test_in.xml) -replace '(\<\!\[CDATA\[)(.*)(\]\]\>)', "$2" | Out-File Desktop\test_out.xml")
You can also create named capture groups if you like:
powershell -Command "(gc Desktop\test_in.xml) -replace '(\<\!\[CDATA\[)(?<CData>.*)(\]\]\>)', "${CData}" | Out-File Desktop\test_out.xml")

Compiling all stylus files from given folder and its sub-folders

For example compiling this folder structure,
x.styl
|--abc/
|--|--a.styl
|--efg/
|--|--b.styl
To
build/
|--x.css
|--abc/
|--|--a.css
|--efg/
|--|--b.css
Using stylus compiler (compiling styl files from a folder and its subfolders)
You can use the --out parameter on building and target a whole folder, it will keep your structure, first you can target a file or folder, and after out the folder or filename you want to have your compiled css
stylus -c ./project/stylus --out ./myfolder/css
For:
|stylus
|--abc/
|--|--a.styl
|--efg/
|--|--b.styl
It would result in something like:
|css
|--abc/
|--|--a.css
|--efg/
|--|--b.css
A bit late on this, and I hope that might help others like it help me, but I found a solution using the package stylus-chokidar.
stylus-chokidar
Just slightly modified stylus CLI, that builds files list recursively and watches > them with chokidar (if --watch provided).
Recursion are always enabled, glob patterns not supported.
With this you can have the stylus files compiled in-place recursively (each component will store their own CSS/stylus files).
I am late on the game, but I believe I have a solution that is not optimal, but workable for your situation.
per your example, keep the same file/folder structure
x.styl
|--abc/
|--|--a.styl
|--efg/
|--|--b.styl
but also include a "combination.styl" file in its own separate folder. So now you have:
x.styl
|--abc/
|--|--a.styl
|--efg/
|--|--b.styl
|--all-stylus/
|--|--combination.styl
inside of combination.styl you should import all of the separate .styl files, so for our example
// combination.styl
#import '../x.styl'
#import '../abc/a.styl'
//etc...
then you can output one large css file wherever you would like!
the command to run this would simply be:
stylus ./stylus -out ./css
I know it doesn't give you the output file/folder structure you were looking for, but I imagine it is helpful to be able to compile all of your stylus into css at one time!

How to Removing XML node using SED or Unix shell script command

I have a sample xml file like below,
<Students>
<student>
<name>john</name>
<id>123</id>
</student>
<student>
<name>mike</name>
<id>234</id>
</student>
</Students>
I wanted to remove one particular student node by using the name. For example i would like to remove the student john element
<student>
<name>john</name>
<id>123</id>
</student>
from the xml file. How can I achieve this in shell script or SED.
Am looking for shell script command rather using xmlstarlet. How to archive the same using SED with REGEX.
Please advise.
You can use xmlstartlet as below;
xmlstarlet ed -d "/Students/student[name='john']" 11
ed is to edit or update XML.
-d is to delete param.
"/Students/student[name='john']" is xpath
Example;
user#host:/tmp$ xmlstarlet ed -d "/Students/student[name='john']" 11
<?xml version="1.0"?>
<Students>
<student>
<name>mike</name>
<id>234</id>
</student>
</Students>

Passing multiple arguments to SQLite via Ant

I need to use both .separator and .import when calling SQLite from my Ant script but can't seem to get the syntax right. Based on an answer here on SO about doing the same in a bash script, my latest attempt is this.
<exec executable="sqlite3">
<arg value="${sqlite.db}" />
<arg value=".separator ';'\n.import ${data.dir}/DISTRICT_BOUNDARY.txt DISTRICT_BOUNDARY" />
</exec>
Unfortunately this results in the following error message.
Error: unknown command or invalid arguments: "separator". Enter ".help" for help
What is the proper syntax for what I am trying to do?
Final solution:
<exec executable="sqlite3" inputstring=".separator ';'
.import ${data.dir}/METADATA_DESCRIPTION.txt METADATA_DESCRIPTION">
<arg value="${sqlite.db}" />
</exec>
It appears that you can't pass meta-commands (i.e., commands that start with a .) via the final argument to sqlite3; only actual SQL statements seem to work there[*]. There are two possible fixes; either write the meta-commands to a file and use the -file filename option (two arguments, before database name) to load them, or pass the whole multi-statement set of instructions in on sqlite3's standard input. This second option should be simpler for you to implement with ant, via the inputstring parameter:
<exec executable="sqlite3" inputstring=".separator ';'
.import ${data.dir}/DISTRICT_BOUNDARY.txt DISTRICT_BOUNDARY">
<arg value="${sqlite.db}" />
</exec>
Yes, that has a real newline in it. Unlike real SQL statements, you can't separate meta-commands with semicolons. You may encode the newline as
if you wish.
[*] Actually, a single meta-command would work, but you can't put two.
I think Ant is interpreting the single quotes in your second arg value as string delimiters. Try escaping the single quotes:
<arg value=".separator \';\'\n.import${data.dir}/DISTRICT_BOUNDARY.txt DISTRICT_BOUNDARY" />
I'm not familiar with SQLite syntax, but the .import parameter may also need to be a separate arg value.

Resources