Skip to content

Commit

Permalink
Support Structure101 License ID
Browse files Browse the repository at this point in the history
Closes gh-10443
  • Loading branch information
jzheaux committed Oct 28, 2021
1 parent 4b0e74a commit 73b0564
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
COMMIT_OWNER: ${{ github.event.pusher.name }}
COMMIT_SHA: ${{ github.sha }}
STRUCTURE101_LICENSEID: ${{ secrets.STRUCTURE101_LICENSEID }}
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
RUN_JOBS: ${{ github.repository == 'spring-projects/spring-security' }}
Expand Down Expand Up @@ -119,7 +120,7 @@ jobs:
export GRADLE_ENTERPRISE_CACHE_USERNAME="$GRADLE_ENTERPRISE_CACHE_USER"
export GRADLE_ENTERPRISE_CACHE_PASSWORD="$GRADLE_ENTERPRISE_CACHE_PASSWORD"
export GRADLE_ENTERPRISE_ACCESS_KEY="$GRADLE_ENTERPRISE_SECRET_ACCESS_KEY"
./gradlew check s101 --stacktrace
./gradlew check s101 -Ps101.licenseId="$STRUCTURE101_LICENSEID" --stacktrace
deploy_artifacts:
name: Deploy Artifacts
needs: [build_jdk_11, snapshot_tests, check_samples, check_tangles]
Expand Down
24 changes: 24 additions & 0 deletions buildSrc/src/main/java/s101/S101Configurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
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;
Expand Down Expand Up @@ -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;

Expand All @@ -84,6 +89,25 @@ public S101Configurer(Project project) {
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
this.licenseDirectory = new File(System.getProperty("user.home") + "/.Structure101/java").toPath();
}

public void license(String licenseId) {
Path propertiesFile = this.licenseDirectory.resolve(".structure101license.properties");
try {
String license = new String(Files.readAllBytes(propertiesFile));
if (license.contains(licenseId)) {
return;
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
this.licenseDirectory.forEach((path) -> path.toFile().delete());
try (PrintWriter pw = new PrintWriter(propertiesFile.toFile())) {
pw.println("licensecode=" + licenseId);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

public void install(File installationDirectory, File configurationDirectory) {
Expand Down
5 changes: 4 additions & 1 deletion buildSrc/src/main/java/s101/S101Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private void configure(JavaExec exec) {
.workingDir(extension.getInstallationDirectory())
.classpath(new File(extension.getInstallationDirectory().get(), "structure101-java-build.jar"))
.args(new File(new File(project.getBuildDir(), "s101"), "config.xml"))
.args("-licensedirectory=" + extension.getLicenseDirectory().get())
.systemProperty("s101.label", computeLabel(extension).get())
.doFirst((task) -> {
installAndConfigureIfNeeded(project);
Expand All @@ -80,6 +79,10 @@ private Property<String> computeLabel(S101PluginExtension extension) {
private void installAndConfigureIfNeeded(Project project) {
S101Configurer configurer = new S101Configurer(project);
S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class);
String licenseId = extension.getLicenseId().getOrNull();
if (licenseId != null) {
configurer.license(licenseId);
}
File installationDirectory = extension.getInstallationDirectory().get();
File configurationDirectory = extension.getConfigurationDirectory().get();
if (!installationDirectory.exists()) {
Expand Down
18 changes: 10 additions & 8 deletions buildSrc/src/main/java/s101/S101PluginExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
import org.gradle.api.tasks.InputDirectory;

public class S101PluginExtension {
private final Property<File> licenseDirectory;
private final Property<String> licenseId;
private final Property<File> installationDirectory;
private final Property<File> configurationDirectory;
private final Property<String> label;

@InputDirectory
public Property<File> getLicenseDirectory() {
return this.licenseDirectory;
@Input
public Property<String> getLicenseId() {
return this.licenseId;
}

public void setLicenseDirectory(String licenseDirectory) {
this.licenseDirectory.set(new File(licenseDirectory));
public void setLicenseId(String licenseId) {
this.licenseId.set(licenseId);
}

@InputDirectory
Expand Down Expand Up @@ -66,8 +66,10 @@ public void setLabel(String label) {
}

public S101PluginExtension(Project project) {
this.licenseDirectory = project.getObjects().property(File.class)
.convention(new File(System.getProperty("user.home") + "/.Structure101/java"));
this.licenseId = project.getObjects().property(String.class);
if (project.hasProperty("s101.licenseId")) {
setLicenseId((String) project.findProperty("s101.licenseId"));
}
this.installationDirectory = project.getObjects().property(File.class)
.convention(new File(project.getBuildDir(), "s101"));
this.configurationDirectory = project.getObjects().property(File.class)
Expand Down

0 comments on commit 73b0564

Please sign in to comment.