Skip to content

Commit

Permalink
Merge pull request #406 from cherylking/removeMavenArtifactDependency
Browse files Browse the repository at this point in the history
Remove maven-artifact dependency
  • Loading branch information
cherylking authored Jun 13, 2023
2 parents 069970b + 25b0279 commit 186bfb4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 56 deletions.
9 changes: 3 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>

<dependency.maven-artifact.version>3.6.3</dependency.maven-artifact.version>
</properties>

<dependencies>
Expand All @@ -63,10 +61,9 @@
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${dependency.maven-artifact.version}</version>
<scope>provided</scope>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.2</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2019, 2021.
* (C) Copyright IBM Corporation 2019, 2023.
*
* 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 @@ -45,8 +45,6 @@
import java.nio.file.WatchService;
import java.nio.file.Watchable;
import java.nio.file.attribute.BasicFileAttributes;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -82,7 +80,6 @@

import com.sun.nio.file.SensitivityWatchEventModifier;

import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
Expand All @@ -93,7 +90,6 @@
import org.apache.commons.io.input.CloseShieldInputStream;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -940,9 +936,8 @@ private void checkDockerVersion() throws PluginExecutionException {
return; // can't tell if the version is valid.
}
debug("Detected Docker version >" + dockerVersion);
ComparableVersion minVer = new ComparableVersion(MIN_DOCKER_VERSION);
ComparableVersion curVer = new ComparableVersion(dockerVersion);
if (curVer.compareTo(minVer) < 0) {

if (VersionUtility.compareArtifactVersion(dockerVersion, MIN_DOCKER_VERSION, false) < 0) {
throw new PluginExecutionException("The detected Docker client version number is not supported:" + dockerVersion.trim() + ". Docker version must be 18.03.0 or higher.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -53,26 +49,12 @@
import java.util.logging.Level;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.regex.Matcher;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.commons.io.FileUtils;


/**
* Utility class to install features from Maven repositories.
*/
Expand Down Expand Up @@ -117,7 +99,7 @@ public abstract class InstallFeatureUtil extends ServerFeatureUtil {
private static final String FEATURES_JSON_ARTIFACT_ID = "features";
private static final String TO_USER = "usr";
private static final String MIN_USER_FEATURE_VERSION = "21.0.0.11";
private static final DefaultArtifactVersion MIN_VERSION = new DefaultArtifactVersion(MIN_USER_FEATURE_VERSION);

private String openLibertyVersion;
private static Boolean saveURLCacheStatus = null;

Expand Down Expand Up @@ -162,14 +144,9 @@ public InstallFeatureUtil(File installDirectory, File buildDirectory, String fro
}
downloadedJsons = downloadProductJsons();

//check if the openliberty kernel meets min required version 21.0.0.11
DefaultArtifactVersion version = null;
if(openLibertyVersion != null) {
version = new DefaultArtifactVersion(openLibertyVersion);
}

if (additionalJsons != null && !additionalJsons.isEmpty() && version != null) {
if (version.compareTo(MIN_VERSION) >= 0) {
//check if the openliberty kernel meets min required version 21.0.0.11
if (additionalJsons != null && !additionalJsons.isEmpty() && openLibertyVersion != null) {
if (VersionUtility.compareArtifactVersion(openLibertyVersion, MIN_USER_FEATURE_VERSION, true) >= 0) {
Set<File> groupIDJsons = getAdditionalJsons();
if (groupIDJsons != null) {
downloadedJsons.addAll(groupIDJsons);
Expand Down Expand Up @@ -631,11 +608,9 @@ public void installFeatures(boolean isAcceptLicense, List<String> featuresList)
Map<String, String> featureToExtMap = new HashMap<String, String>();
List<String> featuresToInstall = new ArrayList<String>();

DefaultArtifactVersion version;
if(openLibertyVersion != null) {
version = new DefaultArtifactVersion(openLibertyVersion);
info("plugin listed esa: " + pluginListedEsas.toString());
if (version.compareTo(MIN_VERSION) < 0 && !pluginListedEsas.isEmpty()) {
if ((VersionUtility.compareArtifactVersion(openLibertyVersion, MIN_USER_FEATURE_VERSION, true) < 0) && !pluginListedEsas.isEmpty()) {
//manually install user feature esas
info("Neither InstallUtility nor FeatureUtility is available to install user feature esa.");
info("Attempting to manually install the user feature esa without resolving its dependencies.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2021.
* (C) Copyright IBM Corporation 2021, 2023.
*
* 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 @@ -29,10 +29,8 @@
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -41,8 +39,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.commons.io.FileUtils;

public abstract class PrepareFeatureUtil extends ServerFeatureUtil {

Expand All @@ -65,12 +61,9 @@ public PrepareFeatureUtil(File installDirectory, String openLibertyVersion)
installJarFile = loadInstallJarFile(installDirectory);

// check if the openliberty kernel meets min required version 21.0.0.11
DefaultArtifactVersion minVersion = new DefaultArtifactVersion(MIN_USER_FEATURE_VERSION);
DefaultArtifactVersion version = new DefaultArtifactVersion(openLibertyVersion);

if (version.compareTo(minVersion) < 0) {
if (VersionUtility.compareArtifactVersion(openLibertyVersion, MIN_USER_FEATURE_VERSION, true) < 0) {
throw new PluginScenarioException(
"Installing user features on Liberty version "+version+" is not supported. The minimum required version of Liberty for installing user features is "+minVersion+".");
"Installing user features on Liberty version "+openLibertyVersion+" is not supported. The minimum required version of Liberty for installing user features is "+MIN_USER_FEATURE_VERSION+".");
}
if (installJarFile == null) {
throw new PluginScenarioException("Install map jar not found.");
Expand Down Expand Up @@ -112,7 +105,6 @@ private Map<File, String> populateESAMap(File additionalBOM) {
* @throws PluginExecutionException
*/
private void prepareFeature(String groupId, String artifactId, String version, File additionalBOM, Map<File, String> esaMap) throws PluginExecutionException {
File json = null;
try {
String repoLocation = parseRepositoryLocation(additionalBOM, groupId, artifactId, "pom", version);
String targetJsonFile = createArtifactFilePath(repoLocation, groupId, FEATURES_JSON_ARTIFACT_ID, "json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* (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.common.plugins.util;

import com.fasterxml.jackson.core.Version;

public class VersionUtility {

/*
* Compare currentVersion to compareVersion. The version may only contain three parts such as 1.15.8.
* If currentVersion is less than compareVersion, -1 is returned.
* If currentVersion is the same as compareVersion, 0 is returned.
* If currentVersion is greater than compareVersion, 1 is returned.
*
* @return integer representing result of comparison
*/
public static int compareArtifactVersion(String currentVersion, String compareVersion) {
return compareArtifactVersion(currentVersion, compareVersion, false);

}

/*
* Compare currentVersion to compareVersion. If the isLibertyVersion flag is set to true, only the first and last digits will be compared,
* since the middle two digits are always zero.
*
* If currentVersion is less than compareVersion, -1 is returned.
* If currentVersion is the same as compareVersion, 0 is returned.
* If currentVersion is greater than compareVersion, 1 is returned.
*
* @return integer representing result of comparison
*/
public static int compareArtifactVersion(String currentVersion, String compareVersion, boolean isLibertyVersion) {
String[] compareVersionArray = compareVersion.split("\\.");
int majorVersion = Integer.parseInt(compareVersionArray[0]);
int minorVersion = isLibertyVersion ? 0 : Integer.parseInt(compareVersionArray[1]);
int patchLevel = isLibertyVersion ? Integer.parseInt(compareVersionArray[3]) : Integer.parseInt(compareVersionArray[2]);
Version minVersion = new Version(majorVersion, minorVersion, patchLevel, null, null, null);

// check for and strip off any classifier
if (currentVersion.contains("-")) {
currentVersion = currentVersion.substring(0, currentVersion.indexOf("-"));
}
String[] currentVersionArray = currentVersion.split("\\.");
majorVersion = Integer.parseInt(currentVersionArray[0]);
minorVersion = isLibertyVersion ? 0 : Integer.parseInt(currentVersionArray[1]);
patchLevel = isLibertyVersion ? Integer.parseInt(currentVersionArray[3]) : Integer.parseInt(currentVersionArray[2]);
Version version = new Version(majorVersion, minorVersion, patchLevel, null, null, null);

return version.compareTo(minVersion);

}

}

0 comments on commit 186bfb4

Please sign in to comment.