Search in sources :

Example 11 with StringResource

use of org.bndtools.templating.StringResource in project bndtools by bndtools.

the class MustacheTemplateEngineTest method testIgnore.

@Test
public void testIgnore() throws Exception {
    MustacheTemplateEngine engine = new MustacheTemplateEngine();
    ResourceMap input = new ResourceMap();
    input.put("_template.properties", new StringResource("ignore=*/donotcopy.*"));
    input.put("{{srcDir}}/", new FolderResource());
    input.put("{{srcDir}}/{{packageDir}}/", new FolderResource());
    input.put("{{srcDir}}/{{packageDir}}/package-info.java", new StringResource("package {{packageName}};"));
    input.put("{{srcDir}}/{{packageDir}}/donotcopy.txt", new StringResource(""));
    Map<String, List<Object>> params = new HashMap<>();
    params.put("srcDir", Collections.<Object>singletonList("src"));
    params.put("packageDir", Collections.<Object>singletonList("org/example/foo"));
    params.put("packageName", Collections.<Object>singletonList("org.example.foo"));
    ResourceMap output = engine.generateOutputs(input, params, new NullProgressMonitor());
    assertEquals(3, output.size());
    assertEquals("package org.example.foo;", IO.collect(output.get("src/org/example/foo/package-info.java").getContent()));
    assertNull(output.get("src/org/example/foo/donotcopy.txt"));
}
Also used : ResourceMap(org.bndtools.templating.ResourceMap) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) StringResource(org.bndtools.templating.StringResource) HashMap(java.util.HashMap) FolderResource(org.bndtools.templating.FolderResource) List(java.util.List) Test(org.junit.Test)

Example 12 with StringResource

use of org.bndtools.templating.StringResource in project bndtools by bndtools.

the class MustacheTemplateEngineTest method testBasic.

@Test
public void testBasic() throws Exception {
    MustacheTemplateEngine engine = new MustacheTemplateEngine();
    ResourceMap input = new ResourceMap();
    input.put("{{srcDir}}/", new FolderResource());
    input.put("{{srcDir}}/{{packageDir}}/", new FolderResource());
    input.put("{{srcDir}}/{{packageDir}}/package-info.java", new StringResource("package {{packageName}};"));
    Map<String, List<Object>> params = new HashMap<>();
    params.put("srcDir", Collections.<Object>singletonList("src"));
    params.put("packageDir", Collections.<Object>singletonList("org/example/foo"));
    params.put("packageName", Collections.<Object>singletonList("org.example.foo"));
    ResourceMap output = engine.generateOutputs(input, params, new NullProgressMonitor());
    assertEquals(3, output.size());
    assertEquals("package org.example.foo;", IO.collect(output.get("src/org/example/foo/package-info.java").getContent()));
}
Also used : ResourceMap(org.bndtools.templating.ResourceMap) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) StringResource(org.bndtools.templating.StringResource) HashMap(java.util.HashMap) FolderResource(org.bndtools.templating.FolderResource) List(java.util.List) Test(org.junit.Test)

Example 13 with StringResource

use of org.bndtools.templating.StringResource in project bndtools by bndtools.

the class MustacheTemplateEngineTest method testAlternativeDelimiters2.

@Test
public void testAlternativeDelimiters2() throws Exception {
    MustacheTemplateEngine engine = new MustacheTemplateEngine();
    ResourceMap input = new ResourceMap();
    input.put("_template.properties", new StringResource("leftDelim=_\nrightDelim=_"));
    input.put("readme.txt", new StringResource("Unprocessed: {{packageName}}. Processed: _packageName_"));
    Map<String, List<Object>> params = new HashMap<>();
    params.put("packageName", Collections.<Object>singletonList("org.example.foo"));
    ResourceMap output = engine.generateOutputs(input, params, new NullProgressMonitor());
    assertEquals(1, output.size());
    assertEquals("Unprocessed: {{packageName}}. Processed: org.example.foo", IO.collect(output.get("readme.txt").getContent()));
}
Also used : ResourceMap(org.bndtools.templating.ResourceMap) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) StringResource(org.bndtools.templating.StringResource) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Example 14 with StringResource

use of org.bndtools.templating.StringResource in project bndtools by bndtools.

