Skip to content

Commit cc3aead

Browse files
committed
Include libs in search for main class for Boot Launch
1 parent cf4edc1 commit cc3aead

File tree

3 files changed

+35
-6
lines changed
  • eclipse-extensions
  • eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/maintype

3 files changed

+35
-6
lines changed

eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/BootProjectDashElement.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected Boolean compute() {
8686
if (p != null && p.exists()) {
8787
IJavaProject jp = JavaCore.create(p);
8888
if (jp != null) {
89-
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[]{jp}, IJavaSearchScope.SOURCES);
89+
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[]{jp}, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES);
9090
MainMethodSearchEngine engine = new MainMethodSearchEngine();
9191
IType[] types = null;
9292
try {

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/MainTypeLaunchTabSection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected void handleSearchButtonSelected() {
164164
if (elements == null) {
165165
elements = new IJavaElement[]{};
166166
}
167-
int constraints = IJavaSearchScope.SOURCES;
167+
int constraints = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES;
168168
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints);
169169
MainMethodSearchEngine engine = new MainMethodSearchEngine();
170170
IType[] types = null;

eclipse-language-servers/org.springsource.ide.eclipse.commons.frameworks.core/src/org/springsource/ide/eclipse/commons/frameworks/core/maintype/MainTypeFinder.java

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2013 Pivotal Software, Inc.
2+
* Copyright (c) 2012, 2025 Pivotal Software, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -96,18 +96,20 @@ private MainTypeFinder() {
9696
// confidence that they are the types requested. Each confidence itself also has a priority
9797
// order, with more authoritative finders listed first.
9898
this.algos.put(Confidence.CERTAIN, new IMainTypeFinder[] {
99-
// add in order of which is more authoritative
99+
// add more here if they should be considered more authorative
100+
new FindInPom()
101+
// add more here if they should be considered less authorative
100102
});
101103

102104
this.algos.put(Confidence.HIGH, new IMainTypeFinder[] {
103105
// add more here if they should be considered more authorative
104-
new FindInPom()
106+
new FindInSource(),
105107
// add more here if they should be considered less authorative
106108
});
107109

108110
this.algos.put(Confidence.LOW, new IMainTypeFinder[] {
109111
// add more here if they should be considered more authorative
110-
new FindInSource()
112+
new FindInLibs()
111113
// add more here if they should be considered less authorative
112114
});
113115

@@ -241,6 +243,33 @@ private boolean isInteresting(IClasspathEntry cpe) {
241243
);
242244
}
243245
}
246+
247+
public static class FindInLibs implements IMainTypeFinder {
248+
249+
public IType[] findMain(IJavaProject javaProject,
250+
IProgressMonitor monitor) throws Exception {
251+
monitor.beginTask("Search main types in project source", 1);
252+
try {
253+
254+
MainMethodSearchEngine engine = new MainMethodSearchEngine();
255+
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(true, new IJavaElement[] { javaProject }, IJavaSearchScope.APPLICATION_LIBRARIES);
256+
257+
boolean includeSubtypes = true;
258+
IType[] types = engine
259+
.searchMainMethods(monitor, scope, includeSubtypes);
260+
if (types == null) {
261+
types = EMPTY;
262+
}
263+
return types;
264+
} catch (Exception e) {
265+
FrameworkCoreActivator.log(e);
266+
} finally {
267+
monitor.done();
268+
}
269+
return EMPTY;
270+
}
271+
272+
}
244273

245274
/**
246275
* Confidence that a search result for main types in a project is what is expected.

0 commit comments

Comments
 (0)