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

removing use of deprecated plugin conventions #904

Merged
57 changes: 27 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import java.io.FileOutputStream
import java.io.IOException
import java.io.OutputStream
import java.util.Properties

apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "com.gradle.plugin-publish"
apply plugin: 'base'

archivesBaseName = 'liberty-gradle-plugin'
group = 'io.openliberty.tools'
version = '3.8.4-SNAPSHOT'

base {
archivesName='liberty-gradle-plugin'
cherylking marked this conversation as resolved.
Show resolved Hide resolved
}
repositories {
mavenLocal()
mavenCentral()
Expand Down Expand Up @@ -116,29 +113,29 @@ test {

try {

output = new FileOutputStream("${buildDir}/gradle.properties");
output = new FileOutputStream("${project.getLayout().getBuildDirectory().getAsFile().get()}/gradle.properties");

if (libertyRuntime == "ol") {
runtimeGroup = "io.openliberty"
runtimeArtifactId = "openliberty-runtime"
kernelArtifactId = "openliberty-kernel"
} else {
runtimeGroup = "com.ibm.websphere.appserver.runtime"
runtimeArtifactId = "wlp-javaee7"
kernelArtifactId = "wlp-kernel"
}
if (libertyRuntime == "ol") {
runtimeGroup = "io.openliberty"
runtimeArtifactId = "openliberty-runtime"
kernelArtifactId = "openliberty-kernel"
} else {
runtimeGroup = "com.ibm.websphere.appserver.runtime"
runtimeArtifactId = "wlp-javaee7"
kernelArtifactId = "wlp-kernel"
}

// set the properties value
prop.setProperty("lgpVersion", version)
prop.setProperty("runtimeGroup", runtimeGroup)
prop.setProperty("runtimeArtifactId", runtimeArtifactId)
prop.setProperty("kernelArtifactId", kernelArtifactId)
prop.setProperty("runtimeVersion", runtimeVersion)
prop.setProperty("antVersion", libertyAntVersion)
prop.setProperty("commonVersion", libertyCommonVersion)
// set the properties value
prop.setProperty("lgpVersion", version)
prop.setProperty("runtimeGroup", runtimeGroup)
prop.setProperty("runtimeArtifactId", runtimeArtifactId)
prop.setProperty("kernelArtifactId", kernelArtifactId)
prop.setProperty("runtimeVersion", runtimeVersion)
prop.setProperty("antVersion", libertyAntVersion)
prop.setProperty("commonVersion", libertyCommonVersion)

// save properties to project root folder
prop.store(output, null)
// save properties to project root folder
prop.store(output, null)

} catch (IOException io) {
io.printStackTrace()
Expand Down Expand Up @@ -181,11 +178,11 @@ pluginBundle {
publishing {
publications {
libertyGradle (MavenPublication) {
artifactId = archivesBaseName
artifactId = base.archivesName.get()

from components.java
artifact groovydocJar
artifact sourcesJar
artifact sourcesJar

pom {
name = 'liberty-gradle-plugin'
Expand Down Expand Up @@ -218,7 +215,7 @@ publishing {
}

if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {

if (!version.endsWith("SNAPSHOT")) {
signing {
sign publishing.publications.libertyGradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,11 @@
*/
package io.openliberty.tools.gradle.tasks

import java.io.File;
import java.text.MessageFormat;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.HashSet;

import org.gradle.api.tasks.TaskAction
import io.openliberty.tools.ant.jsp.CompileJSPs
import org.apache.tools.ant.Project
import org.gradle.api.Task
import org.gradle.api.GradleException
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.bundling.War
import org.gradle.api.logging.LogLevel

import org.apache.tools.ant.Project;
cherylking marked this conversation as resolved.
Show resolved Hide resolved
import io.openliberty.tools.ant.jsp.CompileJSPs;

class CompileJSPTask extends AbstractFeatureTask {
protected Project ant = new Project();
Expand Down Expand Up @@ -59,17 +49,20 @@ class CompileJSPTask extends AbstractFeatureTask {
protected void perTaskCompileJSP(Task task) throws Exception {
CompileJSPs compileJsp = new CompileJSPs()
compileJsp.setInstallDir(getInstallDir(project))
compileJsp.setTempdir(project.buildDir)
compileJsp.setDestdir(new File(project.buildDir.getAbsolutePath()+"/classes/java"))
compileJsp.setTempdir(project.getLayout().getBuildDirectory().getAsFile().get())
compileJsp.setDestdir(new File(project.getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath()+"/classes/java"))
compileJsp.setTimeout(project.liberty.jsp.jspCompileTimeout)
// don't delete temporary server dir
compileJsp.setCleanup(false)
compileJsp.setProject(ant)
compileJsp.setTaskName('antlib:net/wasdev/wlp/ant:compileJSPs')

if (project.convention.plugins.war.webAppDirName != null) {
compileJsp.setSrcdir(project.convention.plugins.war.webAppDir)
} else {
War war;
if(project.plugins.hasPlugin("war")){
war = (War)project.war
if ( war.getWebAppDirectory().getAsFile().get() != null) {
compileJsp.setSrcdir( war.getWebAppDirectory().getAsFile().get())
}
}else {
compileJsp.setSrcdir(new File("src/main/webapp"))
}
Set<String> classpath = new HashSet<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class DeployTask extends AbstractServerTask {
}
}

LooseWarApplication looseWar = new LooseWarApplication(task, config)
LooseWarApplication looseWar = new LooseWarApplication(task, config,logger)
looseWar.addSourceDir()
looseWar.addOutputDir(looseWar.getDocumentRoot() , task.classpath.getFiles().toArray()[0], "/WEB-INF/classes/");

Expand Down Expand Up @@ -403,7 +403,7 @@ class DeployTask extends AbstractServerTask {
}

protected void installLooseConfigEar(LooseConfigData config, Task task) throws Exception{
LooseEarApplication looseEar = new LooseEarApplication(task, config);
LooseEarApplication looseEar = new LooseEarApplication(task, config, logger);
looseEar.addSourceDir();
looseEar.addApplicationXmlFile();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
package io.openliberty.tools.gradle.utils

import java.io.File
import io.openliberty.tools.common.plugins.config.LooseApplication
import io.openliberty.tools.common.plugins.config.LooseConfigData
import org.apache.commons.io.FilenameUtils
import org.gradle.api.Project
import org.gradle.plugins.ear.EarPluginConvention
import org.gradle.api.Task
import org.gradle.api.logging.Logger
import org.gradle.plugins.ear.Ear
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.artifacts.Dependency
import org.w3c.dom.Element;
import org.apache.commons.io.FilenameUtils

import io.openliberty.tools.common.plugins.config.LooseConfigData
import io.openliberty.tools.common.plugins.util.PluginExecutionException
import io.openliberty.tools.common.plugins.config.LooseApplication
import org.w3c.dom.Element

public class LooseEarApplication extends LooseApplication {

protected Task task;
protected Logger logger;

public LooseEarApplication(Task task, LooseConfigData config) {
super(task.getProject().getBuildDir().getAbsolutePath(), config)
public LooseEarApplication(Task task, LooseConfigData config, Logger logger) {
super(task.getProject().getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath(), config)
this.task = task
this.logger = logger
}

public void addSourceDir() throws Exception {
File sourceDir = new File(task.getProject().path.replace(":","") + "/" + task.getProject().getConvention().getPlugin(EarPluginConvention.class).getAppDirName())
config.addDir(sourceDir, "/")
if (task.getProject().getPlugins().hasPlugin("ear")) {
Ear ear = (Ear) task.getProject().ear
File sourceDir = new File(task.getProject().path.replace(":","") + "/" + ear.getAppDirectory().getAsFile().get().getPath())
config.addDir(sourceDir, "/")
}
}

public void addApplicationXmlFile() throws Exception {
String applicationName = "/" + task.getProject().getConvention().getPlugin(EarPluginConvention.class).getDeploymentDescriptor().getFileName()
File applicationXmlFile = new File(task.getProject().path.replace(":","") + "/" + task.getProject().getConvention().getPlugin(EarPluginConvention.class).getAppDirName() + "/META-INF/" + applicationName)
if (applicationXmlFile.exists()) {
config.addFile(applicationXmlFile, "/META-INF/application.xml");
String applicationName = "/application.xml"
File applicationXmlFile;
if (task.getProject().getPlugins().hasPlugin("ear")) {
Ear ear = (Ear) task.getProject().ear
if (ear.getDeploymentDescriptor() != null) {
applicationName = "/" + ear.getDeploymentDescriptor().getFileName()
}
applicationXmlFile = new File(task.getProject().path.replace(":", "") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath() + "/META-INF/" + applicationName)
if (applicationXmlFile.exists()) {
config.addFile(applicationXmlFile, "/META-INF/application.xml")
}
}
else {
if (applicationXmlFile == null || !applicationXmlFile.exists()) {
applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName);
cherylking marked this conversation as resolved.
Show resolved Hide resolved
config.addFile(applicationXmlFile, "/META-INF/application.xml");
config.addFile(applicationXmlFile, "/META-INF/application.xml")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
package io.openliberty.tools.gradle.utils;

import java.io.File;
import org.gradle.api.Project;
import org.gradle.api.plugins.WarPluginConvention
import io.openliberty.tools.common.plugins.config.LooseApplication
import io.openliberty.tools.common.plugins.config.LooseConfigData
import org.gradle.api.Task
import org.gradle.api.logging.Logger
import org.gradle.api.tasks.bundling.War

import io.openliberty.tools.common.plugins.config.LooseConfigData
import io.openliberty.tools.common.plugins.util.PluginExecutionException
import io.openliberty.tools.common.plugins.config.LooseApplication

public class LooseWarApplication extends LooseApplication {

protected Task task;
protected Logger logger;

public LooseWarApplication(Task task, LooseConfigData config) {
super(task.getProject().getBuildDir().getAbsolutePath(), config)
public LooseWarApplication(Task task, LooseConfigData config, Logger logger) {
super(task.getProject().getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath(), config)
this.task = task
this.logger = logger
}

public void addSourceDir() throws Exception {
WarPluginConvention wpc = task.getProject().getConvention().findPlugin(WarPluginConvention)
File sourceDir = new File(wpc.getWebAppDir().getAbsolutePath())

War war;
File sourceDir = new File("src/main/webapp")
if (task.getProject().getPlugins().hasPlugin("war")) {
war = (War) task.getProject().war
if (war.getWebAppDirectory().getAsFile().get() != null) {
sourceDir = new File(war.getWebAppDirectory().getAsFile().get().getAbsolutePath())
}
}else {
logger.warn("Could not get the webAppDirectory location from the WAR plugin because it is not configured. Using the default location src/main/webapp instead. Application may not work as expected.")
}
config.addDir(sourceDir, "/")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corporation 2018.
* (C) Copyright IBM Corporation 2018, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,7 @@
*/
package io.openliberty.tools.gradle

import static junit.framework.Assert.assertEquals
import static org.junit.Assert.*
import static org.junit.Assert.assertEquals

import org.junit.Before
import org.junit.BeforeClass
Expand Down
Loading