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

Groovy File deprecation fix part 1 #903

Merged
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
4 changes: 2 additions & 2 deletions src/main/groovy/io/openliberty/tools/gradle/Liberty.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2014, 2021.
* (C) Copyright IBM Corporation 2014, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -175,7 +175,7 @@ class Liberty implements Plugin<Project> {
return installDir
} else if (project.liberty.installDir == null) {
if (project.liberty.baseDir == null) {
return new File(project.buildDir, 'wlp')
return new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'wlp')
} else {
return new File(project.liberty.baseDir, 'wlp')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2021, 2023.
* (C) Copyright IBM Corporation 2021, 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 @@ -23,13 +23,12 @@ import io.openliberty.tools.common.plugins.util.PluginExecutionException
import io.openliberty.tools.common.plugins.util.PluginScenarioException
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil
import io.openliberty.tools.gradle.utils.ArtifactDownloadUtil
import java.util.Map.Entry
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.options.Option
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.api.artifacts.Configuration

import java.util.Map.Entry

public class AbstractFeatureTask extends AbstractServerTask {

Expand Down Expand Up @@ -297,7 +296,7 @@ public class AbstractFeatureTask extends AbstractServerTask {
private void createNewInstallFeatureUtil(Set<String> pluginListedEsas, List<ProductProperties> propertiesList, String openLibertyVerion, String containerName, List<String> additionalJsons, Collection<Map<String,String>> keyMap) throws PluginExecutionException {
try {
logger.info("Feature signature verify option: " + server.features.verify)
util = new InstallFeatureTaskUtil(getInstallDir(project), project.getBuildDir(), server.features.from, server.features.to, pluginListedEsas, propertiesList, openLibertyVerion, containerName, additionalJsons, server.features.verify, keyMap)
util = new InstallFeatureTaskUtil(getInstallDir(project), project.getLayout().getBuildDirectory().getAsFile().get(), server.features.from, server.features.to, pluginListedEsas, propertiesList, openLibertyVerion, containerName, additionalJsons, server.features.verify, keyMap)
cherylking marked this conversation as resolved.
Show resolved Hide resolved
} catch (PluginScenarioException e) {
logger.debug("Exception received: " + e.getMessage(), (Throwable) e)
logger.debug("Installing features from installUtility.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2017, 2023.
* (C) Copyright IBM Corporation 2017, 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 @@ -16,13 +16,13 @@
package io.openliberty.tools.gradle.tasks

import io.openliberty.tools.gradle.Liberty

import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.Task
import org.gradle.api.artifacts.Dependency
import org.gradle.api.tasks.Internal
import groovy.xml.XmlParser

abstract class AbstractLibertyTask extends DefaultTask {

Expand All @@ -35,7 +35,7 @@ abstract class AbstractLibertyTask extends DefaultTask {
protected boolean isInstallDirChanged(Project project) {

XmlParser pluginXmlParser = new XmlParser()
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.buildDir, 'liberty-plugin-config.xml'))
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml'))
if (!libertyPluginConfig.getAt('installDirectory').isEmpty()) {
Node installDirNode = libertyPluginConfig.getAt('installDirectory').get(0)
File previousInstallDir = new File(installDirNode.text())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,34 @@
package io.openliberty.tools.gradle.tasks

import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlParser
import groovy.xml.XmlNodePrinter
import io.openliberty.tools.ant.ServerTask
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.ServerFeatureUtil
import io.openliberty.tools.gradle.utils.CommonLogger

import org.apache.commons.io.FileUtils
import org.apache.commons.io.FilenameUtils
import org.apache.commons.io.filefilter.FileFilterUtils
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.tasks.bundling.War
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.bundling.War
import org.gradle.plugins.ear.Ear

import javax.xml.parsers.ParserConfigurationException
import javax.xml.transform.TransformerException
import java.nio.file.Files
import java.nio.file.StandardCopyOption

import org.apache.commons.io.FilenameUtils
import org.apache.commons.io.filefilter.FileFilterUtils

import io.openliberty.tools.ant.ServerTask
import io.openliberty.tools.common.plugins.config.ServerConfigXmlDocument;

import java.util.ArrayList
import java.util.List
import java.util.HashMap
import java.util.Map
import java.util.Map.Entry
import java.util.Properties
import java.util.HashSet
import java.util.Set
import java.util.EnumSet
import java.util.regex.Pattern
import java.util.regex.Matcher

import javax.xml.transform.TransformerException
import javax.xml.parsers.ParserConfigurationException
import io.openliberty.tools.common.plugins.util.DevUtil;
import java.util.regex.Pattern

abstract class AbstractServerTask extends AbstractLibertyTask {

Expand Down Expand Up @@ -742,7 +731,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask {

protected void writeServerPropertiesToXml(Project project) {
XmlParser pluginXmlParser = new XmlParser()
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.buildDir, 'liberty-plugin-config.xml'))
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml'))
if (libertyPluginConfig.getAt('servers').isEmpty()) {
libertyPluginConfig.appendNode('servers')
} else {
Expand All @@ -758,14 +747,14 @@ abstract class AbstractServerTask extends AbstractLibertyTask {

libertyPluginConfig.getAt('servers')[0].append(serverNode)

new File( project.buildDir, 'liberty-plugin-config.xml' ).withWriter('UTF-8') { output ->
new File( project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml' ).withWriter('UTF-8') { output ->
output << new StreamingMarkupBuilder().bind { mkp.xmlDeclaration(encoding: 'UTF-8', version: '1.0' ) }
XmlNodePrinter printer = new XmlNodePrinter( new PrintWriter(output) )
printer.preserveWhitespace = true
printer.print( libertyPluginConfig )
}

logger.info ("Adding Liberty plugin config info to ${project.buildDir}/liberty-plugin-config.xml.")
logger.info ("Adding Liberty plugin config info to ${project.getLayout().getBuildDirectory().getAsFile().get()}/liberty-plugin-config.xml.")
}

private void writeBootstrapProperties(File file, Properties properties, Map<String, String> projectProperties) throws IOException {
Expand Down Expand Up @@ -1109,7 +1098,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
File appFile = depArtifact
if (dep instanceof ModuleDependency && server.stripVersion && depArtifact.getName().contains(dep.getVersion())) {
String noVersionName = depArtifact.getName().minus("-" + dep.getVersion()) //Assuming default Gradle naming scheme
File noVersionDependencyFile = new File(project.getBuildDir(), 'libs/' + noVersionName) //Copying the file to build/libs with no version
File noVersionDependencyFile = new File(project.getLayout().getBuildDirectory().asFile.get(), 'libs/' + noVersionName) //Copying the file to build/libs with no version
FileUtils.copyFile(depArtifact, noVersionDependencyFile)
appFile = noVersionDependencyFile
}
Expand Down Expand Up @@ -1220,7 +1209,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask {
}

if (container) {
File devcDestDir = new File(new File(project.buildDir, DevUtil.DEVC_HIDDEN_FOLDER), appsDir)
File devcDestDir = new File(new File(project.getLayout().getBuildDirectory().getAsFile().get(), DevUtil.DEVC_HIDDEN_FOLDER), appsDir)
return (new File(devcDestDir, looseConfigFileName));
} else {
File destDir = new File(getServerDir(project), appsDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package io.openliberty.tools.gradle.tasks

import io.openliberty.tools.gradle.Liberty

import org.gradle.api.Project
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.logging.LogLevel
import org.gradle.api.Project
import groovy.xml.XmlParser

class CreateTask extends AbstractServerTask {

Expand Down Expand Up @@ -70,7 +69,7 @@ class CreateTask extends AbstractServerTask {

@InputFile
File getPluginConfigXml() {
return new File(project.buildDir, 'liberty-plugin-config.xml')
return new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml')
}

@TaskAction
Expand All @@ -97,12 +96,12 @@ class CreateTask extends AbstractServerTask {
}

protected boolean isServerDirChanged(Project project) {
if (!project.buildDir.exists() || !(new File(project.buildDir, 'liberty-plugin-config.xml')).exists()) {
if (!project.getLayout().getBuildDirectory().getAsFile().get().exists() || !(new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml')).exists()) {
return false
}

XmlParser pluginXmlParser = new XmlParser()
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.buildDir, 'liberty-plugin-config.xml'))
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml'))
if (!libertyPluginConfig.getAt('serverDirectory').isEmpty()) {
File currentDir = getServerDir(project)
File previousDir = new File(libertyPluginConfig.getAt('serverDirectory')[0].value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class DeployTask extends AbstractServerTask {
File destDir = new File(getServerDir(project), appsDir)
File looseConfigFile = new File(destDir, looseConfigFileName)

File devcDestDir = new File(new File(project.buildDir, DevUtil.DEVC_HIDDEN_FOLDER), appsDir)
File devcDestDir = new File(new File(project.getLayout().getBuildDirectory().getAsFile().get(), DevUtil.DEVC_HIDDEN_FOLDER), appsDir)
File devcLooseConfigFile = new File(devcDestDir, looseConfigFileName)

LooseConfigData config = new LooseConfigData()
Expand Down Expand Up @@ -312,8 +312,8 @@ class DeployTask extends AbstractServerTask {

if (server.deploy.copyLibsDirectory == null) { // in container mode, copy dependencies from .m2 dir to the build dir to mount in container
// if buildDir is subdirectory of projectDir, use buildDir/libs. Otherwise use projectDir/build/libs since it must be under the project root in order to make use of DEVMODE_PROJECT_ROOT
if (project.getBuildDir().getCanonicalFile().toPath().startsWith(project.getProjectDir().getCanonicalFile().toPath())) {
server.deploy.copyLibsDirectory = new File(project.getBuildDir(), LIBS);
if (project.getLayout().getBuildDirectory().getAsFile().get().getCanonicalFile().toPath().startsWith(project.getProjectDir().getCanonicalFile().toPath())) {
server.deploy.copyLibsDirectory = new File(project.getLayout().getBuildDirectory().getAsFile().get(), LIBS);
logger.debug("Setting copyLibsDirectory to " + server.deploy.copyLibsDirectory);
} else {
server.deploy.copyLibsDirectory = new File(project.getProjectDir(), BUILD_LIBS);
Expand Down Expand Up @@ -343,7 +343,7 @@ class DeployTask extends AbstractServerTask {
addWarEmbeddedLib(looseWar.getDocumentRoot(), looseWar, task);

//add Manifest file
File manifestFile = new File(project.buildDir.getAbsolutePath() + "/tmp/war/MANIFEST.MF")
File manifestFile = new File(project.getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath() + "/tmp/war/MANIFEST.MF")
looseWar.addManifestFile(manifestFile)
}

Expand Down Expand Up @@ -406,12 +406,12 @@ class DeployTask extends AbstractServerTask {
LooseEarApplication looseEar = new LooseEarApplication(task, config);
looseEar.addSourceDir();
looseEar.addApplicationXmlFile();

//Checking ear plugin dependency configurations to determine loose-ear content
processDeployDependencies(looseEar, task)
processEarlibDependencies(looseEar, task)

File manifestFile = new File(project.buildDir.getAbsolutePath() + "/tmp/ear/MANIFEST.MF")
File manifestFile = new File(project.getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath() + "/tmp/ear/MANIFEST.MF")
looseEar.addManifestFile(manifestFile)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2019, 2023.
* (C) Copyright IBM Corporation 2019, 2023, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,6 +49,7 @@ import io.openliberty.tools.common.plugins.util.BinaryScannerUtil
import java.util.concurrent.TimeUnit
import java.util.Map.Entry
import java.nio.file.Path;
import groovy.xml.XmlParser

class DevTask extends AbstractFeatureTask {

Expand Down Expand Up @@ -1253,7 +1254,7 @@ class DevTask extends AbstractFeatureTask {

// Instantiate util before any child gradle tasks launched so it can help find available port if needed
try {
this.util = new DevTaskUtil(project.buildDir, serverInstallDir, getUserDir(project, serverInstallDir),
this.util = new DevTaskUtil(project.getLayout().getBuildDirectory().getAsFile().get(), serverInstallDir, getUserDir(project, serverInstallDir),
serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getRootDir(),
resourceDirs, changeOnDemandTestsAction.booleanValue(), hotTests.booleanValue(), skipTests.booleanValue(), skipInstallFeature.booleanValue(), artifactId, serverStartTimeout.intValue(),
verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(),
Expand Down Expand Up @@ -1400,9 +1401,9 @@ class DevTask extends AbstractFeatureTask {
}

private boolean isInstallDirChanged(Project project, File currentInstallDir) {
if (project.buildDir.exists() && new File(project.buildDir, 'liberty-plugin-config.xml').exists()) {
if (project.getLayout().getBuildDirectory().getAsFile().get().exists() && new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml').exists()) {
XmlParser pluginXmlParser = new XmlParser()
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.buildDir, 'liberty-plugin-config.xml'))
Node libertyPluginConfig = pluginXmlParser.parse(new File(project.getLayout().getBuildDirectory().getAsFile().get(), 'liberty-plugin-config.xml'))
if (!libertyPluginConfig.getAt('installDirectory').isEmpty()) {
Node installDirNode = libertyPluginConfig.getAt('installDirectory').get(0)
String installDirValue = installDirNode.text()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2014, 2023.
* (C) Copyright IBM Corporation 2014, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,7 +102,7 @@ class InstallFeatureTask extends AbstractFeatureTask {
void installFeatureFromAnt() {
// Set default server.outputDir to liberty-alt-output-dir for installFeature task.
if (getOutputDir(project).equals(getUserDir(project).toString() + "/servers")) {
server.outputDir = new File(project.getBuildDir(), "liberty-alt-output-dir");
server.outputDir = new File(project.getLayout().getBuildDirectory().getAsFile().get(), "liberty-alt-output-dir");
}

def params = buildAntParams()
Expand Down
Loading
Loading