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 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  }