diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IIndex.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IIndex.java index 6f693638e..def8ebd77 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IIndex.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IIndex.java @@ -13,11 +13,13 @@ import java.io.File; import java.util.Collection; +import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.m2e.core.embedder.ArtifactKey; + /** * @author igor */ @@ -41,9 +43,24 @@ public interface IIndex { * like SEARCH_ARTIFACT but will only return artifacts with packaging == pom */ public static final String SEARCH_PARENTS = "parents"; //$NON-NLS-1$ - + // search classifiers +// public enum SearchClassifiers { +// JARS, +// +// JAVADOCS, +// +// SOURCES, +// +// TESTS +// } +// +// public Set ALL_CLASSIFIERS = new HashSet(Arrays.asList(SearchClassifiers +// .values())); + + // + public static final int SEARCH_JARS = 1 << 0; public static final int SEARCH_JAVADOCS = 1 << 1; @@ -55,11 +72,11 @@ public interface IIndex { public static final int SEARCH_ALL = 15; // availability flags - + public static final int PRESENT = 1; - + public static final int NOT_PRESENT = 0; - + public static final int NOT_AVAILABLE = 2; // index queries @@ -68,7 +85,33 @@ public interface IIndex { public IndexedArtifactFile identify(File file) throws CoreException; - public Collection find(String groupId, String artifactId, String version, - String packaging) throws CoreException; - + /** + * Performs a search for artifacts with given parameters. + * + * @param groupId + * @param artifactId + * @param version + * @param packaging + * @return + * @throws CoreException + */ + public Collection find(String groupId, String artifactId, String version, String packaging) + throws CoreException; + + /** + * Convenience method to search in all indexes enabled for repositories defined in settings.xml. This method always + * performs "scored" search. + */ + public Map search(String term, String searchType) throws CoreException; + + /** + * Convenience method to search in all indexes enabled for repositories defined in settings.xml. This method always + * performs "scored" search. + * + * @param term - search term + * @param searchType - query type. Should be one of the SEARCH_* values. + * @param classifier - the type of classifiers to search for, SEARCH_ALL, SEARCH_JAVADOCS, SEARCH_SOURCES, + * SEARCH_TESTS + */ + public Map search(String term, String searchType, int classifier) throws CoreException; } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IndexManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IndexManager.java index 381f1d612..0dbf701a3 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IndexManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/index/IndexManager.java @@ -11,31 +11,23 @@ package org.eclipse.m2e.core.index; -import java.io.File; -import java.util.Map; - import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; -import org.apache.lucene.search.Query; - -import org.apache.maven.index.Field; -import org.apache.maven.index.SearchType; - public interface IndexManager { - public static final int MIN_CLASS_QUERY_LENGTH = 6; - // well-known indexes - public static final String LOCAL_INDEX = "local"; //$NON-NLS-1$ + String LOCAL_INDEX = "local"; //$NON-NLS-1$ - public static final String WORKSPACE_INDEX = "workspace"; //$NON-NLS-1$ + String WORKSPACE_INDEX = "workspace"; //$NON-NLS-1$ - public abstract IMutableIndex getWorkspaceIndex(); + // - public abstract IMutableIndex getLocalIndex(); + IMutableIndex getWorkspaceIndex(); + + IMutableIndex getLocalIndex(); /** * For Maven projects, returns index of all repositories configured for the project. Index includes repositories @@ -43,38 +35,19 @@ public interface IndexManager { * project is null or is not a maven project, returns index that includes repositories defined in profiles enabled by * default in settings.xml. */ - public abstract IIndex getIndex(IProject project) throws CoreException; - - /** - * Convenience method to search in all indexes enabled for repositories defined in settings.xml - */ - public abstract Map search(String term, String searchType) throws CoreException; + IIndex getIndex(IProject project) throws CoreException; /** - * Convenience method to search in all indexes enabled for repositories defined in settings.xml + * Returns index aggregating all indexes enabled for repositories defined in settings.xml * - * @param term - search term - * @param searchType - query type. Should be one of the SEARCH_* values. - * @param classifier - the type of classifiers to search for, SEARCH_ALL, SEARCH_JAVADOCS, SEARCH_SOURCES, - * SEARCH_TESTS + * @return + * @throws CoreException */ - public abstract Map search(String term, String type, int classifier) throws CoreException; + IIndex getAllIndexes() throws CoreException; - /** - * Convenience method to search in all indexes enabled for repositories defined in settings.xml - */ - public abstract IndexedArtifactFile identify(File file) throws CoreException; + // - /** - * Method to construct Lucene Queries without need to actually know the structure and details (field names, analyze - * details, etc) of the underlying index. Also, using this methods makes you "future proof". Naturally, at caller - * level you can still combine these queries using BooleanQuery to suit your needs. - * - * @param field - * @param query - * @param type - * @return - */ - public abstract Query constructQuery(Field field, String query, SearchType type); + void removeIndexListener(IndexListener listener); + void addIndexListener(IndexListener listener); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/CompositeIndex.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/CompositeIndex.java index 12bbe160e..81b1924c1 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/CompositeIndex.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/CompositeIndex.java @@ -13,8 +13,10 @@ import java.io.File; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.CoreException; @@ -69,11 +71,33 @@ public Collection find(String groupId, String artifactId, Strin Set result = new LinkedHashSet(); for(IIndex index : indexes) { Collection findResults = index.find(groupId, artifactId, version, packaging); - if(findResults != null){ + if(findResults != null) { result.addAll(findResults); } } return result; } + public Map search(String term, String searchType) throws CoreException { + Map result = new HashMap(); + for(IIndex index : indexes) { + Map iresult = index.search(term, searchType); + if(iresult != null) { + result.putAll(iresult); + } + } + return result; + } + + public Map search(String term, String searchType, int classifier) throws CoreException { + Map result = new HashMap(); + for(IIndex index : indexes) { + Map iresult = index.search(term, searchType, classifier); + if(iresult != null) { + result.putAll(iresult); + } + } + return result; + } + } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndex.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndex.java index cfcd6c8b9..a3936289c 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndex.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndex.java @@ -13,6 +13,7 @@ import java.io.File; import java.util.Collection; +import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -124,8 +125,8 @@ public void scheduleIndexUpdate(boolean force) { indexManager.scheduleIndexUpdate(repository, force); } - public IndexedArtifactGroup[] getRootGroups() throws CoreException { - return indexManager.getRootGroups(repository); + public IndexedArtifactGroup[] getRootIndexedArtifactGroups() throws CoreException { + return indexManager.getRootIndexedArtifactGroups(repository); } public boolean isUpdating() { @@ -143,4 +144,12 @@ public boolean isEnabled() { public void setIndexDetails(String details) throws CoreException { indexManager.setIndexDetails(repository, details, null/*async*/); } + + public Map search(String term, String searchType) throws CoreException { + return indexManager.search(getRepository(), term, searchType); + } + + public Map search(String term, String searchType, int classifier) throws CoreException { + return indexManager.search(getRepository(), term, searchType, classifier); + } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndexManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndexManager.java index c047b7e29..cffd04c02 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndexManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/NexusIndexManager.java @@ -108,6 +108,8 @@ */ public class NexusIndexManager implements IndexManager, IMavenProjectChangedListener, IRepositoryIndexer { + public static final int MIN_CLASS_QUERY_LENGTH = 6; + /** * Lazy instantiated nexus indexer instance. */ @@ -274,6 +276,16 @@ protected IndexedArtifactFile identify(IRepository repository, File file) throws } } + /** + * Method to construct Lucene Queries without need to actually know the structure and details (field names, analyze + * details, etc) of the underlying index. Also, using this methods makes you "future proof". Naturally, at caller + * level you can still combine these queries using BooleanQuery to suit your needs. + * + * @param field + * @param query + * @param type + * @return + */ public Query constructQuery(Field field, String query, SearchType type) { return getIndexer().constructQuery(field, query, type); } @@ -626,7 +638,23 @@ public void run(IProgressMonitor monitor) throws CoreException { } } - protected IndexedArtifactGroup[] getRootGroups(IRepository repository) throws CoreException { + protected Set getRootGroups(IRepository repository) throws CoreException { + synchronized(getIndexLock(repository)) { + IndexingContext context = getIndexingContext(repository); + if(context != null) { + try { + Set rootGroups = context.getRootGroups(); + return rootGroups; + } catch(IOException ex) { + throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, // + NLS.bind(Messages.NexusIndexManager_error_root_grp, repository.toString()), ex)); + } + } + return Collections.emptySet(); + } + } + + protected IndexedArtifactGroup[] getRootIndexedArtifactGroups(IRepository repository) throws CoreException { synchronized(getIndexLock(repository)) { IndexingContext context = getIndexingContext(repository); if(context != null) { @@ -762,6 +790,25 @@ public IIndex getIndex(IProject project) { return new CompositeIndex(indexes); } + public IIndex getAllIndexes() { + ArrayList indexes = new ArrayList(); + indexes.add(getWorkspaceIndex()); + indexes.add(getLocalIndex()); + + for(IMavenProjectFacade facade : projectManager.getProjects()) { + LinkedHashSet repositories = new LinkedHashSet(); + repositories.addAll(facade.getArtifactRepositoryRefs()); + repositories.addAll(facade.getPluginArtifactRepositoryRefs()); + + for(ArtifactRepositoryRef repositoryRef : repositories) { + IRepository repository = repositoryRegistry.getRepository(repositoryRef); + indexes.add(getIndex(repository)); + } + } + + return new CompositeIndex(indexes); + } + public NexusIndex getIndex(IRepository repository) { String details = getIndexDetails(repository); return new NexusIndex(this, repository, details); @@ -807,7 +854,8 @@ public void repositoryAdded(IRepository repository, IProgressMonitor monitor) th setIndexDetails(repository, null, details, null/*async*/); } - protected String getIndexDetails(IRepository repository) { + /** For tests only */ + public String getIndexDetails(IRepository repository) { String details = indexDetails.getProperty(repository.getUid()); if(details == null) { @@ -829,7 +877,7 @@ protected String getIndexDetails(IRepository repository) { * Updates index synchronously if monitor!=null. Schedules index update otherwise. ... and yes, I know this ain't * kosher. Public for unit tests only! */ - protected void setIndexDetails(IRepository repository, String details, IProgressMonitor monitor) throws CoreException { + public void setIndexDetails(IRepository repository, String details, IProgressMonitor monitor) throws CoreException { setIndexDetails(repository, details, details, monitor); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/AddDependencyDialog.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/AddDependencyDialog.java index d743ca5e2..fc629df66 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/AddDependencyDialog.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/AddDependencyDialog.java @@ -545,7 +545,11 @@ protected IStatus run(IProgressMonitor monitor) { try { setResults(IStatus.OK, Messages.AddDependencyDialog_searching, Collections. emptyMap()); - Map results = indexManager.search(query, IIndex.SEARCH_ARTIFACT, IIndex.SEARCH_ALL); + // TODO: before it was searching all indexes, but it should current project? (cstamas) + // If not, the change getIndex(project) to getAllIndexes() and done + // TODO: cstamas identified this as "user input", true? + Map results = indexManager.getIndex(project).search(query, IIndex.SEARCH_ARTIFACT, + IIndex.SEARCH_ALL); setResults(IStatus.OK, NLS.bind(Messages.AddDependencyDialog_searchDone, results.size()), results); } catch(BooleanQuery.TooManyClauses exception) { setResults(IStatus.ERROR, Messages.AddDependencyDialog_tooManyResults, diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/MavenGoalSelectionDialog.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/MavenGoalSelectionDialog.java index 12f8b9547..b8922e85b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/MavenGoalSelectionDialog.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/dialogs/MavenGoalSelectionDialog.java @@ -59,7 +59,7 @@ public class MavenGoalSelectionDialog extends ElementTreeSelectionDialog { Button isQualifiedNameButton; - + boolean isQualifiedName = true; public MavenGoalSelectionDialog(Shell parent) { @@ -91,10 +91,10 @@ protected Control createDialogArea(Composite parent) { gd_filterText.widthHint = 200; filterText.setLayoutData(gd_filterText); filterText.setFocus(); - + final TreeViewer treeViewer = createTreeViewer(composite); treeViewer.addFilter(filter); - + GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 500; data.heightHint = 400; @@ -110,7 +110,7 @@ public void modifyText(ModifyEvent e) { String text = filterText.getText(); filter.setFilter(text); treeViewer.refresh(); - if(text.trim().length()==0) { + if(text.trim().length() == 0) { treeViewer.collapseAll(); } else { treeViewer.expandAll(); @@ -120,14 +120,14 @@ public void modifyText(ModifyEvent e) { filterText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { - if(e.keyCode==SWT.ARROW_DOWN) { + if(e.keyCode == SWT.ARROW_DOWN) { tree.setFocus(); tree.setSelection(tree.getTopItem().getItem(0)); Object[] elements = ((ITreeContentProvider) treeViewer.getContentProvider()).getElements(null); treeViewer.setSelection(new StructuredSelection(elements[0])); } - + } }); @@ -139,7 +139,7 @@ public void widgetSelected(SelectionEvent e) { isQualifiedName = isQualifiedNameButton.getSelection(); } }); - + // if (fIsEmpty) { // messageLabel.setEnabled(false); // treeWidget.setEnabled(false); @@ -147,7 +147,7 @@ public void widgetSelected(SelectionEvent e) { return composite; } - + public boolean isQualifiedName() { return isQualifiedName; } @@ -176,18 +176,21 @@ public GoalsContentProvider() { IndexManager indexManager = MavenPlugin.getDefault().getIndexManager(); try { - Map result = indexManager.search("*", IIndex.SEARCH_PLUGIN); //$NON-NLS-1$ + // TODO: this will search ALL indexes, isn't the right to search _this_ project reposes only? + // I did not find (at first glance, maybe was hasty) a way to get IProject + // TODO: cstamas identified this as "user input", true? + Map result = indexManager.getAllIndexes().search("*", IIndex.SEARCH_PLUGIN); //$NON-NLS-1$ TreeMap map = new TreeMap(); for(IndexedArtifact a : result.values()) { IndexedArtifactFile f = a.getFiles().iterator().next(); - if(f.prefix != null && f.prefix.length()>0 && f.goals != null) { + if(f.prefix != null && f.prefix.length() > 0 && f.goals != null) { List goals = new ArrayList(); for(String goal : f.goals) { - if(goal.length()>0) { + if(goal.length() > 0) { goals.add(new Entry(goal, f.prefix, f)); } } - if(goals.size()>0) { + if(goals.size() > 0) { map.put(f.prefix + ":" + f.group, new Group(f.prefix, f.group, f.artifact, goals)); //$NON-NLS-1$ } } @@ -240,14 +243,14 @@ static class GoalsLabelProvider extends LabelProvider { public String getText(Object element) { if(element instanceof Group) { Group g = (Group) element; - if(g.groupId==null) { + if(g.groupId == null) { return g.name; } return g.name + " - " + g.groupId + ":" + g.artifactId; //$NON-NLS-1$ //$NON-NLS-2$ - + } else if(element instanceof Entry) { return ((Entry) element).name; - + } return super.getText(element); } @@ -258,7 +261,7 @@ public String getText(Object element) { */ static class GoalsFilter extends ViewerFilter { private String filter; - + public boolean select(Viewer viewer, Object parentElement, Object element) { if(filter == null || filter.trim().length() == 0) { return true; @@ -274,10 +277,10 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { return true; } } - + } else if(element instanceof Entry) { Entry e = (Entry) element; - return e.name.indexOf(filter) > -1 || (e.prefix!=null && e.prefix.indexOf(filter) > -1); + return e.name.indexOf(filter) > -1 || (e.prefix != null && e.prefix.indexOf(filter) > -1); } return false; @@ -294,7 +297,8 @@ public void setFilter(String filter) { static class GoalsSelectionValidator implements ISelectionStatusValidator { public IStatus validate(Object[] selection) { if(selection.length == 0) { - return new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, org.eclipse.m2e.core.internal.Messages.MavenGoalSelectionDialog_error, null); + return new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, + org.eclipse.m2e.core.internal.Messages.MavenGoalSelectionDialog_error, null); } for(int j = 0; j < selection.length; j++ ) { if(selection[j] instanceof Entry) { @@ -311,7 +315,9 @@ public IStatus validate(Object[] selection) { */ static class Group { public final String name; + public final String groupId; + public final String artifactId; public final List entries; @@ -348,7 +354,7 @@ public String getQualifiedName() { // return prefix == null ? name : prefix + ":" + name; return prefix == null ? name : f.group + ":" + f.artifact + ":" + f.version + ":" + name; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - + } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java index 8655c12a3..08547ca77 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java @@ -55,12 +55,12 @@ import org.eclipse.m2e.core.actions.MaterializeAction; import org.eclipse.m2e.core.actions.OpenPomAction; import org.eclipse.m2e.core.index.IndexListener; +import org.eclipse.m2e.core.index.IndexManager; import org.eclipse.m2e.core.index.IndexedArtifact; import org.eclipse.m2e.core.index.IndexedArtifactFile; import org.eclipse.m2e.core.internal.Messages; import org.eclipse.m2e.core.internal.index.IndexedArtifactGroup; import org.eclipse.m2e.core.internal.index.NexusIndex; -import org.eclipse.m2e.core.internal.index.NexusIndexManager; import org.eclipse.m2e.core.repository.IRepository; import org.eclipse.m2e.core.ui.internal.views.nodes.AbstractIndexedRepositoryNode; import org.eclipse.m2e.core.ui.internal.views.nodes.IArtifactNode; @@ -83,7 +83,7 @@ public class MavenRepositoryView extends ViewPart { private static final String ENABLE_MIN = Messages.MavenRepositoryView_enable_minimum; private static final String ENABLED_MIN = Messages.MavenRepositoryView_minimum_enabled; - private NexusIndexManager indexManager = (NexusIndexManager) MavenPlugin.getDefault().getIndexManager(); + private IndexManager indexManager = MavenPlugin.getDefault().getIndexManager(); private IAction collapseAllAction; diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/nodes/AbstractIndexedRepositoryNode.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/nodes/AbstractIndexedRepositoryNode.java index 3a1297954..a6fb9f55b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/nodes/AbstractIndexedRepositoryNode.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/ui/internal/views/nodes/AbstractIndexedRepositoryNode.java @@ -44,7 +44,7 @@ public Object[] getChildren() { } try { - IndexedArtifactGroup[] rootGroups = index.getRootGroups(); + IndexedArtifactGroup[] rootGroups = index.getRootIndexedArtifactGroups(); if(rootGroups == null) { return NO_CHILDREN; } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenInstallFileArtifactWizardPage.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenInstallFileArtifactWizardPage.java index faa8c6775..adbcd2a0b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenInstallFileArtifactWizardPage.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenInstallFileArtifactWizardPage.java @@ -250,7 +250,7 @@ void updateFileName(String fileName) { MavenPlugin plugin = MavenPlugin.getDefault(); try { - IndexedArtifactFile iaf = plugin.getIndexManager().identify(file); + IndexedArtifactFile iaf = plugin.getIndexManager().getAllIndexes().identify(file); if(iaf!=null) { groupIdCombo.setText(iaf.group); artifactIdCombo.setText(iaf.artifact); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenPomSelectionComponent.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenPomSelectionComponent.java index 8eac3f8fd..66115ed18 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenPomSelectionComponent.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenPomSelectionComponent.java @@ -66,9 +66,10 @@ import org.eclipse.m2e.core.index.IndexedArtifactFile; import org.eclipse.m2e.core.internal.Messages; + /** * MavenPomSelectionComposite - * + * * @author Eugene Kuleshov */ public class MavenPomSelectionComponent extends Composite { @@ -77,7 +78,7 @@ public class MavenPomSelectionComponent extends Composite { * @see org.eclipse.swt.widgets.Widget#dispose() */ public void dispose() { - if(searchJob != null){ + if(searchJob != null) { searchJob.cancel(); } super.dispose(); @@ -86,43 +87,47 @@ public void dispose() { Text searchText = null; TreeViewer searchResultViewer = null; - + Button javadocCheckBox; + Button sourcesCheckBox; + Button testCheckBox; /** - * One of - * {@link IIndex#SEARCH_ARTIFACT}, - * {@link IIndex#SEARCH_CLASS_NAME}, + * One of {@link IIndex#SEARCH_ARTIFACT}, {@link IIndex#SEARCH_CLASS_NAME}, */ String queryType; - + SearchJob searchJob; private IStatus status; private ISelectionChangedListener selectionListener; - + public static final String P_SEARCH_INCLUDE_JAVADOC = "searchIncludesJavadoc"; //$NON-NLS-1$ - public static final String P_SEARCH_INCLUDE_SOURCES = "searchIncludesSources"; //$NON-NLS-1$ + + public static final String P_SEARCH_INCLUDE_SOURCES = "searchIncludesSources"; //$NON-NLS-1$ + public static final String P_SEARCH_INCLUDE_TESTS = "searchIncludesTests"; //$NON-NLS-1$ + private static final long SHORT_DELAY = 150L; + private static final long LONG_DELAY = 500L; - + HashSet artifactKeys = new HashSet(); public MavenPomSelectionComponent(Composite parent, int style) { super(parent, style); - createSearchComposite(); + createSearchComposite(); } - + private void createSearchComposite() { GridLayout gridLayout = new GridLayout(2, false); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; setLayout(gridLayout); - + Label searchTextlabel = new Label(this, SWT.NONE); searchTextlabel.setText(Messages.MavenPomSelectionComponent_search_title); searchTextlabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); @@ -135,9 +140,9 @@ public void keyPressed(KeyEvent e) { searchResultViewer.getTree().setFocus(); selectFirstElementInTheArtifactTreeIfNoSelectionHasBeenMade(); } - } + } }); - + searchText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { scheduleSearch(searchText.getText(), true); @@ -151,65 +156,65 @@ public void modifyText(ModifyEvent e) { Tree tree = new Tree(this, SWT.BORDER | SWT.SINGLE); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); tree.setData("name", "searchResultTree"); //$NON-NLS-1$ //$NON-NLS-2$ - tree.addFocusListener( new FocusListener() { + tree.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { selectFirstElementInTheArtifactTreeIfNoSelectionHasBeenMade(); } public void focusLost(FocusEvent e) { - + } }); - + searchResultViewer = new TreeViewer(tree); } - + void selectFirstElementInTheArtifactTreeIfNoSelectionHasBeenMade() { // // If we have started a new search when focus is passed to the tree viewer we will automatically select // the first element if no element has been selected from a previous expedition into the tree viewer. // - if(searchResultViewer.getTree().getItemCount()>0 && searchResultViewer.getSelection().isEmpty()) { + if(searchResultViewer.getTree().getItemCount() > 0 && searchResultViewer.getSelection().isEmpty()) { Object artifact = searchResultViewer.getTree().getTopItem().getData(); searchResultViewer.setSelection(new StructuredSelection(artifact), true); - } + } } - - protected boolean showClassifiers(){ + + protected boolean showClassifiers() { return (queryType != null && IIndex.SEARCH_ARTIFACT.equals(queryType)); } - - private void setupButton(final Button button, String label, final String prefName, int horizontalIndent){ + + private void setupButton(final Button button, String label, final String prefName, int horizontalIndent) { button.setText(label); GridData gd = new GridData(SWT.LEFT, SWT.TOP, false, false); - gd.horizontalIndent=horizontalIndent; + gd.horizontalIndent = horizontalIndent; button.setLayoutData(gd); boolean check = MavenPlugin.getDefault().getPreferenceStore().getBoolean(prefName); button.setSelection(check); - button.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e){ + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { boolean checked = button.getSelection(); MavenPlugin.getDefault().getPreferenceStore().setValue(prefName, checked); scheduleSearch(searchText.getText(), false); } }); } - + public void init(String queryText, String queryType, Set artifacts) { this.queryType = queryType; - + if(queryText != null) { searchText.setText(queryText); } - - if(artifacts!=null) { + + if(artifacts != null) { for(ArtifactKey a : artifacts) { artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId()); //$NON-NLS-1$ artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion()); //$NON-NLS-1$ //$NON-NLS-2$ } } - + searchResultViewer.setContentProvider(new SearchResultContentProvider()); searchResultViewer.setLabelProvider(new SearchResultLabelProvider(artifactKeys, queryType)); searchResultViewer.addSelectionChangedListener(new ISelectionChangedListener() { @@ -220,8 +225,11 @@ public void selectionChanged(SelectionChangedEvent event) { IndexedArtifactFile f = getSelectedIndexedArtifactFile(selection.getFirstElement()); // int severity = artifactKeys.contains(f.group + ":" + f.artifact) ? IStatus.ERROR : IStatus.OK; int severity = IStatus.OK; - String date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(f .date); - setStatus(severity, NLS.bind(Messages.MavenPomSelectionComponent_detail1, f.fname, (f.size != -1 ? NLS.bind(Messages.MavenPomSelectionComponent_details2, date, f.size) : date))); + String date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(f.date); + setStatus( + severity, + NLS.bind(Messages.MavenPomSelectionComponent_detail1, f.fname, + (f.size != -1 ? NLS.bind(Messages.MavenPomSelectionComponent_details2, date, f.size) : date))); } else { setStatus(IStatus.OK, NLS.bind(Messages.MavenPomSelectionComponent_selected, selection.size())); } @@ -234,24 +242,25 @@ public void selectionChanged(SelectionChangedEvent event) { setStatus(IStatus.ERROR, ""); //$NON-NLS-1$ scheduleSearch(queryText, false); } - - protected void setupClassifiers(){ - if(showClassifiers()){ + + protected void setupClassifiers() { + if(showClassifiers()) { Composite includesComp = new Composite(this, SWT.NONE); includesComp.setLayout(new GridLayout(3, true)); GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, false); includesComp.setLayoutData(gd); - + javadocCheckBox = new Button(includesComp, SWT.CHECK); - setupButton(javadocCheckBox, Messages.MavenPomSelectionComponent_btnJavadoc, P_SEARCH_INCLUDE_JAVADOC,0); - + setupButton(javadocCheckBox, Messages.MavenPomSelectionComponent_btnJavadoc, P_SEARCH_INCLUDE_JAVADOC, 0); + sourcesCheckBox = new Button(includesComp, SWT.CHECK); - setupButton(sourcesCheckBox, Messages.MavenPomSelectionComponent_btnSource, P_SEARCH_INCLUDE_SOURCES,10); - + setupButton(sourcesCheckBox, Messages.MavenPomSelectionComponent_btnSource, P_SEARCH_INCLUDE_SOURCES, 10); + testCheckBox = new Button(includesComp, SWT.CHECK); - setupButton(testCheckBox, Messages.MavenPomSelectionComponent_btnTests, P_SEARCH_INCLUDE_TESTS,10); + setupButton(testCheckBox, Messages.MavenPomSelectionComponent_btnTests, P_SEARCH_INCLUDE_TESTS, 10); } } + public IStatus getStatus() { return this.status; } @@ -259,18 +268,19 @@ public IStatus getStatus() { public void addDoubleClickListener(IDoubleClickListener listener) { searchResultViewer.addDoubleClickListener(listener); } - + public void addSelectionChangedListener(ISelectionChangedListener listener) { this.selectionListener = listener; } void setStatus(int severity, String message) { this.status = new Status(severity, IMavenConstants.PLUGIN_ID, 0, message, null); - if(selectionListener!=null) { - selectionListener.selectionChanged(new SelectionChangedEvent(searchResultViewer, searchResultViewer.getSelection())); + if(selectionListener != null) { + selectionListener.selectionChanged(new SelectionChangedEvent(searchResultViewer, searchResultViewer + .getSelection())); } } - + public IndexedArtifact getIndexedArtifact() { IStructuredSelection selection = (IStructuredSelection) searchResultViewer.getSelection(); Object element = selection.getFirstElement(); @@ -278,12 +288,12 @@ public IndexedArtifact getIndexedArtifact() { return (IndexedArtifact) element; } TreeItem[] treeItems = searchResultViewer.getTree().getSelection(); - if(treeItems.length == 0){ + if(treeItems.length == 0) { return null; } return (IndexedArtifact) treeItems[0].getParentItem().getData(); } - + public IndexedArtifactFile getIndexedArtifactFile() { IStructuredSelection selection = (IStructuredSelection) searchResultViewer.getSelection(); return getSelectedIndexedArtifactFile(selection.getFirstElement()); @@ -302,7 +312,7 @@ void scheduleSearch(String query, boolean delay) { IndexManager indexManager = MavenPlugin.getDefault().getIndexManager(); searchJob = new SearchJob(queryType, indexManager); } else { - if (!searchJob.cancel()) { + if(!searchJob.cancel()) { //for already running ones, just create new instance so that the previous one can piecefully die //without preventing the new one from completing first IndexManager indexManager = MavenPlugin.getDefault().getIndexManager(); @@ -312,13 +322,12 @@ void scheduleSearch(String query, boolean delay) { searchJob.setQuery(query.toLowerCase()); searchJob.schedule(delay ? LONG_DELAY : SHORT_DELAY); } else { - if (searchJob != null) { + if(searchJob != null) { searchJob.cancel(); } } } - /** * Search Job */ @@ -341,60 +350,68 @@ public SearchJob(String field, IndexManager indexManager) { public void setQuery(String query) { this.query = query; } - + public boolean shouldRun() { stop = false; return super.shouldRun(); } - public int getClassifier(){ + public int getClassifier() { int classifier = IIndex.SEARCH_JARS; - if(MavenPlugin.getDefault().getPreferenceStore().getBoolean(P_SEARCH_INCLUDE_JAVADOC)){ + if(MavenPlugin.getDefault().getPreferenceStore().getBoolean(P_SEARCH_INCLUDE_JAVADOC)) { classifier = classifier + IIndex.SEARCH_JAVADOCS; } - if(MavenPlugin.getDefault().getPreferenceStore().getBoolean(P_SEARCH_INCLUDE_SOURCES)){ + if(MavenPlugin.getDefault().getPreferenceStore().getBoolean(P_SEARCH_INCLUDE_SOURCES)) { classifier = classifier + IIndex.SEARCH_SOURCES; } - if(MavenPlugin.getDefault().getPreferenceStore().getBoolean(P_SEARCH_INCLUDE_TESTS)){ + if(MavenPlugin.getDefault().getPreferenceStore().getBoolean(P_SEARCH_INCLUDE_TESTS)) { classifier = classifier + IIndex.SEARCH_TESTS; } return classifier; } - + protected IStatus run(IProgressMonitor monitor) { int classifier = showClassifiers() ? getClassifier() : IIndex.SEARCH_ALL; - if(searchResultViewer == null || searchResultViewer.getControl() == null || searchResultViewer.getControl().isDisposed()){ + if(searchResultViewer == null || searchResultViewer.getControl() == null + || searchResultViewer.getControl().isDisposed()) { return Status.CANCEL_STATUS; } - if (query != null) { + if(query != null) { String activeQuery = query; try { - setResult(IStatus.OK, NLS.bind(Messages.MavenPomSelectionComponent_searching , activeQuery.toLowerCase()), null); - Map res = indexManager.search(activeQuery, field, classifier); + setResult(IStatus.OK, NLS.bind(Messages.MavenPomSelectionComponent_searching, activeQuery.toLowerCase()), + null); + + // TODO: cstamas identified this as "user input", true? + Map res = indexManager.getAllIndexes().search(activeQuery, field, classifier); setResult(IStatus.OK, NLS.bind(Messages.MavenPomSelectionComponent_results, activeQuery, res.size()), res); - } catch(BooleanQuery.TooManyClauses ex){ - setResult(IStatus.ERROR, Messages.MavenPomSelectionComponent_toomany, Collections.emptyMap()); + } catch(BooleanQuery.TooManyClauses ex) { + setResult(IStatus.ERROR, Messages.MavenPomSelectionComponent_toomany, + Collections. emptyMap()); } catch(final RuntimeException ex) { - setResult(IStatus.ERROR, NLS.bind(Messages.MavenPomSelectionComponent_error, ex.toString()), Collections.emptyMap()); + setResult(IStatus.ERROR, NLS.bind(Messages.MavenPomSelectionComponent_error, ex.toString()), + Collections. emptyMap()); } catch(final Exception ex) { - setResult(IStatus.ERROR, NLS.bind(Messages.MavenPomSelectionComponent_error, ex.getMessage()), Collections.emptyMap()); + setResult(IStatus.ERROR, NLS.bind(Messages.MavenPomSelectionComponent_error, ex.getMessage()), + Collections. emptyMap()); } - } + } return Status.OK_STATUS; } protected void canceling() { - stop = true; + stop = true; } private void setResult(final int severity, final String message, final Map result) { - if (stop) return; + if(stop) + return; Display.getDefault().syncExec(new Runnable() { public void run() { setStatus(severity, message); if(result != null) { - if(!searchResultViewer.getControl().isDisposed()){ - searchResultViewer.setInput(result); + if(!searchResultViewer.getControl().isDisposed()) { + searchResultViewer.setInput(result); } } } @@ -404,6 +421,7 @@ public void run() { public static class SearchResultLabelProvider extends LabelProvider implements IColorProvider { private final Set artifactKeys; + private final String queryType; public SearchResultLabelProvider(Set artifactKeys, String queryType) { @@ -419,15 +437,15 @@ public String getText(Object element) { } else if(element instanceof IndexedArtifactFile) { IndexedArtifactFile f = (IndexedArtifactFile) element; // String displayName = getRepoDisplayName(f.repository); - return f.version + " [" + f.type + (f.classifier != null ? ", " + f.classifier : "") + "]"; //unless there is something reasonably short " [" + displayName + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return f.version + " [" + f.type + (f.classifier != null ? ", " + f.classifier : "") + "]"; //unless there is something reasonably short " [" + displayName + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } return super.getText(element); } - - protected String getRepoDisplayName(String repo){ + + protected String getRepoDisplayName(String repo) { return repo; } - + public Color getForeground(Object element) { if(element instanceof IndexedArtifactFile) { IndexedArtifactFile f = (IndexedArtifactFile) element; @@ -446,11 +464,11 @@ public Color getForeground(Object element) { public Color getBackground(Object element) { return null; } - + public Image getImage(Object element) { if(element instanceof IndexedArtifactFile) { IndexedArtifactFile f = (IndexedArtifactFile) element; - if(f.sourcesExists==IIndex.PRESENT) { + if(f.sourcesExists == IIndex.PRESENT) { return MavenImages.IMG_VERSION_SRC; } return MavenImages.IMG_VERSION; @@ -493,9 +511,8 @@ public Object getParent(Object element) { } public void dispose() { - + } } } - diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenProjectWizardArchetypePage.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenProjectWizardArchetypePage.java index ddbb687ae..3e8ceb57b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenProjectWizardArchetypePage.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenProjectWizardArchetypePage.java @@ -89,7 +89,6 @@ import org.eclipse.m2e.core.index.IMutableIndex; import org.eclipse.m2e.core.index.IndexListener; import org.eclipse.m2e.core.index.IndexManager; -import org.eclipse.m2e.core.internal.index.NexusIndexManager; import org.eclipse.m2e.core.project.ProjectImportConfiguration; import org.eclipse.m2e.core.repository.IRepository; import org.eclipse.m2e.core.util.M2EUtils; @@ -178,7 +177,7 @@ public void createControl(Composite parent) { createAdvancedSettings(composite, new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); - ((NexusIndexManager) MavenPlugin.getDefault().getIndexManager()).addIndexListener(this); + MavenPlugin.getDefault().getIndexManager().addIndexListener(this); setControl(composite); } @@ -475,7 +474,7 @@ public void addArchetypeSelectionListener(ISelectionChangedListener listener) { } public void dispose() { - ((NexusIndexManager) MavenPlugin.getDefault().getIndexManager()).removeIndexListener(this); + MavenPlugin.getDefault().getIndexManager().removeIndexListener(this); super.dispose(); }