Skip to content

Commit d779cd1

Browse files
committed
Support Structure101 License ID
Closes gh-10443
1 parent 7a99542 commit d779cd1

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

.github/workflows/continuous-integration-workflow.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
1414
COMMIT_OWNER: ${{ github.event.pusher.name }}
1515
COMMIT_SHA: ${{ github.sha }}
16+
STRUCTURE101_LICENSEID: ${{ secrets.STRUCTURE101_LICENSEID }}
1617
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
1718
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
1819
RUN_JOBS: ${{ github.repository == 'spring-projects/spring-security' }}
@@ -119,7 +120,7 @@ jobs:
119120
export GRADLE_ENTERPRISE_CACHE_USERNAME="$GRADLE_ENTERPRISE_CACHE_USER"
120121
export GRADLE_ENTERPRISE_CACHE_PASSWORD="$GRADLE_ENTERPRISE_CACHE_PASSWORD"
121122
export GRADLE_ENTERPRISE_ACCESS_KEY="$GRADLE_ENTERPRISE_SECRET_ACCESS_KEY"
122-
./gradlew check s101 --stacktrace
123+
./gradlew check s101 -Ps101.licenseId="$STRUCTURE101_LICENSEID" --stacktrace
123124
deploy_artifacts:
124125
name: Deploy Artifacts
125126
needs: [build_jdk_11, snapshot_tests, check_samples, check_tangles]

buildSrc/src/main/java/s101/S101Configurer.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
import java.io.InputStreamReader;
2525
import java.io.OutputStream;
2626
import java.io.OutputStreamWriter;
27+
import java.io.PrintWriter;
2728
import java.io.UncheckedIOException;
2829
import java.net.URL;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
2932
import java.util.ArrayList;
3033
import java.util.HashMap;
3134
import java.util.LinkedHashMap;
@@ -66,6 +69,8 @@ public class S101Configurer {
6669
private final Mustache hspTemplate;
6770
private final Mustache repositoryTemplate;
6871

72+
private final Path licenseDirectory;
73+
6974
private final Project project;
7075
private final Logger logger;
7176

@@ -84,6 +89,37 @@ public S101Configurer(Project project) {
8489
} catch (IOException ex) {
8590
throw new UncheckedIOException(ex);
8691
}
92+
this.licenseDirectory = new File(System.getProperty("user.home") + "/.Structure101/java").toPath();
93+
}
94+
95+
public void license(String licenseId) {
96+
Path licenseFile = this.licenseDirectory.resolve(".structure101license.properties");
97+
if (needsLicense(licenseFile, licenseId)) {
98+
writeLicense(licenseFile, licenseId);
99+
}
100+
}
101+
102+
private boolean needsLicense(Path licenseFile, String licenseId) {
103+
if (!licenseFile.toFile().exists()) {
104+
return true;
105+
}
106+
try {
107+
String license = new String(Files.readAllBytes(licenseFile));
108+
return !license.contains(licenseId);
109+
} catch (IOException ex) {
110+
throw new RuntimeException(ex);
111+
}
112+
}
113+
114+
private void writeLicense(Path licenseFile, String licenseId) {
115+
if (!this.licenseDirectory.toFile().mkdirs()) {
116+
this.licenseDirectory.forEach((path) -> path.toFile().delete());
117+
}
118+
try (PrintWriter pw = new PrintWriter(licenseFile.toFile())) {
119+
pw.println("licensecode=" + licenseId);
120+
} catch (IOException ex) {
121+
throw new RuntimeException(ex);
122+
}
87123
}
88124

89125
public void install(File installationDirectory, File configurationDirectory) {

buildSrc/src/main/java/s101/S101Plugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ private void configure(JavaExec exec) {
5757
.workingDir(extension.getInstallationDirectory())
5858
.classpath(new File(extension.getInstallationDirectory().get(), "structure101-java-build.jar"))
5959
.args(new File(new File(project.getBuildDir(), "s101"), "config.xml"))
60-
.args("-licensedirectory=" + extension.getLicenseDirectory().get())
6160
.systemProperty("s101.label", computeLabel(extension).get())
6261
.doFirst((task) -> {
6362
installAndConfigureIfNeeded(project);
@@ -80,6 +79,10 @@ private Property<String> computeLabel(S101PluginExtension extension) {
8079
private void installAndConfigureIfNeeded(Project project) {
8180
S101Configurer configurer = new S101Configurer(project);
8281
S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class);
82+
String licenseId = extension.getLicenseId().getOrNull();
83+
if (licenseId != null) {
84+
configurer.license(licenseId);
85+
}
8386
File installationDirectory = extension.getInstallationDirectory().get();
8487
File configurationDirectory = extension.getConfigurationDirectory().get();
8588
if (!installationDirectory.exists()) {

buildSrc/src/main/java/s101/S101PluginExtension.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
import org.gradle.api.tasks.InputDirectory;
2525

2626
public class S101PluginExtension {
27-
private final Property<File> licenseDirectory;
27+
private final Property<String> licenseId;
2828
private final Property<File> installationDirectory;
2929
private final Property<File> configurationDirectory;
3030
private final Property<String> label;
3131

32-
@InputDirectory
33-
public Property<File> getLicenseDirectory() {
34-
return this.licenseDirectory;
32+
@Input
33+
public Property<String> getLicenseId() {
34+
return this.licenseId;
3535
}
3636

37-
public void setLicenseDirectory(String licenseDirectory) {
38-
this.licenseDirectory.set(new File(licenseDirectory));
37+
public void setLicenseId(String licenseId) {
38+
this.licenseId.set(licenseId);
3939
}
4040

4141
@InputDirectory
@@ -66,8 +66,10 @@ public void setLabel(String label) {
6666
}
6767

6868
public S101PluginExtension(Project project) {
69-
this.licenseDirectory = project.getObjects().property(File.class)
70-
.convention(new File(System.getProperty("user.home") + "/.Structure101/java"));
69+
this.licenseId = project.getObjects().property(String.class);
70+
if (project.hasProperty("s101.licenseId")) {
71+
setLicenseId((String) project.findProperty("s101.licenseId"));
72+
}
7173
this.installationDirectory = project.getObjects().property(File.class)
7274
.convention(new File(project.getBuildDir(), "s101"));
7375
this.configurationDirectory = project.getObjects().property(File.class)

0 commit comments

Comments
 (0)