From cd4024907696b3aad76dcf508dd9d23f9b391aa4 Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Tue, 29 Oct 2024 21:06:54 +0100 Subject: [PATCH] improve TemplateFragment icons - show green icon for bndtools org (ours) or 3rd-party with a specific commit SHA - show greyish icon for everything else (means 3rdParty but no Commit SHA... e.g. master branch, which means we verified it when PR was added, but it could change in the future by the author) Signed-off-by: Christoph Rueger --- .../wstemplates/FragmentTemplateEngine.java | 21 +++++++++++++++++-- .../newworkspace/NewWorkspaceWizard.java | 9 ++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/biz.aQute.bndlib/src/aQute/bnd/wstemplates/FragmentTemplateEngine.java b/biz.aQute.bndlib/src/aQute/bnd/wstemplates/FragmentTemplateEngine.java index a5b92dd8df..704d905fdf 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/wstemplates/FragmentTemplateEngine.java +++ b/biz.aQute.bndlib/src/aQute/bnd/wstemplates/FragmentTemplateEngine.java @@ -14,6 +14,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -57,6 +58,7 @@ public class FragmentTemplateEngine { private static final String DESCRIPTION = "description"; private static final String WORKSPACE_TEMPLATES = "-workspace-templates"; private static final String NAME = "name"; + private static final Pattern COMMIT_SHA = Pattern.compile("[a-f0-9]{40}$"); final static Logger log = LoggerFactory.getLogger(FragmentTemplateEngine.class); final List templates = new ArrayList<>(); @@ -90,9 +92,24 @@ public int compareTo(TemplateInfo o) { * by us". */ public boolean isOfficial() { - return id.organisation() - .equals("bndtools"); + return "bndtools".equals(id.organisation()); } + + /** + * Check if the id points to a specific commit SHA e.g. + * githuborg/myrepo/subfolder/workspace-template#b96e0a8877bad1c68cdc050d5854829253ef63bb + * In this case b96e0a8877bad1c68cdc050d5854829253ef63bb would be the + * SHA. + * + * @return true if the repoUrl points to a specific commit + * SHA. + */ + public boolean isCommitSHA() { + String ref = id.ref(); + return ref != null && COMMIT_SHA.matcher(ref) + .matches(); + } + } diff --git a/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java b/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java index a0b8d78f92..ed0a5bdb61 100644 --- a/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java +++ b/bndtools.core/src/bndtools/wizards/newworkspace/NewWorkspaceWizard.java @@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; @@ -66,8 +67,8 @@ public class NewWorkspaceWizard extends Wizard implements IImportWizard, INewWiz final FragmentTemplateEngine templates; private ScrolledFormText txtDescription; - final static Image ok = Icons.image("icons/tick.png", false); - final static Image warn = Icons.image("icons/warning_obj.gif", false); + final static Image verified = Icons.image("icons/tick.png", false); + final static Image verifiedGreyedOut = new Image(Display.getDefault(), verified, SWT.IMAGE_DISABLE); public NewWorkspaceWizard() throws Exception { setWindowTitle("Create New bnd Workspace"); @@ -240,8 +241,8 @@ public String getText(Object element) { @Override public Image getImage(Object element) { if (element instanceof TemplateInfo ti) { - return ti - .isOfficial() ? ok : warn; + boolean officialOrSHA = ti.isOfficial() || ti.isCommitSHA(); + return officialOrSHA ? verified : verifiedGreyedOut; } return super.getImage(element);