use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class BuildScriptModelTest method testParseDependencies.
public void testParseDependencies() throws IOException {
String text = "buildscript {\n" + " dependencies {\n" + " classpath 'com.android.tools.build:gradle:2.0.0-alpha2'\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
DependenciesModel dependenciesModel = buildModel.buildscript().dependencies();
List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
assertThat(dependencies).hasSize(1);
ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
expected.assertMatches(dependencies.get(0));
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class BuildScriptModelTest method testEditDependency.
public void testEditDependency() throws IOException {
String text = "buildscript {\n" + " dependencies {\n" + " classpath 'com.android.tools.build:gradle:2.0.0-alpha2'\n" + " }\n" + "}";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
DependenciesModel dependenciesModel = buildModel.buildscript().dependencies();
List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
assertThat(dependencies).hasSize(1);
ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
ArtifactDependencyModel actual = dependencies.get(0);
expected.assertMatches(actual);
actual.setVersion("2.0.1");
expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.1");
expected.assertMatches(actual);
assertTrue(buildModel.isModified());
applyChanges(buildModel);
assertFalse(buildModel.isModified());
buildModel.reparse();
dependencies = buildModel.buildscript().dependencies().artifacts();
assertThat(dependencies).hasSize(1);
expected.assertMatches(dependencies.get(0));
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.
the class BuildScriptModelTest method testAddDependency.
public void testAddDependency() throws IOException {
String text = "";
writeToBuildFile(text);
GradleBuildModel buildModel = getGradleBuildModel();
BuildScriptModel buildScriptModel = buildModel.buildscript();
DependenciesModel dependenciesModel = buildScriptModel.dependencies();
assertFalse(buildScriptModel.hasValidPsiElement());
assertFalse(dependenciesModel.hasValidPsiElement());
assertThat(dependenciesModel.artifacts()).isEmpty();
dependenciesModel.addArtifact("classpath", "com.android.tools.build:gradle:2.0.0-alpha2");
List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
assertThat(dependencies).hasSize(1);
ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
expected.assertMatches(dependencies.get(0));
assertTrue(buildModel.isModified());
applyChanges(buildModel);
assertFalse(buildModel.isModified());
buildModel.reparse();
buildScriptModel = buildModel.buildscript();
dependenciesModel = buildScriptModel.dependencies();
assertTrue(buildScriptModel.hasValidPsiElement());
assertTrue(dependenciesModel.hasValidPsiElement());
dependencies = dependenciesModel.artifacts();
assertThat(dependencies).hasSize(1);
expected.assertMatches(dependencies.get(0));
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project freeline by alibaba.
the class FreelineUtil method installFreeline.
private static void installFreeline(final Project project, final FreelineStatus status, final PsiFile psiFile, final GradleDependencyEntity dependencyEntity) {
needReformatCode = false;
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (!status.isExistClasspath()) {
Collection<VirtualFile> collection = status.getGradleBuildFiles();
if (dependencyEntity != null) {
for (VirtualFile file : collection) {
GradleBuildModel model = GradleBuildModel.parseBuildFile(file, project);
List<ArtifactDependencyModel> artifactDependencyModels = model.buildscript().dependencies().artifacts();
for (ArtifactDependencyModel model1 : artifactDependencyModels) {
ArtifactDependencyModelWrapper wrapper = new ArtifactDependencyModelWrapper(model1);
if (wrapper.group().equals(Constant.ANDROID_GRADLE_TOOL_GROUP_NAME)) {
ArtifactDependencySpec spec = new ArtifactDependencySpec(dependencyEntity.getArtifactId(), dependencyEntity.getGroupId(), dependencyEntity.getNewestReleaseVersion());
model.buildscript().dependencies().addArtifact("classpath", spec);
model.applyChanges();
needReformatCode = true;
status.setClasspathFile(file);
break;
}
}
if (status.isExistClasspath()) {
break;
}
}
}
}
if (!status.isExistPlugin()) {
if (psiFile != null && psiFile instanceof GroovyFile) {
GradleUtil.applyPlugin(project, (GroovyFile) psiFile, Constant.FREELINE_PLUGIN_ID);
}
}
}
});
}
});
if (needReformatCode && status.getClasspathFile() != null) {
DocumentUtil.reformatCode(project, status.getClasspathFile());
}
LogUtil.d("Sync Project Finish, start download freeline.zip.");
initFreeline(project);
}
use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project freeline by alibaba.
the class UpdateAction method resultHandle.
/**
* 处理结果
*
* @param entity
* @param gradleBuildModels
*/
private void resultHandle(final GradleDependencyEntity entity, final Map<GradleBuildModel, List<ArtifactDependencyModel>> gradleBuildModels) {
String localVersion = null;
StringBuilder builder = new StringBuilder();
for (GradleBuildModel file : gradleBuildModels.keySet()) {
List<ArtifactDependencyModel> models = gradleBuildModels.get(file);
for (ArtifactDependencyModel dependencyModel1 : models) {
ArtifactDependencyModelWrapper dependencyModel = new ArtifactDependencyModelWrapper(dependencyModel1);
if (isClasspathLibrary(dependencyModel) || isDependencyLibrary(dependencyModel)) {
if (isClasspathLibrary(dependencyModel)) {
localVersion = dependencyModel.version();
}
builder.append(dependencyModel.configurationName()).append(" '").append(dependencyModel.group()).append(":").append(dependencyModel.name()).append(":").append(dependencyModel.version()).append("'").append("<br/>");
}
}
}
if (Utils.notEmpty(localVersion)) {
int compare = localVersion.compareTo(entity.getVersion());
final CheckUpdateDialog dialog = new CheckUpdateDialog();
dialog.getButtonOK().setEnabled(compare < 0);
dialog.setServerVersion(entity.getGroupId(), entity.getArtifactId(), entity.getVersion());
dialog.setServerUpdateTime(entity.getUpdateTime());
dialog.setLocalVersion(builder.toString());
dialog.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateAction(entity.getVersion(), gradleBuildModels);
dialog.dispose();
}
});
dialog.showDialog();
} else {
NotificationUtils.infoNotification("please add freeline dependency first");
}
}
Aggregations