Skip to content

Commit

Permalink
Merge pull request OpenLiberty#1844 from arunvenmany-ibm/spring-boot-…
Browse files Browse the repository at this point in the history
…application-node-bug-fix

<springBootApplication/> issue fix
  • Loading branch information
cherylking authored Nov 20, 2024
2 parents 333f9c9 + d7c2400 commit 6198492
Show file tree
Hide file tree
Showing 15 changed files with 649 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.buildResult = failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>springboot-3-appsdirectory-apps-fail-it</artifactId>
<version>1.0.0.Final</version>
<packaging>jar</packaging>

<parent>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- Support for JDK 9 and above-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.3</version>
<!-- Test support for classifier configuration parameter -->
<configuration>
<classifier>exec</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>@pom.version@</version>

<!-- Specify configuration, executions for liberty-maven-plugin -->
<configuration>
<serverName>test</serverName>
<runtimeArtifact>
<groupId>com.ibm.websphere.appserver.runtime</groupId>
<artifactId>wlp-jakartaee10</artifactId>
<version>23.0.0.10</version>
<type>zip</type>
</runtimeArtifact>
<appsDirectory>apps</appsDirectory>
<deployPackages>spring-boot-project</deployPackages>
</configuration>

<executions>
<execution>
<id>stop-server-before-clean</id>
<phase>pre-clean</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>create-server</id>
<phase>prepare-package</phase>
<goals>
<goal>install-server</goal>
<goal>create</goal>
<goal>install-feature</goal>
</goals>
</execution>
<execution>
<id>install-apps</id>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>test-start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>test-start</goal>
</goals>
</execution>
<execution>
<id>test-stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>test-stop</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<runOrder>alphabetical</runOrder>
</configuration>
<executions>
<execution>
<id>default-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>default-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* (C) Copyright IBM Corporation 2024.
*
* 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 application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class SpringBootApp {
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
}

@RequestMapping("/spring")
public String hello() {
return "HELLO SPRING BOOT!!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

<!-- Enable features -->
<featureManager>
<feature>springBoot-3.0</feature>
<feature>servlet-6.0</feature>
</featureManager>

<!-- To access this server from a remote client add a host attribute to
the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443"
id="defaultHttpEndpoint" />


<springBootApplication id="guide-spring-boot"
location="guide-spring-boot-0.1.0.jar"
name="guide-spring-boot" />

<springBootApplication id="guide-spring-boot"
location="guide-spring-boot-0.2.0.jar"
name="guide-spring-boot" />

</server>
1 change: 1 addition & 0 deletions liberty-maven-plugin/src/it/springboot-3-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<modules>
<module>springboot-3-appsdirectory-apps-it</module>
<module>springboot-3-appsdirectory-dropins-it</module>
<module>springboot-3-appsdirectory-server-xml-springboot-node-it</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,56 @@
import static org.junit.Assert.*;

import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Objects;

import org.junit.Test;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

public class InstallSpringBoot30AppIT {

@Test
public void testThinApplicationExistsInAppsDirectory() throws Exception {

File f = new File("target/liberty/wlp/usr/servers/test/apps/thin-springboot-3-appsdirectory-apps-it-1.0.0.Final-exec.jar");
assertTrue(f.getCanonicalFile() + " doesn't exist. Plugin failed to place the file at right destination.", f.exists());
File f2 = new File("target/liberty/wlp/usr/servers/test/configDropins/defaults");
assertTrue(f2.getCanonicalFile() + " folder doesn't exist. Plugin failed to create the config dropins folder ", f2.exists());
assertTrue(f2.getCanonicalFile() + " folder doesn't contain any files. Plugin failed to place config xml at right destination.", f2.list()!=null && Objects.requireNonNull(f2.list()).length == 1);
File configDropinsFile=new File("target/liberty/wlp/usr/servers/test/configDropins/defaults", Arrays.stream(Objects.requireNonNull(f2.list())).findFirst().get());
try (FileInputStream input = new FileInputStream(configDropinsFile)) {
// get configDropins XML Document
DocumentBuilderFactory inputBuilderFactory = DocumentBuilderFactory.newInstance();
inputBuilderFactory.setIgnoringComments(true);
inputBuilderFactory.setCoalescing(true);
inputBuilderFactory.setIgnoringElementContentWhitespace(true);
inputBuilderFactory.setValidating(false);
inputBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
inputBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
DocumentBuilder inputBuilder = inputBuilderFactory.newDocumentBuilder();
Document inputDoc=inputBuilder.parse(input);

// parse configDropins XML Document
XPath xPath = XPathFactory.newInstance().newXPath();
String expression = "/server/springBootApplication";
NodeList nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
assertTrue("Number of <springBootApplication/> element ==>", nodes.getLength()>0);

Node node = nodes.item(0);
Element element = (Element)node;
assertEquals("Value of the 1st <springBootApplication/> ==>"+element.getAttribute("location"), "thin-springboot-3-appsdirectory-apps-it-1.0.0.Final-exec.jar", element.getAttribute("location"));
}
}

@Test
Expand Down
Loading

0 comments on commit 6198492

Please sign in to comment.