-
Notifications
You must be signed in to change notification settings - Fork 126
Add Java projects to classpath container org.eclipse.pde.core.externaJavaSearch #2270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||||
| /******************************************************************************* | ||||||||||
| * Copyright (c) 2026 Simeon Andreev and others. | ||||||||||
| * | ||||||||||
| * This program and the accompanying materials | ||||||||||
| * are made available under the terms of the Eclipse Public License 2.0 | ||||||||||
| * which accompanies this distribution, and is available at | ||||||||||
| * https://www.eclipse.org/legal/epl-2.0/ | ||||||||||
| * | ||||||||||
| * SPDX-License-Identifier: EPL-2.0 | ||||||||||
| * | ||||||||||
| * Contributors: | ||||||||||
| * Simeon Andreev - initial API and implementation | ||||||||||
| *******************************************************************************/ | ||||||||||
| package org.eclipse.pde.core.tests.internal.classpath; | ||||||||||
|
|
||||||||||
| import static org.junit.Assert.assertEquals; | ||||||||||
| import static org.junit.Assert.assertNotNull; | ||||||||||
| import static org.junit.Assert.assertTrue; | ||||||||||
|
|
||||||||||
| import java.util.ArrayList; | ||||||||||
| import java.util.List; | ||||||||||
| import java.util.regex.Matcher; | ||||||||||
| import java.util.regex.Pattern; | ||||||||||
|
|
||||||||||
| import org.eclipse.core.resources.IProject; | ||||||||||
| import org.eclipse.core.resources.IWorkspaceRoot; | ||||||||||
| import org.eclipse.core.resources.ResourcesPlugin; | ||||||||||
| import org.eclipse.core.runtime.NullProgressMonitor; | ||||||||||
| import org.eclipse.jdt.core.IJavaElement; | ||||||||||
| import org.eclipse.jdt.core.IJavaProject; | ||||||||||
| import org.eclipse.jdt.core.JavaCore; | ||||||||||
| import org.eclipse.jdt.core.JavaModelException; | ||||||||||
| import org.eclipse.jdt.core.search.IJavaSearchConstants; | ||||||||||
| import org.eclipse.jdt.core.search.SearchEngine; | ||||||||||
| import org.eclipse.jdt.core.search.SearchPattern; | ||||||||||
| import org.eclipse.jdt.core.search.TypeNameRequestor; | ||||||||||
| import org.eclipse.jdt.internal.core.JavaModelManager; | ||||||||||
| import org.eclipse.pde.core.plugin.IPluginModelBase; | ||||||||||
| import org.eclipse.pde.core.plugin.PluginRegistry; | ||||||||||
| import org.eclipse.pde.internal.core.SearchablePluginsManager; | ||||||||||
| import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; | ||||||||||
| import org.eclipse.pde.internal.ui.wizards.imports.PluginImportWizard; | ||||||||||
| import org.eclipse.pde.ui.tests.runtime.TestUtils; | ||||||||||
| import org.eclipse.pde.ui.tests.util.ProjectUtils; | ||||||||||
| import org.eclipse.ui.IWorkbenchWindow; | ||||||||||
| import org.eclipse.ui.PlatformUI; | ||||||||||
| import org.eclipse.ui.handlers.IHandlerService; | ||||||||||
| import org.junit.ClassRule; | ||||||||||
| import org.junit.Rule; | ||||||||||
| import org.junit.Test; | ||||||||||
| import org.junit.rules.TestName; | ||||||||||
| import org.junit.rules.TestRule; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Test that the External Plug-in Libraries project doesn't find duplicated | ||||||||||
| * types, when a project is imported into the workspace. | ||||||||||
| */ | ||||||||||
| public class ExternalJavaSearchClasspathContainerTests { | ||||||||||
|
|
||||||||||
| public static final String ADD_PLUGINS_TO_SEARCH_COMMAND_ID = "org.eclipse.pde.ui.addAllPluginsToJavaSearch"; | ||||||||||
| @ClassRule | ||||||||||
| public static final TestRule CLEAR_WORKSPACE = ProjectUtils.DELETE_ALL_WORKSPACE_PROJECTS_BEFORE_AND_AFTER; | ||||||||||
| @Rule | ||||||||||
| public final TestRule deleteCreatedTestProjectsAfter = ProjectUtils.DELETE_CREATED_WORKSPACE_PROJECTS_AFTER; | ||||||||||
| @Rule | ||||||||||
| public final TestName name = new TestName(); | ||||||||||
|
|
||||||||||
| @Test | ||||||||||
| public void testSearchWithImportedProject() throws Exception { | ||||||||||
| IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | ||||||||||
| IHandlerService handlerService = window.getService(IHandlerService.class); | ||||||||||
| handlerService.executeCommand(ADD_PLUGINS_TO_SEARCH_COMMAND_ID, null); | ||||||||||
| TestUtils.waitForJobs(name.getMethodName(), 100, 10000); | ||||||||||
| JavaModelManager.getIndexManager().waitForIndex(false, null); | ||||||||||
| IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); | ||||||||||
| IProject proxyProject = root.getProject(SearchablePluginsManager.PROXY_PROJECT_NAME); | ||||||||||
| assertNotNull("Adding " + SearchablePluginsManager.PROXY_PROJECT_NAME + " failed", proxyProject); | ||||||||||
| IJavaProject javaProject = JavaCore.create(proxyProject); | ||||||||||
|
|
||||||||||
| String pluginId = "org.eclipse.core.expressions"; | ||||||||||
| String fqn = "org.eclipse.core.expressions.AndExpression"; | ||||||||||
| // expect a match like this: | ||||||||||
| // .../plugins/org.eclipse.equinox.common_3.20.300.v20251111-0312.jar|org/eclipse/core/runtime/IProgressMonitor.class | ||||||||||
| String expected = ".*.jar\\|" + fqn.replace('.', '/') + ".class"; | ||||||||||
|
|
||||||||||
|
Comment on lines
+82
to
+85
|
||||||||||
| List<String> matches = performSearch(javaProject, fqn); | ||||||||||
| assertSingleMatch(expected, matches); | ||||||||||
|
|
||||||||||
| IPluginModelBase plugin = PluginRegistry.findModel(pluginId); | ||||||||||
|
||||||||||
| IPluginModelBase plugin = PluginRegistry.findModel(pluginId); | |
| IPluginModelBase plugin = PluginRegistry.findModel(pluginId); | |
| assertNotNull("Required plug-in model not found for '" + pluginId | |
| + "'. The test target may be missing this bundle.", plugin); |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pluginProject.getFullPath() contains dots which are regex metacharacters; concatenating it directly into the regexp can match unintended paths. Use Pattern.quote(pluginProject.getFullPath().toString()) (and escape \\.jar/\\.class) to make the assertion precise and resilient.
| expected = pluginProject.getFullPath() + ".*.jar\\|" + fqn.replace('.', '/') + ".class"; | |
| expected = Pattern.quote(pluginProject.getFullPath().toString()) + ".*\\.jar\\|" + fqn.replace('.', '/') + "\\.class"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IWorkspaceRoot#getProject(String)never returns null (it returns a project handle even if the project doesn’t exist), soassertNotNullhere won’t actually verify that the command created/opened the proxy project. Consider assertingproxyProject.exists()/proxyProject.isOpen()(and optionallyPluginProject.isJavaProject(proxyProject)orjavaProject.exists()) to make test failures clearer and more accurate.