1 package com.highstreet.technologies.info;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.nio.file.Path;
8 import java.util.ArrayList;
9 import java.util.jar.Attributes;
10 import java.util.jar.JarInputStream;
11 import java.util.jar.Manifest;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public class KarafBundleList extends ArrayList<KarafBundle>{
19 private static Logger LOG = LoggerFactory.getLogger(KarafBundleList.class);
23 private static final long serialVersionUID = 2856302408338858883L;
24 private final Path _root;
25 public KarafBundleList(String root)
27 this._root=new File(root).toPath();
31 LOG.debug("start scanning "+this._root.toString()+" for bundles");
32 for(File f : this._root.toFile().listFiles())
36 int id=Integer.parseInt(f.getName());
37 File bundleFile=new File(f,"1/bundlefile");
38 if(bundleFile.exists() && bundleFile.isFile())
40 LOG.trace("try to load bundleinfos for "+bundleFile.getName()+"("+id+")");
42 KarafBundle infos=this._readManifestFromZip(id,bundleFile);
44 } catch (IOException e) {
45 LOG.warn("problem reading bundle with id="+id+": "+e.getMessage());
50 private KarafBundle _readManifestFromZip(int id,File bundleFile) throws FileNotFoundException, IOException {
52 JarInputStream jarStream = new JarInputStream(new FileInputStream(bundleFile));
53 Manifest mf = jarStream.getManifest();
54 Attributes a=mf.getMainAttributes();
56 return new KarafBundle(id, a.getValue("Bundle-Name"), a.getValue("Bundle-SymbolicName"), a.getValue("Bundle-Vendor"), a.getValue("Bundle-Version"));
59 public String toJSON()
61 return "["+String.join(",", this)+"]";