private ExternalSourceArchiveManager() { // Prevent instantiation // https://bugs.eclipse.org/bugs/show_bug.cgi?id=377806 if (Platform.isRunning()) { getSourceArchives(); } }
/** * Abstract implementation of {@link edu.cmu.sei.aadl.model.pluginsupport.ErrorReporterManager} that * delegates The implementation of the methods {@link #internalError(Exception)}, {@link * #internalError(String)}, and {@link #getNumInternalErrors()} to another {@link * edu.cmu.sei.aadl.model.pluginsupport.InternalErrorReporter} object. This is done to acheive a * sort of "mix-in" implementation, because the {@link * edu.cmu.sei.aadl.model.pluginsupport.ParseErrorReporterManager} and {@link * edu.cmu.sei.aadl.model.pluginsupport.AnalysisErrorReporterManager} in general have quite * different (although similar) implementations, although it is likely that in any given environment * they will want to share the implementation of the internal error reporter (e.g., to log events to * the Eclipse "error" view). * * @author aarong */ public abstract class AbstractErrorReporterManager implements ErrorReporterManager { private static InternalErrorReporter internalErrDelegate = Platform.isRunning() ? new LogInternalErrorReporter(OsateCorePlugin.getDefault().getBundle()) : WriterInternalErrorReporter.SYSTEM_ERR; protected AbstractErrorReporterManager() {} @Deprecated protected AbstractErrorReporterManager(final InternalErrorReporter ier) { internalErrDelegate = ier; } public void internalError(final String message) { internalErrDelegate.internalError(message); } public void internalError(final Exception e) { internalErrDelegate.internalError(e); } public int getNumInternalErrors() { return internalErrDelegate.getNumInternalErrors(); } }
/** * call to wait until index maintenance has completed * * @throws InterruptedException */ public void waitUntilIdle() throws InterruptedException { if (!Platform.isRunning() && reindexDelay != 0L) { // job join() behaviour is not the same when platform is not running Logger.getLogger(TaskListIndex.class.getName()) .warning( "Index job joining may not work properly when Eclipse platform is not running"); //$NON-NLS-1$ } maintainIndexJob.join(); }
static { try { Configuration cfg = new Configuration() .addAnnotatedClass(Location.class) .addAnnotatedClass(Unit.class) .addAnnotatedClass(Version.class) .setProperty("hibernate.dialect", SQLiteDialect.class.getName()) .setProperty("hibernate.connection.driver_class", org.sqlite.JDBC.class.getName()) .setProperty("hibernate.show_sql", "false") .setProperty("hibernate.format_sql", "false") .setProperty("hibernate.connection.username", "") .setProperty("hibernate.connection.password", "") .setProperty("hibernate.current_session_context_class", "thread") .setProperty("connection.pool_size", "1"); if (Platform.isRunning()) { IPath path = Activator.getDefault().getStateLocation().append("contents.db"); File file = path.toFile(); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); // http://stackoverflow.com/a/1689769 // validate, update, create, create-drop cfg = cfg.setProperty("hibernate.hbm2ddl.auto", "create"); } else { cfg = cfg.setProperty("hibernate.hbm2ddl.auto", "update"); } cfg = cfg.setProperty("hibernate.connection.url", "jdbc:sqlite:" + path.toOSString()); } else { File file = new File(System.getProperty("user.dir") + "/contents.db"); cfg = cfg.setProperty("hibernate.hbm2ddl.auto", "create"); if (!file.exists()) { file.createNewFile(); } String path = file.getAbsolutePath().replace("\\", "/"); cfg = cfg.setProperty("hibernate.connection.url", "jdbc:sqlite:" + path); } ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); sessionFactory = cfg.buildSessionFactory(serviceRegistry); } catch (Exception e) { Activator.getDefault() .getLog() .log( new Status( IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), e.getMessage(), e)); throw new RuntimeException(e); } }
protected static String getPluginDirectoryPath() { try { if (Platform.isRunning()) { URL platformURL = Platform.getBundle("org.eclipse.jdt.compiler.apt.tests").getEntry("/"); return new File(FileLocator.toFileURL(platformURL).getFile()).getAbsolutePath(); } return new File(System.getProperty("user.dir")).getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); } return null; }
protected Image getImage(EObject element) { if (!Platform.isRunning()) { return null; } ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory()); adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory()); adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory); return labelProvider.getImage(element); }
/** Construct an instance of AvailableModelExtensionDefinitionsDialog. */ public AvailableModelExtensionDefinitionsDialog( Shell shell, ModelResource resource, List<ModelExtensionDefinitionHeader> currentModelHeaders) { super(shell); this.setTitle(Messages.availableMedsDialogTitle); setShellStyle(getShellStyle() | SWT.RESIZE); setStatusLineAboveButtons(true); this.registry = (Platform.isRunning() ? ExtensionPlugin.getInstance().getRegistry() : null); this.modelResource = resource; this.availableMedsList = getAddableMEDs(this.modelResource, currentModelHeaders); this.selectedMedsList = new ArrayList(); }
/** * Tries to determine the file for the given resource. If the platform is not running, the * resource is not a platform resource, or the resource cannot be found in the workspace, this * method returns <code>null</code>. */ protected org.eclipse.core.resources.IFile getFile( org.eclipse.emf.ecore.resource.Resource resource) { if (resource == null || !org.eclipse.core.runtime.Platform.isRunning()) { return null; } String platformString = resource.getURI().toPlatformString(true); if (platformString == null) { return null; } org.eclipse.core.resources.IFile file = (org.eclipse.core.resources.IFile) org.eclipse.core.resources.ResourcesPlugin.getWorkspace() .getRoot() .findMember(platformString); return file; }
/** Initializes all plugin stores by inspecting all extensions. */ public static void init() { if (Platform.isRunning()) { IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_STORE_EP_ID); IConfigurationElement[] entries = ep.getConfigurationElements(); List<URI> existingURIs = new ArrayList<URI>(); for (int i = 0; i < entries.length; i++) { String path = entries[i].getAttribute("folder"); String bundleID = entries[i].getDeclaringExtension().getNamespaceIdentifier(); Bundle bundle = Platform.getBundle(bundleID); String updateString = entries[i].getAttribute("update"); boolean update = false; if ("true".equals(updateString) || "TRUE".equals(updateString)) { update = true; } if (path != null && bundle != null) { String storeURI = "/" + bundleID + "/" + path; while (storeURI.endsWith("/")) { storeURI = storeURI.substring(0, storeURI.length() - 1); } registerStore(URI.createPlatformPluginURI(storeURI, true)); @SuppressWarnings("unchecked") Enumeration<URL> urlEnum = bundle.findEntries(path, null, true); while (urlEnum.hasMoreElements()) { URL url = urlEnum.nextElement(); String uriString = url.toExternalForm(); if (!uriString.endsWith("/") && !uriString.contains("/.")) { uriString = uriString.substring("bundleentry://".length()); uriString = uriString.substring(uriString.indexOf("/")); uriString = "/" + bundleID + uriString; URI uri = URI.createPlatformPluginURI(uriString, true); addOrUpdateArtifact(uri, update); existingURIs.add(uri); } } } } removeOldArtifacts(existingURIs); } }
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); } } } } }
/** * Returns the preferences of line seperator. * * @param project * @return */ public static String getLineSeparator(IProject project) { if (Platform.isRunning()) { String lineSeparator = null; // line delimiter in project preference IScopeContext[] scopeContext; if (project != null) { scopeContext = new IScopeContext[] {new ProjectScope(project)}; lineSeparator = Platform.getPreferencesService() .getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); if (lineSeparator != null) return lineSeparator; } // line delimiter in workspace preference scopeContext = new IScopeContext[] {InstanceScope.INSTANCE}; lineSeparator = Platform.getPreferencesService() .getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); if (lineSeparator != null) return lineSeparator; } return System.getProperty("line.separator"); }
/** * Get the absolute installation path of plugin. * * @param pluginId * @return the plugin path or an empty string when it's not found. */ public static String getPluginInstallPath(String pluginId) { String pluginPath = ""; try { boolean running = Platform.isRunning(); if (!running) { return pluginPath; } URL url = FileLocator.resolve(Platform.getBundle(pluginId).getEntry("/")); // $NON-NLS-1$ if (url == null) { return pluginPath; } pluginPath = url.getFile(); String protoPath = url.getProtocol(); if (pluginPath.startsWith("file:")) { // $NON-NLS-1$ pluginPath = pluginPath.substring(pluginPath.indexOf("file:") + 6); // $NON-NLS-1$ } if ("jar".equals(protoPath) && pluginPath.endsWith("!/")) { // $NON-NLS-1$ //$NON-NLS-2$ pluginPath = pluginPath.substring(0, pluginPath.lastIndexOf("!/")); // $NON-NLS-1$ } } catch (IOException e) { ExceptionHandler.process(e); } return pluginPath; }
@Override public IEditingDomainFactory getEditingDomainFactory() { if (extension == null) { if (Platform.isRunning()) { try { extension = (IEditingDomainFactory) element.createExecutableExtension(EDITING_DOMAIN_FACTORY_CLASS_ATTRIBUTE); } catch (CoreException e) { DslCommonPlugin.getDefault() .getLog() .log( new Status( IStatus.ERROR, DslCommonPlugin.PLUGIN_ID, MessageFormat.format( Messages.EclipseEditingDomainFactoryDescriptor_errorLoadingExtension, element.getDeclaringExtension().getUniqueIdentifier()), e)); } } } return extension; }
@BeforeClass public static void checkEclipseIsRunning() { assertTrue( "These tests are meant to be running as Eclipse plug-in tests", Platform.isRunning()); }
@Override public void execute() throws BuildException { checkParameters(); AntClassLoader taskloader = setClassLoader(); registerResourceFactories(); try { log("loading syntax file..."); ICsTextResource csResource = CsResourceUtil.getResource(syntaxFile); EList<EObject> contents = csResource.getContents(); if (contents.size() < 1) { if (!csResource.getErrors().isEmpty()) { log("Resource has the following errors:"); logErrors(csResource); } throw new BuildException( "Generation failed, because the syntax file could not be loaded. Probably it contains syntactical errors."); } ResourceSet resourceSet = csResource.getResourceSet(); EcoreUtil.resolveAll(resourceSet); Set<EObject> unresolvedProxies = CsResourceUtil.findUnresolvedProxies(resourceSet); logUnresolvedProxies(unresolvedProxies); if (unresolvedProxies.size() > 0) { throw new BuildException( "Generation failed, because the syntax file contains unresolved proxy objects."); } ConcreteSyntax syntax = (ConcreteSyntax) contents.get(0); performPreprocessing(syntax); IFileSystemConnector folderConnector = new IFileSystemConnector() { public File getProjectFolder(IPluginDescriptor plugin) { return new File(rootFolder.getAbsolutePath() + File.separator + plugin.getName()); } }; Result result = null; boolean useUIJob = false; if (Platform.isRunning()) { File wsFolder = new File(ResourcesPlugin.getWorkspace().getRoot().getLocationURI()); if (rootFolder.equals(wsFolder)) useUIJob = true; } AntProblemCollector problemCollector = new AntProblemCollector(this); if (useUIJob) { UIGenerationContext context = new UIGenerationContext(folderConnector, problemCollector, syntax); UICreateResourcePluginsJob job = new UICreateResourcePluginsJob(); result = job.run(context, new AntLogMarker(this), new AntDelegateProgressMonitor(this)); } else { AntGenerationContext context = new AntGenerationContext( folderConnector, problemCollector, syntax, rootFolder, syntaxProjectName, generateANTLRPlugin, generateModelCode); AntResourcePluginGenerator generator = new AntResourcePluginGenerator(); result = generator.run(context, new AntLogMarker(this), new AntDelegateProgressMonitor(this)); } if (result != Result.SUCCESS) { if (result == Result.ERROR_FOUND_UNRESOLVED_PROXIES) { logUnresolvedProxies(result.getUnresolvedProxies()); resetClassLoader(taskloader); throw new BuildException("Generation failed " + result); } else { logErrors(syntax.eResource()); resetClassLoader(taskloader); throw new BuildException("Generation failed " + result); } } Collection<GenerationProblem> errors = problemCollector.getErrors(); if (!errors.isEmpty()) { for (GenerationProblem error : errors) { log("Found problem: " + error.getMessage(), Project.MSG_ERR); } throw new BuildException( "Generation failed. Found " + errors.size() + " problem(s) while generating text resource plug-ins."); } } catch (Exception e) { resetClassLoader(taskloader); log("Exception while generation text resource: " + e.getMessage(), Project.MSG_ERR); e.printStackTrace(); throw new BuildException(e); } resetClassLoader(taskloader); }