/** * Checks an output {@link File} object. * This checks the following: * - the file is not an existing directory. * - if the file exists, that it can be modified. * - if it doesn't exists, that a new file can be created. * @param file the File to check * @throws PackagerException If the check fails */ private void checkOutputFile(File file) throws PackagerException { if (file.isDirectory()) { throw new PackagerException("%s is a directory!", file); } if (file.exists()) { // will be a file in this case. if (!file.canWrite()) { throw new PackagerException("Cannot write %s", file); } } else { try { if (!file.createNewFile()) { throw new PackagerException("Failed to create %s", file); } } catch (IOException e) { throw new PackagerException( "Failed to create '%1$ss': %2$s", file, e.getMessage()); } } }
/** * Checks an input {@link File} object. * This checks the following: * - the file is not an existing directory. * - that the file exists and can be read. * @param file the File to check * @throws FileNotFoundException if the file is not here. * @throws PackagerException If the file is a folder or a file that cannot be read. */ private static void checkInputFile(File file) throws FileNotFoundException, PackagerException { if (file.isDirectory()) { throw new PackagerException("%s is a directory!", file); } if (file.exists()) { if (!file.canRead()) { throw new PackagerException("Cannot read %s", file); } } else { throw new FileNotFoundException(String.format("%s does not exist", file)); } }
/** * Checks an input {@link File} object. * This checks the following: * - the file is not an existing directory. * - that the file exists (if <var>throwIfDoesntExist</var> is <code>false</code>) and can * be read. * @param file the File to check * @throws FileNotFoundException if the file is not here. * @throws PackagerException If the file is a folder or a file that cannot be read. */ private static void checkInputFile(File file) throws FileNotFoundException, PackagerException { if (file.isDirectory()) { throw new PackagerException("%s is a directory!", file); } if (file.exists()) { if (!file.canRead()) { throw new PackagerException("Cannot read %s", file); } } else { throw new FileNotFoundException(String.format("%s does not exist", file)); } }
throw new PackagerException("%s is a directory!", file); throw new PackagerException("Cannot write %s", file); throw new PackagerException("Failed to create %s", file); throw new PackagerException("Failed to delete newly created %s", file); throw new PackagerException( "Failed to create '%1$ss': %2$s", file, e.getMessage());
/** * Checks the merger folder is: * - a directory. * - if the folder exists, that it can be modified. * - if it doesn't exists, that a new folder can be created. * @param file the File to check * @throws PackagerException If the check fails */ private static void checkMergingFolder(File file) throws PackagerException { if (file.isFile()) { throw new PackagerException("%s is a file!", file); } if (file.exists()) { // will be a directory in this case. if (!file.canWrite()) { throw new PackagerException("Cannot write %s", file); } FileUtils.deleteFolder(file); } if (!file.mkdirs()) { throw new PackagerException("Failed to create %s", file); } }
throw e; } catch (Exception e) { throw new PackagerException(e, "Failed to add %s", sourceFolder); throw new PackagerException("%s is not a folder", sourceFolder);
private void doAddFile( @NonNull File file, @NonNull String archivePath) throws PackagerException { Preconditions.checkNotNull(mApkCreator, "mApkCreator == null"); mAddedFiles.put(archivePath, file); try { mApkCreator.writeFile(file, archivePath); } catch (IOException e) { throw new PackagerException(e); } }
throw new PackagerException("%s is not a folder", nativeFolder); } else { throw new PackagerException("%s does not exist", nativeFolder); } catch (IOException e) { mBuilder.cleanUp(); throw new PackagerException(e, "Failed to add %s", lib);
throw new PackagerException(e, "Failed to add merged file %s", inputFile); mIsSealed = true; } catch (Exception e) { throw new PackagerException(e, "Failed to seal APK"); } finally { mBuilder.cleanUp();
throw new PackagerException(e);
/** * Adds a file to the APK at a given path * @param file the file to add * @param archivePath the path of the file inside the APK archive. * @throws PackagerException if an error occurred * @throws com.android.builder.packaging.SealedPackageException if the APK is already sealed. * @throws DuplicateFileException if a file conflicts with another already added to the APK * at the same location inside the APK archive. */ @Override public void addFile(File file, String archivePath) throws PackagerException, SealedPackageException, DuplicateFileException { if (mIsSealed) { throw new SealedPackageException("APK is already sealed"); } try { doAddFile(file, archivePath); } catch (DuplicateFileException e) { mBuilder.cleanUp(); throw e; } catch (Exception e) { mBuilder.cleanUp(); throw new PackagerException(e, "Failed to add %s", file); } }
} catch (Exception e) { mBuilder.cleanUp(); throw new PackagerException(e, "Failed to add %s", zipFile); } finally { try {
} catch (Exception e) { mBuilder.cleanUp(); throw new PackagerException(e, "Failed to add %s", jarFile); } finally { try {
mBuilder.cleanUp(); throw new PackagerException(e);
throw new PackagerException("Unable to compute hash of " + jar.getAbsolutePath());