001package org.eclipse.aether.internal.impl.resolution; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.List; 023 024import org.eclipse.aether.RepositorySystemSession; 025import org.eclipse.aether.resolution.ArtifactResult; 026import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor; 027import org.eclipse.aether.util.ConfigUtils; 028 029import static java.util.Objects.requireNonNull; 030 031/** 032 * Support class to implement {@link ArtifactResolverPostProcessor}. 033 * 034 * @since 1.9.0 035 */ 036public abstract class ArtifactResolverPostProcessorSupport 037 implements ArtifactResolverPostProcessor 038{ 039 private static final String CONFIG_PROP_PREFIX = "aether.artifactResolver.postProcessor."; 040 041 private final String name; 042 043 protected ArtifactResolverPostProcessorSupport( String name ) 044 { 045 this.name = requireNonNull( name ); 046 } 047 048 /** 049 * This implementation will call into underlying code only if enabled. 050 */ 051 @Override 052 public void postProcess( RepositorySystemSession session, List<ArtifactResult> artifactResults ) 053 { 054 if ( isEnabled( session ) ) 055 { 056 doPostProcess( session, artifactResults ); 057 } 058 } 059 060 protected abstract void doPostProcess( RepositorySystemSession session, List<ArtifactResult> artifactResults ); 061 062 /** 063 * To be used by underlying implementations to form configuration property keys properly scoped. 064 */ 065 protected String configPropKey( String name ) 066 { 067 requireNonNull( name ); 068 return CONFIG_PROP_PREFIX + this.name + "." + name; 069 } 070 071 /** 072 * Returns {@code true} if session configuration marks this instance as enabled. 073 * <p> 074 * Default value is {@code false}. 075 */ 076 protected boolean isEnabled( RepositorySystemSession session ) 077 { 078 return ConfigUtils.getBoolean( session, false, CONFIG_PROP_PREFIX + this.name ); 079 } 080}