diff --git a/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/configuration/Configurator.java b/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/configuration/Configurator.java index 4a3593ad65f4e0832289578ee2225d2ccaccae18..e5946eb6264fd8943a49415175962c56697839f2 100644 --- a/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/configuration/Configurator.java +++ b/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/configuration/Configurator.java @@ -1,12 +1,15 @@ package org.universAAL.ucc.core.configuration; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.Dictionary; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Scanner; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -85,6 +88,12 @@ public class Configurator implements IConfigurator { return "App Registration failed!"; if(!Activator.getModel().getApplicationRegistration().writeToConfigFile(appName,Activator.getInformation().getRunDir())) return "Error writing Configuration File!"; + String[] order=readStartupOrder(install_base); + if(order!=null){ + ArrayList<Bundle> orderedbundles=sortBundles(bundles, order); + if(orderedbundles!=null) bundles=orderedbundles; + } + Iterator<Bundle> itr=bundles.iterator(); while(itr.hasNext()){ Bundle b=itr.next(); @@ -301,4 +310,49 @@ public class Configurator implements IConfigurator { public boolean checkEnteredValues(){ return configuration.checkEnteredValues(); } + + private String[] readStartupOrder(String path){ + String[] order = new String[9]; + + + FileInputStream fis=null; + try { + fis=new FileInputStream(path+"/startup.txt"); + } catch (FileNotFoundException e) { + System.out.println("Couldn't find startup.txt"); + return null; + } + Scanner scanner = new Scanner(fis, "UTF-8"); + int i=0; + try { + while (scanner.hasNextLine()){ + order[i]=scanner.nextLine(); + i++; + } + } + finally{ + scanner.close(); + } + return order; + } + private ArrayList<Bundle> sortBundles(ArrayList<Bundle> bundles, String[] order){ + ArrayList<Bundle> orderedBundles = new ArrayList<Bundle>(); + if(order.length!=bundles.size()) return null; + Bundle current; + for(int i=0;i<order.length;i++){ + current=findBySymbolicName(order[i], bundles); + if(current==null) return null; + orderedBundles.add(current); + } + return orderedBundles; + } + private Bundle findBySymbolicName(String sn, ArrayList<Bundle> bundles){ + Iterator<Bundle>itr=bundles.iterator(); + Bundle current; + while(itr.hasNext()){ + current=itr.next(); + if(current.getSymbolicName().equals(sn)) return current; + } + return null; + } } \ No newline at end of file diff --git a/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/information/Information.java b/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/information/Information.java index 8e87245e34c968ef8b1693435f558d0367e7b2f8..4b33e275ed58deeb96368bf94a94ea82cdd9a39c 100644 --- a/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/information/Information.java +++ b/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/information/Information.java @@ -20,12 +20,13 @@ public class Information implements IInformation { if(countOccurrences(bundlePath)==2){ rundir= bundlePath.substring(bundlePath.indexOf(":")+2, bundlePath.lastIndexOf("/")); + bundledir=rundir; System.out.println(rundir); rundir= rundir.substring(0, rundir.lastIndexOf("/")); System.out.println(rundir); rundir= rundir.substring(0, rundir.lastIndexOf("/")+1); System.out.println(rundir); - bundledir="plugins/"; + }else{ /*rundir= bundlePath.substring(bundlePath.indexOf(":")+1, bundlePath.lastIndexOf("/")+1); System.out.println(rundir);*/ diff --git a/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/installation/Installer.java b/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/installation/Installer.java index c39bdb7191f85a65fd5c1b251d265002887a415f..a3b49f3399e0af8d2717e98a8f8b137c7906a604 100644 --- a/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/installation/Installer.java +++ b/ucc/ucc.core/src/main/java/org/universAAL/ucc/core/installation/Installer.java @@ -1,5 +1,7 @@ package org.universAAL.ucc.core.installation; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; @@ -11,6 +13,10 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; import org.osgi.framework.Bundle; @@ -86,7 +92,7 @@ public class Installer extends ApplicationManager implements IInstaller { } if(!jarok) throw new Exception("There is no installable jar File in uaal Package!"); if(!configok) throw new Exception("config.owl file not found!"); - if(!eulaok) throw new Exception("No License agreement found!"); + //if(!eulaok) throw new Exception("No License agreement found!"); } @@ -139,7 +145,7 @@ public class Installer extends ApplicationManager implements IInstaller { private String extractBundles(String path) { String destDir = path.substring(path.lastIndexOf(File.separator) + 1,path.lastIndexOf(".")); - destDir =Activator.getInformation().getRunDir()+Activator.getInformation().getBundleDir()+ destDir; + destDir =Activator.getInformation().getBundleDir()+"/"+ destDir; File appDir=new File(destDir); int suffix=1; int slength=0; @@ -151,26 +157,16 @@ private String extractBundles(String path) { } appDir.mkdir(); try { - JarFile jar; - jar = new JarFile(path); - Enumeration<JarEntry> e = jar.entries(); - while (e.hasMoreElements()) { - JarEntry file = (JarEntry) e.nextElement(); - File f = new File(destDir + File.separator + file.getName()); - InputStream is = jar.getInputStream(file); // get the input stream - FileOutputStream fos = new java.io.FileOutputStream(f); - while (is.available() > 0) { // write contents of 'is' to 'fos' - fos.write(is.read()); - } - fos.close(); - is.close(); + extractFolder(path, destDir); + } catch (ZipException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return destDir; } - return destDir; - } catch (IOException e1) { - Deinstaller.deleteFolder(appDir); - return null; - } - } public void revertInstallation(File folder){ Iterator<Bundle> itr=installedBundles.iterator(); @@ -186,4 +182,54 @@ public void revertInstallation(File folder){ } Deinstaller.deleteFolder(folder); } + +static public void extractFolder(String zipFile, String destdir) throws ZipException, IOException +{ + System.out.println(zipFile); + int BUFFER = 2048; + File file = new File(zipFile); + + ZipFile zip = new ZipFile(file); + String newPath = destdir; + + new File(newPath).mkdir(); + Enumeration zipFileEntries = zip.entries(); + + // Process each entry + while (zipFileEntries.hasMoreElements()) + { + // grab a zip file entry + ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); + String currentEntry = entry.getName(); + File destFile = new File(newPath, currentEntry); + //destFile = new File(newPath, destFile.getName()); + File destinationParent = destFile.getParentFile(); + + // create the parent directory structure if needed + destinationParent.mkdirs(); + + if (!entry.isDirectory()) + { + BufferedInputStream is = new BufferedInputStream(zip + .getInputStream(entry)); + int currentByte; + // establish buffer for writing file + byte data[] = new byte[BUFFER]; + + // write the current file to disk + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, + BUFFER); + + // read and write until last byte is encountered + while ((currentByte = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, currentByte); + } + dest.flush(); + dest.close(); + is.close(); + } + + } +} } \ No newline at end of file