]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.maven/src/main/java/org/argeo/slc/maven/DependencyFileLoader.java
Clean up directories
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.maven / src / main / java / org / argeo / slc / maven / DependencyFileLoader.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.maven;
17
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.StringTokenizer;
22
23 import org.apache.commons.io.IOUtils;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.argeo.slc.SlcException;
27 import org.springframework.beans.factory.FactoryBean;
28 import org.springframework.core.io.Resource;
29
30 public class DependencyFileLoader implements FactoryBean{
31 private final static Log log = LogFactory.getLog(DependencyFileLoader.class);
32
33 private Resource dependenciesResource;
34
35 @SuppressWarnings("unchecked")
36 public List<MavenFile> loadMavenFiles() {
37 try {
38 List<MavenFile> mavenFiles = new ArrayList<MavenFile>();
39
40 List<String> lines = IOUtils.readLines(dependenciesResource
41 .getInputStream());
42 for (String line : lines) {
43 try {
44 line = line.trim();
45 if (line.equals("")
46 || line
47 .startsWith("The following files have been resolved:"))
48 continue;// skip
49
50 mavenFiles.add(convert(line));
51 } catch (Exception e) {
52 log.warn("Could not load line " + line);
53 }
54 }
55
56 return mavenFiles;
57 } catch (IOException e) {
58 throw new SlcException("Could not read dependencies resource "
59 + dependenciesResource, e);
60 }
61 }
62
63 protected MavenFile convert(String str) {
64 StringTokenizer st = new StringTokenizer(str, ":");
65 MavenFile component = new MavenFile();
66 component.setGroupId(st.nextToken());
67 component.setArtifactId(st.nextToken());
68 component.setType(st.nextToken());
69 component.setVersion(st.nextToken());
70 component.setScope(st.nextToken());
71 return component;
72 }
73
74 public void setDependenciesResource(Resource dependenciesResource) {
75 this.dependenciesResource = dependenciesResource;
76 }
77
78 public Object getObject() throws Exception {
79 return loadMavenFiles();
80 }
81
82 @SuppressWarnings("unchecked")
83 public Class<List> getObjectType() {
84 return List.class;
85 }
86
87 public boolean isSingleton() {
88 return false;
89 }
90
91
92 }