001/*
002 * Copyright 2012-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.cli.compiler.dependencies;
018
019import java.util.ArrayList;
020import java.util.Arrays;
021import java.util.List;
022
023/**
024 * {@link DependencyManagement} that delegates to one or more {@link DependencyManagement}
025 * instances.
026 *
027 * @author Andy Wilkinson
028 * @since 1.3.0
029 */
030public class CompositeDependencyManagement implements DependencyManagement {
031
032        private final List<DependencyManagement> delegates;
033
034        private final List<Dependency> dependencies = new ArrayList<Dependency>();
035
036        public CompositeDependencyManagement(DependencyManagement... delegates) {
037                this.delegates = Arrays.asList(delegates);
038                for (DependencyManagement delegate : delegates) {
039                        this.dependencies.addAll(delegate.getDependencies());
040                }
041        }
042
043        @Override
044        public List<Dependency> getDependencies() {
045                return this.dependencies;
046        }
047
048        @Override
049        public String getSpringBootVersion() {
050                for (DependencyManagement delegate : this.delegates) {
051                        String version = delegate.getSpringBootVersion();
052                        if (version != null) {
053                                return version;
054                        }
055                }
056                return null;
057        }
058
059        @Override
060        public Dependency find(String artifactId) {
061                for (DependencyManagement delegate : this.delegates) {
062                        Dependency found = delegate.find(artifactId);
063                        if (found != null) {
064                                return found;
065                        }
066                }
067                return null;
068        }
069
070}