Page 1 of 1

${ask} for a folder rather than a file

Posted: Wed Mar 08, 2017 8:23 pm
by martindholmes
Hi there,

We have an ant scenario which requires as input a folder whose contents will be processed. We're using ${ask} to have the user specify that folder, with the param 'url', which enables the user to choose a local file; but we don't actually want a file, we want a folder. Of course if the user chooses any file, we can strip the filename off the end to get the folder, but there will be cases in which there are no files in the folder, only subfolders. Is there any way to ${ask} for a folder rather than a file?

All help appreciated,
Martin

Re: ${ask} for a folder rather than a file

Posted: Thu Mar 09, 2017 1:55 am
by martindholmes
I hadn't realized that Ron had already asked this:

topic11034.html

and the response (from 2014) was that an improvement request would be added. Did anything happen with that?

I'd like to avoid the necessity for users to install a plugin just for this functionality if possible.

Cheers,
Martin

Re: ${ask} for a folder rather than a file

Posted: Thu Mar 09, 2017 9:27 am
by Radu
Hi Martin,

We have not yet implemented this request. I will try to enhance its priority, maybe we'll get the time to do it for Oxygen 19.1 (Autumn this year).
Actually besides building an Oxygen plugin which would maybe resolve a custom editor variable by showing the dialog to the end user, you can also show dialogs directly from ANT. ANT allows Javascript code to be executed and this Javascript code can invoke in its turn Java code.
Something like this:

Code: Select all

<project basedir="." name="bla" default="dist">
<target name="dist">
<script language="javascript">
<![CDATA[
var answer = javax.swing.JOptionPane.showInputDialog( 'Question for you', 'defaultValue' );
project.setProperty('answer', answer);
]]>
</script>
<echo>${answer}</echo>
</target>
</project>
Regards,
Radu

Re: ${ask} for a folder rather than a file

Posted: Thu Mar 09, 2017 8:18 pm
by martindholmes
Thanks Radu, that's a good suggestion; I've used Java dialogs and JS in ant before.

Re Joey's post in the other thread: we're actually both working on the same project and hacking at the same problem, but we didn't realize we'd both posted on it. :-)

Cheers,
Martin

Re: ${ask} for a folder rather than a file

Posted: Fri Mar 10, 2017 2:53 am
by martindholmes
For anyone else trying to do this, this works both inside and outside Oxygen (tested only on Linux so far, but I'll report back if it fails when tested on other platforms):

Code: Select all


    <target name="getDirectory">
<script language="javascript">
<![CDATA[
var chooser = new javax.swing.JFileChooser();
chooser.setDialogTitle("Choose the directory containing your TEI files");
chooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
chooser.setCurrentDirectory(new java.io.File("."));
if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
dir = chooser.getSelectedFile();
project.setProperty('projectDir', dir);
}
]]>
</script>
<echo>${projectDir}</echo>
</target>

Re: ${ask} for a folder rather than a file

Posted: Sat Mar 11, 2017 12:01 am
by martindholmes
Update on this: it works fine in Oxygen on Windows, but fails if I run ant from the command line, with:"

C:\Users\mholmes\Documents\diagnostics\build.xml:107: org.mozilla.javascript.EcmaError: ReferenceError: "javax" is not defined.
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)

For the record, I have the Oracle JDK 8 installed, I have the JDK's bin in my path, JAVA_HOME is set correctly, tools.jar is there, javac -version works; I can't think of anything else I can test. Do any of you Windows mavens know what generates this? The OpenJDK on Linux seems to be using Nashorn, whereas these messages look like they might be coming from Rhino, but I don't know.

(I realize it's not strictly on-topic to try to get something working _outside_ Oxygen, but I'd like to allow non-Oxygen users to run the script too.)

Re: ${ask} for a folder rather than a file

Posted: Mon Mar 13, 2017 10:08 am
by Radu
Hi Martin,

I'm afraid I have no idea how to help further.

Regards,
Radu