use of org.bndtools.templating.FolderResource in project bndtools by bndtools.
the class MustacheTemplateEngineTest method testNoProcessDefaultPattern.
@Test
public void testNoProcessDefaultPattern() 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}};"));
input.put("{{srcDir}}/{{packageDir}}/package-info.jpg", 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(4, output.size());
assertEquals("package org.example.foo;", IO.collect(output.get("src/org/example/foo/package-info.java").getContent()));
assertEquals("package {{packageName}};", IO.collect(output.get("src/org/example/foo/package-info.jpg").getContent()));
}
use of org.bndtools.templating.FolderResource in project bndtools by bndtools.
the class MustacheTemplateEngineTest method testNoProcessExtendedPattern.
@Test
public void testNoProcessExtendedPattern() throws Exception {
MustacheTemplateEngine engine = new MustacheTemplateEngine();
ResourceMap input = new ResourceMap();
input.put("_template.properties", new StringResource("process.before=!*.java"));
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 {{packageName}};", IO.collect(output.get("src/org/example/foo/package-info.java").getContent()));
}
use of org.bndtools.templating.FolderResource in project bndtools by bndtools.
the class GitCloneTemplate method recurse.
private static void recurse(String prefix, File file, FileFilter filter, ResourceMap resourceMap) {
if (file.isDirectory()) {
String path = prefix + file.getName() + "/";
resourceMap.put(path, new FolderResource());
File[] children = file.listFiles(filter);
for (File child : children) {
recurse(path, child, filter, resourceMap);
}
} else {
String path = prefix + file.getName();
// TODO: WTF is the encoding?
resourceMap.put(path, new FileResource(file, "UTF-8"));
}
}
use of org.bndtools.templating.FolderResource 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;
}
use of org.bndtools.templating.FolderResource 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"));
}
Aggregations