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

View File

@ -13,6 +13,7 @@ env:
GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }} GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
COMMIT_OWNER: ${{ github.event.pusher.name }} COMMIT_OWNER: ${{ github.event.pusher.name }}
COMMIT_SHA: ${{ github.sha }} COMMIT_SHA: ${{ github.sha }}
STRUCTURE101_LICENSEID: ${{ secrets.STRUCTURE101_LICENSEID }}
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
RUN_JOBS: ${{ github.repository == 'spring-projects/spring-security' }} RUN_JOBS: ${{ github.repository == 'spring-projects/spring-security' }}
@ -119,7 +120,7 @@ jobs:
export GRADLE_ENTERPRISE_CACHE_USERNAME="$GRADLE_ENTERPRISE_CACHE_USER" export GRADLE_ENTERPRISE_CACHE_USERNAME="$GRADLE_ENTERPRISE_CACHE_USER"
export GRADLE_ENTERPRISE_CACHE_PASSWORD="$GRADLE_ENTERPRISE_CACHE_PASSWORD" export GRADLE_ENTERPRISE_CACHE_PASSWORD="$GRADLE_ENTERPRISE_CACHE_PASSWORD"
export GRADLE_ENTERPRISE_ACCESS_KEY="$GRADLE_ENTERPRISE_SECRET_ACCESS_KEY" export GRADLE_ENTERPRISE_ACCESS_KEY="$GRADLE_ENTERPRISE_SECRET_ACCESS_KEY"
./gradlew check s101 --stacktrace ./gradlew check s101 -Ps101.licenseId="$STRUCTURE101_LICENSEID" --stacktrace
deploy_artifacts: deploy_artifacts:
name: Deploy Artifacts name: Deploy Artifacts
needs: [build_jdk_11, snapshot_tests, check_samples, check_tangles] needs: [build_jdk_11, snapshot_tests, check_samples, check_tangles]

View File

@ -24,8 +24,11 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -66,6 +69,8 @@ public class S101Configurer {
private final Mustache hspTemplate; private final Mustache hspTemplate;
private final Mustache repositoryTemplate; private final Mustache repositoryTemplate;
private final Path licenseDirectory;
private final Project project; private final Project project;
private final Logger logger; private final Logger logger;
@ -84,6 +89,37 @@ public class S101Configurer {
} catch (IOException ex) { } catch (IOException ex) {
throw new UncheckedIOException(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) { public void install(File installationDirectory, File configurationDirectory) {

View File

@ -57,7 +57,6 @@ public class S101Plugin implements Plugin<Project> {
.workingDir(extension.getInstallationDirectory()) .workingDir(extension.getInstallationDirectory())
.classpath(new File(extension.getInstallationDirectory().get(), "structure101-java-build.jar")) .classpath(new File(extension.getInstallationDirectory().get(), "structure101-java-build.jar"))
.args(new File(new File(project.getBuildDir(), "s101"), "config.xml")) .args(new File(new File(project.getBuildDir(), "s101"), "config.xml"))
.args("-licensedirectory=" + extension.getLicenseDirectory().get())
.systemProperty("s101.label", computeLabel(extension).get()) .systemProperty("s101.label", computeLabel(extension).get())
.doFirst((task) -> { .doFirst((task) -> {
installAndConfigureIfNeeded(project); installAndConfigureIfNeeded(project);
@ -80,6 +79,10 @@ public class S101Plugin implements Plugin<Project> {
private void installAndConfigureIfNeeded(Project project) { private void installAndConfigureIfNeeded(Project project) {
S101Configurer configurer = new S101Configurer(project); S101Configurer configurer = new S101Configurer(project);
S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class); S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class);
String licenseId = extension.getLicenseId().getOrNull();
if (licenseId != null) {
configurer.license(licenseId);
}
File installationDirectory = extension.getInstallationDirectory().get(); File installationDirectory = extension.getInstallationDirectory().get();
File configurationDirectory = extension.getConfigurationDirectory().get(); File configurationDirectory = extension.getConfigurationDirectory().get();
if (!installationDirectory.exists()) { if (!installationDirectory.exists()) {

View File

@ -24,18 +24,18 @@ import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory; import org.gradle.api.tasks.InputDirectory;
public class S101PluginExtension { public class S101PluginExtension {
private final Property<File> licenseDirectory; private final Property<String> licenseId;
private final Property<File> installationDirectory; private final Property<File> installationDirectory;
private final Property<File> configurationDirectory; private final Property<File> configurationDirectory;
private final Property<String> label; private final Property<String> label;
@InputDirectory @Input
public Property<File> getLicenseDirectory() { public Property<String> getLicenseId() {
return this.licenseDirectory; return this.licenseId;
} }
public void setLicenseDirectory(String licenseDirectory) { public void setLicenseId(String licenseId) {
this.licenseDirectory.set(new File(licenseDirectory)); this.licenseId.set(licenseId);
} }
@InputDirectory @InputDirectory
@ -66,8 +66,10 @@ public class S101PluginExtension {
} }
public S101PluginExtension(Project project) { public S101PluginExtension(Project project) {
this.licenseDirectory = project.getObjects().property(File.class) this.licenseId = project.getObjects().property(String.class);
.convention(new File(System.getProperty("user.home") + "/.Structure101/java")); if (project.hasProperty("s101.licenseId")) {
setLicenseId((String) project.findProperty("s101.licenseId"));
}
this.installationDirectory = project.getObjects().property(File.class) this.installationDirectory = project.getObjects().property(File.class)
.convention(new File(project.getBuildDir(), "s101")); .convention(new File(project.getBuildDir(), "s101"));
this.configurationDirectory = project.getObjects().property(File.class) this.configurationDirectory = project.getObjects().property(File.class)