Skip to content
Snippets Groups Projects
Commit 2302a021 authored by Herr Michel Frigge's avatar Herr Michel Frigge
Browse files

No commit message

No commit message
parent 6e56ff41
No related branches found
No related tags found
No related merge requests found
package org.universAAL.ucc.core.configuration; package org.universAAL.ucc.core.configuration;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Scanner;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
...@@ -85,6 +88,12 @@ public class Configurator implements IConfigurator { ...@@ -85,6 +88,12 @@ public class Configurator implements IConfigurator {
return "App Registration failed!"; return "App Registration failed!";
if(!Activator.getModel().getApplicationRegistration().writeToConfigFile(appName,Activator.getInformation().getRunDir())) if(!Activator.getModel().getApplicationRegistration().writeToConfigFile(appName,Activator.getInformation().getRunDir()))
return "Error writing Configuration File!"; 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(); Iterator<Bundle> itr=bundles.iterator();
while(itr.hasNext()){ while(itr.hasNext()){
Bundle b=itr.next(); Bundle b=itr.next();
...@@ -301,4 +310,49 @@ public class Configurator implements IConfigurator { ...@@ -301,4 +310,49 @@ public class Configurator implements IConfigurator {
public boolean checkEnteredValues(){ public boolean checkEnteredValues(){
return configuration.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
...@@ -20,12 +20,13 @@ public class Information implements IInformation { ...@@ -20,12 +20,13 @@ public class Information implements IInformation {
if(countOccurrences(bundlePath)==2){ if(countOccurrences(bundlePath)==2){
rundir= bundlePath.substring(bundlePath.indexOf(":")+2, bundlePath.lastIndexOf("/")); rundir= bundlePath.substring(bundlePath.indexOf(":")+2, bundlePath.lastIndexOf("/"));
bundledir=rundir;
System.out.println(rundir); System.out.println(rundir);
rundir= rundir.substring(0, rundir.lastIndexOf("/")); rundir= rundir.substring(0, rundir.lastIndexOf("/"));
System.out.println(rundir); System.out.println(rundir);
rundir= rundir.substring(0, rundir.lastIndexOf("/")+1); rundir= rundir.substring(0, rundir.lastIndexOf("/")+1);
System.out.println(rundir); System.out.println(rundir);
bundledir="plugins/";
}else{ }else{
/*rundir= bundlePath.substring(bundlePath.indexOf(":")+1, bundlePath.lastIndexOf("/")+1); /*rundir= bundlePath.substring(bundlePath.indexOf(":")+1, bundlePath.lastIndexOf("/")+1);
System.out.println(rundir);*/ System.out.println(rundir);*/
......
package org.universAAL.ucc.core.installation; package org.universAAL.ucc.core.installation;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
...@@ -11,6 +13,10 @@ import java.util.Enumeration; ...@@ -11,6 +13,10 @@ import java.util.Enumeration;
import java.util.Iterator; import java.util.Iterator;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; 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; import org.osgi.framework.Bundle;
...@@ -86,7 +92,7 @@ public class Installer extends ApplicationManager implements IInstaller { ...@@ -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(!jarok) throw new Exception("There is no installable jar File in uaal Package!");
if(!configok) throw new Exception("config.owl file not found!"); 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 { ...@@ -139,7 +145,7 @@ public class Installer extends ApplicationManager implements IInstaller {
private String extractBundles(String path) { private String extractBundles(String path) {
String destDir = path.substring(path.lastIndexOf(File.separator) + 1,path.lastIndexOf(".")); 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); File appDir=new File(destDir);
int suffix=1; int suffix=1;
int slength=0; int slength=0;
...@@ -151,26 +157,16 @@ private String extractBundles(String path) { ...@@ -151,26 +157,16 @@ private String extractBundles(String path) {
} }
appDir.mkdir(); appDir.mkdir();
try { try {
JarFile jar; extractFolder(path, destDir);
jar = new JarFile(path); } catch (ZipException e) {
Enumeration<JarEntry> e = jar.entries(); // TODO Auto-generated catch block
while (e.hasMoreElements()) { e.printStackTrace();
JarEntry file = (JarEntry) e.nextElement(); } catch (IOException e) {
File f = new File(destDir + File.separator + file.getName()); // TODO Auto-generated catch block
InputStream is = jar.getInputStream(file); // get the input stream e.printStackTrace();
FileOutputStream fos = new java.io.FileOutputStream(f); }
while (is.available() > 0) { // write contents of 'is' to 'fos' return destDir;
fos.write(is.read());
}
fos.close();
is.close();
} }
return destDir;
} catch (IOException e1) {
Deinstaller.deleteFolder(appDir);
return null;
}
}
public void revertInstallation(File folder){ public void revertInstallation(File folder){
Iterator<Bundle> itr=installedBundles.iterator(); Iterator<Bundle> itr=installedBundles.iterator();
...@@ -186,4 +182,54 @@ public void revertInstallation(File folder){ ...@@ -186,4 +182,54 @@ public void revertInstallation(File folder){
} }
Deinstaller.deleteFolder(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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment