use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class ChooseGradleHomeDialog method validateMinimumGradleVersion.
@Nullable
private ValidationInfo validateMinimumGradleVersion() {
if (isNotEmpty(myMinimumGradleVersion)) {
// When we reach this point we know the path entered is a valid Gradle home path. Now we need to verify the version of Gradle at that
// location is equal or greater than the one in myMinimumGradleVersion.
GradleVersion minimum = GradleVersion.parse(myMinimumGradleVersion);
File enteredGradleHomePath = getGradleHomePath(getEnteredGradleHomePath());
GradleVersion gradleVersion = GradleVersions.getInstance().getGradleVersion(enteredGradleHomePath);
if (gradleVersion == null) {
return newPathIsInvalidInfo("Unable to detect Gradle version");
}
if (minimum.compareTo(gradleVersion) > 0) {
return newPathIsInvalidInfo(String.format("Gradle %1$s or newer is required", myMinimumGradleVersion));
}
}
return null;
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class AndroidPluginInfo method find.
@Nullable
private static AndroidPluginInfo find(@NotNull Project project, boolean searchInBuildFilesOnly) {
Module appModule = null;
AndroidModuleModel appGradleModel = null;
VirtualFile pluginBuildFile = null;
if (!searchInBuildFilesOnly) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
AndroidModuleModel gradleModel = AndroidModuleModel.get(module);
if (gradleModel != null && gradleModel.getProjectType() == PROJECT_TYPE_APP) {
// This is the 'app' module in the project.
appModule = module;
appGradleModel = gradleModel;
break;
}
}
}
GradleVersion pluginVersion = appGradleModel != null ? appGradleModel.getModelVersion() : null;
AndroidPluginGeneration pluginGeneration = null;
if (appModule != null) {
pluginGeneration = AndroidPluginGeneration.find(appModule);
if (pluginGeneration == COMPONENT) {
// "Experimental" plugin does not retrieve correct version yet.
pluginVersion = null;
}
}
boolean appModuleFound = appModule != null;
boolean pluginVersionFound = pluginVersion != null;
if (!appModuleFound || !pluginVersionFound) {
// Try to find 'app' module or plugin version by reading build.gradle files.
BuildFileSearchResult result = searchInBuildFiles(project, !appModuleFound);
if (result.appVirtualFile != null) {
appModule = findModuleForFile(result.appVirtualFile, project);
}
if (isNotEmpty(result.pluginVersion)) {
pluginVersion = GradleVersion.tryParse(result.pluginVersion);
}
if (pluginGeneration == null) {
pluginGeneration = result.pluginGeneration;
}
pluginBuildFile = result.pluginVirtualFile;
}
if (appModule != null && pluginGeneration != null) {
return new AndroidPluginInfo(appModule, pluginGeneration, pluginVersion, pluginBuildFile);
}
return null;
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class DependenciesExtractor method extractFrom.
@NotNull
public DependencySet extractFrom(@NotNull AndroidModuleModel androidModel) {
DependencySet dependencies = new DependencySet();
GradleVersion modelVersion = androidModel.getModelVersion();
for (BaseArtifact testArtifact : androidModel.getTestArtifactsInSelectedVariant()) {
populate(dependencies, testArtifact, TEST, modelVersion);
}
AndroidArtifact mainArtifact = androidModel.getMainArtifact();
populate(dependencies, mainArtifact, COMPILE, modelVersion);
return dependencies;
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class ProjectStructureUsageTracker method trackProjectStructure.
@VisibleForTesting
void trackProjectStructure(@NotNull Module[] modules) {
AndroidModuleModel appModel = null;
AndroidModuleModel libModel = null;
int appCount = 0;
int libCount = 0;
List<GradleLibrary> gradleLibraries = new ArrayList<>();
for (Module module : modules) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
if (androidModel.getProjectType() == PROJECT_TYPE_LIBRARY) {
libModel = androidModel;
libCount++;
continue;
}
appModel = androidModel;
appCount++;
GradleLibrary gradleLibrary = trackExternalDependenciesInAndroidApp(androidModel);
if (gradleLibrary != null) {
gradleLibraries.add(gradleLibrary);
}
}
}
// Ideally we would like to get data from an "app" module, but if the project does not have one (which would be unusual, we can use
// an Android library one.)
AndroidModuleModel model = appModel != null ? appModel : libModel;
if (model != null) {
List<GradleAndroidModule> gradleAndroidModules = new ArrayList<>();
List<GradleNativeAndroidModule> gradleNativeAndroidModules = new ArrayList<>();
String appId = AndroidStudioUsageTracker.anonymizeUtf8(model.getApplicationId());
AndroidProject androidProject = model.getAndroidProject();
GradleVersion gradleVersion = GradleVersions.getInstance().getGradleVersion(myProject);
if (gradleVersion == null) {
gradleVersion = new GradleVersion(0, 0, 0);
}
GradleModule gradleModule = GradleModule.newBuilder().setTotalModuleCount(modules.length).setAppModuleCount(appCount).setLibModuleCount(libCount).build();
for (Module module : modules) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
gradleAndroidModules.add(GradleAndroidModule.newBuilder().setModuleName(AndroidStudioUsageTracker.anonymizeUtf8(module.getName())).setSigningConfigCount(androidModel.getAndroidProject().getSigningConfigs().size()).setIsLibrary(androidModel.getProjectType() == PROJECT_TYPE_LIBRARY).setBuildTypeCount(androidModel.getBuildTypeNames().size()).setFlavorCount(androidModel.getProductFlavorNames().size()).setFlavorDimension(getFlavorDimensions(androidModel).size()).build());
}
boolean shouldReportNative = false;
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
NativeBuildSystemType buildSystemType = NativeBuildSystemType.UNKNOWN_NATIVE_BUILD_SYSTEM_TYPE;
String moduleName = "";
if (ndkModuleModel != null) {
shouldReportNative = true;
if (ndkModuleModel.modelVersionIsAtLeast("2.2.0")) {
for (String buildSystem : ndkModuleModel.getAndroidProject().getBuildSystems()) {
buildSystemType = stringToBuildSystemType(buildSystem);
}
} else {
buildSystemType = NativeBuildSystemType.GRADLE_EXPERIMENTAL;
}
moduleName = AndroidStudioUsageTracker.anonymizeUtf8(ndkModuleModel.getModuleName());
} else if (androidModel != null && areNativeLibrariesPresent(androidModel.getAndroidProject())) {
shouldReportNative = true;
if (AndroidPluginGeneration.find(module) == COMPONENT) {
buildSystemType = NativeBuildSystemType.GRADLE_EXPERIMENTAL;
} else {
buildSystemType = NativeBuildSystemType.NDK_COMPILE;
}
}
if (shouldReportNative) {
gradleNativeAndroidModules.add(GradleNativeAndroidModule.newBuilder().setModuleName(moduleName).setBuildSystemType(buildSystemType).build());
}
}
UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(EventCategory.GRADLE).setKind(AndroidStudioEvent.EventKind.GRADLE_BUILD_DETAILS).setGradleBuildDetails(GradleBuildDetails.newBuilder().setAppId(appId).setAndroidPluginVersion(androidProject.getModelVersion()).setGradleVersion(gradleVersion.toString()).setUserEnabledIr(InstantRunSettings.isInstantRunEnabled()).setModelSupportsIr(InstantRunGradleUtils.modelSupportsInstantRun(model)).setVariantSupportsIr(InstantRunGradleUtils.variantSupportsInstantRun(model)).addAllLibraries(gradleLibraries).addModules(gradleModule).addAllAndroidModules(gradleAndroidModules).addAllNativeAndroidModules(gradleNativeAndroidModules)));
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class AndroidLintGlobalInspectionContext method performPreRunActivities.
@Override
public void performPreRunActivities(@NotNull List<Tools> globalTools, @NotNull List<Tools> localTools, @NotNull final GlobalInspectionContext context) {
final Project project = context.getProject();
// Running a single inspection that's not lint? If so don't run lint
if (localTools.isEmpty() && globalTools.size() == 1) {
Tools tool = globalTools.get(0);
if (!tool.getShortName().startsWith(LINT_INSPECTION_PREFIX)) {
return;
}
}
if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID)) {
return;
}
List<Issue> issues = AndroidLintExternalAnnotator.getIssuesFromInspections(project, null);
if (issues.size() == 0) {
return;
}
// If running a single check by name, turn it on if it's off by default.
if (localTools.isEmpty() && globalTools.size() == 1) {
Tools tool = globalTools.get(0);
String id = tool.getShortName().substring(LINT_INSPECTION_PREFIX.length());
Issue issue = new LintIdeIssueRegistry().getIssue(id);
if (issue != null && !issue.isEnabledByDefault()) {
issues = Collections.singletonList(issue);
issue.setEnabledByDefault(true);
// And turn it back off again in cleanup
myEnabledIssue = issue;
}
}
final Map<Issue, Map<File, List<ProblemData>>> problemMap = new HashMap<>();
AnalysisScope scope = context.getRefManager().getScope();
if (scope == null) {
scope = AndroidLintLintBaselineInspection.ourRerunScope;
if (scope == null) {
return;
}
}
final LintIdeClient client = LintIdeClient.forBatch(project, problemMap, scope, issues);
final LintDriver lint = new LintDriver(new LintIdeIssueRegistry(), client);
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
ProgressWrapper.unwrap(indicator).setText("Running Android Lint");
}
EnumSet<Scope> lintScope;
//noinspection ConstantConditions
if (!LintIdeProject.SUPPORT_CLASS_FILES) {
lintScope = EnumSet.copyOf(Scope.ALL);
// Can't run class file based checks
lintScope.remove(Scope.CLASS_FILE);
lintScope.remove(Scope.ALL_CLASS_FILES);
lintScope.remove(Scope.JAVA_LIBRARIES);
} else {
lintScope = Scope.ALL;
}
List<VirtualFile> files = null;
final List<Module> modules = Lists.newArrayList();
int scopeType = scope.getScopeType();
switch(scopeType) {
case AnalysisScope.MODULE:
{
SearchScope searchScope = ReadAction.compute(scope::toSearchScope);
if (searchScope instanceof ModuleWithDependenciesScope) {
ModuleWithDependenciesScope s = (ModuleWithDependenciesScope) searchScope;
if (!s.isSearchInLibraries()) {
modules.add(s.getModule());
}
}
break;
}
case AnalysisScope.FILE:
case AnalysisScope.VIRTUAL_FILES:
case AnalysisScope.UNCOMMITTED_FILES:
{
files = Lists.newArrayList();
SearchScope searchScope = scope.toSearchScope();
if (searchScope instanceof LocalSearchScope) {
final LocalSearchScope localSearchScope = (LocalSearchScope) searchScope;
final PsiElement[] elements = localSearchScope.getScope();
final List<VirtualFile> finalFiles = files;
ApplicationManager.getApplication().runReadAction(() -> {
for (PsiElement element : elements) {
if (element instanceof PsiFile) {
// should be the case since scope type is FILE
Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module != null && !modules.contains(module)) {
modules.add(module);
}
VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
if (virtualFile != null) {
if (virtualFile instanceof StringsVirtualFile) {
StringsVirtualFile f = (StringsVirtualFile) virtualFile;
if (!modules.contains(f.getFacet().getModule())) {
modules.add(f.getFacet().getModule());
}
} else {
finalFiles.add(virtualFile);
}
}
}
}
});
} else {
final List<VirtualFile> finalList = files;
scope.accept(new PsiElementVisitor() {
@Override
public void visitFile(PsiFile file) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
finalList.add(virtualFile);
}
}
});
}
if (files.isEmpty()) {
files = null;
} else {
// Lint will compute it lazily based on actual files in the request
lintScope = null;
}
break;
}
case AnalysisScope.PROJECT:
{
modules.addAll(Arrays.asList(ModuleManager.getInstance(project).getModules()));
break;
}
case AnalysisScope.CUSTOM:
case AnalysisScope.MODULES:
case AnalysisScope.DIRECTORY:
{
// Handled by the getNarrowedComplementaryScope case below
break;
}
case AnalysisScope.INVALID:
break;
default:
Logger.getInstance(this.getClass()).warn("Unexpected inspection scope " + scope + ", " + scopeType);
}
if (modules.isEmpty()) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (scope.containsModule(module)) {
modules.add(module);
}
}
if (modules.isEmpty() && files != null) {
for (VirtualFile file : files) {
Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module != null && !modules.contains(module)) {
modules.add(module);
}
}
}
if (modules.isEmpty()) {
AnalysisScope narrowed = scope.getNarrowedComplementaryScope(project);
for (Module module : ModuleManager.getInstance(project).getModules()) {
if (narrowed.containsModule(module)) {
modules.add(module);
}
}
}
}
LintRequest request = new LintIdeRequest(client, project, files, modules, false);
request.setScope(lintScope);
// Baseline analysis?
myBaseline = null;
for (Module module : modules) {
AndroidModuleModel model = AndroidModuleModel.get(module);
if (model != null) {
GradleVersion version = model.getModelVersion();
if (version != null && version.isAtLeast(2, 3, 0, "beta", 2, true)) {
LintOptions options = model.getAndroidProject().getLintOptions();
try {
File baselineFile = options.getBaselineFile();
if (baselineFile != null && !AndroidLintLintBaselineInspection.ourSkipBaselineNextRun) {
if (!baselineFile.isAbsolute()) {
String path = module.getProject().getBasePath();
if (path != null) {
baselineFile = new File(FileUtil.toSystemDependentName(path), baselineFile.getPath());
}
}
myBaseline = new LintBaseline(client, baselineFile);
lint.setBaseline(myBaseline);
if (!baselineFile.isFile()) {
myBaseline.setWriteOnClose(true);
} else if (AndroidLintLintBaselineInspection.ourUpdateBaselineNextRun) {
myBaseline.setRemoveFixed(true);
myBaseline.setWriteOnClose(true);
}
}
} catch (Throwable unsupported) {
// During 2.3 development some builds may have this method, others may not
}
}
break;
}
}
lint.analyze(request);
AndroidLintLintBaselineInspection.clearNextRunState();
myResults = problemMap;
}
Aggregations