Skip to content

Instantly share code, notes, and snippets.

@warmuuh
Last active December 18, 2015 12:29
Show Gist options
  • Save warmuuh/5782748 to your computer and use it in GitHub Desktop.
Save warmuuh/5782748 to your computer and use it in GitHub Desktop.
groovyMonkey scripts for stripes, urlrewrite, svn pre-hook
script overview:
*svn__commit.gm => pre-hook script for svn.
blablabla
/*
* Menu: Stripes > Find HandlesEvent/Before
* Script-Path: /GroovyMonkeyScripts/monkey/FindHandleEvent_bsh.gm
* Kudos: Bjorn Freeman-Benson & Ward Cunningham & James E. Ervin
* License: EPL 1.0
* LANG: Beanshell
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
regex = "\\\".*?\\\"";
pattern = Pattern.compile(regex);
files = resources.filesMatching( ".*\\.java" );
for( i = 0; i < files.length; i++ )
{
files[i].removeMyTasks( metadata.scriptPath() );
lines = files[i].lines;
for( j = 0; j < lines.size(); j++ )
{
if( lines.get( j ).string.contains( "@HandlesEvent" ) ){
matcher = pattern.matcher(lines.get( j ).string.trim());
while(matcher.find())
lines.get( j ).addMyTask( metadata.scriptPath(), matcher.group().toString().replace("\"", "") );
//lines.get( j ).addMyTask( metadata.scriptPath(), lines.get( j ).string.trim() );
}
if( lines.get( j ).string.contains( "@Before(" ) ){
matcher = pattern.matcher(lines.get( j ).string.trim());
while(matcher.find())
lines.get( j ).addMyTask( metadata.scriptPath(), matcher.group().toString().replace("\"", "") + ":before" );
//lines.get( j ).addMyTask( metadata.scriptPath(), lines.get( j ).string.trim() );
}
if( lines.get( j ).string.contains( "@ValidationMethod" ) ){
matcher = pattern.matcher(lines.get( j ).string.trim());
while(matcher.find())
lines.get( j ).addMyTask( metadata.scriptPath(), matcher.group().toString().replace("\"", "") + ":validation" );
//lines.get( j ).addMyTask( metadata.scriptPath(), lines.get( j ).string.trim() );
}
}
}
final Runnable runnable = new Runnable()
{
public void run()
{
window.getActivePage().showView( "org.eclipse.ui.views.TaskList" );
}
};
runnerDOM.asyncExec( runnable );
/*
* Menu: resolve url > by link
* Script-Path: /GroovyMonkeyScripts/monkey/NiceUrlResolve.gm
* Kudos: Bjorn Freeman-Benson & Ward Cunningham & James E. Ervin
* License: EPL 1.0
* LANG: Beanshell
* DOM: http://groovy-monkey.sourceforge.net/update/plugins/net.sf.groovyMonkey.dom
*/
url = JOptionPane.showInputDialog(null,"nice url to resolve?", "urlrewrite", JOptionPane.INFORMATION_MESSAGE).trim();
files = resources.filesMatching( ".*src/main/webapp/WEB-INF/urlrewrite.xml" );
out.clear();
for( i = 0; i < files.length; i++ )
{
files[i].removeMyTasks( metadata.scriptPath() );
lines = files[i].lines;
for( j = 0; j < lines.size()-1; j++ )
if( lines.get( j ).string.contains( "<from>" ) && lines.get( j ).string.contains( url ) ){
out.println( lines.get( j ).string.replace("<from>", "").replace("</from>","").trim() );
out.println( "-> " + lines.get( j + 1).string.replace("<to type=\"forward\" last=\"true\">", "").replace("</to>","").trim() );
out.println( " " );
}
}
/*
* Menu: resolve url > by id
* Script-Path: /GroovyMonkeyScripts/monkey/NiceUrlResolve_ID.gm
* Kudos: Bjorn Freeman-Benson & Ward Cunningham & James E. Ervin
* License: EPL 1.0
* LANG: Beanshell
* DOM: http://groovy-monkey.sourceforge.net/update/plugins/net.sf.groovyMonkey.dom
*/
urlId = JOptionPane.showInputDialog(null,"nice url-id to resolve?", "urlrewrite", JOptionPane.INFORMATION_MESSAGE).trim();
url = "";
files = resources.filesMatching( ".*src/resources/LinkResources_de.properties" );
for( i = 0; i < files.length; i++ )
{
lines = files[i].lines;
for( j = 0; j < lines.size(); j++ )
if( lines.get( j ).string.contains( urlId ) ){
url = lines.get( j ).string.split("=")[1];
out.println(urlId + " = " + url);
}
}
//end-terminator for urlrewrite
url = url + "|";
files = resources.filesMatching( ".*src/main/webapp/WEB-INF/urlrewrite.xml" );
out.clear();
for( i = 0; i < files.length; i++ )
{
files[i].removeMyTasks( metadata.scriptPath() );
lines = files[i].lines;
for( j = 0; j < lines.size()-1; j++ )
if( lines.get( j ).string.contains( "<from>" ) && lines.get( j ).string.contains( url ) ){
out.println( lines.get( j ).string.replace("<from>", "").replace("</from>","").trim() );
out.println( "-> " + lines.get( j + 1).string.replace("<to type=\"forward\" last=\"true\">", "").replace("</to>","").trim() );
out.println( " " );
}
}
/*
* Menu: SVN > test and commit
* Script-Path: /GroovyMonkeyScripts/monkey/SVN__Commit.gm
* Kudos: pmucha
* License: EPL 1.0
* LANG: Beanshell
* Job: UIJob
* DOM: http://groovy-monkey.sourceforge.net/update/net.sf.groovyMonkey.dom
* DOM: http://groovy-monkey.sourceforge.net/update/plugins/net.sf.groovyMonkey.dom
* Include-Bundle: org.eclipse.debug.core
*/
import org.eclipse.debug.core.*;
hs = window.getService(org.eclipse.ui.handlers.IHandlerService.class);
commandId = "org.eclipse.team.svn.ui.command.CommitCommand";
configurations = launchManager.manager().getLaunchConfigurations();
listener = new org.eclipse.debug.core.ILaunchesListener2(){
public void launchesTerminated(ILaunch[] launches){
launchManager.manager().removeLaunchListener(listener);
runnerDOM.asyncExec(new Runnable(){
public void run()
{
hs.executeCommand(commandId, null);
}
});
}
public void launchesAdded(ILaunch[] launches){}
public void launchesChanged(ILaunch[] launches){}
public void launchesRemoved(ILaunch[] launches){}
};
launchManager.manager().addLaunchListener(listener);
for(c:configurations)
if (c.getName().equals("All Tests")){
c.launch("run", null);
}
/*
* Menu: test
* Script-Path: /GroovyMonkeyScripts/monkey/Test.gm
* Kudos: pmucha
* License: EPL 1.0
* DOM: http://groovy-monkey.sourceforge.net/update/plugins/net.sf.groovyMonkey.dom
*/
out.println "test"
//hs.executeCommand("org.eclipse.team.svn.ui.command.CommitCommand", null);
#cs = window.getService( ICommandService.class )
#cmd_manager = org.eclipse.core.commands.CommandManager
#cmd = window.getWorkbench().commandManager.getCommand(commandId)
#pc = cs.deserialize("org.eclipse.team.svn.ui.command.CommitCommand()")
#hs.executeCommandInContext(pc, null, hs.createContextSnapshot(true));
#hs.executeCommand(commandId, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment