1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import org.eclipse.aether.RepositorySystemSession;
22 import org.eclipse.aether.artifact.Artifact;
23 import org.eclipse.aether.impl.UpdateCheck;
24 import org.eclipse.aether.impl.UpdateCheckManager;
25 import org.eclipse.aether.metadata.Metadata;
26 import org.eclipse.aether.transfer.ArtifactNotFoundException;
27 import org.eclipse.aether.transfer.ArtifactTransferException;
28 import org.eclipse.aether.transfer.MetadataNotFoundException;
29 import org.eclipse.aether.transfer.MetadataTransferException;
30
31 import static java.util.Objects.requireNonNull;
32
33 class StaticUpdateCheckManager implements UpdateCheckManager {
34
35 private final boolean checkRequired;
36
37 private final boolean localUpToDate;
38
39 public StaticUpdateCheckManager(boolean checkRequired) {
40 this(checkRequired, !checkRequired);
41 }
42
43 public StaticUpdateCheckManager(boolean checkRequired, boolean localUpToDate) {
44 this.checkRequired = checkRequired;
45 this.localUpToDate = localUpToDate;
46 }
47
48 @Override
49 public void touchMetadata(RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check) {
50 requireNonNull(session, "session cannot be null");
51 requireNonNull(check, "check cannot be null");
52 }
53
54 @Override
55 public void touchArtifact(RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check) {
56 requireNonNull(session, "session cannot be null");
57 requireNonNull(check, "check cannot be null");
58 }
59
60 @Override
61 public void checkMetadata(RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check) {
62 requireNonNull(session, "session cannot be null");
63 requireNonNull(check, "check cannot be null");
64 check.setRequired(checkRequired);
65
66 if (check.getLocalLastUpdated() != 0L && localUpToDate) {
67 check.setRequired(false);
68 }
69 if (!check.isRequired() && !check.getFile().isFile()) {
70 check.setException(new MetadataNotFoundException(check.getItem(), check.getRepository()));
71 }
72 }
73
74 @Override
75 public void checkArtifact(RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check) {
76 requireNonNull(session, "session cannot be null");
77 requireNonNull(check, "check cannot be null");
78 check.setRequired(checkRequired);
79
80 if (check.getLocalLastUpdated() != 0L && localUpToDate) {
81 check.setRequired(false);
82 }
83 if (!check.isRequired() && !check.getFile().isFile()) {
84 check.setException(new ArtifactNotFoundException(check.getItem(), check.getRepository()));
85 }
86 }
87 }