AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 軟件

vivo 互聯網自研代碼評審 VCR 落地實踐

來源: 責編: 時間:2024-06-27 17:19:23 122觀看
導讀代碼評審是軟件質量保證一種活動,由一個或者多個人對一個程序的部分或者全部源代碼進閱讀理解。一般來說分為作者和評審者兩種角色,作者方提供代碼邏輯的介紹和代碼,評審者則對提供的代碼基于設計,功能性和非功能性等方面

VDb28資訊網——每日最新資訊28at.com

代碼評審是軟件質量保證一種活動,由一個或者多個人對一個程序的部分或者全部源代碼進閱讀理解。一般來說分為作者和評審者兩種角色,作者方提供代碼邏輯的介紹和代碼,評審者則對提供的代碼基于設計,功能性和非功能性等方面認知進行閱讀并提出問題。常見的評審組織形式是有同行評審(Peer Review)和小組檢查 (Team Inspection)兩種方式。VDb28資訊網——每日最新資訊28at.com

在代碼評審中,評審的目的在通過代碼的評審發現潛在的問題,同時分享和表達是代碼評審的重要收獲,我們知道人相同在不同的文化下生產力是不同的,代碼評審是一個工具,工具受文化的影響的同時也影響著文化,最終朝著我們希望的責任共擔、持續改進的方向發展。VDb28資訊網——每日最新資訊28at.com

一、代碼評審演進


VDb28資訊網——每日最新資訊28at.com

4)插件運行調試打包安裝VDb28資訊網——每日最新資訊28at.com

Gradle構建方式進行調試打包安裝VDb28資訊網——每日最新資訊28at.com

運行/調試:runIde 可以選擇Debug模式或者是Run模式VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

打包VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

安裝:可以將打的包發布市場(本地idea配置插件倉庫),從Marketplace搜索插件或者是直接從Settings->plugins->Install->Install Plugin from Disk安裝VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

步驟2:研究Gerrit插件源碼,搞清楚整理開發流程和模塊VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

步驟3:基于Gerrit插件規劃VCR插件模塊,增加clone、branch、mergeRequest、VCR模塊,并對各組件增強VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

步驟4:定制原有流程模塊push,自動化關聯工作項VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com


VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

在使用Git依賴插件之前,先了解一下插件的擴展以及擴展點(Extensions、Extension Points)。VDb28資訊網——每日最新資訊28at.com

Intellij 平臺提供了允許一個插件與其他插件或者 IDE 交互的 extensions 以及 extension points 的概念。VDb28資訊網——每日最新資訊28at.com

  • Extension Points:如果你想要你的插件可以被其他插件使用,那么你必須在你的插件內聲明一個或多個擴展點(extension points)。每個擴展點定義了允許訪問這個點的類或者接口。
  • Extensions:如果你想要你的插件擴展其他插件或者 Intellij 平臺,你必須聲明一個或多個 extensions。

可以在 plugin.xml 中的和塊中定義 extensions 以及 extension points。VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com


VDb28資訊網——每日最新資訊28at.com

plugin.xmlVDb28資訊網——每日最新資訊28at.com

<!--依賴插件包--!><depends>Git4Idea</depends><!—idea第一次打開, 實際上就是訂閱了應用程序打開的事件--><application-components><component><implementation-class>com.demo.intellij.plugin.vcr.push.VcrPushExtension$Proxy</implementation-class></component></application-components>

上述我們看到依賴的Git4Idea 包,如果我們想修改原生的的Git,先看下push依賴包中如何實現的。VDb28資訊網——每日最新資訊28at.com

Git4Idea(plugin.xml)VDb28資訊網——每日最新資訊28at.com

<extensions defaultExtensionNs="com.intellij"><pushSupport implementation="git4idea.push.GitPushSupport"/>...</extensions>

intellij-dvcs.jar(plugin.xml)VDb28資訊網——每日最新資訊28at.com

<extensionPoints>  <extensionPoint name="pushSupport"                  interface="com.intellij.dvcs.push.PushSupport"                  area="IDEA_PROJECT"                  dynamic="true"/>....</extensionPoints>

從上述可看到,Git4Idea 的GitPushSupport擴展實現push的功能點,接下來我們主要對GitPushSupport進行javassist字節碼修改以達到擴展git push組件能力。VDb28資訊網——每日最新資訊28at.com

擴展使用GitPushSupport之前,需要將需要的類進行裝載至GitPlugin中,然后再對GitPushSupport進行字節碼改造,至此對git Push原生插件頁進行改造。VDb28資訊網——每日最新資訊28at.com


VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

步驟5:使用樹狀列表模式,展示一次push請求VCR提交內容及多個CR情況VDb28資訊網——每日最新資訊28at.com

主要是實現JTreeTable,對VCR與CR進行管理。VDb28資訊網——每日最新資訊28at.com

一次評審請求VCR包含所有CR的提交變更記錄,可針對該變更記錄進行代碼評審,單個CR也可以進行評審。VDb28資訊網——每日最新資訊28at.com


VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com


VDb28資訊網——每日最新資訊28at.com

步驟6:展示變更文件視圖及定制評論展示模塊,精準定位代碼VDb28資訊網——每日最新資訊28at.com

代碼評審主要根據編輯器獲取代碼行及位置,評論可精準定位到代碼行。VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

