Netbeans Ant build task to take multiple values in one input dialog - java

Upon building a jar/war etc I'd like to show the user the current version (stored in a properties file in the project) and already read into ns.MAJORVERSION and ns.MINORVERSION and allow them to update before writing to the manifest.
Ideally I'd like to take two inputs at once like so...
<input
message="Current Version is ${ns.MAJORVERSION} :${ns.MINORVERSION} update?"
addproperty="new.majorversion"
addproperty="new.minorversion"
/>
However this is not allowed and fails with an error saying 'Attribute "addproperty" was already specified'
Is there anyway of doing this in one dialog (I presume netbeans is setting the default input handler as a pop up dialog) or do I just need to have two inputs?

have single input as version in a format like MAJORVERSION.MINORVERSION and then split them in two separate properties.
PropertyRegex from ant contrib may come handy (http://ant-contrib.sourceforge.net/tasks/tasks/propertyregex.html)
Alternatively, yes, separate in two distinct inputs.

Related

Auto Diff and Merge for Java Strings

In my system the user can make changes to JBoss Drools code either through a code editor or a GUI. My problem is if the user makes changes in the code editor and then subsequently in the GUI then the changes from the code editor are lost. Because the GUI tool works by taking a template of the code and plugging in changes made through parameters (FreeMarkerTemplateUtils.processTemplateIntoString).
Does anyone have any suggestions for this problem in general?
One thought was to use Diff Match Patch to somehow merge the changes from GUI with those in the code editor. If this is the way could you please share some code (most of what I found online was just for comparing files not for generating the acutal diff from Strings).
Thanks.
First assumption, the change pattern in code editor would always match with the one GUI uses?
e.g., if the file body pattern is something like
<some text .........>___ReplaceThisString__<some more text ..............>
If it is like that, you could write a method on GUI save, which works something like most of the code repository, like SVN's diff and merge do.
Make a line by line comparison between file saved by code editor (say left) and GUI (say right), you will have 3 conditions,
Only left (changes in a line by code editor content)
Only in right (changes in a line by GUI)
Conflict (a line changed in both code content and GUI)
Ideally, you could merge only left/right without any difficulty, with logic that you take the either change.
For 3rd condition, you must let user decide what to take to maintain correctness of the file functionally, otherwise the file may fail to behave correctly by the next program.
For letting the user decide, you may with to create a compare window showing the user, the difference in two files, and let user simply click on that which one needs to be taken.
Ideally, in all the cases, it is better to show diff and let user confirm that the merge is not breaking the content integrity of the file.
2 things are important here:
A) The merge functionality should be there for code editor as well as in GUI; whenever someone try to save something from code editor. If it is not possible to have this (say you are using a code editor from a 3rd party, e.g. notepad), you should go for 2-step save-promote solution.
In this case, only saving will not change the actual file, rather the file is written in a different location, as a temporary file.
In step-2, 'promote step' - You should have a tool (build one with above strategy) to compare the temp file and original file. Then the user could visually merge the changes.
Same applies for GUI editor.
B) Whenever you do a compare and merge, the original file must be locked for modification, so that another user do not change the file, while somebody is merging.

How can I set the default Scope in IntelliJ 12 for Find Usages?

I've returned to IntelliJ after a long hiatus for Android development so I'm getting used to it again. The problem I have is that for example when you want to see where is a class being used, you'd position the caret in the class declaration and issue cmdaltF7 (on Mac OS X) to Find Usages, which is returning stuff from mapping.txt and seeds.txt as well as the .java results, and even tho I can set up the defaults by doing shiftcmdaltF7 and un-tick the: search for text occurrences and even change the scope from Project Files to a custom scope (for example), these options are not saved when I invoke Find Usages again.
Does anybody know of a way to personalize the Find Usages so it's more close to what Eclipse would do? (I.e., find the real usages instead of a text search for occurrences).
Reporting back from the future: the behaviour described in the question has now been implemented (Intellij issue mentioned in the comments).
To configure cmdaltF7 to run in a default scope, start by running it against some Symbol
Clicking on the wrench icon, one can select one of the pre-defined scopes, or create a new one (using the ... button).
The + creates a new scope. Find the folder in which to look, and click Include recursively. And voila!
Any consequent searches will use that scope until it is changed.
Instead of cmdaltF7, use the shortcut altF7. This will open a pop-up for you to make a selection about Scope, Test occurrences, and types of usage. You will have to make this selection one time. The next time you press altF7 then your choices are remembered.
The result is that altF7 followed by enter gives you what you need.

Create Eclipse shortcut to run particular target of an build file

