Skip to content

Commit 2eacf58

Browse files
committed
Improvements
1 parent 7e9fa5f commit 2eacf58

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

maven-resolver-api/src/main/java/org/eclipse/aether/SyncContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void acquire(Collection<? extends Artifact> artifacts, Collection<? extends Meta
7676
/**
7777
* Specific exception thrown by {@link #acquire(Collection, Collection)} method when it cannot acquire the lock.
7878
*
79-
* @since 2.0.14
79+
* @since 1.9.25
8080
*/
8181
final class FailedToAcquireLockException extends IllegalStateException {
8282
private final boolean shared;

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapter.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collection;
2323
import java.util.Deque;
2424
import java.util.concurrent.TimeUnit;
25+
import java.util.stream.Collectors;
2526

2627
import org.eclipse.aether.ConfigurationProperties;
2728
import org.eclipse.aether.RepositorySystemSession;
@@ -33,6 +34,7 @@
3334
import org.eclipse.aether.named.NamedLockKey;
3435
import org.eclipse.aether.named.providers.FileLockNamedLockFactory;
3536
import org.eclipse.aether.util.ConfigUtils;
37+
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
3638
import org.slf4j.Logger;
3739
import org.slf4j.LoggerFactory;
3840

@@ -255,14 +257,48 @@ public void acquire(Collection<? extends Artifact> artifacts, Collection<? exten
255257
}
256258
// if we are here, means all attempts were unsuccessful: fail
257259
close();
258-
FailedToAcquireLockException ex = new FailedToAcquireLockException(
259-
shared,
260-
"Could not acquire " + lockKind + " lock for "
261-
+ namedLock.key().resources() + " using lock "
262-
+ namedLock.key().name() + " in " + timeStr);
260+
String message = "Could not acquire " + lockKind + " lock for "
261+
+ lockSubjects(artifacts, metadatas) + " in " + timeStr
262+
+ "; consider using '" + CONFIG_PROP_TIME
263+
+ "' property to increase lock timeout to a value that fits your environment";
264+
FailedToAcquireLockException ex = new FailedToAcquireLockException(shared, message);
263265
throw namedLockFactory.onFailure(ex);
264266
}
265267

268+
private String lockSubjects(
269+
Collection<? extends Artifact> artifacts, Collection<? extends Metadata> metadatas) {
270+
StringBuilder builder = new StringBuilder();
271+
if (artifacts != null && !artifacts.isEmpty()) {
272+
builder.append("artifacts: ")
273+
.append(artifacts.stream().map(ArtifactIdUtils::toId).collect(Collectors.joining(", ")));
274+
}
275+
if (metadatas != null && !metadatas.isEmpty()) {
276+
if (builder.length() != 0) {
277+
builder.append("; ");
278+
}
279+
builder.append("metadata: ")
280+
.append(metadatas.stream().map(this::metadataSubjects).collect(Collectors.joining(", ")));
281+
}
282+
return builder.toString();
283+
}
284+
285+
private String metadataSubjects(Metadata metadata) {
286+
String name = "";
287+
if (!metadata.getGroupId().isEmpty()) {
288+
name += metadata.getGroupId();
289+
if (!metadata.getArtifactId().isEmpty()) {
290+
name += ":" + metadata.getArtifactId();
291+
if (!metadata.getVersion().isEmpty()) {
292+
name += ":" + metadata.getVersion();
293+
}
294+
}
295+
}
296+
if (!metadata.getType().isEmpty()) {
297+
name += (name.isEmpty() ? "" : ":") + metadata.getType();
298+
}
299+
return name;
300+
}
301+
266302
@Override
267303
public void close() {
268304
while (!locks.isEmpty()) {

0 commit comments

Comments
 (0)