use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class GradleUtil method getDirectLibraryDependencies.
/**
* Returns the library dependencies in the given variant. This method checks dependencies in the main and test (as currently selected
* in the UI) artifacts. The dependency lookup is not transitive (only direct dependencies are returned.)
*/
@NotNull
public static List<AndroidLibrary> getDirectLibraryDependencies(@NotNull Variant variant, @NotNull AndroidModuleModel androidModel) {
List<AndroidLibrary> libraries = Lists.newArrayList();
GradleVersion modelVersion = androidModel.getModelVersion();
AndroidArtifact mainArtifact = variant.getMainArtifact();
Dependencies dependencies = getDependencies(mainArtifact, modelVersion);
libraries.addAll(dependencies.getLibraries());
for (BaseArtifact testArtifact : getTestArtifacts(variant)) {
dependencies = getDependencies(testArtifact, modelVersion);
libraries.addAll(dependencies.getLibraries());
}
return libraries;
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class NewModuleWizardDynamic method determineGradlePluginVersion.
@NotNull
private static String determineGradlePluginVersion(@Nullable Project project) {
if (project != null) {
GradleVersion versionInUse = GradleUtil.getAndroidGradleModelVersionInUse(project);
if (versionInUse != null) {
return versionInUse.toString();
}
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(project);
if (androidPluginInfo != null) {
GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
if (pluginVersion != null) {
return pluginVersion.toString();
}
}
}
return AndroidPluginGeneration.ORIGINAL.getLatestKnownVersion();
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class DefaultRecipeExecutor method addClasspath.
@Override
public void addClasspath(@NotNull String mavenUrl) {
mavenUrl = mavenUrl.trim();
myReferences.addClasspath(mavenUrl);
ArtifactDependencySpec toBeAddedDependency = ArtifactDependencySpec.create(mavenUrl);
if (toBeAddedDependency == null) {
throw new RuntimeException(mavenUrl + " is not a valid classpath dependency");
}
Project project = myContext.getProject();
File rootBuildFile = getGradleBuildFilePath(getBaseDirPath(project));
if (project.isInitialized()) {
GradleBuildModel buildModel = getBuildModel(rootBuildFile, project);
DependenciesModel buildscriptDependencies = buildModel.buildscript().dependencies();
ArtifactDependencyModel targetDependencyModel = null;
for (ArtifactDependencyModel dependencyModel : buildscriptDependencies.artifacts(CLASSPATH_CONFIGURATION_NAME)) {
if (toBeAddedDependency.equalsIgnoreVersion(ArtifactDependencySpec.create(dependencyModel))) {
targetDependencyModel = dependencyModel;
}
}
if (targetDependencyModel == null) {
buildscriptDependencies.addArtifact(CLASSPATH_CONFIGURATION_NAME, toBeAddedDependency);
} else {
GradleVersion toBeAddedDependencyVersion = GradleVersion.parse(nullToEmpty(toBeAddedDependency.version));
GradleVersion existingDependencyVersion = GradleVersion.parse(nullToEmpty(targetDependencyModel.version().value()));
if (toBeAddedDependencyVersion.compareTo(existingDependencyVersion) > 0) {
targetDependencyModel.setVersion(nullToEmpty(toBeAddedDependency.version));
}
}
myIO.applyChanges(buildModel);
} else {
String destinationContents = rootBuildFile.exists() ? nullToEmpty(readTextFile(rootBuildFile)) : "";
String result = myIO.mergeGradleFiles(formatClasspath(mavenUrl), destinationContents, project, "");
try {
myIO.writeFile(this, result, rootBuildFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
myNeedsGradleSync = true;
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class AndroidPluginInfoTest method testFindWithStablePlugin.
public void testFindWithStablePlugin() throws Exception {
loadSimpleApplication();
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(getProject());
assertNotNull(androidPluginInfo);
assertNotNull(androidPluginInfo.getModule());
assertEquals("app", androidPluginInfo.getModule().getName());
assertEquals(ORIGINAL, androidPluginInfo.getPluginGeneration());
assertNull(androidPluginInfo.getPluginBuildFile());
GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
assertNotNull(pluginVersion);
assertEquals(BuildEnvironment.getInstance().getGradlePluginVersion(), pluginVersion.toString());
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class AndroidPluginInfoTest method testFindWithStablePluginReadingBuildFilesOnly.
public void testFindWithStablePluginReadingBuildFilesOnly() throws Exception {
loadSimpleApplication();
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(getProject());
assertNotNull(androidPluginInfo);
assertNotNull(androidPluginInfo.getModule());
assertEquals("app", androidPluginInfo.getModule().getName());
assertEquals(ORIGINAL, androidPluginInfo.getPluginGeneration());
assertNotNull(androidPluginInfo.getPluginBuildFile());
assertEquals(new File(getProjectFolderPath(), FN_BUILD_GRADLE), new File(androidPluginInfo.getPluginBuildFile().getPath()));
GradleVersion pluginVersion = androidPluginInfo.getPluginVersion();
assertNotNull(pluginVersion);
assertEquals(BuildEnvironment.getInstance().getGradlePluginVersion(), pluginVersion.toString());
}
Aggregations