I have different projects and several build files with different targets in it.
Generally if i want to run a target i use to navigate to 'Ant' view and then select the build file and then selects the target to run.
Instead of doing several steps every time, is there any way to assign a keyboard shortcut for particular target so that i can run that target easily.
The main preference page for keys can be found under Window > Preferences > General > Keys (or faster: Press Ctrl+3, type Keys and press Enter) . See How to manage keyboard shortcuts in Eclipse and why you should article to achieve what you want.
Ok, I've given the "EASE-script + keyboard shortcut" technique a try and that works much better:
I created a "my_build_target.js" javascript file at the base of my workspace/project:
/**
* keyboard: Alt+Shift+2
*/
targetmanager = org.eclipse.cdt.make.core.MakeCorePlugin.getDefault().getTargetManager()
projects = targetmanager.getTargetBuilderProjects()
folder = projects[0].getFolder("Test/Scenarios/Win32")
// targets = targetmanager.getTargets(folder)
target = targetmanager.findTarget(folder, "MyBuildTargetName")
target.build(new org.eclipse.core.runtime.NullProgressMonitor())
Note the use of the "magic keyword" within the header comment which specifies the desired shortcut-key you want for the script.
You then need to specify the locations for your scripts to be loaded from by going to:
"Windows >> Preferences >> Scripting >> Script Locations"
Personally, I clicked the "Add Workspace" button and specified the base of my workspace/project (that's where I housed my script).
I restarted Eclipse and then used my specified "Alt+Shift+2" shortcut key.
Awesome, it works :)
One gotchya is that I can't cancel a build that's in progress with this method. I suspect it's due to me using that NullProgressMonitor class when I call .build(). If I learn of a way to add a proper progress monitor here (that lets you cancel a progressing build), then I will update this answer...
NOTE: This is my initial "Practically Macro + Beanshell script" technique, which I've given up on. I prefer the other technique mentioned in my 2nd answer.
I've been looking for a way to do this for specific make targets too. The only in-built shortcut available is to "Rebuilt Last Target", which isn't all that helpful if you're frequently swapping between targets.
While I don't have a concrete solution yet, I'm working towards one.
I'm assessing the "Practically Macro" plug-in. It has the ability to assign a shortcut key to a macro. It also has the ability to define a macro as a beanshell script.
So all that's left is to figure out what kind of beanshell script would be capable of running a specific make target.
I've tried to explore the Eclipse API via the EASE scripting tool.
I'll share my steps/notes on how I successfully ran a make-target programmatically (via their javascript interface):
targetmanager = org.eclipse.cdt.make.core.MakeCorePlugin.getDefault().getTargetManager()
projects = targetmanager.getTargetBuilderProjects()
folder = projects[0].getFolder("Path/To/My/Build/Targets/")
// targets = targetmanager.getTargets(folder)
target = targetmanager.findTarget(folder, "MyBuildTargetName")
target.build(new org.eclipse.core.runtime.NullProgressMonitor())
So I think all that's left is for me (or someone else that's interested) to:
convert this script from javascript to beanshell and add it as a macro via the "Practically Macro" plugin
Assign a shortcut key to it
...quite an involved way to go about it, so if anyone has any simpler alternatives, I'm open to hear them.
UPDATE:
FWIW, I managed to create a beanshell script for "Practically Macro" in this form:
//Scripts are beanshell format (see http://www.beanshell.org/)
//variable type
//styledText the org.eclipse.swt.custom.StyledText instance for the current editor
//console write output to the macro console via console.write(String), .writeln(String), .write(Exception)
//findTarget the instance of org.eclipse.jface.text.IFindReplaceTarget
import org.eclipse.swt.custom.StyledText;
import org.eclipse.jface.text.IFindReplaceTarget;
c = org.eclipse.core.runtime.Platform.getBundle("org.eclipse.cdt.make.core").loadClass("org.eclipse.cdt.make.core.MakeCorePlugin");
m = c.getMethod("getDefault", null);
dflt = m.invoke(null, null);
targetmanager = dflt.getTargetManager();
projects = targetmanager.getTargetBuilderProjects();
folder = projects[0].getFolder("Path/To/My/Build/Targets/");
target = targetmanager.findTarget(folder, "MyBuildTargetName");
target.build(new org.eclipse.core.runtime.NullProgressMonitor());
And yes, it does kind-of work, but the only gotchya is that the eclipse ide stalls without any refreshing. Only after the build completes does the console pane get updated with the final build output (in one hit) and Eclipse becomes responsive again.
So it's not perfect, but I suppose it's incremental progress in the direction I'm after... As for what causes this freeze/stall during the build, I can't say for sure, but I suspect that the Practically Macro plugin locks Eclipse up until the macro completes.
Next Time:
Perhaps if I had another window of time to look into this again, I'd try to see if I can trigger an EASE-javascript script via a keyboard shortcut. This page seems to hint that it is possible:
https://wiki.eclipse.org/EASE/Scripts

How can I build a Java App with GUI and CLI?

I have to develop a small app to compare automatically generated folders. It must compare the folders, sub-folders and file contents. The problem is that this app needs to be launched either from a user on his computer to manually check for changes, or automatically along with the ANT nightlies. In the first case the results are displayed as a table in the Swing GUI. But in the other case, it must create a file to put the results in (format doesn't matter, XML, CSV, ...).
Anyone got some tips, or a link to a tutorial ?
You might want to add some command line option that switches between ui and file export, e.g. --gui or --export=[filename]. You could use Apache Commons CLI for that.
The other method is to create a set of classes that performs the task, and returns a set of values, which can then be either written to disk, or displayed in a GUI. I.e., an engine, and two front-ends (the GUI and the CLI).
for example:
public interface DirectoryComparer {
CompareResult performCompare(Directory dir1, Directory dir2);
public static interface CompareResult {
//...things here that you need, such as, file or dir difference, etc
Iterable<File> getFileDiff();
Iterable<Directory> getDirectoryDiff();
}
}
then, the GUI clients will just use DirectoryComparer to display the results, and the CLI client will write these results to a file or three. But those two clients are completely separate, and can be maintained separately.

Limiting/controlling the users ability to print in Java

I am looking to right an application that limits the number of times a user can print something, its there anything in Java that will allow me to control the printing dialogue to this aim?
Im going to look into these:
http://www.wildcrest.com/Software/J2PrinterWorks/documentation/J2Printer14.html
http://www.softframeworks.com/products/products.php
This is probably something you'll need to implement yourself as it is too-specific a requirement to have been included in the JDK's API.
Assuming you've developed a standalone Swing application you could consider using the Preferences class to store the number of times a user has printed a document for a given date. On Windows this translates to storing information in the registry and is therefore "hidden" from the user to a certain extent, but would allow you to reset the value in an emergency using regedit.
The advantage of this approach is that the user cannot circumvent the print-threshold by simply restarting the application.
I decided to go with J2Printer. I allows the suppression of the print dialogue.

Categories

Resources