//================= //File: RunAntTarget.jsee //Version: 1.3 //Author: Ysengrimus //Date: 7/11/2007 //Info: Macro to run ANT with selectable target(s) //===== /* USAGE: * Edit java_command, ant_classpath, ant_home (and maybe ant_launcher) * and change them appropriate to your requirements. * Running this script on an ant build file will popup a menu with * the available target(s), selecting one will launch ANT with the * configured settings and selected target or the target(s) you've * entered when prompted (choosed menu item: Prompt). A DOS box * will popup (working dir is ${Dir}) and shows ant output. */ /* Changes in version 1.3: - default target and target definitions now may contain blanks and will be quoted in the command string Changes in version 1.2: - introduced PauseAndExit var. if true pause after ANT finished and exit on any key else dos box stays open (old behaviour) Changes in version 1.1: - removed needless sortArray function (JS-Arrays have a sort method) - disabled redrawing during search (avoids flashing) */ // pause after ANT finished and exit on any key var PauseAndExit = true; // path to java.exe // e.g.: var java_command = 'c:\\jdk142\\bin\\java.exe'; var java_command = '[PATH_TO_JAVA_EXE]'; // or just: var java_command = 'java'; // if java is in path // path to ant home // e.g.: var ant_home = 'f:\\ant162'; // var ant_home = '[ANT_HOME_PATH]'; // path to ant launcher jar file // e.g.: var ant_classpath = ant_home + '\\lib\\ant-launcher.jar'; var ant_classpath = '[PATH_TO_ANT_LAUNCHER_JAR]'; // ant launcher classname // e.g.: var ant_launcher = 'org.apache.tools.ant.launch.Launcher'; var ant_launcher = 'org.apache.tools.ant.launch.Launcher'; // Keep as is: // ${Drive} and ${Dir} will be replaced. changes drive and changes to dir var chdir_command = 'cmd /k ${Drive} & cd ${Dir} &'; // ${Filename} and ${Target} will be replaced var ant_command = '-cp ' + ant_classpath + ' -Dant.home=' + ant_home + ' ' + ant_launcher + ' -f ${Filename} ${Target}'; // build full command var full_command = chdir_command + ' ' + java_command + ' ' + ant_command; if ( PauseAndExit ) { full_command += " & pause & exit"; } // check that script has been edited and configured if ( ((java_command.charAt(0) == '[') || (java_command.charAt(java_command.length - 1) == ']') ) || ((ant_home.charAt(0) == '[') || (ant_home.charAt(ant_home.length - 1) == ']') ) || ((ant_classpath.charAt(0) == '[') || (ant_classpath.charAt(ant_classpath.length - 1) == ']') ) ) { alert( ScriptName + ' needs to be edited and properly configured to run'); editor.openFile( ScriptFullName ); } else { // run the script var x = document.selection.GetActivePointX( eePosLogical ); // get cursor column var y = document.selection.GetActivePointY( eePosLogical ); // get cursor line var xml_extension = /^.*(\.xml)$/i; if ( xml_extension.test( document.Name ) ) { // it's a XML file (: Redraw = false; // don't flashes screen document.selection.StartOfDocument(); var project_name = ''; if ( document.selection.Find('[ \t]?', eeFindNext | eeFindReplaceRegExp) ) { // it seems to be a valid ant build file if ( document.selection.text != false ) { document.selection.StartOfLine(); var default_target = ''; if ( document.selection.Find('[ \t]? 0 ) { // we have at least one target definition //targets = sortArray(targets); targets = targets.sort(); menu = CreatePopupMenu(); menu.Add( 'Cancel', 0 ); menu.Add( '', 1, eeMenuSeparator ); menu.Add( 'Default (' + default_target + ')', 2 ); menu.Add( '', 3, eeMenuSeparator ); index = 4; if ( targets.length > 1 ) { // else we have only the default target for(i in targets) { if ( targets[i] != default_target ) { menu.Add( targets[i], index++ ); } if ( targets[i].indexOf(' ') >= 0 ) { targets[i] = '"' + targets[i] + '"'; } } menu.Add( '', index++, eeMenuSeparator ); } // else { } menu.Add( 'Prompt', index++ ); Redraw = true; // repaint screen document.HighlightFind=false; document.selection.SetActivePoint( eePosLogical, x, y ); // restore cursor position result = menu.Track(eePosMouse); var from_prompt = false; if ( result > 1 ) { build_target = menu.GetText(result); build_targets = targets.join(' '); if ( build_target == 'Prompt' ) { if ( project_name != '' ) { build_target = prompt( 'Enter build target(s) for project "' + project_name + '" (' + document.FullName +'):', build_targets ); } else { build_target = prompt( 'Enter build target(s) (' + document.FullName + '):', build_targets ); } if ( build_target != '' && build_target.indexOf(' ') > 0) { from_prompt = true; } } else if ( build_target == 'Default (' + default_target + ')' ) { build_target = default_target; } else {} //alert( 'build_target: ' + build_target ); if ( build_target != '' ) { var Filename = document.Name; var Dir = document.Path; var Drive = Dir.substring(0,2); var Target = build_target; var Command = full_command; Command = Command.replace( /\$\{Drive\}/, Drive); Command = Command.replace( /\$\{Dir\}/, Dir); Command = Command.replace( /\$\{Filename\}/, Filename); if ( Target != undefined && Target != '' ) { if ( !from_prompt && Target.indexOf(' ') > 0 && !Target.indexOf('"') == 0 ) { Command = Command.replace( /\$\{Target\}/, '"' + Target + '"'); } else { Command = Command.replace( /\$\{Target\}/, Target); } } else { Command = Command.replace( /\$\{Target\}/, ''); } //alert( 'Command: ' + Command ); runCommand( Command ); } // else no build target -> cancel } // else canceled } else { // no targets defined alert( "Not a valid ANT .xml buildfile:\ndefault target is '"+ default_target +"'\nbut it is not defined as a target" ); } } else { // not a proper ant build file alert( "Seems not to be a proper ANT .xml buildfile:\ndefault target not defined in project tag" ); } } } else { // not an ant build file alert( "Seems not to be an ANT .xml buildfile:\nproject tag not found" ); } } else { // not a xml file alert( "Works on .xml files only!\nShould be an ANT .xml buildfile" ); } } function contains ( list, candidate ) { result = false; for ( i = 0; i < list.length ; i++ ) { if ( list[i] == candidate ) { result = true; break; } } return result; } function runCommand( Command ) { if ( Command != undefined && Command != "" ) { var Shell = new ActiveXObject("WScript.Shell"); // alert( '"' + Command + '"'); Shell.run( Command ); } else { alert('Invalid command: ' + Command); } }