mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Modify ArtifactParser and get the version of an artifact through ArtifatcParser
This commit is contained in:
parent
05d5ab2e9a
commit
a01ecdb9c3
@ -36,6 +36,8 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorag
|
|||||||
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
|
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.exception.ParsingException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
|
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
|
||||||
@ -207,27 +209,11 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ApplicationType.ANDROID.toString().equals(deviceType)) {
|
if (ApplicationType.ANDROID.toString().equals(deviceType)) {
|
||||||
String prefix = "stream2file";
|
ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(binaryFile);
|
||||||
String suffix = ".apk";
|
|
||||||
File tempFile = File.createTempFile(prefix, suffix);
|
|
||||||
FileOutputStream out = new FileOutputStream(tempFile);
|
|
||||||
IOUtils.copy(binaryFile, out);
|
|
||||||
try (ApkFile apkFile = new ApkFile(tempFile)){
|
|
||||||
ApkMeta apkMeta = apkFile.getApkMeta();
|
|
||||||
applicationRelease.setVersion(apkMeta.getVersionName());
|
applicationRelease.setVersion(apkMeta.getVersionName());
|
||||||
Files.delete(tempFile.toPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (ApplicationType.IOS.toString().equals(deviceType)) {
|
} else if (ApplicationType.IOS.toString().equals(deviceType)) {
|
||||||
String prefix = "stream2file";
|
NSDictionary plistInfo = ArtifactsParser.readiOSManifestFile(binaryFile);
|
||||||
String suffix = ".ipa";
|
applicationRelease.setVersion(plistInfo.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString());
|
||||||
|
|
||||||
File tempFile = File.createTempFile(prefix, suffix);
|
|
||||||
FileOutputStream out = new FileOutputStream(tempFile);
|
|
||||||
IOUtils.copy(binaryFile, out);
|
|
||||||
Map<String, String> plistInfo = getIPAInfo(tempFile);
|
|
||||||
applicationRelease.setVersion(plistInfo.get("CFBundleVersion"));
|
|
||||||
Files.delete(tempFile.toPath());
|
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
|
throw new ApplicationStorageManagementException("Application Type doesn't match with supporting " +
|
||||||
"application types " + applicationRelease.getUuid());
|
"application types " + applicationRelease.getUuid());
|
||||||
@ -249,6 +235,10 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|||||||
throw new ApplicationStorageManagementException(
|
throw new ApplicationStorageManagementException(
|
||||||
"IO Exception while saving the release artifacts in the server for the application UUID "
|
"IO Exception while saving the release artifacts in the server for the application UUID "
|
||||||
+ applicationRelease.getUuid(), e);
|
+ applicationRelease.getUuid(), e);
|
||||||
|
} catch (ParsingException e) {
|
||||||
|
throw new ApplicationStorageManagementException(
|
||||||
|
"Error occured while parsing the artifact file. Application release UUID is " + applicationRelease
|
||||||
|
.getUuid(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationRelease;
|
return applicationRelease;
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import net.dongliu.apk.parser.bean.ApkMeta;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.ParsingException;
|
import org.wso2.carbon.device.application.mgt.core.exception.ParsingException;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -38,6 +37,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
@ -55,19 +55,22 @@ public class ArtifactsParser {
|
|||||||
File tempFile = null;
|
File tempFile = null;
|
||||||
ApkMeta apkMeta;
|
ApkMeta apkMeta;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".apk");
|
tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".apk");
|
||||||
try (FileOutputStream out = new FileOutputStream(tempFile)) {
|
try (FileOutputStream out = new FileOutputStream(tempFile)) {
|
||||||
IOUtils.copy(inputStream, out);
|
IOUtils.copy(inputStream, out);
|
||||||
}
|
try (ApkFile apkFile = new ApkFile(tempFile)) {
|
||||||
|
|
||||||
ApkFile apkFile = new ApkFile(tempFile);
|
|
||||||
apkMeta = apkFile.getApkMeta();
|
apkMeta = apkFile.getApkMeta();
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ParsingException("Error while parsing the apk.", e);
|
throw new ParsingException("Error while parsing the apk.", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (tempFile != null) {
|
if (tempFile != null) {
|
||||||
tempFile.delete();
|
try {
|
||||||
|
Files.delete(tempFile.toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error occured while deleting the temp file", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return apkMeta;
|
return apkMeta;
|
||||||
@ -75,34 +78,27 @@ public class ArtifactsParser {
|
|||||||
|
|
||||||
public static NSDictionary readiOSManifestFile(InputStream inputStream) throws ParsingException {
|
public static NSDictionary readiOSManifestFile(InputStream inputStream) throws ParsingException {
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
File tempFile = null;
|
|
||||||
NSDictionary rootDict;
|
NSDictionary rootDict;
|
||||||
ZipInputStream stream = null;
|
File tempFile = null;
|
||||||
FileOutputStream out = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".ipa");
|
tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".ipa");
|
||||||
out = new FileOutputStream(tempFile);
|
try (FileOutputStream out = new FileOutputStream(tempFile)) {
|
||||||
IOUtils.copy(inputStream, out);
|
IOUtils.copy(inputStream, out);
|
||||||
stream = new ZipInputStream(new FileInputStream(tempFile));
|
try (ZipInputStream stream = new ZipInputStream(new FileInputStream(tempFile))) {
|
||||||
|
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
while ((entry = stream.getNextEntry()) != null) {
|
while ((entry = stream.getNextEntry()) != null) {
|
||||||
if (entry.getName().matches("^(Payload/)(.)+(.app/Info.plist)$")) {
|
if (entry.getName().matches("^(Payload/)(.)+(.app/Info.plist)$")) {
|
||||||
InputStream is = stream;
|
InputStream is = stream;
|
||||||
|
|
||||||
int nRead;
|
int nRead;
|
||||||
byte[] data = new byte[16384];
|
byte[] data = new byte[16384];
|
||||||
|
|
||||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||||
buffer.write(data, 0, nRead);
|
buffer.write(data, 0, nRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.flush();
|
buffer.flush();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray());
|
rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -113,6 +109,8 @@ public class ArtifactsParser {
|
|||||||
throw new ParsingException("Error while parsing the non binary plist.", e1);
|
throw new ParsingException("Error while parsing the non binary plist.", e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (PropertyListFormatException e1) {
|
} catch (PropertyListFormatException e1) {
|
||||||
throw new ParsingException("Error while parsing the plist.", e1);
|
throw new ParsingException("Error while parsing the plist.", e1);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
@ -121,21 +119,13 @@ public class ArtifactsParser {
|
|||||||
throw new ParsingException("Error while parsing the file.", e);
|
throw new ParsingException("Error while parsing the file.", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (tempFile != null) {
|
if (tempFile != null) {
|
||||||
tempFile.delete();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (out != null) {
|
Files.delete(tempFile.toPath());
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
if (stream != null) {
|
|
||||||
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
log.error("Error occured while deleting the temp file", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rootDict;
|
return rootDict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user