View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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 boolean checkRequired;
36  
37      private 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      public void touchMetadata(RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check) {
49          requireNonNull(session, "session cannot be null");
50          requireNonNull(check, "check cannot be null");
51      }
52  
53      public void touchArtifact(RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check) {
54          requireNonNull(session, "session cannot be null");
55          requireNonNull(check, "check cannot be null");
56      }
57  
58      public void checkMetadata(RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check) {
59          requireNonNull(session, "session cannot be null");
60          requireNonNull(check, "check cannot be null");
61          check.setRequired(checkRequired);
62  
63          if (check.getLocalLastUpdated() != 0L && localUpToDate) {
64              check.setRequired(false);
65          }
66          if (!check.isRequired() && !check.getFile().isFile()) {
67              check.setException(new MetadataNotFoundException(check.getItem(), check.getRepository()));
68          }
69      }
70  
71      public void checkArtifact(RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check) {
72          requireNonNull(session, "session cannot be null");
73          requireNonNull(check, "check cannot be null");
74          check.setRequired(checkRequired);
75  
76          if (check.getLocalLastUpdated() != 0L && localUpToDate) {
77              check.setRequired(false);
78          }
79          if (!check.isRequired() && !check.getFile().isFile()) {
80              check.setException(new ArtifactNotFoundException(check.getItem(), check.getRepository()));
81          }
82      }
83  }