private boolean checkPackage() {
        if (getBarPackage().getApkFile() == null
                || !getBarPackage().getApkFile().canRead()) {
            getLog().error("APK file is not specified or cannot be read.");
            return false;
        }

        String apkName = getBarPackage().getApkFile().getName();

        if (getBarPackage().getBarFile() == null) {
            getLog().error("BAR file is not specified.");
            return false;
        }

        File currentBarFile = new File(getBarPackage().getBarFile().getParent(),
                                       apkName.replace(".apk", ".bar"));

        if (!currentBarFile.exists()) {
            getLog().error("BAR file does not exist.");
            return false;
        }

        File desirableBarFile = getBarPackage().getBarFile();

        if (currentBarFile.getPath().equals(desirableBarFile.getPath())) {
            // APK file name matches BAR file name, no need to rename.
            return true;
        }

        if (!currentBarFile.canWrite()) {
            getLog().error("BAR file does not exist or no permission to write.");
            return false;
        }

        // If a file with such name already exists, try to delete it.
        if (desirableBarFile.exists() && !desirableBarFile.delete()) {
            getLog().error("Failed to delete existing BAR file with desirable " +
                           "name. Path: " + desirableBarFile.getPath());
            return false;
        }

        return currentBarFile.renameTo(desirableBarFile);
    }