2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.maven
;
18 import java
.io
.IOException
;
19 import java
.util
.ArrayList
;
20 import java
.util
.List
;
21 import java
.util
.StringTokenizer
;
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
;
30 public class DependencyFileLoader
implements FactoryBean
{
31 private final static Log log
= LogFactory
.getLog(DependencyFileLoader
.class);
33 private Resource dependenciesResource
;
35 @SuppressWarnings("unchecked")
36 public List
<MavenFile
> loadMavenFiles() {
38 List
<MavenFile
> mavenFiles
= new ArrayList
<MavenFile
>();
40 List
<String
> lines
= IOUtils
.readLines(dependenciesResource
42 for (String line
: lines
) {
47 .startsWith("The following files have been resolved:"))
50 mavenFiles
.add(convert(line
));
51 } catch (Exception e
) {
52 log
.warn("Could not load line " + line
);
57 } catch (IOException e
) {
58 throw new SlcException("Could not read dependencies resource "
59 + dependenciesResource
, e
);
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());
74 public void setDependenciesResource(Resource dependenciesResource
) {
75 this.dependenciesResource
= dependenciesResource
;
78 public Object
getObject() throws Exception
{
79 return loadMavenFiles();
82 @SuppressWarnings("unchecked")
83 public Class
<List
> getObjectType() {
87 public boolean isSingleton() {