Last active
December 30, 2015 22:19
-
-
Save DinisCruz/7893246 to your computer and use it in GitHub Desktop.
Multiple ways I tried to figure out the best way to execute a script in the Fortify Class loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fortifyAPI = tm.eclipse.ui.Startup.loadedPlugins.first() | |
| def issuesList = fortifyAPI.getIssuesListView() | |
| def tree = issuesList.tree.getTree(); | |
| //return String.format("%s \n %s " , this.class.getClassLoader() , issuesList.class.getClassLoader()); | |
| def _eclipse = eclipse | |
| def groovyExecution = new GroovyExecution(); | |
| def folder = "/Users/plugin/_Dev/eclipses/QA - Fortify - Kepler/plugins/com.fortify.plugin.remediation_3.90.0/Core/lib/"; | |
| //groovyExecution.addRefToGroovyShell(folder + "com.fortify.rcp.common_3.90-3.90.jar"); | |
| //groovyExecution.addRefToGroovyShell(folder + "model-3.90.jar" ) | |
| //groovyExecution.addRefToGroovyShell(folder + "fortify-common-3.90.jar" ) | |
| def script = """ | |
| return com.fortify.awb.util.SWTIntegrationUtil.class | |
| """; | |
| Thread currentThread = Thread.currentThread(); | |
| ClassLoader clCurrent = currentThread.getContextClassLoader(); | |
| eclipse.log("Current thread class loader is: " +clCurrent); | |
| currentThread.setContextClassLoader(issuesList.class.getClassLoader()); | |
| eclipse.log("Getting WordprozessingPackage"); | |
| //return currentThread.getContextClassLoader(); | |
| //return Class.forName("com.fortify.awb.util.SWTIntegrationUtil") | |
| //return currentThread; | |
| def ge = new GroovyExecution(); | |
| ge.addRefToGroovyShell("/Users/plugin/Downloads/bsh-2.0b4.jar"); | |
| def contentProvider = ge.executeScript("return new bsh.Interpreter().eval(' return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider() ')"); | |
| return ge; | |
| inspect(contentProvider.selectedIssue.mainIssue); | |
| return contentProvider.selectedIssue.theMainIssue.dump(); | |
| //ge.executeScript("return new bsh.Interpreter().eval('Thread.currentThread().getContextClassLoader()')"); | |
| return ge; | |
| //Config:UIThread_False | |
| def binding = groovyExecution.binding; | |
| def configuration = groovyExecution.configuration; | |
| def fortifyClassLoader= issuesList.class.getClassLoader(); | |
| def newGroovyShell = new GroovyShell(fortifyClassLoader, binding,configuration); | |
| groovyExecution.groovyShell = newGroovyShell; | |
| inspect(fortifyClassLoader.delegate.loaderProxy.bundleLoader.parentClassLoader) | |
| //fortifyClassLoader = fortifyClassLoader.systemClassLoader; | |
| return fortifyClassLoader; | |
| //return script; | |
| def addJarForClass = { clazz -> | |
| def jarToAdd = clazz.protectionDomain.codeSource.location.path; | |
| groovyExecution.addRefToGroovyShell(jarToAdd) | |
| } | |
| import org.eclipse.swtbot.swt.finder.results.Result | |
| addJarForClass(groovyExecution.class); | |
| addJarForClass(Binding.class); | |
| addJarForClass(GroovyObject.class); | |
| addJarForClass(Result.class); | |
| addJarForClass(org.codehaus.groovy.activator.GroovyActivator.class) | |
| addJarForClass(org.codehaus.groovy.eclipse.GroovyPlugin.class) | |
| addJarForClass(org.eclipse.jdt.groovy.core.Activator.class) | |
| addJarForClass(org.apache.commons.io.FileUtils.class) | |
| //return groovyExecution.class.protectionDomain.codeSource.location.path; | |
| def file = new File("/Users/plugin/_Dev/git/TeamMentor_Eclipse_Plugin/TeamMentor.Eclipse.PlugIn.Fortify/TM_Plugins/Tests/MeaningOfLife.groovy"); | |
| def codeFile = new groovy.lang.GroovyCodeSource(file); | |
| //return new GroovyExecution().groovyShell.evaluate(codefile); | |
| groovyExecution.addRefsFor_SWTBot() | |
| //return groovyExecution.get_GroovyShell_ClassLoader_Urls(); | |
| //inspect(groovyExecution.groovyShell) | |
| groovyExecution.groovyShell.classLoader = issuesList.class.getClassLoader() | |
| //inspect(fortifyClassLoader) | |
| //return groovyExecution.get_GroovyShell_ClassLoader_Urls(); | |
| //return groovyExecution.groovyShell.classLoader | |
| //groovyExecution.executeScript(script); | |
| //return groovyExecution.groovyShell.parse(codeFile); | |
| //groovyExecution.groovyShell.evaluate(script); | |
| return groovyExecution.groovyShell.evaluate("2+2"); | |
| return groovyExecution; | |
| //getSelectedIssue; | |
| import org.eclipse.swt.widgets.* | |
| import org.eclipse.swt.* | |
| def listener = new Listener() { | |
| public void handleEvent(Event event) | |
| { | |
| def a= com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider(); | |
| // _eclipse.log(event.toString() + " : " + event.type.toString()); | |
| // log.info(event.type); | |
| } | |
| }; | |
| //inspect tree.getListeners(SWT.MouseHover)[1].class | |
| //inspect(tree) | |
| tree.getListeners(SWT.Selection).each | |
| { | |
| tree.removeListener(SWT.Selection, it) | |
| _eclipse.log("removed " + it.toString()) | |
| } | |
| tree.addListener(SWT.Selection,listener); | |
| return tree.getListeners(SWT.Selection).size() | |
| return org.eclipse.swt.widgets.Listener.class | |
| return issuesList.tree;//.getData(); | |
| //inspect(fortifyAPI) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //run these first (once per Eclipse instance, not that this will not be needed on the next version of the Plugin (which will have the bsh included in the class path) | |
| //def beanShellPath = "/Users/plugin/Downloads/bsh-2.0b4.jar"; | |
| //eclipse.extraGroovyJars.add(beanShellPath); | |
| //return eclipse.extraGroovyJars; | |
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //inspect( result); | |
| //return result.selectedIssueChangeListeners; // view the mapped 'issue change' listeners | |
| return result.selectedIssue; // view the current selected issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //run these first (once per Eclipse instance, not that this will not be needed on the next version of the Plugin (which will have the bsh included in the class path) | |
| //def beanShellPath = "/Users/plugin/Downloads/bsh-2.0b4.jar"; | |
| //eclipse.extraGroovyJars.add(beanShellPath); | |
| //return eclipse.extraGroovyJars; | |
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| // | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| //def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def swtIntegrationUtil_Class = new bsh.Interpreter().eval(beanShellScript); | |
| def swtIntegration = swtIntegrationUtil_Class.newInstance(); | |
| currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //this also works | |
| //return swtIntegration; | |
| // return swtIntegration.getActiveShell().text="Live changing the shell title"; | |
| //return swtIntegration.getDefaultProject(); | |
| return swtIntegration.getDefaultContentProvider() | |
| //return swtIntegration.getDefaultContentProvider().selectedIssue.mainIssue.name | |
| //swtIntegration.closeProject() | |
| //def projectFile = new File("/Users/plugin/Downloads/Scans/ejb.fpr"); | |
| //swtIntegration.loadProject(projectFile,null) | |
| return swtIntegration.issueListeners.size(); | |
| //Config:UIThread_False | |
| //inspect(swtIntegration.getDefaultProject()) | |
| return "done" | |
| //inspect( result); | |
| //return result.selectedIssueChangeListeners; // view the mapped 'issue change' listeners | |
| return result.selectedIssue; // view the current selected issue | |
| inspect( result.selectedIssue) | |
| inspect( result.selectedIssue.children.first()) | |
| return result.selectedIssue; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| // | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| //def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def swtIntegrationUtil_Class = new bsh.Interpreter().eval(beanShellScript); | |
| def swtIntegration = swtIntegrationUtil_Class.newInstance(); | |
| //Config:UIThread_False | |
| //currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //this also works | |
| //return swtIntegration; | |
| // return swtIntegration.getActiveShell().text="Live changing the shell title"; | |
| //return swtIntegration.getDefaultProject(); | |
| //return swtIntegration.contentProvider | |
| //import com.fortify.ui.model.contentProvider.listeners; | |
| def script =""" | |
| import com.fortify.ui.model.contentProvider.listeners.*; | |
| import com.fortify.ui.model.issue.*; | |
| import com.fortify.ui.model.xml.interfaces.*; | |
| return new IssueChangeListener() | |
| { | |
| public abstract void notify(DisplayableIssue paramDisplayableIssue, | |
| IssueAttribute paramIssueAttribute, | |
| AttributeValue paramAttributeValue1, | |
| AttributeValue paramAttributeValue2, | |
| IssueChangeType paramIssueChangeType) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log(" **** IssueChangeListener notify event"); | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - paramDisplayableIssue: " + paramDisplayableIssue.toString()); | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - paramIssueAttribute : " + paramIssueAttribute.toString()); | |
| if (paramAttributeValue1 != null) | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - paramAttributeValue1 : " + paramAttributeValue1.toString()); | |
| if (paramAttributeValue2 != null) | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - paramAttributeValue2 : " + paramAttributeValue2.toString()); | |
| if (paramIssueChangeType != null) | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - paramIssueChangeType : " + paramIssueChangeType.toString()); | |
| } | |
| } | |
| """; | |
| def changeListener = new bsh.Interpreter().eval(script); | |
| //inspect(changeListener) | |
| //changeListener.notify(null,null,null); | |
| //return changeListener; | |
| swtIntegration.issueListeners.collect | |
| { | |
| // swtIntegration.removeSelectedIssueChangeListener(it) | |
| swtIntegration.issueListeners.remove(it) | |
| } | |
| //swtIntegration.registerIssueListener(changeListener) | |
| return swtIntegration.issueListeners |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| // | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| //def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def swtIntegrationUtil_Class = new bsh.Interpreter().eval(beanShellScript); | |
| def swtIntegration = swtIntegrationUtil_Class.newInstance(); | |
| //Config:UIThread_False | |
| //currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //inspect(swtIntegration.contentProvider.selectedIssue.getDescriptableIssue() ) | |
| //return swtIntegration.contentProvider.selectedIssue.getDescriptableIssue() | |
| //return swtIntegration.contentProvider.selectedIssue.mainIssue | |
| //this also works | |
| //return swtIntegration; | |
| // return swtIntegration.getActiveShell().text="Live changing the shell title"; | |
| //inspect(swtIntegration.contentProvider.selectedIssue) | |
| //return swtIntegration.contentProvider.selectedIssue.getDescriptableIssue() | |
| // | |
| def script =""" | |
| import com.fortify.ui.model.util.render.SCAPrettyPrinter; | |
| contentProvider = com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider(); | |
| issue = contentProvider.getSelectedIssue(); | |
| //return issue.getDescriptableIssue(); | |
| return SCAPrettyPrinter.getRecommendation(issue.getDescriptableIssue(),false); | |
| return "here"; | |
| """; | |
| return new bsh.Interpreter().eval(script); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| // | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| //def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def swtIntegrationUtil_Class = new bsh.Interpreter().eval(beanShellScript); | |
| def swtIntegration = swtIntegrationUtil_Class.newInstance(); | |
| //Config:UIThread_False | |
| //currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //this also works | |
| //return swtIntegration; | |
| // return swtIntegration.getActiveShell().text="Live changing the shell title"; | |
| //return swtIntegration.getDefaultProject(); | |
| //return swtIntegration.contentProvider | |
| //import com.fortify.ui.model.contentProvider.listeners; | |
| def script =""" | |
| import com.fortify.ui.model.contentProvider.listeners.*; | |
| import com.fortify.ui.model.issue.*; | |
| import com.fortify.ui.model.contentProvider.*; | |
| return new ContentProviderStateListener() | |
| { | |
| public abstract void notifyEvent(ContentProvider contentProvider, | |
| ContentProviderEventType eventType) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log(" ******* ContentProviderStateListener notify event: " + eventType); | |
| if (eventType == ContentProviderEventType.SELECTED_ISSUES_CHANGED) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - contentProvider : " + contentProvider.toString()); | |
| issue = contentProvider.getSelectedIssue(); | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - issue : " + issue.toString()); | |
| } | |
| } | |
| } | |
| """; | |
| def stateListener = new bsh.Interpreter().eval(script); | |
| //inspect(changeListener) | |
| //return stateListener; | |
| swtIntegration.cpStateListeners.toList().collect | |
| { | |
| if (it.toString().contains("bsh")) | |
| swtIntegration.removeContentProviderStateListener(it) | |
| // swtIntegration.issueListeners.remove(it) | |
| } | |
| swtIntegration.registerContentProviderStateListener(stateListener) | |
| return swtIntegration.cpStateListeners |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| // | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| //def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def swtIntegrationUtil_Class = new bsh.Interpreter().eval(beanShellScript); | |
| def swtIntegration = swtIntegrationUtil_Class.newInstance(); | |
| //Config:UIThread_False | |
| //currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //this also works | |
| //return swtIntegration; | |
| // return swtIntegration.getActiveShell().text="Live changing the shell title"; | |
| //return swtIntegration.getDefaultProject(); | |
| //return swtIntegration.contentProvider | |
| //import com.fortify.ui.model.contentProvider.listeners; | |
| def script =""" | |
| import com.fortify.ui.model.contentProvider.listeners.*; | |
| import com.fortify.ui.model.issue.*; | |
| import com.fortify.ui.model.contentProvider.*; | |
| import com.fortify.ui.model.util.render.SCAPrettyPrinter; | |
| return new ContentProviderStateListener() | |
| { | |
| public abstract void notifyEvent(ContentProvider contentProvider, | |
| ContentProviderEventType eventType) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log(" ******* ContentProviderStateListener notify event: " + eventType); | |
| if (eventType == ContentProviderEventType.SELECTED_ISSUES_CHANGED) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - contentProvider : " + contentProvider.toString()); | |
| issue = contentProvider.getSelectedIssue(); | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - issue : " + issue.toString()); | |
| descriptableIssue = issue.getDescriptableIssue(); | |
| recommendation = SCAPrettyPrinter.getRecommendation(descriptableIssue, false); | |
| if (recommendation != null && recommendation != "") | |
| { | |
| recommendation = "</br>Since there is no TeamMentor article for the current Fortify mapping, here is the default Fortify Recommendation content:<br><br>" + | |
| "<pre>" + recommendation + " </pre>"; | |
| tm.eclipse.api.TeamMentorAPI.show_Html_With_TeamMentor_Banner(recommendation); | |
| } | |
| else | |
| tm.eclipse.api.TeamMentorAPI.show_Html_With_TeamMentor_Banner("No finding selected"); | |
| } | |
| } | |
| } | |
| """; | |
| def stateListener = new bsh.Interpreter().eval(script); | |
| //inspect(changeListener) | |
| //return stateListener; | |
| swtIntegration.cpStateListeners.toList().collect | |
| { | |
| if (it.toString().contains("bsh")) | |
| swtIntegration.removeContentProviderStateListener(it) | |
| // swtIntegration.issueListeners.remove(it) | |
| } | |
| swtIntegration.registerContentProviderStateListener(stateListener) | |
| return swtIntegration.cpStateListeners |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def issuesList = eclipse.activeWorkbenchPage.findView("com.fortify.awb.views.views.IssuesListView"); // gets a reference to the Fortify view | |
| def fortifyClassLoader = issuesList.class.getClassLoader(); // gets the class loader of the Fortify plugin | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| //def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.getDefaultContentProvider()"; // beanShell script to execute that will give us an live fortify's ContentProvider object | |
| // | |
| def currentThread = Thread.currentThread(); // get the curren thead | |
| def originalClassLoader = currentThread.getContextClassLoader(); // save its class loader | |
| currentThread.setContextClassLoader(fortifyClassLoader); // change to Fortify's class loader | |
| //def result = new bsh.Interpreter().eval(beanShellScript); // execute bean shell script | |
| def beanShellScript = "return com.fortify.awb.util.SWTIntegrationUtil.class"; | |
| def swtIntegrationUtil_Class = new bsh.Interpreter().eval(beanShellScript); | |
| def swtIntegration = swtIntegrationUtil_Class.newInstance(); | |
| //Config:UIThread_False | |
| //currentThread.setContextClassLoader(originalClassLoader) // restore the original thread class loader | |
| //this also works | |
| //return swtIntegration; | |
| // return swtIntegration.getActiveShell().text="Live changing the shell title"; | |
| //return swtIntegration.getDefaultProject(); | |
| //return swtIntegration.contentProvider | |
| //import com.fortify.ui.model.contentProvider.listeners; | |
| def script =""" | |
| import com.fortify.awb.util.SWTIntegrationUtil; | |
| import com.fortify.ui.model.contentProvider.listeners.*; | |
| import com.fortify.ui.model.issue.*; | |
| import com.fortify.ui.model.contentProvider.*; | |
| import com.fortify.ui.model.util.render.SCAPrettyPrinter; | |
| return new ContentProviderStateListener() | |
| { | |
| public abstract void notifyEvent(ContentProvider contentProvider, | |
| ContentProviderEventType eventType) | |
| { | |
| currentThread = Thread.currentThread(); | |
| originalClassLoader = currentThread.getContextClassLoader(); | |
| fortifyClassLoader = contentProvider.getClass().getClassLoader(); | |
| currentThread.setContextClassLoader(fortifyClassLoader); | |
| tm.eclipse.ui.Startup.eclipseApi.log(" ****--- ContentProviderStateListener notify event: " + eventType); | |
| if (eventType == ContentProviderEventType.SELECTED_ISSUES_CHANGED) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - contentProvider : " + contentProvider.toString()); | |
| issue = contentProvider.getSelectedIssue(); | |
| tm.eclipse.ui.Startup.eclipseApi.log(" - issue : " + issue.toString()); | |
| descriptableIssue = issue.getDescriptableIssue(); | |
| if(descriptableIssue == null) | |
| { | |
| tm.eclipse.ui.Startup.eclipseApi.log("Error: descriptableIssue was null"); | |
| } | |
| recommendation = SCAPrettyPrinter.getRecommendation(descriptableIssue, false); | |
| if (recommendation != null && recommendation != "") | |
| { | |
| recommendation = "</br>Since there is no TeamMentor article for the current Fortify mapping, here is the default Fortify Recommendation content:<br><br>" + | |
| "<pre>" + recommendation + " </pre>"; | |
| tm.eclipse.api.TeamMentorAPI.show_Html_With_TeamMentor_Banner(recommendation); | |
| } | |
| else | |
| tm.eclipse.api.TeamMentorAPI.show_Html_With_TeamMentor_Banner("No finding selected"); | |
| } | |
| currentThread.setContextClassLoader(originalClassLoader); | |
| } | |
| } | |
| """; | |
| def stateListener = new bsh.Interpreter().eval(script); | |
| //inspect(changeListener) | |
| //return stateListener; | |
| swtIntegration.cpStateListeners.toList().collect | |
| { | |
| if (it.toString().contains("bsh")) | |
| swtIntegration.removeContentProviderStateListener(it) | |
| // swtIntegration.issueListeners.remove(it) | |
| } | |
| swtIntegration.registerContentProviderStateListener(stateListener) | |
| return swtIntegration.cpStateListeners |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment