use of com.android.tools.idea.gradle.parser.GradleBuildFile in project android by JetBrains.
the class ArchiveToGradleModuleModelTest method assertSourceProjectCorrectlyModified.
private void assertSourceProjectCorrectlyModified(@NotNull String expectedBuildGradle, @NotNull String sourceModuleFilePath) throws IOException {
Project project = getProject();
VirtualFile gradleBuildFile = project.getBaseDir().findFileByRelativePath(sourceModuleFilePath + "/" + SdkConstants.FN_BUILD_GRADLE);
assertThat(gradleBuildFile).isNotNull();
GradleBuildFile buildModel = new GradleBuildFile(gradleBuildFile, project);
assertThat(expectedBuildGradle).isEqualTo(buildModel.getPsiFile().getText());
}
use of com.android.tools.idea.gradle.parser.GradleBuildFile 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.parser.GradleBuildFile in project android by JetBrains.
the class ManifestPanel method describePosition.
private void describePosition(@NotNull HtmlBuilder sb, @NotNull AndroidFacet facet, @NotNull SourceFilePosition sourceFilePosition) {
SourceFile sourceFile = sourceFilePosition.getFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
File file = sourceFile.getSourceFile();
if (file == GRADLE_MODEL_MARKER_FILE) {
VirtualFile gradleBuildFile = GradleUtil.getGradleBuildFile(facet.getModule());
if (gradleBuildFile != null) {
file = VfsUtilCore.virtualToIoFile(gradleBuildFile);
sb.addHtml("<a href=\"");
sb.add(file.toURI().toString());
sb.addHtml("\">");
sb.add(file.getName());
sb.addHtml("</a>");
sb.add(" injection");
} else {
sb.add("build.gradle injection (source location unknown)");
}
return;
}
AndroidLibrary library;
if (file != null) {
String source = null;
Module libraryModule = null;
Module[] modules = ModuleManager.getInstance(facet.getModule().getProject()).getModules();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vFile != null) {
Module module = ModuleUtilCore.findModuleForFile(vFile, facet.getModule().getProject());
if (module != null) {
if (modules.length >= 2) {
source = module.getName();
}
// AAR Library?
if (file.getPath().contains(EXPLODED_AAR)) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
library = GradleUtil.findLibrary(file.getParentFile(), androidModel.getSelectedVariant(), androidModel.getModelVersion());
if (library != null) {
if (library.getProject() != null) {
libraryModule = GradleUtil.findModuleByGradlePath(facet.getModule().getProject(), library.getProject());
if (libraryModule != null) {
module = libraryModule;
source = module.getName();
} else {
source = library.getProject();
source = StringUtil.trimStart(source, ":");
}
} else {
MavenCoordinates coordinates = library.getResolvedCoordinates();
source = /*coordinates.getGroupId() + ":" +*/
coordinates.getArtifactId() + ":" + coordinates.getVersion();
}
}
}
}
}
IdeaSourceProvider provider = ManifestUtils.findManifestSourceProvider(facet, vFile);
if (provider != null) /*&& !provider.equals(facet.getMainIdeaSourceProvider())*/
{
String providerName = provider.getName();
if (source == null) {
source = providerName;
} else {
// "the app main manifest" - "app" is the module name, "main" is the source provider name
source = source + " " + providerName;
}
}
}
if (source == null) {
source = file.getName();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
source += ":" + String.valueOf(sourcePosition);
}
}
sb.addHtml("<a href=\"");
boolean redirected = false;
if (libraryModule != null) {
AndroidFacet libraryFacet = AndroidFacet.getInstance(libraryModule);
if (libraryFacet != null) {
File manifestFile = libraryFacet.getMainSourceProvider().getManifestFile();
if (manifestFile.exists()) {
sb.add(manifestFile.toURI().toString());
redirected = true;
// Line numbers probably aren't right
sourcePosition = SourcePosition.UNKNOWN;
// TODO: Set URL which points to the element/attribute path
}
}
}
if (!redirected) {
sb.add(file.toURI().toString());
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartLine()));
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartColumn()));
}
}
sb.addHtml("\">");
sb.add(source);
sb.addHtml("</a>");
sb.add(" manifest");
if (FileUtil.filesEqual(file, VfsUtilCore.virtualToIoFile(myFile))) {
sb.add(" (this file)");
}
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(", line ");
sb.add(Integer.toString(sourcePosition.getStartLine()));
}
}
}
Aggregations