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

Add task for installing interim fixes #165

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -103,7 +102,6 @@
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
Expand Down
2 changes: 1 addition & 1 deletion src/it/tests/deploy-eba-it/windows/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<wlp:server ref="testServer" operation="stop" />

<wlp:clean ref="testServer" apps="true" dropins="true" />
<wlp:clean ref="testServer" apps="true" dropins="true" logs="false" workarea="false" />

</target>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* (C) Copyright IBM Corporation 2023.
*
* 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.ant;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Java;

/*
* Install Liberty interim fix(es) task.
*/
public class InstallLibertyInterimFixTask extends AbstractTask {

private File interimFixDirectory;
private boolean suppressInfo = true;

@Override
public void execute() throws BuildException {
super.initTask();

try {
doExecute();
} catch (Exception e) {
throw new BuildException(e);
}
}

private void doExecute() throws Exception {

if (interimFixDirectory == null) {
throw new BuildException("The interimFixDirectory was not specified.");
}

if (!interimFixDirectory.exists() || !interimFixDirectory.isDirectory()) {
throw new BuildException("The interimFixDirectory does not exist or is not a directory.");
}

// Find all .jar files in the ifixDir
File[] jarFiles = findFilesEndsWithInDirectory(interimFixDirectory, ".jar");
if (jarFiles == null || jarFiles.length == 0) {
throw new BuildException("The interimFixDirectory does not contain any interim fix JAR files.");
}

List<String> failedInstallIfixes = new ArrayList<String>();

for (File nextJarFile : jarFiles) {
if (!installInterimFix(nextJarFile)) {
failedInstallIfixes.add(nextJarFile.getName());
}
}

if (!failedInstallIfixes.isEmpty()) {
throw new BuildException("The following Liberty interim fixes failed to install: "+failedInstallIfixes.toString());
}
}

protected boolean installInterimFix(File jarFile) throws Exception {
Java java = (Java) getProject().createTask("java");
java.setJar(jarFile);
java.setFork(true);
java.createArg().setValue("-installLocation");
java.createArg().setValue(installDir.getCanonicalPath());
if (suppressInfo) {
java.createArg().setValue("-suppressInfo");
}

int exitCode = java.executeJava();
return (exitCode == 0);
}

/**
* Search the dir path for all files that end with a name or extension. If none are found,
* an empty List is returned.
*
* @param dir File dir to search under
* @param ext String to match
* @return File[] collection of File that match the given ext in the specified dir.
*/
protected File[] findFilesEndsWithInDirectory(File dir, String ext) throws IOException {

final String extension = ext;
File[] matchingFiles = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(extension);
}
});

return matchingFiles;
}

public File getInterimFixDirectory() {
return interimFixDirectory;
}

public void setInterimFixDirectory(File interimFixDirectory) {
this.interimFixDirectory = interimFixDirectory;
}

public boolean isSuppressInfo() {
return suppressInfo;
}

public void setSuppressInfo(boolean suppressInfo) {
this.suppressInfo = suppressInfo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void install(InstallLibertyTask task, File cacheDir, String url) throws
task.checkLicenseSet();

// download Liberty jar
task.downloadFile(downloadURL, cachedFile);
task.downloadFile(downloadURL, cachedFile, true);

// do license check
task.checkLicense(getLicenseCode(cachedFile));
Expand All @@ -91,7 +91,7 @@ private void install(InstallLibertyTask task, File cacheDir, String url) throws
task.installLiberty(cachedFile);
} else {
// download zip file
task.downloadFile(downloadURL, cachedFile);
task.downloadFile(downloadURL, cachedFile, true);

// unzip
task.unzipLiberty(cachedFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ private void doExecute() throws Exception {
}

protected void downloadFile(URL source, File dest) throws IOException {
downloadFile(source, dest, false);
}

protected void downloadFile(URL source, File dest, boolean skipExisting) throws IOException {
if (offline) {
offlineDownload(source, dest);
} else {
onlineDownload(source, dest);
onlineDownload(source, dest, skipExisting);
}
}

Expand All @@ -113,13 +117,15 @@ private void offlineDownload(URL source, File dest) throws IOException {
}
}

private void onlineDownload(URL source, File dest) throws IOException {
private void onlineDownload(URL source, File dest, boolean skipExisting) throws IOException {
Get get = (Get) getProject().createTask("get");
DownloadProgress progress = null;
if (verbose) {
progress = new Get.VerboseProgress(System.out);
}
get.setUseTimestamp(true);
if (skipExisting) {
get.setSkipExisting(true);
}
get.setUsername(username);
get.setPassword(password);
get.setMaxTime(maxDownloadTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void install(InstallLibertyTask task) throws Exception {
String versionUrl = baseUrl + version + "/";
URL runtimeInfoUrl = new URL(versionUrl + "info.json");
File runtimeInfoFile = new File(cacheDir, version + ".json");
task.downloadFile(runtimeInfoUrl, runtimeInfoFile);
task.downloadFile(runtimeInfoUrl, runtimeInfoFile, true);

// Parse JSON
InputStream runtimeInfoIs = new FileInputStream(runtimeInfoFile);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void install(InstallLibertyTask task) throws Exception {

URL runtimeUrl = new URL(runtimeUrlString);
File runtimeFile = new File(versionCacheDir, InstallUtils.getFile(runtimeUrl));
task.downloadFile(runtimeUrl, runtimeFile);
task.downloadFile(runtimeUrl, runtimeFile, true);

if(runtimeUrlString.endsWith(".jar")) {
task.installLiberty(runtimeFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@ public void install(InstallLibertyTask task) throws Exception {
// download license
URL licenseURL = new URL(selectedVersion.getLicenseUri());
File licenseFile = new File(versionCacheDir, InstallUtils.getFile(licenseURL));
task.downloadFile(licenseURL, licenseFile);
task.downloadFile(licenseURL, licenseFile, true);

// do license check
task.checkLicense(InstallUtils.getLicenseCode(licenseFile, LICENSE_REGEX));

// download Liberty jar
URL libertyURL = new URL(uri);
File libertyFile = new File(versionCacheDir, InstallUtils.getFile(libertyURL));
task.downloadFile(libertyURL, libertyFile);
task.downloadFile(libertyURL, libertyFile, true);

// install Liberty jar
task.installLiberty(libertyFile);
} else if(uri.endsWith(".zip")) {
// download zip file
URL libertyURL = new URL(uri);
File libertyFile = new File(versionCacheDir, InstallUtils.getFile(libertyURL));
task.downloadFile(libertyURL, libertyFile);
task.downloadFile(libertyURL, libertyFile, true);

// unzip
task.unzipLiberty(libertyFile);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/io/openliberty/tools/ant/antlib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<taskdef classname="io.openliberty.tools.ant.UninstallFeatureTask" name="uninstall-feature" />
<taskdef classname="io.openliberty.tools.ant.CleanTask" name="clean" />
<taskdef classname="io.openliberty.tools.ant.install.InstallLibertyTask" name="install-liberty" />
<taskdef classname="io.openliberty.tools.ant.InstallLibertyInterimFixTask" name="install-fix" />
<taskdef classname="io.openliberty.tools.ant.jsp.CompileJSPs" name="compileJSPs"/>
<taskdef classname="io.openliberty.tools.ant.SpringBootUtilTask" name="springBootUtil"/>
</antlib>