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  class StaticUpdateCheckManager
33      implements UpdateCheckManager
34  {
35  
36      private boolean checkRequired;
37  
38      private boolean localUpToDate;
39  
40      public StaticUpdateCheckManager( boolean checkRequired )
41      {
42          this( checkRequired, !checkRequired );
43      }
44  
45      public StaticUpdateCheckManager( boolean checkRequired, boolean localUpToDate )
46      {
47          this.checkRequired = checkRequired;
48          this.localUpToDate = localUpToDate;
49      }
50  
51      public void touchMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check )
52      {
53      }
54  
55      public void touchArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check )
56      {
57      }
58  
59      public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check )
60      {
61          check.setRequired( checkRequired );
62  
63          if ( check.getLocalLastUpdated() != 0L && localUpToDate )
64          {
65              check.setRequired( false );
66          }
67          if ( !check.isRequired() && !check.getFile().isFile() )
68          {
69              check.setException( new MetadataNotFoundException( check.getItem(), check.getRepository() ) );
70          }
71      }
72  
73      public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check )
74      {
75          check.setRequired( checkRequired );
76  
77          if ( check.getLocalLastUpdated() != 0L && localUpToDate )
78          {
79              check.setRequired( false );
80          }
81          if ( !check.isRequired() && !check.getFile().isFile() )
82          {
83              check.setException( new ArtifactNotFoundException( check.getItem(), check.getRepository() ) );
84          }
85      }
86  
87  }