I'm writing a unit test that verify if the xml is formatted correctly, but this is failing and I can't figure out why.
So I decided to test the code of this blog post and test in the Grails console, it also fails.
import groovy.xml.*
def prettyXml = '''\
<?xml version="1.0" encoding="UTF-8"?>
<languages>
<language id="1">Groovy</language>
<language id="2">Java</language>
<language id="3">Scala</language>
</languages>
'''
// Pretty print a non-formatted XML String.
def xmlString = '<languages><language id="1">Groovy</language><language id="2">Java</language><language id="3">Scala</language></languages>'
assert XmlUtil.serialize(xmlString) == prettyXml
Assertion fails with:
Assertion failed:
assert XmlUtil.serialize(xmlString) == prettyXml
| | | |
| | | <?xml version="1.0" encoding="UTF-8"?>
| | | <languages>
| | | <language id="1">Groovy</language>
| | | <language id="2">Java</language>
| | | <language id="3">Scala</language>
| | | </languages>
| | false
| <languages><language id="1">Groovy</language><language id="2">Java</language><language id="3">Scala</language></languages>
<?xml version="1.0" encoding="UTF-8"?>
<languages>
<language id="1">Groovy</language>
<language id="2">Java</language>
<language id="3">Scala</language>
</languages>
I'm using Grails 2.2.1, that uses Groovy 2.0.7, on Windows 7.
Maybe is something related with the OS line separator?
EDIT
I saved both strings to file, and checked with Notepad++
The parsed xml (XmlUtils) have CL+RF as line separator but the prettyXml have only LF. I also tested using \n instead of a multi line declaration, with same result!
Groovy shouldn't use CL+RF always, since this is the Windows line separator?
In the Groovy String/GString docs, it says in relation to multi-line literals:
There[sic] are always represented by the character '\n', regardless of
the line-termination conventions of the host system.
They don't really say why, unfortunately.
Related
I need to verify xml textvalue of an element in my xml as show below, so far I got the value of all the dmdindex:field but I just need the last one drep.rightsFacet result output. Keep in mind that xmllint version I have does not have xpath so I have to resort to xmllint --shell. Any help is appreciated.
here's the xml file snippet:
<?xml version="1.0" encoding="UTF-8"?>
<dmdindex:dmdindex xmlns:dmdindex="http://www.example.com/example/dmdindex/"
xmlns:functx="http://www.functx.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dmdindex:record>
<dmdindex:field name="drep.yearStart">1881</dmdindex:field>
<dmdindex:field name="drep.pubConcat">[Detroit : Parke, Davis & Co., 1881?]</dmdindex:field>
<dmdindex:field name="drep.rights">blahblahblah</dmdindex:field>
<dmdindex:field name="drep.rightsLink">https://creativecommons.org/publicdomain/mark/1.0/</dmdindex:field>
<dmdindex:field name="drep.rightsFacet">Public domain</dmdindex:field>
</dmdindex:record>
</dmdindex:dmdindex>
here's the command I used
echo "cat //*[local-name()='dmdindex']/*[local-name()='record']/*[local-name()='field']" | xmllint --shell example.xml | sed '/^\/ >/d' | sed 's/<[^>]*.//g'
which returned
-------
Philadelphia : Sunshine Press, [1897]
-------
blahblahblah
-------
https://creativecommons.org/publicdomain/mark/1.0/
-------
Public domain
I only need to grab the value of "Public domain" and ignore the rest. thanks!
You can add a predicate to your xpath to test the value of the name attribute...
echo "cat //*[local-name()='dmdindex']/*[local-name()='record']/*[local-name()='field'][#name='drep.rightsFacet']/text()" | xmllint --shell example.xml | sed '/^\/ >/d'
I want codesniffer to produce error output in CLI and exit before proceeding any further to avoid running other tests like behat, phpmd, phpcpd so that comes after.
Current code (as shown below) creates a XML report with errors listed in but it won't terminate the process. How should I modify the code in order to have a XML report, CLI error output and terminate the process in case of an error?
CURRENT CODE in PHING:
<target name="codesniffer-phpcs">
<echo msg="Checking coding standards ..." />
<tstamp />
<phpcodesniffer standard="PSR2" showWarnings="true" format="full">
<fileset refid="sourcecode" />
<formatter type="checkstyle" outfile="phing/phpcs/psr2_${DSTAMP}-${TSTAMP}.xml" />
</phpcodesniffer>
</target>
This is what I would like to see in CLI as well as having XML file:
FOUND 4 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
69 | ERROR | There must not be more than one property declared per statement
108 | ERROR | The abstract declaration must precede the visibility
657 | ERROR | Expected 1 space after comma in function call; 2 found
812 | ERROR | A cast statement must be followed by a single space
--------------------------------------------------------------------------------
I think the attribute "haltonerror" inside the task will be your friend here.
http://www.phing.info/docs/guide/stable/apcs48.html
I would like to deploy a vaadin (version 7.2.5) web application using embedded jetty (eclipse luna builtin version).
Currently, my code looks like:
public class Launcher {
private static int httpPort = 8080;
public static void main(String[] args) throws Exception
{
Server server = new Server();
SocketConnector connector = new SocketConnector();
connector.setMaxIdleTime(1000 * 60 * 10);
connector.setSoLingerTime(-1);
connector.setPort(httpPort);
connector.setReuseAddress(false);
QueuedThreadPool pool = new QueuedThreadPool();
pool.setMinThreads(10);
pool.setMaxThreads(100);
server.setConnectors(new Connector[] { connector });
server.setThreadPool(pool);
WebAppContext context = new WebAppContext();
context.setServer(server);
context.setContextPath("/");
context.setWar("ReportWriter.war");
context.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setHandler(context);
try
{
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I've copied it from a vaadin forum thread. The server seems to start and the WAR actually gets extracted.
Pointing my browser to http://localhost:8080/, instead of starting my vaadin (version 7.2.5) app, all what I see is:
Just in case it might be important: My directory tree of the WAR project in eclipse:
ReportWriter
| .classpath
| .project
| ivy.xml
| ivysettings.xml
|
+---.settings
| (...)
|
+---build
| \---classes
| +---(...)
| \---META-INF
| persistence.xml
|
+---src
| +---(...)
| \---META-INF
| persistence.xml
|
\---WebContent
| dropDDL.sql
| init.sql
| reportwriter.xml
|
+---META-INF
| MANIFEST.MF
|
+---VAADIN
\---WEB-INF
\---lib
BorderLayout-0.5.jar
confirmdialog-2.0.4.jar
dawn-2.jar
derby.jar
derbynet.jar
derbyrun.jar
derbytools.jar
messagebox-2.0.6.jar
refresher-1.2.1.7.jar
vaadin-jpacontainer-3.1.1-javadoc.jar
vaadin-jpacontainer-3.1.1-sources.jar
vaadin-jpacontainer-3.1.1.jar
wizards-for-vaadin-1.0.1.jar
And the one of my RWRunner (launcher) project:
RWRunner
| .classpath
| .project
| ivy.xml
| ivysettings.xml
| ReportWriter.war <-- The war file generated from the project above
| test.txt
| web.xml
|
+---.settings
| .jsdtscope
| com.vaadin.integration.eclipse.prefs
| org.eclipse.jdt.core.prefs
| org.eclipse.wst.common.component
| org.eclipse.wst.common.project.facet.core.xml
| org.eclipse.wst.jsdt.ui.superType.container
| org.eclipse.wst.jsdt.ui.superType.name
|
+---build
| \---classes
| \---ch
| \---darkspot
| \---rwrunner
| Launcher.class
|
\---src
\---ch
\---darkspot
\---rwrunner
Launcher.java
Looks like you are somehow missing the servlet configuration needed to map the /* to the Vaadin web application. There seems to be web.xml in place that should take care of that, but check that the content is referring to right Servlet/UI classes and URI.
Alternatively to mapping in web.xml you can have a #WebServlet annotated servlet in your UI class (when using JSR 315):
#WebServlet(value = "/*", asyncSupported = true)
#VaadinServletConfiguration(productionMode = false, ui = MyDemoUI.class)
public static class Servlet extends VaadinServlet {
}
Furthermore, the WAR structure above looks suspicious (although the directory listing in browser screenshot looks ok). Make sure the classes are under /WEB-INF/classes/, in order to be visible for the servlet container. And also that web.xml under /WEB-INF.
I have a directory structure managed by perforce checked out to my local system.
In my ant build targets of my java code. I want surf down into some subdirectory "Subdirectory_Start_here" I want to know what the highest change list information for all files under that directory.
-depot
|
|-Directory A
| |
| |-directory A.1
| |-directory A.2
| | |-Subdirectory_Start_here
| | |
| |-directory A.3
|
|-Directory B
My ant build.xml target
<target name="snapshot" depends="fully_configured,set_revision_slot">
.......
<echo>************************************^^^^^^^^^^^^^^^^^^${env.LOCAL_FS_PATH_TO_P4_MANAGED_DIRECTORY}</echo>
<taskdef resource="com/perforce/p4java/ant/tasks/P4Tasks.properties" classpath="../../../lib/p4ant-2010.1.293250.jar:../../../lib/p4java-2010.1.269249.jar" />
<p4jchanges maxmostrecent="1" client="peterc_peterc-ml" property="platformVersion" longdesc="true" type="submitted" files="${env.LOCAL_FS_PATH_TO_P4_MANAGED_DIRECTORY}/Directory A/directory A.2/Subdirectory_Start_Here/*"/>
<echo>************************************PLATFORM VERSION^^^^^^^^^^^^^^^^^^ ${platformVersion}</echo>
<exec executable="${NF}" dir="${COMMANDLINE_DIR}" failonerror="true">
<arg line="platformVersion:${platformVersion}"/>
</exec>
</target>
According to http://www.perforce.com/perforce/doc.current/manuals/p4ant/p4tasks.html#p4jchanges a type of "submitted" should be allowed. Submitted works on the standalone p4 command. But I am getting.
'submitted' is not a permitted value for com.perforce.p4java.core.IChangelist$Type
If I take type out. The echo does contain a changelist number that is different than if I don't have a files property. So it appears that I get the latest pending or submitted change info from "Subdirectory_Start_Here" and down.
Any thoughts?????
Thanks for any help?
It's a bit daft, but try 'SUBMITTED'.
<p4jchanges maxmostrecent="1" longdesc="true" type="SUBMITTED" />
I have a vendor-propriety files that I am converting to csv. I need to delete the first 7 characters of each file. These characters are a mix of printable and non-printable characters.
For example, the one file might have
$([char]0x56)$([char]0x28)$([char]0x00)$([char]0x00)$([char]0x4C)$([char]0x01)$([char]0x01)
And the next file might have
$([char]0x4F)$([char]0xE7)$([char]0x00)$([char]0x00)$([char]0x4C)$([char]0x01)$([char]0x01)
And the next file might have something completely different.
Even simpler:
(Get-Content <CSV file path> | Out-String).Substring(7) | Out-File <CSV file path>
To do this for all CSV files in a directory:
gci <path to directory>\*.csv | (Get-Content $_ | Out-String).Substring(7) | Out-File $_