the class NewBndProjectWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
    super.init(workbench, currentSelection);
    BuiltInTemplate baseTemplate = new BuiltInTemplate(EMPTY_TEMPLATE_NAME, DEFAULT_TEMPLATE_ENGINE);
    //$NON-NLS-1$
    baseTemplate.addInputResource(Project.BNDFILE, new StringResource(""));
    //$NON-NLS-1$
    baseTemplate.setHelpPath("docs/empty_project.xml");
    templatePage = new ProjectTemplateSelectionWizardPage("projectTemplateSelection", "project", baseTemplate);
    templatePage.setTitle("Select Project Template");
    paramsPage = new TemplateParamsWizardPage(ProjectTemplateParam.valueStrings());
    templatePage.addPropertyChangeListener(TemplateSelectionWizardPage.PROP_TEMPLATE, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Template template = templatePage.getTemplate();
            pageOne.setTemplate(template);
            paramsPage.setTemplate(template);
        }
    });
    setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(Plugin.getDefault().getBundle().getEntry("icons/bndtools-wizban.png")));
}
Also used : BuiltInTemplate(org.bndtools.core.ui.wizards.shared.BuiltInTemplate) StringResource(org.bndtools.templating.StringResource) TemplateParamsWizardPage(org.bndtools.core.ui.wizards.shared.TemplateParamsWizardPage) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) BuiltInTemplate(org.bndtools.core.ui.wizards.shared.BuiltInTemplate) Template(org.bndtools.templating.Template)

Example 15 with StringResource

use of org.bndtools.templating.StringResource in project bndtools by bndtools.

the class BndRunFileWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    this.workbench = workbench;
    mainPage = new WizardNewFileCreationPage("newFilePage", selection) {

        @Override
        protected InputStream getInitialContents() {
            try {
                return getTemplateContents(getFileName());
            } catch (Exception e) {
                throw new WrappingException(e);
            }
        }
    };
    mainPage.setTitle("New Bnd Run Descriptor");
    //$NON-NLS-1$
    mainPage.setFileExtension("bndrun");
    mainPage.setAllowExistingResources(false);
    BuiltInTemplate baseTemplate = new BuiltInTemplate("«Empty»", DEFAULT_TEMPLATE_ENGINE);
    baseTemplate.addInputResource("$fileName$", new StringResource(""));
    baseTemplate.setHelpPath("docs/empty_run.xml");
    templatePage = new TemplateSelectionWizardPage("runTemplateSelection", "bndrun", baseTemplate);
    templatePage.setTitle("Select Run Descriptor Template");
    paramsPage = new TemplateParamsWizardPage(PROPS);
    templatePage.addPropertyChangeListener(TemplateSelectionWizardPage.PROP_TEMPLATE, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            paramsPage.setTemplate(templatePage.getTemplate());
        }
    });
}
Also used : BuiltInTemplate(org.bndtools.core.ui.wizards.shared.BuiltInTemplate) StringResource(org.bndtools.templating.StringResource) TemplateSelectionWizardPage(org.bndtools.core.ui.wizards.shared.TemplateSelectionWizardPage) TemplateParamsWizardPage(org.bndtools.core.ui.wizards.shared.TemplateParamsWizardPage) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) InputStream(java.io.InputStream) WizardNewFileCreationPage(org.eclipse.ui.dialogs.WizardNewFileCreationPage) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

StringResource (org.bndtools.templating.StringResource)15 ResourceMap (org.bndtools.templating.ResourceMap)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)7 List (java.util.List)7 FolderResource (org.bndtools.templating.FolderResource)4 StringReader (java.io.StringReader)3 Properties (java.util.Properties)3 Resource (org.bndtools.templating.Resource)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 Enumeration (java.util.Enumeration)2 BuiltInTemplate (org.bndtools.core.ui.wizards.shared.BuiltInTemplate)2 TemplateParamsWizardPage (org.bndtools.core.ui.wizards.shared.TemplateParamsWizardPage)2 STGroup (org.stringtemplate.v4.STGroup)2 BndEditModel (aQute.bnd.build.model.BndEditModel)1 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)1 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 Attrs (aQute.bnd.header.Attrs)1