| /*=============================================================================# |
| # Copyright (c) 2007, 2020 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.ltk.core; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.osgi.framework.BundleContext; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Plugin; |
| |
| import org.eclipse.statet.jcommons.lang.Disposable; |
| |
| import org.eclipse.statet.ltk.core.IExtContentTypeManager; |
| import org.eclipse.statet.ltk.model.core.ISourceUnitManager; |
| |
| |
| /** |
| * The activator class controls the plug-in life cycle |
| */ |
| public final class LTKCorePlugin extends Plugin { |
| |
| |
| public static final String BUNDLE_ID= "org.eclipse.statet.ltk.core"; //$NON-NLS-1$ |
| |
| |
| private static LTKCorePlugin instance; |
| private static LTKCorePlugin gSafe; |
| |
| /** |
| * Returns the shared plug-in instance |
| * |
| * @return the shared instance |
| */ |
| public static LTKCorePlugin getInstance() { |
| return instance; |
| } |
| |
| /** |
| * Returns the shared plug-in instance |
| * |
| * @return the shared instance |
| */ |
| public static LTKCorePlugin getSafe() { |
| return gSafe; |
| } |
| |
| |
| public static void log(final IStatus status) { |
| final LTKCorePlugin plugin= getInstance(); |
| if (plugin != null) { |
| plugin.getLog().log(status); |
| } |
| } |
| |
| |
| private boolean started; |
| |
| private final List<Disposable> disposables= new ArrayList<>(); |
| |
| private ExtContentTypeServices contentTypeServices; |
| private SourceUnitManager sourceUnitManager; |
| |
| private AdapterFactory modelAdapterFactory; |
| |
| |
| /** |
| * The default constructor |
| */ |
| public LTKCorePlugin() { |
| instance= this; |
| gSafe= this; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public void start(final BundleContext context) throws Exception { |
| super.start(context); |
| |
| synchronized (this) { |
| this.started= true; |
| |
| this.contentTypeServices= new ExtContentTypeServices(); |
| addStoppingListener(this.contentTypeServices); |
| this.sourceUnitManager= new SourceUnitManager(); |
| addStoppingListener(this.sourceUnitManager); |
| } |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public void stop(final BundleContext context) throws Exception { |
| try { |
| synchronized (this) { |
| this.started= false; |
| |
| this.contentTypeServices= null; |
| this.sourceUnitManager= null; |
| } |
| |
| try { |
| for (final Disposable listener : this.disposables) { |
| listener.dispose(); |
| } |
| } |
| finally { |
| this.disposables.clear(); |
| } |
| } |
| finally { |
| instance= null; |
| super.stop(context); |
| } |
| } |
| |
| |
| public void addStoppingListener(final Disposable listener) { |
| if (listener == null) { |
| throw new NullPointerException(); |
| } |
| synchronized (this) { |
| if (!this.started) { |
| throw new IllegalStateException("Plug-in is not started."); |
| } |
| this.disposables.add(listener); |
| } |
| } |
| |
| public IExtContentTypeManager getContentTypeServices() { |
| return this.contentTypeServices; |
| } |
| |
| public ISourceUnitManager getSourceUnitManager() { |
| return this.sourceUnitManager; |
| } |
| |
| public synchronized AdapterFactory getModelAdapterFactory() { |
| if (this.modelAdapterFactory == null) { |
| if (!this.started) { |
| throw new IllegalStateException("Plug-in is not started."); |
| } |
| this.modelAdapterFactory= new AdapterFactory("org.eclipse.statet.ltk.ModelAdapters"); //$NON-NLS-1$ |
| } |
| return this.modelAdapterFactory; |
| } |
| |
| } |