)jsonRule.get("tags"));
+ repositoryRules.add(repositoryRule);
+ }
+ }
+ return repositoryRules;
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/antlr/AntlrContextTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/antlr/AntlrContextTest.java
new file mode 100644
index 00000000..20bbf2e5
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/antlr/AntlrContextTest.java
@@ -0,0 +1,58 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.antlr;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.sonar.api.batch.fs.InputFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AntlrContextTest {
+
+ @Test
+ public void loadFromStreams() throws IOException {
+
+ AntlrContext context = new AntlrContext() {
+ @Override
+ public void loadFromStreams(InputFile inputFile, InputStream file, InputStream linesStream, Charset charset) throws IOException {
+
+ SourceLine[] lines = new SourceLine[1];
+ lines[0] = new SourceLine(0, 0, 0, 0);
+ this.setLines(lines);
+ this.setRoot(null);
+ this.setStream(null);
+ this.setFile(null);
+ }
+ };
+
+ // Load an empty content as loadFromStreams is mocked in test
+ context.loadFromStreams(null, IOUtils.toInputStream("", Charset.defaultCharset()),
+ IOUtils.toInputStream("", Charset.defaultCharset()), Charset.defaultCharset());
+
+ assertThat(context.getLines()).hasSize(1);
+ assertThat(context.getRoot()).isNull();
+ assertThat(context.getStream()).isNull();
+ assertThat(context.getFile()).isNull();
+
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/antlr/SourceLinesProviderTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/antlr/SourceLinesProviderTest.java
new file mode 100644
index 00000000..2e47ffe9
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/antlr/SourceLinesProviderTest.java
@@ -0,0 +1,36 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.antlr;
+
+import org.junit.Test;
+import java.nio.charset.Charset;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class SourceLinesProviderTest {
+
+ private static final String MAIN_SRC = "/antlr/main.swift";
+
+ @Test
+ public void getLines() {
+
+
+ SourceLinesProvider provider = new SourceLinesProvider();
+ SourceLine[] lines = provider.getLines(this.getClass().getResourceAsStream(MAIN_SRC), Charset.defaultCharset());
+ assertThat(lines).hasSize(6);
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/checks/RuleCheckTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/checks/RuleCheckTest.java
new file mode 100644
index 00000000..a98e7372
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/checks/RuleCheckTest.java
@@ -0,0 +1,83 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.checks;
+
+import io.ecocode.ios.antlr.AntlrContext;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.junit.Test;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.api.batch.sensor.internal.SensorContextTester;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RuleCheckTest {
+
+ private static final String TEST_ROOT = "src/test/resources";
+ private static final int LINE_COUNT = 100;
+
+ @Test
+ public void fillContext() {
+
+ AntlrContext antlrContext = new AntlrContext() {
+ @Override
+ public void loadFromStreams(InputFile inputFile, InputStream file, InputStream linesStream, Charset charset) throws IOException {
+ }
+
+ @Override
+ public InputFile getFile() {
+ return new TestInputFileBuilder("", "main.swift")
+ .setType(InputFile.Type.MAIN)
+ .setLines(LINE_COUNT)
+ .setOriginalLineEndOffsets(new int[LINE_COUNT])
+ .setOriginalLineStartOffsets(new int[LINE_COUNT])
+ .setModuleBaseDir(Paths.get(TEST_ROOT))
+ .setLanguage("swift").build();
+ }
+
+ @Override
+ public int[] getLineAndColumn(int global) {
+ return new int[] {1, 1};
+ }
+ };
+
+ RuleCheck ruleCheck = new RuleCheck("rule1", "/rules/rules.json", "repositoryKey") {
+
+ @Override
+ public void apply(ParseTree tree) {
+ this.recordIssue(this.ruleId, 0);
+ }
+ };
+
+
+ ruleCheck.apply(null);
+
+ SensorContextTester sensorContext = SensorContextTester.create(new File(TEST_ROOT));
+ sensorContext.fileSystem().add(antlrContext.getFile());
+ ruleCheck.fillContext(sensorContext, antlrContext);
+
+ assertThat(sensorContext.allIssues()).hasSize(1);
+
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/JSONRulesDefinitionTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/JSONRulesDefinitionTest.java
new file mode 100644
index 00000000..25804455
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/JSONRulesDefinitionTest.java
@@ -0,0 +1,47 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.rules;
+
+import io.ecocode.ios.rules.JSONRulesDefinition;
+import org.junit.Test;
+import org.sonar.api.server.rule.RulesDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JSONRulesDefinitionTest {
+
+ @Test
+ public void define() {
+
+ JSONRulesDefinition rulesDefinition = new JSONRulesDefinition("rep_key", "rep_name", "lang", "/rules/rules.json") {};
+
+
+ RulesDefinition.Context context = new RulesDefinition.Context();
+ rulesDefinition.define(context);
+
+ RulesDefinition.Repository repository = context.repository("rep_key");
+ assertThat(repository).isNotNull();
+ assertThat(repository.name()).isEqualTo("rep_name");
+ assertThat(repository.language()).isEqualTo("lang");
+ assertThat(repository.rules()).isNotEmpty();
+ assertThat(repository.rules().get(0).tags()).isNotEmpty();
+ assertThat(repository.rules().get(0).htmlDescription()).isEqualTo("Test description from HTML file
");
+ assertThat(repository.rules().get(1).htmlDescription()).isEqualTo("This is rule 2.");
+
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/ReportIssueRecorderTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/ReportIssueRecorderTest.java
new file mode 100644
index 00000000..8e2a57e0
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/ReportIssueRecorderTest.java
@@ -0,0 +1,61 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.rules;
+
+import io.ecocode.ios.checks.ReportIssue;
+import io.ecocode.ios.checks.ReportIssueRecorder;
+import org.junit.Test;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.api.batch.sensor.internal.SensorContextTester;
+
+import java.io.File;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.assertj.core.api.Java6Assertions.assertThat;
+
+public class ReportIssueRecorderTest {
+
+ private static final String TEST_ROOT = "src/test/resources";
+ private static final String TEST_FILENAME = "swift/main.swift";
+
+ @Test
+ public void recordIssues() {
+
+ SensorContextTester context = SensorContextTester.create(new File(TEST_ROOT));
+ DefaultInputFile testFile = new TestInputFileBuilder("", TEST_FILENAME)
+ .setLanguage("swift")
+ .setLines(10)
+ .setOriginalLineEndOffsets(new int[10])
+ .setOriginalLineStartOffsets(new int[10])
+ .setModuleBaseDir(Paths.get(TEST_ROOT))
+ .build();
+ context.fileSystem().add(testFile);
+
+ List issues = new ArrayList<>();
+ issues.add(new ReportIssue("ruleId", "message", testFile.path().toString(), 3));
+
+ ReportIssueRecorder recorder = new ReportIssueRecorder(context);
+ recorder.recordIssues(issues, "TestRepo");
+
+ assertThat(context.allIssues()).hasSize(1);
+
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/ReportIssueTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/ReportIssueTest.java
new file mode 100644
index 00000000..3f0fb3d7
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/ReportIssueTest.java
@@ -0,0 +1,42 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.rules;
+
+import io.ecocode.ios.checks.ReportIssue;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ReportIssueTest {
+
+ @Test
+ public void equals() {
+ ReportIssue issue1 = new ReportIssue("1", "msg", "/test/path", 20);
+ ReportIssue issue2 = new ReportIssue("1", "msg", "/test/path", 20);
+
+ assertThat(issue1).isEqualTo(issue2);
+ }
+
+ @Test
+ public void notEqual() {
+ ReportIssue issue1 = new ReportIssue("1", "msg", "/test/path", 20);
+ ReportIssue issue2 = new ReportIssue("2", "msg", "/test/path", 20);
+
+ assertThat(issue1).isNotEqualTo(issue2);
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/RepositoryRuleParserTest.java b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/RepositoryRuleParserTest.java
new file mode 100644
index 00000000..24ee0f42
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/java/io/ecocode/ios/rules/RepositoryRuleParserTest.java
@@ -0,0 +1,60 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.rules;
+
+import io.ecocode.ios.rules.RepositoryRule;
+import io.ecocode.ios.rules.RepositoryRuleParser;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RepositoryRuleParserTest {
+
+ @Test
+ public void parse() throws Throwable {
+
+ RepositoryRuleParser parser = new RepositoryRuleParser();
+ List repositoryRules = parser.parse("/rules/rules.json");
+ assertThat(repositoryRules).hasSize(2);
+
+ RepositoryRule repositoryRule1 = repositoryRules.get(0);
+ assertThat(repositoryRule1.getKey()).isEqualTo("rule1");
+ assertThat(repositoryRule1.getName()).isEqualTo("Rule 1");
+ assertThat(repositoryRule1.getDescription()).isEqualTo("This is rule 1.");
+ assertThat(repositoryRule1.getSeverity()).isEqualTo("MINOR");
+ assertThat(repositoryRule1.getDebt()).isNotNull();
+ assertThat(repositoryRule1.getDebt().getFunction()).isEqualTo("CONSTANT_ISSUE");
+ assertThat(repositoryRule1.getDebt().getOffset()).isEqualTo("5min");
+ assertThat(repositoryRule1.getTags()).hasSize(2);
+ assertThat(repositoryRule1.getTags().get(0)).isEqualTo("tag1");
+ assertThat(repositoryRule1.getTags().get(1)).isEqualTo("tag2");
+
+ RepositoryRule repositoryRule2 = repositoryRules.get(1);
+ assertThat(repositoryRule2.getKey()).isEqualTo("rule2");
+ assertThat(repositoryRule2.getName()).isEqualTo("Rule 2");
+ assertThat(repositoryRule2.getDescription()).isEqualTo("This is rule 2.");
+ assertThat(repositoryRule2.getSeverity()).isEqualTo("MAJOR");
+ assertThat(repositoryRule2.getDebt()).isNotNull();
+ assertThat(repositoryRule2.getDebt().getFunction()).isEqualTo("CONSTANT_ISSUE");
+ assertThat(repositoryRule2.getDebt().getOffset()).isEqualTo("15min");
+ assertThat(repositoryRule2.getTags()).hasSize(1);
+ assertThat(repositoryRule2.getTags().get(0)).isEqualTo("tag1");
+ }
+}
diff --git a/ios-plugin/commons-ios/src/test/resources/antlr/main.swift b/ios-plugin/commons-ios/src/test/resources/antlr/main.swift
new file mode 100644
index 00000000..d1b6be4c
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/resources/antlr/main.swift
@@ -0,0 +1,6 @@
+@main
+struct App {
+ static func main() {
+ print("Starting.")
+ }
+}
\ No newline at end of file
diff --git a/ios-plugin/commons-ios/src/test/resources/rule1.html b/ios-plugin/commons-ios/src/test/resources/rule1.html
new file mode 100644
index 00000000..de83f7f6
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/resources/rule1.html
@@ -0,0 +1 @@
+Test description from HTML file
\ No newline at end of file
diff --git a/ios-plugin/commons-ios/src/test/resources/rules/rules.json b/ios-plugin/commons-ios/src/test/resources/rules/rules.json
new file mode 100644
index 00000000..7cba46dc
--- /dev/null
+++ b/ios-plugin/commons-ios/src/test/resources/rules/rules.json
@@ -0,0 +1,29 @@
+[
+ {
+ "key": "rule1",
+ "name": "Rule 1",
+ "severity": "MINOR",
+ "description": "This is rule 1.",
+ "debt": {
+ "function": "CONSTANT_ISSUE",
+ "offset": "5min"
+ },
+ "tags": [
+ "tag1",
+ "tag2"
+ ]
+ },
+ {
+ "key": "rule2",
+ "name": "Rule 2",
+ "severity": "MAJOR",
+ "description": "This is rule 2.",
+ "debt": {
+ "function": "CONSTANT_ISSUE",
+ "offset": "15min"
+ },
+ "tags": [
+ "tag1"
+ ]
+ }
+]
diff --git a/ios-plugin/docker-compose.yml b/ios-plugin/docker-compose.yml
new file mode 100644
index 00000000..20ee4878
--- /dev/null
+++ b/ios-plugin/docker-compose.yml
@@ -0,0 +1,45 @@
+version: "3.3"
+services:
+ sonar:
+ build:
+ dockerfile: Dockerfile
+ ports:
+ - "9000:9000"
+ networks:
+ - sonarnet
+ depends_on:
+ - db
+ environment:
+ SONAR_JDBC_USERNAME: sonar
+ SONAR_JDBC_PASSWORD: sonar
+ SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonarqube
+ SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true'
+ volumes:
+ - type: bind
+ source: ./sonar-ios-plugin/target/ecodecode-sonar-ios-plugin-0.1.1-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecodecode-sonar-ios-plugin-0.1.1-SNAPSHOT.jar
+ - "logs:/opt/sonarqube/logs"
+ - "data:/opt/sonarqube/data"
+
+ db:
+ image: postgres:12
+ container_name: postgresql
+ networks:
+ - sonarnet
+ volumes:
+ - pg_data:/var/lib/postgresql/data
+ environment:
+ POSTGRES_USER: sonar
+ POSTGRES_PASSWORD: sonar
+ POSTGRES_DB: sonarqube
+ PGDATA: pg_data:/var/lib/postgresql/data/pgdata
+
+networks:
+ sonarnet:
+ driver: bridge
+
+volumes:
+ data:
+ logs:
+ extensions:
+ pg_data:
\ No newline at end of file
diff --git a/ios-plugin/docs/logoInsideApp.jpg b/ios-plugin/docs/logoInsideApp.jpg
new file mode 100644
index 00000000..0081d738
Binary files /dev/null and b/ios-plugin/docs/logoInsideApp.jpg differ
diff --git a/ios-plugin/pom.xml b/ios-plugin/pom.xml
new file mode 100644
index 00000000..6b612924
--- /dev/null
+++ b/ios-plugin/pom.xml
@@ -0,0 +1,174 @@
+
+
+ 4.0.0
+
+
+ io.ecocode
+ ecocode-mobile-parent
+ 0.1.1-SNAPSHOT
+
+
+ ios-plugin
+ pom
+
+ ecoCode iOS plugin
+ Help the earth, adopt this green plugin for your applications
+ https://github.com/cnumr/ecoCode
+ 2022
+
+
+ swift-lang
+ commons-ios
+ sonar-ios-plugin
+
+
+
+
+ GNU LGPL 3
+ http://www.gnu.org/licenses/lgpl.txt
+ repo
+
+
+
+
+
+ 1.21
+ 2.6
+ 0.1.2
+ 4.10
+ 4.4.0
+
+
+
+
+
+ org.sonarsource.sonarqube
+ sonar-plugin-api
+ provided
+
+
+
+
+ org.sonarsource.sonarqube
+ sonar-plugin-api-impl
+
+
+
+ org.sonarsource.analyzer-commons
+ sonar-analyzer-commons
+
+
+
+ org.sonarsource.analyzer-commons
+ sonar-xml-parsing
+ ${sonar.analyzerCommons.version}
+
+
+
+ commons-io
+ commons-io
+ ${sonar.apacheCommons.version}
+
+
+
+ org.antlr
+ antlr4-runtime
+ ${antlr.version}
+
+
+
+
+
+ org.sonarsource.sonarqube
+ sonar-testing-harness
+ ${sonarqube.version}
+ test
+
+
+ org.sonarsource.sslr
+ sslr-testing-harness
+ ${sslr.version}
+ test
+
+
+ junit
+ junit
+ test
+
+
+ org.assertj
+ assertj-core
+ test
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+
+
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+
+
+ **/generated/**
+
+
+
+
+ prepare-agent
+
+ prepare-agent
+
+
+
+ report
+
+ report
+
+
+
+
+
+
+ com.mycila
+ license-maven-plugin
+ 4.1
+
+
+ ecoCode iOS plugin
+ https://www.ecocode.io/
+
+
+
+ com/mycila/maven/plugin/license/templates/LGPL-3.txt
+
+ **/*.java
+
+
+
+
+
+
+ validate
+
+ check
+
+ validate
+
+
+
+
+
+
+
+
diff --git a/ios-plugin/sonar-ios-plugin/pom.xml b/ios-plugin/sonar-ios-plugin/pom.xml
new file mode 100644
index 00000000..26c1f440
--- /dev/null
+++ b/ios-plugin/sonar-ios-plugin/pom.xml
@@ -0,0 +1,47 @@
+
+
+
+ io.ecocode
+ ios-plugin
+ 0.1.1-SNAPSHOT
+
+ 4.0.0
+
+ ecodecode-sonar-ios-plugin
+
+ sonar-plugin
+
+
+
+
+ io.ecocode
+ ecocode-swift-lang
+ ${project.version}
+
+
+
+
+
+
+
+
+
+ org.sonarsource.sonar-packaging-maven-plugin
+ sonar-packaging-maven-plugin
+ true
+
+ ${project.artifactId}
+ ${project.name}
+ io.ecocode.ios.EcoCodeIOSPlugin
+ ${sonarqube.version}
+ false
+ ${java.version}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ios-plugin/sonar-ios-plugin/src/main/java/io/ecocode/ios/EcoCodeIOSPlugin.java b/ios-plugin/sonar-ios-plugin/src/main/java/io/ecocode/ios/EcoCodeIOSPlugin.java
new file mode 100644
index 00000000..6c7200db
--- /dev/null
+++ b/ios-plugin/sonar-ios-plugin/src/main/java/io/ecocode/ios/EcoCodeIOSPlugin.java
@@ -0,0 +1,32 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios;
+
+import io.ecocode.ios.swift.EcoCodeSwiftProfile;
+import io.ecocode.ios.swift.EcoCodeSwiftRulesDefinition;
+import io.ecocode.ios.swift.SwiftSensor;
+import org.sonar.api.Plugin;
+
+public class EcoCodeIOSPlugin implements Plugin {
+
+ @Override
+ public void define(Context context) {
+
+ context.addExtensions(SwiftSensor.class, EcoCodeSwiftProfile.class, EcoCodeSwiftRulesDefinition.class);
+ }
+}
diff --git a/ios-plugin/swift-lang/pom.xml b/ios-plugin/swift-lang/pom.xml
new file mode 100644
index 00000000..32a3fc37
--- /dev/null
+++ b/ios-plugin/swift-lang/pom.xml
@@ -0,0 +1,21 @@
+
+
+ io.ecocode
+ ios-plugin
+ 0.1.1-SNAPSHOT
+
+ 4.0.0
+
+ ecocode-swift-lang
+
+
+
+
+ io.ecocode
+ ecocode-commons-ios
+ ${project.version}
+
+
+
+
+
\ No newline at end of file
diff --git a/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftProfile.java b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftProfile.java
new file mode 100644
index 00000000..faccf779
--- /dev/null
+++ b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftProfile.java
@@ -0,0 +1,30 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.swift;
+
+import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
+import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader;
+
+public class EcoCodeSwiftProfile implements BuiltInQualityProfilesDefinition {
+ @Override
+ public void define(Context context) {
+ NewBuiltInQualityProfile ecoCodeProfile = context.createBuiltInQualityProfile(Swift.PROFILE_NAME, Swift.KEY);
+ BuiltInQualityProfileJsonLoader.load(ecoCodeProfile, Swift.REPOSITORY_KEY, Swift.PROFILE_PATH);
+ ecoCodeProfile.done();
+ }
+}
diff --git a/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftRulesDefinition.java b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftRulesDefinition.java
new file mode 100644
index 00000000..095a0865
--- /dev/null
+++ b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftRulesDefinition.java
@@ -0,0 +1,27 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.swift;
+
+import io.ecocode.ios.rules.JSONRulesDefinition;
+
+public class EcoCodeSwiftRulesDefinition extends JSONRulesDefinition {
+
+ public EcoCodeSwiftRulesDefinition() {
+ super(Swift.REPOSITORY_KEY, Swift.REPOSITORY_NAME, Swift.KEY, Swift.RULES_PATH);
+ }
+}
diff --git a/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftVisitor.java b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftVisitor.java
new file mode 100644
index 00000000..617d1f1b
--- /dev/null
+++ b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/EcoCodeSwiftVisitor.java
@@ -0,0 +1,54 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.swift;
+
+import io.ecocode.ios.antlr.AntlrContext;
+import io.ecocode.ios.antlr.ParseTreeItemVisitor;
+import io.ecocode.ios.checks.RuleCheck;
+import io.ecocode.ios.swift.checks.idleness.IdleTimerDisabledCheck;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.sonar.api.batch.sensor.SensorContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class EcoCodeSwiftVisitor implements ParseTreeItemVisitor {
+
+ private List checks = new ArrayList<>();
+
+ public EcoCodeSwiftVisitor() {
+
+ // Load checks
+ checks.add(new IdleTimerDisabledCheck());
+
+ }
+
+ @Override
+ public void apply(ParseTree tree) {
+ for (RuleCheck check : checks) {
+ check.apply(tree);
+ }
+ }
+
+ @Override
+ public void fillContext(SensorContext context, AntlrContext antlrContext) {
+ for (RuleCheck check : checks) {
+ check.fillContext(context, antlrContext);
+ }
+ }
+}
diff --git a/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/Swift.java b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/Swift.java
new file mode 100644
index 00000000..6cac095b
--- /dev/null
+++ b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/Swift.java
@@ -0,0 +1,32 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.swift;
+
+public final class Swift {
+
+ private Swift() {}
+
+ public static final String KEY = "swift";
+ public static final String PROFILE_NAME = "ecoCode";
+ public static final String REPOSITORY_NAME = "ecoCode";
+ public static final String REPOSITORY_KEY = "ecoCode-swift";
+ public static final String PROFILE_PATH = "ecocode_swift_profile.json";
+
+ public static final String RULES_PATH = "/ecocode-swift-rules.json";
+
+}
diff --git a/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/SwiftSensor.java b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/SwiftSensor.java
new file mode 100644
index 00000000..98e57973
--- /dev/null
+++ b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/SwiftSensor.java
@@ -0,0 +1,44 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.swift;
+
+import io.ecocode.ios.swift.antlr.ParseTreeAnalyzer;
+import io.ecocode.ios.swift.antlr.SwiftAntlrContext;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.sensor.Sensor;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.SensorDescriptor;
+
+public class SwiftSensor implements Sensor {
+
+ @Override
+ public void describe(SensorDescriptor sensorDescriptor) {
+ sensorDescriptor
+ .onlyOnLanguage(Swift.KEY)
+ .name("ecoCode Swift Sensor")
+ .onlyOnFileType(InputFile.Type.MAIN);
+ }
+
+ @Override
+ public void execute(SensorContext sensorContext) {
+ final SwiftAntlrContext antlrContext = new SwiftAntlrContext();
+ // Analyse source files
+ new ParseTreeAnalyzer(Swift.KEY, InputFile.Type.MAIN, antlrContext, sensorContext)
+ .analyze(new EcoCodeSwiftVisitor());
+ }
+}
diff --git a/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/antlr/CustomTreeVisitor.java b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/antlr/CustomTreeVisitor.java
new file mode 100644
index 00000000..90cb4eba
--- /dev/null
+++ b/ios-plugin/swift-lang/src/main/java/io/ecocode/ios/swift/antlr/CustomTreeVisitor.java
@@ -0,0 +1,62 @@
+/*
+ * ecoCode iOS plugin - Help the earth, adopt this green plugin for your applications
+ * Copyright © 2022 Green code Initiative (https://www.ecocode.io/)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package io.ecocode.ios.swift.antlr;
+
+import io.ecocode.ios.antlr.AntlrContext;
+import io.ecocode.ios.antlr.ParseTreeItemVisitor;
+import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.sonar.api.batch.sensor.SensorContext;
+
+public class CustomTreeVisitor extends AbstractParseTreeVisitor