use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class DependencySetupTest method WithUnresolvedDependencies.
// Fails in Bazel PSQ because of missing dependencies in the prebuilt Android SDK.
public void WithUnresolvedDependencies() throws Exception {
loadSimpleApplication();
File buildFilePath = getBuildFilePath("app");
VirtualFile buildFile = findFileByIoFile(buildFilePath, true);
assertNotNull(buildFile);
boolean versionChanged = false;
Project project = getProject();
GradleBuildModel buildModel = GradleBuildModel.parseBuildFile(buildFile, project);
for (ArtifactDependencyModel artifact : buildModel.dependencies().artifacts()) {
if ("com.android.support".equals(artifact.group().value()) && "appcompat-v7".equals(artifact.name().value())) {
artifact.setVersion("100.0.0");
versionChanged = true;
break;
}
}
assertTrue(versionChanged);
runWriteCommandAction(project, buildModel::applyChanges);
LocalFileSystem.getInstance().refresh(false);
SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(project);
requestSyncAndWait();
SyncMessage reportedMessage = syncMessages.getFirstReportedMessage();
assertNotNull(reportedMessage);
String[] text = reportedMessage.getText();
assertThat(text).isNotEmpty();
assertEquals("Failed to resolve: com.android.support:appcompat-v7:100.0.0", text[0]);
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project freeline by alibaba.
the class FreelineUtil method getFreelineStatus.
/**
* 获取freeline安装状态
*
* @param project
* @return
*/
public static FreelineStatus getFreelineStatus(@NotNull Project project) {
FreelineStatus status = new FreelineStatus();
Collection<VirtualFile> gradleFiles = GradleUtil.getAllGradleFile(project);
status.setGradleBuildFiles(gradleFiles);
for (VirtualFile file : gradleFiles) {
if (!status.isExistClasspath()) {
GradleBuildModel model = GradleBuildModel.parseBuildFile(file, project);
if (model != null) {
List<ArtifactDependencyModel> classPaths = model.buildscript().dependencies().artifacts();
for (ArtifactDependencyModel classpath : classPaths) {
ArtifactDependencyModelWrapper wrapper = new ArtifactDependencyModelWrapper(classpath);
if (wrapper.group().equals(Constant.FREELINE_CLASSPATH_GROUP) && wrapper.name().equals(Constant.FREELINE_CLASSPATH_ARTIFACT)) {
status.setClasspathFile(file);
break;
}
}
}
}
// 正则二次判断是否存在Freeline classpath
if (!status.isExistClasspath() && regularExistFreelineClassPath(file)) {
status.setClasspathFile(file);
}
if (!status.isExistPlugin()) {
GradleBuildFile gradleBuildFile = new GradleBuildFile(file, project);
if (gradleBuildFile != null) {
List<String> plugins = gradleBuildFile.getPlugins();
if (plugins.contains(Constant.FREELINE_PLUGIN_ID)) {
status.setPluginFile(file);
}
}
}
if (status.isExistClasspath() && status.isExistPlugin()) {
break;
}
}
File baseFile = new File(project.getBasePath());
if (new File(baseFile, Constant.FREELINE_ROOT_FOLDER).exists() && new File(baseFile, Constant.FREELINE_PYTHON).exists()) {
if (SystemInfo.isWindows) {
if (new File(baseFile, Constant.FREELINE_ROOT_FOLDER_CORE).exists()) {
status.setExistFreelineCore(true);
}
} else {
status.setExistFreelineCore(true);
}
}
return status;
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project freeline by alibaba.
the class UpdateAction method updateAction.
/**
* 更新操作
*
* @param newVersion
* @param gradleBuildModels
*/
protected void updateAction(final String newVersion, final Map<GradleBuildModel, List<ArtifactDependencyModel>> gradleBuildModels) {
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (GradleBuildModel file : gradleBuildModels.keySet()) {
List<ArtifactDependencyModel> models = gradleBuildModels.get(file);
for (ArtifactDependencyModel dependencyModel1 : models) {
ArtifactDependencyModelWrapper dependencyModel = new ArtifactDependencyModelWrapper(dependencyModel1);
if (isClasspathLibrary(dependencyModel)) {
dependencyModel1.setVersion(newVersion);
}
if (isDependencyLibrary(dependencyModel)) {
file.dependencies().remove(dependencyModel1);
}
}
file.applyChanges();
}
GradleUtil.executeTask(currentProject, "initFreeline", "-Pmirror", new ExternalSystemTaskNotificationListenerAdapter() {
@Override
public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
super.onTaskOutput(id, text, stdOut);
}
});
}
});
}
});
}
Aggregations