Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 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.
 import java.util.*;

Provides meta information about the current dependencies

Sergio Fernández
 public class DependenciesServiceImpl implements DependenciesService {
     private Logger log;
     private List<Map<StringString>> dependencies;
     public DependenciesServiceImpl() {
         this. = new ArrayList<Map<StringString>>();
     public void populate() {
         InputStream deps;
         // first try to get webapp dependencies
         if (deps == null) {
             // fallback to the core dependencies only
             .warn("Dependencies not found at the webapp, so falling back to core dependencies...");
             deps = DependenciesServiceImpl.class.getResourceAsStream(.);
         if (deps == null) {
             .error("No suitable '{}' file found".);
         } else {
             DataInputStream in = new DataInputStream(deps);
             BufferedReader br = new BufferedReader(new InputStreamReader(in));
             String line;
             try {
                 // first two line generated by maven are not actually dependencies,
                 // anyway this code could be really buggy
                 while ((line = br.readLine()) != null) {
                     line = StringUtils.stripToNull(line);
                     if (line != null) {
                         Map<StringStringdep = new HashMap<StringString>();
                         String[] split = StringUtils.split(line":");
                         if (split.length >= 4) {
                             .debug("Recovered dependency " + split[0] + ":" + split[2] + ":" + split[2]);
             } catch (IOException e) {
                 .error("Error reading dependencies: " + e.getMessage());
             } catch (NullPointerException e) {
                 .error("Error reading dependencies: " + e.getMessage());
     public List<Map<StringString>> getArtifacts() {
         return Collections.unmodifiableList(this.);
    public List<Map<StringString>> getArtifacts(String groupId) {
        List<Map<StringString>> deps = new ArrayList<Map<StringString>>();
        for (Map<StringStringdep : this.) {
            if (groupId.equals(dep.get(.))) {
        return Collections.unmodifiableList(deps);
    public String getVersion(String groupIdString artifactId) {
        for (Map<StringStringdep : this.) {
            if (groupId.equals(dep.get(.)) &&
                    artifactId.equals(dep.get(.))) return dep.get(.);
        return null;
New to GrepCode? Check out our FAQ X