From 0b4724f5953fe97aa13bb91c6f59bc22a5355280 Mon Sep 17 00:00:00 2001 From: Chuck Bridgham Date: Fri, 12 Jul 2024 21:33:53 -0400 Subject: [PATCH] Forwarding Result data --- .../RepositoryResolutionException.java | 37 +++++----- .../resolver/RepositoryResolver.java | 29 ++++++-- .../kernel/KernelResolverRepository.java | 67 +++++++++++++++++++ 3 files changed, 109 insertions(+), 24 deletions(-) diff --git a/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolutionException.java b/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolutionException.java index 6ef662fc8d76..440ed0ec55cc 100755 --- a/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolutionException.java +++ b/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolutionException.java @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -44,6 +45,7 @@ public class RepositoryResolutionException extends RepositoryException { private Set resolvedPlatforms; private Set missingPlatforms; private boolean hasVersionlessIssue; + private List missingBasePlatforms; /** * @param cause @@ -68,15 +70,17 @@ public RepositoryResolutionException(ResolutionException cause, Collectionnull + * @param allRequirementsResourcesNotFound The {@link MissingRequirement} objects that were not found. Must not be null. + * @param featureConflicts the details of any feature conflicts which occurred during feature resolution, as returned from {@link Result#getConflicts()} * @param resolvedPlatforms - * @param missingPlatforms + * @param missingPlatforms Unknown platform names + * @param missingBasePlatforms unresolved versionless features needing platforms defined */ public RepositoryResolutionException(ResolutionException cause, Collection topLevelFeaturesNotResolved, Collection allRequirementsNotFound, Collection missingProductInformation, Collection allRequirementsResourcesNotFound, - Map> featureConflicts, Set resolvedPlatforms, Set missingPlatforms) { + Map> featureConflicts, Set resolvedPlatforms, Set missingPlatforms, + List missingBasePlatforms) { super(cause); this.topLevelFeaturesNotResolved = topLevelFeaturesNotResolved; this.allRequirementsNotFound = allRequirementsNotFound; @@ -85,7 +89,8 @@ public RepositoryResolutionException(ResolutionException cause, Collection> getFeatureConflicts() { public String getMessage() { StringBuilder sb = new StringBuilder(); - if (hasVersionlessIssue()) { - if (!getMissingPlatforms().isEmpty()) { - for (String missing : getMissingPlatforms()) { - sb.append("Platform: ").append(missing).append(" couldn't be found, no versionless features will be resolved").append("\n"); - } - } - if (getResolvedPlatforms().isEmpty() && getMissingPlatforms().isEmpty()) { - sb.append("Platform couldn't be determined, no versionless features will be resolved").append("\n"); + if (!getMissingPlatforms().isEmpty()) { + for (String missing : getMissingPlatforms()) { + sb.append("Platform: ").append(missing).append(" couldn't be found, no versionless features will be resolved").append("\n"); } } + if (getResolvedPlatforms().isEmpty() && getMissingPlatforms().isEmpty()) { + sb.append("Platform couldn't be determined, no versionless features will be resolved").append("\n"); + } for (String missing : getTopLevelFeaturesNotResolved()) { sb.append("Top level feature not resolved: resource=").append(missing).append("\n"); @@ -384,10 +387,10 @@ public Set getMissingPlatforms() { } /** - * @return the hasVersionlessIssue + * @return the missingBasePlatforms */ - public boolean hasVersionlessIssue() { - return hasVersionlessIssue; + public List getMissingBasePlatforms() { + return missingBasePlatforms; } } diff --git a/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolver.java b/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolver.java index c79fabd0377b..56b44028e8ca 100755 --- a/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolver.java +++ b/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/RepositoryResolver.java @@ -32,6 +32,7 @@ import com.ibm.ws.kernel.feature.provisioning.ProvisioningFeatureDefinition; import com.ibm.ws.kernel.feature.resolver.FeatureResolver; import com.ibm.ws.kernel.feature.resolver.FeatureResolver.Chain; +import com.ibm.ws.kernel.feature.resolver.FeatureResolver.Repository; import com.ibm.ws.kernel.feature.resolver.FeatureResolver.Result; import com.ibm.ws.kernel.productinfo.ProductInfo; import com.ibm.ws.product.utility.extension.IFixUtils; @@ -567,7 +568,7 @@ void resolveFeaturesAsSet() { featureConflicts.putAll(result.getConflicts()); if (hasRequestedVersionlessFeatures(featureNamesToResolve, resolverRepository)) - recordVersionless(result); + recordVersionless(result, resolverRepository); for (String name : result.getResolvedFeatures()) { ProvisioningFeatureDefinition feature = resolverRepository.getFeature(name); @@ -583,9 +584,10 @@ void resolveFeaturesAsSet() { * Record Versionless Messages and Issues * * @param result + * @param resolverRepo * @param requestedFeatures */ - private void recordVersionless(Result result) { + private void recordVersionless(Result result, Repository resolverRepo) { resolvedPlatforms = result.getResolvedPlatforms(); missingPlatforms = result.getMissingPlatforms(); @@ -1008,6 +1010,22 @@ private void reportErrors() throws RepositoryResolutionException { return; } + List missingBasePlatforms = new ArrayList(); + + // Versionless feature issues + if (!missingTopLevelRequirements.isEmpty()) { + for (String name : missingTopLevelRequirements) { + ProvisioningFeatureDefinition feature = resolverRepository.getFeature(name); + if (feature != null && feature.isVersionless()) { + ProvisioningFeatureDefinition firstChild = resolverRepository.findAllPossibleVersions(feature).get(0); + String plat = firstChild.getPlatformName(); + if (plat != null && plat.indexOf("-") != -1) { + missingBasePlatforms.add(resolverRepository.getFeatureBaseName(plat)); + } + } + } + } + Set missingProductInformation = new HashSet<>(); for (ApplicableToProduct esa : resourcesWrongProduct) { @@ -1034,11 +1052,8 @@ private void reportErrors() throws RepositoryResolutionException { missingRequirementNames.add(req.getRequirementName()); } - if (hasVersionlessIssue()) - throw new RepositoryResolutionException(null, missingTopLevelRequirements, missingRequirementNames, missingProductInformation, missingRequirements, featureConflicts, - resolvedPlatforms, missingPlatforms); - else - throw new RepositoryResolutionException(null, missingTopLevelRequirements, missingRequirementNames, missingProductInformation, missingRequirements, featureConflicts); + throw new RepositoryResolutionException(null, missingTopLevelRequirements, missingRequirementNames, missingProductInformation, missingRequirements, featureConflicts, + resolvedPlatforms, missingPlatforms, missingBasePlatforms); } /** diff --git a/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/internal/kernel/KernelResolverRepository.java b/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/internal/kernel/KernelResolverRepository.java index 911d9d42b8b7..fe3fc5c78fa3 100644 --- a/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/internal/kernel/KernelResolverRepository.java +++ b/dev/com.ibm.ws.repository.resolver/src/com/ibm/ws/repository/resolver/internal/kernel/KernelResolverRepository.java @@ -24,7 +24,9 @@ import org.osgi.framework.Version; import com.ibm.ws.kernel.feature.Visibility; +import com.ibm.ws.kernel.feature.provisioning.FeatureResource; import com.ibm.ws.kernel.feature.provisioning.ProvisioningFeatureDefinition; +import com.ibm.ws.kernel.feature.provisioning.SubsystemContentType; import com.ibm.ws.kernel.feature.resolver.FeatureResolver; import com.ibm.ws.repository.common.enums.FilterableAttribute; import com.ibm.ws.repository.common.enums.ResourceType; @@ -244,6 +246,71 @@ public ProvisioningFeatureDefinition getFeature(String featureName) { return feature; } + /** + * Answer the list of public versioned features derived from the passed versionless feature or empty List if doesn't exist. + * + * @return List + */ + public List findAllPossibleVersions(ProvisioningFeatureDefinition versionlessFeature) { + List result = new ArrayList<>(); + for (FeatureResource dependency : versionlessFeature.getConstituents(SubsystemContentType.FEATURE_TYPE)) { + result.add(getVersionedFeature(dependency.getSymbolicName())); + + String baseName = getFeatureBaseName(dependency.getSymbolicName()); + List tolerates = dependency.getTolerates(); + if (tolerates != null) { + for (String toleratedVersion : tolerates) { + String featureName = baseName + toleratedVersion; + result.add(getVersionedFeature(featureName)); + } + } + } + return result; + } + + /** + * + * Answer the public versioned feature based on the internal versionless linking feature + * + * @param versionlessLinkingFeatureName + * @return ProvisioningFeatureDefinition + */ + private ProvisioningFeatureDefinition getVersionedFeature(String versionlessLinkingFeatureName) { + ProvisioningFeatureDefinition result = null; + ProvisioningFeatureDefinition feature = getFeature(versionlessLinkingFeatureName); + if (feature != null) { + //This is the versionless linking feature pointing to a public versioned feature + for (FeatureResource versionedFeature : feature.getConstituents(SubsystemContentType.FEATURE_TYPE)) { + //Find the right public feature (should only be one) - set the result + ProvisioningFeatureDefinition versionedFeatureDef = getFeature(versionedFeature.getSymbolicName()); + if (versionedFeatureDef.getVisibility() != Visibility.PUBLIC) { + continue; + } + result = versionedFeatureDef; + } + } + return result; + } + + /** + * Removes the version from the end of a feature symbolic name + *

+ * The version is presumed to start after the last dash character in the name. + *

+ * E.g. {@code getFeatureBaseName("com.example.featureA-1.0")} returns {@code "com.example.featureA-"} + * + * @param nameAndVersion the feature symbolic name + * @return the feature symbolic name with any version stripped + */ + public String getFeatureBaseName(String nameAndVersion) { + int dashPosition = nameAndVersion.lastIndexOf('-'); + if (dashPosition != -1) { + return nameAndVersion.substring(0, dashPosition + 1); + } else { + return nameAndVersion; + } + } + /** * Get a feature by name, but without going and checking the remote repository if we don't know about it *