View Javadoc
1   package org.eclipse.aether.internal.impl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.eclipse.aether.RepositorySystemSession;
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.impl.UpdateCheck;
25  import org.eclipse.aether.impl.UpdateCheckManager;
26  import org.eclipse.aether.metadata.Metadata;
27  import org.eclipse.aether.transfer.ArtifactNotFoundException;
28  import org.eclipse.aether.transfer.ArtifactTransferException;
29  import org.eclipse.aether.transfer.MetadataNotFoundException;
30  import org.eclipse.aether.transfer.MetadataTransferException;
31  
32  import static java.util.Objects.requireNonNull;
33  
34  class StaticUpdateCheckManager
35      implements UpdateCheckManager
36  {
37  
38      private boolean checkRequired;
39  
40      private boolean localUpToDate;
41  
42      public StaticUpdateCheckManager( boolean checkRequired )
43      {
44          this( checkRequired, !checkRequired );
45      }
46  
47      public StaticUpdateCheckManager( boolean checkRequired, boolean localUpToDate )
48      {
49          this.checkRequired = checkRequired;
50          this.localUpToDate = localUpToDate;
51      }
52  
53      public void touchMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check )
54      {
55          requireNonNull( session, "session cannot be null" );
56          requireNonNull( check, "check cannot be null" );
57      }
58  
59      public void touchArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check )
60      {
61          requireNonNull( session, "session cannot be null" );
62          requireNonNull( check, "check cannot be null" );
63      }
64  
65      public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check )
66      {
67          requireNonNull( session, "session cannot be null" );
68          requireNonNull( check, "check cannot be null" );
69          check.setRequired( checkRequired );
70  
71          if ( check.getLocalLastUpdated() != 0L && localUpToDate )
72          {
73              check.setRequired( false );
74          }
75          if ( !check.isRequired() && !check.getFile().isFile() )
76          {
77              check.setException( new MetadataNotFoundException( check.getItem(), check.getRepository() ) );
78          }
79      }
80  
81      public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check )
82      {
83          requireNonNull( session, "session cannot be null" );
84          requireNonNull( check, "check cannot be null" );
85          check.setRequired( checkRequired );
86  
87          if ( check.getLocalLastUpdated() != 0L && localUpToDate )
88          {
89              check.setRequired( false );
90          }
91          if ( !check.isRequired() && !check.getFile().isFile() )
92          {
93              check.setException( new ArtifactNotFoundException( check.getItem(), check.getRepository() ) );
94          }
95      }
96  
97  }