1 // =========================================================================
2 //
3 // INTEL CONFIDENTIAL
4 // Copyright 2005 - 2015
5 // Intel Corporation All Rights Reserved.
6 //
7 // =========================================================================
8 // The source code contained or described herein and all documents
9 // related to the source code ("Material") are owned by Intel Corporation
10 // or its suppliers or licensors. Title to the Material remains with
11 // Intel Corporation or its suppliers and licensors. The Material contains
12 // trade secrets and proprietary and confidential information of Intel or
13 // its suppliers and licensors. The Material is protected by worldwide
14 // copyright and trade secret laws and treaty provisions. No part of the
15 // Material may be used, copied, reproduced, modified, published, uploaded,
16 // posted, transmitted, distributed, or disclosed in any way without Intel’s
17 // prior express written permission.
18 //
19 // No license under any patent, copyright, trade secret or other intellectual
20 // property right is granted to or conferred upon you by disclosure or
21 // delivery of the Materials, either expressly, by implication, inducement,
22 // estoppel or otherwise. Any license under such intellectual property rights
23 // must be express and approved by Intel in writing.
24 // ==========================================================================
25
26 using System;
27 using System.Collections.Generic;
28 using System.Globalization;
29 using System.IO;
30 using System.Linq;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33
34 namespace Intel.Tools.MSBuildTasks.Localize
35 {
36 /// <summary>
37 /// An MSBuild Task for listing the languages supported by the given PCJ files.
38 /// </summary>
39 public class ListLanguages : Task
40 {
41 #region Constructor
42 /// <summary>
43 /// Creates a new instance of <see cref="ListLanguages"/>.
44 /// </summary>
45 public ListLanguages()
46 {
47 this.TranslationDatabaseFiles = new ITaskItem[0];
48 this.LanguageList = string.Empty;
49 }
50 #endregion
51
52 #region Fields
53 private const string _LogPrefix = " ** ListLanguages ** ";
54 #endregion
55
56 #region Properties
57 /// <summary>
58 /// Gets a prefix for log file entries.
59 /// </summary>
60 protected override string LogPrefix
61 {
62 get { return ListLanguages._LogPrefix; }
63 }
64
65 /// <summary>
66 /// Gets or sets the absolute file paths to the localized translation database files.
67 /// </summary>
68 [Required]
69 public ITaskItem[] TranslationDatabaseFiles { get; set; }
70 /// <summary>
71 /// Gets or sets comma-separated list of languages.
72 /// </summary>
73 [Output]
74 public string LanguageList { get; set; }
75 #endregion
76
77 #region Methods
78 /// <summary>
79 /// When overridden in a derived class, executes the Task
80 /// with logging initialized and error handling implemented.
81 /// </summary>
82 /// <returns>A boolean value indicating whether the Task completed successfully.</returns>
83 protected override bool ExecuteSafe()
84 {
85 var pcjFiles = new List<string>();
86
87 //Get all the pcj files.
88 if (this.TranslationDatabaseFiles != null)
89 {
90 foreach (var file in this.TranslationDatabaseFiles.Select(item => item.ItemSpec))
91 {
92 if (File.Exists(file))
93 {
94 pcjFiles.Add(Path.GetFullPath(file));
95 }
96 else throw new FileNotFoundException("File does not exist: " + file, file);
97 }
98 }
99 else throw new ArgumentOutOfRangeException("TranslationDatabaseFiles", "Must provide at least one translation database file.");
100
101 //Warn if there are no pcj files.
102 if (pcjFiles.Count == 0)
103 {
104 base.Log.LogWarning("No translation database files were found.");
105 }
106
(1) Event returned_null: |
"GetParent" returns "null" (checked 1 out of 4 times). |
(3) Event null_method_call: |
Calling a method on null object "System.IO.Directory.GetParent(pcjFile)". |
Also see events: |
[example_checked] |
107 var languageNames = pcjFiles.Select(pcjFile => new CultureInfo(Directory.GetParent(pcjFile).Name).Name);
108
109 this.LanguageList = string.Join(";", languageNames);
110
111 return true;
112 }
113 #endregion
114 }
115 }
116