3333import java .util .List ;
3434import java .util .Map ;
3535import java .util .concurrent .atomic .AtomicBoolean ;
36- import java .util .function .Supplier ;
3736
3837import org .eclipse .aether .ConfigurationProperties ;
3938import org .eclipse .aether .RepositoryEvent ;
@@ -98,20 +97,19 @@ public class DefaultArtifactResolver implements ArtifactResolver {
9897 * Configuration to enable "snapshot normalization", downloaded snapshots from remote with timestamped file names
9998 * will have file names converted back to baseVersion. It replaces the timestamped snapshot file name with a
10099 * filename containing the SNAPSHOT qualifier only. This only affects resolving/retrieving artifacts but not
101- * uploading those. Provides Maven 2 compatibility.
100+ * uploading those.
102101 *
103102 * @configurationSource {@link RepositorySystemSession#getConfigProperties()}
104103 * @configurationType {@link java.lang.Boolean}
105104 * @configurationDefaultValue {@link #DEFAULT_SNAPSHOT_NORMALIZATION}
106105 */
107106 public static final String CONFIG_PROP_SNAPSHOT_NORMALIZATION = CONFIG_PROPS_PREFIX + "snapshotNormalization" ;
108107
109- public static final boolean DEFAULT_SNAPSHOT_NORMALIZATION = false ;
108+ public static final boolean DEFAULT_SNAPSHOT_NORMALIZATION = true ;
110109
111110 /**
112111 * Configuration to enable "interoperability" with Simple LRM, but this breaks RRF feature, hence this configuration
113112 * is IGNORED when RRF is used, and is warmly recommended to leave it disabled even if no RRF is being used.
114- * Provides Maven 2 compatibility.
115113 *
116114 * @configurationSource {@link RepositorySystemSession#getConfigProperties()}
117115 * @configurationType {@link java.lang.Boolean}
@@ -188,52 +186,35 @@ public List<ArtifactResult> resolveArtifacts(
188186 throws ArtifactResolutionException {
189187 requireNonNull (session , "session cannot be null" );
190188 requireNonNull (requests , "requests cannot be null" );
191-
192- Collection <Artifact > artifacts = new ArrayList <>(requests .size ());
193- SystemDependencyScope systemDependencyScope = session .getSystemDependencyScope ();
194- for (ArtifactRequest request : requests ) {
195- if (systemDependencyScope != null && systemDependencyScope .getSystemPath (request .getArtifact ()) != null ) {
196- continue ;
189+ try (SyncContext shared = syncContextFactory .newInstance (session , true );
190+ SyncContext exclusive = syncContextFactory .newInstance (session , false )) {
191+ Collection <Artifact > artifacts = new ArrayList <>(requests .size ());
192+ SystemDependencyScope systemDependencyScope = session .getSystemDependencyScope ();
193+ for (ArtifactRequest request : requests ) {
194+ if (systemDependencyScope != null
195+ && systemDependencyScope .getSystemPath (request .getArtifact ()) != null ) {
196+ continue ;
197+ }
198+ artifacts .add (request .getArtifact ());
197199 }
198- artifacts .add (request .getArtifact ());
199- }
200200
201- return resolve (
202- () -> syncContextFactory .newInstance (session , true ),
203- () -> syncContextFactory .newInstance (session , false ),
204- artifacts ,
205- session ,
206- requests );
201+ return resolve (shared , exclusive , artifacts , session , requests );
202+ }
207203 }
208204
209205 @ SuppressWarnings ("checkstyle:methodlength" )
210206 private List <ArtifactResult > resolve (
211- Supplier < SyncContext > sharedSupplier ,
212- Supplier < SyncContext > exclusiveSupplier ,
207+ SyncContext shared ,
208+ SyncContext exclusive ,
213209 Collection <Artifact > subjects ,
214210 RepositorySystemSession session ,
215211 Collection <? extends ArtifactRequest > requests )
216212 throws ArtifactResolutionException {
217213 SystemDependencyScope systemDependencyScope = session .getSystemDependencyScope ();
218- boolean firstAttempt = true ; // controls eventing; must happen only once
219- boolean currentShared = true ;
220- SyncContext current = sharedSupplier .get ();
214+ SyncContext current = shared ;
221215 try {
222216 while (true ) {
223- try {
224- current .acquire (subjects , null );
225- } catch (SyncContext .FailedToAcquireLockException e ) {
226- if (currentShared ) {
227- // we have to give up; timeout on shared lock acquire
228- throw e ;
229- } else {
230- // assume "someone else is working on this"; swap back to shared and retry
231- current .close ();
232- current = sharedSupplier .get ();
233- currentShared = true ;
234- continue ;
235- }
236- }
217+ current .acquire (subjects , null );
237218
238219 boolean failures = false ;
239220 final List <ArtifactResult > results = new ArrayList <>(requests .size ());
@@ -253,7 +234,7 @@ private List<ArtifactResult> resolve(
253234
254235 Artifact artifact = request .getArtifact ();
255236
256- if (firstAttempt ) {
237+ if (current == shared ) {
257238 artifactResolving (session , trace , artifact );
258239 }
259240
@@ -408,11 +389,9 @@ private List<ArtifactResult> resolve(
408389 }
409390 }
410391
411- if (!groups .isEmpty () && currentShared ) {
412- firstAttempt = false ; // all "resolving" events fired, no more of them
392+ if (!groups .isEmpty () && current == shared ) {
413393 current .close ();
414- currentShared = false ;
415- current = exclusiveSupplier .get ();
394+ current = exclusive ;
416395 continue ;
417396 }
418397
0 commit comments