1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Support Structure101 License ID

Closes gh-10443
This commit is contained in:
Josh Cummings
2021-10-26 15:10:28 -06:00
parent 7a99542662
commit d779cd1d48
4 changed files with 52 additions and 10 deletions
@@ -24,8 +24,11 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -66,6 +69,8 @@ public class S101Configurer {
private final Mustache hspTemplate;
private final Mustache repositoryTemplate;
private final Path licenseDirectory;
private final Project project;
private final Logger logger;
@@ -84,6 +89,37 @@ public class S101Configurer {
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
this.licenseDirectory = new File(System.getProperty("user.home") + "/.Structure101/java").toPath();
}
public void license(String licenseId) {
Path licenseFile = this.licenseDirectory.resolve(".structure101license.properties");
if (needsLicense(licenseFile, licenseId)) {
writeLicense(licenseFile, licenseId);
}
}
private boolean needsLicense(Path licenseFile, String licenseId) {
if (!licenseFile.toFile().exists()) {
return true;
}
try {
String license = new String(Files.readAllBytes(licenseFile));
return !license.contains(licenseId);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
private void writeLicense(Path licenseFile, String licenseId) {
if (!this.licenseDirectory.toFile().mkdirs()) {
this.licenseDirectory.forEach((path) -> path.toFile().delete());
}
try (PrintWriter pw = new PrintWriter(licenseFile.toFile())) {
pw.println("licensecode=" + licenseId);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public void install(File installationDirectory, File configurationDirectory) {