Using compiler constants with <compc /> ant task - apache-flex

I'm converting an existing build script from <mxmlc /> to <compc /> to generate a swc.
However, the build is failing, giving the error:
[compc] C:\xxxx\LogViewer.mxml(32): Error: Access of undefined property VERSION.
[compc]
[compc] private static const VERSION:String = CONFIG::VERSION;
In my ant task, I have the following defined:
<compc compiler.as3="true" output="${output.dir}/${swc.name}.swc" incremental="true" fork="true" maxmemory="512m" compiler.show-deprecation-warnings="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${srcdir}" />
<include-sources dir="${srcdir}" includes="*" />
<external-library-path dir="${swc.libs.dir}" append="true">
<include name="*.swc" />
</external-library-path>
<external-library-path dir="${output.common.swc.dir}" append="true">
<include name="*.swc" />
</external-library-path>
<compiler.define name="CONFIG::VERSION" value="${build.version}" />
<compiler.define name="CONFIG::RELEASE" value="${config.release}" />
<compiler.define name="CONFIG::DEBUG" value="${config.debug}" />
<compiler.define name="CONFIG::AUTOMATION" value="false" />
</compc>
This approach worked fine with the task, but is now failing.
What's the correct way to use compiler constants with compc?

String values need to be put in single quotes. For instance:
<compiler.define name="CONFIG::VERSION" value="'${build.version}'" />
The Flex Ant tasks really are incredibly frustrating, mainly due to the lack of documentation. I struggled with this for a while until I figured it out.

We do something similar in our build, and the only difference I can see is that we don't have the compiler bit:
<define name="CONFIG::build" value="5" />

Related

How to loop macrodef in Ant script?

Currently, I am writing an Ant Script that removes the signatures of signed Jar files.
Removing the signature for a single jar file was successful using the script below.
<project name="unsign">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="ant-lib/ant-contrib-0.6.jar" />
<property name="jarPath" location="C:\Users\Administrator\Desktop\tempDir" />
<property name="resultPath" location="C:\Users\Administrator\Desktop\tempDir-result" />
<target name="unsignJar">
<unsignjar jarFile="${jarPath}/com.google.guava_15.0.0.v201403281430.jar" />
</target>
<macrodef name="unsignjar" description="Unsign a jar file">
<attribute name="jarfile" description="Jar file to unsign " />
<sequential>
<copy toFile="#{jarFile}_MANIFEST.tmp">
<resources>
<zipentry zipfile="#{jarFile}" name="META-INF/MANIFEST.MF" />
</resources>
</copy>
<replaceregexp file="#{jarFile}_MANIFEST.tmp" match="\nName:(.+?)\nSH" replace="SH" flags="gis" byline="false" />
<replaceregexp file="#{jarFile}_MANIFEST.tmp" match="SHA(.*)" replace="" flags="gis" byline="false" />
<jar jarfile="#{jarFile}.tmp" manifest="#{jarFile}_MANIFEST.tmp">
<zipfileset src="#{jarFile}">
<include name="**" />
<exclude name="META-INF/*.SF" />
<exclude name="META-INF/*.DSA" />
<exclude name="META-INF/*.RSA" />
</zipfileset>
</jar>
<!-- Removing the temporary manifest -->
<delete file="#{jarFile}_MANIFEST.tmp" />
<!-- Swapping the original Jar file with the temporary one -->
<move file="#{jarFile}.tmp" tofile="#{jarFile}" overwrite="true" />
</sequential>
</macrodef>
</project>

NLog use Connection String Name in appsettings

I have an NLog database target that looks like this:
<target xsi:type="Database" name="database"
connectionString="Server=.\SQLEXPRESS;Database=ApplicationOne;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=User0101;Password=PW0101"
commandText="INSERT INTO [SchemaOne].[EventLogs](Id, Message, Level, Logger )VALUES(NewID(), #Message, #Level, #Logger)">
<parameter name="#Message" layout="${message}" />
<parameter name="#Level" layout="${level}" />
<parameter name="#Logger" layout="${logger}" />
</target>
Is it possible to change the connectionString to use connectionStringName from my appsettings instead?
My appsettings is called dssettings.json and it contains the connection details here:
"DatabaseConfiguration": {
"DatabaseName": "ApplicationOne",
"ConnectionName": "DefaultConnection",
"ConnectionString": "Server=.\\SQLEXPRESS;Database=ApplicationOne;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=User0101;Password=PW0101"
},
Update NLog.Extension.Logging ver. 1.4.0
With NLog.Extension.Logging ver. 1.4.0 then you can now use ${configsetting}
See also: https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer
Original Answer
With help from nuget-package NLog.Appsettings.Standard then you can normally do this:
<extensions>
<add assembly="NLog.Appsettings.Standard" />
</extensions>
<targets>
<target xsi:type="Database" name="database"
connectionString="${appsettings:name=DatabaseConfiguration.ConnectionString}"
commandText="INSERT INTO [SchemaOne].[EventLogs](Id, Message, Level, Logger )VALUES(NewID(), #Message, #Level, #Logger)">
<parameter name="#Message" layout="${message}" />
<parameter name="#Level" layout="${level}" />
<parameter name="#Logger" layout="${logger}" />
</target>
</targets>
But because you are using a special dssettings.json (instead of appsettings.json), then you probably have to implement your own custom NLog layout renderer:
https://github.com/NLog/NLog/wiki/How-to-write-a-custom-layout-renderer
Maybe you can use the source-code from the above nuget-package as inspiration for loading dssettings.json. Or maybe create PullRequest that adds support for specifying non-default config-filename.

