1 package org
.argeo
.slc
.osgiboot
;
3 import java
.util
.HashMap
;
6 import java
.util
.StringTokenizer
;
8 import org
.osgi
.framework
.Bundle
;
9 import org
.osgi
.framework
.BundleActivator
;
10 import org
.osgi
.framework
.BundleContext
;
11 import org
.osgi
.framework
.BundleException
;
13 public class Activator
implements BundleActivator
{
15 public void start(BundleContext bundleContext
) throws Exception
{
17 info("SLC OSGi bootstrap starting...");
18 OsgiBoot osgiBoot
= new OsgiBoot(bundleContext
);
20 osgiBoot
.installUrls( osgiBoot
.getBundlesUrls());
22 osgiBoot
.installUrls( osgiBoot
.getLocationsUrls());
24 // installUrls(bundleContext, getMavenUrls());
26 osgiBoot
.startBundles();
28 info("SLC OSGi bootstrap completed");
29 } catch (Exception e
) {
35 public void stop(BundleContext context
) throws Exception
{
39 protected List<String> getMavenUrls() throws Exception {
40 String baseUrl = "reference:file:" + System.getProperty("user.home")
42 String config = getProperty(PROP_SLC_MAVEN_DEPENDENCY_FILE);
44 return new ArrayList<String>();
46 List<MavenFile> mavenFiles = new ArrayList<MavenFile>();
47 BufferedReader in = new BufferedReader(new FileReader(config));
49 while ((line = in.readLine()) != null) {
54 .startsWith("The following files have been resolved:"))
57 mavenFiles.add(convert(line));
58 } catch (Exception e) {
59 warn("Could not load line " + line);
63 return asUrls(baseUrl, mavenFiles);
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));
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() + '.'
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());
93 protected static String getProperty(String name, String defaultValue) {
95 if (defaultValue != null)
96 value = System.getProperty(name, defaultValue);
98 value = System.getProperty(name);
100 if (value == null || value.equals(""))
106 protected static String getProperty(String name) {
107 return getProperty(name, null);
110 private static void info(Object obj
) {
111 System
.out
.println("# INFO " + obj
);
114 private static void debug(Object obj) {
116 System.out.println("# DBUG " + obj);
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);
124 // System.err.println("# WARN " + obj);
127 static class MavenFile {
128 private String groupId;
129 private String artifactId;
130 private String version;
132 private String classifier;
133 private String scope;
135 public String getScope() {
139 public void setScope(String scope) {
143 private String distributionId;
145 public String getDistributionId() {
146 return distributionId;
149 public void setDistributionId(String distributionId) {
150 this.distributionId = distributionId;
153 public String getGroupId() {
157 public void setGroupId(String groupId) {
158 this.groupId = groupId;
161 public String getArtifactId() {
165 public void setArtifactId(String artifactId) {
166 this.artifactId = artifactId;
169 public String getVersion() {
173 public void setVersion(String version) {
174 this.version = version;
177 public String getType() {
181 public void setType(String type) {
185 public String getClassifier() {
189 public void setClassifier(String classifier) {
190 this.classifier = classifier;