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.util.graph.transformer;
20  
21  import org.eclipse.aether.RepositoryException;
22  import org.eclipse.aether.util.artifact.DependencyScopes;
23  import org.eclipse.aether.util.artifact.JavaScopes;
24  import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeContext;
25  import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeDeriver;
26  
27  /**
28   * A scope deriver for use with {@link ConflictResolver} that supports the scopes from {@link JavaScopes}.
29   *
30   * @deprecated This class belongs to consumer project. Resolver have no notion of scopes other than those defined
31   * in {@link DependencyScopes} class, moreover it has no knowledge about scope transformation
32   * of dependencies to build path scopes.
33   */
34  @Deprecated
35  public final class JavaScopeDeriver extends ScopeDeriver {
36  
37      /**
38       * Creates a new instance of this scope deriver.
39       */
40      public JavaScopeDeriver() {}
41  
42      @Override
43      public void deriveScope(ScopeContext context) throws RepositoryException {
44          context.setDerivedScope(getDerivedScope(context.getParentScope(), context.getChildScope()));
45      }
46  
47      private String getDerivedScope(String parentScope, String childScope) {
48          String derivedScope;
49  
50          if (JavaScopes.SYSTEM.equals(childScope) || JavaScopes.TEST.equals(childScope)) {
51              derivedScope = childScope;
52          } else if (parentScope == null || parentScope.isEmpty() || JavaScopes.COMPILE.equals(parentScope)) {
53              derivedScope = childScope;
54          } else if (JavaScopes.TEST.equals(parentScope) || JavaScopes.RUNTIME.equals(parentScope)) {
55              derivedScope = parentScope;
56          } else if (JavaScopes.SYSTEM.equals(parentScope) || JavaScopes.PROVIDED.equals(parentScope)) {
57              derivedScope = JavaScopes.PROVIDED;
58          } else {
59              derivedScope = JavaScopes.RUNTIME;
60          }
61  
62          return derivedScope;
63      }
64  }