11// Copyright (C) 2012 Xamarin, Inc. All rights reserved.
22
3- using System ;
4- using System . Collections . Generic ;
5- using System . Linq ;
63using System . IO ;
7- using System . Reflection ;
8- using Microsoft . Build . Framework ;
9- using Microsoft . Build . Utilities ;
10- using System . Text ;
11- using Bytecode = Xamarin . Android . Tools . Bytecode ;
12- using System . Diagnostics ;
134using Microsoft . Android . Build . Tasks ;
5+ using Microsoft . Build . Framework ;
146
157namespace Xamarin . Android . Tasks
168{
17- public class ClassParse : AndroidTask
9+ public class ClassParse : AndroidDotnetToolTask
1810 {
1911 public override string TaskPrefix => "CLP" ;
2012
13+ protected override string BaseToolName => "class-parse" ;
14+
2115 [ Required ]
2216 public string OutputFile { get ; set ; }
2317
@@ -26,43 +20,33 @@ public class ClassParse : AndroidTask
2620
2721 public ITaskItem [ ] DocumentationPaths { get ; set ; }
2822
29- public override bool RunTask ( )
23+ protected override string GenerateCommandLineCommands ( )
3024 {
31- using ( var output = new StreamWriter ( OutputFile , append : false ,
32- encoding : Files . UTF8withoutBOM ) ) {
33- Bytecode . Log . OnLog = LogEventHandler ;
34- var classPath = new Bytecode . ClassPath ( ) {
35- ApiSource = "class-parse" ,
36- DocumentationPaths = ( DocumentationPaths ?? Enumerable . Empty < ITaskItem > ( ) ) . Select ( x => x . ItemSpec )
37- } ;
38- foreach ( var jar in SourceJars ) {
39- if ( Bytecode . ClassPath . IsJarFile ( jar . ItemSpec ) ) {
40- classPath . Load ( jar . ItemSpec ) ;
41- }
42- }
43- classPath . SaveXmlDescription ( output ) ;
25+ var cmd = GetCommandLineBuilder ( ) ;
26+
27+ var responseFile = Path . Combine ( Path . GetDirectoryName ( OutputFile ) , "class-parse.rsp" ) ;
28+ Log . LogDebugMessage ( "[class-parse] response file: {0}" , responseFile ) ;
29+
30+ using ( var sw = new StreamWriter ( responseFile , append : false , encoding : Files . UTF8withoutBOM ) ) {
31+ WriteLine ( sw , $ "--o=\" { OutputFile } \" ") ;
32+
33+ if ( DocumentationPaths != null )
34+ foreach ( var doc in DocumentationPaths )
35+ WriteLine ( sw , $ "--docspath=\" { doc } \" ") ;
36+
37+ foreach ( var doc in SourceJars )
38+ WriteLine ( sw , $ "\" { doc } \" ") ;
4439 }
45- return true ;
40+
41+ cmd . AppendSwitch ( $ "@{ responseFile } ") ;
42+
43+ return cmd . ToString ( ) ;
4644 }
4745
48- void LogEventHandler ( TraceLevel type , int verbosity , string message , params object [ ] args )
46+ void WriteLine ( StreamWriter sw , string line )
4947 {
50- switch ( type ) {
51- case TraceLevel . Error :
52- Log . LogError ( message , args ) ;
53- break ;
54- case TraceLevel . Warning :
55- Log . LogWarning ( message , args ) ;
56- break ;
57- case TraceLevel . Info :
58- Log . LogMessage ( ( MessageImportance ) verbosity , message , args ) ;
59- break ;
60- default :
61- Log . LogDebugMessage ( message , args ) ;
62- break ;
63-
64- }
48+ sw . WriteLine ( line ) ;
49+ Log . LogDebugMessage ( line ) ;
6550 }
6651 }
6752}
68-
0 commit comments