]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/Activator.java
Start implementing OSGi integration tests
[gpl/argeo-slc.git] / runtime / org.argeo.slc.osgiboot / src / main / java / org / argeo / slc / osgiboot / Activator.java
1 package org.argeo.slc.osgiboot;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.StringTokenizer;
7
8 import org.osgi.framework.Bundle;
9 import org.osgi.framework.BundleActivator;
10 import org.osgi.framework.BundleContext;
11 import org.osgi.framework.BundleException;
12
13 public class Activator implements BundleActivator {
14
15 public void start(BundleContext bundleContext) throws Exception {
16 try {
17 info("SLC OSGi bootstrap starting...");
18 OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
19
20 osgiBoot.installUrls( osgiBoot.getBundlesUrls());
21
22 osgiBoot.installUrls( osgiBoot.getLocationsUrls());
23
24 // installUrls(bundleContext, getMavenUrls());
25
26 osgiBoot.startBundles();
27
28 info("SLC OSGi bootstrap completed");
29 } catch (Exception e) {
30 e.printStackTrace();
31 throw e;
32 }
33 }
34
35 public void stop(BundleContext context) throws Exception {
36 }
37
38 /*
39 protected List<String> getMavenUrls() throws Exception {
40 String baseUrl = "reference:file:" + System.getProperty("user.home")
41 + "/.m2/repository/";
42 String config = getProperty(PROP_SLC_MAVEN_DEPENDENCY_FILE);
43 if (config == null)
44 return new ArrayList<String>();
45
46 List<MavenFile> mavenFiles = new ArrayList<MavenFile>();
47 BufferedReader in = new BufferedReader(new FileReader(config));
48 String line = null;
49 while ((line = in.readLine()) != null) {
50 try {
51 line = line.trim();
52 if (line.equals("")
53 || line
54 .startsWith("The following files have been resolved:"))
55 continue;// skip
56
57 mavenFiles.add(convert(line));
58 } catch (Exception e) {
59 warn("Could not load line " + line);
60 }
61 }
62
63 return asUrls(baseUrl, mavenFiles);
64 }
65 */
66 /*
67 protected static List<String> asUrls(String baseUrl,
68 List<MavenFile> mavenFiles) {
69 List<String> urls = new ArrayList<String>();
70 for (MavenFile mf : mavenFiles)
71 urls.add(convertToUrl(baseUrl, mf));
72 return urls;
73 }
74
75 protected static String convertToUrl(String baseUrl, MavenFile mf) {
76 return baseUrl + mf.getGroupId().replace('.', '/') + '/'
77 + mf.getArtifactId() + '/' + mf.getVersion() + '/'
78 + mf.getArtifactId() + '-' + mf.getVersion() + '.'
79 + mf.getType();
80 }
81
82 protected static MavenFile convert(String str) {
83 StringTokenizer st = new StringTokenizer(str, ":");
84 MavenFile component = new MavenFile();
85 component.setGroupId(st.nextToken());
86 component.setArtifactId(st.nextToken());
87 component.setType(st.nextToken());
88 component.setVersion(st.nextToken());
89 component.setScope(st.nextToken());
90 return component;
91 }
92 *//*
93 protected static String getProperty(String name, String defaultValue) {
94 final String value;
95 if (defaultValue != null)
96 value = System.getProperty(name, defaultValue);
97 else
98 value = System.getProperty(name);
99
100 if (value == null || value.equals(""))
101 return null;
102 else
103 return value;
104 }
105
106 protected static String getProperty(String name) {
107 return getProperty(name, null);
108 }
109 */
110 private static void info(Object obj) {
111 System.out.println("# INFO " + obj);
112 }
113 /*
114 private static void debug(Object obj) {
115 if (debug)
116 System.out.println("# DBUG " + obj);
117 }
118
119 private static void warn(Object obj) {
120 System.out.println("# WARN " + obj);
121 // if (System.getProperty("os.name").contains("Windows"))
122 // System.out.println("# WARN " + obj);
123 // else
124 // System.err.println("# WARN " + obj);
125 }
126 *//*
127 static class MavenFile {
128 private String groupId;
129 private String artifactId;
130 private String version;
131 private String type;
132 private String classifier;
133 private String scope;
134
135 public String getScope() {
136 return scope;
137 }
138
139 public void setScope(String scope) {
140 this.scope = scope;
141 }
142
143 private String distributionId;
144
145 public String getDistributionId() {
146 return distributionId;
147 }
148
149 public void setDistributionId(String distributionId) {
150 this.distributionId = distributionId;
151 }
152
153 public String getGroupId() {
154 return groupId;
155 }
156
157 public void setGroupId(String groupId) {
158 this.groupId = groupId;
159 }
160
161 public String getArtifactId() {
162 return artifactId;
163 }
164
165 public void setArtifactId(String artifactId) {
166 this.artifactId = artifactId;
167 }
168
169 public String getVersion() {
170 return version;
171 }
172
173 public void setVersion(String version) {
174 this.version = version;
175 }
176
177 public String getType() {
178 return type;
179 }
180
181 public void setType(String type) {
182 this.type = type;
183 }
184
185 public String getClassifier() {
186 return classifier;
187 }
188
189 public void setClassifier(String classifier) {
190 this.classifier = classifier;
191 }
192
193 }
194 */
195 }