diff --git a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/CachingMarketplaceService.java b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/CachingMarketplaceService.java index 42b09352..f67d3997 100644 --- a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/CachingMarketplaceService.java +++ b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/CachingMarketplaceService.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -284,6 +285,11 @@ public ISearchResult doSearch(IProgressMonitor monitor) throws CoreException { }); } + public ISearchResult tagged(List tags, IProgressMonitor monitor) throws CoreException { + String combinedTags = tags.stream().collect(Collectors.joining(",")); //$NON-NLS-1$ + return tagged(combinedTags, monitor); + } + private ISearchResult performSearch(IProgressMonitor monitor, String key, SearchOperation searchOperation) throws CoreException { ISearchResult result = null; diff --git a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/DefaultMarketplaceService.java b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/DefaultMarketplaceService.java index dc8a4eee..2bd66717 100644 --- a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/DefaultMarketplaceService.java +++ b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/internal/mpc/core/service/DefaultMarketplaceService.java @@ -27,6 +27,7 @@ import java.util.ListIterator; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; @@ -364,7 +365,7 @@ public List getNodes(Collection nodes, IProgressMonitor Messages.DefaultMarketplaceService_nodeNotFound, query); if (missingNodes == null) { missingNodes = new MultiStatus(MarketplaceClientCore.BUNDLE_ID, 0, - "Some entries could not be found on the Marketplace", null); + "Some entries could not be found on the Marketplace", null); //$NON-NLS-1$ } missingNodes.add(missingNodeDetailStatus); } @@ -535,6 +536,11 @@ public SearchResult tagged(String tag, IProgressMonitor monitor) throws CoreExce return processSearchRequest(API_FREETAGGING_URI + URLUtil.urlEncode(tag) + '/' + API_URI_SUFFIX, tag, monitor); } + public SearchResult tagged(List tags, IProgressMonitor monitor) throws CoreException { + String combinedTags = tags.stream().collect(Collectors.joining(",")); //$NON-NLS-1$ + return tagged(combinedTags, monitor); + } + public SearchResult featured(IProgressMonitor monitor) throws CoreException { return featured(null, null, monitor); } diff --git a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/mpc/core/service/IMarketplaceService.java b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/mpc/core/service/IMarketplaceService.java index 37285e23..f86a00fc 100644 --- a/org.eclipse.epp.mpc.core/src/org/eclipse/epp/mpc/core/service/IMarketplaceService.java +++ b/org.eclipse.epp.mpc.core/src/org/eclipse/epp/mpc/core/service/IMarketplaceService.java @@ -118,6 +118,16 @@ ISearchResult search(IMarket market, ICategory category, String queryText, IProg */ ISearchResult tagged(String tag, IProgressMonitor monitor) throws CoreException; + /** + * Find nodes in the marketplace tagged with the given tags. Only nodes having an exact (case-insensitie) match for + * at least one of the given tags will be returned. + * + * @param tags + * free-form tags + * @return the search result + */ + ISearchResult tagged(List tags, IProgressMonitor monitor) throws CoreException; + /** * Find featured nodes in the marketplace * diff --git a/org.eclipse.epp.mpc.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.epp.mpc.ui/.settings/org.eclipse.jdt.core.prefs index c5d2671b..8b823fb7 100644 --- a/org.eclipse.epp.mpc.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.epp.mpc.ui/.settings/org.eclipse.jdt.core.prefs @@ -180,9 +180,12 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/DiscoverFileSupportJob.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/DiscoverFileSupportJob.java index 51676c96..099a1b78 100644 --- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/DiscoverFileSupportJob.java +++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/DiscoverFileSupportJob.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Red Hat Inc. + * Copyright (c) 2017 Red Hat Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,10 +7,16 @@ * * Contributors: * Mickael Istria (Red Hat Inc.) - initial implementation + * Lucas Bullen (Red Hat Inc.) - Bug 517818: search IDE extensions by all subname's of the file *******************************************************************************/ package org.eclipse.epp.internal.mpc.ui.discovery; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -22,6 +28,7 @@ import org.eclipse.epp.internal.mpc.ui.Messages; import org.eclipse.epp.mpc.core.model.INode; import org.eclipse.epp.mpc.core.model.ISearchResult; +import org.eclipse.epp.mpc.core.model.ITag; import org.eclipse.epp.mpc.core.service.IMarketplaceService; import org.eclipse.epp.mpc.core.service.IMarketplaceServiceLocator; import org.eclipse.osgi.util.NLS; @@ -56,7 +63,8 @@ protected IStatus run(IProgressMonitor monitor) { ServiceReference locatorReference = bundleContext .getServiceReference(IMarketplaceServiceLocator.class); IMarketplaceServiceLocator locator = bundleContext.getService(locatorReference); - IMarketplaceService marketplaceService = locator.getDefaultMarketplaceService(); + IMarketplaceService marketplaceService = locator + .getDefaultMarketplaceService(); try { return run(marketplaceService, monitor); } finally { @@ -65,12 +73,17 @@ protected IStatus run(IProgressMonitor monitor) { } private IStatus run(IMarketplaceService marketplaceService, IProgressMonitor monitor) { - final String fileExtension = getFileExtension(fileName); - String fileExtensionTag = getFileExtensionTag(fileExtension); + final List fileExtensions = getFileExtensions(fileName); + final List fileExtensionTags = new ArrayList(); + + for (String string : fileExtensions) { + fileExtensionTags.add(getFileExtensionTag(string)); + } + final List nodes; try { - ISearchResult searchResult = marketplaceService.tagged(fileExtensionTag, monitor); - nodes = searchResult.getNodes(); + ISearchResult searchResult = marketplaceService.tagged(fileExtensionTags, monitor); + nodes = orderNodesByTagSubExtensionCount(searchResult.getNodes(), fileExtensionTags); } catch (CoreException ex) { IStatus status = new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, NLS.bind(Messages.DiscoverFileSupportJob_discoveryFailed, getFileExtensionLabel(fileName)), ex); @@ -93,14 +106,79 @@ private static String getFileExtensionTag(final String fileExtension) { return "fileExtension_" + fileExtension;//$NON-NLS-1$ } + /** + * Sorts the given list of tags by number of sub extension dividers(.) and uses the sorted list to return an ordered + * list of the nodes by first occurrence of highest sub extension tag in fileExtensionTags. + * + * @param nodes + * @param fileExtensionTags + * @return nodes ordered by first occurrence of highest sub extension count found in fileExtensionTags + */ + private static List orderNodesByTagSubExtensionCount(List nodes, + List fileExtensionTags) { + + Collections.sort(fileExtensionTags, new Comparator() { + public int compare(String s1, String s2) { + return (s2.length() - s2.replace(".", "").length()) - (s1.length() - s1.replace(".", "").length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + }); + + Map> nodesByTags = new HashMap>(); + for (INode iNode : nodes) { + for (ITag nodeTag : iNode.getTags().getTags()) { + boolean foundTag = false; + for (String tag : fileExtensionTags) { + if (nodeTag.getName().equals(tag)) { + if (nodesByTags.containsKey(tag)) { + nodesByTags.get(tag).add(iNode); + } else { + List newNodeList = new ArrayList(); + newNodeList.add(iNode); + nodesByTags.put(tag, newNodeList); + } + foundTag = true; + break; + } + } + if (foundTag) { + break; + } + } + } + List ordered = new ArrayList(); + for (String tag : fileExtensionTags) { + if (nodesByTags.containsKey(tag)) { + ordered.addAll(nodesByTags.get(tag)); + } + } + return nodes; + } + + /** + * @param fileName + * full name of the file including all extensions + * @return The last segment of the file's extension. eg "file.tar.gz" returns "gz" + */ static String getFileExtensionLabel(String fileName) { - String fileExtension = getFileExtension(fileName); - return fileExtension.length() == fileName.length() ? fileName - : "*." + fileExtension; //$NON-NLS-1$ + return fileName.indexOf('.') == -1 ? fileName + : '*' + fileName.substring(fileName.lastIndexOf('.'), fileName.length()); } - static String getFileExtension(String fileName) { - String[] split = fileName.split("\\."); //$NON-NLS-1$ - return split[split.length - 1]; + /** + * @param fileName + * full name of the file including all extensions + * @return All sub-strings of the fileName in longest to shortest order split by periods moving from left to right. + * eg "file.tar.gz" returns ["file.tar.gz", "tar.gz", "gz"] + */ + static List getFileExtensions(String fileName) { + List extensions = new ArrayList(); + while (fileName.length() > 0) { + extensions.add(fileName); + if (fileName.indexOf('.') == -1) { + break; + } + fileName = fileName.substring(fileName.indexOf('.') + 1, fileName.length()); + } + return extensions; } } \ No newline at end of file diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/ShowFileSupportProposalsJob.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/ShowFileSupportProposalsJob.java index e5e09c2f..cd598b47 100644 --- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/ShowFileSupportProposalsJob.java +++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/discovery/ShowFileSupportProposalsJob.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Red Hat Inc. + * Copyright (c) 2017 Red Hat Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Mickael Istria (Red Hat Inc.) - initial implementation + * Lucas Bullen (Red Hat Inc.) - Bug 517818: retain same functionality post fix *******************************************************************************/ package org.eclipse.epp.internal.mpc.ui.discovery; @@ -67,8 +68,9 @@ public IStatus runInUIThread(IProgressMonitor monitor) { IMarketplaceClientConfiguration config = marketplaceClientService.newConfiguration(); marketplaceClientService.open(config, new LinkedHashSet(nodes)); } else if (dialog.isAssociateToExtension()) { - String fileExtension = DiscoverFileSupportJob.getFileExtension(fileName); - IFileEditorMapping newMapping = createDefaultDescriptorMapping(fileExtension); + List fileExtensions = DiscoverFileSupportJob.getFileExtensions(fileName); + IFileEditorMapping newMapping = createDefaultDescriptorMapping( + fileExtensions.get(fileExtensions.size() - 1)); addEditorMapping(newMapping); } return Status.OK_STATUS;