Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

preloz to do hezkeho ceskeho akademickeho textu Solution Architecture The check has been…

  1. User

    preloz to do hezkeho ceskeho akademickeho textu

    Solution Architecture The check has been designed and implemented in Java programming language. It is a project that acts as an extension to the SonarQube, that means it cannot run without being instantiated and executed from SonarQube. That means during the analysis the SonarQube executes its own checks against the code and there is one part of the process when extensions, which were defined to be used on the project, are being executed as well. Hence at that point of analysis our extension gets the time to execute analysis and pass results back to the SonarQube. There is also second time during post analysis is when our extension gets control, therefore we can also make some conclusions on the data we have collected in the first run. 6.1 Implementation of the check As was already slightly described, the tool that we are using enables to add extensions to the checking process in order to enhance analysis about custom information and customize already acquired results. That is the basis for our solution as it is created as a extension to the tool. Furthermore our solution is executed twice, at first during the analysis of a source code and second time for the post analysis of our own results and to send back results of our analysis back to the SonarQube. Analysis with our solution looks like nothing at all and in the interface of the check are shown new information. 6.2 Intermediate data storage Stores scores to every class and respective parts of design patterns are stored in custom object that will be used during the second part of the analysis. This object essentially contains all retrieved classes alongside with the collection of design pattern part attributes and some attributes to ease the work- such as name of the class. This object needed to be created in order to be able to store 74 DesignPatternsJavaSensor DesignPatternsJavaPlugin define(Context) describe(SensorDescriptor) execute(SensorContext) forFileAddIssue(InputFile, RequirementForFile) forFileAddMeasurements(InputFile, PatternPartAttributeInterface) generateMetrics(Iterable) StaticMatrix cuteStaticThing: HashMap f ilesWithContext: HashMap currentRequirementForFile: RequirementForFile allRequirementForFile: HashMap relationStrategies: Map patternVisitorInterfaces: List currentPattern: int currentClassTree: ClassTree pvf: PatternCreationFactory analyzeAllPatternVisitors(Tree) calculateAllMetrics() refreshPatternVisitors() obtainAllPatternPartAttributes() addPatternPartAttributeToList(ClassTree, PatternPartAttributeInterface) startNewRequirementForFile(String) insertContextToNewRequirementForFile(JavaFileScannerContext) insertCurrentJavaCheckToNewRequirementForFile(AstVisitor) insertCurrentClassToNewRequirementForFile() PatternCreationFactory getPatternVisitorz(): List getPatternRelations(): Map getPatternVisitors(): Object[] RequirementForFile addPatternPartAttribute(PatternPartAttributeInterface) PatternVisitorInterface visit() get(): PatternPartAttributeInterface Obrázek 6.1: Static Matrix And Relations AstVisitor RULE_KEY: String context: JavaFileScannerContext scanFile(JavaFileScannerContext) visit() RelationsStrategyInterface calculate(attributes, relatedAttributes, String) forAttribute(): String our data, for otherwise we might have chosen writing all the information to the specific classes in SonarQube’s interface, or storing the data as the file, for example in json format. Next image describes a way how the application behaves during Sensor execution- the main part is that the Sensor is being executed from SonarQube’s context and therefore I have no possibility of passing any data into that class. Hence this is the very reason why does the StaticMatrix class exists, since that one stores data in easy to obtain manner throughout the whole runtime of the application. For otherwise it might be a bit more complicated to pass data between the visitors and Relations used by this sensor. This assumption is based on examination of the SonarQube that there seems to be no straightforward way through which the data might be stored on the server and then obtained back on the client in between the analysis. Hence I used the fact that the analysis runs locally and that the analysis should be done in one go and created this Static Matrix[6.1] that acts as data storage.

  2. Assistant

    Architektura Řešení

    Kontrola byla navržena a implementována v programovacím jazyce Java. Jedná se o projekt, který funguje jako rozšíření nástroje SonarQube, což znamená, že nemůže být spuštěn bez jeho instance a vykonání z prostředí SonarQube. Během analýzy SonarQube provádí své vlastní kontroly proti kódu a během procesu nastává bod, kdy jsou vykonávány i rozšíření definované pro tento projekt. V tomto okamžiku analýzy dostane naše rozšíření prostor k vykonání své analýzy a vrácení výsledků zpět do SonarQube. Během post-analýzy je naše rozšíření spuštěno podruhé, což umožňuje vyhodnotit shromážděná data z prvního spuštění.

    6.1 Implementace Kontroly

    Jak bylo již krátce popsáno, nástroj, který používáme, umožňuje přidávat rozšíření do procesu kontroly s cílem rozšířit analýzu o vlastní informace a přizpůsobit již získané výsledky. Toto je základ našeho řešení, jelikož je vytvořeno jako rozšíření nástroje. Naše řešení je spuštěno dvakrát: poprvé během analýzy zdrojového kódu a podruhé pro post-analýzu vlastních výsledků a jejich odeslání zpět do SonarQube. Analýza s naším řešením probíhá neznatelně a v rozhraní kontroly se zobrazují nové informace.

    6.2 Dočasné Ukládání Dat

    Ukládá skóre pro každou třídu a příslušné části návrhových vzorů jsou uloženy do vlastního objektu, který bude použit během druhé části analýzy. Tento objekt v podstatě obsahuje všechny načtené třídy spolu se sbírkou atributů částí návrhových vzorů a některými atributy, které usnadňují práci – jako je například název třídy. Tento objekt bylo nutné vytvořit, aby bylo možné ukládat data. Pokud bychom to neudělali, mohli bychom volit mezi ukládáním všech informací do specifických tříd v rozhraní SonarQube nebo ukládáním dat do souboru, například ve formátu JSON.

    Následující obrázek popisuje, jak se aplikace chová během vykonávání senzoru – hlavní částí je, že senzor je vykonáván z kontextu SonarQube, a proto nemám možnost předat žádná data do této třídy. Proto existuje třída StaticMatrix, která ukládá data snadno přístupným způsobem po celou dobu běhu aplikace. Jinak by bylo o něco složitější předat data mezi návštěvníky a relace použité tímto senzorem. Tento předpoklad je založen na zkoumání SonarQube, kde se zdá, že neexistuje žádný jednoznačný způsob, jak by mohly být data uložena na serveru a následně získána zpět na klientovi mezi analýzami. Proto jsem využil faktu, že analýza probíhá lokálně a měla by být provedena najednou, a vytvořil tuto Statickou matici [6.1], která slouží jako úložiště dat.

    Obrázek 6.1: Statická Matice a Vztahy