//================= //File: RunAntTarget.jsee //Version: 1.0 //Author: Ysengrimus //Date: 11/7/2006 //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. */ // 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; // 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 (: 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); 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++ ); } } menu.Add( '', index++, eeMenuSeparator ); } // else { } menu.Add( 'Prompt', index++ ); result = menu.Track(eePosMouse); document.HighlightFind=false; document.selection.SetActivePoint( eePosLogical, x, y ); // restore cursor position 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 ); } } else if ( build_target == 'Default (' + default_target + ')' ) { build_target = default_target; } else {} 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 != '' ) { Command = Command.replace( /\$\{Target\}/, Target); } else { Command = Command.replace( /\$\{Target\}/, ''); } 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" ); } document.HighlightFind=false; document.selection.SetActivePoint( eePosLogical, x, y ); // restore cursor position } 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); } } function sortArray( StrArray ) { var arrUnsorted; var arrSorted; var bolSorted; var strSorted; //strValue = StrArray.join("\n"); //arrUnsorted = strValue.split("\n"); arrUnsorted = StrArray; bolSorted = false; do { bolSorted = true; for ( var i = 0; i < arrUnsorted.length; i++) { if ( i < arrUnsorted.length ) { if ( arrUnsorted[i+1] < arrUnsorted[i] ) { strTemp = arrUnsorted[i+1]; arrUnsorted[i+1] = arrUnsorted[i]; arrUnsorted[i] = strTemp; bolSorted = false; } } } } while ( bolSorted != true ); strSorted = ""; for ( var i = 0; i < arrUnsorted.length; i++ ) { strSorted = strSorted + arrUnsorted[i]; if ( i < (arrUnsorted.length - 1) ) { strSorted = strSorted + "\n"; } } arrSorted = strSorted.split("\n"); return arrSorted; }