[jOOQ/jOOQ#9506] More work on Migrations API:
- Support a commit author
This commit is contained in:
parent
2343e3c53d
commit
12d1aa31ab
@ -138,7 +138,7 @@ public final class GitCommitProvider implements CommitProvider {
|
||||
|
||||
// The commits seem to come in reverse order from jgit.
|
||||
Collections.reverse(revCommits);
|
||||
Commit init = commits.root();
|
||||
Commit root = commits.root();
|
||||
|
||||
// TODO: This algorithm is quadradic in the worst case. Can we find a better one?
|
||||
// TODO: We collect all the commits from git, when we could ignore the empty ones
|
||||
@ -150,7 +150,7 @@ public final class GitCommitProvider implements CommitProvider {
|
||||
RevCommit revCommit = it.next();
|
||||
|
||||
if (revCommit.getParents() == null || revCommit.getParents().length == 0) {
|
||||
commits.add(tag(tags, init.commit(revCommit.getName(), revCommit.getFullMessage(), editFiles(r, revCommit))));
|
||||
commits.add(tag(tags, root.commit(revCommit.getName(), revCommit.getFullMessage(), revCommit.getAuthorIdent().getName(), editFiles(r, revCommit))));
|
||||
it.remove();
|
||||
}
|
||||
else {
|
||||
@ -165,9 +165,9 @@ public final class GitCommitProvider implements CommitProvider {
|
||||
continue commitLoop;
|
||||
|
||||
if (parents.length == 1)
|
||||
commits.add(tag(tags, parents[0].commit(revCommit.getName(), revCommit.getFullMessage(), editFiles(r, revCommit))));
|
||||
commits.add(tag(tags, parents[0].commit(revCommit.getName(), revCommit.getFullMessage(), revCommit.getAuthorIdent().getName(), editFiles(r, revCommit))));
|
||||
else if (parents.length == 2)
|
||||
commits.add(tag(tags, parents[0].merge(revCommit.getName(), revCommit.getFullMessage(), parents[1], editFiles(r, revCommit))));
|
||||
commits.add(tag(tags, parents[0].merge(revCommit.getName(), revCommit.getFullMessage(), revCommit.getAuthorIdent().getName(), parents[1], editFiles(r, revCommit))));
|
||||
else
|
||||
throw new UnsupportedOperationException("Merging more than two parents not yet supported");
|
||||
|
||||
@ -178,7 +178,7 @@ public final class GitCommitProvider implements CommitProvider {
|
||||
|
||||
Status status = g.status().call();
|
||||
if (status.hasUncommittedChanges() || !status.getUntracked().isEmpty())
|
||||
commits.add(commit(last != null ? commits.get(last.getName()) : init, status));
|
||||
commits.add(commit(last != null ? commits.get(last.getName()) : root, status));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new GitException("Error while providing git versions", e);
|
||||
|
||||
@ -130,6 +130,18 @@ public interface Commit extends Node<Commit> {
|
||||
@NotNull
|
||||
Commit commit(String id, String message, Collection<? extends File> delta);
|
||||
|
||||
/**
|
||||
* Create a new commit on top of this one.
|
||||
*/
|
||||
@NotNull
|
||||
Commit commit(String id, String message, String author, File... delta);
|
||||
|
||||
/**
|
||||
* Create a new commit on top of this one.
|
||||
*/
|
||||
@NotNull
|
||||
Commit commit(String id, String message, String author, Collection<? extends File> delta);
|
||||
|
||||
/**
|
||||
* Merge two commits.
|
||||
*/
|
||||
@ -153,4 +165,16 @@ public interface Commit extends Node<Commit> {
|
||||
*/
|
||||
@NotNull
|
||||
Commit merge(String id, String message, Commit with, Collection<? extends File> delta);
|
||||
|
||||
/**
|
||||
* Merge two commits.
|
||||
*/
|
||||
@NotNull
|
||||
Commit merge(String id, String message, String author, Commit with, File... delta);
|
||||
|
||||
/**
|
||||
* Merge two commits.
|
||||
*/
|
||||
@NotNull
|
||||
Commit merge(String id, String message, String author, Commit with, Collection<? extends File> delta);
|
||||
}
|
||||
|
||||
@ -71,6 +71,12 @@ public interface Node<N extends Node<N>> extends Scope {
|
||||
@Nullable
|
||||
String message();
|
||||
|
||||
/**
|
||||
* The author of this node.
|
||||
*/
|
||||
@Nullable
|
||||
String author();
|
||||
|
||||
/**
|
||||
* The root node of the graph.
|
||||
*/
|
||||
|
||||
@ -2,12 +2,14 @@
|
||||
package org.jooq.conf;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jooq.util.jaxb.tools.XMLAppendable;
|
||||
import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
import org.jooq.util.jaxb.tools.XMLAppendable;
|
||||
import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -48,6 +48,8 @@ import org.jooq.Node;
|
||||
import org.jooq.exception.DataDefinitionException;
|
||||
import org.jooq.exception.DataMigrationVerificationException;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@ -55,15 +57,17 @@ abstract class AbstractNode<N extends Node<N>> extends AbstractLazyScope impleme
|
||||
|
||||
final N root;
|
||||
final String id;
|
||||
String message;
|
||||
final String message;
|
||||
final String author;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
AbstractNode(Configuration configuration, String id, String message, N root) {
|
||||
AbstractNode(Configuration configuration, String id, String message, String author, N root) {
|
||||
super(configuration);
|
||||
|
||||
this.root = root != null ? root : (N) this;
|
||||
this.id = id;
|
||||
this.message = defaultIfNull(message, "");
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,6 +80,11 @@ abstract class AbstractNode<N extends Node<N>> extends AbstractLazyScope impleme
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String author() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final N root() {
|
||||
return root;
|
||||
|
||||
@ -83,8 +83,16 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
final Map<String, File> delta;
|
||||
final Map<String, File> files;
|
||||
|
||||
CommitImpl(Configuration configuration, String id, String message, Commit root, List<Commit> parents, Collection<? extends File> delta) {
|
||||
super(configuration, id, message, root);
|
||||
CommitImpl(
|
||||
Configuration configuration,
|
||||
String id,
|
||||
String message,
|
||||
String author,
|
||||
Commit root,
|
||||
List<Commit> parents,
|
||||
Collection<? extends File> delta
|
||||
) {
|
||||
super(configuration, id, message, author, root);
|
||||
|
||||
if (Node.ROOT.equals(id) && root != null)
|
||||
throw new DataMigrationVerificationException("Cannot use reserved ID \"root\"");
|
||||
@ -97,7 +105,7 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
}
|
||||
|
||||
private CommitImpl(CommitImpl copy) {
|
||||
super(copy.configuration(), copy.id(), copy.message(), copy.root);
|
||||
super(copy.configuration(), copy.id(), copy.message(), copy.author(), copy.root);
|
||||
|
||||
this.ctx = copy.ctx;
|
||||
this.parents = copy.parents;
|
||||
@ -189,12 +197,22 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
|
||||
@Override
|
||||
public final Commit commit(String newId, String newMessage, File... newFiles) {
|
||||
return commit(newId, newMessage, Arrays.asList(newFiles));
|
||||
return commit(newId, newMessage, null, Arrays.asList(newFiles));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit commit(String newId, String newMessage, Collection<? extends File> newFiles) {
|
||||
return new CommitImpl(configuration(), newId, newMessage, root, Arrays.asList(this), newFiles);
|
||||
return commit(newId, newMessage, null, newFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit commit(String newId, String newMessage, String newAuthor, File... newFiles) {
|
||||
return commit(newId, newMessage, newAuthor, Arrays.asList(newFiles));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit commit(String newId, String newMessage, String newAuthor, Collection<? extends File> newFiles) {
|
||||
return new CommitImpl(configuration(), newId, newMessage, newAuthor, root, Arrays.asList(this), newFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -209,12 +227,22 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
|
||||
@Override
|
||||
public final Commit merge(String newId, String newMessage, Commit with, File... newFiles) {
|
||||
return merge(newId, newMessage, with, Arrays.asList(newFiles));
|
||||
return merge(newId, newMessage, null, with, Arrays.asList(newFiles));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit merge(String newId, String newMessage, Commit with, Collection<? extends File> newFiles) {
|
||||
return new CommitImpl(configuration(), newId, newMessage, root, Arrays.asList(this, with), newFiles);
|
||||
return merge(newId, newMessage, null, with, newFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit merge(String newId, String newMessage, String newAuthor, Commit with, File... newFiles) {
|
||||
return merge(newId, newMessage, newAuthor, with, Arrays.asList(newFiles));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Commit merge(String newId, String newMessage, String newAuthor, Commit with, Collection<? extends File> newFiles) {
|
||||
return new CommitImpl(configuration(), newId, newMessage, newAuthor, root, Arrays.asList(this, with), newFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -450,8 +478,11 @@ final class CommitImpl extends AbstractNode<Commit> implements Commit {
|
||||
if (!isBlank(message()))
|
||||
sb.append(" - ").append(message());
|
||||
|
||||
if (!isBlank(author()))
|
||||
sb.append(", author: " + author());
|
||||
|
||||
if (!tags.isEmpty())
|
||||
sb.append(' ').append(tags);
|
||||
sb.append(", tags: ").append(tags);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -383,8 +383,8 @@ final class CommitsImpl implements Commits {
|
||||
}
|
||||
|
||||
result = p2 == null
|
||||
? p1.commit(commit.getId(), commit.getMessage(), files(commit))
|
||||
: p1.merge(commit.getId(), commit.getMessage(), p2, files(commit));
|
||||
? p1.commit(commit.getId(), commit.getMessage(), commit.getAuthor(), files(commit))
|
||||
: p1.merge(commit.getId(), commit.getMessage(), commit.getAuthor(), p2, files(commit));
|
||||
|
||||
for (TagType tag : commit.getTags())
|
||||
result = result.tag(tag.getId(), tag.getMessage());
|
||||
|
||||
@ -76,7 +76,7 @@ final class MigrationsImpl extends AbstractScope implements Migrations {
|
||||
|
||||
@Override
|
||||
public final Commits commits() {
|
||||
return new CommitsImpl(configuration(), new CommitImpl(configuration(), ROOT, ROOT, null, emptyList(), emptyList()));
|
||||
return new CommitsImpl(configuration(), new CommitImpl(configuration(), ROOT, null, null, null, emptyList(), emptyList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -72,7 +72,7 @@ final class VersionImpl extends AbstractNode<Version> implements Version {
|
||||
final List<Parent> parents;
|
||||
|
||||
private VersionImpl(Configuration configuration, String id, Meta meta, Version root, List<Parent> parents) {
|
||||
super(configuration, id, null, root);
|
||||
super(configuration, id, null, null, root);
|
||||
|
||||
this.ctx = configuration.dsl();
|
||||
this.meta = meta != null ? meta : init(ctx);
|
||||
|
||||
@ -24,11 +24,12 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <all>
|
||||
* <element name="parents" type="{http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd}ParentsType" minOccurs="0"/>
|
||||
* <element name="parents" type="{http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd}ParentsType" minOccurs="0"/>
|
||||
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* <element name="message" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="tags" type="{http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd}TagsType" minOccurs="0"/>
|
||||
* <element name="files" type="{http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd}FilesType" minOccurs="0"/>
|
||||
* <element name="author" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="tags" type="{http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd}TagsType" minOccurs="0"/>
|
||||
* <element name="files" type="{http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd}FilesType" minOccurs="0"/>
|
||||
* </all>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
@ -47,10 +48,11 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
public class CommitType implements Serializable, XMLAppendable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = 31900L;
|
||||
private final static long serialVersionUID = 32000L;
|
||||
@XmlElement(required = true)
|
||||
protected String id;
|
||||
protected String message;
|
||||
protected String author;
|
||||
@XmlElementWrapper(name = "parents")
|
||||
@XmlElement(name = "parent")
|
||||
protected List<ParentType> parents;
|
||||
@ -77,6 +79,14 @@ public class CommitType implements Serializable, XMLAppendable
|
||||
this.message = value;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String value) {
|
||||
this.author = value;
|
||||
}
|
||||
|
||||
public List<ParentType> getParents() {
|
||||
if (parents == null) {
|
||||
parents = new ArrayList<ParentType>();
|
||||
@ -120,6 +130,11 @@ public class CommitType implements Serializable, XMLAppendable
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommitType withAuthor(String value) {
|
||||
setAuthor(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommitType withParents(ParentType... values) {
|
||||
if (values!= null) {
|
||||
for (ParentType value: values) {
|
||||
@ -187,6 +202,7 @@ public class CommitType implements Serializable, XMLAppendable
|
||||
public final void appendTo(XMLBuilder builder) {
|
||||
builder.append("id", id);
|
||||
builder.append("message", message);
|
||||
builder.append("author", author);
|
||||
builder.append("parents", "parent", parents);
|
||||
builder.append("tags", "tag", tags);
|
||||
builder.append("files", "file", files);
|
||||
@ -229,6 +245,15 @@ public class CommitType implements Serializable, XMLAppendable
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (author == null) {
|
||||
if (other.author!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!author.equals(other.author)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (parents == null) {
|
||||
if (other.parents!= null) {
|
||||
return false;
|
||||
@ -265,6 +290,7 @@ public class CommitType implements Serializable, XMLAppendable
|
||||
int result = 1;
|
||||
result = ((prime*result)+((id == null)? 0 :id.hashCode()));
|
||||
result = ((prime*result)+((message == null)? 0 :message.hashCode()));
|
||||
result = ((prime*result)+((author == null)? 0 :author.hashCode()));
|
||||
result = ((prime*result)+((parents == null)? 0 :parents.hashCode()));
|
||||
result = ((prime*result)+((tags == null)? 0 :tags.hashCode()));
|
||||
result = ((prime*result)+((files == null)? 0 :files.hashCode()));
|
||||
|
||||
@ -27,7 +27,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
* <element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* <element name="content" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="contentType" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="change" type="{http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd}ChangeType"/>
|
||||
* <element name="change" type="{http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd}ChangeType"/>
|
||||
* </all>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
@ -46,7 +46,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
public class FileType implements Serializable, XMLAppendable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = 31900L;
|
||||
private final static long serialVersionUID = 32000L;
|
||||
@XmlElement(required = true)
|
||||
protected String path;
|
||||
protected String content;
|
||||
|
||||
@ -24,7 +24,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <all>
|
||||
* <element name="commits" type="{http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd}CommitsType" minOccurs="0"/>
|
||||
* <element name="commits" type="{http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd}CommitsType" minOccurs="0"/>
|
||||
* </all>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
@ -43,7 +43,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
public class MigrationsType implements Serializable, XMLAppendable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = 31900L;
|
||||
private final static long serialVersionUID = 32000L;
|
||||
@XmlElementWrapper(name = "commits")
|
||||
@XmlElement(name = "commit")
|
||||
protected List<CommitType> commits;
|
||||
|
||||
@ -24,7 +24,7 @@ import javax.xml.namespace.QName;
|
||||
@XmlRegistry
|
||||
public class ObjectFactory {
|
||||
|
||||
private final static QName _Migrations_QNAME = new QName("http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd", "migrations");
|
||||
private final static QName _Migrations_QNAME = new QName("http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd", "migrations");
|
||||
|
||||
/**
|
||||
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.jooq.migrations.xml.jaxb
|
||||
@ -81,7 +81,7 @@ public class ObjectFactory {
|
||||
* @return
|
||||
* the new instance of {@link JAXBElement }{@code <}{@link MigrationsType }{@code >}
|
||||
*/
|
||||
@XmlElementDecl(namespace = "http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd", name = "migrations")
|
||||
@XmlElementDecl(namespace = "http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd", name = "migrations")
|
||||
public JAXBElement<MigrationsType> createMigrations(MigrationsType value) {
|
||||
return new JAXBElement<MigrationsType>(_Migrations_QNAME, MigrationsType.class, null, value);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
public class ParentType implements Serializable, XMLAppendable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = 31900L;
|
||||
private final static long serialVersionUID = 32000L;
|
||||
@XmlElement(required = true)
|
||||
protected String id;
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ import org.jooq.util.jaxb.tools.XMLBuilder;
|
||||
public class TagType implements Serializable, XMLAppendable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = 31900L;
|
||||
private final static long serialVersionUID = 32000L;
|
||||
@XmlElement(required = true)
|
||||
protected String id;
|
||||
protected String message;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
@jakarta.xml.bind.annotation.XmlSchema(namespace = "http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
@jakarta.xml.bind.annotation.XmlSchema(namespace = "http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
package org.jooq.migrations.xml.jaxb;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:tns="http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd"
|
||||
targetNamespace="http://www.jooq.org/xsd/jooq-migrations-3.19.0.xsd"
|
||||
xmlns:tns="http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd"
|
||||
targetNamespace="http://www.jooq.org/xsd/jooq-migrations-3.20.0.xsd"
|
||||
elementFormDefault="qualified">
|
||||
|
||||
<element name="migrations" type="tns:MigrationsType"/>
|
||||
@ -23,6 +23,7 @@
|
||||
<element name="parents" type="tns:ParentsType" minOccurs="0" maxOccurs="1" />
|
||||
<element name="id" type="string" minOccurs="1" maxOccurs="1" />
|
||||
<element name="message" type="string" minOccurs="0" maxOccurs="1" />
|
||||
<element name="author" type="string" minOccurs="0" maxOccurs="1" />
|
||||
<element name="tags" type="tns:TagsType" minOccurs="0" maxOccurs="1" />
|
||||
<element name="files" type="tns:FilesType" minOccurs="0" maxOccurs="1" />
|
||||
</all>
|
||||
Loading…
Reference in New Issue
Block a user