55import com .intellij .openapi .module .Module ;
66import com .intellij .openapi .project .Project ;
77import org .apache .commons .io .FileUtils ;
8+ import org .apache .velocity .runtime .directive .Foreach ;
89import org .eclipse .jgit .api .Git ;
910import org .eclipse .jgit .api .errors .GitAPIException ;
1011
@@ -280,6 +281,7 @@ private static Boolean updateInstallProjectSettingsForModule(GearSpec spec, Proj
280281 //Install dependency and sub-dependencies
281282 File settingsFile = new File (project .getBasePath () + pathSeparator + "settings.gradle" );
282283 File buildFile = new File (new File (module .getModuleFilePath ()).getParentFile ().getAbsolutePath () + pathSeparator + "build.gradle" );
284+ File gearBuildFile = new File (Utils .fileInstallPathForSpec (spec , project ).getParentFile ().getAbsolutePath () + pathSeparator + spec .getVersion () + pathSeparator + "build.gradle" );
283285
284286 //Create comment string
285287 String commentString = "\n /////////////////////\n " +
@@ -322,7 +324,6 @@ private static Boolean updateInstallProjectSettingsForModule(GearSpec spec, Proj
322324 //Create new addition
323325 String newDependencyString = "\n dependencies{compile project (':Gears:Modules:" +spec .getName ()+":" +spec .getVersion ()+"')}" ;
324326
325-
326327 if (!buildFileString .contains (newDependencyString )){
327328 int commentIndex = buildFileString .lastIndexOf (commentString );
328329
@@ -339,11 +340,56 @@ private static Boolean updateInstallProjectSettingsForModule(GearSpec spec, Proj
339340 FileUtils .write (buildFile , buildFileString );
340341 }
341342
343+ //Get compileSDK version and buildTools version
344+ String [] appLines = buildFileString .split ("\n " );
345+ String compileSDKVersion = null ;
346+ String buildToolsVersion = null ;
347+ for (String line : appLines ){
348+ if (line .contains ("compileSdkVersion" )){
349+ compileSDKVersion = line .replace ("compileSdkVersion" , "" ).replace (" " , "" );
350+ }
351+ else if (line .contains ("buildToolsVersion" )){
352+ buildToolsVersion = line .replace ("buildToolsVersion" , "" ).replace (" " , "" );
353+ }
354+ }
355+
356+ //Apply collected compile version and build tools version
357+ if (compileSDKVersion != null || buildToolsVersion != null ) {
358+ String gearBuildFileString = FileUtils .readFileToString (gearBuildFile );
359+
360+ //Apply compiled sdk and build tools sdk to new module
361+ String [] moduleLines = gearBuildFileString .split ("\n " );
362+ String modifiedModuleBuildFileString = "" ;
363+ for (String line : moduleLines ) {
364+ if (line .contains ("'android-library'" )){
365+ modifiedModuleBuildFileString = modifiedModuleBuildFileString + "apply plugin: 'com.android.library'" + "\n " ;
366+ }
367+ else if (line .contains ("compileSdkVersion" )){
368+ modifiedModuleBuildFileString = modifiedModuleBuildFileString + "compileSdkVersion " +compileSDKVersion +"\n " ;
369+ }
370+ else if (line .contains ("buildToolsVersion" )){
371+ modifiedModuleBuildFileString = modifiedModuleBuildFileString + "buildToolsVersion " +buildToolsVersion +"\n " ;
372+ }
373+ else {
374+ modifiedModuleBuildFileString = modifiedModuleBuildFileString + line +"\n " ;
375+ }
376+ }
377+
378+ //Write changes to build.gradle
379+ FileUtils .forceDelete (gearBuildFile );
380+ FileUtils .write (gearBuildFile , modifiedModuleBuildFileString );
381+
382+ }
383+
384+
342385 } catch (IOException e ) {
343386 e .printStackTrace ();
344387 return false ;
345388 }
346389
390+
391+
392+
347393 return true ;
348394 }
349395
0 commit comments