1)changeBrowser變更視圖展示VCR變更文件信息VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

2)雙擊文件,diff視圖展示inline和side-by-side兩種代碼差異VDb28資訊網——每日最新資訊28at.com

聲明擴展,針對擴展類進行定制化改造。VDb28資訊網——每日最新資訊28at.com

plugin.xmlVDb28資訊網——每日最新資訊28at.com

<diff.DiffTool implementatinotallow="com.demo.intellij.plugin.vcr.ui.diff.VcrCommentsDiffTool$Proxy"/>


VDb28資訊網——每日最新資訊28at.com

圖片VDb28資訊網——每日最新資訊28at.com

3)添加代碼塊評論,定位代碼塊VDb28資訊網——每日最新資訊28at.com

AddCommentAction.javaVDb28資訊網——每日最新資訊28at.com

public class AddCommentAction extends AnAction implements DumbAware {public AddCommentAction(String label,                        Icon icon,                        CommentsDiffTool commentsDiffTool,                                         Editor editor,                         List<CommentInfo> fileComments                        ....                        ) {    super(label, null, icon);}private CommentInput createComment() {//獲取用戶選擇代碼位置位置//行的情況下,默認是開頭和行結束  得到光標的位置caretModel.getOffset();/*取到插字光標模式對象 CaretModel caretModel = editor.getCaretModel();得到光標的位置int caretOffset = caretModel.getOffset();//得到一行開始和結束的地方int lineNum = document.getLineNumber(caretOffset);int lineStartOffset = document.getLineStartOffset(lineNum);int lineEndOffset = document.getLineEndOffset(lineNum);獲取一行內容String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));*/Document document = editor.getDocument();int lineNum  = document.getLineNumber(editor.getCaretModel().getOffset()) ;int lineStartOffset = document.getLineStartOffset(lineNum);int lineEndOffset = document.getLineEndOffset(lineNum);String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));.....}}

所有評論展示列表如何精準定位代碼VDb28資訊網——每日最新資訊28at.com

SafeHtmlHistoryComments.javaVDb28資訊網——每日最新資訊28at.com

public class SafeHtmlHistoryComments extends JPanel {    private Iterable<CommentInfo> fileComments;    private List<CommentInfo> commentInfos = new ArrayList<>();    private CommentInfo currentCommentInfo;    private SelectedComment selectedComment;    private SelectedComment operatorSelectedComment;    private Editor editor;    public SafeHtmlHistoryComments(Editor editor,Iterable<CommentInfo> fileComments, Comment selectedComment) {        super(new BorderLayout());        ....      HistoryCommentListPanel historyCommentListPanel = new HistoryCommentListPanel(fileComments);               //雙擊table某行觸發代碼定位        historyCommentListPanel.addTableMouseDoubleHit(new Consumer<CommentInfo>() {            @Override            public void consume(CommentInfo commentInfo) {                 codeTextHit(editor,commentInfo);            }        });    }    /**     * 定位代碼     * @param editor     * @param commentInfo     */    private static void codeTextHit(Editor editor, CommentInfo commentInfo) {        SelectionModel selectionModel = editor.getSelectionModel();        // 優化:如果文件修改過了,則不進行選中操作,換為提示        if (null != commentInfo.startIndex && null != commentInfo.endIndex && commentInfo.startIndex != 0 && commentInfo.endIndex != 0) {            editor.getCaretModel().moveToOffset(commentInfo.endIndex);            selectionModel.setSelection(commentInfo.startIndex, commentInfo.endIndex);        } else if (null != commentInfo.line && commentInfo.line != 0) {            int lineNum = commentInfo.line - 1;            editor.getCaretModel().moveToOffset(lineNum);            CharSequence charsSequence = editor.getMarkupModel().getDocument().getCharsSequence();            if(null!=commentInfo.range) {                RangeUtils.Offset offset = RangeUtils.rangeToTextOffset(charsSequence, commentInfo.range);                selectionModel.setSelection(offset.start, offset.end);            }else{                Document document = editor.getDocument();                int lineStartOffset = document.getLineStartOffset(lineNum);                int lineEndOffset = document.getLineEndOffset(lineNum);                selectionModel.setSelection(lineStartOffset, lineEndOffset);            }        }        editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);    }....}

六、未來展望

6.1 自動化代碼評審

  1. 代碼提交評審或代碼合并之前,先自動化檢查(Sonar/安全掃描)快速發現并糾正潛在問題,檢查成功后提交評審。
  2. 代碼評審通過之后,結合流水線,自定義部署構建策略,實現快速迭代。
  3. 自動匯聚測試報告,根據評審問題類型進行分類,不斷改進Sonar檢查規則,從而形成良性循環。

6.2智能化代碼評審

  1. 提交代碼評審之后,通過AI大模型對代碼進行綜合評價,并給出建議。
  2. 通過智能代碼評審,產生評審報告,并進行智能化分析。

本文鏈接:http://www.tebozhan.com/showinfo-26-96989-0.htmlvivo 互聯網自研代碼評審 VCR 落地實踐

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: React Query 的 useQuery 竟也內置了分頁查詢支持!

下一篇: 掉了兩根頭發后,我悟了!Vue3的Scoped原來是這樣避免樣式污染

標簽:
  • 熱門焦點
Top