Skip to content

Commit

Permalink
Forwarding Result data
Browse files Browse the repository at this point in the history
  • Loading branch information
cbridgha committed Jul 13, 2024
1 parent e17c5e3 commit 31282d3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class RepositoryResolutionException extends RepositoryException {
private Set<String> resolvedPlatforms;
private Set<String> missingPlatforms;
private boolean hasVersionlessIssue;
private List<String> missingBasePlatforms;

/**
* @param cause
Expand All @@ -68,15 +70,17 @@ public RepositoryResolutionException(ResolutionException cause, Collection<Strin
* @param object
* @param missingTopLevelRequirements
* @param missingRequirementNames
* @param missingProductInformation2
* @param missingRequirements
* @param featureConflicts2
* @param missingProductInformation all the product information requirements that could not be found. Can be empty but must not be <code>null</code>
* @param allRequirementsResourcesNotFound The {@link MissingRequirement} objects that were not found. Must not be <code>null</code>.
* @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<String> topLevelFeaturesNotResolved, Collection<String> allRequirementsNotFound,
Collection<ProductRequirementInformation> missingProductInformation, Collection<MissingRequirement> allRequirementsResourcesNotFound,
Map<String, Collection<Chain>> featureConflicts, Set<String> resolvedPlatforms, Set<String> missingPlatforms) {
Map<String, Collection<Chain>> featureConflicts, Set<String> resolvedPlatforms, Set<String> missingPlatforms,
List<String> missingBasePlatforms) {
super(cause);
this.topLevelFeaturesNotResolved = topLevelFeaturesNotResolved;
this.allRequirementsNotFound = allRequirementsNotFound;
Expand All @@ -85,7 +89,8 @@ public RepositoryResolutionException(ResolutionException cause, Collection<Strin
this.featureConflicts = featureConflicts;
this.resolvedPlatforms = resolvedPlatforms;
this.missingPlatforms = missingPlatforms;
this.hasVersionlessIssue = true;
this.missingBasePlatforms = missingBasePlatforms;

}

/**
Expand Down Expand Up @@ -280,16 +285,14 @@ public Map<String, Collection<Chain>> 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");
Expand Down Expand Up @@ -384,10 +387,10 @@ public Set<String> getMissingPlatforms() {
}

/**
* @return the hasVersionlessIssue
* @return the missingBasePlatforms
*/
public boolean hasVersionlessIssue() {
return hasVersionlessIssue;
public List<String> getMissingBasePlatforms() {
return missingBasePlatforms;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -1008,6 +1010,22 @@ private void reportErrors() throws RepositoryResolutionException {
return;
}

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

// 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<ProductRequirementInformation> missingProductInformation = new HashSet<>();

for (ApplicableToProduct esa : resourcesWrongProduct) {
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProvisioningFeatureDefinition>
*/
public List<ProvisioningFeatureDefinition> findAllPossibleVersions(ProvisioningFeatureDefinition versionlessFeature) {
List<ProvisioningFeatureDefinition> result = new ArrayList<>();
for (FeatureResource dependency : versionlessFeature.getConstituents(SubsystemContentType.FEATURE_TYPE)) {
result.add(getVersionedFeature(dependency.getSymbolicName()));

String baseName = getFeatureBaseName(dependency.getSymbolicName());
List<String> 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
* <p>
* The version is presumed to start after the last dash character in the name.
* <p>
* 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
*
Expand Down

0 comments on commit 31282d3

Please sign in to comment.