}
public static Configuration loadConfiguration(File file) throws FileNotFoundException, IOException, InvalidCSConfigVersionException {
DesignDefinition syncInfo = null;
CSConfig csConfig = null;
String licenseText = null;
// Normal plugin file
if (file.isFile()) {
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(file));
try {
ZipEntry entry;
while ((entry = zipIn.getNextEntry()) != null) {
String entryName = entry.getName();
if (entryName.equals(DesignDirectory.DESIGN_DEFINITION_FILE) || entryName.equals(DesignDirectory.SYNCINFO_FILE)) {
TemporaryFile tempFile = new TemporaryFile("design", zipIn, null);
syncInfo = DesignDefinition.load(tempFile.getFile());
tempFile.delete();
}
else if (entryName.equals(SystemContainerManager.CSCONFIG_PATH)) {
TemporaryFile tempFile = new TemporaryFile("csconfig", zipIn, null);
csConfig = CSConfig.load(tempFile.getFile());
tempFile.delete();
}
else if (entryName.equals(SystemContainerManager.LICENSE_PATH)) {
licenseText = WGUtils.readString(new InputStreamReader(zipIn, "UTF-8")).trim();
}
if (syncInfo != null && csConfig != null) {
break;
}
}
}
finally {
zipIn.close();
}
}
// Developer plugin folder
else {
File syncInfoFile = DesignDirectory.getDesignDefinitionFile(file);
if (syncInfoFile.exists()) {
syncInfo = DesignDefinition.load(syncInfoFile);
}
File csConfigFile = new File(file, SystemContainerManager.CSCONFIG_PATH);
if (csConfigFile.exists()) {
csConfig = CSConfig.load(csConfigFile);
}
File licenseTextFile = new File(file, SystemContainerManager.LICENSE_PATH);
if (licenseTextFile.exists()) {
Reader reader = new InputStreamReader(new FileInputStream(licenseTextFile) , "UTF-8");
licenseText = WGUtils.readString(reader).trim();
reader.close();
}
}
if (syncInfo != null && csConfig != null && csConfig.getPluginConfig() != null) {
return new Configuration(syncInfo, csConfig, licenseText);
}
else {
return null;
}