diff --git a/tools.templates/org.eclipse.tools.templates.freemarker/META-INF/MANIFEST.MF b/tools.templates/org.eclipse.tools.templates.freemarker/META-INF/MANIFEST.MF index 3968d606f5f..e3d80afcdfe 100644 --- a/tools.templates/org.eclipse.tools.templates.freemarker/META-INF/MANIFEST.MF +++ b/tools.templates/org.eclipse.tools.templates.freemarker/META-INF/MANIFEST.MF @@ -1,9 +1,10 @@ Manifest-Version: 1.0 +Automatic-Module-Name: org.eclipse.tools.templates.freemarker Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.tools.templates.freemarker -Bundle-Version: 1.1.100.qualifier -Bundle-Activator: org.eclipse.tools.templates.freemarker.internal.Activator +Bundle-Version: 1.1.200.qualifier +Bundle-Name: %pluginName +Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, org.freemarker;visibility:=reexport, @@ -12,4 +13,4 @@ Require-Bundle: org.eclipse.core.runtime, Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.tools.templates.freemarker -Bundle-Vendor: %providerName +Bundle-Localization: plugin diff --git a/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/FMGenerator.java b/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/FMGenerator.java index 35d01126da8..0641c5bf2a4 100644 --- a/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/FMGenerator.java +++ b/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/FMGenerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 QNX Software Systems and others. + * Copyright (c) 2016, 2020 QNX Software Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -46,9 +47,9 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.tools.templates.core.IGenerator; -import org.eclipse.tools.templates.freemarker.internal.Activator; import org.eclipse.tools.templates.freemarker.internal.Messages; import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; import com.sun.xml.bind.v2.ContextFactory; @@ -63,11 +64,15 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader { private final String manifestPath; private TemplateManifest manifest; private List filesToOpen = new ArrayList<>(); + private final String pluginId; protected FMGenerator(String manifestPath) { templateConfig = new Configuration(Configuration.VERSION_2_3_22); templateConfig.setTemplateLoader(this); this.manifestPath = manifestPath; + this.pluginId = Optional.ofNullable(FrameworkUtil.getBundle(FMGenerator.class))// + .map(b -> b.getSymbolicName())// + .orElse(FMGenerator.class.getName()); } protected abstract Bundle getSourceBundle(); @@ -107,7 +112,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader { Unmarshaller unmarshaller = xmlContext.createUnmarshaller(); manifest = (TemplateManifest) unmarshaller.unmarshal(new StringReader(writer.toString())); } catch (JAXBException e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), Messages.FMGenerator_0, e)); + throwCoreException(Messages.FMGenerator_0, e); } // generate files @@ -132,8 +137,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader { } } } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), - String.format(Messages.FMGenerator_1, fileTemplate.getSrc()), e)); + throwCoreException(String.format(Messages.FMGenerator_1, fileTemplate.getSrc()), e); } } @@ -160,8 +164,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader { Template template = templateConfig.getTemplate(templateFile); template.process(model, out); } catch (IOException | TemplateException e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), - String.format(Messages.FMGenerator_2, templateFile), e)); + throwCoreException(String.format(Messages.FMGenerator_2, templateFile), e); } } @@ -179,8 +182,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader { } } } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), - String.format(Messages.FMGenerator_3, templateFile), e)); + throwCoreException(String.format(Messages.FMGenerator_3, templateFile), e); } } @@ -234,4 +236,8 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader { // Nothing } + private void throwCoreException(String message, Throwable e) throws CoreException { + throw new CoreException(new Status(IStatus.ERROR, pluginId, message, e)); + } + } diff --git a/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/internal/Activator.java b/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/internal/Activator.java deleted file mode 100644 index 92850cf1968..00000000000 --- a/tools.templates/org.eclipse.tools.templates.freemarker/src/org/eclipse/tools/templates/freemarker/internal/Activator.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 QNX Software Systems and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.tools.templates.freemarker.internal; - -import org.eclipse.core.runtime.Plugin; -import org.osgi.framework.BundleContext; - -public class Activator extends Plugin { - - private static Activator plugin; - - @Override - public void start(BundleContext bundleContext) throws Exception { - super.start(bundleContext); - plugin = this; - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - super.stop(bundleContext); - plugin = null; - } - - public static String getId() { - return plugin.getBundle().getSymbolicName(); - } - -}