ConfigPackage extends JarFile implements Closeable { public ConfigPackage(File file) throws IOException, ZipException { super(file); Manifest manifest = getManifest(); if (manifest == null) { throw new IOException("Not a valid config package. MANIFEST.MF is not present."); } Attributes attr = manifest.getMainAttributes(); configPackageName = attr.getValue(ATTRIBUTE_DT_CONF_PACKAGE_NAME); appPackageName = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_NAME); appPackageGroupId = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_GROUP_ID); appPackageMinVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_MIN_VERSION); appPackageMaxVersion = attr.getValue(ATTRIBUTE_DT_APP_PACKAGE_MAX_VERSION); configPackageDescription = attr.getValue(ATTRIBUTE_DT_CONF_PACKAGE_DESCRIPTION); String classPathString = attr.getValue(ATTRIBUTE_CLASS_PATH); String filesString = attr.getValue(ATTRIBUTE_FILES); if (configPackageName == null) { throw new IOException("Not a valid config package. DT-Conf-Package-Name is missing from MANIFEST.MF"); } if (!StringUtils.isBlank(classPathString)) { classPath.addAll(Arrays.asList(StringUtils.split(classPathString, " "))); } if (!StringUtils.isBlank(filesString)) { files.addAll(Arrays.asList(StringUtils.split(filesString, " "))); } ZipFile zipFile = new ZipFile(file); if (zipFile.isEncrypted()) { throw new ZipException("Encrypted conf package not supported yet"); } File newDirectory = Files.createTempDirectory("dt-configPackage-").toFile(); newDirectory.mkdirs(); directory = newDirectory.getAbsolutePath(); zipFile.extractAll(directory); processPropertiesXml(); processAppDirectory(new File(directory, "app")); } ConfigPackage(File file); List<AppPackage.AppInfo> getApplications(); String tempDirectory(); @Override void close(); String getConfigPackageName(); String getAppPackageName(); String getAppPackageGroupId(); String getAppPackageMinVersion(); String getAppPackageMaxVersion(); String getConfigPackageDescription(); List<String> getClassPath(); List<String> getFiles(); Map<String, String> getProperties(String appName); static final String ATTRIBUTE_DT_CONF_PACKAGE_NAME; static final String ATTRIBUTE_DT_APP_PACKAGE_NAME; static final String ATTRIBUTE_DT_APP_PACKAGE_GROUP_ID; static final String ATTRIBUTE_DT_APP_PACKAGE_MIN_VERSION; static final String ATTRIBUTE_DT_APP_PACKAGE_MAX_VERSION; static final String ATTRIBUTE_DT_CONF_PACKAGE_DESCRIPTION; static final String ATTRIBUTE_CLASS_PATH; static final String ATTRIBUTE_FILES; }
@Test public void testConfigPackage() throws Exception { Assert.assertEquals("com.example", json.getString("appPackageGroupId")); Assert.assertEquals("myapexapp", json.getString("appPackageName")); Assert.assertEquals("1.0.0", json.getString("appPackageMinVersion")); Assert.assertEquals("1.9999.9999", json.getString("appPackageMaxVersion")); Assert.assertEquals("classpath/*", json.getJSONArray("classPath").getString(0)); Assert.assertEquals("files/*", json.getJSONArray("files").getString(0)); }