Changeset 23913 in osm
- Timestamp:
- 2010-10-30T11:31:42+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/smed_fw
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed_fw/build.xml
r23895 r23913 40 40 ** should not be necessary to change the following properties 41 41 --> 42 <property name="josm" location=" ../../core/dist/josm-custom.jar" />42 <property name="josm" location="core/dist/josm-custom.jar" /> 43 43 <property name="felix" location="core/dist/felix.jar"/> 44 44 <property name="plugin.build.dir" value="build/" /> … … 104 104 </fileset> 105 105 </copy> 106 107 <copy file="${felix}" todir="${plugin.build.dir}" /> 108 106 109 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 107 110 <!-- … … 125 128 --> 126 129 <attribute name="Plugin-Version" value="${version.entry.commit.revision}" /> 130 <attribute name="Class-Path" value="bin/felix.jar"/> 127 131 128 132 </manifest> -
applications/editors/josm/plugins/smed_fw/src/smed_fw/SmedFW.java
r23895 r23913 1 1 package smed_fw; 2 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 3 import java.io.BufferedInputStream; 4 import java.io.BufferedOutputStream; 5 import java.io.File; 6 import java.io.FileOutputStream; 7 import java.io.IOException; 8 import java.util.Enumeration; 9 import java.util.jar.JarEntry; 10 import java.util.jar.JarFile; 7 11 8 import org. apache.felix.framework.Felix;9 import org. apache.felix.framework.util.FelixConstants;12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.gui.MapFrame; 10 14 import org.openstreetmap.josm.plugins.Plugin; 11 15 import org.openstreetmap.josm.plugins.PluginInformation; 12 import org.osgi.framework.Bundle;13 import org.osgi.framework.BundleActivator;14 import org.osgi.framework.BundleContext;15 import org.osgi.framework.BundleException;16 16 17 public class SmedFW extends Plugin implements BundleActivator{ 17 import smed_fw.io.JARFileFilter; 18 import smed_fw.io.SmedFWFile; 18 19 19 private BundleContext context; 20 private Felix felix; 20 public class SmedFW extends Plugin { 21 22 public static final String FW_BIN_DIR = "bin"; 23 public static final String FW_SMED_JAR = "smed_fw.jar"; 24 public static final String FW_NAME = "felix.jar"; 25 public static final String FW_BUNDLE_LOCATION = "fwplug"; 21 26 22 27 public SmedFW(PluginInformation info) { 23 28 super(info); 29 30 JarEntry e = null; 31 BufferedInputStream inp = null; 32 byte[] buffer = new byte[16384]; 33 int len; 34 35 String eName = null; 36 String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath() + "/"; 37 File fwDir = new File(pluginDirName + FW_BIN_DIR); 38 39 if(!fwDir.exists()) fwDir.mkdir(); 40 41 SmedFWFile fwplugDir = new SmedFWFile(pluginDirName + FW_BUNDLE_LOCATION); 42 if(!fwplugDir.exists()) fwplugDir.mkdir(); 24 43 25 init(); 44 File[] jars = fwplugDir.listFiles(new JARFileFilter()); 45 46 // extract framework and plugins 47 try { 48 JarFile file = new JarFile(pluginDirName + FW_SMED_JAR); 49 50 boolean fwFound = false; 51 FileOutputStream pfos = null; 52 Enumeration<JarEntry> ent = file.entries(); 53 while(ent.hasMoreElements()) { 54 e = ent.nextElement(); 55 eName = e.getName(); 56 57 if(eName.endsWith(".jar")) { 58 if(eName.equals(FW_NAME)) { 59 pfos = new FileOutputStream(pluginDirName + FW_BIN_DIR + "/" + FW_NAME); 60 fwFound = true; 61 } 62 else { 63 pfos = new FileOutputStream(pluginDirName + FW_BUNDLE_LOCATION + "/" + eName); 64 fwFound = false; 65 } 66 if(fwFound || fwplugDir.needUpdate(jars,eName)) { 67 BufferedOutputStream pos = new BufferedOutputStream(pfos); 68 inp = new BufferedInputStream(file.getInputStream( e )); 69 70 while ((len = inp.read(buffer)) > 0) pos.write(buffer, 0, len); 71 72 pos.flush(); 73 pos.close(); 74 inp.close(); 75 pfos.close(); 76 } 77 } 78 } 79 } catch (IOException ex) { 80 ex.printStackTrace(); 81 } 82 83 RunFW runFW = new RunFW(); 84 runFW.init(); 26 85 System.out.println("SmedFW (OSGi-Implementation) noch nicht weiter programmiert"); 27 86 } 28 29 private void init() {30 Map config = new HashMap();31 List list = new ArrayList();32 33 list.add(this);34 config.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);35 36 // Now create an instance of the framework with37 // our configurations properties38 felix = new Felix(config);39 40 // now start Felix instance41 try {42 felix.start();43 } catch (BundleException e) {44 System.err.println("Could not generate framework: " + e);45 e.printStackTrace();46 }47 }48 49 @Override50 public void start(BundleContext context) throws Exception {51 this.context = context;52 }53 54 @Override55 public void stop(BundleContext context) throws Exception {56 context = null;57 }58 87 59 public Bundle[] getBundles() { 60 if(context != null) return context.getBundles(); 61 62 return null; 88 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 89 if (oldFrame == null && newFrame != null) { 90 System.out.println("josm zeigt Karte"); 91 } else { 92 System.out.println("josm zeigt keine Karte"); 93 } 63 94 } 64 95
Note:
See TracChangeset
for help on using the changeset viewer.