-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathInfo.java
More file actions
174 lines (154 loc) · 5.82 KB
/
Info.java
File metadata and controls
174 lines (154 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright (C) 2016 Google Inc.
*
* 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.
*/
package com.google.copybara;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.copybara.revision.Change;
import com.google.copybara.revision.Revision;
import java.util.Optional;
import javax.annotation.Nullable;
/**
* Represents the information about a Migration.
*
* <p>A migration can have one or more {@link MigrationReference}s.
*/
@AutoValue
public abstract class Info<O extends Revision> {
public static final Info<? extends Revision> EMPTY =
create(
ImmutableMultimap.of(), ImmutableMultimap.of(), ImmutableList.of(), ImmutableList.of());
public static <O extends Revision> Info<O> create(
ImmutableMultimap<String, String> originDescription,
ImmutableMultimap<String, String> destinationDescription,
Iterable<MigrationReference<O>> migrationReferences) {
return new AutoValue_Info<>(
originDescription,
destinationDescription,
ImmutableList.copyOf(migrationReferences),
ImmutableList.of());
}
public static <O extends Revision> Info<O> create(
ImmutableMultimap<String, String> originDescription,
ImmutableMultimap<String, String> destinationDescription,
Iterable<MigrationReference<O>> migrationReferences,
ImmutableList<Change<O>> versions) {
return new AutoValue_Info<>(
originDescription,
destinationDescription,
ImmutableList.copyOf(migrationReferences),
versions);
}
/**
* Returns origin description of the migration.
*/
public abstract ImmutableMultimap<String, String> originDescription();
/**
* Returns destination description of the migration.
*/
public abstract ImmutableMultimap<String, String> destinationDescription();
/**
* Returns information about a migration for one reference (like 'master')
*
* <p>Public so that it can be used programmatically.
*/
public abstract Iterable<MigrationReference<O>> migrationReferences();
/** Returns a list of the upstream versions for an origin. */
public abstract ImmutableList<Change<O>> versions();
@AutoValue
public abstract static class MigrationReference<O extends Revision> {
public static <O extends Revision> MigrationReference<O> create(
String label,
@Nullable O lastMigrated,
@Nullable Change<O> lastMigratedChange,
Iterable<Change<O>> availableToMigrate) {
return new AutoValue_Info_MigrationReference<>(
label, lastMigrated, lastMigratedChange, ImmutableList.copyOf(availableToMigrate), null);
}
public static <O extends Revision> MigrationReference<O> create(
String label,
@Nullable Change<O> lastMigratedChange,
Iterable<Change<O>> availableToMigrate) {
return new AutoValue_Info_MigrationReference<>(
label,
lastMigratedChange == null ? null : lastMigratedChange.getRevision(),
lastMigratedChange,
ImmutableList.copyOf(availableToMigrate),
null);
}
public static <O extends Revision> MigrationReference<O> create(
String label,
@Nullable O lastMigrated,
@Nullable Change<O> lastMigratedChange,
Iterable<Change<O>> availableToMigrate,
@Nullable Change<O> lastResolvedChange) {
return new AutoValue_Info_MigrationReference<>(
label,
lastMigrated,
lastMigratedChange,
ImmutableList.copyOf(availableToMigrate),
lastResolvedChange);
}
/**
* The name of this {@link MigrationReference}.
*
* <p>For a {@code Workflow} migration, the label is the string "workflow_" followed by the
* workflow name.
*
* <p>For a {@code Mirror} migration, the name is the string "mirror_" followed by the refspec.
*/
abstract String getLabel();
/**
* Returns the last migrated {@link Revision} from the origin, or {@code null} if no change was
* ever migrated.
*/
@Nullable
public abstract O getLastMigrated();
/**
* Returns the last migrated {@link Change} from the origin, or {@code null} if no change was
* ever migrated or if the last migrated reference is not in the list of changes.
*/
@Nullable
public abstract Change<O> getLastMigratedChange();
/**
* Returns the last available {@link Revision} to migrate from the origin, or {@code null} if
* there are no changes available to migrate.
*
* <p>There might be more available changes to migrate, but this is the revision of the most
* recent change available at this moment.
*/
@Nullable
public O getLastAvailableToMigrate() {
Optional<O> lastAvailable =
getAvailableToMigrate()
.stream()
.map(Change::getRevision)
.reduce((first, second) -> second);
return lastAvailable.orElse(null);
}
/**
* Returns a list of the next available {@link Change}s to migrate from the origin.
*/
public abstract ImmutableList<Change<O>> getAvailableToMigrate();
/**
* Returns the most recent {@link Change} that was resolved by the migration.
*
* @return The resolved {@link Change}.
*/
@Nullable
public abstract Change<O> getLastResolvedChange();
}
}