Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS plugin #5

Merged
merged 47 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c865d2c
Swift plugin layout setup + conflicts (DDC)
Jun 10, 2022
c79fde9
Swift plugin: sensor and visitor base impl
Jun 10, 2022
d628bb9
First rule implementation
Jun 10, 2022
b4bbf5a
Swift plugin refactored to iOS plugin and modularized
Jul 4, 2022
dbcf822
iOs plugin: added CONTRIBUTING doc
Jul 4, 2022
5315c77
Merge branch 'main' into insideapp-oss_feature_swift-plugin
dedece35 Nov 28, 2022
44b99cb
Use Docker for local deployment
Dec 13, 2022
5a1bef2
README update
Dec 13, 2022
7cdf263
iOS: renamed commons module to commons-ios
Dec 13, 2022
fe0b55f
iOS: updated pom parent
Dec 13, 2022
7b08483
iOS: moved project folder + plugged to pom hierarchy
Dec 13, 2022
7ebe25b
iOS: SonarQube API 8.7 support
Dec 13, 2022
f8f7beb
iOS: renamed commons package to avoid name collisions
Dec 13, 2022
4e7688b
iOS: removed unnecessary synchonized
Dec 13, 2022
4f960d3
iOS: fixed docker-compose not picking the right plugin archive
Jan 1, 2023
df2823f
iOS: removed ios plugin version for now
Jan 1, 2023
5948ff4
iOS: refactored package names
Jan 1, 2023
ad2cddd
iOS: added prefix on module artifacts
Jan 2, 2023
a485d9a
iOS: documentation update
Jan 2, 2023
596949b
iOS: removed redundant properties from pom
Jan 2, 2023
adbadca
Merge branch 'main' into insideapp-oss_feature_swift-plugin
Jan 20, 2023
f1fedc1
iOS: removed redundant maven-compiler-plugin from pom.xml
Jan 20, 2023
5250d32
iOS: removed unnecessary jacoco version from pom.xml
Jan 20, 2023
1bf1645
iOS: replaced sonar.version by sonarqube.version (from parent) in pom…
Jan 20, 2023
381276e
iOS: removed hardcoded project version from pom.xml files
Jan 20, 2023
2230955
iOS: removed unnecessary version for sonar-packaging-maven-plugin in …
Jan 20, 2023
861c94f
iOS: updated plugin configuration in pom.xml
Jan 20, 2023
b1bd04e
iOS: updated SonarQube image version to 9.8 in docker-compose
Jan 20, 2023
cf99ae0
Merge branch 'main' into insideapp-oss_feature_swift-plugin
Jan 20, 2023
10edd51
iOS: updated parent pom version to 0.1.1-SNAPSHOT
Jan 20, 2023
f51c411
iOS: fixed SonarQube smell
Jan 20, 2023
743e664
iOs: code coverage configuration
Jan 20, 2023
21dfa22
iOS: exclude antlr generated sources from SonarQube analysis
Jan 20, 2023
af64d16
iOS: excluded antlr generated files from sonar coverage
Jan 20, 2023
3aff0a4
iOS: antlr generated sources exclusion from sonar analysis attempt
Jan 20, 2023
e6576e3
Removed sonar.exclusion from GH action, and put it in parent pom (so …
Jan 20, 2023
1687c0f
iOS: code cleanup + added unit tests
Jan 20, 2023
2b78b6b
iOS: added unit tests
Jan 20, 2023
6dd0649
iOS: more unit tests
Jan 20, 2023
d54080a
iOS: fixed plugin packaging
Jan 24, 2023
1aa0eef
iOS: added source file headers (with https://mycila.carbou.me/license…
Jan 24, 2023
66fac5f
iOS: added more tests and javadoc on first rule
Jan 24, 2023
5feba25
iOS: poms clean up
Jan 24, 2023
7d61f04
iOS: source code header update + renamed parent pom org
Jan 26, 2023
b159569
iOS: docker-compose cleanup
Feb 2, 2023
9a0513e
iOS: added tags support on rules
Feb 3, 2023
430a3c8
iOS: added support for separated html files for rule descriptions
Feb 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -e -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode-mobile -Dsonar.exclusions=**/codenarc-converter/**,**/*.groovy,**/android-plugin/src/test/**,**/*.dummy
run: mvn -e -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode-mobile
2 changes: 1 addition & 1 deletion android-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<dependency>
<groupId>org.codenarc</groupId>
<artifactId>CodeNarc</artifactId>
<version>2.2.3</version>
<version>2.2.0</version>
zippy1978 marked this conversation as resolved.
Show resolved Hide resolved
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion codenarc-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<name>Sonar CodeNarc Converter</name>

<properties>
<codenarc.version>2.2.3</codenarc.version>
<codenarc.version>2.2.0</codenarc.version>
zippy1978 marked this conversation as resolved.
Show resolved Hide resolved
<auto.version>1.8.2</auto.version>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
Expand Down
50 changes: 50 additions & 0 deletions ios-plugin/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Contributing

## General information

The iOS plugin is split into 3 different modules:
- `swift-lang` is for Swift source files parsing and checks
- `commons-ios` gather common parsing utils and models that can be reused to implement other languages support
- `sonar-ios-plugin` the actual SonarQube plugin declaration

Swift file parser is build using the [ANTLR](https://www.antlr.org/) parser generator.

The generated parser source files are located into `swift-lang/src/main/java/io/ecocode/ios/swift/antlr/generated`. those source files should not be edited manually.

When necessary (in case of Swift language syntax upgrade for example), those source files should be re-generated with ANTLR.

## Adding new rules

When adding a new rule, the following steps are required:
- Declare the rule
- Implement a check
- Add the check to the visitor

### Declaring the rule

The new rule must be declared into 2 files :
- `swift-lang/src/resources/ecocode-swift_profile.json`
- `swift-lang/src/resources/ecocode-swift-rules.json`

> Note: if a rich HTML description of the rule is required. Use a separated .html file put aside `swift-lang/src/resources/ecocode-swift-rules.json` and name it after the rule key. For example: `RULE_KEY.html`. When an specific HTML description file is provided for a rule, it overrides the description provided into the `ecocode-swift-rules.json`.

### Implementing a check

In order to implement a check for the rule, create a Check class inherited from `RuleCheck` in `src/main/java/io/ecocode/ios/swift/checks`.

Have a look at `swift-lang/src/main/java/io/ecocode/ios/swift/checks/idleness/IdleTimerDisabledCheck` to learn more about the implementation.

### Adding check to the visitor

Once implemented, add the new check to `swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftVisitor`.

For example:

```java
public EcoCodeSwiftVisitor() {
...
// Load checks
checks.add(new MyNewCheck());
...
}
```
2 changes: 2 additions & 0 deletions ios-plugin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM sonarqube:9.8-community
ADD https://github.com/insideapp-oss/sonar-apple/releases/download/0.3.0/sonar-apple-plugin-0.3.0.jar /opt/sonarqube/extensions/plugins/sonar-apple-plugin-0.3.0.jar
165 changes: 165 additions & 0 deletions ios-plugin/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
3 changes: 3 additions & 0 deletions ios-plugin/NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ecoCode SonarQube plugin
Copyright (C) 2020-2021 Snapp' - Université de Pau et des Pays de l'Adour
mailto: [email protected]
31 changes: 31 additions & 0 deletions ios-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ecoCode iOS SonarQube plugin

ecoCode iOS SonarQube plugin is an "eco-responsibility" static code analyzer for iOS projects written in Swift. Its aim is to detect code smells indicating how the source code can be improved to reduce their environmental and social impact.

## Requirements

- Java JDK 11+
- Maven 3.8 or later
- A local SonarQube instance for local testing

## Main commands

#### Local deployment using Docker

**This implies to have a machine ready to run containerized applications.** Please refer to Docker documentation: https://www.docker.com/.

The project uses a 8.6 docker instance of SonarQube to run.

Pop docker containers by using:

```bash
docker-compose up --build -d && docker ps
```

The tests instance of SonarQube with the plugin will then be available at: http://localhost:9000

#### Packaging

```bash
$ mvn package
```
33 changes: 33 additions & 0 deletions ios-plugin/commons-ios/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.ecocode</groupId>
<artifactId>ios-plugin</artifactId>
<version>0.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ecocode-commons-ios</artifactId>

<dependencies>

<dependency>
<groupId>com.fasterxml.staxmate</groupId>
<artifactId>staxmate</artifactId>
<version>2.4.0</version>
</dependency>

<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.10</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
</dependency>

</dependencies>

</project>
Loading