/** Quick sensorshell when Hackystat Eclipse Sensor is closed or stopped. */ public void quit() { try { this.shell.quit(); } catch (SensorShellException e) { EclipseSensorPlugin plugin = EclipseSensorPlugin.getDefault(); plugin.log(e); processStatusLine("Hackystat Sensor : Error occurred during prior autosend. "); } }
/** Sends all Hackystat data to the server. Do nothing if sensor shell instance is null. */ public void send() { try { this.shell.send(); } catch (SensorShellException e) { EclipseSensorPlugin plugin = EclipseSensorPlugin.getDefault(); plugin.log(e); processStatusLine("Hackystat Sensor : Error occurred when sending data to server. "); } }
/** * Add key-value pairs of metrics to sensorshell to be sent to the Hackystat server automatically. * * @param keyValuePairs Key-value pairs of metrics. * @param message A message to appear on the Eclipse's status bar. */ public void add(Map<String, String> keyValuePairs, String message) { processStatusLine("Hackystat Sensor : " + message); try { this.shell.add(keyValuePairs); } catch (Exception e) { EclipseSensorPlugin plugin = EclipseSensorPlugin.getDefault(); plugin.log(e); processStatusLine("Hackystat Sensor : Error occurred when sending data to server. "); } }
/** * Gets the fully qualified class name for an active file. For example, its value is foo.bar.Baz. * * @param file Get fully qualified class file. * @return The fully qualified class name. For example,foo.bar.Baz. */ private String getFullyQualifedClassName(IFile file) { String fullClassName = ""; if (file.exists() && file.getName().endsWith(EclipseSensorConstants.JAVA_EXT)) { ICompilationUnit compilationUnit = (ICompilationUnit) JavaCore.create(file); String className = compilationUnit.getElementName(); if (className.endsWith(EclipseSensorConstants.JAVA_EXT)) { className = className.substring(0, className.length() - 5); } try { IPackageDeclaration[] packageDeclarations = compilationUnit.getPackageDeclarations(); // Should only have one package declaration if (packageDeclarations == null || packageDeclarations.length == 0) { fullClassName = className; } else { fullClassName = packageDeclarations[0].getElementName() + '.' + className; } } catch (JavaModelException e) { // This exception will be thrown if user is working on a Java but did not open // it with "Java Perspective". Thus, the Java Model does not exist to parse // Java files. So we only log out exception while Eclipse's Java Perspective // exits. if (!e.isDoesNotExist()) { EclipseSensorPlugin.getDefault().log(file.getName(), e); } } } return fullClassName; }
/** * Provide the initialization of the listeners additions. The Window, Part, and Document Listener * are added. Note that sensor shell should be instantiated before this method is called because * <code>processActivity()</code> method uses sensor shell instance. */ private void registerListeners() { IWorkbench workbench = EclipseSensorPlugin.getInstance().getWorkbench(); // :RESOLVED: JULY 1, 2003 // Supports the multiple window for sensor collection. IWorkbenchWindow[] activeWindows = workbench.getWorkbenchWindows(); // Check if window listener is not added yet. Otherwise multi instances are notified. if (this.windowListener == null) { this.windowListener = new WindowListenerAdapter(); workbench.addWindowListener(new WindowListenerAdapter()); } for (int i = 0; i < activeWindows.length; i++) { IWorkbenchPage activePage = activeWindows[i].getActivePage(); activePage.addPartListener(new PartListenerAdapter()); IEditorPart activeEditorPart = activePage.getActiveEditor(); // Adds this EclipseSensorPlugin instance to IDocumentListener // only when activeEditorPart is the instance of ITextEditor // so that null case is also ignored. if (activeEditorPart instanceof ITextEditor) { // Sets activeTextEditor. Otherwise a first activated file would not be recorded. this.activeTextEditor = (ITextEditor) activeEditorPart; // Gets opened file since the initial opened file is not notified from IPartListener. URI fileResource = EclipseSensor.this.getFileResource(this.activeTextEditor); Map<String, String> keyValueMap = new HashMap<String, String>(); keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Open"); keyValueMap.put(EclipseSensorConstants.UNIT_TYPE, EclipseSensorConstants.FILE); keyValueMap.put( EclipseSensorConstants.UNIT_NAME, EclipseSensor.this.extractFileName(fileResource)); this.addDevEvent( EclipseSensorConstants.DEVEVENT_EDIT, fileResource, keyValueMap, "Opened " + fileResource.toString()); IDocumentProvider provider = this.activeTextEditor.getDocumentProvider(); IDocument document = provider.getDocument(activeEditorPart.getEditorInput()); // Initially sets active buffer and threshold buffer. // Otherwise a first activated buffer would not be recorded. this.activeBufferSize = document.getLength(); this.thresholdBufferSize = document.getLength(); document.addDocumentListener(new DocumentListenerAdapter()); } } // Handles breakpoint set/unset event. IBreakpointManager bpManager = DebugPlugin.getDefault().getBreakpointManager(); bpManager.addBreakpointListener(new BreakPointerSensor(this)); // Listens to debug event. DebugPlugin.getDefault().addDebugEventListener(new DebugSensor(this)); // Creates instance to handle build error. this.buildErrorSensor = new BuildErrorSensor(this); }
/** * Build sensor properties out from user's preference. * * @throws SensorShellException Sensorshell properties problem. * @return Sensorshell properties. */ private SensorShellProperties buildProperties() throws SensorShellException { EclipseSensorPlugin plugin = EclipseSensorPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); Properties props = new Properties(); String host = store.getString(PreferenceConstants.P_SENSORBASE); props.put(SensorShellProperties.SENSORSHELL_SENSORBASE_HOST_KEY, host); String email = store.getString(PreferenceConstants.P_EMAIL); props.put(SensorShellProperties.SENSORSHELL_SENSORBASE_USER_KEY, email); String password = store.getString(PreferenceConstants.P_PASSWORD); props.put(SensorShellProperties.SENSORSHELL_SENSORBASE_PASSWORD_KEY, password); String autosendInterval = store.getString(PreferenceConstants.P_AUTOSEND_INTERVAL); props.put(SensorShellProperties.SENSORSHELL_AUTOSEND_TIMEINTERVAL_KEY, autosendInterval); SensorShellProperties sensorShellProperties = new SensorShellProperties(props, true); return sensorShellProperties; }