Metadata tool correction: Output empty proto in case of no input

Change-Id: I85ca22574433ab164c303c1f6b0d29191e704cbb
diff --git a/tools/metadata/generator.go b/tools/metadata/generator.go
index d328876..b7668be 100644
--- a/tools/metadata/generator.go
+++ b/tools/metadata/generator.go
@@ -77,9 +77,18 @@
 	return string(data)
 }
 
-func writeNewlineToOutputFile(outputFile string) {
+func writeEmptyOutputProto(outputFile string, metadataRule string) {
 	file, err := os.Create(outputFile)
-	data := "\n"
+	if err != nil {
+		log.Fatal(err)
+	}
+	var message proto.Message
+	if metadataRule == "test_spec" {
+		message = &test_spec_proto.TestSpec{}
+	} else if metadataRule == "code_metadata" {
+		message = &code_metadata_proto.CodeMetadata{}
+	}
+	data, err := proto.Marshal(message)
 	if err != nil {
 		log.Fatal(err)
 	}
@@ -92,8 +101,8 @@
 }
 
 func processTestSpecProtobuf(
-		filePath string, ownershipMetadataMap *sync.Map, keyLocks *keyToLocksMap,
-		errCh chan error, wg *sync.WaitGroup,
+	filePath string, ownershipMetadataMap *sync.Map, keyLocks *keyToLocksMap,
+	errCh chan error, wg *sync.WaitGroup,
 ) {
 	defer wg.Done()
 
@@ -121,7 +130,7 @@
 				if metadata.GetTrendyTeamId() != existing.GetTrendyTeamId() {
 					errCh <- fmt.Errorf(
 						"Conflicting trendy team IDs found for %s at:\n%s with teamId"+
-								": %s,\n%s with teamId: %s",
+							": %s,\n%s with teamId: %s",
 						key,
 						metadata.GetPath(), metadata.GetTrendyTeamId(), existing.GetPath(),
 						existing.GetTrendyTeamId(),
@@ -147,8 +156,8 @@
 
 // processCodeMetadataProtobuf processes CodeMetadata protobuf files
 func processCodeMetadataProtobuf(
-		filePath string, ownershipMetadataMap *sync.Map, sourceFileMetadataMap *sync.Map, keyLocks *keyToLocksMap,
-		errCh chan error, wg *sync.WaitGroup,
+	filePath string, ownershipMetadataMap *sync.Map, sourceFileMetadataMap *sync.Map, keyLocks *keyToLocksMap,
+	errCh chan error, wg *sync.WaitGroup,
 ) {
 	defer wg.Done()
 
@@ -182,8 +191,8 @@
 				if attributes.TeamID != existing.TeamID && (!attributes.MultiOwnership || !existing.MultiOwnership) {
 					errCh <- fmt.Errorf(
 						"Conflict found for source file %s covered at %s with team ID: %s. Existing team ID: %s and path: %s."+
-								" If multi-ownership is required, multiOwnership should be set to true in all test_spec modules using this target. "+
-								"Multiple-ownership in general is discouraged though as it make infrastructure around android relying on this information pick up a random value when it needs only one.",
+							" If multi-ownership is required, multiOwnership should be set to true in all test_spec modules using this target. "+
+							"Multiple-ownership in general is discouraged though as it make infrastructure around android relying on this information pick up a random value when it needs only one.",
 						srcFile, internalMetadata.GetPath(), attributes.TeamID, existing.TeamID, existing.Path,
 					)
 					srcFileLock.Unlock()
@@ -235,7 +244,7 @@
 	inputFileData := strings.TrimRight(readFileToString(*inputFile), "\n")
 	filePaths := strings.Split(inputFileData, " ")
 	if len(filePaths) == 1 && filePaths[0] == "" {
-		writeNewlineToOutputFile(*outputFile)
+		writeEmptyOutputProto(*outputFile, *rule)
 		return
 	}
 	ownershipMetadataMap := &sync.Map{}