use of com.android.tools.idea.gradle.util.GradleWrapper in project android by JetBrains.
the class AndroidGradleTestCase method createGradleWrapper.
protected static void createGradleWrapper(File projectRoot) throws IOException {
GradleWrapper wrapper = GradleWrapper.create(projectRoot);
File path = getWorkspaceFile("tools/external/gradle/gradle-" + GRADLE_LATEST_VERSION + "-bin.zip");
assertAbout(file()).that(path).named("Gradle distribution path").isFile();
wrapper.updateDistributionUrl(path);
}
use of com.android.tools.idea.gradle.util.GradleWrapper in project android by JetBrains.
the class GradleDslMethodNotFoundErrorHandler method getGradleSettingsHyperlink.
@NotNull
private static NotificationHyperlink getGradleSettingsHyperlink(@NotNull Project project) {
if (isUsingWrapper(project)) {
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
VirtualFile propertiesFile = gradleWrapper.getPropertiesFile();
if (propertiesFile != null) {
return new NotificationHyperlink("open.wrapper.file", "Open Gradle wrapper file") {
@Override
protected void execute(@NotNull Project project) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, propertiesFile);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
};
}
}
}
return new OpenGradleSettingsHyperlink();
}
use of com.android.tools.idea.gradle.util.GradleWrapper in project android by JetBrains.
the class UnsupportedGradleVersionErrorHandler method getQuickFixHyperlinks.
@NotNull
public static List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull Project project, @Nullable String gradleVersion) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
// It is very likely that we need to fix the model version as well. Do everything in one shot.
NotificationHyperlink hyperlink = createIfProjectUsesGradleWrapper(project, gradleVersion);
if (hyperlink != null) {
hyperlinks.add(hyperlink);
}
} else {
GradleProjectSettings gradleProjectSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
if (gradleProjectSettings != null && gradleProjectSettings.getDistributionType() == DistributionType.LOCAL) {
hyperlinks.add(new CreateGradleWrapperHyperlink());
}
}
hyperlinks.add(new OpenGradleSettingsHyperlink());
return hyperlinks;
}
use of com.android.tools.idea.gradle.util.GradleWrapper in project android by JetBrains.
the class GradleDistributionCleanUpTask method cleanUp.
@Override
void cleanUp(@NotNull Project project) {
GradleProjectSettings gradleSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
GradleWrapper gradleWrapper = GradleWrapper.find(project);
DistributionType distributionType = gradleSettings != null ? gradleSettings.getDistributionType() : null;
boolean usingWrapper = (distributionType == null || distributionType == DEFAULT_WRAPPED) && gradleWrapper != null;
if (usingWrapper && gradleSettings != null) {
// Do this just to ensure that the right distribution type is set. If this is not set, build.gradle editor will not have code
// completion (see BuildClasspathModuleGradleDataService, line 119).
gradleSettings.setDistributionType(DEFAULT_WRAPPED);
} else if (gradleWrapper == null && gradleSettings != null) {
createWrapperIfNecessary(project, gradleSettings, distributionType);
}
}
use of com.android.tools.idea.gradle.util.GradleWrapper in project android by JetBrains.
the class AndroidPluginVersionUpdater method updatePluginVersion.
/**
* Updates the plugin version and, optionally, the Gradle version used by the project.
*
* @param pluginVersion the plugin version to update to.
* @param gradleVersion the version of Gradle to update to (optional.)
* @return the result of the update operation.
*/
@NotNull
public UpdateResult updatePluginVersion(@NotNull GradleVersion pluginVersion, @Nullable GradleVersion gradleVersion) {
List<GradleBuildModel> modelsToUpdate = Lists.newArrayList();
BuildFileProcessor.getInstance().processRecursively(myProject, buildModel -> {
DependenciesModel dependencies = buildModel.buildscript().dependencies();
for (ArtifactDependencyModel dependency : dependencies.artifacts(CLASSPATH)) {
String artifactId = dependency.name().value();
String groupId = dependency.group().value();
if (AndroidPluginGeneration.find(artifactId, groupId) != null) {
String versionValue = dependency.version().value();
if (isEmpty(versionValue) || pluginVersion.compareTo(versionValue) != 0) {
dependency.setVersion(pluginVersion.toString());
modelsToUpdate.add(buildModel);
}
break;
}
}
return true;
});
UpdateResult result = new UpdateResult();
boolean updateModels = !modelsToUpdate.isEmpty();
if (updateModels) {
try {
runWriteCommandAction(myProject, new ThrowableComputable<Void, RuntimeException>() {
@Override
public Void compute() {
for (GradleBuildModel buildModel : modelsToUpdate) {
buildModel.applyChanges();
}
result.pluginVersionUpdated();
return null;
}
});
} catch (Throwable e) {
result.setPluginVersionUpdateError(e);
}
}
if (gradleVersion != null) {
String basePath = myProject.getBasePath();
if (basePath != null) {
try {
File wrapperPropertiesFilePath = getDefaultPropertiesFilePath(new File(basePath));
GradleWrapper gradleWrapper = GradleWrapper.get(wrapperPropertiesFilePath);
String current = gradleWrapper.getGradleVersion();
GradleVersion parsedCurrent = null;
if (current != null) {
parsedCurrent = GradleVersion.tryParse(current);
}
if (parsedCurrent != null && !isSupportedGradleVersion(parsedCurrent)) {
gradleWrapper.updateDistributionUrl(gradleVersion.toString());
result.gradleVersionUpdated();
}
} catch (Throwable e) {
result.setGradleVersionUpdateError(e);
}
}
}
return result;
}
Aggregations