public override List <FixProblemInstruction> check() { List <FixProblemInstruction> instructions = new List <FixProblemInstruction>(); string appodealDependenciesFile = getAppodealDependenciesFile(); Regex reAar = new Regex(@"play-services.+-(?<version>\d+\.\d+(\.\d+)*)"); string[] aarFiles = getPlayServicesAarFiles(); foreach (string file in aarFiles) { foreach (string service in requiredServices.Keys) { if (file.Contains(service)) { Match m = reAar.Match(file); if (m.Success) { requiredServices[service].Add(m.Value); } else { FixProblemInstruction instr = new FixProblemInstruction( "Play service without specified version found. " + "Please specify version to be able to resolve possible conflicts automatically." + file, false); instructions.Add(instr); return(instructions); } } } } HashSet <string> absentServices = new HashSet <string>(); HashSet <string> allVersions = new HashSet <string>(); foreach (KeyValuePair <string, HashSet <string> > service in requiredServices) { if (service.Value.Count == 0) { absentServices.Add(service.Key); } allVersions.UnionWith(service.Value); } DependenciesParser deps = new DependenciesParser(getAllDependenciesFiles()); absentServices.RemoveWhere(s => deps.foundServices.Contains(s)); if (absentServices.Count > 0) { string absent = string.Join(",", absentServices.ToArray()); FixProblemInstruction instr = new FixProblemInstruction("Some required Play Services are absent in your project: " + absent, false); instructions.Add(instr); return(instructions); } HashSet <string> allVersionsInDependencies = new HashSet <string>(); foreach (KeyValuePair <string, HashSet <string> > kv in deps.playServicesVersions) { if (kv.Value.Count > 1) { FixProblemInstruction instr = new FixProblemInstruction( "Two or more different versions of play services are presented in " + kv.Key + ". Please contact the plugin developers to clarify what version is required.", false); instructions.Add(instr); return(instructions); } allVersionsInDependencies.UnionWith(kv.Value); } if (allVersions.Count == 0) { if (allVersionsInDependencies.Count == 0) { FixProblemInstruction instr = new FixProblemInstruction( "There is no Google Play Services in the project. It's a essential condition if you want to use Appodeal plugin. Please visit our web site to get more information.", false); instructions.Add(instr); return(instructions); } else if (allVersionsInDependencies.Count == 1) { //and at least some of required services are in xml } //Надо узнать, есть ли зависимости в градле и правильные ли они или xml прежде чем что-то предлагать //В xml - ресолвим //В градл - вообще все норм (при условии отсуствия конфликтов) } else if (allVersions.Count == 2) { //1 Зависимости от разных xml (если один из них - AppodealDependencies, то меняем в нем; если нет, то придется ограничится предупреждением) //2 Одни - зависимость от xml, другие просто положены каким-то плагином (Если есть AppodealDependencies, то меняем в нем? иначе предупреждение) //3 Все напрямую распространялись плагинами (предупреждение) } else if (allVersions.Count > 2) { FixProblemInstruction instr = new FixProblemInstruction( "There are three or more different versions of google play services " + "in your project: " + allVersions + ". It's not possible to resolve this conflict automatically. " + "Try to update all plugins in your project and run the checker again.", false); instructions.Add(instr); return(instructions); } //What if aar file is a result of JarResolver work? We can change version in resolver and aar version will be changed too //On the other hand, it can be just an aar. And we can't change anything in this case. return(instructions); }
public override List <FixProblemInstruction> check() { var instructions = new List <FixProblemInstruction>(); var reAar = new Regex(@"play-services.+-(?<version>\d+\.\d+(\.\d+)*)"); var aarFiles = getPlayServicesAarFiles(); foreach (var file in aarFiles) { foreach (var service in requiredServices.Keys) { if (!file.Contains(service)) { continue; } var m = reAar.Match(file); if (m.Success) { requiredServices[service].Add(m.Value); } else { var instr = new FixProblemInstruction( "Play service without specified version found. " + "Please specify version to be able to resolve possible conflicts automatically." + file, false); instructions.Add(instr); return(instructions); } } } var absentServices = new HashSet <string>(); var allVersions = new HashSet <string>(); foreach (var service in requiredServices) { if (service.Value.Count == 0) { absentServices.Add(service.Key); } allVersions.UnionWith(service.Value); } var deps = new DependenciesParser(getAllDependenciesFiles()); absentServices.RemoveWhere(s => deps.foundServices.Contains(s)); if (absentServices.Count > 0) { var absent = string.Join(",", absentServices.ToArray()); var instr = new FixProblemInstruction("Some required Play Services are absent in your project: " + absent, false); instructions.Add(instr); return(instructions); } var allVersionsInDependencies = new HashSet <string>(); foreach (var kv in deps.playServicesVersions) { if (kv.Value.Count > 1) { var instr = new FixProblemInstruction( "Two or more different versions of play services are presented in " + kv.Key + ". Please contact the plugin developers to clarify what version is required.", false); instructions.Add(instr); return(instructions); } allVersionsInDependencies.UnionWith(kv.Value); } switch (allVersions.Count) { case 0: { switch (allVersionsInDependencies.Count) { case 0: { var instr = new FixProblemInstruction( "There is no Google Play Services in the project. It's a essential condition if you want to use Appodeal plugin. Please visit our web site to get more information.", false); instructions.Add(instr); return(instructions); } case 1: break; } break; } case 2: break; default: { if (allVersions.Count > 2) { var instr = new FixProblemInstruction( "There are three or more different versions of google play services " + "in your project: " + allVersions + ". It's not possible to resolve this conflict automatically. " + "Try to update all plugins in your project and run the checker again.", false); instructions.Add(instr); return(instructions); } break; } } return(instructions); }