Tweaked ordering of modules within trains and train iterations.

We're now using the global sorting of the projects defined by the topological graph analysis run at startup to implement Comparable and exposing this comparability on more upper levels like modules.
This commit is contained in:
Oliver Gierke
2016-02-10 14:26:25 +01:00
parent 37372d0f3c
commit 5d330e2573
7 changed files with 44 additions and 26 deletions

View File

@@ -23,7 +23,7 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
*/
@Value
public class Module implements VersionAware {
public class Module implements VersionAware, Comparable<Module> {
private final Project project;
private final Version version;
@@ -67,6 +67,19 @@ public class Module implements VersionAware {
return this.project.equals(module.project);
}
/*
* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Module that) {
return this.project.compareTo(that.project);
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return String.format("Spring Data %s %s - %s", project.getName(), version, project.getKey());

View File

@@ -15,21 +15,34 @@
*/
package org.springframework.data.release.model;
import lombok.RequiredArgsConstructor;
import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;
import org.springframework.data.release.Streamable;
/**
* A {@link Streamable} set of modules. Makes sure the stream order will match the natural dependency order of the given
* {@link Module} instances.
*
* @author Oliver Gierke
*/
@RequiredArgsConstructor
public class Modules implements Streamable<Module> {
class Modules implements Streamable<Module> {
private final Collection<Module> modules;
private Modules(Collection<Module> modules) {
this.modules = new TreeSet<>(modules);
}
public static Modules of(Collection<Module> modules) {
return new Modules(modules);
}
/*
* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
public Iterator<Module> iterator() {
return modules.iterator();
}

View File

@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
*/
@ToString
@EqualsAndHashCode
public class Project {
public class Project implements Comparable<Project> {
private final @Getter ProjectKey key;
private final @Getter String name;
@@ -83,4 +83,13 @@ public class Project {
return dependencies.stream().anyMatch(dependency -> dependency.equals(project) || dependency.dependsOn(project));
}
/*
* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Project that) {
return Projects.PROJECTS.indexOf(this) - Projects.PROJECTS.indexOf(that);
}
}

View File

@@ -50,7 +50,7 @@ public class Train implements Streamable<Module> {
public Train(String name, Collection<Module> modules) {
this.name = name;
this.modules = new Modules(modules);
this.modules = Modules.of(modules);
this.iterations = Iterations.DEFAULT;
}
@@ -117,7 +117,6 @@ public class Train implements Streamable<Module> {
return modules.stream().//
filter(module -> !exclusionList.contains(module.getProject())).//
map(module -> new ModuleIteration(module, new TrainIteration(this, iteration))).//
sorted().//
collect(Collectors.toList());
}
@@ -147,7 +146,6 @@ public class Train implements Streamable<Module> {
builder.append(modules.stream().//
map(Module::toString).//
sorted().//
collect(Collectors.joining(OsUtils.LINE_SEPARATOR)));
return builder.toString();

View File

@@ -83,5 +83,4 @@ public class TrainIteration implements Streamable<ModuleIteration> {
public String toString() {
return String.format("%s %s", train.getName(), iteration.getName());
}
}

View File

@@ -48,7 +48,7 @@ public class Logger {
log(train.getName(), template, args);
}
private void log(String context, Object template, Object... args) {
public void log(String context, Object template, Object... args) {
LOGGER.info(String.format(PREFIX_TEMPLATE, context, String.format(template.toString(), args)));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,18 +39,4 @@ public class TrainsUnitTest {
public void addsNewlyAddedModule() {
assertThat(ReleaseTrains.HOPPER.getModule(Projects.ENVERS), is(notNullValue()));
}
@Test
public void testname() {
Iterable<ModuleIteration> iterations = ReleaseTrains.HOPPER.getModuleIterations(Iteration.M1);
for (ModuleIteration iteration : iterations) {
System.out.println(iteration);
}
System.out.println();
iterations.forEach(System.out::println);
}
}