/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.sling.testing.paxexam;

import java.util.HashMap;
import java.util.Map;

import org.ops4j.pax.exam.MavenUtils;
import org.ops4j.pax.exam.options.MavenUrlReference.VersionResolver;

/**
 * NOTE: This file is generated from Sling's Karaf Features
 */
public class SlingVersionResolver implements VersionResolver {

    private final Map<String, String> versions = new HashMap<>();

    public static final String SLING_GROUP_ID = "org.apache.sling";

    public SlingVersionResolver() {
        versions.put("org.apache.sling:org.apache.sling.scripting.jsp-api", "1.0.0");
        versions.put("org.apache.sling:org.apache.sling.scripting.el-api", "1.0.0");
        versions.put("org.apache.felix:org.apache.felix.configadmin", "1.8.14");
        versions.put("org.apache.felix:org.apache.felix.eventadmin", "1.4.8");
        versions.put("org.apache.felix:org.apache.felix.http.jetty", "3.4.2");
        versions.put("org.apache.felix:org.apache.felix.http.servlet-api", "1.1.2");
        versions.put("org.apache.felix:org.apache.felix.http.whiteboard", "3.0.0");
        versions.put("org.apache.felix:org.apache.felix.webconsole.plugins.ds", "2.0.6");
        versions.put("org.apache.aries:org.apache.aries.util", "1.1.3");
        versions.put("org.apache.aries.jmx:org.apache.aries.jmx.api", "1.1.5");
        versions.put("org.apache.aries.jmx:org.apache.aries.jmx.core", "1.1.7");
        versions.put("org.apache.aries.jmx:org.apache.aries.jmx.whiteboard", "1.1.5");
        versions.put("org.apache.felix:org.apache.felix.inventory", "1.0.4");
        versions.put("org.apache.felix:org.apache.felix.metatype", "1.1.2");
        versions.put("org.apache.felix:org.apache.felix.scr", "2.0.8");
        versions.put("org.apache.felix:org.apache.felix.webconsole", "4.3.0");
        versions.put("org.ops4j.base:ops4j-base-lang", "1.5.0");
        versions.put("org.ops4j.base:ops4j-base-util-property", "1.5.0");
        versions.put("org.ops4j.pax.swissbox:pax-swissbox-property", "1.8.2");
        versions.put("org.ops4j.pax.url:pax-url-classpath", "2.5.2");
        versions.put("org.ops4j.pax.url:pax-url-commons", "2.5.2");
        versions.put("org.slf4j:log4j-over-slf4j", "1.7.24");[# th:each="bundle : ${bundles}"]
        versions.put("[(${bundle.groupId})]:[(${bundle.artifactId})]", "[(${bundle.version})]");
[/]    }

    private String key(final String groupId, final String artifactId) {
        return String.format("%s:%s", groupId, artifactId);
    }

    public String setVersion(final String groupId, final String artifactId, final String version) {
        return versions.put(key(groupId, artifactId), version);
    }

    public String setVersionFromProject(final String groupId, final String artifactId) {
        final String version = MavenUtils.getArtifactVersion(groupId, artifactId);
        return versions.put(key(groupId, artifactId), version);
    }

    @Override
    public String getVersion(final String groupId, final String artifactId) {
        return versions.get(key(groupId, artifactId));
    }

}
