Revision 2163
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/StringWithAlias.java | ||
---|---|---|
1 |
package org.gvsig.tools.packageutils; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public interface StringWithAlias { |
|
6 |
|
|
7 |
public StringWithAlias add(String value); |
|
8 |
|
|
9 |
public List getAlias(); |
|
10 |
|
|
11 |
public boolean equals(Object other); |
|
12 |
|
|
13 |
public boolean equalsIgnoreCase(Object other); |
|
14 |
|
|
15 |
public boolean matches(String regex); |
|
16 |
|
|
17 |
public boolean endsWith(Object suffix); |
|
18 |
|
|
19 |
public boolean startsWith(Object suffix); |
|
20 |
|
|
21 |
public boolean startsWith(Object suffix, int toffset); |
|
22 |
|
|
23 |
public int compareTo(Object other); |
|
24 |
|
|
25 |
public int compareToIgnoreCase(Object other); |
|
26 |
|
|
27 |
public String toString(); |
|
28 |
|
|
29 |
public String concat(Object other); |
|
30 |
|
|
31 |
} |
|
32 |
|
|
0 | 33 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/Dependency.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.packageutils; |
|
25 |
|
|
26 |
import org.gvsig.tools.lang.Cloneable; |
|
27 |
import org.gvsig.installer.lib.api.Version; |
|
28 |
|
|
29 |
public interface Dependency extends Cloneable, org.gvsig.installer.lib.api.Dependency { |
|
30 |
public final String REQUIRED = "required"; |
|
31 |
public final String CONFLICT = "conflict"; |
|
32 |
public final String RECOMMENDED = "recommended"; |
|
33 |
|
|
34 |
public org.gvsig.installer.lib.api.Dependency parse(String dependency); |
|
35 |
|
|
36 |
public String getType(); |
|
37 |
|
|
38 |
public String getCode(); |
|
39 |
|
|
40 |
public String getOp(); |
|
41 |
|
|
42 |
public Version getVersion(); |
|
43 |
|
|
44 |
public boolean match(String type, String code, Version version); |
|
45 |
} |
|
0 | 46 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/DefaultDependency.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.packageutils.impl; |
|
25 |
|
|
26 |
import java.text.MessageFormat; |
|
27 |
|
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.exception.BaseRuntimeException; |
|
30 |
import org.gvsig.tools.packageutils.Dependency; |
|
31 |
import org.gvsig.tools.packageutils.PackageInfo; |
|
32 |
import org.gvsig.tools.packageutils.StringWithAlias; |
|
33 |
import org.gvsig.installer.lib.api.Version; |
|
34 |
|
|
35 |
public class DefaultDependency implements Dependency { |
|
36 |
|
|
37 |
protected String type; |
|
38 |
protected String code; |
|
39 |
protected String op; |
|
40 |
protected Version version; |
|
41 |
|
|
42 |
public DefaultDependency() { |
|
43 |
super(); |
|
44 |
clear(); |
|
45 |
} |
|
46 |
|
|
47 |
public DefaultDependency(org.gvsig.installer.lib.api.PackageInfo packageInfo) { |
|
48 |
this(); |
|
49 |
this.fromPackageInfo(packageInfo); |
|
50 |
} |
|
51 |
|
|
52 |
public void fromPackageInfo(org.gvsig.installer.lib.api.PackageInfo packageInfo) { |
|
53 |
this.clear(); |
|
54 |
this.code = packageInfo.getCode(); |
|
55 |
this.type = "required"; |
|
56 |
this.op = ">="; |
|
57 |
this.version = packageInfo.getVersion(); |
|
58 |
} |
|
59 |
|
|
60 |
public void clear() { |
|
61 |
this.type = "required"; |
|
62 |
this.code = "unknow"; |
|
63 |
this.op = "="; |
|
64 |
this.version = ToolsLocator.getPackageManager().createVersion(); |
|
65 |
} |
|
66 |
|
|
67 |
public org.gvsig.installer.lib.api.Dependency parse(String dependency) { |
|
68 |
// Parse a string with the dependency specification |
|
69 |
// (required|suggested|recommended|conflict)[:] code (=|>|<|>=|<=) |
|
70 |
// version |
|
71 |
if (dependency == null) { |
|
72 |
this.clear(); |
|
73 |
return this; |
|
74 |
} |
|
75 |
dependency = dependency.trim(); |
|
76 |
if (dependency.equals("")) { |
|
77 |
this.clear(); |
|
78 |
return this; |
|
79 |
} |
|
80 |
|
|
81 |
String s = dependency; |
|
82 |
/* |
|
83 |
* Remove special characters, so |
|
84 |
* dependency description in pom.xml is not |
|
85 |
* so fragile |
|
86 |
*/ |
|
87 |
s = s.replace('\n', ' '); |
|
88 |
s = s.replace('\t', ' '); |
|
89 |
s = s.replace('\r', ' '); |
|
90 |
s = s.replace(':', ' '); |
|
91 |
|
|
92 |
/* |
|
93 |
* Added loop because replaceAll is not |
|
94 |
* exhaustive in this case |
|
95 |
*/ |
|
96 |
while (s.indexOf(" ") != -1) { |
|
97 |
s = s.replaceAll(" ", " "); |
|
98 |
} |
|
99 |
|
|
100 |
String[] x = s.split(" "); |
|
101 |
if (x.length != 4) { |
|
102 |
throw new InvalidDependencyFormatException(dependency); |
|
103 |
} |
|
104 |
|
|
105 |
this.type = x[0]; |
|
106 |
this.code = x[1]; |
|
107 |
this.op = x[2]; |
|
108 |
this.version.parse(x[3]); |
|
109 |
return this; |
|
110 |
} |
|
111 |
|
|
112 |
private class InvalidDependencyFormatException extends BaseRuntimeException { |
|
113 |
|
|
114 |
private static final long serialVersionUID = 2856837862117653856L; |
|
115 |
|
|
116 |
private static final String message = "Error parsing dependecy '%(dependency)s'"; |
|
117 |
|
|
118 |
private static final String KEY = "_Error_parsing_dependecy_XdependecyX"; |
|
119 |
|
|
120 |
public InvalidDependencyFormatException(String dependency) { |
|
121 |
super(message, null, KEY, serialVersionUID); |
|
122 |
setValue("dependency", dependency); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
public String getType() { |
|
127 |
return this.type; |
|
128 |
} |
|
129 |
|
|
130 |
public String getCode() { |
|
131 |
return this.code; |
|
132 |
} |
|
133 |
|
|
134 |
public String getOp() { |
|
135 |
return this.op; |
|
136 |
} |
|
137 |
|
|
138 |
public Version getVersion() { |
|
139 |
return this.version; |
|
140 |
} |
|
141 |
|
|
142 |
public boolean match(String type, String code, Version version) { |
|
143 |
if (!this.type.equalsIgnoreCase(type)) { |
|
144 |
return false; |
|
145 |
} |
|
146 |
if (!this.code.equalsIgnoreCase(code)) { |
|
147 |
return false; |
|
148 |
} |
|
149 |
return version.check(this.op, this.version); |
|
150 |
} |
|
151 |
|
|
152 |
public boolean match(String type, StringWithAlias code, Version version) { |
|
153 |
if (!this.type.equalsIgnoreCase(type)) { |
|
154 |
return false; |
|
155 |
} |
|
156 |
if (!code.equalsIgnoreCase(this.code)) { |
|
157 |
return false; |
|
158 |
} |
|
159 |
return version.check(this.op, this.version); |
|
160 |
} |
|
161 |
|
|
162 |
public String toString() { |
|
163 |
return MessageFormat.format("{0}: {1} {2} {3}", |
|
164 |
new Object[] { |
|
165 |
this.type, |
|
166 |
this.code, |
|
167 |
this.op, |
|
168 |
this.version.toString() |
|
169 |
} |
|
170 |
); |
|
171 |
} |
|
172 |
|
|
173 |
public Object clone() throws CloneNotSupportedException { |
|
174 |
DefaultDependency x = (DefaultDependency) super.clone(); |
|
175 |
x.version = (Version) this.version.clone(); |
|
176 |
return x; |
|
177 |
} |
|
178 |
|
|
179 |
public boolean equals(Object obj) { |
|
180 |
Dependency other; |
|
181 |
try { |
|
182 |
other = (Dependency) obj; |
|
183 |
} catch (Exception ex) { |
|
184 |
return false; |
|
185 |
} |
|
186 |
if (!this.code.equalsIgnoreCase(other.getCode())) { |
|
187 |
return false; |
|
188 |
} |
|
189 |
if (!this.type.equalsIgnoreCase(other.getType())) { |
|
190 |
return false; |
|
191 |
} |
|
192 |
if (!this.op.equalsIgnoreCase(other.getOp())) { |
|
193 |
return false; |
|
194 |
} |
|
195 |
if (!this.version.equals(other.getVersion())) { |
|
196 |
return false; |
|
197 |
} |
|
198 |
return true; |
|
199 |
} |
|
200 |
|
|
201 |
/* (non-Javadoc) |
|
202 |
* @see java.lang.Object#hashCode() |
|
203 |
*/ |
|
204 |
public int hashCode() { |
|
205 |
return version.hashCode() + code.hashCode() |
|
206 |
+ type.hashCode() + op.hashCode(); |
|
207 |
} |
|
208 |
} |
|
0 | 209 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/PackageInfoFileWriter.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.packageutils.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.FileOutputStream; |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.OutputStream; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Properties; |
|
32 |
|
|
33 |
import org.gvsig.tools.packageutils.PackageInfo; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
|
37 |
*/ |
|
38 |
public class PackageInfoFileWriter { |
|
39 |
|
|
40 |
public void write(PackageInfo packageInfo, String fileName) |
|
41 |
throws IOException { |
|
42 |
write(packageInfo, new File(fileName)); |
|
43 |
} |
|
44 |
|
|
45 |
public void write(PackageInfo packageInfo, File file) |
|
46 |
throws IOException { |
|
47 |
write(packageInfo, new FileOutputStream(file)); |
|
48 |
} |
|
49 |
|
|
50 |
public void write(PackageInfo pkg, OutputStream os) throws IOException { |
|
51 |
Properties props = new Properties(); |
|
52 |
|
|
53 |
props.setProperty(PackageInfoTags.CODE, pkg.getCode()); |
|
54 |
|
|
55 |
String codealias1 = null; |
|
56 |
List codealias2 = pkg.getAllCodes().getAlias(); |
|
57 |
for( int i=0; i<codealias2.size(); i++ ) { |
|
58 |
if( codealias1 == null ) { |
|
59 |
codealias1 = ((String) codealias2.get(i)).trim(); |
|
60 |
} else { |
|
61 |
codealias1 = codealias1 +","+((String) codealias2.get(i)).trim(); |
|
62 |
} |
|
63 |
} |
|
64 |
if( codealias1==null ) { |
|
65 |
codealias1 = ""; |
|
66 |
} |
|
67 |
props.setProperty(PackageInfoTags.CODEALIAS, toStr(codealias1)); |
|
68 |
props.setProperty(PackageInfoTags.NAME, toStr(pkg.getName())); |
|
69 |
props.setProperty(PackageInfoTags.DESCRIPTION, toStr(pkg.getDescription())); |
|
70 |
props.setProperty(PackageInfoTags.VERSION, pkg.getVersion().toString()); |
|
71 |
props.setProperty(PackageInfoTags.STATE, toStr(pkg.getState())); |
|
72 |
props.setProperty(PackageInfoTags.OFFICIAL, |
|
73 |
Boolean.toString(pkg.isOfficial())); |
|
74 |
props.setProperty(PackageInfoTags.TYPE, toStr(pkg.getType())); |
|
75 |
props.setProperty(PackageInfoTags.OS, toStr(pkg.getOperatingSystem())); |
|
76 |
props.setProperty(PackageInfoTags.ARCHITECTURE, toStr(pkg.getArchitecture())); |
|
77 |
props.setProperty(PackageInfoTags.JVM, toStr(pkg.getJavaVM())); |
|
78 |
props.setProperty(PackageInfoTags.APPLICATION_VERSION, toStr(pkg.getApplicationVersion())); |
|
79 |
props.setProperty(PackageInfoTags.OWNER, toStr(pkg.getOwner())); |
|
80 |
props.setProperty(PackageInfoTags.CATEGORIES, toStr(pkg.getCategoriesAsString())); |
|
81 |
props.setProperty(PackageInfoTags.DEPENDENCIES, toStr(pkg.getDependencies())); |
|
82 |
props.setProperty(PackageInfoTags.SOURCES_URL, toStr(pkg.getSourcesURL())); |
|
83 |
props.setProperty(PackageInfoTags.WEB_URL, toStr(pkg.getWebURL())); |
|
84 |
props.setProperty(PackageInfoTags.DOWNLOAD_URL, toStr(pkg.getDownloadURLAsString())); |
|
85 |
props.setProperty(PackageInfoTags.OWNER_URL, toStr(pkg.getOwnerURL())); |
|
86 |
props.setProperty(PackageInfoTags.MODEL_VERSION, toStr(pkg.getModelVersion())); |
|
87 |
props.store(os, ""); |
|
88 |
os.close(); |
|
89 |
} |
|
90 |
|
|
91 |
private String toStr(Object s) { |
|
92 |
return s == null ? "" : s.toString(); |
|
93 |
} |
|
94 |
|
|
95 |
} |
|
0 | 96 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/PackageInfoTags.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
/* |
|
25 |
* AUTHORS (In addition to CIT): |
|
26 |
* 2010 {Prodevelop} {Task} |
|
27 |
*/ |
|
28 |
|
|
29 |
package org.gvsig.tools.packageutils.impl; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
|
33 |
*/ |
|
34 |
public class PackageInfoTags { |
|
35 |
|
|
36 |
public static final String CODE = "code"; |
|
37 |
public static final String CODEALIAS = "code-alias"; |
|
38 |
public static final String NAME = "name"; |
|
39 |
public static final String DESCRIPTION = "description"; |
|
40 |
public static final String VERSION = "version"; |
|
41 |
public static final String BUILD = "buildNumber"; |
|
42 |
public static final String BUILD_OLD = "build"; |
|
43 |
public static final String STATE = "state"; |
|
44 |
public static final String OFFICIAL = "official"; |
|
45 |
public static final String TYPE = "type"; |
|
46 |
public static final String OS = "operating-system"; |
|
47 |
public static final String ARCHITECTURE = "architecture"; |
|
48 |
public static final String JVM = "java-version"; |
|
49 |
/** @deprecated use APPLICATION_VERSION */ |
|
50 |
public static final String GVSIG_VERSION = "gvSIG-version"; |
|
51 |
public static final String APPLICATION_VERSION = "application-version"; |
|
52 |
public static final String DOWNLOAD_URL = "download-url"; |
|
53 |
public static final String MODEL_VERSION = "model-version"; |
|
54 |
public static final String OWNER = "owner"; |
|
55 |
public static final String OWNER_URL = "owner-url"; |
|
56 |
public static final String SOURCES_URL = "sources-url"; |
|
57 |
public static final String WEB_URL = "web-url"; |
|
58 |
public static final String DEPENDENCIES = "dependencies"; |
|
59 |
public static final String CATEGORIES = "categories"; |
|
60 |
} |
|
0 | 61 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/DefaultVersion.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.packageutils.impl; |
|
25 |
|
|
26 |
import java.security.InvalidParameterException; |
|
27 |
import java.text.MessageFormat; |
|
28 |
|
|
29 |
import org.gvsig.tools.packageutils.Version; |
|
30 |
|
|
31 |
public class DefaultVersion implements Version { |
|
32 |
|
|
33 |
private int major = 0; |
|
34 |
private int minor = 0; |
|
35 |
private int rev = 0; |
|
36 |
private String classifier = null; |
|
37 |
private int build = 0; |
|
38 |
|
|
39 |
public DefaultVersion() { |
|
40 |
super(); |
|
41 |
} |
|
42 |
|
|
43 |
protected DefaultVersion(int mayor, int minor, int rev, String classifier, |
|
44 |
int build) { |
|
45 |
this(); |
|
46 |
this.major = mayor; |
|
47 |
this.minor = minor; |
|
48 |
this.rev = rev; |
|
49 |
this.classifier = classifier; |
|
50 |
this.build = build; |
|
51 |
} |
|
52 |
|
|
53 |
public org.gvsig.installer.lib.api.Version parse(String version) { |
|
54 |
try { |
|
55 |
if( version == null || version.length()==0 ) { |
|
56 |
this.major = 0; |
|
57 |
this.minor = 0; |
|
58 |
this.rev = 0; |
|
59 |
this.classifier = null; |
|
60 |
this.build = 0; |
|
61 |
return this; |
|
62 |
} |
|
63 |
// Formato: mayor.minor.rev-classifier-build |
|
64 |
|
|
65 |
String[] x = version.split("[.]"); |
|
66 |
int lx = x.length; |
|
67 |
if (lx == 1) { |
|
68 |
this.major = parseIntClassifierAndBuild(x[0], version); |
|
69 |
this.minor = 0; |
|
70 |
this.rev = 0; |
|
71 |
this.classifier = null; |
|
72 |
this.build = 0; |
|
73 |
} else if (lx == 2) { |
|
74 |
this.major = Integer.parseInt(x[0]); |
|
75 |
this.minor = parseIntClassifierAndBuild(x[1], version); |
|
76 |
this.rev = 0; |
|
77 |
this.classifier = null; |
|
78 |
this.build = 0; |
|
79 |
} else if (lx == 3) { |
|
80 |
this.major = Integer.parseInt(x[0]); |
|
81 |
this.minor = Integer.parseInt(x[1]); |
|
82 |
this.rev = parseIntClassifierAndBuild(x[2], version); |
|
83 |
} else { |
|
84 |
throw new InvalidParameterException(version); |
|
85 |
} |
|
86 |
} catch(InvalidParameterException ex) { |
|
87 |
throw ex; |
|
88 |
} catch(Exception ex) { |
|
89 |
InvalidParameterException e = new InvalidParameterException(version); |
|
90 |
e.initCause(ex); |
|
91 |
throw e; |
|
92 |
} |
|
93 |
return this; |
|
94 |
} |
|
95 |
|
|
96 |
private int parseIntClassifierAndBuild(String s, String fullversion) { |
|
97 |
int value; |
|
98 |
|
|
99 |
String[] y = s.split("[-]"); |
|
100 |
int ly = y.length; |
|
101 |
if (ly == 1) { |
|
102 |
value = Integer.parseInt(y[0]); |
|
103 |
this.classifier = null; |
|
104 |
this.build = 0; |
|
105 |
} else if (ly == 2) { |
|
106 |
value = Integer.parseInt(y[0]); |
|
107 |
try { |
|
108 |
this.build = Integer.parseInt(y[1]); |
|
109 |
this.classifier = null; |
|
110 |
} catch (NumberFormatException e) { |
|
111 |
this.build = 0; |
|
112 |
this.classifier = y[1]; |
|
113 |
} |
|
114 |
} else if (ly == 3) { |
|
115 |
value = Integer.parseInt(y[0]); |
|
116 |
this.classifier = y[1]; |
|
117 |
this.build = Integer.parseInt(y[2]); |
|
118 |
} else { |
|
119 |
throw new InvalidParameterException(fullversion); |
|
120 |
} |
|
121 |
return value; |
|
122 |
} |
|
123 |
|
|
124 |
public int getMajor() { |
|
125 |
return this.major; |
|
126 |
} |
|
127 |
|
|
128 |
|
|
129 |
public int getMayor() { |
|
130 |
return getMajor(); |
|
131 |
} |
|
132 |
|
|
133 |
public int getMinor() { |
|
134 |
return this.minor; |
|
135 |
} |
|
136 |
|
|
137 |
public int getRevision() { |
|
138 |
return this.rev; |
|
139 |
} |
|
140 |
|
|
141 |
public String getClassifier() { |
|
142 |
return this.classifier; |
|
143 |
} |
|
144 |
|
|
145 |
public int getBuild() { |
|
146 |
return this.build; |
|
147 |
} |
|
148 |
|
|
149 |
public boolean check(String op, org.gvsig.installer.lib.api.Version other) { |
|
150 |
if ("=".equals(op) || "==".equals(op) || "-eq".equals(op)) { |
|
151 |
return this.fullFormat().compareTo(other.fullFormat()) == 0; |
|
152 |
} |
|
153 |
if (">".equals(op) || "-gt".equals(op)) { |
|
154 |
return this.fullFormat().compareTo(other.fullFormat()) > 0; |
|
155 |
} |
|
156 |
if (">=".equals(op) || "-ge".equals(op)) { |
|
157 |
return this.fullFormat().compareTo(other.fullFormat()) >= 0; |
|
158 |
} |
|
159 |
if ("<".equals(op) || "-lt".equals(op)) { |
|
160 |
return this.fullFormat().compareTo(other.fullFormat()) < 0; |
|
161 |
} |
|
162 |
if ("<=".equals(op) || "-le".equals(op)) { |
|
163 |
return this.fullFormat().compareTo(other.fullFormat()) <= 0; |
|
164 |
} |
|
165 |
return false; |
|
166 |
} |
|
167 |
|
|
168 |
public String toString() { |
|
169 |
if (this.classifier == null) { |
|
170 |
return MessageFormat.format("{0}.{1}.{2}-{3,number,####}", |
|
171 |
new Object[] { |
|
172 |
new Integer(this.major), |
|
173 |
new Integer(this.minor), |
|
174 |
new Integer(this.rev), |
|
175 |
new Integer(this.build) |
|
176 |
} |
|
177 |
); |
|
178 |
} else { |
|
179 |
return MessageFormat.format("{0}.{1}.{2}-{3}-{4,number,####}", |
|
180 |
new Object[] { |
|
181 |
new Integer(this.major), |
|
182 |
new Integer(this.minor), |
|
183 |
new Integer(this.rev), |
|
184 |
this.classifier, |
|
185 |
new Integer(this.build) |
|
186 |
} |
|
187 |
); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
public String fullFormat() { |
|
192 |
if (this.classifier == null) { |
|
193 |
// classifier ZZZZ allows compare correctly tow versions |
|
194 |
return MessageFormat.format( |
|
195 |
"{0,number,0000}.{1,number,0000}.{2,number,0000}-ZZZZ-{3,number,0000}", |
|
196 |
new Object[] { |
|
197 |
new Integer(this.major), |
|
198 |
new Integer(this.minor), |
|
199 |
new Integer(this.rev), |
|
200 |
new Integer(this.build) |
|
201 |
} |
|
202 |
); |
|
203 |
} else { |
|
204 |
return MessageFormat.format( |
|
205 |
"{0,number,0000}.{1,number,0000}.{2,number,0000}-{3}-{4,number,0000}", |
|
206 |
new Object[] { |
|
207 |
new Integer(this.major), |
|
208 |
new Integer(this.minor), |
|
209 |
new Integer(this.rev), |
|
210 |
this.classifier, |
|
211 |
new Integer(this.build) |
|
212 |
} |
|
213 |
); |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
public int compareTo(Object arg0) { |
|
218 |
Version other = (Version)arg0; |
|
219 |
return this.fullFormat().compareTo(other.fullFormat()); |
|
220 |
} |
|
221 |
|
|
222 |
public Object clone() throws CloneNotSupportedException { |
|
223 |
return super.clone(); |
|
224 |
} |
|
225 |
|
|
226 |
public boolean equals(Object obj) { |
|
227 |
if( obj==null ) { |
|
228 |
return false; |
|
229 |
} |
|
230 |
Version other = (Version) obj; |
|
231 |
if (this.major != other.getMajor()) { |
|
232 |
return false; |
|
233 |
} |
|
234 |
if (this.minor != other.getMinor()) { |
|
235 |
return false; |
|
236 |
} |
|
237 |
if (this.rev != other.getRevision()) { |
|
238 |
return false; |
|
239 |
} |
|
240 |
if (this.build != other.getBuild()) { |
|
241 |
return false; |
|
242 |
} |
|
243 |
if (this.classifier == null) { |
|
244 |
if (other.getClassifier() == null) { |
|
245 |
return true; |
|
246 |
} else { |
|
247 |
return false; |
|
248 |
} |
|
249 |
} |
|
250 |
if (!this.classifier.equalsIgnoreCase(other.getClassifier())) { |
|
251 |
return false; |
|
252 |
} |
|
253 |
return true; |
|
254 |
} |
|
255 |
|
|
256 |
public int hashCode() { |
|
257 |
return (classifier == null ? 0 : classifier.hashCode()) + |
|
258 |
(major<<13) + (minor<<19) + (rev<<25) + build; |
|
259 |
} |
|
260 |
|
|
261 |
public org.gvsig.installer.lib.api.Version setBuild(int build) { |
|
262 |
this.build = build; |
|
263 |
return this; |
|
264 |
} |
|
265 |
|
|
266 |
public String format(String fmt) { |
|
267 |
String s = fmt; |
|
268 |
s = s.replaceAll("%M", String.valueOf(this.major)); |
|
269 |
s = s.replaceAll("%m", String.valueOf(this.minor)); |
|
270 |
s = s.replaceAll("%r", String.valueOf(this.rev)); |
|
271 |
s = s.replaceAll("%c", this.classifier); |
|
272 |
s = s.replaceAll("%b", String.valueOf(this.build)); |
|
273 |
return s; |
|
274 |
} |
|
275 |
} |
|
0 | 276 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/PackageInfoFileReader.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
/* |
|
25 |
* AUTHORS (In addition to CIT): |
|
26 |
* 2010 {Prodevelop} {Task} |
|
27 |
*/ |
|
28 |
|
|
29 |
package org.gvsig.tools.packageutils.impl; |
|
30 |
|
|
31 |
import java.io.File; |
|
32 |
import java.io.FileInputStream; |
|
33 |
import java.io.FileNotFoundException; |
|
34 |
import java.io.IOException; |
|
35 |
import java.io.InputStream; |
|
36 |
import java.net.MalformedURLException; |
|
37 |
import java.net.URL; |
|
38 |
import java.util.Properties; |
|
39 |
import org.apache.commons.lang3.StringUtils; |
|
40 |
|
|
41 |
import org.gvsig.tools.packageutils.PackageInfo; |
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
|
|
45 |
public class PackageInfoFileReader { |
|
46 |
|
|
47 |
private static final Logger logger = LoggerFactory |
|
48 |
.getLogger(PackageInfoFileReader.class); |
|
49 |
|
|
50 |
public void read(PackageInfo packageInfo, String fileName) throws IOException, FileNotFoundException { |
|
51 |
this.read(packageInfo, new File(fileName)); |
|
52 |
} |
|
53 |
|
|
54 |
public void read(PackageInfo packageInfo, File file) throws IOException, FileNotFoundException { |
|
55 |
this.read(packageInfo, new FileInputStream(file)); |
|
56 |
} |
|
57 |
|
|
58 |
public void read(PackageInfo packageInfo, InputStream is) throws IOException { |
|
59 |
Properties properties = new Properties(); |
|
60 |
properties.load(is); |
|
61 |
is.close(); |
|
62 |
read(packageInfo, properties); |
|
63 |
} |
|
64 |
|
|
65 |
public void read(PackageInfo packageInfo, Properties properties ) { |
|
66 |
|
|
67 |
packageInfo.setCode(properties.getProperty(PackageInfoTags.CODE)); |
|
68 |
|
|
69 |
String codealias1 = properties.getProperty(PackageInfoTags.CODEALIAS); |
|
70 |
if( codealias1 != null ) { |
|
71 |
String[] s = codealias1.split(","); |
|
72 |
for( int i=0; i<s.length; i++) { |
|
73 |
s[i] = s[i].trim(); |
|
74 |
if(! "".equals(s[i]) ) { // isEmpty |
|
75 |
packageInfo.getAllCodes().add(s[i]); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
packageInfo.setName(properties.getProperty(PackageInfoTags.NAME)); |
|
81 |
|
|
82 |
String pkgName = packageInfo.getName(); |
|
83 |
|
|
84 |
packageInfo.setDescription(properties.getProperty(PackageInfoTags.DESCRIPTION)); |
|
85 |
packageInfo.getVersion().parse(properties.getProperty(PackageInfoTags.VERSION)); |
|
86 |
String build = properties.getProperty(PackageInfoTags.BUILD); |
|
87 |
if( build!=null ) { |
|
88 |
try { |
|
89 |
int buildNumber = Integer.parseInt(build); |
|
90 |
packageInfo.getVersion().setBuild(buildNumber); |
|
91 |
} catch(Exception e) { |
|
92 |
// Ignore |
|
93 |
} |
|
94 |
} |
|
95 |
packageInfo.setType(properties.getProperty(PackageInfoTags.TYPE)); |
|
96 |
packageInfo.setState(properties.getProperty(PackageInfoTags.STATE)); |
|
97 |
packageInfo.setOfficial(Boolean.valueOf(properties.getProperty(PackageInfoTags.OFFICIAL)).booleanValue()); |
|
98 |
packageInfo.setOperatingSystem(properties.getProperty(PackageInfoTags.OS)); |
|
99 |
packageInfo.setArchitecture(properties.getProperty(PackageInfoTags.ARCHITECTURE)); |
|
100 |
packageInfo.setJavaVM(properties.getProperty(PackageInfoTags.JVM)); |
|
101 |
String value = properties.getProperty(PackageInfoTags.APPLICATION_VERSION); |
|
102 |
if( value == null ) { |
|
103 |
value = properties.getProperty(PackageInfoTags.GVSIG_VERSION); |
|
104 |
} |
|
105 |
packageInfo.getApplicationVersion().parse(value); |
|
106 |
packageInfo.setDownloadURL(properties.getProperty(PackageInfoTags.DOWNLOAD_URL)); |
|
107 |
packageInfo.setModelVersion(properties.getProperty(PackageInfoTags.MODEL_VERSION)); |
|
108 |
packageInfo.setOwner(properties.getProperty(PackageInfoTags.OWNER)); |
|
109 |
packageInfo.setDependencies(properties.getProperty(PackageInfoTags.DEPENDENCIES)); |
|
110 |
packageInfo.setSourcesURL(getUrl(properties, PackageInfoTags.SOURCES_URL, pkgName)); |
|
111 |
packageInfo.setWebURL(getUrl(properties, PackageInfoTags.WEB_URL, pkgName)); |
|
112 |
packageInfo.setOwnerURL(getUrl(properties, PackageInfoTags.OWNER_URL, pkgName)); |
|
113 |
packageInfo.addCategoriesAsString(properties.getProperty(PackageInfoTags.CATEGORIES)); |
|
114 |
} |
|
115 |
|
|
116 |
private URL getUrl(Properties properties, String name, String pkgName) { |
|
117 |
String s = properties.getProperty(name); |
|
118 |
if ( !StringUtils.isBlank(s) ) { |
|
119 |
URL url; |
|
120 |
try { |
|
121 |
url = new URL(s); |
|
122 |
} catch (MalformedURLException e) { |
|
123 |
logger.info("Malformed url for '"+name+"' in package '"+pkgName+"', url='"+s+"'."); |
|
124 |
return null; |
|
125 |
} |
|
126 |
return url; |
|
127 |
} else { |
|
128 |
return null; |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
} |
|
0 | 134 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/DefaultDependencies.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.packageutils.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.gvsig.tools.ToolsLocator; |
|
31 |
import org.gvsig.tools.packageutils.Dependencies; |
|
32 |
import org.gvsig.tools.packageutils.StringWithAlias; |
|
33 |
import org.gvsig.installer.lib.api.Dependency; |
|
34 |
import org.gvsig.tools.packageutils.PackageManager; |
|
35 |
import org.gvsig.installer.lib.api.Version; |
|
36 |
|
|
37 |
public class DefaultDependencies extends ArrayList implements |
|
38 |
Dependencies { |
|
39 |
|
|
40 |
/** |
|
41 |
* |
|
42 |
*/ |
|
43 |
private static final long serialVersionUID = -6743931124069465522L; |
|
44 |
|
|
45 |
private Dependency createDependency() { |
|
46 |
PackageManager manager = ToolsLocator.getPackageManager(); |
|
47 |
return manager.createDependency(); |
|
48 |
} |
|
49 |
|
|
50 |
public Object clone() { |
|
51 |
PackageManager manager = ToolsLocator.getPackageManager(); |
|
52 |
Dependencies other = manager.createDependencies(); |
|
53 |
Iterator it = this.iterator(); |
|
54 |
while( it.hasNext() ) { |
|
55 |
Dependency dependency = (Dependency) it.next(); |
|
56 |
try { |
|
57 |
other.add(dependency.clone()); |
|
58 |
} catch (CloneNotSupportedException e) { |
|
59 |
// This exception can by done |
|
60 |
} |
|
61 |
} |
|
62 |
return other; |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
public org.gvsig.installer.lib.api.Dependencies parse(String dependecies) { |
|
67 |
if (dependecies == null) { |
|
68 |
this.clear(); |
|
69 |
return this; |
|
70 |
} |
|
71 |
dependecies = dependecies.trim(); |
|
72 |
if (dependecies.equals("")) { |
|
73 |
this.clear(); |
|
74 |
return this; |
|
75 |
} |
|
76 |
|
|
77 |
String[] x = dependecies.split(","); |
|
78 |
for (int i = 0; i < x.length; i++) { |
|
79 |
this.add(createDependency().parse(x[i])); |
|
80 |
} |
|
81 |
return this; |
|
82 |
} |
|
83 |
|
|
84 |
public String toString() { |
|
85 |
StringBuffer s = null; |
|
86 |
Iterator it = this.iterator(); |
|
87 |
while (it.hasNext()) { |
|
88 |
if (s == null) { |
|
89 |
s = new StringBuffer(); |
|
90 |
} else { |
|
91 |
s.append(", "); |
|
92 |
} |
|
93 |
s.append(it.next().toString()); |
|
94 |
} |
|
95 |
if (s == null) { |
|
96 |
return ""; |
|
97 |
} |
|
98 |
return s.toString(); |
|
99 |
} |
|
100 |
|
|
101 |
public boolean contains(Object o) { |
|
102 |
if (!(o instanceof Dependency)) { |
|
103 |
return false; |
|
104 |
} |
|
105 |
Iterator it = this.iterator(); |
|
106 |
while (it.hasNext()) { |
|
107 |
Dependency dep = (Dependency) it.next(); |
|
108 |
if (dep.equals(o)) { |
|
109 |
return true; |
|
110 |
} |
|
111 |
} |
|
112 |
return false; |
|
113 |
} |
|
114 |
|
|
115 |
public boolean match(String type, String code, Version version) { |
|
116 |
Iterator it = this.iterator(); |
|
117 |
while (it.hasNext()) { |
|
118 |
Dependency dependency = (Dependency) it.next(); |
|
119 |
if (dependency.match(type, code, version)) { |
|
120 |
return true; |
|
121 |
} |
|
122 |
} |
|
123 |
return false; |
|
124 |
} |
|
125 |
|
|
126 |
public Dependency find(String type, String code, Version version) { |
|
127 |
Iterator it = this.iterator(); |
|
128 |
while (it.hasNext()) { |
|
129 |
Dependency dependency = (Dependency) it.next(); |
|
130 |
if (dependency.match(type, code, version)) { |
|
131 |
return dependency; |
|
132 |
} |
|
133 |
} |
|
134 |
return null; |
|
135 |
} |
|
136 |
|
|
137 |
public List findAll(String type, String code, Version version) { |
|
138 |
|
|
139 |
List resp = null; |
|
140 |
Iterator it = this.iterator(); |
|
141 |
while (it.hasNext()) { |
|
142 |
Dependency dependency = (Dependency) it.next(); |
|
143 |
if (dependency.match(type, code, version)) { |
|
144 |
if (resp == null) { |
|
145 |
resp = new ArrayList(); |
|
146 |
} |
|
147 |
resp.add(dependency); |
|
148 |
} |
|
149 |
} |
|
150 |
return resp; |
|
151 |
} |
|
152 |
|
|
153 |
public boolean match(String type, StringWithAlias code, Version version) { |
|
154 |
Iterator it = this.iterator(); |
|
155 |
while (it.hasNext()) { |
|
156 |
Dependency dependency = (Dependency) it.next(); |
|
157 |
if (dependency.match(type, code, version)) { |
|
158 |
return true; |
|
159 |
} |
|
160 |
} |
|
161 |
return false; |
|
162 |
} |
|
163 |
|
|
164 |
public Dependency find(String type, StringWithAlias code, Version version) { |
|
165 |
Iterator it = this.iterator(); |
|
166 |
while (it.hasNext()) { |
|
167 |
Dependency dependency = (Dependency) it.next(); |
|
168 |
if (dependency.match(type, code, version)) { |
|
169 |
return dependency; |
|
170 |
} |
|
171 |
} |
|
172 |
return null; |
|
173 |
} |
|
174 |
|
|
175 |
public List findAll(String type, StringWithAlias code, Version version) { |
|
176 |
|
|
177 |
List resp = null; |
|
178 |
Iterator it = this.iterator(); |
|
179 |
while (it.hasNext()) { |
|
180 |
Dependency dependency = (Dependency) it.next(); |
|
181 |
if (dependency.match(type, code, version)) { |
|
182 |
if (resp == null) { |
|
183 |
resp = new ArrayList(); |
|
184 |
} |
|
185 |
resp.add(dependency); |
|
186 |
} |
|
187 |
} |
|
188 |
return resp; |
|
189 |
} |
|
190 |
|
|
191 |
|
|
192 |
} |
|
0 | 193 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/DefaultPackageManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.packageutils.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.FileInputStream; |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.InputStream; |
|
30 |
import java.io.OutputStream; |
|
31 |
import java.util.Properties; |
|
32 |
import org.apache.commons.io.IOUtils; |
|
33 |
import org.apache.commons.lang3.StringUtils; |
|
34 |
|
|
35 |
import org.gvsig.tools.exception.BaseException; |
|
36 |
import org.gvsig.tools.packageutils.Dependencies; |
|
37 |
import org.gvsig.tools.packageutils.Dependency; |
|
38 |
import org.gvsig.tools.packageutils.PackageInfo; |
|
39 |
import org.gvsig.tools.packageutils.PackageManager; |
|
40 |
import org.gvsig.tools.packageutils.Version; |
|
41 |
|
|
42 |
public class DefaultPackageManager implements PackageManager { |
|
43 |
private String operatingSystemName; |
|
44 |
private String operatingSystemFamily; |
|
45 |
private String operatingSystemVersion; |
|
46 |
|
|
47 |
@Override |
|
48 |
public Version createVersion() { |
|
49 |
return new DefaultVersion(); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public Version createVersion(String version) { |
|
54 |
Version v = new DefaultVersion(); |
|
55 |
v.parse(version); |
|
56 |
return v; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public PackageInfo createPackageInfo() { |
|
61 |
return new DefaultPackageInfo(); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public PackageInfo createPackageInfo(InputStream packegeinfo) |
|
66 |
throws BaseException { |
|
67 |
PackageInfo pkg = createPackageInfo(); |
|
68 |
try { |
|
69 |
this.readPacakgeInfo(pkg, packegeinfo); |
|
70 |
} catch (IOException e) { |
|
71 |
throw new BaseIOException(e); |
|
72 |
} |
|
73 |
return pkg; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public PackageInfo createPackageInfo(File packegeinfo) throws BaseException { |
|
78 |
PackageInfo pkg = createPackageInfo(); |
|
79 |
try { |
|
80 |
this.readPacakgeInfo(pkg, packegeinfo); |
|
81 |
} catch (IOException e) { |
|
82 |
throw new BaseIOException(packegeinfo, e); |
|
83 |
} |
|
84 |
return pkg; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public Dependency createDependency() { |
|
89 |
return new DefaultDependency(); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public Dependency createDependency(PackageInfo packageInfo) { |
|
94 |
DefaultDependency dependency = (DefaultDependency) this.createDependency(); |
|
95 |
dependency.fromPackageInfo(packageInfo); |
|
96 |
return dependency; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public Dependencies createDependencies() { |
|
101 |
return new DefaultDependencies(); |
|
102 |
} |
|
103 |
|
|
104 |
private void loadOperatingSystemInfo() { |
|
105 |
String osname = System.getProperty("os.name"); |
|
106 |
String osversion = System.getProperty("os.version"); |
|
107 |
if (osname.toLowerCase().startsWith("linux")) { |
|
108 |
this.operatingSystemFamily = OS.LINUX; |
|
109 |
FileInputStream fis = null; |
|
110 |
try { |
|
111 |
Properties p = new Properties(); |
|
112 |
fis = new FileInputStream("/etc/os-release"); |
|
113 |
p.load(fis); |
|
114 |
this.operatingSystemName = p.getProperty("ID", null); |
|
115 |
this.operatingSystemVersion = p.getProperty("VERSION_ID", null); |
|
116 |
|
|
117 |
this.operatingSystemName = StringUtils.removeEnd(this.operatingSystemName,"\""); |
|
118 |
this.operatingSystemName = StringUtils.removeStart(this.operatingSystemName,"\""); |
|
119 |
this.operatingSystemName = StringUtils.trimToNull(this.operatingSystemName); |
|
120 |
this.operatingSystemVersion = StringUtils.removeEnd(this.operatingSystemVersion,"\""); |
|
121 |
this.operatingSystemVersion = StringUtils.removeStart(this.operatingSystemVersion,"\""); |
|
122 |
this.operatingSystemVersion = StringUtils.trimToNull(this.operatingSystemVersion); |
|
123 |
} catch(Exception ex) { |
|
124 |
|
|
125 |
} finally { |
|
126 |
IOUtils.closeQuietly(fis); |
|
127 |
} |
|
128 |
|
|
129 |
} else if (osname.toLowerCase().startsWith("window")) { |
|
130 |
this.operatingSystemFamily = OS.WINDOWS; |
|
131 |
String s = osname.replace(" ", ""); |
|
132 |
s = s.replace("_", ""); |
|
133 |
s = s.replace("-", ""); |
|
134 |
this.operatingSystemName = s; |
|
135 |
this.operatingSystemVersion = osversion; |
|
136 |
|
|
137 |
} else { |
|
138 |
String s = osname.replace(" ", ""); |
|
139 |
s = s.replace("_", ""); |
|
140 |
s = s.replace("-", ""); |
|
141 |
this.operatingSystemFamily = s; |
|
142 |
this.operatingSystemName = null; |
|
143 |
this.operatingSystemVersion = osversion; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public String getOperatingSystem() { |
|
149 |
if( this.operatingSystemFamily == null ) { |
|
150 |
loadOperatingSystemInfo(); |
|
151 |
} |
|
152 |
StringBuilder builder = new StringBuilder(); |
|
153 |
builder.append(this.operatingSystemFamily); |
|
154 |
if( this.operatingSystemName!=null ) { |
|
155 |
builder.append("_"); |
|
156 |
builder.append(this.operatingSystemName); |
|
157 |
if( this.operatingSystemVersion!=null ) { |
|
158 |
builder.append("_"); |
|
159 |
builder.append(this.operatingSystemVersion); |
|
160 |
} |
|
161 |
} |
|
162 |
return builder.toString(); |
|
163 |
} |
|
164 |
|
|
165 |
@Override |
|
166 |
public String getOperatingSystemFamily() { |
|
167 |
if( this.operatingSystemFamily == null ) { |
|
168 |
loadOperatingSystemInfo(); |
|
169 |
} |
|
170 |
return this.operatingSystemFamily; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public String getOperatingSystemName() { |
|
175 |
if( this.operatingSystemFamily == null ) { |
|
176 |
loadOperatingSystemInfo(); |
|
177 |
} |
|
178 |
return this.operatingSystemName; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public String getOperatingSystemVersion() { |
|
183 |
if( this.operatingSystemFamily == null ) { |
|
184 |
loadOperatingSystemInfo(); |
|
185 |
} |
|
186 |
return this.operatingSystemVersion; |
|
187 |
} |
|
188 |
|
|
189 |
@Override |
|
190 |
public String getArchitecture() { |
|
191 |
String osarch = System.getProperty("os.arch"); |
|
192 |
if (osarch.toLowerCase().startsWith("i386")) { |
|
193 |
return ARCH.X86; |
|
194 |
} |
|
195 |
if (osarch.toLowerCase().startsWith("i686")) { |
|
196 |
return ARCH.X86; |
|
197 |
} |
|
198 |
if (osarch.toLowerCase().startsWith("x86_64")) { |
|
199 |
return ARCH.X86_64; |
|
200 |
} |
|
201 |
if (osarch.toLowerCase().startsWith("x86")) { |
|
202 |
return ARCH.X86; |
|
203 |
} |
|
204 |
if (osarch.toLowerCase().startsWith("amd64")) { |
|
205 |
return ARCH.X86_64; |
|
206 |
} |
|
207 |
return osarch; |
|
208 |
} |
|
209 |
|
|
210 |
@Override |
|
211 |
public void writePacakgeInfo(PackageInfo packageInfo, File file) |
|
212 |
throws IOException { |
|
213 |
PackageInfoFileWriter writer = new PackageInfoFileWriter(); |
|
214 |
writer.write(packageInfo, file); |
|
215 |
} |
|
216 |
|
|
217 |
@Override |
|
218 |
public void writePacakgeInfo(PackageInfo pkg, OutputStream os) |
|
219 |
throws IOException { |
|
220 |
PackageInfoFileWriter writer = new PackageInfoFileWriter(); |
|
221 |
writer.write(pkg, os); |
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public void readPacakgeInfo(PackageInfo packageInfo, File file) |
|
226 |
throws IOException { |
|
227 |
PackageInfoFileReader reader = new PackageInfoFileReader(); |
|
228 |
reader.read(packageInfo, file); |
|
229 |
} |
|
230 |
|
|
231 |
@Override |
|
232 |
public void readPacakgeInfo(PackageInfo pkg, InputStream is) |
|
233 |
throws IOException { |
|
234 |
PackageInfoFileReader reader = new PackageInfoFileReader(); |
|
235 |
reader.read(pkg, is); |
|
236 |
} |
|
237 |
|
|
238 |
public class BaseIOException extends BaseException { |
|
239 |
|
|
240 |
/** |
|
241 |
* |
|
242 |
*/ |
|
243 |
private static final long serialVersionUID = 3154855738763990310L; |
|
244 |
|
|
245 |
public BaseIOException(Throwable cause) { |
|
246 |
super("Can't load package info","_Cant_load_package_info", serialVersionUID); |
|
247 |
} |
|
248 |
|
|
249 |
public BaseIOException(File file, Throwable cause) { |
|
250 |
super("Can't load package info %(file)","_Cant_load_package_info_XfileX", serialVersionUID); |
|
251 |
setValue("file",file); |
|
252 |
} |
|
253 |
} |
|
254 |
|
|
255 |
} |
|
0 | 256 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.224/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/packageutils/impl/DefaultPackageInfo.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
/* |
|
25 |
* AUTHORS (In addition to CIT): |
|
26 |
* 2010 {Prodevelop} {Task} |
|
27 |
*/ |
|
28 |
|
|
29 |
package org.gvsig.tools.packageutils.impl; |
|
30 |
|
|
31 |
import java.io.File; |
|
32 |
import java.net.MalformedURLException; |
|
33 |
import java.net.URL; |
|
34 |
import java.security.InvalidParameterException; |
|
35 |
import java.text.MessageFormat; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.HashMap; |
|
38 |
import java.util.Iterator; |
|
39 |
import java.util.List; |
|
40 |
import java.util.Map; |
|
41 |
import org.apache.commons.lang3.StringUtils; |
|
42 |
|
|
43 |
import org.gvsig.installer.lib.api.Dependencies; |
|
44 |
import org.gvsig.installer.lib.api.Version; |
|
45 |
import org.gvsig.tools.ToolsLocator; |
|
46 |
import org.gvsig.tools.exception.BaseException; |
|
47 |
import org.gvsig.tools.packageutils.PackageInfo; |
|
48 |
import org.gvsig.tools.packageutils.PackageManager; |
|
49 |
import org.gvsig.tools.packageutils.PackageManager.ARCH; |
|
50 |
import org.gvsig.tools.packageutils.PackageManager.JVM; |
|
51 |
import org.gvsig.tools.packageutils.PackageManager.OS; |
|
52 |
import org.gvsig.tools.packageutils.PackageManager.STATE; |
|
53 |
import org.gvsig.tools.packageutils.StringWithAlias; |
|
54 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
55 |
import org.slf4j.Logger; |
|
56 |
import org.slf4j.LoggerFactory; |
|
57 |
|
|
58 |
/** |
|
59 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
|
60 |
*/ |
|
61 |
public class DefaultPackageInfo implements PackageInfo { |
|
62 |
|
|
63 |
private static final Logger logger = LoggerFactory |
|
64 |
.getLogger(DefaultPackageInfo.class); |
|
65 |
|
|
66 |
private static PackageManager packageManager = null; |
|
67 |
|
|
68 |
public static interface PACKAGE_FILE_NAME_FIELDS { |
|
69 |
static final int GVSIG_VERSION = 0; |
|
70 |
static final int NAME = 1; |
|
71 |
static final int VERSION = 2; |
|
72 |
static final int BUILD = 3; |
|
73 |
static final int STATE = 4; |
|
74 |
static final int OS = 5; |
|
75 |
static final int ARCH = 6; |
|
76 |
static final int JVM = 7; |
|
77 |
} |
|
78 |
private static final String PACKAGE_NAME_FORMAT = "gvSIG-desktop-{0}-{1}-{2}-{4}-{5}-{6}-{7}.gvspkg"; |
|
79 |
|
|
80 |
private static final String DEFAULT_MODEL_VERSION = "1.0.1"; |
|
81 |
private static final String DEFAULT_TYPE = "unknow"; |
|
82 |
|
|
83 |
private StringWithAlias code = null; |
|
84 |
private String name = null; |
|
85 |
private String description = null; |
|
86 |
private Version version = null; |
|
87 |
private boolean official; |
|
88 |
private String type = DEFAULT_TYPE; |
|
89 |
private boolean broken = false; |
|
90 |
|
|
91 |
private String state = STATE.DEVEL; |
|
92 |
// private String operatingSystem = OS.ALL; |
|
93 |
private String operatingSystemFamily = OS.ALL; |
|
94 |
private String operatingSystemName = null; |
|
95 |
private String operatingSystemVersion = null; |
|
96 |
private String architecture = ARCH.ALL; |
|
97 |
private String javaVM = JVM.J1_5; |
|
98 |
|
|
99 |
private String owner = ""; |
|
100 |
private URL ownerURL = null; |
|
101 |
private URL sources = null; |
|
102 |
private Version applicationVersion = null; |
Also available in: Unified diff