I have a xml file "versionreferance.xml". below is the coding
<?xml version="1.0" encoding="utf-8"?>
<!-- Update "revision" value to -1 when the next build is intended to have its revision as 0. This needs to be done for patch/release builds-->
<BuildVersions>
<property name="major" value="1" />
<property name="minor" value="0" />
<property name="patch" value="0" />
<property name="revision" value="93" />
</BuildVersions>
The other is my ant-build.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xmlproperty-demo" default="init">
<xmlproperty file="versionreferance.xml" collapseAttributes="true" />
<echo>Major : ${BuildVersions.major}</echo>
<echo>Minor : ${BuildVersions.minor}</echo>
<echo>Patch : ${BuildVersions.patch}</echo>
<echo>Revision : ${BuildVersions.revision}</echo>
</project>
I am not getting the value in the output.
I want to get the path path dynamically of versionReference.xml , which will be in different place than antbuild.xml
Development\Build\VersionReference.xml
Development\Src\JAAS API\antbuild.xml
It should be dynamically. I am able to get the values form below code. But it's not dynamic.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xmlproperty-demo" default="init">
<xmlproperty file="C:\\Development\\Build\\versionreferance.xml" collapseAttributes="true" />
<echo>Major : ${BuildVersions.major}</echo>
<echo>Minor : ${BuildVersions.minor}</echo>
<echo>Patch : ${BuildVersions.patch}</echo>
<echo>Revision : ${BuildVersions.revision}</echo>
</project>
I want to get the values only in this format.
<?xml version="1.0" encoding="utf-8"?>
<!-- Update "revision" value to -1 when the next build is intended to have its revision as 0. This needs to be done for patch/release builds-->
<BuildVersions>
<property name="major" value="1" />
<property name="minor" value="0" />
<property name="patch" value="0" />
<property name="revision" value="93" />
</BuildVersions>
I highly recommend using the free, third-party XmlTask library:
build.xml
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" />
<xmltask>
<fileset file="versionreferance.xml"/>
<copy path="/BuildVersions/property[#name = 'major']/#value" property="BuildVersions.major"/>
<copy path="/BuildVersions/property[#name = 'minor']/#value" property="BuildVersions.minor"/>
<copy path="/BuildVersions/property[#name = 'patch']/#value" property="BuildVersions.patch"/>
<copy path="/BuildVersions/property[#name = 'revision']/#value" property="BuildVersions.revision"/>
</xmltask>
<echo>Major : ${BuildVersions.major}</echo>
<echo>Minor : ${BuildVersions.minor}</echo>
<echo>Patch : ${BuildVersions.patch}</echo>
<echo>Revision : ${BuildVersions.revision}</echo>
Output
run:
[echo] Major : 1
[echo] Minor : 0
[echo] Patch : 0
[echo] Revision : 93
If you add <echoproperties/> after the <xmlproperty> line you should see the properties are loaded but not as you expect. They will be something like:
BuildVersions.property=,,,
BuildVersions.property.name=major,minor,patch,revision
BuildVersions.property.value=1,0,0,93
This is because the properties are based off the node names, and in your case you have four instances of a "property" child node that are not unique. Your best bet may be to change the xml such as:
<BuildVersions>
<major>1</major>
....
</BuildVersions>
When you say xmlproperty with collapseAttributes="true" on xml file, it will flatten nested elements.
Details: https://ant.apache.org/manual/Tasks/xmlproperty.html
So just saying ${BuildVersions.major} doesn't give or print value as 1. Since you have same named xml element 'prooerty' you won't be able to get single propertie's value
For eg, in your case ${BuildVersions.property.name} will print 'major,minor,patch,revision'
Either you can redesign your versionreferance.xml to respect xmlproperty to work . Or you can make it as property file & say <property file="your.properties.file"/> & access them as normal properties!
If VersionReference.xml is going to be exactly where you mentioned in your question corresponding to your antbuild.xml.
I would suggest you to change your Absolute Path (as mentioned in question) with "..\..\Build\VersionReference.xml" which corresponds to the basedir="." in your project
This should work fine.
And considering your string format requirement.
I think the default comma(,) seperated value can then be replaced by dot(.) or manipulated as per your requirement by the following syntax
<propertyregex property="propB"
input="${propA}"
regexp=","
replace="."
global="true" />
Please find more info on this link :
Replacing characters in Ant property
Hope this helps.
Related
I'm getting this error in my project, and I cannot for the life of me find where my navigationMode is getting defined twice.
Error:(707) Attribute "navigationMode" already defined with incompatible format.
The source of the error is this file:
/Users/temp/code/MyCoolProject/app/build/intermediates/res/merged/debug/values/values.xml
How is this file generated? I didn't write it.
Here it is defined in my:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="navigationMode">
<enum name="listMode" value="1" />
<enum name="normal" value="0" />
<enum name="tabMode" value="2" />
</attr>
</resources>
How can I get rid of this error?
Check your operations with action bar.
I want to generate a MSI package which contains only one feature.
I have a wxi file which is generated automatically. I cannot change this process.
wxi file looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<Include>
<!-- components -->
<Feature Id="DefaultFeature" Title="Main Feature" Level="1">
<ComponentRef Id="comp0" />
<ComponentRef Id="comp1" />
<ComponentRef Id="comp2" />
<ComponentRef Id="comp3" />
<ComponentRef Id="CleanupMainApplicationFolder" />
</Feature>
</Include>
I have a wxs file which I can change:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product ...>
<!-- components -->
<?include bundle.wxi ?>
<UI/>
<FeatureRef Id="DefaultFeature">
<ComponentRef Id="comp999" />
</FeatureRef>
</Product>
</Wix>
When I compile the wxs to MSI package Light is stating this error:
error LGHT0095 : Multiple primary references were found for Feature 'DefaultFeature' in Product '{...}' and Product '{...}'.
How do I change my wxs file to add a component to the feature defined in wxi file?
Thanks in advance.
Use <ComponentGroup> in your include files instead of <Feature>. Then, define your features in one place, the main .wxs file with <Product> element.
For example, this is how include file might look:
<Fragment>
<Component Id="Comp1" Guid="{GUID-GOES-HERE}">
...
</Component>
<Component Id="Comp2" Guid="{GUID-GOES-HERE}">
...
</Component>
<Component Id="Comp3" Guid="{GUID-GOES-HERE}">
...
</Component>
<ComponentGroup Id="CG1">
<ComponentRef Id="Comp1"/>
<ComponentRef Id="Comp2"/>
<ComponentRef Id="Comp3"/>
</ComponentGroup>
</Fragment>
And the main product.wxs defines the feature, includes the component group in there and allows including more components:
<Feature Id="MainFeature" Title="..." Level="100">
<ComponentGroupRef Id="CG1"/>
<!-- More components can go here -->
<Component Id="..">
</Component>
</Feature>
Moreover, you can include wxs files instead of include, too. As long as the main wxs references at least one element from another wxs, the entire contents will be included.
I am using PMD plugin (version 4.0.2) for Eclipse (Eclipse Kepler Java EE). I have configured a naming rule: ShortVariable.
This works fine except for parameters like "id" and "e". I want PMD to ignore these. So I searched for a way to ignore certain parameters. I found this link (although it's for phpmd) and tried it, yet I can't seem to get it working. My config file looks like this (XML):
<?xml version="1.0"?>
<ruleset name="My PMD ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
My PMD
</description>
<rule ref="rulesets/java/naming.xml/ShortVariable">
<property name="exceptions" value="id" />
</rule>
</ruleset>
When I try to import this ruleset using the eclipse plugin, it shows no possible rules to import.
Any ideas?
I found a solution to my problem here.
The resulting xml looks like this:
<?xml version="1.0"?>
<ruleset name="My PMD ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
My PMD
</description>
<rule ref="rulesets/java/naming.xml/ShortVariable">
<properties>
<property name="xpath">
<value>
//VariableDeclaratorId[(string-length(#Image) < 3) and (not (#Image='id'))]
[not(ancestor::ForInit)]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))]
</value>
</property>
</properties>
</rule>
</ruleset>
To be able to ignore more variable names, repeat the following part:
and (not (#Image='myVariableToIgnore'))
The folowing XML is valid for PHP tool PHPMD 2.2.3
<?xml version="1.0"?>
<!DOCTYPE ruleset>
<ruleset
name="My PMD ruleset for symfony 2.5"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
>
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="id,em" />
</properties>
</rule>
</ruleset>
Update xml
<rule ref="category/java/codestyle.xml/ShortVariable">
<properties>
<property name="xpath">
<value>
//VariableDeclaratorId[(string-length(#Image) < 3) and (not (#Name='id'))]
[not(ancestor::ForInit)]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))]
</value>
</property>
</properties>
</rule>
I was creating custom content model
in datalistModel.xml
<type name="dl:car">
<title>Car List</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:carName">
<title>Car Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:carCompany">
<title>Company Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
</type>
in share-datalist-form-config.xml
<!-- dl:contact type create car form -->
<config evaluator="model-type" condition="dl:car">
<forms>
<!-- Create item form -->
<form>
<field-visibility>
<!-- dl:contact type -->
<show id="dl:carName" />
<show id="dl:carCompany" />
</field-visibility>
<create-form template="../data-lists/forms/dataitem.ftl" />
</form>
</forms>
</config>
When I create a new car content in repository browser(I later configured menu to add content type 'Car'), the file name is 91b65385-86c6-4923-859d-6ecb3326319c.
<create-content>
<content id="plain-text" mimetype="text/plain" label="create-content.text" itemid="cm:content" icon="text"/>
<content id="html" mimetype="text/html" label="create-content.html" itemid="cm:content"/>
<content id="xml" mimetype="text/xml" label="create-content.xml" itemid="cm:content"/>
<content id="car" mimetype="text/xml" icon="xml" label="create-content.car" itemid="dl:car"/>
</create-content>
How can I make the file name to carName instead of 91b65385-86c6-4923-859d-6ecb3326319c
Any kind help is appreciated.
Take a look at the default 'share-datalist-form-config.xml'
You will see that almost every type specify <show id="cm:title" />
You could also just put <show id="name" /> or <show id="cm:name" /> to show the name attribute.
In order to put the title you will need to put the cm:titled aspect in your model.
Just check the 'datalistModel.xml' how the defaults are defined
And check this blog post to know a bit more how to create custom datalists.
Can I read the the property value from an external file instead of specifing the value within the <property> tag.
So instead of -
<property name="device" value="test" />
Use something like
<property name="device" value="c:\\fileToRead" />
where file to read contains test,test2,test3
Thanks
The <property> task provides a means to load a java properties file, if that's what you mean:
<property file="c:\\fileToRead"/>
Maybe. While you can't use the content of the file, you can use a file that looks like so:
device=C:\\fileToRead
and then read that with
<property file="foo.properties"/>
(see the docs).
in build.xml
<property file="general.properties" />
general.properties file
svnant.version=1.0.0
lib.dir=${ant.home}/lib
So for you will be:
<property file="c:\\fileToRead" />
fileToRread is
device=test