Skip to content
Snippets Groups Projects
Commit c8d25fc1 authored by Shanshan Jiang's avatar Shanshan Jiang
Browse files

update to version 2.0.0 to work with MW2.0; implement...

update to version 2.0.0 to work with MW2.0; implement installServiceFromOnlineStore(); installService(); modify others to handle the new .uapp file.
parent a9b47dd9
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<relativePath>../ucc.pom/pom.xml</relativePath> <relativePath>../ucc.pom/pom.xml</relativePath>
</parent> </parent>
<artifactId>ucc.core</artifactId> <artifactId>ucc.core</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<name>Core of the uCC</name> <name>Core of the uCC</name>
<description>Provides the main functionalities of the uCC.</description> <description>Provides the main functionalities of the uCC.</description>
<packaging>bundle</packaging> <packaging>bundle</packaging>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>org.universAAL.tools.ucc</groupId> <groupId>org.universAAL.tools.ucc</groupId>
<artifactId>ucc.api</artifactId> <artifactId>ucc.api</artifactId>
<version>1.1.1-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sf.qtjambi</groupId> <groupId>net.sf.qtjambi</groupId>
......
...@@ -55,14 +55,15 @@ public class Installer extends ApplicationManager implements IInstaller { ...@@ -55,14 +55,15 @@ public class Installer extends ApplicationManager implements IInstaller {
private boolean initialized = false; private boolean initialized = false;
private DeployManager deployManager; private DeployManager deployManager;
private AALSpaceManager aalSpaceManager; private AALSpaceManager aalSpaceManager;
private static String MPA_EXTENSION="-mpa"; private static String MPA_EXTENSION=".uapp";
public Installer(BundleContext con) { public Installer(BundleContext con) {
context=con; context=con;
} }
public Installer(String path) throws Exception { public Installer(String path) throws Exception {
installApplication(path); //installApplication(path);
installService(path);
} }
public void finalize() throws Throwable { public void finalize() throws Throwable {
...@@ -72,31 +73,18 @@ public class Installer extends ApplicationManager implements IInstaller { ...@@ -72,31 +73,18 @@ public class Installer extends ApplicationManager implements IInstaller {
/** /**
* *
* @param Path * @param Path
* return the path for the extract .uapp file (root)
* @throws Exception * @throws Exception
*/ */
public String installApplication(String path) throws Exception { public String installApplication(String path) throws Exception {
//Activator.getModel().getApplicationRegistration().writeToConfigFile("test"); //Activator.getModel().getApplicationRegistration().writeToConfigFile("test");
//System.out.println("[Installer.installApplication] the path for install is: " + path); System.out.println("[Installer.installApplication] the path for install is: " + path);
String exdir=extractBundles(path); String exdir=extractBundles(path);
if(exdir==null)throw new Exception("Error extracting uaal Package"); if(exdir==null)throw new Exception("[Installer.installApplication] Error extracting .uapp Package");
// convert "/" to "\" // convert "/" to "\"
exdir = exdir.replaceAll("/", "\\"); exdir = exdir.replaceAll("/", "\\");
File appDir=new File(exdir);
checkApplicationForInstall(appDir); checkApplicationForInstall(exdir);
if (!mpa) {
// install on local node / OSGi container
String[] bundlelist=appDir.list();
for(int i=0;i<bundlelist.length;i++){
if(bundlelist[i].endsWith(".jar")){
Bundle temp=installBundle(exdir+File.separator+bundlelist[i]);
if(temp==null){
revertInstallation(appDir);
throw new Exception("Error installing Bundle "+ bundlelist[i]);
}
installedBundles.add(temp);
}
}
}
return exdir; return exdir;
} }
...@@ -105,30 +93,38 @@ public class Installer extends ApplicationManager implements IInstaller { ...@@ -105,30 +93,38 @@ public class Installer extends ApplicationManager implements IInstaller {
* Is bundle valid? All need files available? Dependencies to check and all * Is bundle valid? All need files available? Dependencies to check and all
* right? Check if concrete instances available (but how)? * right? Check if concrete instances available (but how)?
* *
* Check if the application is MPA? * Does the .uapp file exist?
* Does the license file exist? (which one to check/how?)
* *
* @param Path * @param Path
*
* @throws Exception * @throws Exception
*/ */
private void checkApplicationForInstall(File folder) throws Exception { private void checkApplicationForInstall(String folder) throws Exception {
String[] content = folder.list(); String uappfile = null;
boolean jarok=false; boolean aslok=false;
boolean configok=false; boolean uappok=false;
boolean eulaok=false; System.out.println("[Installer.checkApplicationForInstall] the uapp file folder: " + folder);
File confolder = new File(folder+"\\config");
String[] content = confolder.list();
for(int i=0;i<content.length;i++){ for(int i=0;i<content.length;i++){
if(content[i].endsWith(".jar")) jarok=true; System.out.println("[Installer.checkApplicationForInstall] get one file under /config/:" + content[i]);
if(content[i].equals("config.owl")) configok=true; if(content[i].contains(".uapp")) {
if(content[i].equals("EULA.txt")) eulaok=true; uappok=true;
if(content[i].contains(MPA_EXTENSION)) mpa=true; uappfile = confolder + "\\" + content[i];
System.out.println("[Installer.checkApplicationForInstall] the uapp file is:" + uappfile);
}
} }
if(!jarok) throw new Exception("There is no installable jar File in uaal Package!"); confolder = new File(folder+"\\license");
if(!configok) throw new Exception("config.owl file not found!"); content = confolder.list();
//if(!eulaok) throw new Exception("No License agreement found!"); for(int i = 0;i<content.length;i++){
if(mpa) { if(content[i].equals("ASL2.0.txt")) aslok=true;
System.out.println("This is a multi-part application, initialing...");
// initialization: get references to DeployManager and AALSpaceManager
initMpaInstallation();
} }
if(!aslok) throw new Exception("No license agreement found!");
if(!uappok) throw new Exception("The uapp file not found!");
// initialization: get references to DeployManager and AALSpaceManager
//initMpaInstallation();
} }
...@@ -180,8 +176,10 @@ public class Installer extends ApplicationManager implements IInstaller { ...@@ -180,8 +176,10 @@ 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().getBundleDir() +"/"+ destDir; //Does this work only on Linux/Unix? System.out.println("[Installer.extractBundles] destDir - " + destDir);
//System.out.println("[Installer.extractBundles] destDir is " + destDir); destDir =Activator.getInformation().getBundleDir() + destDir;
//destDir =Activator.getInformation().getBundleDir() +"/"+ destDir; //Does this work only on Linux/Unix?
System.out.println("[Installer.extractBundles] destDir is " + destDir);
destDir =destDir.replace("/", "\\"); // For windows version destDir =destDir.replace("/", "\\"); // For windows version
//System.out.println("[Installer.extractBundles] destDir2 is " + destDir); //System.out.println("[Installer.extractBundles] destDir2 is " + destDir);
File appDir=new File(destDir); File appDir=new File(destDir);
...@@ -194,6 +192,7 @@ private String extractBundles(String path) { ...@@ -194,6 +192,7 @@ private String extractBundles(String path) {
slength=(suffix+"").length(); slength=(suffix+"").length();
appDir=new File(destDir); appDir=new File(destDir);
suffix++; suffix++;
System.out.println("[Installer.extractBundles] appDir - " + appDir + " suffix -" + suffix);
} }
appDir.mkdir(); appDir.mkdir();
try { try {
...@@ -205,6 +204,7 @@ private String extractBundles(String path) { ...@@ -205,6 +204,7 @@ private String extractBundles(String path) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("[Installer.extractBundles] the destination path is: " + destDir);
return destDir; return destDir;
} }
...@@ -225,7 +225,7 @@ public void revertInstallation(File folder){ ...@@ -225,7 +225,7 @@ public void revertInstallation(File folder){
static public void extractFolder(String zipFile, String destdir) throws ZipException, IOException static public void extractFolder(String zipFile, String destdir) throws ZipException, IOException
{ {
//System.out.println("[Installer.extractFolder] the zip file is: " + zipFile); System.out.println("[Installer.extractFolder] the zip file is: " + zipFile + " and dest dir: " + destdir);
int BUFFER = 2048; int BUFFER = 2048;
File file = new File(zipFile); File file = new File(zipFile);
...@@ -329,7 +329,9 @@ static public void extractFolder(String zipFile, String destdir) throws ZipExcep ...@@ -329,7 +329,9 @@ static public void extractFolder(String zipFile, String destdir) throws ZipExcep
* *
*/ */
public InstallationResults requestToInstall(URI deployFolder, Map layout) { public InstallationResults requestToInstall(URI deployFolder, Map layout) {
System.out.println("[Installer.requestToInstall] deployFolder: " + deployFolder); System.out.println("[Installer.requestToInstall] deployFolder: " + deployFolder);
// initialization: get references to DeployManager and AALSpaceManager
if (!initialized) initMpaInstallation();
if (deployManager==null) { if (deployManager==null) {
System.out.println("[Installer.requestToInstall] No deploy manager exists!"); System.out.println("[Installer.requestToInstall] No deploy manager exists!");
return InstallationResults.NOT_A_DEPLOYMANAGER; return InstallationResults.NOT_A_DEPLOYMANAGER;
...@@ -343,6 +345,9 @@ static public void extractFolder(String zipFile, String destdir) throws ZipExcep ...@@ -343,6 +345,9 @@ static public void extractFolder(String zipFile, String destdir) throws ZipExcep
* *
*/ */
public Map<String, PeerCard> getPeers() { public Map<String, PeerCard> getPeers() {
// initialization: get references to DeployManager and AALSpaceManager
if (!initialized) initMpaInstallation();
Map peers = new HashMap(); Map peers = new HashMap();
if (aalSpaceManager!=null) { if (aalSpaceManager!=null) {
peers = aalSpaceManager.getPeers(); peers = aalSpaceManager.getPeers();
...@@ -365,5 +370,53 @@ static public void extractFolder(String zipFile, String destdir) throws ZipExcep ...@@ -365,5 +370,53 @@ static public void extractFolder(String zipFile, String destdir) throws ZipExcep
return peers; return peers;
} }
/**
* installing a service
* @param path - the path of the downloaded .usrv file
* return the folder of the extracted contents for the .usrv file
*/
public String installService(String path) {
// TODO: add a window to show the starting of installing the service
// extract .usrv file under "/bundles" folder
System.out.println("[Installer.installService] extract the .usrv file from: " + path);
String srvPath = extractBundles(path);
System.out.println("[Installer.installService] the service bundles are extracted to: " + srvPath);
// TODO: check the contents of the .usrv file
// initialization: get references to DeployManager and AALSpaceManager
initMpaInstallation();
return srvPath;
}
/**
* installing a service from uStore
* @param path: the path for the downloaded .usrv file
*
*/
public void installServiceFromOnlineStore(String path) {
String srvPath = installService(path);
// install each .uapp file found
if(srvPath==null)
System.out.println("[Installer.installServiceFromOnlineStore] Error extracting .usrv Package");
//TODO: update with the .usrv file structure - this has the same logic as InstallView.installFile()
srvPath = srvPath + "\\config\\";
System.out.println("[Installer.installServiceFromOnlineStore] the .uapp files contained in: " + srvPath);
File appDir=new File(srvPath);
String[] content = appDir.list();
String appPath;
for(int i=0;i<content.length;i++){
if(content[i].endsWith(".uapp")) {
try {
appPath = installApplication(srvPath + content[i]);
Activator.getMainWindow().installApp(appPath);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
} }
\ 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