001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.scope;
020
021import java.util.Map;
022
023import org.eclipse.aether.artifact.Artifact;
024import org.eclipse.aether.artifact.ArtifactProperties;
025
026/**
027 * A special dependency scope: "system".
028 * <p>
029 * This is a special scope. In this scope case, Resolver should handle dependencies specially, as they have no POM (so
030 * are always a leaf on graph), are not in any repository, but are actually hosted on host OS file system. On resolution
031 * resolver merely checks is file present or not.
032 *
033 * @since 2.0.0
034 *
035 * @noimplement This interface is not intended to be implemented by clients.
036 * @noextend This interface is not intended to be extended by clients.
037 */
038public interface SystemDependencyScope extends DependencyScope {
039    /**
040     * Returns system path string of provided artifact, or {@code null}.
041     *
042     * @param artifact The artifact that we want system path from, must not be {@code null}.
043     * @return the system path from passed in properties, or {@code null} if not present.
044     */
045    String getSystemPath(Artifact artifact);
046
047    /**
048     * Sets system path in properties. The passed in {@code systemPath} can be {@code null}, in which case expected
049     * operation is "remove" (or "unset").
050     *
051     * @param properties the properties map, must not be {@code null}.
052     * @param systemPath the system path to set (if not {@code null}) or unset (if {@code null}).
053     */
054    void setSystemPath(Map<String, String> properties, String systemPath);
055
056    /**
057     * The "legacy" system scope, used when there is no {@link ScopeManager} set on session.
058     */
059    SystemDependencyScope LEGACY = new SystemDependencyScope() {
060        @Override
061        public String getSystemPath(Artifact artifact) {
062            return artifact.getProperty(ArtifactProperties.LOCAL_PATH, null);
063        }
064
065        @Override
066        public void setSystemPath(Map<String, String> properties, String systemPath) {
067            if (systemPath == null) {
068                properties.remove(ArtifactProperties.LOCAL_PATH);
069            } else {
070                properties.put(ArtifactProperties.LOCAL_PATH, systemPath);
071            }
072        }
073
074        @Override
075        public String getId() {
076            return "system";
077        }
078
079        @Override
080        public boolean isTransitive() {
081            return false;
082        }
083    };
084}