Css is not working after deployment of a JavaFX app in Eclipse

If I deploy a JavaFX app from Eclipse then it won't load the CSS file for some reason, though the app works as expected inside Eclipse.
Main class:
public class Main extends Application {
Stage primaryStage;
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
showMain();
}
public void showMain(){
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("Mainwindow.fxml"));
AnchorPane ap = loader.load();
ap.getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
Scene scene = new Scene(ap);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
The css is:
#CHARSET "UTF-8";
.button{
-fx-background-color: blue;
}
The fxml:
<AnchorPane prefHeight="381.0" prefWidth="446.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<children>
<Button layoutX="14.0" layoutY="14.0" mnemonicParsing="false" text="Button" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="14.0" />
</children>
</AnchorPane>
In the build.xml I just set the obligatory things. I don't convert the css into bss. I sign it and that's all.
The build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="JavaFXTester6_Web" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
<target name="setup-staging-area">
<delete dir="externalLibs" />
<delete dir="project" />
<delete dir="projectRefs" />
<mkdir dir="externalLibs" />
<mkdir dir="project" />
<copy todir="project">
<fileset dir="/home/zooey/LinuxEclipse/linuxWorkspace/JavaFXTester6_Web">
<include name="src/**" />
</fileset>
</copy>
<mkdir dir="projectRefs" />
</target>
<target name='do-compile'>
<delete dir="build" />
<mkdir dir="build/src" />
<mkdir dir="build/libs" />
<mkdir dir="build/classes" />
<!-- Copy project-libs references -->
<copy todir="build/libs">
<fileset dir="externalLibs">
</fileset>
</copy>
<!-- Copy project references -->
<!-- Copy project sources itself -->
<copy todir="build/src">
<fileset dir="project/src">
<include name="**/*"/>
</fileset>
</copy>
<javac includeantruntime="false" source="1.8" target="1.8" srcdir="build/src" destdir="build/classes" encoding="UTF-8">
<classpath>
<fileset dir="build/libs">
<include name="*"/>
</fileset>
</classpath>
</javac>
<!-- Copy over none Java-Files -->
<copy todir="build/classes">
<fileset dir="project/src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="do-deploy" depends="setup-staging-area, do-compile, init-fx-tasks">
<delete file="dist"/>
<delete file="deploy" />
<mkdir dir="dist" />
<mkdir dir="dist/libs" />
<copy todir="dist/libs">
<fileset dir="externalLibs">
<include name="*" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="JavaFXTester6_Web.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
</fx:resources>
<fx:application id="fxApplication"
name="Test"
mainClass="application.Main"
/>
<mkdir dir="build/classes/META-INF" />
<fx:jar destfile="dist/JavaFXTester6_Web.jar">
<fx:application refid="fxApplication"/>
<fileset dir="build/classes">
</fileset>
<fx:resources refid="appRes"/>
<manifest>
<attribute name="Implementation-Vendor" value="ZA"/>
<attribute name="Implementation-Title" value="Test"/>
<attribute name="Implementation-Version" value="1.0"/>
<attribute name="JavaFX-Feature-Proxy" value="None"/>
</manifest>
</fx:jar>
<fx:signjar //intentionally removed >
<fileset dir='dist'>
<include name='**/*.jar' />
</fileset>
</fx:signjar>
<mkdir dir="deploy" />
<!-- Need to use ${basedir} because somehow the ant task is calculating the directory differently -->
<fx:deploy
embedJNLP="false"
extension="false"
width="400" height="400"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="JavaFXTester6_Web"
placeholderref="webtest"
placeholderid="webtest"
updatemode="background" >
<fx:info title="JavaFXTester6_Web" vendor="ZA"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
<fx:permissions elevated="true"/>
</fx:deploy>
</target>
The file system I get after running the build.xml:
The same in my file browser:
I couldn't fin any solutions, everybody mentions the conversion from css to bss, but I tried both (so with Main.class.getResource(style.bss)... too) and no solution. I have unfortunately no more ideas. Can you help? Thank you!
The problem is because of the #CHARSET "UTF-8"; in your css file.
JavaFX cannot parse it and will throw a parse exception.
Remove the CHARSET declaration from the css and try again.
I have the same problem. It all works fine in Eclipse but when I compile and run the jar, the CSS is ignored. Extracting the complied jar shows the CSS file and images in the same folder as the Java class files.
FXML
<stylesheets>
<URL value="#Style.css" />
</stylesheets>
CSS
-fx-background-image: url("background.jpg");
Okay, I figured it out. The CSS file and the image file need to be in the root directory of the jar. In Eclipse the CSS file and image files are in the package with the Java files, but when you compile they need to go in the src folder outside of the package.
You do not need the line;
Java
ap.getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
The FXML file should tell the program where to find the CSS file, and the CSS file tells the program where to find images.

