Search in sources :

Example 1 with SourceFile

use of com.android.ide.common.blame.SourceFile in project android by JetBrains.

the class ManifestPanel method goToDeclaration.

private void goToDeclaration(Node element) {
    List<? extends Actions.Record> records = ManifestUtils.getRecords(myManifest, element);
    for (Actions.Record record : records) {
        SourceFilePosition sourceFilePosition = ManifestUtils.getActionLocation(myFacet.getModule(), record);
        SourceFile sourceFile = sourceFilePosition.getFile();
        if (!SourceFile.UNKNOWN.equals(sourceFile)) {
            File ioFile = sourceFile.getSourceFile();
            if (ioFile != null) {
                VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(ioFile);
                assert file != null;
                int line = -1;
                int column = 0;
                SourcePosition sourcePosition = sourceFilePosition.getPosition();
                if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
                    line = sourcePosition.getStartLine();
                    column = sourcePosition.getStartColumn();
                }
                Project project = myFacet.getModule().getProject();
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
                FileEditorManager.getInstance(project).openEditor(descriptor, true);
                break;
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) IdeActions(com.intellij.openapi.actionSystem.IdeActions) Actions(com.android.manifmerger.Actions) SourcePosition(com.android.ide.common.blame.SourcePosition) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) SourceFile(com.android.ide.common.blame.SourceFile) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFile(com.android.ide.common.blame.SourceFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File)

Example 2 with SourceFile

use of com.android.ide.common.blame.SourceFile in project android by JetBrains.

the class AndroidPluginOutputParser method parse.

@Override
public boolean parse(@NotNull String line, @NotNull OutputLineReader reader, @NotNull List<Message> messages, @NotNull ILogger logger) throws ParsingFailedException {
    if (line.contains("[DEBUG] ") || line.contains("[INFO] ")) {
        // Ignore 'debug' and 'info' messages.
        return false;
    }
    if (IGNORED_MESSAGE_PATTERN.matcher(line).matches()) {
        return false;
    }
    // pattern is type|path|message
    String[] segments = line.split("\\|", SEGMENT_COUNT);
    if (segments.length == SEGMENT_COUNT) {
        Message.Kind kind = Message.Kind.findIgnoringCase(segments[0], Message.Kind.ERROR);
        String path = segments[1];
        if (StringUtil.isEmpty(path)) {
            return false;
        }
        String msg = StringUtil.notNullize(segments[2]);
        // The SourceFile description is the Gradle path of the project.
        messages.add(new Message(kind, msg.trim(), new SourceFilePosition(new SourceFile(path.trim()), SourcePosition.UNKNOWN)));
        return true;
    }
    return false;
}
Also used : SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) Message(com.android.ide.common.blame.Message) SourceFile(com.android.ide.common.blame.SourceFile)

Example 3 with SourceFile

use of com.android.ide.common.blame.SourceFile in project atlas by alibaba.

the class AwbXmlProcessor method getLayoutXmlProcessor.

public static LayoutXmlProcessor getLayoutXmlProcessor(AppVariantContext appVariantContext, AwbBundle awbBundle, DataBindingBuilder dataBindingBuilder) {
    File resourceBlameLogDir = appVariantContext.getAwbBlameLogFolder(awbBundle);
    // if (!resourceBlameLogDir.exists()) {
    // resourceBlameLogDir = appVariantContext.getScope().getResourceBlameLogDir();
    // }
    final MergingLog mergingLog = new MergingLog(resourceBlameLogDir);
    LayoutXmlProcessor layoutXmlProcessor = new LayoutXmlProcessor(awbBundle.getPackageName(), dataBindingBuilder.createJavaFileWriter(appVariantContext.getAwbClassOutputForDataBinding(awbBundle)), // appVariantContext.getVariantData().getType() == VariantType.LIBRARY,
    new LayoutXmlProcessor.OriginalFileLookup() {

        @Override
        public File getOriginalFileFor(File file) {
            SourceFile input = new SourceFile(file);
            SourceFile original = mergingLog.find(input);
            // it is not what we want so we alter the response.
            return original == input ? input.getSourceFile() : original.getSourceFile();
        }
    });
    return layoutXmlProcessor;
}
Also used : MergingLog(com.android.ide.common.blame.MergingLog) SourceFile(com.android.ide.common.blame.SourceFile) SourceFile(com.android.ide.common.blame.SourceFile) File(java.io.File) LayoutXmlProcessor(android.databinding.tool.LayoutXmlProcessor)

