1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.jjar; |
18 | |
|
19 | |
import java.util.Properties; |
20 | |
import java.util.StringTokenizer; |
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import java.io.InputStream; |
26 | |
|
27 | |
import java.net.URL; |
28 | |
import java.net.URLConnection; |
29 | |
|
30 | 0 | public class RepositoryProps extends Properties implements Repository |
31 | |
{ |
32 | 0 | private List packageList = null; |
33 | 0 | private DependencyEngine de = new DependencyEngine(); |
34 | |
|
35 | |
public void load( URL url ) |
36 | |
{ |
37 | |
try |
38 | |
{ |
39 | 0 | URLConnection conn = url.openConnection(); |
40 | 0 | InputStream is = conn.getInputStream(); |
41 | |
|
42 | 0 | load(is); |
43 | |
|
44 | 0 | is.close(); |
45 | |
} |
46 | 0 | catch(Exception e ) |
47 | |
{ |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 0 | String packages = getProperty("packages"); |
55 | |
|
56 | 0 | packages.trim(); |
57 | |
|
58 | 0 | packageList = makeList( packages ); |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | Iterator i = packageList.iterator(); |
65 | |
|
66 | 0 | while( i.hasNext() ) |
67 | |
{ |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | String p = (String) i.next(); |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | 0 | String depstr = getProperty( p + ".dependencies"); |
81 | |
|
82 | 0 | depstr.trim(); |
83 | |
|
84 | 0 | List dep = makeList( depstr ); |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | 0 | Iterator ii = dep.iterator(); |
91 | |
|
92 | 0 | List deplist = new ArrayList(); |
93 | |
|
94 | 0 | while( ii.hasNext() ) |
95 | |
{ |
96 | 0 | String sdep = (String) ii.next(); |
97 | |
|
98 | 0 | if ( !sdep.equals("<none>")) |
99 | 0 | deplist.add( sdep ); |
100 | 0 | } |
101 | |
|
102 | |
try |
103 | |
{ |
104 | 0 | de.addProject( p, deplist, p ); |
105 | |
} |
106 | 0 | catch( Exception e ) |
107 | |
{ |
108 | 0 | System.out.println("Repository.Repository() : " + p + " : " + e ); |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } |
112 | |
|
113 | |
public List getDependencyList( String pkg, String version ) |
114 | |
{ |
115 | 0 | if( isPackage( pkg )) |
116 | 0 | return de.getDependencies( pkg ); |
117 | |
|
118 | 0 | return new ArrayList(); |
119 | |
} |
120 | |
|
121 | |
public Iterator getPackageListIter() |
122 | |
{ |
123 | 0 | return packageList.iterator(); |
124 | |
} |
125 | |
|
126 | |
public int getPackageCount() |
127 | |
{ |
128 | 0 | return packageList.size(); |
129 | |
} |
130 | |
|
131 | |
public String getPackageDefaultVersion( String pkg ) |
132 | |
{ |
133 | 0 | if (isPackage( pkg ) ) |
134 | |
{ |
135 | 0 | return getProperty( pkg + ".default" ); |
136 | |
} |
137 | |
|
138 | 0 | return null; |
139 | |
} |
140 | |
|
141 | |
public String getPackageDescription( String pkg ) |
142 | |
{ |
143 | 0 | if (isPackage( pkg ) ) |
144 | |
{ |
145 | 0 | return getProperty( pkg + ".desc" ); |
146 | |
} |
147 | |
|
148 | 0 | return null; |
149 | |
} |
150 | |
|
151 | |
public String getFetchTarget( String pkg, String version ) |
152 | |
{ |
153 | 0 | if (!isPackage( pkg )) |
154 | 0 | return null; |
155 | |
|
156 | 0 | String ft = getProperty( pkg + "." + version + ".jar"); |
157 | |
|
158 | 0 | return ft; |
159 | |
} |
160 | |
|
161 | |
public boolean isPackage( String pkg ) |
162 | |
{ |
163 | 0 | Iterator i = packageList.iterator(); |
164 | |
|
165 | 0 | while( i.hasNext() ) |
166 | |
{ |
167 | 0 | String p = (String) i.next(); |
168 | |
|
169 | 0 | if (p.equals( pkg ) ) |
170 | 0 | return true; |
171 | 0 | } |
172 | |
|
173 | 0 | return false; |
174 | |
} |
175 | |
|
176 | |
public List getPackageVersionList( String pkg ) |
177 | |
{ |
178 | 0 | if(!isPackage( pkg )) |
179 | 0 | return null; |
180 | |
|
181 | 0 | return makeList( getProperty( pkg + ".version" ) ); |
182 | |
} |
183 | |
|
184 | |
private List makeList( String thing ) |
185 | |
{ |
186 | 0 | StringTokenizer st = new StringTokenizer( thing, ", "); |
187 | |
|
188 | 0 | List list = new ArrayList(); |
189 | |
|
190 | 0 | while(st.hasMoreTokens() ) |
191 | |
{ |
192 | 0 | list.add( st.nextToken().trim() ); |
193 | |
} |
194 | |
|
195 | 0 | return list; |
196 | |
} |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|