Search in sources :

Example 11 with ResourceMap

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

the class EnrouteProjectTemplate method generateOutputs.

@Override
public ResourceMap generateOutputs(Map<String, List<Object>> params, IProgressMonitor monitor) throws Exception {
    String projectName = param(PROP_PROJECT_NAME, params);
    String pkg = param(PROP_BASE_PACKAGE_NAME, params);
    String srcDir = param(PROP_SRC_DIR, params);
    String testSrcDir = param(PROP_TEST_SRC_DIR, params);
    ResourceMap resources = new ResourceMap();
    resources.put("bnd.bnd", generateBndFile(projectName, pkg));
    generateSources(resources, projectName, pkg, srcDir, testSrcDir);
    return resources;
}
Also used : ResourceMap(org.bndtools.templating.ResourceMap)

Example 12 with ResourceMap

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

the class ReposTemplateLoaderTest method testReferTemplateDefinitions.

public void testReferTemplateDefinitions() throws Exception {
    List<Template> templates = loader.findTemplates("test3", new ProgressMonitorReporter(new NullProgressMonitor(), "")).getValue();
    assertEquals(1, templates.size());
    Template template = templates.get(0);
    Map<String, List<Object>> parameters = new HashMap<>();
    parameters.put("name", Collections.<Object>singletonList("Homer Simpson"));
    ResourceMap outputs = template.generateOutputs(parameters);
    assertEquals(1, outputs.size());
    Iterator<Entry<String, Resource>> iter = outputs.entries().iterator();
    Entry<String, Resource> entry;
    entry = iter.next();
    assertEquals("example.html", entry.getKey());
    assertEquals("My name is <i>Homer Simpson</i>!", IO.collect(entry.getValue().getContent()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProgressMonitorReporter(org.bndtools.utils.progress.ProgressMonitorReporter) HashMap(java.util.HashMap) Resource(org.bndtools.templating.Resource) Template(org.bndtools.templating.Template) ResourceMap(org.bndtools.templating.ResourceMap) Entry(java.util.Map.Entry) List(java.util.List)

Example 13 with ResourceMap

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

the class ReposTemplateLoaderTest method testExtendUnprocessedPatternAndIgnore.

public void testExtendUnprocessedPatternAndIgnore() throws Exception {
    List<Template> templates = loader.findTemplates("test4", new ProgressMonitorReporter(new NullProgressMonitor(), "")).getValue();
    assertEquals(1, templates.size());
    Template template = templates.get(0);
    Map<String, List<Object>> parameters = new HashMap<>();
    parameters.put("projectName", Collections.<Object>singletonList("org.example.foo"));
    ResourceMap outputs = template.generateOutputs(parameters);
    assertEquals(1, outputs.size());
    Entry<String, Resource> entry;
    Iterator<Entry<String, Resource>> iter = outputs.entries().iterator();
    entry = iter.next();
    assertEquals("pic.xxx", entry.getKey());
    // Check the digest of the pic to ensure it didn't get damaged by the templating engine
    DigestInputStream digestStream = new DigestInputStream(entry.getValue().getContent(), MessageDigest.getInstance("SHA-256"));
    IO.drain(digestStream);
    byte[] digest = digestStream.getMessageDigest().digest();
    assertEquals("ea5d770bc2deddb1f9a20df3ad337bdc1490ba7b35fa41c33aa4e9a534e82ada", Hex.toHexString(digest).toLowerCase());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DigestInputStream(java.security.DigestInputStream) ProgressMonitorReporter(org.bndtools.utils.progress.ProgressMonitorReporter) HashMap(java.util.HashMap) Resource(org.bndtools.templating.Resource) Template(org.bndtools.templating.Template) ResourceMap(org.bndtools.templating.ResourceMap) Entry(java.util.Map.Entry) List(java.util.List)

Example 14 with ResourceMap

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

the class GitCloneTemplate method toResourceMap.

private static ResourceMap toResourceMap(File baseDir, FileFilter filter) {
    ResourceMap result = new ResourceMap();
    File[] files = baseDir.listFiles(filter);
    if (files != null)
        for (File file : files) {
            recurse("", file, filter, result);
        }
    return result;
}
Also used : ResourceMap(org.bndtools.templating.ResourceMap) File(java.io.File)

Example 15 with ResourceMap

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

the class CapabilityBasedTemplate method getInputSources.

private synchronized ResourceMap getInputSources() throws IOException {
    File bundleFile = fetchBundle();
    _inputResources = new ResourceMap();
    try (JarInputStream in = new JarInputStream(IO.stream(bundleFile))) {
        JarEntry jarEntry = in.getNextJarEntry();
        while (jarEntry != null) {
            String entryPath = jarEntry.getName().trim();
            if (entryPath.startsWith(dir)) {
                String relativePath = entryPath.substring(dir.length());
                if (!relativePath.isEmpty()) {
                    // skip the root folder
                    Resource resource;
                    if (relativePath.endsWith("/")) {
                        // strip the trailing slash
                        relativePath.substring(0, relativePath.length());
                        resource = new FolderResource();
                    } else {
                        // cannot use IO.collect() because it closes the whole JarInputStream
                        resource = BytesResource.loadFrom(in);
                    }
                    _inputResources.put(relativePath, resource);
                }
            }
            jarEntry = in.getNextJarEntry();
        }
    }
    return _inputResources;
}
Also used : ResourceMap(org.bndtools.templating.ResourceMap) JarInputStream(java.util.jar.JarInputStream) BytesResource(org.bndtools.templating.BytesResource) Resource(org.bndtools.templating.Resource) FolderResource(org.bndtools.templating.FolderResource) FolderResource(org.bndtools.templating.FolderResource) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

ResourceMap (org.bndtools.templating.ResourceMap)22 List (java.util.List)13 StringResource (org.bndtools.templating.StringResource)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 HashMap (java.util.HashMap)12 Resource (org.bndtools.templating.Resource)10 Test (org.junit.Test)9 Template (org.bndtools.templating.Template)6 Entry (java.util.Map.Entry)5 FolderResource (org.bndtools.templating.FolderResource)5 ProgressMonitorReporter (org.bndtools.utils.progress.ProgressMonitorReporter)4 File (java.io.File)3 InputStream (java.io.InputStream)3 DigestInputStream (java.security.DigestInputStream)3 StringReader (java.io.StringReader)2 Properties (java.util.Properties)2 JarEntry (java.util.jar.JarEntry)2 JarFile (java.util.jar.JarFile)2 JarInputStream (java.util.jar.JarInputStream)2 BuiltInTemplate (org.bndtools.core.ui.wizards.shared.BuiltInTemplate)2