mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 561658 - Remove Activator for CDT Templates Freemaker
Replaced "org.eclipse.tools.templates.freemarker.internal.Activator" with "FMGenerator"-local code to determine pluginId for IStatus creation Change-Id: Iaff6d51b09de225d6d2c657e83e36ac8418f62b3 Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
parent
36de92cc77
commit
f965614e9a
3 changed files with 20 additions and 49 deletions
|
@ -1,9 +1,10 @@
|
||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
|
Automatic-Module-Name: org.eclipse.tools.templates.freemarker
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
|
||||||
Bundle-SymbolicName: org.eclipse.tools.templates.freemarker
|
Bundle-SymbolicName: org.eclipse.tools.templates.freemarker
|
||||||
Bundle-Version: 1.1.100.qualifier
|
Bundle-Version: 1.1.200.qualifier
|
||||||
Bundle-Activator: org.eclipse.tools.templates.freemarker.internal.Activator
|
Bundle-Name: %pluginName
|
||||||
|
Bundle-Vendor: %providerName
|
||||||
Require-Bundle: org.eclipse.core.runtime,
|
Require-Bundle: org.eclipse.core.runtime,
|
||||||
org.eclipse.core.resources,
|
org.eclipse.core.resources,
|
||||||
org.freemarker;visibility:=reexport,
|
org.freemarker;visibility:=reexport,
|
||||||
|
@ -12,4 +13,4 @@ Require-Bundle: org.eclipse.core.runtime,
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||||
Bundle-ActivationPolicy: lazy
|
Bundle-ActivationPolicy: lazy
|
||||||
Export-Package: org.eclipse.tools.templates.freemarker
|
Export-Package: org.eclipse.tools.templates.freemarker
|
||||||
Bundle-Vendor: %providerName
|
Bundle-Localization: plugin
|
||||||
|
|
|
@ -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
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* 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.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
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.Path;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.tools.templates.core.IGenerator;
|
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.eclipse.tools.templates.freemarker.internal.Messages;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
|
import org.osgi.framework.FrameworkUtil;
|
||||||
|
|
||||||
import com.sun.xml.bind.v2.ContextFactory;
|
import com.sun.xml.bind.v2.ContextFactory;
|
||||||
|
|
||||||
|
@ -63,11 +64,15 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader {
|
||||||
private final String manifestPath;
|
private final String manifestPath;
|
||||||
private TemplateManifest manifest;
|
private TemplateManifest manifest;
|
||||||
private List<IFile> filesToOpen = new ArrayList<>();
|
private List<IFile> filesToOpen = new ArrayList<>();
|
||||||
|
private final String pluginId;
|
||||||
|
|
||||||
protected FMGenerator(String manifestPath) {
|
protected FMGenerator(String manifestPath) {
|
||||||
templateConfig = new Configuration(Configuration.VERSION_2_3_22);
|
templateConfig = new Configuration(Configuration.VERSION_2_3_22);
|
||||||
templateConfig.setTemplateLoader(this);
|
templateConfig.setTemplateLoader(this);
|
||||||
this.manifestPath = manifestPath;
|
this.manifestPath = manifestPath;
|
||||||
|
this.pluginId = Optional.ofNullable(FrameworkUtil.getBundle(FMGenerator.class))//
|
||||||
|
.map(b -> b.getSymbolicName())//
|
||||||
|
.orElse(FMGenerator.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Bundle getSourceBundle();
|
protected abstract Bundle getSourceBundle();
|
||||||
|
@ -107,7 +112,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader {
|
||||||
Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
|
Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
|
||||||
manifest = (TemplateManifest) unmarshaller.unmarshal(new StringReader(writer.toString()));
|
manifest = (TemplateManifest) unmarshaller.unmarshal(new StringReader(writer.toString()));
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), Messages.FMGenerator_0, e));
|
throwCoreException(Messages.FMGenerator_0, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate files
|
// generate files
|
||||||
|
@ -132,8 +137,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(),
|
throwCoreException(String.format(Messages.FMGenerator_1, fileTemplate.getSrc()), e);
|
||||||
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 template = templateConfig.getTemplate(templateFile);
|
||||||
template.process(model, out);
|
template.process(model, out);
|
||||||
} catch (IOException | TemplateException e) {
|
} catch (IOException | TemplateException e) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(),
|
throwCoreException(String.format(Messages.FMGenerator_2, templateFile), e);
|
||||||
String.format(Messages.FMGenerator_2, templateFile), e));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,8 +182,7 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(),
|
throwCoreException(String.format(Messages.FMGenerator_3, templateFile), e);
|
||||||
String.format(Messages.FMGenerator_3, templateFile), e));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,4 +236,8 @@ public abstract class FMGenerator implements IGenerator, TemplateLoader {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void throwCoreException(String message, Throwable e) throws CoreException {
|
||||||
|
throw new CoreException(new Status(IStatus.ERROR, pluginId, message, e));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue