-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize rule exporter tooling module
- Loading branch information
Showing
17 changed files
with
876 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.ecocode</groupId> | ||
<artifactId>ecocode-parent</artifactId> | ||
<version>1.5.4-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rule-exporter</artifactId> | ||
|
||
<name>ecoCode Rule Exporter</name> | ||
<description>Export all rules to JSON files usable by the website</description> | ||
<url>https://github.com/green-code-initiative/ecoCode/tree/main/tools</url> | ||
<inceptionYear>2024</inceptionYear> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
<maven.install.skip>true</maven.install.skip> | ||
|
||
<version.jakarta-json-api>2.1.3</version.jakarta-json-api> | ||
<version.jakarta-json>2.0.1</version.jakarta-json> | ||
<version.junit>5.10.1</version.junit> | ||
<version.assertj>3.25.3</version.assertj> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.json</groupId> | ||
<artifactId>jakarta.json-api</artifactId> | ||
<version>${version.jakarta-json-api}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish</groupId> | ||
<artifactId>jakarta.json</artifactId> | ||
<version>${version.jakarta-json}</version> | ||
<classifier>module</classifier> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>${version.junit}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${version.assertj}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.11.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.1.2</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
tools/rule-exporter/src/main/java/io/ecocode/tools/exporter/RuleExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* ecoCode Rule Exporter - Export all rules to JSON files usable by the website | ||
* Copyright © 2024 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.ecocode.tools.exporter; | ||
|
||
import io.ecocode.tools.exporter.infra.RuleReader; | ||
import io.ecocode.tools.exporter.infra.RuleWriter; | ||
|
||
import java.io.IOException; | ||
|
||
public class RuleExporter { | ||
|
||
public static void main(String[] args) throws IOException { | ||
if (args.length != 2) { | ||
System.out.println("Usage: java -jar rule-exporter.jar <input jar> <output json>"); | ||
System.exit(1); | ||
} | ||
|
||
RuleReader reader = new RuleReader(args[0]); | ||
RuleWriter writer = new RuleWriter(args[1]); | ||
writer.writeRules(reader.readRules()); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
tools/rule-exporter/src/main/java/io/ecocode/tools/exporter/domain/RuleId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* ecoCode Rule Exporter - Export all rules to JSON files usable by the website | ||
* Copyright © 2024 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.ecocode.tools.exporter.domain; | ||
|
||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class RuleId implements Comparable<RuleId> { | ||
|
||
private static final Pattern PATTERN = Pattern.compile("^EC(\\d+)$"); | ||
|
||
private final String naturalId; | ||
|
||
private final long id; | ||
|
||
public RuleId(String naturalId) { | ||
Matcher matcher = PATTERN.matcher(naturalId); | ||
if (matcher.find()) { | ||
this.naturalId = naturalId; | ||
this.id = Long.parseLong(matcher.group(1)); | ||
} else { | ||
throw new IllegalArgumentException("Invalid rule id: " + naturalId); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.naturalId; | ||
} | ||
|
||
@Override | ||
public int compareTo(RuleId o) { | ||
return Long.compare(this.id, o.id); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
RuleId ruleId = (RuleId) o; | ||
return id == ruleId.id; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
tools/rule-exporter/src/main/java/io/ecocode/tools/exporter/domain/RuleMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* ecoCode Rule Exporter - Export all rules to JSON files usable by the website | ||
* Copyright © 2024 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.ecocode.tools.exporter.domain; | ||
|
||
public class RuleMetadata { | ||
|
||
private final RuleId id; | ||
private final String technology; | ||
private final String title; | ||
private final RuleSeverity severity; | ||
private final RuleStatus status; | ||
|
||
private RuleMetadata(String id, String technology, String title, RuleSeverity severity, RuleStatus status) { | ||
this.id = new RuleId(id); | ||
this.technology = technology; | ||
this.title = title; | ||
this.severity = severity; | ||
this.status = status; | ||
} | ||
|
||
public RuleId getId() { | ||
return this.id; | ||
} | ||
|
||
public String getTechnology() { | ||
return this.technology; | ||
} | ||
|
||
public String getTitle() { | ||
return this.title; | ||
} | ||
|
||
public RuleSeverity getSeverity() { | ||
return this.severity; | ||
} | ||
|
||
public RuleStatus getStatus() { | ||
return this.status; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RuleMetadata{" + | ||
"id='" + id + '\'' + | ||
", language='" + technology + '\'' + | ||
", title='" + title + '\'' + | ||
", severity=" + severity + | ||
", status=" + status + | ||
'}'; | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String id; | ||
private String technology; | ||
private String title; | ||
private RuleSeverity severity; | ||
private RuleStatus status; | ||
|
||
public Builder id(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public Builder technology(String technology) { | ||
this.technology = technology; | ||
return this; | ||
} | ||
|
||
public Builder title(String title) { | ||
this.title = title; | ||
return this; | ||
} | ||
|
||
public Builder severity(RuleSeverity severity) { | ||
this.severity = severity; | ||
return this; | ||
} | ||
|
||
public Builder status(RuleStatus status) { | ||
this.status = status; | ||
return this; | ||
} | ||
|
||
public RuleMetadata build() { | ||
return new RuleMetadata(id, technology, title, severity, status); | ||
} | ||
|
||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
tools/rule-exporter/src/main/java/io/ecocode/tools/exporter/domain/RuleSeverity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* ecoCode Rule Exporter - Export all rules to JSON files usable by the website | ||
* Copyright © 2024 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.ecocode.tools.exporter.domain; | ||
|
||
public enum RuleSeverity { | ||
INFO, MINOR, MAJOR, CRITICAL | ||
} |
22 changes: 22 additions & 0 deletions
22
tools/rule-exporter/src/main/java/io/ecocode/tools/exporter/domain/RuleStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* ecoCode Rule Exporter - Export all rules to JSON files usable by the website | ||
* Copyright © 2024 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.ecocode.tools.exporter.domain; | ||
|
||
public enum RuleStatus { | ||
READY, DEPRECATED | ||
} |
Oops, something went wrong.