-
Notifications
You must be signed in to change notification settings - Fork 22
feat: use Semver compatibility for dependency info #101
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,5 @@ | ||
| /* | ||
| * Copyright 2019 MovingBlocks | ||
| * | ||
| * 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. | ||
| */ | ||
| // Copyright 2021 The Terasology Foundation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.terasology.gestalt.module.dependencyresolution; | ||
|
|
||
|
|
@@ -30,7 +17,6 @@ | |
| import org.terasology.gestalt.module.ModuleRegistry; | ||
| import org.terasology.gestalt.naming.Name; | ||
| import org.terasology.gestalt.naming.Version; | ||
| import org.terasology.gestalt.naming.VersionRange; | ||
| import org.terasology.gestalt.util.collection.UniqueQueue; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
@@ -42,6 +28,7 @@ | |
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| class ResolutionAttempt { | ||
|
|
@@ -58,7 +45,7 @@ class ResolutionAttempt { | |
| this.optionalStrategy = optionalStrategy; | ||
| } | ||
|
|
||
| ResolutionResult resolve(Map<Name, Optional<VersionRange>> validVersions) { | ||
| ResolutionResult resolve(Map<Name, Optional<Predicate<Version>>> validVersions) { | ||
| rootModules = ImmutableSet.copyOf(validVersions.keySet()); | ||
| populateDomains(validVersions); | ||
| populateConstraints(); | ||
|
|
@@ -80,7 +67,7 @@ ResolutionResult resolve(Map<Name, Optional<VersionRange>> validVersions) { | |
| /** | ||
| * Populates the domains (modules of interest) for resolution. Includes all versions of all modules depended on by any version of a module of interest, recursively. | ||
| */ | ||
| private void populateDomains(Map<Name, Optional<VersionRange>> validVersions) { | ||
| private void populateDomains(Map<Name, Optional<Predicate<Version>>> validVersions) { | ||
| moduleVersionPool = HashMultimap.create(); | ||
| Set<Name> involvedModules = Sets.newHashSet(); | ||
| Deque<Name> moduleQueue = Queues.newArrayDeque(); | ||
|
|
@@ -92,8 +79,8 @@ private void populateDomains(Map<Name, Optional<VersionRange>> validVersions) { | |
| while (!moduleQueue.isEmpty()) { | ||
| Name id = moduleQueue.pop(); | ||
| for (Module version : registry.getModuleVersions(id)) { | ||
| Optional<VersionRange> range = validVersions.getOrDefault(version.getId(), Optional.empty()); | ||
| if (!range.isPresent() || range.get().contains(version.getVersion())) { | ||
| Optional<Predicate<Version>> range = validVersions.getOrDefault(version.getId(), Optional.empty()); | ||
| if (!range.isPresent() || range.get().test(version.getVersion())) { | ||
| moduleVersionPool.put(id, new PossibleVersion(version.getVersion())); | ||
| for (DependencyInfo dependency : version.getMetadata().getDependencies()) { | ||
| if (involvedModules.add(dependency.getId())) { | ||
|
|
@@ -125,7 +112,7 @@ private void populateConstraints() { | |
| Module versionedModule = registry.getModule(name, version.getVersion().get()); | ||
| DependencyInfo info = versionedModule.getMetadata().getDependencyInfo(dependency); | ||
| if (info != null) { | ||
| constraintTable.put(version.getVersion().get(), new CompatibleVersions(info.versionRange(), info.isOptional() && !optionalStrategy.isRequired())); | ||
| constraintTable.put(version.getVersion().get(), new CompatibleVersions(info.versionPredicate(), info.isOptional() && !optionalStrategy.isRequired())); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to have a uniform code formatter...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what prompted that thought on this line in particular?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, probably the length of that line 🤔 |
||
| } | ||
| } | ||
| } | ||
|
|
@@ -376,17 +363,17 @@ public String toString() { | |
| } | ||
|
|
||
| private static class CompatibleVersions { | ||
| private final VersionRange versionRange; | ||
| private final Predicate<Version> versionRange; | ||
| private final boolean missingAllowed; | ||
|
|
||
| public CompatibleVersions(VersionRange versionRange, boolean missingAllowed) { | ||
| public CompatibleVersions(Predicate<Version> versionRange, boolean missingAllowed) { | ||
| this.versionRange = versionRange; | ||
| this.missingAllowed = missingAllowed; | ||
| } | ||
|
|
||
| public boolean isCompatible(PossibleVersion version) { | ||
| if (version.getVersion().isPresent()) { | ||
| return versionRange.contains(version.getVersion().get()); | ||
| return versionRange.test(version.getVersion().get()); | ||
| } else { | ||
| return missingAllowed; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright 2021 The Terasology Foundation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.terasology.gestalt.naming; | ||
|
|
||
| import com.github.zafarkhaja.semver.expr.ExpressionParser; | ||
| import com.google.common.base.MoreObjects; | ||
|
|
||
| import java.util.function.Predicate; | ||
|
|
||
| public class SemverExpression implements Predicate<Version> { | ||
keturn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final Predicate<com.github.zafarkhaja.semver.Version> expression; | ||
| private final String source; | ||
|
|
||
| public SemverExpression(String source) { | ||
| this.source = source; | ||
| this.expression = ExpressionParser.newInstance().parse(source); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: error handling |
||
| } | ||
|
|
||
| @Override | ||
| public boolean test(Version version) { | ||
| return expression.test(version.semver); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return MoreObjects.toStringHelper(this) | ||
| .addValue(source) | ||
| .toString(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.