Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit d1b93ba

Browse files
author
Matt York
committed
- Made module installs auto-correct compile version and build tools version
1 parent ba9e304 commit d1b93ba

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

AndroidGears/src/Utilities/GearSpecManager.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.intellij.openapi.module.Module;
66
import com.intellij.openapi.project.Project;
77
import org.apache.commons.io.FileUtils;
8+
import org.apache.velocity.runtime.directive.Foreach;
89
import org.eclipse.jgit.api.Git;
910
import 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 = "\ndependencies{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

Comments
 (0)