Skip to content

Commit e12716c

Browse files
committed
Read REUSE.toml, if license is missing #49
Signed-off-by: Mārtiņš Avots <martins.avots@splitcells.net>
1 parent e01f447 commit e12716c

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

projects/net.splitcells.maven.plugin.resource.list/src/main/java/net/splitcells/maven/plugin/resource/list/MetaData.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
package net.splitcells.maven.plugin.resource.list;
1717

1818
import lombok.val;
19+
import org.tomlj.Toml;
1920

21+
import java.io.IOException;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
2024
import java.util.regex.Pattern;
2125

2226
public class MetaData {
@@ -28,7 +32,7 @@ public class MetaData {
2832
String license;
2933
String copyrightText;
3034

31-
public MetaData parseMetaData(String fileContent) {
35+
public MetaData parseMetaData(Path projectPath, String fileContent) {
3236
val licenseMatch = SPX_LICENSE.matcher(fileContent);
3337
if (licenseMatch.find()) {
3438
license = licenseMatch.group(2);
@@ -37,6 +41,20 @@ public MetaData parseMetaData(String fileContent) {
3741
if (copyrightMatch.find()) {
3842
copyrightText = copyrightMatch.group(2);
3943
}
44+
if (license == null) {
45+
val reuseToml = projectPath.resolve("REUSE.toml");
46+
if (Files.exists(reuseToml)) {
47+
try {
48+
val tomlParsing = Toml.parse(reuseToml);
49+
if (!tomlParsing.errors().isEmpty()) {
50+
throw new RuntimeException("The REUSE TOML file containing license data is not correct: " + reuseToml);
51+
}
52+
System.out.println(tomlParsing + " was successfully parsed.");
53+
} catch (IOException e) {
54+
throw new RuntimeException(e);
55+
}
56+
}
57+
}
4058
return this;
4159
}
4260

projects/net.splitcells.maven.plugin.resource.list/src/main/java/net/splitcells/maven/plugin/resource/list/ResourceListMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void execute() throws MojoExecutionException {
117117
throw new RuntimeException("Could not create folder for meta data file: " + metaFileFolder, e);
118118
}
119119
final var metaData = new MetaData();
120-
metaData.parseMetaData(resourceContent);
120+
metaData.parseMetaData(project.getBasedir().toPath(), resourceContent);
121121
try (final BufferedWriter metaWriter = new BufferedWriter(new FileWriter(metaFilePath.toFile()))) {
122122
metaWriter.write(metaData.toString());
123123
} catch (IOException e) {

0 commit comments

Comments
 (0)