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.scope;
20  
21  import java.util.Map;
22  
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.artifact.ArtifactProperties;
25  
26  /**
27   * A special dependency scope: "system".
28   * <p>
29   * This is a special scope. In this scope case, Resolver should handle dependencies specially, as they have no POM (so
30   * are always a leaf on graph), are not in any repository, but are actually hosted on host OS file system. On resolution
31   * resolver merely checks is file present or not.
32   *
33   * @since 2.0.0
34   *
35   * @noimplement This interface is not intended to be implemented by clients.
36   * @noextend This interface is not intended to be extended by clients.
37   */
38  public interface SystemDependencyScope extends DependencyScope {
39      /**
40       * Returns system path string of provided artifact, or {@code null}.
41       *
42       * @param artifact The artifact that we want system path from, must not be {@code null}.
43       * @return the system path from passed in properties, or {@code null} if not present.
44       */
45      String getSystemPath(Artifact artifact);
46  
47      /**
48       * Sets system path in properties. The passed in {@code systemPath} can be {@code null}, in which case expected
49       * operation is "remove" (or "unset").
50       *
51       * @param properties the properties map, must not be {@code null}.
52       * @param systemPath the system path to set (if not {@code null}) or unset (if {@code null}).
53       */
54      void setSystemPath(Map<String, String> properties, String systemPath);
55  
56      /**
57       * The "legacy" system scope, used when there is no {@link ScopeManager} set on session.
58       */
59      SystemDependencyScope LEGACY = new SystemDependencyScope() {
60          @Override
61          public String getSystemPath(Artifact artifact) {
62              return artifact.getProperty(ArtifactProperties.LOCAL_PATH, null);
63          }
64  
65          @Override
66          public void setSystemPath(Map<String, String> properties, String systemPath) {
67              if (systemPath == null) {
68                  properties.remove(ArtifactProperties.LOCAL_PATH);
69              } else {
70                  properties.put(ArtifactProperties.LOCAL_PATH, systemPath);
71              }
72          }
73  
74          @Override
75          public String getId() {
76              return "system";
77          }
78  
79          @Override
80          public boolean isTransitive() {
81              return false;
82          }
83      };
84  }