/** * Adds message to log. * * @param level severity level of the message (OK, INFO, WARNING, ERROR, OK_DEBUG, INFO_DEBUG, * WARNING_DEBUG, ERROR_DEBUG) * @param message text to add to the log * @param exception exception thrown */ protected static void _log(int level, String message, Throwable exception) { if (level == OK_DEBUG || level == INFO_DEBUG || level == WARNING_DEBUG || level == ERROR_DEBUG) { if (!isDebugging()) return; } int severity = IStatus.OK; switch (level) { case INFO_DEBUG: case INFO: severity = IStatus.INFO; break; case WARNING_DEBUG: case WARNING: severity = IStatus.WARNING; break; case ERROR_DEBUG: case ERROR: severity = IStatus.ERROR; } message = (message != null) ? message : "null"; // $NON-NLS-1$ Status statusObj = new Status(severity, PLUGIN_ID, severity, message, exception); Bundle bundle = Platform.getBundle(PLUGIN_ID); if (bundle != null) Platform.getLog(bundle).log(statusObj); }
public static ILog getLog() { if (log == null) { Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); log = Platform.getLog(bundle); } return log; }
@Before public void setup() { ILog log = Platform.getLog(Platform.getBundle(Activator.PLUGIN_ID)); log.log( new Status( IStatus.ERROR, ERROR_ID_1, ERROR_MESSAGE_1, new NullPointerException(ERROR_STACK_1))); log.log( new Status( IStatus.ERROR, ERROR_ID_2, ERROR_MESSAGE_2, new NullPointerException(ERROR_STACK_2))); log.log(new Status(IStatus.OK, OK_ID_1, OK_MESSAGE_1, null)); log.log(new Status(IStatus.OK, OK_ID_2, OK_MESSAGE_2, new NullPointerException(OK_STACK_2))); log.log( new Status( IStatus.WARNING, WARNING_ID_1, WARNING_MESSAGE_1, new IllegalArgumentException(WARNING_STACK_1))); log.log( new Status( IStatus.WARNING, WARNING_ID_2, WARNING_MESSAGE_2, new NullPointerException(WARNING_STACK_2))); log.log(new Status(IStatus.INFO, INFO_ID_1, INFO_MESSAGE_1, null)); log.log( new Status( IStatus.INFO, INFO_ID_2, INFO_MESSAGE_2, new NullPointerException(INFO_STACK_2))); }
protected void validateState(IEditorInput input) { IDocumentProvider provider = getDocumentProvider(); if (!(provider instanceof IDocumentProviderExtension)) return; IDocumentProviderExtension extension = (IDocumentProviderExtension) provider; try { extension.validateState(input, getSite().getShell()); } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID); ILog log = Platform.getLog(bundle); log.log(x.getStatus()); Shell shell = getSite().getShell(); String title = "EditorMessages.Editor_error_validateEdit_title"; String msg = "EditorMessages.Editor_error_validateEdit_message"; ErrorDialog.openError(shell, title, msg, x.getStatus()); } return; } if (fSourceViewer != null) fSourceViewer.setEditable(isEditable()); }
/** * Prints message to log if category matches /debug/tracefilter option. * * @param message text to print * @param category category of the message, to be compared with /debug/tracefilter */ protected static void _trace(String category, String message, Throwable exception) { if (isTracing(category)) { message = (message != null) ? message : "null"; // $NON-NLS-1$ Status statusObj = new Status(IStatus.OK, PLUGIN_ID, IStatus.OK, message, exception); Bundle bundle = Platform.getBundle(PLUGIN_ID); if (bundle != null) Platform.getLog(bundle).log(statusObj); } }
/* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { System.out.println("start plugin " + PLUGIN_ID); super.start(context); plugin = this; Bundle bundle = Platform.getBundle(Platform.PI_RUNTIME); log = Platform.getLog(bundle); registerEventHandler(context); }
/** Generates an error in the Eclipse error log. Note that most people never look at it! */ public static void error( CompilationUnitDeclaration cud, String message, String bundleName, Throwable error) { Bundle bundle = Platform.getBundle(bundleName); if (bundle == null) { System.err.printf( "Can't find bundle %s while trying to report error:\n%s\n", bundleName, message); return; } ILog log = Platform.getLog(bundle); log.log(new Status(IStatus.ERROR, bundleName, message, error)); if (cud != null) EclipseAST.addProblemToCompilationResult(cud, false, message + " - See error log.", 0, 0); }
/* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; logger = Platform.getLog(this.getBundle()); IPreferenceStore store = getPreferenceStore(); HybridToolsPreferences.init(store); store.addPropertyChangeListener( new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { HybridToolsPreferences.getPrefs().loadValues(event); } }); HybridToolsPreferences.getPrefs().loadValues(); }
private Connector[] getAllConnectors() { try { BundleContext context = Platform.getBundle(Activator.PLUGIN_ID).getBundleContext(); ServiceReference[] refs = context.getAllServiceReferences( Server.class.getName(), "(managedServerName=defaultJettyServer)"); for (ServiceReference ref : refs) { Server server = (Server) context.getService(ref); return server.getConnectors(); } } catch (InvalidSyntaxException e) { IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Can not find jetty server.", e); Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); Platform.getLog(bundle).log(status); throw new RuntimeException("Can not find jetty server.", e); } throw new RuntimeException("Can not find jetty server."); }
private static URL getDynamicTemplatesURL(String templateDirectory) { if (templateDirectory != null) { URI templatesURI = templateDirectory.indexOf(":") == -1 ? URI.createPlatformResourceURI(templateDirectory, true) : URI.createURI(templateDirectory); // $NON-NLS-1$ try { return new URL(templatesURI.toString()); } catch (MalformedURLException e) { Platform.getLog(getTemplatesBundle()) .log( new Status( IStatus.ERROR, getTemplatesBundle().getSymbolicName(), 0, "Incorrecct dynamic templates location", e)); //$NON-NLS-1$ } } return null; }
@Override protected void append(ILoggingEvent logEvent) { int severity = 0; switch (logEvent.getLevel().levelInt) { case Level.ERROR_INT: severity = IStatus.ERROR; break; case Level.WARN_INT: severity = IStatus.WARNING; break; case Level.INFO_INT: severity = IStatus.INFO; break; default: return; } IStatus status = new Status(severity, BUNDLE_ID, logEvent.getFormattedMessage(), getThrowable(logEvent)); ILog eclipseLog = Platform.getLog(getSelfBundle()); eclipseLog.log(status); }
private static void init() { if (evaluatorMap == null) { evaluatorMap = new LinkedHashMap<String, Evaluator>(); if (Platform.isRunning()) { // read extension point IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(EVALUATOR_EP_ID); IConfigurationElement[] entries = ep.getConfigurationElements(); for (int i = 0; i < entries.length; i++) { try { Evaluator evaluator = (Evaluator) entries[i].createExecutableExtension("class"); evaluatorMap.put(evaluator.getPrefix(), evaluator); } catch (CoreException e) { IStatus status = new Status( IStatus.ERROR, PLUGIN_ID, 0, "[Reuseware] Failed to install an evaluator", e); Platform.getLog(Platform.getBundle(PLUGIN_ID)).log(status); } } } } }
private PluginHelper() { super(); Bundle bundle = Platform.getBundle(Platform.PI_RUNTIME); log = Platform.getLog(bundle); }
public static void log(IStatus status) { ILog log = Platform.getLog(context.getBundle()); if (log != null) log.log(status); }
public class RSetupUtil { public static final String EXTENSION_POINT_ID = "de.walware.rj.rSetups"; // $NON-NLS-1$ private static final String PLUGIN_ID = "de.walware.rj.server"; // $NON-NLS-1$ private static final ILog LOGGER = Platform.getLog(Platform.getBundle(PLUGIN_ID)); private static final String SETUP_ELEMENT_NAME = "setup"; // $NON-NLS-1$ private static final String BASE_ELEMENT_NAME = "base"; // $NON-NLS-1$ private static final String LIBRARY_ELEMENT_NAME = "library"; // $NON-NLS-1$ private static final String ID_ATTRIBUTE_NAME = "id"; // $NON-NLS-1$ private static final String SETUP_ID_ATTRIBUTE_NAME = "setupId"; // $NON-NLS-1$ private static final String NAME_ATTRIBUTE_NAME = "name"; // $NON-NLS-1$ private static final String INHERIT_BASE_ATTRIBUTE_NAME = "inheritBase"; // $NON-NLS-1$ private static final String LOCATION_ATTRIBUTE_NAME = "location"; // $NON-NLS-1$ private static final String GROUP_ATTRIBUTE_NAME = "group"; // $NON-NLS-1$ /** * Loads all available R setups for the current or the specified platform. * * <p>A filter map specifying a platform contains the arguments like <code>$os$</code> and <code> * $arch$</code> as keys; its values must be set to the known constant of the desired. platform. * * @param filter a platform filter or <code>null</code> for the current platform * @return a list with available R setups */ public static List<RSetup> loadAvailableSetups(final Map<String, String> filter) { final Set<String> ids = new HashSet<String>(); final List<RSetup> setups = new ArrayList<RSetup>(); final IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); for (int i = 0; i < configurationElements.length; i++) { if (configurationElements[i].getName().equals(SETUP_ELEMENT_NAME)) { final String id = configurationElements[i].getAttribute(ID_ATTRIBUTE_NAME); if (id != null && id.length() > 0 && !ids.contains(id)) { ids.add(id); final RSetup setup = loadSetup(id, filter, configurationElements); if (setup != null) { setups.add(setup); } } } } return setups; } /** * Loads the R setup with the specified id for the current or the specified platform. * * <p>A filter map specifying a platform contains the arguments like <code>$os$</code> and <code> * $arch$</code> as keys; its values must be set to the known constant of the desired. platform. * * @param id the id of the R setup * @param filter a platform filter or <code>null</code> for the current platform * @return the R setup or <code>null</code> if loading failed */ public static RSetup loadSetup(final String id, final Map<String, String> filter) { final IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); return loadSetup(id, filter, configurationElements); } private static RSetup loadSetup( final String id, final Map<String, String> filter, final IConfigurationElement[] configurationElements) { try { for (int i = 0; i < configurationElements.length; i++) { final IConfigurationElement element = configurationElements[i]; if (element.getName().equals(SETUP_ELEMENT_NAME) && id.equals(element.getAttribute(ID_ATTRIBUTE_NAME))) { final RSetup setup = new RSetup(id); if (filter != null && filter.containsKey("$os$")) { // $NON-NLS-1$ setup.setOS(filter.get("$os$"), filter.get("$arch$")); // $NON-NLS-1$ //$NON-NLS-2$ } else { setup.setOS(Platform.getOS(), Platform.getOSArch()); } setup.setName(element.getAttribute(NAME_ATTRIBUTE_NAME)); loadSetupBase(id, filter, configurationElements, setup); if (setup.getRHome() == null) { log( IStatus.WARNING, "Incomplete R setup: Missing R home for setup '" + id + "', the setup is ignored.", element); return null; } loadSetupLibraries(id, filter, configurationElements, setup); return setup; } } } catch (final Exception e) { LOGGER.log( new Status(IStatus.ERROR, PLUGIN_ID, "Error in R setup: Failed to load setup.", e)); } return null; } private static void loadSetupBase( final String id, final Map<String, String> filter, final IConfigurationElement[] configurationElements, final RSetup setup) throws Exception { for (int i = 0; i < configurationElements.length; i++) { final IConfigurationElement element = configurationElements[i]; if (element.getName().equals(BASE_ELEMENT_NAME) && id.equals(element.getAttribute(SETUP_ID_ATTRIBUTE_NAME))) { final String path = getLocation(element, filter); setup.setRHome(path); return; } } for (int i = 0; i < configurationElements.length; i++) { final IConfigurationElement element = configurationElements[i]; if (element.equals(SETUP_ELEMENT_NAME) && id.equals(element.getAttribute(SETUP_ID_ATTRIBUTE_NAME))) { final String inheritId = element.getAttribute(INHERIT_BASE_ATTRIBUTE_NAME); if (inheritId != null) { loadSetupBase(inheritId, filter, configurationElements, setup); } return; } } } private static void loadSetupLibraries( final String id, final Map<String, String> filter, final IConfigurationElement[] configurationElements, final RSetup setup) throws Exception { for (int i = 0; i < configurationElements.length; i++) { final IConfigurationElement element = configurationElements[i]; if (element.getName().equals(LIBRARY_ELEMENT_NAME) && id.equals(element.getAttribute(SETUP_ID_ATTRIBUTE_NAME))) { final String path = getLocation(element, filter); if (path == null) { continue; } final String groupId = element.getAttribute(GROUP_ATTRIBUTE_NAME); if (groupId == null || groupId.length() == 0 || groupId.equals("R_LIBS")) { // $NON-NLS-1$ setup.getRLibs().add(path); } else if (groupId.equals("R_LIBS_SITE")) { // $NON-NLS-1$ setup.getRLibsSite().add(path); } else if (groupId.equals("R_LIBS_USER")) { // $NON-NLS-1$ setup.getRLibsUser().add(path); } else { log( IStatus.WARNING, "Invalid R setup element: " + "Unknown library group '" + groupId + "', the library is ignored", element); } } } } private static String getLocation( final IConfigurationElement element, final Map<String, String> filter) throws Exception { final Bundle bundle = Platform.getBundle(element.getContributor().getName()); final String path = element.getAttribute(LOCATION_ATTRIBUTE_NAME); if (bundle != null && path != null && path.length() > 0) { final URL[] bundleURLs = FileLocator.findEntries(bundle, new Path(path), filter); for (int i = 0; i < bundleURLs.length; i++) { final URI fileURI = URIUtil.toURI(FileLocator.toFileURL(bundleURLs[i])); if (fileURI.getScheme().equals("file")) { // $NON-NLS-1$ final File file = new File(fileURI); if (file.exists() && file.isDirectory() && file.list().length > 0) { return file.getAbsolutePath(); } } } } return null; } private static void log( final int severity, final String message, final IConfigurationElement element) { final StringBuilder info = new StringBuilder(message); if (element != null) { info.append(" (contributed by '"); info.append(element.getContributor().getName()); info.append("')."); } LOGGER.log(new Status(IStatus.WARNING, PLUGIN_ID, info.toString())); } }
public MasterListTestSuite() { super("WTP Source Editing Master List Test Suite"); System.setProperty("wtp.autotest.noninteractive", "true"); addTest(SSEModelTestSuite.suite()); addTest(SSEModelXMLTestSuite.suite()); addTest(DTDCoreTestSuite.suite()); addTest(AllXSDCoreTests.suite()); addTest(CSSCoreTestSuite.suite()); addTest(HTMLCoreTestSuite.suite()); addTest(JSPCoreTestSuite.suite()); // addTest(EncodingTestSuite.suite()); // addTest(CSSEncodingTestSuite.suite()); // addTest(HTMLEncodingTestSuite.suite()); // addTest(JSPEncodingTestSuite.suite()); // // addTest(AllXMLTests.suite()); // addTest(AllXSDTests.suite()); addTest(SSEUITestSuite.suite()); addTest(XMLUITestSuite.suite()); addTest(DTDUITestSuite.suite()); addTest(CSSUITestSuite.suite()); addTest(HTMLUITestSuite.suite()); addTest(JSPUITestSuite.suite()); addTest(RunJSDTCoreTests.suite()); addTest(JSDTCompilerTests.suite()); addTest(JSDTUITests.suite()); addTest(AllWebCoreTests.suite()); addTest(AllWebUITests.suite()); // addTest(new AllTestsSuite()); // addTest(RegressionBucket.suite()); // addTest(AllTestCases.suite()); IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); for (int i = 0; i < elements.length; i++) { if (elements[i].getName().equals("suite")) { TestSuite suite; try { suite = (TestSuite) elements[i].createExecutableExtension(CLASS); addTestSuite(suite.getClass()); System.err.println("Adding TestSuite " + suite.getClass().getName()); } catch (CoreException e) { e.printStackTrace(System.err); Platform.getLog(Platform.getBundle("org.eclipse.wst.sse.unittests")).log(e.getStatus()); } } else if (elements[i].getName().equals("test")) { Test test; try { test = (Test) elements[i].createExecutableExtension(CLASS); addTestSuite(test.getClass()); System.err.println("Adding TestCase " + test.getClass().getName()); } catch (CoreException e) { e.printStackTrace(System.err); Platform.getLog(Platform.getBundle("org.eclipse.wst.sse.unittests")).log(e.getStatus()); } } } }
public static void logError(Throwable exception) { Platform.getLog(Platform.getBundle(PLUGIN_ID)) .log(createStatus(IStatus.ERROR, exception.getMessage(), exception)); }
public static void logError(CoreException exception) { Platform.getLog(Platform.getBundle(PLUGIN_ID)).log(exception.getStatus()); }