Find workspace location using ANT - apache-flex

I'm working on a build script in the Flash Builder version of Eclipse. This build script needs to import launch configuration .launch files into the user's workspace. However there doesn't seem to be an available ANT var for determining the workspace location. While stepping through the available vars with intellisense I noticed that ${osgi.instance.area} does point to my current workspace but when I tried to echo it back in a running ant script it just spat out "${osgi.instance.area}" and not the path.
Any help would be greatly appreciated. Thank you!!!

If anyone is curious here is how I achieved this, however this is specifically tailored to Flash Builder/Flex Builder (as that's what our team uses) and unfortunately I could never get the ${eclipse.home} property to work in Ant so I had to use ${eclipse.pdebuild.scripts} to get at the installation directory:
<property name="install_loc" value=""/>
<!-- find the eclipse install location -->
<script language="javascript">
<![CDATA[
// Because ${eclipse.home} is not available, determine the install
// location using the pdebuild.scripts location
self.log("Looking for Eclipse installation...");
var base = project.getProperty("eclipse.pdebuild.scripts");
var path_pieces = base.split("/");
var path = "";
outterLoop: for(var i = path_pieces.length; i >= 0; --i)
{
if(path_pieces[i] == "Adobe Flash Builder 4" || path_pieces[i] == "Adobe Flex Builder 3")
{
// After determining which array item refers to the Adobe Flash Builder or Flex Builder
// installation, start at the beginning of the array and count up to that point, adding
// paths as you go.
var k = 0;
while( k <= i )
{
path += path_pieces[k] + "/";
++k;
}
break outterLoop;
}
}
// TODO: MAKE SURE THE PATH IS NOT EMPTY
self.log("Install path found at: " + path);
project.setProperty("install_loc", path);
]]>
</script>
<loadfile
property="workspace_prefs"
srcFile="${install_loc}configuration/.settings/org.eclipse.ui.ide.prefs">
</loadfile>
<property name="workspace_loc" value=""/>
<scriptdef name="find-workspace" language="javascript">
<attribute name="workspace_data"/>
<![CDATA[
// Find and return the workspace location
self.log("Looking for Eclipse workspace...");
var defs = attributes.get("workspace_data").split("=");
var loc = defs[defs.length - 1];
self.log("Workspace found: " + loc);
project.setProperty("workspace_loc", loc);
]]>
</scriptdef>
<find-workspace workspace_data="${workspace_prefs}" />
</target>

FWIW, I think this may give you similar functionality to the javascript part of your solution. The regular expression may be too simplistic for real-world use.
<pathconvert property="install_loc" dirsep="/">
<path location="${eclipse.pdebuild.scripts}"/>
<regexpmapper from="(^.*/Adobe [^/]*)" to="\1/"/>
</pathconvert>
For reference: Ant pathconvert and mapper docs.

This worked for me with a regular Eclipse installation, providing the script is run in Eclipse's own JVM:
<eclipse.convertPath resourcepath="workspace_loc:/" property="eclipse.workspace.home"/>
In order to denote an Ant script should run in Eclipse's own JVM, open the "External Tools Configurations..." dialog, choose your script from the left panel, go to the "JRE" tab, and choose the obvious radio button.
Amnon Grossman

Related

How can I have karate.log call from javascript added to cucumber reports? [duplicate]

This question already has answers here:
Logging Messages from Java Class back to the Karate Report
(3 answers)
Closed 1 year ago.
I want to be able to write log statements, that get added to the karate.log file as well as to the Cucumber Reports that get generated when using standalone karate.jar.
When I use karate.log from a javascript function it only adds the log statement to the karate.log file and not the cucumber report.
I have also tried to do this from a java function as well by using both slf4j logger as well as the com.intuit.karate.Logger class. However both of these only add logs to the karate.log file and not to the cucumber reports.
I need this because I am writing some common code for which I don't want my QA-Engineers to write * print <> statements in the karate feature files.
I also looked at the com.intuit.karate.core.ScriptBridge.log(Object... objects) method which is what I am assuming gets called when you call karate.log(..), it looks like it should work, but it isn't working for me.
I am using karate-0.9.4, and here's what my karate-config.js looks like
function conf() {
var env = karate.env // set the environment that is to be used for executing the test scripts
var host = '<some-host-name>';
var port = '443';
var protocol = 'https';
var basePath = java.lang.System.getenv('GOPATH') + '/src/karate-tests';
// a custom 'intelligent' default
if (!env) {
env = 'dev';
}
var applicationURL = ((!port || port == '') || (port == '80' && protocol == 'http') || (port == '443' && protocol == 'https'))
? protocol + '://' + host
: protocol + '://' + host + ":" + port;
// Fail quickly if there is a problem establishing connection or if server takes too long to respond
karate.configure('connectTimeout', 30000);
karate.configure('readTimeout', 30000);
// pretty print request and response
//karate.configure('logPrettyRequest', true);
//karate.configure('logPrettyResponse', true);
karate.configure('printEnabled', true);
// do not print steps starting with * in the reports
//karate.configure('report',{showLog: true, showAllSteps: true });
// Turn off SSL certificate check
karate.configure('ssl', true);
var config = {
env: env,
appBaseURL: applicationURL,
sharedBasePath: basePath
};
karate.log("config.sharedBasePath = ", config.sharedBasePath)
karate.log('karate.env = ', config.env);
karate.log('config.appBaseURL = ', config.appBaseURL);
return config
}
This is because of a bug in karate-0.9.4 which seems to be partially fixed in karate-0.9.5.RC4 release. I have opened a ticket for it on GitHub - https://github.com/intuit/karate/issues/975
I just tried this in 0.9.5.RC4. If you are looking for something more than this - it needs a change in Karate. You are welcome to contribute. I have to say that I'm surprised (and somewhat annoyed) to see these requests. Why are you so concerned about pretty reports instead of focusing on testing. I'd like you to think about it.
This other discussion may be a related reference: https://github.com/intuit/karate/issues/951 | https://github.com/intuit/karate/issues/965
If you really want to pursue this, you can look at the "hook" interceptor mentioned in this comment: https://github.com/intuit/karate/issues/970#issuecomment-557443551
So in void afterStep(StepResult result, ScenarioContext context); - you can modify the StepResult by calling appendToStepLog(String log).
EDIT: other references:
https://stackoverflow.com/a/57079152/143475
https://stackoverflow.com/a/47366897/143475

Lightswitch HTML - chat application upgrade

I wanted to know if anyone has given this a go and got it working?
http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/182/Connecting-To-SignalR-With-LightSwitch-HTML-Client.aspx
Basically my issue is i cant open the file to begin with, whether it be Visual Studio 2012, 2013 or 2015, so I have followed the guide and used the files from the downloaded project for this error message to occur:
which is caused by this line under the sendmessage_execute function:
chat.server.send(screen.displayname, screen.message);
im hoping someone has got this working and could point out anything different from the user guide, heres what I have used/done:
Under the PROJECT.Server I have:
created a folder called SignalR with the file ChatHub.cs in
added the json2.js (both) and signalR (both) files to the scripts
folder
Under the Project.HTMLClient
added the json2.js (both) and signalR (both) files to the scripts
folder
referenced the scripts including the localhost in the default.htm file
Created a screen. called ChatScreen and added all the referenced code here from the guide online (3 strings and 1 button)
i also installed the Nu-GET as instructed
More research for this was required, I found this post which explains how to do it a lot easier and in an application for both 2013/2015, works a treat and can easily be adapted for other screens
https://blogs.msdn.microsoft.com/rmattsampson/2013/03/14/asp-net-signalr-and-lightswitch-vs-2012-update-2-vs-2013-and-later/
I have also managed to edit there block of code to list all messages in a string, this is not stored and refresh's each time but its now possible to have a conversation while on the same screen
var string;
myapp.ChatScreen.created = function (screen) {
string = "";
$(function () {
chat = $.connection.chatHub;
chat.client.broadcastMessage = function (message) {
string = string + message + ";";
screen.updates = string.split(';').join("\r\n");
console.log(string.split(';').join("\r\n"))
};
$.connection.hub.start()
.done(function () {
})
.fail(function () {
alert("Could not Connect! - ensure EnableCrossDomain = true");
});
});
};
It would be better practice using an array and displaying it this way but the code above demonstrates it works

Qt Installer Framework Change Installation path and add subfolder

How to change the installer path and add subfolder using qt installer framework.
Default output:
C:\Program Files (x86)\Subfolder
I want to path to example output.
Example output:
D:\Subfolder
C:\Desktop\Subfolder
C:\Documents\Subfolder
I know this is old but maybe is usefull for someone.
I changed a Qt Installer Framework example called dynamicpage (look in QtIfw examples dir), where the target directory is selected from a custom widget called targetwidgetui. To avoid the user write directly in the line edit I added in my file config/controllerscript.qs this code:
Controller.prototype.TargetDirectoryPageCallback = function()
{
currentPage.TargetDirectoryLineEdit.enabled = false;
}
I also added #ApplicationsDir#/MyAppFolder in config.xml so this is the default install path.
When the user change the destination folder I take the path and append "/MyAppFolder". To do this I changed a function in the dynamicpage example, in file installscript.qs. This is how my function look like now:
Component.prototype.chooseTarget = function () {
var widget = gui.pageWidgetByObjectName("DynamicTargetWidget");
if (widget != null) {
var newTarget = QFileDialog.getExistingDirectory("Choose your target directory.", widget
.targetDirectory.text);
if (newTarget != "")
{
newTarget += "/MyAppFolder"; // The same subfolder of TargetDir in config.xml
widget.targetDirectory.text = Dir.toNativeSparator(newTarget);
}
}
}
Using this you will append always your folder to the installation path.
In your config.xml file you can add
<TargetDir>*YOUR_PATH*/subfolder</TargetDir>
To install to a custom directory.
From Qt Installer Framework documentation:
TargetDir
Default target directory for installation. On Linux, this is usually the user's home directory.
Note that you can use predefined variables like #ApplicationsDir# or #DesktopDir# as stated here.

wsh currentdirectory broken on Win 8.1?

We use HTA files to build installation CD's, so that we can display some introductory information and links to different setup options - each link goes to the appropriate setup.exe etc file. This has worked fine up to and including Windows 7, but on 8.1 (- not tried 8.0) it fails with an error 'Cannot find the file specified'. Turns out that this is because the current directory is now C:\Windows\System32, whereas it used to be the directory where the file was located - on the CD drive, and so relative paths would work for the links to the other files on the CD; now they don't.
In other words using this code in an hta file:
<script type="text/javascript" language="javascript">
function RunFile(appname)
{
WshShell = new ActiveXObject("WScript.Shell");
alert( WshShell.CurrentDirectory );
WshShell.Run(appname, 1, false);
}
on win 8.1 we see C:\Windows\System32 in the alert box and so relative paths such as ..\ourproduct\setup.exe no longer work.
Is this a bug? Any ideas how I can work around this?
You could extract the correct path from window.location.pathname, and then set the value to CurrentDirectory. I've used something like the code below:
var shell = new ActiveXObject('WScript.Shell'),
defaultInstallationFolder = 'installation_folder_name',
currentPath = window.location.pathname.replace(/\\/g,'/'),
defaultRootPath;
if (currentPath.charAt(0) === '/') { // For the browser environment
currentPath = currentPath.substring(1, currentPath.length);
}
currentPath = currentPath.split(defaultInstallationFolder);
defaultRootPath = currentPath[0] + defaultInstallationFolder;
shell.CurrentDirectory = defaultRootPath;
IE and HTA give a slightly different pathname (in IE it starts with /). Sometimes it's nice to debug a HTA in IE, hence the check for currentPath.

Flex: Loading assets into externally loaded modules

So, I have Flex project that loads a Module using the ModuleManager - not the module loader. The problem that I'm having is that to load an external asset (like a video or image) the path to load that asset has to be relative to the Module swf...not relative to the swf that loaded the module.
The question is - How can I load an asset into a loaded module using a path relative to the parent swf, not the module swf?
Arg! So in digging through the SWFLoader Class I found this chunk of code in private function loadContent:
// make relative paths relative to the SWF loading it, not the top-level SWF
if (!(url.indexOf(":") > -1 || url.indexOf("/") == 0 || url.indexOf("\\") == 0))
{
var rootURL:String;
if (SystemManagerGlobals.bootstrapLoaderInfoURL != null && SystemManagerGlobals.bootstrapLoaderInfoURL != "")
rootURL = SystemManagerGlobals.bootstrapLoaderInfoURL;
else if (root)
rootURL = LoaderUtil.normalizeURL(root.loaderInfo);
else if (systemManager)
rootURL = LoaderUtil.normalizeURL(DisplayObject(systemManager).loaderInfo);
if (rootURL)
{
var lastIndex:int = Math.max(rootURL.lastIndexOf("\\"), rootURL.lastIndexOf("/"));
if (lastIndex != -1)
url = rootURL.substr(0, lastIndex + 1) + url;
}
}
}
So apparently, Adobe has gone through the extra effort to make images load in the actual swf and not the top level swf (with no flag to choose otherwise...), so I guess I should submit a feature request to have some sort of "load relative to swf" flag, edit the SWFLoader directly, or maybe I should have everything relative to the individual swf and not the top level...any suggestions?
You can import mx.core.Application and then use Application.application.url to get the path of the host application in your module and use that as the basis for building the URLs.
For help in dealing with URLs, see the URLUtil class in the standard Flex libraries and the URI class in the as3corelib project.
You can use this.url in the module and use this as a baseURL.
var urlParts:Array = this.url.split("/");
urlParts.pop();
baseURL = urlParts.join("/");
Alert.show(baseURL);
and use {baseURL + "/location/file.ext"} instead of /location/file.ext

Resources