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 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.marmotta.platform.core.services.config;
 
 
 import java.io.*;
 import java.util.*;

Provides meta information about the current dependencies

Author(s):
Sergio Fernández
 
 public class DependenciesServiceImpl implements DependenciesService {
 
     @Inject
     private Logger log;
 
     private List<Map<StringString>> dependencies;
 
     public DependenciesServiceImpl() {
         this. = new ArrayList<Map<StringString>>();
     }
 
     @PostConstruct
     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
                 br.readLine();
                 br.readLine();
 
                 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) {
                             dep.put(.split[0]);
                             dep.put(.split[1]);
                             dep.put(.split[3]);
                             this..add(dep);
                             .debug("Recovered dependency " + split[0] + ":" + split[2] + ":" + split[2]);
                         }
                     }
                 }
 
                 br.close();
 
             } catch (IOException e) {
                 .error("Error reading dependencies: " + e.getMessage());
             } catch (NullPointerException e) {
                 .error("Error reading dependencies: " + e.getMessage());
             }
         }
     }
 
     @Override
     public List<Map<StringString>> getArtifacts() {
         return Collections.unmodifiableList(this.);
    }
    @Override
    public List<Map<StringString>> getArtifacts(String groupId) {
        List<Map<StringString>> deps = new ArrayList<Map<StringString>>();
        for (Map<StringStringdep : this.) {
            if (groupId.equals(dep.get(.))) {
                deps.add(Collections.unmodifiableMap(dep));
            }
        }
        return Collections.unmodifiableList(deps);
    }
    @Override
    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