diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 1bf7cca0c4..10f406d4cf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -181,15 +181,14 @@ org.wso2.carbon org.wso2.carbon.core - - net.dongliu - apk-parser - 2.5.2 - + com.googlecode.plist dd-plist - 1.20 + + + net.dongliu + apk-parser commons-validator diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ParsingException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ParsingException.java new file mode 100644 index 0000000000..85e806f7f1 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ParsingException.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.application.mgt.core.exception; + +public class ParsingException extends Exception { + + private static final long serialVersionUID = -8935642383846122660L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public ParsingException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public ParsingException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public ParsingException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public ParsingException() { + super(); + } + + public ParsingException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java new file mode 100644 index 0000000000..d619185ef9 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.wso2.carbon.device.application.mgt.core.util; + +import com.dd.plist.BinaryPropertyListParser; +import com.dd.plist.NSDictionary; +import com.dd.plist.PropertyListFormatException; +import com.dd.plist.PropertyListParser; +import net.dongliu.apk.parser.ApkFile; +import net.dongliu.apk.parser.bean.ApkMeta; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.wso2.carbon.device.application.mgt.core.exception.ParsingException; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.UUID; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class ArtifactsParser { + + //ios CF Bundle keys + public static final String IPA_BUNDLE_VERSION_KEY = "CFBundleVersion"; + public static final String IPA_BUNDLE_NAME_KEY = "CFBundleName"; + public static final String IPA_BUNDLE_IDENTIFIER_KEY = "CFBundleIdentifier"; + + private static final Log log = LogFactory.getLog(ArtifactsParser.class); + + public static ApkMeta readAndroidManifestFile(InputStream inputStream) throws ParsingException { + File tempFile = null; + ApkMeta apkMeta; + try { + + tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".apk"); + try (FileOutputStream out = new FileOutputStream(tempFile)) { + IOUtils.copy(inputStream, out); + } + + ApkFile apkFile = new ApkFile(tempFile); + apkMeta = apkFile.getApkMeta(); + } catch (IOException e) { + throw new ParsingException("Error while parsing the apk.", e); + } finally { + if (tempFile != null) { + tempFile.delete(); + } + } + return apkMeta; + } + + public static NSDictionary readiOSManifestFile(InputStream inputStream) throws ParsingException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + File tempFile = null; + NSDictionary rootDict; + ZipInputStream stream = null; + FileOutputStream out = null; + + try { + tempFile = File.createTempFile("temp" + UUID.randomUUID(), ".ipa"); + out = new FileOutputStream(tempFile); + IOUtils.copy(inputStream, out); + stream = new ZipInputStream(new FileInputStream(tempFile)); + + ZipEntry entry; + while ((entry = stream.getNextEntry()) != null) { + if (entry.getName().matches("^(Payload/)(.)+(.app/Info.plist)$")) { + InputStream is = stream; + + int nRead; + byte[] data = new byte[16384]; + + while ((nRead = is.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, nRead); + } + + buffer.flush(); + break; + } + } + + try { + rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray()); + } catch (IllegalArgumentException e) { + log.debug("Uploaded file didn't have a Binary Plist"); + try { + rootDict = (NSDictionary) PropertyListParser.parse(buffer.toByteArray()); + } catch (Exception e1) { + throw new ParsingException("Error while parsing the non binary plist.", e1); + } + } + } catch (PropertyListFormatException e1) { + throw new ParsingException("Error while parsing the plist.", e1); + } catch (FileNotFoundException e) { + throw new ParsingException("Error while creating temporary file.", e); + } catch (IOException e) { + throw new ParsingException("Error while parsing the file.", e); + } finally { + if (tempFile != null) { + tempFile.delete(); + } + try { + if (out != null) { + out.close(); + } + if (stream != null) { + + stream.close(); + + } + } catch (IOException e) { + } + } + + return rootDict; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index 5609ba9c2e..f36ef23f83 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -54,7 +54,7 @@ import javax.ws.rs.core.Response; * Implementation of Application Management related APIs. */ @Produces({"application/json"}) -@Path("/publisher/applications") +@Path("/applications") public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); diff --git a/pom.xml b/pom.xml index 05596b0688..43e2268bf2 100644 --- a/pom.xml +++ b/pom.xml @@ -1725,6 +1725,16 @@ test ${slf4j.nop.version} + + com.googlecode.plist + dd-plist + ${googlecode.plist.version} + + + net.dongliu + apk-parser + ${net.dongliu.version} + @@ -2165,6 +2175,10 @@ 1.4.0.wso2v1 1.7.25 + + 1.8 + 2.4.2 +