Skip to content

Commit

Permalink
added quarkus.http.root-path property to CodeLensURL
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Chen <alchen@redhat.com>
  • Loading branch information
Alexander Chen committed Sep 3, 2021
1 parent cbcc381 commit 30574e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class JaxRsContext {
private static final String CONTEXT_KEY = JaxRsContext.class.getName();

private int serverPort;

// The quarkus.http.root-path property in application.properties
private String rootPath;

public JaxRsContext() {
setServerPort(DEFAULT_PORT);
Expand All @@ -40,6 +43,22 @@ public int getServerPort() {
public void setServerPort(int serverPort) {
this.serverPort = serverPort;
}

/** Get the quarkus.http.root-path property
*
* @return the rootPath
*/
public String getRootPath() {
return rootPath;
}

/** Set the quarkus.http.root-path property
*
* @param rootPath the rootPath to set
*/
public void setRootPath(String rootPath) {
this.rootPath = rootPath;
}

public static JaxRsContext getJaxRsContext(JavaCodeLensContext context) {
JaxRsContext jaxRsContext = (JaxRsContext) context.get(CONTEXT_KEY);
Expand All @@ -49,4 +68,18 @@ public static JaxRsContext getJaxRsContext(JavaCodeLensContext context) {
}
return jaxRsContext;
}

/** Create the local base URL
*
* @return the String representation of the project base URL
*/
public String getLocalBaseURL() {
StringBuilder localBaseURL = new StringBuilder("http://localhost:");
localBaseURL.append(getServerPort()).toString();
if (rootPath != null) {
localBaseURL.append(getRootPath());
}
return localBaseURL.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ public boolean isAdaptedForCodeLens(JavaCodeLensContext context, IProgressMonito
public List<CodeLens> collectCodeLens(JavaCodeLensContext context, IProgressMonitor monitor) throws CoreException {
ITypeRoot typeRoot = context.getTypeRoot();
IJavaElement[] elements = typeRoot.getChildren();
int serverPort = JaxRsContext.getJaxRsContext(context).getServerPort();
JaxRsContext jaxrsContext = JaxRsContext.getJaxRsContext(context);
int serverPort = jaxrsContext.getServerPort();
IJDTUtils utils = context.getUtils();
MicroProfileJavaCodeLensParams params = context.getParams();
params.setLocalServerPort(serverPort);
List<CodeLens> lenses = new ArrayList<>();
collectURLCodeLenses(elements, null, lenses, params, utils, monitor);
collectURLCodeLenses(elements, null, lenses, params, jaxrsContext, utils, monitor);
return lenses;
}

private static void collectURLCodeLenses(IJavaElement[] elements, String rootPath, Collection<CodeLens> lenses,
MicroProfileJavaCodeLensParams params, IJDTUtils utils, IProgressMonitor monitor)
throws JavaModelException {
MicroProfileJavaCodeLensParams params, JaxRsContext jaxrsContext, IJDTUtils utils, IProgressMonitor monitor)
throws JavaModelException, CoreException {

for (IJavaElement element : elements) {
if (monitor.isCanceled()) {
return;
Expand All @@ -99,7 +101,7 @@ private static void collectURLCodeLenses(IJavaElement[] elements, String rootPat
|| isServerAvailable(LOCALHOST, params.getLocalServerPort(), PING_TIMEOUT)) {
// Loop for each method annotated with @Path to generate URL code lens per
// method.
collectURLCodeLenses(type.getChildren(), pathValue, lenses, params, utils, monitor);
collectURLCodeLenses(type.getChildren(), pathValue, lenses, params, jaxrsContext, utils, monitor);
}
}
continue;
Expand All @@ -125,7 +127,7 @@ private static void collectURLCodeLenses(IJavaElement[] elements, String rootPat
// JAX-RS
// annotation
if (isJaxRsRequestMethod(method) && Flags.isPublic(method.getFlags())) {
String baseURL = params.getLocalBaseURL();
String baseURL = jaxrsContext.getLocalBaseURL();
String openURICommandId = params.getOpenURICommand();
CodeLens lens = createURLCodeLens(baseURL, rootPath, openURICommandId, (IMethod) element, utils);
if (lens != null) {
Expand Down

0 comments on commit 30574e3

Please sign in to comment.