Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
[template] Show help for Github repos
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Bartlett <njbartlett@gmail.com>
  • Loading branch information
njbartlett committed Mar 26, 2016
1 parent 5d6d3f2 commit c015bc6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Expand Up @@ -236,6 +236,16 @@ public void linkActivated(HyperlinkEvent ev) {
}
}
});
txtDescription.getFormText().addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent ev) {
try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL((String) ev.getHref()));
} catch (Exception ex) {
log.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Browser open error", ex));
}
}
});
}

private class LoadTemplatesJob implements IRunnableWithProgress {
Expand Down
2 changes: 1 addition & 1 deletion bndtools.repository.base/_plugin.xml
Expand Up @@ -5,7 +5,7 @@
<extension point="bndtools.core.workspaceTemplates">
<template
name="Bndtools Bundle Hub"
description="Built-in Template – Deprecated"
description="Built-in Template – DEPRECATED"
category="Legacy Templates"
class="org.bndtools.wizards.workspace.legacy.ExtensionWorkspaceTemplate"
icon="icons/bndtools-logo-16x16.png"
Expand Down
Expand Up @@ -145,7 +145,7 @@ public URI getIcon() {

@Override
public URI getHelpContent() {
return null;
return params.helpUri;
}

private static ResourceMap toResourceMap(File baseDir, FileFilter filter) {
Expand Down
Expand Up @@ -11,5 +11,6 @@ public class GitCloneTemplateParams {
String name;
String category;
URI iconUri;
URI helpUri;

}
Expand Up @@ -22,6 +22,7 @@

import aQute.bnd.header.Attrs;
import aQute.bnd.header.Parameters;
import aQute.lib.base64.Base64;
import aQute.service.reporter.Reporter;

@Component(name = "org.bndtools.core.templating.workspace.github", property = {
Expand Down Expand Up @@ -59,7 +60,7 @@ public Promise<List<Template>> findTemplates(String type, Reporter reporter) {
final Attrs attribs = entry.getValue();

try {
GitHub gitHub = new GitHub(cache, executor);
final GitHub gitHub = new GitHub(cache, executor);
promises.add(gitHub.loadRepoDetails(repo).then(new Success<GithubRepoDetailsDTO,Template>() {
@Override
public Promise<Template> call(Promise<GithubRepoDetailsDTO> resolved) throws Exception {
Expand All @@ -77,7 +78,7 @@ public Promise<Template> call(Promise<GithubRepoDetailsDTO> resolved) throws Exc
if (name == null)
name = repo;
String branch = attribs.get("branch");
GitCloneTemplateParams params = new GitCloneTemplateParams();
final GitCloneTemplateParams params = new GitCloneTemplateParams();
params.cloneUrl = detailsDTO.clone_url;
if (branch != null)
params.branch = branch;
Expand All @@ -87,9 +88,13 @@ public Promise<Template> call(Promise<GithubRepoDetailsDTO> resolved) throws Exc
params.category = "GitHub";
params.iconUri = avatarUri;

Template template = new GitCloneTemplate(params);
return Promises.resolved(template);
if (detailsDTO.html_url != null) {
params.helpUri = createHelpUri(repo, detailsDTO.html_url);
}

return Promises.<Template> resolved(new GitCloneTemplate(params));
}

}));
} catch (Exception e) {
reporter.exception(e, "Error loading template from Github repository %s", repo);
Expand All @@ -99,4 +104,14 @@ public Promise<Template> call(Promise<GithubRepoDetailsDTO> resolved) throws Exc
return Promises.all(promises);
}

private static URI createHelpUri(String repoName, String linkUri) {
try {
String formText = String.format("<form><p>This is a GitHub template using the repository %s. See the <a href='%s'>project homepage</a> for more information.</p></form>", repoName, new URI(linkUri));
String encodedFormText = Base64.encodeBase64(formText.getBytes("UTF-8"));
return new URI("data:text/xml;base64," + encodedFormText);
} catch (Exception e) {
return null;
}
}

}

0 comments on commit c015bc6

Please sign in to comment.