org.arquillian.droidium.container.deployment.AndroidDeploymentInstaller Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed 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.arquillian.droidium.container.deployment;
import java.io.File;
import org.arquillian.droidium.container.impl.AndroidApplicationHelper;
import org.arquillian.droidium.container.impl.AndroidApplicationManager;
import org.arquillian.droidium.container.sign.APKSigner;
import org.arquillian.droidium.container.spi.AndroidDeployment;
import org.arquillian.droidium.container.spi.event.AfterAndroidDeploymentDeployed;
import org.arquillian.droidium.container.spi.event.AndroidDeploy;
import org.arquillian.droidium.container.spi.event.BeforeAndroidDeploymentDeployed;
import org.arquillian.droidium.container.utils.DroidiumFileUtils;
import org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription;
import org.jboss.arquillian.core.api.Event;
import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.core.api.annotation.Observes;
import org.jboss.shrinkwrap.api.Archive;
/**
* Installs Android package to Android device.
*
* Observes:
*
* - {@link AndroidDeploy}
*
* Fires:
*
* - {@link BeforeAndroidDeploymentDeployed}
* - {@link AfterAndroidDeploymentDeployed}
*
*
* @author Stefan Miklosovic
*
*/
public class AndroidDeploymentInstaller {
@Inject
private Instance signer;
@Inject
private Instance androidApplicationHelper;
@Inject
private Instance androidApplicationManager;
@Inject
private Instance androidDeploymentRegister;
@Inject
private Event beforeAndroidDeployment;
@Inject
private Event afterAndroidDeployment;
public void onAndroidDeployArchive(@Observes AndroidDeploy event, DeploymentDescription description) {
beforeAndroidDeployment.fire(new BeforeAndroidDeploymentDeployed(event.getArchive()));
Archive> archive = event.getArchive();
File deployApk = new File(DroidiumFileUtils.getTmpDir(), DroidiumFileUtils.getRandomAPKFileName());
DroidiumFileUtils.export(archive, deployApk);
File resignedApk = signer.get().resign(deployApk);
AndroidDeployment deployment = new AndroidDeployment();
deployment.setDeployment(archive)
.setDeployApk(deployApk)
.setResignedApk(resignedApk)
.setApplicationBasePackage(androidApplicationHelper.get().getApplicationBasePackage(resignedApk))
.setDeploymentName(description.getName());
androidDeploymentRegister.get().add(deployment);
androidApplicationManager.get().install(deployment);
afterAndroidDeployment.fire(new AfterAndroidDeploymentDeployed(resignedApk));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy