I don't understand this line of the code why we have list and DetailedUser?
<data>
//app class
<import type = "com.androidistanbul.databindingdemo.layoutdetails.DetailedUser/>
// java class
<import type= "java.util.List"/>
<variable
name = "userList"
type = "detailedUser" /> // import class
<variable
name="userList"
type = "list<DetailedUser" />
</data>
// List index
<TextView
// android:layout_midth = "wrap_content"
// android:layout_height= "wrap_content"
// android:layout_marginTop = "8dp"
android:text="#{userList[index].name + "" + userList[index].surnane}"/>
< and > are html entities and they represent < and >, respectively.
So List<DetailedUser> translates to List<DetailedUser>
My knowledge of ant is close to nothing.
i do understand it should not be used as a programming language but i'm a consumer of a certain ant project and want to modify something in my own project while using the libraries that project offers me.
the main point i want to do is I have a string and need to modify it before sending it to the parent project target.
i'll try providing a code easy to understand, but at the moment the part i have left is:
either store the value in a variable instead of a property (not sure how to do this)
directly call the other target from my javascript function.
so this is the code:
<target name="deploy-custom" depends="init">
<scriptdef name="replaceString" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
echo.setMessage("replace " + fileOut );
echo.perform( );
project.setProperty("undeploy_name", fileOut);]]>
</scriptdef>
<echo message="executing target deploy-custom" />
<for param="file">
<path>
<fileset dir="${mydir}/content/custom-deploy">
<include name="*.war" />
</fileset>
</path>
<sequential>
<replaceString fileIn="#{file}" directoryFile="${mydir}/content/custom-deploy/" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="#{file}" />
</sequential>
</for>
<echo>ABRS custom banklets deployed!</echo>
</target>
so my question is at the time i try to save the undeploy_name property can I just call the target deployToLiferay? if not is there a way i can save that in a variable instead a property?
i don't mind using other language instead of javascript but not really sure how can i do what i need to do.
based on the info i found in here i'm now trying to focus on the using the script directly. this is the info i get:
https://coderanch.com/t/108191/call-ant-macrodef-groovy-script
i tried to modify my script to something like this:
<macrodef name="undeploy">
<attribute name="undplPattern" />
<sequential>
<echo message="undeploy undplPattern #{undplPattern}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="#{undplPattern}" />
</JBossCLI>
</sequential>
</macrodef>
<scriptdef name="undeploy-pattern" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[
var echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
fileOut = fileOut.replace(/\d+/g, "");
fileOut = fileOut.replace("..",".*");
fileOut = fileOut.replace(/[.]/g,"\\.");
fileOut = fileOut.replace("web-\\.*\\.war","web.*");
echo.setMessage("undeploy pattern transformation: " + fileOut );
echo.perform( );
var undeploy_t = project.createTask("undeploy");
undeploy_t.setDynamicAttribute("undplPattern", fileOut);
undeploy_t.perform( );
]]>
</scriptdef>
called from:
<echo message="item #{file}" />
<undeploy-pattern fileIn="#{file}" directoryFile="${currentScriptDirectory}/content/custom-banklets/" />
<deployToLiferay file="#{file}" />
after this modifications it now fails when i try to set setDynamicAttribute and perform that task.
08:01:18.492: item /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.509: file name: /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.510: dir in /data/
08:01:18.520: undeploy pattern transformation: com\.client-dshbrd-banklet-web.*
08:01:18.528: COMMAND 'deploy-custom-banklets' FAILED (execution time: 2 seconds)
08:01:18.528: * /data/contribution.xml:250: The following error occurred while executing this line:
08:01:18.528: * /data/contribution.xml:259: required attribute undplpattern not set
I don't think you need an embedded script. I reviewed the logic and I think it would be simpler to use the ANT basename task in order to obtain the file name.
Example
├── build.xml
└── src
└── files
└── file1.war
Project run as follows
$ ant
build:
[echo] file1.war
build.xml
<project name="demo" default="build">
<target name="build">
<basename property="undeploy_name" file="src/files/file1.war"/>
<echo>${undeploy_name}</echo>
</target>
</project>
I need to specify default shipping method, for when none is provided on the entry form in Netsuite. For various reasons I have to do this within the PDF/HTML template.
This is the code I have so far, but it doesn't seem to work;
<#function toNumber val>
<#if val?has_content && val?length gt 0 >
<#return val?html?replace('[^0-9.]','','r')?number >
<#else><#return 0 ></#if></#function>
<#if record.shipmethod?has_content>
${record.shipmethod} <!-- if a courier is selected -->
<#else> <!-- else -->
<#list 2000..2560 as pcx> <!-- Sydney Metro postcodes -->
<#if toNumber(record.shipzip)==pcx>
Courier1 <!-- Standard Sydney Metro Courier -->
<#else> <!-- else -->
Courier2 <!-- Standard Interstate Courier -->
</#if></#list></#if>
Your loop is going to print something each time it runs (i.e. 560 lines)! Instead of looping through the numbers, you should to test if the zip code falls within a desired range using the lte (less than or equal to) and gte (greater than or equal to) comparison operators:
<#function toNumber val>
<#if val?has_content && val?length gt 0 >
<#return val?html?replace('[^0-9.]','','r')?number >
<#else><#return 0 ></#if></#function>
<#assign zip = toNumber(record.shipzip)>
<#if record.shipmethod?has_content>
${record.shipmethod}
<#elseif zip gte 2000 && zip lte 2560 >
Courier 1
<#else>
Courier 2
</#if>
I have created a msbuild file which will build a solution file(NOTE: not a project file). I would like to be able to change the debug and release target path in the msbuild file. How can i go about doing that? Thank you very much.
msbuild file
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="deploy">
<MSBuild Projects="foo.sln" Properties="Configuration=Release" ContinueOnError="false" />
</Target>
</Project>
Solution file Below:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "foo", ".", "{3D958438-10F1-4211-BC7F-F0A5E5601C3F}"
ProjectSection(WebsiteProperties) = preProject
TargetFramework = "3.5"
Debug.AspNetCompiler.VirtualPath = "/foo"
Debug.AspNetCompiler.PhysicalPath = "..\foo\"
Debug.AspNetCompiler.TargetPath = "..\..\PrecompiledWeb\foo\"
Debug.AspNetCompiler.Updateable = "true"
Debug.AspNetCompiler.ForceOverwrite = "true"
Debug.AspNetCompiler.FixedNames = "false"
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.VirtualPath = "/foo"
Release.AspNetCompiler.PhysicalPath = "..\foo\"
Release.AspNetCompiler.TargetPath = "..\..\PrecompiledWeb\foo\"
Release.AspNetCompiler.Updateable = "true"
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "51644"
DefaultWebSiteLanguage = "Visual Basic"
EndProjectSection
EndProject
To change the output, set the OutDir property. So instead of:
Properties="Configuration=Release"
try:
Properties="Configuration=Release;OutDir=d:\myCode\out\"
Hii,
there are many others had already post so many question about this..But here the scenario is different.
I need to extract the first three digits ie. $(major).$(Minor).$(Build) from version number.
how can i do this??..i tried AssemblyInfo Task..but that task is just for overwriting the version number.not to extract the version number.
I need to extract first three number and assign them to some property.for further use.
well,i can overwrite them using FileUpdate task.like ::
<FileUpdate
Files="#(AssemblyFile)"
Regex='(\d+)\.(\d+)\.(\d+)\.(\d+)'
ReplacementText='$1.$2.$3.$(Revision)'>
</FileUpdate>
now how can i use their value ie. $1,$2,$3 to assign to properties.???
Thanx.
You can read lines from files, get the string using regex and change it if you need. And if you're using MSBuild 4.0 you can use Property Functions, which give you an access to .NET API.
This example should give you first three numbers of the AssemblyVersion.
<Target Name="ReadAssemblyVersion">
<ReadLinesFromFile File="$(VersionFile)">
<Output TaskParameter="Lines"
ItemName="ItemsFromFile"/>
</ReadLinesFromFile>
<PropertyGroup>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+)</Pattern>
<In>#(ItemsFromFile)</In>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
</PropertyGroup>
<Message Text="Output : $(Out.Remove(0, 28))"/>
</Target>
http://blogs.msdn.com/b/visualstudio/archive/2010/04/02/msbuild-property-functions.aspx
Awesome thread, building upon the work of Alex and RobPol, I was able to define extended msbuild properties that is inspired by semver.org (Major, Minor, Patch, PreRelease). I chose to parse the AssemblyInformalVersion since that is the only attribute compatible with SemVer. Here is My example:
<PropertyGroup>
<In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs'))</In>
<Pattern>\[assembly: AssemblyInformationalVersion\("(?<Major>\d+)\.(?<Minor>\d+)\.(?<Patch>[\d]+)(?<PreReleaseInfo>[0-9A-Za-z-.]+)?</Pattern>
<AssemblyVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["Major"].Value)</AssemblyVersionMajor>
<AssemblyVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["Minor"].Value)</AssemblyVersionMinor>
<AssemblyVersionPatch>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["Patch"].Value)</AssemblyVersionPatch>
<AssemblyVersionPreRelease>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["PreReleaseInfo"].Value)</AssemblyVersionPreRelease>
</PropertyGroup>
You can test the output of this operation by adding the following to your .csproj:
<Target Name="AfterBuild">
<Message Text="$(AssemblyVersionMajor)"></Message>
<Message Text="$(AssemblyVersionMinor)"></Message>
<Message Text="$(AssemblyVersionPatch)"></Message>
<Message Text="$(AssemblyVersionPreRelease)"></Message>
</Target>
Ex: Snippet from my AssemblyInfo.cs:
[assembly: AssemblyInformationalVersion("0.9.1-beta")]
Will output: Major: '0', Minor: '9', Patch: '1', PreRelease: '-beta'
Building on Alex's answer, I used RegEx to read the AssemblyVersion (and other information) and use that in my WiX/MSI filename and version strings. Hopefully my answer isn't too noisy.
Here is the top of my .wixproj file. Points of interest are the first PropertyGroup, OutputName, and DefineConstants:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\..\MyApplication\Properties\AssemblyInfoCommon.cs'))</In>
<Pattern>^\s*\[assembly: AssemblyVersion\(\D*(\d+)\.(\d+)\.(\d+)</Pattern>
<AssemblyVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyVersionMajor>
<AssemblyVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[2].Value)</AssemblyVersionMinor>
<AssemblyVersionBuild>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[3].Value)</AssemblyVersionBuild>
<Pattern>^\s*\[assembly: AssemblyDescription\(\s*"([^"]+)"</Pattern>
<AssemblyDescription>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyDescription>
<Pattern>^\s*\[assembly: AssemblyProduct\(\s*"([^"]+)"</Pattern>
<AssemblyProduct>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyProduct>
<Pattern>^\s*\[assembly: AssemblyCompany\(\s*"([^"]+)"</Pattern>
<AssemblyCompany>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyCompany>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.7</ProductVersion>
<ProjectGuid>MYGUID00-840B-4055-8251-F2B83BC5DBB9</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>$(AssemblyProduct)-$(AssemblyVersionMajor).$(AssemblyVersionMinor).$(AssemblyVersionBuild)</OutputName>
<OutputType>Package</OutputType>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;AssemblyVersionMajor=$(AssemblyVersionMajor);AssemblyVersionMinor=$(AssemblyVersionMinor);AssemblyVersionBuild=$(AssemblyVersionBuild);AssemblyDescription=$(AssemblyDescription);AssemblyProduct=$(AssemblyProduct);AssemblyCompany=$(AssemblyCompany)</DefineConstants>
<SuppressValidation>False</SuppressValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>AssemblyVersionMajor=$(AssemblyVersionMajor);AssemblyVersionMinor=$(AssemblyVersionMinor);AssemblyVersionBuild=$(AssemblyVersionBuild);AssemblyDescription=$(AssemblyDescription);AssemblyProduct=$(AssemblyProduct);AssemblyCompany=$(AssemblyCompany)</DefineConstants>
</PropertyGroup>
And then in a .wxi file I have this:
<?define MajorVersion="$(var.AssemblyVersionMajor)" ?>
<?define MinorVersion="$(var.AssemblyVersionMinor)" ?>
<?define BuildVersion="$(var.AssemblyVersionBuild)" ?>
<?define VersionNumber="$(var.MajorVersion).$(var.MinorVersion).$(var.BuildVersion)" ?>
And finally in my Product.wxs:
<?include Definitions.wxi ?>
<Product Id="$(var.GuidProduct)" Name="$(var.AssemblyProduct) $(var.VersionNumber)" Language="!(loc.LANG)"
Version="$(var.VersionNumber)" Manufacturer="$(var.AssemblyCompany)" UpgradeCode="$(var.GuidUpgrade)">
<Package Id="$(var.GuidPackage)" InstallerVersion="301" Compressed="yes" InstallScope="perMachine"
Keywords="!(loc.Keywords)" Description="$(var.AssemblyProduct)" Comments="$(var.AssemblyDescription)" />
If you want to be able to process your AssemblyInfo file with 100% accuracy you can use a C# task + Roslyn.
public class ReadAssemblyInfo : Task {
[Required]
public string AssemblyInfoFilePath { get; set; }
[Output]
public TaskItem AssemblyVersion { get; set; }
[Output]
public TaskItem AssemblyInformationalVersion { get; set; }
[Output]
public TaskItem AssemblyFileVersion { get; set; }
public override bool Execute() {
using (var reader = new StreamReader(AssemblyInfoFilePath)) {
var text = reader.ReadToEnd();
var tree = CSharpSyntaxTree.ParseText(text);
var root = (CompilationUnitSyntax)tree.GetRoot();
var attributeLists = root.DescendantNodes().OfType<AttributeListSyntax>();
foreach (var p in attributeLists) {
foreach (var attribute in p.Attributes) {
var identifier = attribute.Name as IdentifierNameSyntax;
if (identifier != null) {
var value = ParseAttribute("AssemblyInformationalVersion", identifier, attribute);
if (value != null) {
SetMetadata(AssemblyInformationalVersion = new TaskItem(value.ToString()), value);
break;
}
value = ParseAttribute("AssemblyVersion", identifier, attribute);
if (value != null) {
SetMetadata(AssemblyVersion = new TaskItem(value.ToString()), value);
break;
}
value = ParseAttribute("AssemblyFileVersion", identifier, attribute);
if (value != null) {
SetMetadata(AssemblyFileVersion = new TaskItem(value.ToString()), value);
break;
}
}
}
}
}
return !Log.HasLoggedErrors;
}
private void SetMetadata(TaskItem taskItem, Version version) {
taskItem.SetMetadata(nameof(version.Major), version.Major.ToString());
taskItem.SetMetadata(nameof(version.Minor), version.Minor.ToString());
taskItem.SetMetadata(nameof(version.Build), version.Build.ToString());
taskItem.SetMetadata(nameof(version.Revision), version.Revision.ToString());
}
private static Version ParseAttribute(string attributeName, IdentifierNameSyntax identifier, AttributeSyntax attribute) {
if (identifier.Identifier.Text.IndexOf(attributeName, StringComparison.Ordinal) >= 0) {
AttributeArgumentSyntax listArgument = attribute.ArgumentList.Arguments[0];
var rawText = listArgument.Expression.GetText().ToString();
if (!string.IsNullOrWhiteSpace(rawText)) {
rawText = rawText.Replace("\"", "");
Version version;
if (Version.TryParse(rawText, out version)) {
return version;
}
}
}
return null;
}
}
I just found this on google, might help:
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.version%28v=VS.90%29.aspx
Particularly:
//For AssemblyFileVersion
Assembly asm = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
string version = fvi.FileVersion
//For AssemblyVersion
string revision = Assembly.GetExecutingAssembly().GetName().Version.Revision;
You can use MSBuild.Community.Tasks.AssemblyInfo.AssemblyVersion to access AssemblyVersion and AssemblyFileVersion from AssemblyInfo.cs.
Indeed this task can only be used to set the version.
Maybe this post is usefull.
I use the RegexMatch-task from the MSBuild.Community.Tasks.
You can write the output of the match to an itemgroup, although you want to read it into 3 properties, as above, a custom task would then be prefered.
The only solution is to write a custom build task, and parse the version number manually in the code.