@Test public void testBadVersionIsDetected() { List<Checkpoint> checkpoints = ImmutableList.of( new org.sonatype.nexus.upgrade.example.CheckpointFoo() ); List<Upgrade> upgrades = ImmutableList.of( new org.sonatype.nexus.upgrade.bad.UpgradeFoo_1_1(), new org.sonatype.nexus.upgrade.bad.UpgradeFoo_1_2() ); UpgradeManager upgradeManager = createUpgradeManager(checkpoints, upgrades); thrown.expect(IllegalStateException.class); thrown.expectMessage("Found 2 problem(s) with upgrades:" + lineSeparator() + "Upgrade step org.sonatype.nexus.upgrade.bad.UpgradeFoo_1_1 " + "has invalid version: 1.1 is not after 1.1" + lineSeparator() + "Upgrade step org.sonatype.nexus.upgrade.bad.UpgradeFoo_1_2 " + "has invalid version: 1.1 is not after 1.2"); upgradeManager.selectUpgrades(ImmutableMap.of(), false); }
public List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly) { List<Upgrade> upgrades = upgradeIndex.entrySet().stream() .filter(e -> applies(modelVersions, e.getKey())) .map(e -> e.getValue()) .collect(toList()); List<String> problems = new ArrayList<>(); upgrades.forEach(u -> checkUpgrade(u, problems)); if (!problems.isEmpty()) { String message = String.format("Found %d problem(s) with upgrades:%n%s", problems.size(), problems.stream().collect(joining(lineSeparator()))); throw new IllegalStateException(message); } Stream<UpgradeStep> upgradeSteps = order(modelVersions, upgrades); if (localOnly) { upgradeSteps = upgradeSteps.filter(step -> localModels.contains(step.getModel())); } return upgradeSteps .map(UpgradeStep::getUpgrade) .collect(toList()); }
UpgradeManager extends ComponentSupport { public List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly) { List<Upgrade> upgrades = upgradeIndex.entrySet().stream() .filter(e -> applies(modelVersions, e.getKey())) .map(e -> e.getValue()) .collect(toList()); List<String> problems = new ArrayList<>(); upgrades.forEach(u -> checkUpgrade(u, problems)); if (!problems.isEmpty()) { String message = String.format("Found %d problem(s) with upgrades:%n%s", problems.size(), problems.stream().collect(joining(lineSeparator()))); throw new IllegalStateException(message); } Stream<UpgradeStep> upgradeSteps = order(modelVersions, upgrades); if (localOnly) { upgradeSteps = upgradeSteps.filter(step -> localModels.contains(step.getModel())); } return upgradeSteps .map(UpgradeStep::getUpgrade) .collect(toList()); } }
UpgradeManager extends ComponentSupport { public List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly) { List<Upgrade> upgrades = upgradeIndex.entrySet().stream() .filter(e -> applies(modelVersions, e.getKey())) .map(e -> e.getValue()) .collect(toList()); List<String> problems = new ArrayList<>(); upgrades.forEach(u -> checkUpgrade(u, problems)); if (!problems.isEmpty()) { String message = String.format("Found %d problem(s) with upgrades:%n%s", problems.size(), problems.stream().collect(joining(lineSeparator()))); throw new IllegalStateException(message); } Stream<UpgradeStep> upgradeSteps = order(modelVersions, upgrades); if (localOnly) { upgradeSteps = upgradeSteps.filter(step -> localModels.contains(step.getModel())); } return upgradeSteps .map(UpgradeStep::getUpgrade) .collect(toList()); } @Inject  UpgradeManager(final List<Checkpoint> managedCheckpoints,
                        final List<Upgrade> managedUpgrades,
                        @Named("${nexus.upgrade.warnOnMissingDependencies:-false}")
                        final boolean warnOnMissingDependencies); }
UpgradeManager extends ComponentSupport { public List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly) { List<Upgrade> upgrades = upgradeIndex.entrySet().stream() .filter(e -> applies(modelVersions, e.getKey())) .map(e -> e.getValue()) .collect(toList()); List<String> problems = new ArrayList<>(); upgrades.forEach(u -> checkUpgrade(u, problems)); if (!problems.isEmpty()) { String message = String.format("Found %d problem(s) with upgrades:%n%s", problems.size(), problems.stream().collect(joining(lineSeparator()))); throw new IllegalStateException(message); } Stream<UpgradeStep> upgradeSteps = order(modelVersions, upgrades); if (localOnly) { upgradeSteps = upgradeSteps.filter(step -> localModels.contains(step.getModel())); } return upgradeSteps .map(UpgradeStep::getUpgrade) .collect(toList()); } @Inject  UpgradeManager(final List<Checkpoint> managedCheckpoints,
                        final List<Upgrade> managedUpgrades,
                        @Named("${nexus.upgrade.warnOnMissingDependencies:-false}")
                        final boolean warnOnMissingDependencies); Set<String> getLocalModels(); Set<String> getClusteredModels(); List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly); List<Checkpoint> selectCheckpoints(final List<Upgrade> upgrades); Map<String, String> latestKnownModelVersions(); String getModel(final Checkpoint checkpoint); Upgrades getMetadata(final Upgrade upgrade); }
UpgradeManager extends ComponentSupport { public List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly) { List<Upgrade> upgrades = upgradeIndex.entrySet().stream() .filter(e -> applies(modelVersions, e.getKey())) .map(e -> e.getValue()) .collect(toList()); List<String> problems = new ArrayList<>(); upgrades.forEach(u -> checkUpgrade(u, problems)); if (!problems.isEmpty()) { String message = String.format("Found %d problem(s) with upgrades:%n%s", problems.size(), problems.stream().collect(joining(lineSeparator()))); throw new IllegalStateException(message); } Stream<UpgradeStep> upgradeSteps = order(modelVersions, upgrades); if (localOnly) { upgradeSteps = upgradeSteps.filter(step -> localModels.contains(step.getModel())); } return upgradeSteps .map(UpgradeStep::getUpgrade) .collect(toList()); } @Inject  UpgradeManager(final List<Checkpoint> managedCheckpoints,
                        final List<Upgrade> managedUpgrades,
                        @Named("${nexus.upgrade.warnOnMissingDependencies:-false}")
                        final boolean warnOnMissingDependencies); Set<String> getLocalModels(); Set<String> getClusteredModels(); List<Upgrade> selectUpgrades(final Map<String, String> modelVersions, final boolean localOnly); List<Checkpoint> selectCheckpoints(final List<Upgrade> upgrades); Map<String, String> latestKnownModelVersions(); String getModel(final Checkpoint checkpoint); Upgrades getMetadata(final Upgrade upgrade);  }