Unity Interception MethodSignatureMatchingRule could not be resolved

Im using Unity (3.0) interception to add some crosscutting concerns to my application. Somehow I can't use the MethodSignatureMatchingRule in my configuration getting this error message:
{"The type name or alias MethodSignatureMatchingRule could not be resolved. Please check your configuration file and verify this type name."}
My configuration:
<?xml version="1.0"?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />
<alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<containers>
<container name="MyContainer">
<extension type="Interception"/>
<interception>
<policy name="EhabAspect">
<matchingRule name="MethodSignatureMatchingRule" type="MethodSignatureMatchingRule">
<constructor>
<param name="methodName" value="Receive" type="string"/>
</constructor>
</matchingRule>
<callHandler ... (omitted)
</policy>
</interception>
<register type="IMyClass" mapTo="MyClass">
<lifetime type="singleton" />
<interceptor type="InterfaceInterceptor"/>
<policyInjection/>
</register>
</container>
</containers>
</unity>
The same configuration with the NamespaceMatchingRule works fine.
My assembly contains a reference to
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.Unity
Microsoft.Practices.Unity.Configuration
Any suggestions?
I was facing the same problem here. I solved using the full qualified name of the of the class.
<matchingRule name="AuthorizationMethod" type="Microsoft.Practices.Unity.InterceptionExtension.MethodSignatureMatchingRule, Microsoft.Practices.Unity.Interception">
<constructor>
<param name="methodName" value="Authenticate" type="string"/>
<param name="parameterTypeNames" dependencyName="EmptyArray"/>
</constructor>
</matchingRule>

preserve-order set true does not run TestNG tests in order with group dependencies defined

I am trying to run grouped TestNG tests. The given xml is a test in testng.xml:
<test name="demo test" preserve-order="true">
<groups>
<run>
<include name="openlogin"/>
<include name="login"/>
<include name="searchPatient"/>
<include name="scheduleBySearch" />
<include name="openDashboardFromPatientToday"/>
<include name="openPatientChart"/>
<include name="referralSearch"/>
<include name="referralNotes"/>
<include name="removeReferral"/>
<include name="nonExistingReferralSearch"/>
</run>
<dependencies>
<group name="removeReferral" depends-on="referralNotes"/>
<group name="referralNotes" depends-on="referralSearch"/>
<group name="referralSearch" depends-on="openPatientChart"/>
<group name="openPatientChart" depends-on="openDashboardFromPatientToday"/>
<group name="openDashboardFromPatientToday" depends-on="scheduleBySearch"/>
<group name="scheduleBySearch" depends-on="searchPatient" />
<group name="searchPatient" depends-on="login" />
<group name="login" depends-on="openlogin"/>
</dependencies>
</groups>
<classes>
<class name="xtr.webaut.sanitytests.LoginTests"/>
<class name="xtr.webaut.sanitytests.PatientSearchTest"/>
<class name="xtr.webaut.sanitytests.PatientScheduleTests"/>
<class name="xtr.webaut.sanitytests.PatientTodayTests"/>
<class name="xtr.webaut.sanitytests.PatientDashboardViewTests"/>
<class name="xtr.webaut.sanitytests.PatientChartReferralTests"/>
</classes>
</test>
Here there is a group "nonExistingReferralSearch" that I don't want to be dependent upon any other group. But I want it to be executed in the specified order and I have set "preserve-order" as true for the <test>. While execution, I find that TestNG does not execute the non-dependent group in order. It executes that group immediately after the group "openlogin" whereas I am expecting it to get executed in the end.
Is it wrong to define dependencies as well as tell TestNG to maintain an order of execution? Is there an unknown priority defined that TestNG will execute any non-dependent tests/groups first and then the dependent tests? I hope it is not that inflexible.
Even for a generic scenario in a <test>, is it not possible to run some test methods/groups without any dependency and some test methods/groups with dependencies, in an order?
I added the preserve-order parameter in the suite. The tests run in the order we specified.
<suite name="Suite" preserve-order="true">
Worked for me when I gave like this .
<test name="Suite" preserve-order="true" parallel="false" enabled="true">

Resources