mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
New core plug-in and clean up API of generator.
Change-Id: Ifdfa47f31b34aafa07ee860e4e73201a00808677
This commit is contained in:
parent
5917bd9534
commit
896a160c7d
18 changed files with 311 additions and 23 deletions
7
bundles/org.eclipse.tools.templates.core/.classpath
Normal file
7
bundles/org.eclipse.tools.templates.core/.classpath
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
bundles/org.eclipse.tools.templates.core/.project
Normal file
28
bundles/org.eclipse.tools.templates.core/.project
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.tools.templates.core</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,7 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,12 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Templates Core
|
||||
Bundle-SymbolicName: org.eclipse.tools.templates.core
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: org.eclipse.tools.templates.core.internal.Activator
|
||||
Bundle-Vendor: Eclipse CDT
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.tools.templates.core
|
24
bundles/org.eclipse.tools.templates.core/about.html
Normal file
24
bundles/org.eclipse.tools.templates.core/about.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
|
||||
|
||||
<body lang="EN-US">
|
||||
<h2>About This Content</h2>
|
||||
|
||||
<p>June 22, 2007</p>
|
||||
<h3>License</h3>
|
||||
|
||||
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
|
||||
indicated below, the Content is provided to you under the terms and conditions of the
|
||||
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
|
||||
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
|
||||
For purposes of the EPL, "Program" will mean the Content.</p>
|
||||
|
||||
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
|
||||
being redistributed by another party ("Redistributor") and different terms and conditions may
|
||||
apply to your use of any object code in the Content. Check the Redistributor's license that was
|
||||
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
|
||||
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
|
||||
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
|
||||
|
||||
</body></html>
|
|
@ -0,0 +1,5 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
about.html
|
37
bundles/org.eclipse.tools.templates.core/pom.xml
Normal file
37
bundles/org.eclipse.tools.templates.core/pom.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.eclipse.tools.templates</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<artifactId>org.eclipse.tools.templates.core</artifactId>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-source-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>plugin-source</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>attach-source</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tools.templates.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public interface IGenerator {
|
||||
|
||||
void generate(Map<String, Object> model, IProgressMonitor monitor) throws CoreException;
|
||||
|
||||
IFile[] getFilesToOpen();
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tools.templates.core.internal;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
public class Activator implements BundleActivator {
|
||||
|
||||
private static BundleContext context;
|
||||
|
||||
static BundleContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(BundleContext bundleContext) throws Exception {
|
||||
Activator.context = bundleContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext bundleContext) throws Exception {
|
||||
Activator.context = null;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,8 @@ Bundle-Version: 1.0.0.qualifier
|
|||
Bundle-Activator: org.eclipse.tools.templates.freemarker.internal.Activator
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
org.freemarker;visibility:=reexport
|
||||
org.freemarker;visibility:=reexport,
|
||||
org.eclipse.tools.templates.core;bundle-version="1.0.0";visibility:=reexport
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.tools.templates.freemarker
|
||||
|
|
|
@ -41,7 +41,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
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 freemarker.cache.TemplateLoader;
|
||||
|
@ -49,32 +51,30 @@ import freemarker.template.Configuration;
|
|||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
||||
public abstract class FMGenerator implements TemplateLoader {
|
||||
public abstract class FMGenerator implements IGenerator, TemplateLoader {
|
||||
|
||||
private final Configuration templateConfig;
|
||||
private String manifestPath;
|
||||
private final String manifestPath;
|
||||
private TemplateManifest manifest;
|
||||
private List<IFile> filesToOpen = new ArrayList<>();
|
||||
|
||||
protected FMGenerator() {
|
||||
protected FMGenerator(String manifestPath) {
|
||||
templateConfig = new Configuration(Configuration.VERSION_2_3_22);
|
||||
templateConfig.setTemplateLoader(this);
|
||||
}
|
||||
|
||||
public abstract Bundle getSourceBundle();
|
||||
|
||||
public void setTemplateManifestPath(String manifestPath) {
|
||||
this.manifestPath = manifestPath;
|
||||
}
|
||||
|
||||
public TemplateManifest getManifest() {
|
||||
return manifest;
|
||||
}
|
||||
|
||||
protected abstract Bundle getSourceBundle();
|
||||
|
||||
protected Class<? extends TemplateManifest> getManifestClass() {
|
||||
return TemplateManifest.class;
|
||||
}
|
||||
|
||||
protected TemplateManifest getManifest() {
|
||||
return manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Map<String, Object> model, IProgressMonitor monitor) throws CoreException {
|
||||
// If no manifest, just return
|
||||
if (manifestPath == null) {
|
||||
|
@ -90,7 +90,7 @@ public abstract class FMGenerator implements 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(), "Loading template manifest", e));
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), Messages.FMGenerator_0, e));
|
||||
}
|
||||
|
||||
// generate files
|
||||
|
@ -116,7 +116,7 @@ public abstract class FMGenerator implements TemplateLoader {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(),
|
||||
"Reading file " + fileTemplate.getSrc(), e));
|
||||
String.format(Messages.FMGenerator_1, fileTemplate.getSrc()), e));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,17 +138,17 @@ public abstract class FMGenerator implements TemplateLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public void loadFile(String templateFile, Object model, Writer out) throws CoreException {
|
||||
protected void loadFile(String templateFile, Map<String, Object> model, Writer out) throws CoreException {
|
||||
try {
|
||||
Template template = templateConfig.getTemplate(templateFile);
|
||||
template.process(model, out);
|
||||
} catch (IOException | TemplateException e) {
|
||||
throw new CoreException(
|
||||
new Status(IStatus.ERROR, Activator.getId(), "Processing template " + templateFile, e));
|
||||
new Status(IStatus.ERROR, Activator.getId(), String.format(Messages.FMGenerator_2, templateFile), e));
|
||||
}
|
||||
}
|
||||
|
||||
public void generateFile(String templateFile, final Object model, final IFile outputFile, IProgressMonitor monitor)
|
||||
public void generateFile(String templateFile, Map<String, Object> model, final IFile outputFile, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
try (StringWriter writer = new StringWriter()) {
|
||||
loadFile(templateFile, model, writer);
|
||||
|
@ -162,11 +162,11 @@ public abstract class FMGenerator implements TemplateLoader {
|
|||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Generating file " + templateFile, e));
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), String.format(Messages.FMGenerator_3, templateFile), e));
|
||||
}
|
||||
}
|
||||
|
||||
public static void createParent(IResource child, IProgressMonitor monitor) throws CoreException {
|
||||
protected static void createParent(IResource child, IProgressMonitor monitor) throws CoreException {
|
||||
if (child == null)
|
||||
return;
|
||||
|
||||
|
@ -180,9 +180,10 @@ public abstract class FMGenerator implements TemplateLoader {
|
|||
parent.create(true, true, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFile[] getFilesToOpen() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
// TODO
|
||||
return new IFile[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,10 @@ public abstract class FMProjectGenerator extends FMGenerator {
|
|||
private IProject[] referencedProjects;
|
||||
|
||||
private IProject project;
|
||||
|
||||
public FMProjectGenerator(String manifestPath) {
|
||||
super(manifestPath);
|
||||
}
|
||||
|
||||
protected abstract void initProjectDescription(IProjectDescription description) throws CoreException;
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tools.templates.freemarker.internal;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.tools.templates.freemarker.internal.messages"; //$NON-NLS-1$
|
||||
public static String FMGenerator_0;
|
||||
public static String FMGenerator_1;
|
||||
public static String FMGenerator_2;
|
||||
public static String FMGenerator_3;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
FMGenerator_0=Loading template manifest
|
||||
FMGenerator_1=Reading file %s
|
||||
FMGenerator_2=Processing template %s
|
||||
FMGenerator_3=Generating file %s
|
|
@ -7,7 +7,8 @@ Bundle-Activator: org.eclipse.tools.templates.ui.internal.Activator
|
|||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.ui.ide,
|
||||
org.eclipse.core.resources
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.tools.templates.core;bundle-version="1.0.0";visibility:=reexport
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.tools.templates.ui
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.tools.templates.ui.internal.Template;
|
|||
import org.eclipse.tools.templates.ui.internal.TemplateExtension;
|
||||
import org.eclipse.tools.templates.ui.internal.TemplateTable;
|
||||
import org.eclipse.ui.IWorkbenchWizard;
|
||||
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
|
||||
|
||||
public class TemplateSelectionPage extends WizardPage {
|
||||
|
||||
|
@ -99,6 +100,8 @@ public class TemplateSelectionPage extends WizardPage {
|
|||
if (template != null) {
|
||||
try {
|
||||
IWorkbenchWizard nextWizard = template.getWizard();
|
||||
BasicNewResourceWizard oldWizard = (BasicNewResourceWizard) getWizard();
|
||||
nextWizard.init(oldWizard.getWorkbench(), oldWizard.getSelection());
|
||||
nextWizard.addPages();
|
||||
return nextWizard.getPages()[0];
|
||||
} catch (CoreException e) {
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tools.templates.ui;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.tools.templates.core.IGenerator;
|
||||
import org.eclipse.tools.templates.ui.internal.Activator;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
|
||||
|
||||
public abstract class TemplateWizard extends BasicNewResourceWizard {
|
||||
|
||||
protected abstract IGenerator getGenerator();
|
||||
|
||||
protected void populateModel(Map<String, Object> model) {
|
||||
// nothing by default
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish() {
|
||||
IGenerator generator = getGenerator();
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
populateModel(model);
|
||||
|
||||
try {
|
||||
getContainer().run(true, true, new WorkspaceModifyOperation() {
|
||||
@Override
|
||||
protected void execute(IProgressMonitor monitor)
|
||||
throws CoreException, InvocationTargetException, InterruptedException {
|
||||
monitor.beginTask("Generating project", 1); //$NON-NLS-1$
|
||||
generator.generate(model, monitor);
|
||||
monitor.done();
|
||||
getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
for (IFile file : generator.getFilesToOpen()) {
|
||||
IDE.openEditor(activePage, file);
|
||||
}
|
||||
} catch (PartInitException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISchedulingRule getRule() {
|
||||
return ResourcesPlugin.getWorkspace().getRoot();
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
1
pom.xml
1
pom.xml
|
@ -60,6 +60,7 @@
|
|||
</repositories>
|
||||
|
||||
<modules>
|
||||
<module>bundles/org.eclipse.tools.templates.core</module>
|
||||
<module>bundles/org.eclipse.tools.templates.freemarker</module>
|
||||
<module>bundles/org.eclipse.tools.templates.ui</module>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue