I'd like to be able to do things like separate the directory and file name from a full path in Hudson/Jenkins's jelly script.
For example if I have /dir1/dir2/dir3/file.ext I'd like to (in jelly script) get access to /dir1/dir2/dir3 and file.ext.
Are the java io functions like getPath() and getName() available to jelly script?
Dion Gillard's Jelly: Executable XML deck was really helpful in sorting this out. From the slides I learned about the invoke (and invokeStatic) tags which were exactly what I needed. The Apache FilenameUtils class has some very nice static methods for dealing with filenames and it's included with Hudson.
<j:jelly xmlns:j="jelly:core">
<j:set var="fullpath" value="/dir1/dir2/dir3/file.ext"/>
<!-- get the path without the filename -->
<j:invokeStatic var="justpath" method="getPath" className="org.apache.commons.io.FilenameUtils">
<j:arg value="${fullpath}"/>
</j:invokeStatic>
<!-- get just the filename -->
<j:invokeStatic var="justname" method="getName" className="org.apache.commons.io.FilenameUtils">
<j:arg value="${fullpath}"/>
</j:invokeStatic>
</j:jelly>
In the example above, justpath will be set to /dir1/dir2/dir3/ and justname will be set to file.ext.
Related
I'm trying to convert the GTK+2 code to compile and run on GTK+3. In the old code I have following:
gtk_widget_push_composite_child()/gtk_widget_pop_composite_child()
Now GTK+3 states that instead I should first call gtk_widget_init_template() and then gtk_widget_class_set_template()/gtk_widget_class_set_template_from_resource().
Now, those 2 functions use an XML template to build the composite widget from. Unfortunately there is no example on how to make one and what to pass to those function(s).
Do I pass the XML file name? The XML tree root node? The schema verification? Trying to google for the code example didn't yield anything useful.
Can anyone shed some light on this please?
There is an old blog post "Announcing Composite Widget Templates" that explains how it works. Usually taking a look at gtk3-demo should shed some light (better to run it).
To pass the name, you call it in the init method, as the example in the blog post:
static void
my_widget_class_init (MyWidgetClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
/* Setup the template GtkBuilder xml for this class
*/
gtk_widget_class_set_template_from_resource (widget_class, "/org/foo/my/mywidget.ui");
}
static void
my_widget_init (MyWidget *widget)
{
/* Initialize the template for this instance */
gtk_widget_init_template (GTK_WIDGET (widget));
}
The resources' files would look something like:
<gresources>
<gresource prefix="/org/foo/my">
<file alias="ui/password-view.ui" compressed="true" preprocess="xml-stripblanks">myapp-mywidget.ui</file>
</gresource>
</gresources>
In some part of your code, you will need to load the resources' file, where myapp-mywidget.ui is the actual filename with the UI file. You can have one file per template, and all of them listed in the resources' file.
I've seen that some projects used _ function that takes string as an argument, like _("Hello World"). But I couldn't find any manuals or articles about what is it and how to use it.
I guess this has something to do with i18n and l10n (it was mentioned in some article I found on the internet), but can you explain to me how it works and how to use it?
That is the GNU gettext localization function. You can provide language specific alternate strings for the one specified in the function call.
There is the xgettext tool, which generates a .pot file (abbreviation for portable object template) from your application code, then translators can make .po localization files for it. Then, you can bundle these with your application, and deliver a more widely usable piece of software.
I18n. See gettext example here: https://ewgeny.wordpress.com/2012/05/10/supporting-multiple-languages-in-your-application-a-simple-gettext-step-by-step-example/
Also found some info about what exactly this function do, it seems to be the macro for Glib.dgettext() function in Vala, this is from valadoc.org:
dgettext
public unowned string dgettext (string? domain, string msgid)
This function is a wrapper of dgettext which does not translate the message if the default domain as set with textdomain has no translations for the current locale.
...
Applications should normally not use this function directly, but use the _ macro for translations.
I have a project in Apps script that uses several libraries. The project needed a more complex logger (logging levels, color coding) so I wrote one that outputs to google docs. All is fine and dandy if I immediately print the output to the google doc, when I import the logger in all of the libraries separately. However I noticed that when doing a lot of logging it takes much longer than without. So I am looking for a way to write all of the output in a single go at the end when the main script finishes.
This would require either:
Being able to define the logging library once (in the main file) and somehow accessing this in the attached libs. I can't seem to find a way to get the main projects closure from within the libraries though.
Some sort of singleton logger object. Not sure if this is possible from with a library, I have trouble figuring it out either way.
Extending the built-in Logger to suit my needs, not sure though...
My project looks at follows:
Main Project
Library 1
Library 2
Library 3
Library 4
This is how I use my current logger:
var logger = new BetterLogger(/* logging level */);
logger.warn('this is a warning');
Thanks!
Instead of writing to the file at each logged message (which is the source of your slow down), you could write your log messages to the Logger Library's ScriptDB instance and add a .write() method to your logger that will output the messages in one go. Your logger constructor can take a messageGroup parameter which can serve as a unique identifier for the lines you would like to write. This would also allow you to use different files for logging output.
As you build your messages into proper output to write to the file (don't write each line individually, batch operations are your friend), you might want to remove the message from the ScriptDB. However, it might also be a nice place to pull back old logs.
Your message object might look something like this:
{
message: "My message",
color: "red",
messageGroup: "groupName",
level: 25,
timeStamp: new Date().getTime(), //ScriptDB won't take date objects natively
loggingFile: "Document Key"
}
The query would look like:
var db = ScriptDb.getMyDb();
var results = db.query({messageGroup: "groupName"}).sortBy("timeStamp",db.NUMERIC);
Is there any way to write to a text file in Flex 4.6? Its a desktop app for AIR. I would like to write the data from several arrays, as well as the time and date.
Threw a simple logger together for this test project:
http://www.shaunhusain.com/DrawTextRandomly/srcview/
it's in src/util/Logger.as
As is it marks the first time a log entry is made then counts the time from then till all other log entries and outputs it along with the logged string, it also outputs the time difference from the last log entry so you can get some idea of how long it takes for a function/algorithm/operation to complete. Feel free to grab this, albeit just a test snippet I should probably post a license on my code, I'll update the src folders with a license.txt with MIT License http://www.opensource.org/licenses/mit-license.html
You can re-purpose this class and have it write using a FileStream/File object in Flex. File itself is basically a handle to a particular file, FileStream will allow you to call writeUTFBytes(string) to write data to a file.
Code would be something like this:
var fs:FileStream = new FileStream();
fs.open(new File("logfile.txt"),FileMode.WRITE);
fs.writeUTFBytes("Some output");
fs.close();
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html
The as3corelib has a FileTarget class that can be used with the Flex Logging API.
This documentation page explains how to use the logging API.
1. Compiled Assembly from JSC
I've compiled what is intended to be client-side JavaScript using the JScript compiler (jsc.exe) on the server side in an attempt to make something that can be tested from a unit testing project, and maybe even something that can be debugged on the server side.
The compiled file contains only functions as follows (just for example) and it compiles fine into BitField.exe. Notice, no wrapper class or package in the source code.
------ BEGIN FILE (BitField.js) -------
function BitField(){
this.values = [];
}
// more functions ...
------- END FILE -------
jsc /fast- /out:BitField.exe Bitfield.js
Results in a BitField.exe assembly.
Success! Well, kind of ....
2. Testing Assembly / Access Point?
Secondly I've created a test project (in C#) and referenced in the BitField.exe assembly successfully. (The type of project is irrelevant but I'm providing more description to paint a full picture.)
The problem seems to be: I cannot find the namespace or a point at which I can access the BitField functions inside the BitField.exe assembly from my C# test project. The assembly doesn't seem to be a "normal".
In other words I need in C#
using ???WHAT???
Note: I don't want to use JScript "extensions", meaning keywords that won't run client-side (in a web browser), for example, class, package etc because I want the code to be clean as possible for copy & paste back into client side script environment (Regardless said "clean" code compiles fine by jsc.exe without use of those extensions). When I try to wrap the functions in package and class it starts producing compile errors so that's another reason not to use them - because they appear to make me alter my code.
Any suggestions as to how I can use the functions of the compiled JScript assembly (by having it referenced into another assembly) when there are no explicit containers in it?
Update / Proof
.NET Reflector view
After playing around with it for a while, and trying various combinations of command-line switches for jsc.exe, I'm pretty sure that what you're trying to do won't work as you'd wish it to. If you try to compile a js file that contains functions into a .Net library assembly, you get an error:
BitField.js(1,1) : error JS1234: Only type and package definitions are allowed inside a library
But, there is hope, yet! Here's what I would do...
I would keep your "clean" BitField.js file just as it is, and then create a batch file that wraps it in a JScript class and writes it out to a "dirty" js file. It's pretty clean if you think of it as part of the compilation of the code into the DLL. The code to wrap the BitField.js into BitFieldClass.js would look like this:
merge-into-class.js
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1;
var inputFile = fso.OpenTextFile("BitField.js",ForReading, false);
var outputFile = fso.CreateTextFile("BitFieldClass.js", true);
outputFile.write("class BitFieldClass{\n");
while (!inputFile.AtEndOfStream)
{
var textLine = inputFile.ReadLine();
outputFile.write (textLine + "\n");
}
outputFile.write("}");
outputFile.close();
Then the batch file to wrap it and compile it is really simple:
compile-js.bat
cscript merge-into-class.js
jsc /t:library /out:BitFieldClass.dll bitFieldClass.js
Of course, if you wanted to do multiple files, you'd have to parameterize things a bit, but hopefully this is enough to demonstrate the idea.