@@ -66,6 +66,9 @@ public Path getResourcesDir() {
6666 @ Input
6767 public abstract Property <String > getCurrentUpperBoundName ();
6868
69+ @ Input
70+ public abstract Property <Boolean > getCI ();
71+
6972 private static final Pattern NAME_FORMAT = Pattern .compile ("[a-z0-9_]+" );
7073
7174 @ ServiceReference ("transportVersionResources" )
@@ -82,13 +85,14 @@ public void validateTransportVersions() throws IOException {
8285 Map <String , TransportVersionUpperBound > upperBounds = resources .getUpperBounds ();
8386 TransportVersionUpperBound currentUpperBound = upperBounds .get (getCurrentUpperBoundName ().get ());
8487 boolean onReleaseBranch = checkIfDefinitelyOnReleaseBranch (upperBounds );
88+ boolean validateModifications = onReleaseBranch == false || getCI ().get ();
8589
8690 for (var definition : referableDefinitions .values ()) {
87- validateNamedDefinition (definition , referencedNames );
91+ validateNamedDefinition (definition , referencedNames , validateModifications );
8892 }
8993
9094 for (var definition : unreferableDefinitions .values ()) {
91- validateUnreferableDefinition (definition );
95+ validateUnreferableDefinition (definition , validateModifications );
9296 }
9397
9498 for (var entry : idsByBase .entrySet ()) {
@@ -101,10 +105,10 @@ public void validateTransportVersions() throws IOException {
101105
102106 if (onReleaseBranch ) {
103107 // on release branches we only check the current upper bound, others may be inaccurate
104- validateUpperBound (currentUpperBound , allDefinitions , idsByBase );
108+ validateUpperBound (currentUpperBound , allDefinitions , idsByBase , validateModifications );
105109 } else {
106110 for (var upperBound : upperBounds .values ()) {
107- validateUpperBound (upperBound , allDefinitions , idsByBase );
111+ validateUpperBound (upperBound , allDefinitions , idsByBase , validateModifications );
108112 }
109113
110114 validatePrimaryIds (resources , upperBounds , allDefinitions );
@@ -126,7 +130,11 @@ private Map<String, TransportVersionDefinition> collectAllDefinitions(
126130 return allDefinitions ;
127131 }
128132
129- private void validateNamedDefinition (TransportVersionDefinition definition , Set <String > referencedNames ) {
133+ private void validateNamedDefinition (
134+ TransportVersionDefinition definition ,
135+ Set <String > referencedNames ,
136+ boolean validateModifications
137+ ) {
130138 if (referencedNames .contains (definition .name ()) == false ) {
131139 throwDefinitionFailure (definition , "is not referenced" );
132140 }
@@ -152,35 +160,39 @@ private void validateNamedDefinition(TransportVersionDefinition definition, Set<
152160 }
153161 }
154162 }
155- // validate any modifications
156- TransportVersionDefinition originalDefinition = getResources ().get ().getReferableDefinitionFromGitBase (definition .name ());
157- if (originalDefinition != null ) {
158- validateIdenticalPrimaryId (definition , originalDefinition );
159- for (int i = 1 ; i < originalDefinition .ids ().size (); ++i ) {
160- TransportVersionId originalId = originalDefinition .ids ().get (i );
161-
162- // we have a very small number of ids in a definition, so just search linearly
163- boolean found = false ;
164- for (int j = 1 ; j < definition .ids ().size (); ++j ) {
165- TransportVersionId id = definition .ids ().get (j );
166- if (id .base () == originalId .base ()) {
167- found = true ;
168- if (id .complete () != originalId .complete ()) {
169- throwDefinitionFailure (definition , "has modified patch id from " + originalId + " to " + id );
163+
164+ if (validateModifications ) {
165+ TransportVersionDefinition originalDefinition = getResources ().get ().getReferableDefinitionFromGitBase (definition .name ());
166+ if (originalDefinition != null ) {
167+ validateIdenticalPrimaryId (definition , originalDefinition );
168+ for (int i = 1 ; i < originalDefinition .ids ().size (); ++i ) {
169+ TransportVersionId originalId = originalDefinition .ids ().get (i );
170+
171+ // we have a very small number of ids in a definition, so just search linearly
172+ boolean found = false ;
173+ for (int j = 1 ; j < definition .ids ().size (); ++j ) {
174+ TransportVersionId id = definition .ids ().get (j );
175+ if (id .base () == originalId .base ()) {
176+ found = true ;
177+ if (id .complete () != originalId .complete ()) {
178+ throwDefinitionFailure (definition , "has modified patch id from " + originalId + " to " + id );
179+ }
170180 }
171181 }
172- }
173- if ( found == false ) {
174- throwDefinitionFailure ( definition , "has removed id " + originalId );
182+ if ( found == false ) {
183+ throwDefinitionFailure ( definition , "has removed id " + originalId );
184+ }
175185 }
176186 }
177187 }
178188 }
179189
180- private void validateUnreferableDefinition (TransportVersionDefinition definition ) {
181- TransportVersionDefinition originalDefinition = getResources ().get ().getUnreferableDefinitionFromGitBase (definition .name ());
182- if (originalDefinition != null ) {
183- validateIdenticalPrimaryId (definition , originalDefinition );
190+ private void validateUnreferableDefinition (TransportVersionDefinition definition , boolean validateModifications ) {
191+ if (validateModifications ) {
192+ TransportVersionDefinition originalDefinition = getResources ().get ().getUnreferableDefinitionFromGitBase (definition .name ());
193+ if (originalDefinition != null ) {
194+ validateIdenticalPrimaryId (definition , originalDefinition );
195+ }
184196 }
185197 if (definition .ids ().isEmpty ()) {
186198 throwDefinitionFailure (definition , "does not contain any ids" );
@@ -204,7 +216,8 @@ private void validateIdenticalPrimaryId(TransportVersionDefinition definition, T
204216 private void validateUpperBound (
205217 TransportVersionUpperBound upperBound ,
206218 Map <String , TransportVersionDefinition > definitions ,
207- Map <Integer , List <IdAndDefinition >> idsByBase
219+ Map <Integer , List <IdAndDefinition >> idsByBase ,
220+ boolean validateModifications
208221 ) {
209222 TransportVersionDefinition upperBoundDefinition = definitions .get (upperBound .definitionName ());
210223 if (upperBoundDefinition == null ) {
@@ -240,13 +253,16 @@ private void validateUpperBound(
240253 );
241254 }
242255
243- TransportVersionUpperBound existingUpperBound = getResources ().get ().getUpperBoundFromGitBase (upperBound .name ());
244- if (existingUpperBound != null && getShouldValidatePrimaryIdNotPatch ().get ()) {
245- if (upperBound .definitionId ().patch () != 0 && upperBound .definitionId ().base () != existingUpperBound .definitionId ().base ()) {
246- throwUpperBoundFailure (
247- upperBound ,
248- "modifies base id from " + existingUpperBound .definitionId ().base () + " to " + upperBound .definitionId ().base ()
249- );
256+ if (validateModifications ) {
257+ TransportVersionUpperBound existingUpperBound = getResources ().get ().getUpperBoundFromGitBase (upperBound .name ());
258+ if (existingUpperBound != null && getShouldValidatePrimaryIdNotPatch ().get ()) {
259+ if (upperBound .definitionId ().patch () != 0
260+ && upperBound .definitionId ().base () != existingUpperBound .definitionId ().base ()) {
261+ throwUpperBoundFailure (
262+ upperBound ,
263+ "modifies base id from " + existingUpperBound .definitionId ().base () + " to " + upperBound .definitionId ().base ()
264+ );
265+ }
250266 }
251267 }
252268 }
0 commit comments