Skip to content

Commit

Permalink
automatically delete temporary files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nada Ismail committed May 4, 2015
1 parent 39f4c61 commit 68dc58f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Expand Up @@ -140,6 +140,9 @@ public class SelendroidConfiguration {
@Parameter(names = "-folder", description = "The folder which contains Android applications under test. This folder will monitor and add new apps to the apps store during the lifetime of the selendroid node.")
private String folder = null;

@Parameter(names = "-deleteTmpFiles", description = "Deletes temporary files created by the Selendroid Server.")
private boolean deleteTmpFiles = true;

public void setKeystore(String keystore) {
this.keystore = keystore;
}
Expand Down Expand Up @@ -364,6 +367,14 @@ public String getAppFolderToMonitor() {
return folder;
}

public boolean isDeleteTmpFiles() {
return deleteTmpFiles;
}

public void setDeleteTmpFiles(boolean deleteTmpFiles){
this.deleteTmpFiles = deleteTmpFiles;
}

/**
* @return {@code true} if Selendroid standalone should run in grid mode.
*/
Expand Down
Expand Up @@ -96,7 +96,9 @@ public SelendroidServerBuilder(SelendroidConfiguration serverConfiguration) {
/* package */void init(AndroidApp aut) throws IOException, ShellCommandException {
applicationUnderTest = aut;
File customizedServer = File.createTempFile("selendroid-server", ".apk");

if(serverConfiguration != null && serverConfiguration.isDeleteTmpFiles()) {
customizedServer.deleteOnExit(); //Deletes temporary files created
}
log.info("Creating customized Selendroid-server: " + customizedServer.getAbsolutePath());
InputStream is = getResourceAsStream(selendroidPrebuildServerPath);

Expand All @@ -113,10 +115,12 @@ public AndroidApp createSelendroidServer(AndroidApp aut) throws IOException,
cleanUpPrebuildServer();
File selendroidServer = createAndAddCustomizedAndroidManifestToSelendroidServer();
File outputFile =
new File(FileUtils.getTempDirectory(), String.format("selendroid-server-%s-%s.apk",
new File(FileUtils.getTempDirectory(), String.format("selendroid-server-%s-%s.apk",
applicationUnderTest.getBasePackage(),
getJarVersionNumber()));

if(serverConfiguration != null && serverConfiguration.isDeleteTmpFiles()) {
outputFile.deleteOnExit(); //Deletes file when done
}
return signTestServer(selendroidServer, outputFile);
}

Expand Down Expand Up @@ -146,6 +150,9 @@ public AndroidApp resignApp(File appFile) throws ShellCommandException, AndroidS
deleteFileFromAppSilently(app, "META-INF/NDKEYSTO.RSA");

File outputFile = new File(appFile.getParentFile(), "resigned-" + appFile.getName());
if(serverConfiguration != null && serverConfiguration.isDeleteTmpFiles()) {
outputFile.deleteOnExit();
}
return signTestServer(appFile, outputFile);
}

Expand Down Expand Up @@ -215,6 +222,7 @@ public AndroidApp resignApp(File appFile) throws ShellCommandException, AndroidS
ZipArchiveEntry binaryManifestXml = manifestApk.getEntry("AndroidManifest.xml");

File finalSelendroidServerFile = new File(tempdir.getAbsolutePath() + "selendroid-server.apk");

ZipArchiveOutputStream finalSelendroidServer =
new ZipArchiveOutputStream(finalSelendroidServerFile);
finalSelendroidServer.putArchiveEntry(binaryManifestXml);
Expand Down
Expand Up @@ -164,8 +164,12 @@ public void addToAppsStore(File file) throws AndroidSdkException {
// using "android" as the app name, because that is the desired capability default in
// selenium for
// DesiredCapabilities.ANDROID
File androidAPK = androidDriverAPKBuilder.extractAndroidDriverAPK();
if(serverConfiguration != null && serverConfiguration.isDeleteTmpFiles()) {
androidAPK.deleteOnExit(); //Deletes temporary files if flag set
}
AndroidApp app =
selendroidApkBuilder.resignApp(androidDriverAPKBuilder.extractAndroidDriverAPK());
selendroidApkBuilder.resignApp(androidAPK);
appsStore.put(BrowserType.ANDROID, app);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 68dc58f

Please sign in to comment.