View Javadoc
1   package org.eclipse.aether.internal.impl.resolution;
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 java.util.List;
23  
24  import org.eclipse.aether.RepositorySystemSession;
25  import org.eclipse.aether.resolution.ArtifactResult;
26  import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor;
27  import org.eclipse.aether.util.ConfigUtils;
28  
29  import static java.util.Objects.requireNonNull;
30  
31  /**
32   * Support class to implement {@link ArtifactResolverPostProcessor}.
33   *
34   * @since 1.9.0
35   */
36  public abstract class ArtifactResolverPostProcessorSupport
37          implements ArtifactResolverPostProcessor
38  {
39      private static final String CONFIG_PROP_PREFIX = "aether.artifactResolver.postProcessor.";
40  
41      private final String name;
42  
43      protected ArtifactResolverPostProcessorSupport( String name )
44      {
45          this.name = requireNonNull( name );
46      }
47  
48      /**
49       * This implementation will call into underlying code only if enabled.
50       */
51      @Override
52      public void postProcess( RepositorySystemSession session, List<ArtifactResult> artifactResults )
53      {
54          if ( isEnabled( session ) )
55          {
56              doPostProcess( session, artifactResults );
57          }
58      }
59  
60      protected abstract void doPostProcess( RepositorySystemSession session, List<ArtifactResult> artifactResults );
61  
62      /**
63       * To be used by underlying implementations to form configuration property keys properly scoped.
64       */
65      protected String configPropKey( String name )
66      {
67          requireNonNull( name );
68          return CONFIG_PROP_PREFIX + this.name + "." + name;
69      }
70  
71      /**
72       * Returns {@code true} if session configuration marks this instance as enabled.
73       * <p>
74       * Default value is {@code false}.
75       */
76      protected boolean isEnabled( RepositorySystemSession session )
77      {
78          return ConfigUtils.getBoolean( session, false, CONFIG_PROP_PREFIX + this.name );
79      }
80  }