use of org.bndtools.templating.Template in project bndtools by bndtools.
the class RepoTemplateLabelProvider method update.
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Category) {
Category cat = (Category) element;
cell.setText(cat.getName());
cell.setImage(IMG_FOLDER);
} else if (element instanceof Template) {
Template template = (Template) element;
// Name
StyledString label = new StyledString(template.getName(), BoldStyler.INSTANCE_DEFAULT);
// Version, with all segments except qualifier in bold
Version version = template.getVersion();
if (version != null) {
label.append(" ");
label.append(String.format("%d.%d.%d", version.getMajor(), version.getMinor(), version.getMicro()), BoldStyler.INSTANCE_COUNTER);
String q = version.getQualifier();
if (q != null && !q.isEmpty())
label.append("." + q, StyledString.COUNTER_STYLER);
}
String description = template.getShortDescription();
if (description != null) {
label.append(" \u2014 [", StyledString.QUALIFIER_STYLER).append(template.getShortDescription(), StyledString.QUALIFIER_STYLER).append("]", StyledString.QUALIFIER_STYLER);
}
cell.setText(label.toString());
cell.setStyleRanges(label.getStyleRanges());
Image image = loadedImages.get(template);
if (image == null)
cell.setImage(defaultIcon);
else
cell.setImage(image);
}
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class TemplateSelectionWizardPage method setTemplate.
public void setTemplate(final Template template) {
Template old = this.selected;
this.selected = template;
propSupport.firePropertyChange(PROP_TEMPLATE, old, template);
if (template != null) {
txtDescription.setText(String.format("<form>Loading help content for template '%s'...</form>", template.getName()));
Job updateDescJob = new UpdateDescriptionJob(template, txtDescription);
updateDescJob.setSystem(true);
updateDescJob.schedule();
} else {
txtDescription.setText(NO_HELP_CONTENT);
}
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class LatestTemplateFilter method filter.
@Override
public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
Object[] result;
if (parent instanceof Category) {
// Preserves the order of names, as they were
Map<String, Template> selected = new LinkedHashMap<>();
// already sorted by the content provider.
for (Object element : elements) {
Template template = (Template) element;
Template existing = selected.get(template.getName());
if (existing == null)
// no selected template for this name -> add
selected.put(template.getName(), template);
else if (template.getVersion().compareTo(existing.getVersion()) > 0)
// existing selected template for this name is lower -> replace
selected.put(template.getName(), template);
}
result = selected.values().toArray();
} else {
result = elements;
}
return result;
}
use of org.bndtools.templating.Template in project bndtools by bndtools.
the class ReposTemplateLoaderTest method testLoad.
public void testLoad() throws Exception {
List<Template> templates = loader.findTemplates("test1", new ProgressMonitorReporter(new NullProgressMonitor(), "")).getValue();
assertEquals(1, templates.size());
Template template = templates.get(0);
assertEquals("Hello", template.getName());
assertEquals(0, template.getRanking());
assertNull(template.getCategory());
}
use of org.bndtools.templating.Template 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());
}
Aggregations