diff --git a/pom.xml b/pom.xml index e323e33760..ca015b684e 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,12 @@ 5.5.4 test + + + org.json + json + 20240303 + diff --git a/src/main/content/_assets/js/builds.js b/src/main/content/_assets/js/builds.js index 7c7d0c3352..3c810cdbb8 100644 --- a/src/main/content/_assets/js/builds.js +++ b/src/main/content/_assets/js/builds.js @@ -24,6 +24,7 @@ var starter_domain = isNotProdSite() ? 'https://starter-staging.rh9j6zz75er.us-east.codeengine.appdomain.cloud' : 'https://start.openliberty.io'; var starter_info_url = starter_domain + '/api/start/info'; var starter_submit_url = starter_domain + '/api/start'; +var starter_plugin_url='/api/start/plugin-versions' var failed_builds_request = false; // Controls what build zips are exposed on openliberty.io. This will need to be updated @@ -1565,6 +1566,19 @@ $(document).ready(function () { } }) + $.ajax({ + url: starter_plugin_url, + type: 'GET', + dataType: 'json', + success: function(data) { + $('#maven_version').text(data.mavenVersion); + $('#gradle_version').text(data.gradleVersion); + }, + error: function(error) { + console.error('Error fetching Maven and Gradle plugin versions:', error); + } + }); + $(window).on('scroll', function (event) { // start animation if images are in viewport if ($('#bottom_images_container').isInViewport()) { diff --git a/src/main/content/start.html b/src/main/content/start.html index 7dc4b18295..becab526cf 100644 --- a/src/main/content/start.html +++ b/src/main/content/start.html @@ -162,7 +162,7 @@

{% t st
Copied to clipboard
-
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.10.2</version>
</plugin>
+
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.10.3</version>
</plugin>

{% t start.add_to_existing_app.maven_guide_text %} @@ -177,7 +177,7 @@

{% t st
Copied to clipboard
-
buildscript { 
repositories {
mavenCentral()
}
dependencies {
classpath 'io.openliberty.tools:liberty-gradle-plugin:'3.8.2'
}
}
+
buildscript { 
repositories {
mavenCentral()
}
dependencies {
classpath 'io.openliberty.tools:liberty-gradle-plugin:'3.8.3'
}
}

The plugin also needs to be applied in the build file in order to be utilized.

diff --git a/src/main/java/io/openliberty/website/OpenLibertyEndpoint.java b/src/main/java/io/openliberty/website/OpenLibertyEndpoint.java index cb51bffe89..53cccbfc5f 100644 --- a/src/main/java/io/openliberty/website/OpenLibertyEndpoint.java +++ b/src/main/java/io/openliberty/website/OpenLibertyEndpoint.java @@ -17,11 +17,19 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; import io.openliberty.website.data.BuildData; import io.openliberty.website.data.LastUpdate; import io.openliberty.website.data.LatestReleases; +import org.json.JSONObject; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import org.json.JSONArray; + /** * This is the main JAX-RS entry point for the Open Liberty website REST API. * The API is defined in the source repo website-api.yml. @@ -33,6 +41,31 @@ public class OpenLibertyEndpoint extends Application { @Inject private BuildsManager buildsManager; @Inject private GitHubManager githubManager; + + public String getJsonData(String jsonUrl) throws Exception{ + URL url = new URL(jsonUrl); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuilder response = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + con.disconnect(); + return parseJsonObject(new JSONObject(response.toString())); + } + + private String parseJsonObject(JSONObject jsonObject) { + JSONObject response = jsonObject.getJSONObject("response"); + JSONArray docs = response.getJSONArray("docs"); + JSONObject doc=docs.getJSONObject(0); + String pluginVersion = doc.getString("v"); + return pluginVersion; + } @GET @Path("builds") @@ -61,4 +94,29 @@ public LatestReleases latestsReleases() { public String githubIssues() { return githubManager.getIssues(); } + + String mavenUrl="https://search.maven.org/solrsearch/select?q=g:io.openliberty.tools+AND+a:liberty-maven-plugin&core=gav&rows=20&wt=json"; + String gradleUrl="https://search.maven.org/solrsearch/select?q=g:io.openliberty.tools+AND+a:liberty-gradle-plugin&core=gav&rows=20&wt=json"; + @GET + @Produces({ "application/json" }) + @Path("start/plugin-versions") + public Response getVersionFromJson() { + try { + String mavenVersion=getJsonData(mavenUrl); + String gradleVersion=getJsonData(gradleUrl); + return Response.ok(new JSONObject() + .put("mavenVersion", mavenVersion) + .put("gradleVersion", gradleVersion) + .toString()) + .build(); + } catch (Exception e) { + e.printStackTrace(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(new JSONObject() + .put("status", "error") + .put("message", "Failed to fetch plugin versions") + .toString()) + .build(); + } + } } diff --git a/src/main/java/io/openliberty/website/SecurityFilter.java b/src/main/java/io/openliberty/website/SecurityFilter.java index 936377809f..0a03ca5950 100644 --- a/src/main/java/io/openliberty/website/SecurityFilter.java +++ b/src/main/java/io/openliberty/website/SecurityFilter.java @@ -109,8 +109,10 @@ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain req.getRequestDispatcher(uri.concat(".gz")).include(req, response); } catch(FileNotFoundException e) { - response.setStatus(HttpServletResponse.SC_NOT_FOUND); - response.sendRedirect("/404.html"); + response.reset(); + response.setHeader("Content-Type", "text/html"); + response.sendError(404); + return; } } } else if (uri.startsWith("/api/builds/") || uri.startsWith("/api/github/")) {