Example 4 with SourceFile

use of com.android.ide.common.blame.SourceFile in project android by JetBrains.

the class ManifestUtils method getActionLocation.

@NotNull
static SourceFilePosition getActionLocation(@NotNull Module module, @NotNull Actions.Record record) {
    SourceFilePosition sourceFilePosition = record.getActionLocation();
    SourceFile sourceFile = sourceFilePosition.getFile();
    File file = sourceFile.getSourceFile();
    SourcePosition sourcePosition = sourceFilePosition.getPosition();
    if (file != null && !SourcePosition.UNKNOWN.equals(sourcePosition)) {
        VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
        assert vFile != null;
        Module fileModule = ModuleUtilCore.findModuleForFile(vFile, module.getProject());
        if (fileModule != null && !fileModule.equals(module)) {
            MergedManifest manifest = MergedManifest.get(fileModule);
            Document document = manifest.getDocument();
            assert document != null;
            Element root = document.getDocumentElement();
            assert root != null;
            int startLine = sourcePosition.getStartLine();
            int startColumn = sourcePosition.getStartColumn();
            Node node = PositionXmlParser.findNodeAtLineAndCol(document, startLine, startColumn);
            if (node == null) {
                Logger.getInstance(ManifestPanel.class).warn("Can not find node in " + fileModule + " for " + sourceFilePosition);
            } else {
                List<? extends Actions.Record> records = getRecords(manifest, node);
                if (!records.isEmpty()) {
                    return getActionLocation(fileModule, records.get(0));
                }
            }
        }
    }
    return sourceFilePosition;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MergedManifest(com.android.tools.idea.model.MergedManifest) Actions(com.android.manifmerger.Actions) XmlNode(com.android.manifmerger.XmlNode) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SourcePosition(com.android.ide.common.blame.SourcePosition) SourceFile(com.android.ide.common.blame.SourceFile) Module(com.intellij.openapi.module.Module) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) SourceFile(com.android.ide.common.blame.SourceFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with SourceFile

use of com.android.ide.common.blame.SourceFile 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()));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) MavenCoordinates(com.android.builder.model.MavenCoordinates) AndroidLibrary(com.android.builder.model.AndroidLibrary) SourcePosition(com.android.ide.common.blame.SourcePosition) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) SourceFile(com.android.ide.common.blame.SourceFile) Module(com.intellij.openapi.module.Module) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFile(com.android.ide.common.blame.SourceFile) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File)

Aggregations

SourceFile (com.android.ide.common.blame.SourceFile)8 SourcePosition (com.android.ide.common.blame.SourcePosition)6 File (java.io.File)6 SourceFilePosition (com.android.ide.common.blame.SourceFilePosition)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Message (com.android.ide.common.blame.Message)3 XmlFile (com.intellij.psi.xml.XmlFile)3 Actions (com.android.manifmerger.Actions)2 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)2 Module (com.intellij.openapi.module.Module)2 Matcher (java.util.regex.Matcher)2 LayoutXmlProcessor (android.databinding.tool.LayoutXmlProcessor)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 MergingLog (com.android.ide.common.blame.MergingLog)1 XmlNode (com.android.manifmerger.XmlNode)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)1 MergedManifest (com.android.tools.idea.model.MergedManifest)1 IdeActions (com.intellij.openapi.actionSystem.IdeActions)1