Search in sources :

Example 1 with Control

use of com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control in project bazel by bazelbuild.

the class PlMerge method main.

public static void main(String[] args) throws OptionsParsingException, IOException {
    FileSystem fileSystem = FileSystems.getDefault();
    OptionsParser parser = OptionsParser.newOptionsParser(PlMergeOptions.class);
    parser.parse(args);
    PlMergeOptions options = parser.getOptions(PlMergeOptions.class);
    if (options.controlPath == null) {
        missingArg("control");
    }
    InputStream in = Files.newInputStream(fileSystem.getPath(options.controlPath));
    Control control = Control.parseFrom(in);
    validateControl(control);
    PlistMerging merging = PlistMerging.from(control, new KeysToRemoveIfEmptyString("CFBundleIconFile", "NSPrincipalClass"));
    String primaryBundleId = Strings.emptyToNull(control.getPrimaryBundleId());
    String fallbackBundleId = Strings.emptyToNull(control.getFallbackBundleId());
    if (primaryBundleId != null || fallbackBundleId != null) {
        // Only set the bundle identifier if we were passed arguments to do so.
        // This prevents CFBundleIdentifiers being put into strings files.
        merging.setBundleIdentifier(primaryBundleId, fallbackBundleId);
    }
    Path outputPath = fileSystem.getPath(control.getOutFile());
    switch(control.getOutputFormat()) {
        case BINARY:
            merging.writePlist(outputPath);
            break;
        case XML:
            merging.writeXmlPlist(outputPath);
            break;
        default:
            throw new IllegalArgumentException(String.format("Unknown output format in the control file: %s", control.getOutputFormat()));
    }
}
Also used : Path(java.nio.file.Path) Control(com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control) InputStream(java.io.InputStream) FileSystem(java.nio.file.FileSystem) OptionsParser(com.google.devtools.common.options.OptionsParser)

Aggregations

Control (com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos.Control)1 OptionsParser (com.google.devtools.common.options.OptionsParser)1 InputStream (java.io.InputStream)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1