-
Notifications
You must be signed in to change notification settings - Fork 33
adding code changes to accept spring boot jars without release tag in… #521
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
Merged
venmanyarun
merged 2 commits into
OpenLiberty:main
from
venmanyarun:spring_boot_4_support
Jun 3, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
src/test/java/io/openliberty/tools/common/plugins/util/SpringBootUtilTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| /** | ||
| * (C) Copyright IBM Corporation 2026. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.openliberty.tools.common.plugins.util; | ||
|
|
||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
| import java.util.jar.Attributes; | ||
| import java.util.jar.JarEntry; | ||
| import java.util.jar.JarOutputStream; | ||
| import java.util.jar.Manifest; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| /** | ||
| * Unit tests for SpringBootUtil | ||
| * Tests both Tier 1 (manifest) and Tier 2 (regex) detection for Spring Boot applications | ||
| */ | ||
| public class SpringBootUtilTest { | ||
|
|
||
| @Rule | ||
| public TemporaryFolder tempFolder = new TemporaryFolder(); | ||
|
|
||
| // ========== Manifest Attributes based Detection Tests ========== | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot2_WithManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithManifest("2.7.18", "BOOT-INF/lib/spring-boot-2.7.18.RELEASE.jar"); | ||
| assertTrue("Should detect Spring Boot 2.7.18 via manifest", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot3_WithManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithManifest("3.1.3", "BOOT-INF/lib/spring-boot-3.1.3.jar"); | ||
| assertTrue("Should detect Spring Boot 3.1.3 via manifest", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot4_WithManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithManifest("4.0.0", "BOOT-INF/lib/spring-boot-4.0.0.jar"); | ||
| assertTrue("Should detect Spring Boot 4.0.0 via manifest", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot4_War_WithManifest() throws Exception { | ||
| File testWar = createSpringBootWarWithManifest("4.0.0", "WEB-INF/lib/spring-boot-4.0.0.jar"); | ||
| assertTrue("Should detect Spring Boot 4.0.0 WAR via manifest", | ||
| SpringBootUtil.isSpringBootUberJar(testWar)); | ||
| } | ||
|
|
||
| // ========== Regex based Detection Tests ( Fallback) ========== | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot2_WithoutManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithoutManifest("BOOT-INF/lib/spring-boot-2.7.18.RELEASE.jar"); | ||
| assertTrue("Should detect Spring Boot 2.7.18.RELEASE via regex", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot3_WithoutManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithoutManifest("BOOT-INF/lib/spring-boot-3.1.3.jar"); | ||
| assertTrue("Should detect Spring Boot 3.1.3 via regex", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot4_WithoutManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithoutManifest("BOOT-INF/lib/spring-boot-4.0.0.jar"); | ||
| assertTrue("Should detect Spring Boot 4.0.0 via regex - CRITICAL TEST", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot3_4_WithoutManifest() throws Exception { | ||
| File testJar = createSpringBootJarWithoutManifest("BOOT-INF/lib/spring-boot-3.4.13.jar"); | ||
| assertTrue("Should detect Spring Boot 3.4.13 via regex", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_SpringBoot4_War_WithoutManifest() throws Exception { | ||
| File testWar = createSpringBootJarWithoutManifest("WEB-INF/lib/spring-boot-4.0.0.jar"); | ||
| assertTrue("Should detect Spring Boot 4.0.0 WAR via regex", | ||
| SpringBootUtil.isSpringBootUberJar(testWar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_MultiDigitVersion() throws Exception { | ||
| File testJar = createSpringBootJarWithoutManifest("BOOT-INF/lib/spring-boot-10.5.3.jar"); | ||
| assertTrue("Should detect Spring Boot 10.5.3 via regex - future-proof test", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| // ========== Negative Tests ========== | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_RegularJar() throws Exception { | ||
| File testJar = tempFolder.newFile("regular.jar"); | ||
| try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(testJar))) { | ||
| Manifest manifest = new Manifest(); | ||
| manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); | ||
| jos.putNextEntry(new JarEntry("com/example/Main.class")); | ||
| jos.write(new byte[0]); | ||
| jos.closeEntry(); | ||
| } | ||
| assertFalse("Should NOT detect regular JAR as Spring Boot", | ||
| SpringBootUtil.isSpringBootUberJar(testJar)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_NullFile() { | ||
| assertFalse("Should return false for null file", | ||
| SpringBootUtil.isSpringBootUberJar(null)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsSpringBootUberJar_NonExistentFile() { | ||
| File nonExistent = new File("non-existent-file.jar"); | ||
| assertFalse("Should return false for non-existent file", | ||
| SpringBootUtil.isSpringBootUberJar(nonExistent)); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a Spring Boot JAR with manifest attributes | ||
| */ | ||
| private File createSpringBootJarWithManifest(String version, String springBootJarPath) throws Exception { | ||
| File testJar = tempFolder.newFile("spring-boot-" + version + "-test.jar"); | ||
|
|
||
| try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(testJar))) { | ||
| // Create manifest with Spring Boot attributes | ||
| Manifest manifest = new Manifest(); | ||
| manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); | ||
| manifest.getMainAttributes().putValue(SpringBootUtil.BOOT_VERSION_ATTRIBUTE, version); | ||
| manifest.getMainAttributes().putValue(SpringBootUtil.BOOT_START_CLASS_ATTRIBUTE, "com.example.Application"); | ||
|
|
||
| // Write manifest | ||
| JarEntry manifestEntry = new JarEntry("META-INF/MANIFEST.MF"); | ||
| jos.putNextEntry(manifestEntry); | ||
| manifest.write(jos); | ||
| jos.closeEntry(); | ||
|
|
||
| // Add spring-boot jar entry | ||
| JarEntry springBootEntry = new JarEntry(springBootJarPath); | ||
| jos.putNextEntry(springBootEntry); | ||
| jos.write(new byte[0]); | ||
| jos.closeEntry(); | ||
| } | ||
|
|
||
| return testJar; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a Spring Boot WAR with manifest attributes | ||
| */ | ||
| private File createSpringBootWarWithManifest(String version, String springBootJarPath) throws Exception { | ||
| File testWar = tempFolder.newFile("spring-boot-" + version + "-test.war"); | ||
|
|
||
| try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(testWar))) { | ||
| // Create manifest with Spring Boot attributes | ||
| Manifest manifest = new Manifest(); | ||
| manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); | ||
| manifest.getMainAttributes().putValue(SpringBootUtil.BOOT_VERSION_ATTRIBUTE, version); | ||
| manifest.getMainAttributes().putValue(SpringBootUtil.BOOT_START_CLASS_ATTRIBUTE, "com.example.Application"); | ||
|
|
||
| // Write manifest | ||
| JarEntry manifestEntry = new JarEntry("META-INF/MANIFEST.MF"); | ||
| jos.putNextEntry(manifestEntry); | ||
| manifest.write(jos); | ||
| jos.closeEntry(); | ||
|
|
||
| // Add spring-boot jar entry | ||
| JarEntry springBootEntry = new JarEntry(springBootJarPath); | ||
| jos.putNextEntry(springBootEntry); | ||
| jos.write(new byte[0]); | ||
| jos.closeEntry(); | ||
| } | ||
|
|
||
| return testWar; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a Spring Boot JAR WITHOUT manifest attributes | ||
| * This forces the regex-based detection to be used | ||
| */ | ||
| private File createSpringBootJarWithoutManifest(String springBootJarPath) throws Exception { | ||
| File testJar = tempFolder.newFile("spring-boot-no-manifest-test.jar"); | ||
|
|
||
| try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(testJar))) { | ||
| // Create manifest WITHOUT Spring Boot attributes | ||
| Manifest manifest = new Manifest(); | ||
| manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); | ||
| // NO Spring-Boot-Version attribute | ||
| // NO Start-Class attribute | ||
|
|
||
| // Write manifest | ||
| JarEntry manifestEntry = new JarEntry("META-INF/MANIFEST.MF"); | ||
| jos.putNextEntry(manifestEntry); | ||
| manifest.write(jos); | ||
| jos.closeEntry(); | ||
|
|
||
| // Add spring-boot jar entry - this is what regex will detect | ||
| JarEntry springBootEntry = new JarEntry(springBootJarPath); | ||
| jos.putNextEntry(springBootEntry); | ||
| jos.write(new byte[0]); | ||
| jos.closeEntry(); | ||
| } | ||
|
|
||
| return testJar; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.