From 0c70f358d59f6daa378f66bd5982d0119be4c839 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Tue, 20 Feb 2024 11:39:36 -0700 Subject: [PATCH] Update to Structure101 7.0.24375 Closes gh-14629 --- build.gradle | 2 + .../src/main/java/s101/S101Configurer.java | 57 ++++--------------- buildSrc/src/main/java/s101/S101Plugin.java | 2 +- .../main/java/s101/S101PluginExtension.java | 56 +++++++++++++++++- 4 files changed, 69 insertions(+), 48 deletions(-) diff --git a/build.gradle b/build.gradle index f3737eee35..735eb8165a 100644 --- a/build.gradle +++ b/build.gradle @@ -148,5 +148,7 @@ tasks.register('cloneSamples', IncludeRepoTask) { } s101 { + repository = 'https://s101-pickup.s3.amazonaws.com' + version = '7.0.24375' configurationDirectory = project.file("etc/s101") } diff --git a/buildSrc/src/main/java/s101/S101Configurer.java b/buildSrc/src/main/java/s101/S101Configurer.java index 1575f47fbd..3db57edc0e 100644 --- a/buildSrc/src/main/java/s101/S101Configurer.java +++ b/buildSrc/src/main/java/s101/S101Configurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package s101; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -34,18 +33,11 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.html.HtmlAnchor; -import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.github.mustachejava.DefaultMustacheFactory; import com.github.mustachejava.Mustache; import com.github.mustachejava.MustacheFactory; @@ -71,6 +63,10 @@ public class S101Configurer { private final Path licenseDirectory; + private final String repository; + + private final String version; + private final Project project; private final Logger logger; @@ -90,6 +86,9 @@ public class S101Configurer { throw new UncheckedIOException(ex); } this.licenseDirectory = new File(System.getProperty("user.home") + "/.Structure101/java").toPath(); + S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class); + this.repository = extension.getRepository().get(); + this.version = extension.getVersion().get(); } public void license(String licenseId) { @@ -129,25 +128,7 @@ public class S101Configurer { public void configure(File installationDirectory, File configurationDirectory) { deleteDirectory(configurationDirectory); - String version = computeVersionFromInstallation(installationDirectory); - configureProject(version, configurationDirectory); - } - - private String computeVersionFromInstallation(File installationDirectory) { - File buildJar = new File(installationDirectory, "structure101-java-build.jar"); - try (JarInputStream input = new JarInputStream(new FileInputStream(buildJar))) { - JarEntry entry; - while ((entry = input.getNextJarEntry()) != null) { - if (entry.getName().contains("structure101-build.properties")) { - Properties properties = new Properties(); - properties.load(input); - return properties.getProperty("s101-build"); - } - } - } catch (Exception ex) { - throw new RuntimeException(ex); - } - throw new IllegalStateException("Unable to determine Structure101 version"); + configureProject(this.version, configurationDirectory); } private boolean deleteDirectory(File directoryToBeDeleted) { @@ -161,24 +142,8 @@ public class S101Configurer { } private String installBuildTool(File installationDirectory, File configurationDirectory) { - String source = "https://structure101.com/binaries/v6"; - try (final WebClient webClient = new WebClient()) { - HtmlPage page = webClient.getPage(source); - Matcher matcher = null; - for (HtmlAnchor anchor : page.getAnchors()) { - Matcher candidate = Pattern.compile("(structure101-build-java-all-)(.*).zip").matcher(anchor.getHrefAttribute()); - if (candidate.find()) { - matcher = candidate; - } - } - if (matcher == null) { - return null; - } - copyZipToFilesystem(source, installationDirectory, matcher.group(1) + matcher.group(2)); - return matcher.group(2); - } catch (Exception ex) { - throw new RuntimeException(ex); - } + copyZipToFilesystem(this.repository, installationDirectory, "structure101-build-java-all-" + this.version); + return this.version; } private void copyZipToFilesystem(String source, File destination, String name) { diff --git a/buildSrc/src/main/java/s101/S101Plugin.java b/buildSrc/src/main/java/s101/S101Plugin.java index 00894fb335..6d2e01abc0 100644 --- a/buildSrc/src/main/java/s101/S101Plugin.java +++ b/buildSrc/src/main/java/s101/S101Plugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/s101/S101PluginExtension.java b/buildSrc/src/main/java/s101/S101PluginExtension.java index f3abe0f156..6c355ed33c 100644 --- a/buildSrc/src/main/java/s101/S101PluginExtension.java +++ b/buildSrc/src/main/java/s101/S101PluginExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,12 @@ package s101; import java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlAnchor; +import com.gargoylesoftware.htmlunit.html.HtmlPage; import org.gradle.api.Project; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; @@ -25,6 +30,11 @@ import org.gradle.api.tasks.InputDirectory; public class S101PluginExtension { private final Property licenseId; + + private final Property repository; + + private final Property version; + private final Property installationDirectory; private final Property configurationDirectory; private final Property label; @@ -65,6 +75,24 @@ public class S101PluginExtension { this.label.set(label); } + @Input + public Property getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository.set(repository); + } + + @Input + public Property getVersion() { + return this.version; + } + + public void setVersion(String version) { + this.version.set(version); + } + public S101PluginExtension(Project project) { this.licenseId = project.getObjects().property(String.class); if (project.hasProperty("s101.licenseId")) { @@ -78,5 +106,31 @@ public class S101PluginExtension { if (project.hasProperty("s101.label")) { setLabel((String) project.findProperty("s101.label")); } + this.repository = project.getObjects().property(String.class); + if (project.hasProperty("s101.repository")) { + setRepository((String) project.findProperty("s101.repository")); + } else { + setRepository("https://structure101.com/binaries/v6"); + } + this.version = project.getObjects().property(String.class); + if (project.hasProperty("s101.version")) { + setVersion((String) project.findProperty("s101.version")); + } else { + try (final WebClient webClient = new WebClient()) { + HtmlPage page = webClient.getPage(getRepository().get()); + Matcher matcher = null; + for (HtmlAnchor anchor : page.getAnchors()) { + Matcher candidate = Pattern.compile("(structure101-build-java-all-)(.*).zip").matcher(anchor.getHrefAttribute()); + if (candidate.find()) { + matcher = candidate; + } + } + if (matcher != null) { + setVersion(matcher.group(2)); + } + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } } }