Skip to content
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

Making change to create thin application with same name as provided i… #921

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.openliberty.tools.common.plugins.config.ApplicationXmlDocument
import io.openliberty.tools.common.plugins.config.ServerConfigDocument
import io.openliberty.tools.common.plugins.config.ServerConfigXmlDocument
import io.openliberty.tools.common.plugins.util.DevUtil
import io.openliberty.tools.common.plugins.util.PluginExecutionException
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil
import io.openliberty.tools.gradle.utils.CommonLogger
import org.apache.commons.io.FileUtils
Expand Down Expand Up @@ -506,8 +507,13 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
}

protected ServerConfigDocument getServerConfigDocument(CommonLogger log, File serverXML, Map<String, File> libertyDirPropertyFiles) throws IOException {

if (scd == null || !scd.getOriginalServerXMLFile().getCanonicalPath().equals(serverXML.getCanonicalPath())) {
scd = new ServerConfigDocument(log, serverXML, libertyDirPropertyFiles)
try {
scd = new ServerConfigDocument(log, serverXML, libertyDirPropertyFiles);
} catch (PluginExecutionException e) {
throw new GradleException(e.getMessage());
}
}

return scd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,23 @@ class DeployTask extends AbstractServerTask {

private String invokeThinOperation(String appsDir) {
Map<String, String> params = buildLibertyMap(project);

String targetThinAppPath
project.ant.taskdef(name: 'invokeUtil',
classname: 'io.openliberty.tools.ant.SpringBootUtilTask',
classpath: project.buildscript.configurations.classpath.asPath)

String sourceAppPath = getArchiveOutputPath()
params.put('sourceAppPath', sourceAppPath)
params.put('targetLibCachePath', getTargetLibCachePath())
String targetThinAppPath = getTargetThinAppPath(appsDir, "thin-" + sourceAppPath.substring(sourceAppPath.lastIndexOf(File.separator) + 1))

File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml")
ServerConfigDocument scd = getServerConfigDocument(new CommonLogger(project), serverXML, getLibertyDirectoryPropertyFiles(null))
if (scd != null && scd.getSpringBootAppNodeLocation().isPresent()) {
targetThinAppPath = getTargetThinAppPath(appsDir, scd.getSpringBootAppNodeLocation().get())
} else {
targetThinAppPath = getTargetThinAppPath(appsDir, "thin-" + sourceAppPath.substring(sourceAppPath.lastIndexOf(File.separator) + 1))
}

params.put('targetThinAppPath', targetThinAppPath)
project.ant.invokeUtil(params)
return targetThinAppPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,4 @@ abstract class AbstractIntegrationTest {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ class BaseDevTest extends AbstractIntegrationTest {
}

/**
* Count number of lines that contain the given string
*/
* Count number of lines that contain the given string
*/
protected static int countOccurrences(String str, File file) throws FileNotFoundException, IOException {
int occurrences = 0;
BufferedReader br = new BufferedReader(new FileReader(file));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@
*/
package io.openliberty.tools.gradle

import org.gradle.testkit.runner.BuildResult
import org.junit.*
import org.junit.rules.TestName

import static org.junit.Assert.assertTrue

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 TestSpringBootApplication30 extends AbstractIntegrationTest{
static File resourceDir = new File("build/resources/test/sample.springboot3")
static String buildFilename = "springboot_3_archive.gradle"
Expand Down Expand Up @@ -49,6 +63,32 @@ public class TestSpringBootApplication30 extends AbstractIntegrationTest{
Assert.assertEquals("Did not get expected http response.","Hello!", webPage)
Assert.assertTrue('defaultServer/dropins has app deployed',
new File(buildDir, 'build/wlp/usr/servers/defaultServer/dropins').list().size() == 0)
Assert.assertTrue('defaultServer/configDropins/defaults has no config',
new File(buildDir, 'build/wlp/usr/servers/defaultServer/configDropins/defaults').list().size() == 1)
cherylking marked this conversation as resolved.
Show resolved Hide resolved
File configDropinsDir=new File(buildDir, 'build/wlp/usr/servers/defaultServer/configDropins/defaults')
File configDropinsFile=new File(configDropinsDir,configDropinsDir.list().getAt(0))
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);
Assert.assertTrue("Number of <springBootApplication/> element ==>", nodes.getLength()>0);

Node node = nodes.item(0);
Element element = (Element)node;
Assert.assertEquals("Value of the 1st <springBootApplication/> ==>"+element.getAttribute("location"), "thin-${testName.getMethodName()}-1.0-SNAPSHOT.jar".toString(), element.getAttribute("location"));
}
Assert.assertTrue('no app in apps folder',
new File(buildDir, "build/wlp/usr/servers/defaultServer/apps/thin-${testName.getMethodName()}-1.0-SNAPSHOT.jar").exists() )
} catch (Exception e) {
Expand Down Expand Up @@ -148,4 +188,33 @@ public class TestSpringBootApplication30 extends AbstractIntegrationTest{
throw new AssertionError ("Fail on task deploy.", e)
}
}

@Test
public void test_spring_boot_with_springbootapplication_apps_30() {
try {
runTasks(buildDir, 'deploy', 'libertyStart')

String webPage = new URL("http://localhost:9080").getText()
Assert.assertEquals("Did not get expected http response.","Hello!", webPage)
Assert.assertTrue('defaultServer/dropins has app deployed',
new File(buildDir, 'build/wlp/usr/servers/defaultServer/dropins').list().size() == 0)
Assert.assertTrue('generated thin app name not same as specified in server.xml <SpingBootApplication/> node',
new File(buildDir, "build/wlp/usr/servers/defaultServer/apps/${testName.getMethodName()}-1.0-SNAPSHOT.jar").exists() )
} catch (Exception e) {
throw new AssertionError ("Fail on task deploy.", e)
}
}

@Test
public void test_spring_boot_with_springbootapplication_nodes_apps_30() {
try {
BuildResult result = runTasksFailResult(buildDir, 'deploy', 'libertyStart')
String output = result.getOutput()
assertTrue(output.contains("Found multiple springBootApplication elements specified in the server configuration. Only one springBootApplication can be configured per Liberty server."))
} catch (Exception e) {
throw new AssertionError ("Fail on task deploy.", e)
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<server description="Sample Liberty server">

<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 id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<springBootApplication id="guide-spring-boot"
location="test_spring_boot_with_springbootapplication_apps_30-1.0-SNAPSHOT.jar"
name="guide-spring-boot" />

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<server description="Sample Liberty server">

<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 id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<springBootApplication id="guide-spring-boot"
location="test_spring_boot_with_springbootapplication_apps_30-1.0-SNAPSHOT.jar"
name="guide-spring-boot" />
<springBootApplication id="guide-spring-boot"
location="test_spring_boot_with_springbootapplication_apps_31-1.0-SNAPSHOT.jar"
name="guide-spring-boot" />

</server>
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ dependencies {
liberty {
server {
serverXmlFile = file("src/main/liberty/config/server30.xml")
deploy {
apps = [bootJar]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
buildscript {
ext {
springBootVersion = '3.1.3'
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion"
}
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'liberty'

group = 'liberty.gradle'
version = '1.0-SNAPSHOT'
sourceCompatibility = 17

repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
testImplementation('org.springframework.boot:spring-boot-starter-test')
libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '23.0.0.10'
}

liberty {
server {
serverXmlFile = file("src/main/liberty/alternateConfig/server.xml")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
buildscript {
ext {
springBootVersion = '3.1.3'
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion"
}
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'liberty'

group = 'liberty.gradle'
version = '1.0-SNAPSHOT'
sourceCompatibility = 17

repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
testImplementation('org.springframework.boot:spring-boot-starter-test')
libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '23.0.0.10'
}

liberty {
server {
serverXmlFile = file("src/main/liberty/alternateConfig/server_invalid.xml")
}
}
Loading