Skip to content

Commit d80fade

Browse files
committed
Merge branch '5.8.x' into 6.1.x
Closes gh-14638
2 parents 748c723 + 0c70f35 commit d80fade

File tree

4 files changed

+69
-48
lines changed

4 files changed

+69
-48
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,7 @@ tasks.register('cloneRepository', IncludeRepoTask) {
106106
}
107107

108108
s101 {
109+
repository = 'https://s101-pickup.s3.amazonaws.com'
110+
version = '7.0.24375'
109111
configurationDirectory = project.file("etc/s101")
110112
}

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

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package s101;
1818

1919
import java.io.File;
20-
import java.io.FileInputStream;
2120
import java.io.FileOutputStream;
2221
import java.io.IOException;
2322
import java.io.InputStream;
@@ -34,18 +33,11 @@
3433
import java.util.LinkedHashMap;
3534
import java.util.List;
3635
import java.util.Map;
37-
import java.util.Properties;
3836
import java.util.Set;
39-
import java.util.jar.JarEntry;
40-
import java.util.jar.JarInputStream;
41-
import java.util.regex.Matcher;
4237
import java.util.regex.Pattern;
4338
import java.util.zip.ZipEntry;
4439
import java.util.zip.ZipInputStream;
4540

46-
import com.gargoylesoftware.htmlunit.WebClient;
47-
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
48-
import com.gargoylesoftware.htmlunit.html.HtmlPage;
4941
import com.github.mustachejava.DefaultMustacheFactory;
5042
import com.github.mustachejava.Mustache;
5143
import com.github.mustachejava.MustacheFactory;
@@ -71,6 +63,10 @@ public class S101Configurer {
7163

7264
private final Path licenseDirectory;
7365

66+
private final String repository;
67+
68+
private final String version;
69+
7470
private final Project project;
7571
private final Logger logger;
7672

@@ -90,6 +86,9 @@ public S101Configurer(Project project) {
9086
throw new UncheckedIOException(ex);
9187
}
9288
this.licenseDirectory = new File(System.getProperty("user.home") + "/.Structure101/java").toPath();
89+
S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class);
90+
this.repository = extension.getRepository().get();
91+
this.version = extension.getVersion().get();
9392
}
9493

9594
public void license(String licenseId) {
@@ -129,25 +128,7 @@ public void install(File installationDirectory, File configurationDirectory) {
129128

130129
public void configure(File installationDirectory, File configurationDirectory) {
131130
deleteDirectory(configurationDirectory);
132-
String version = computeVersionFromInstallation(installationDirectory);
133-
configureProject(version, configurationDirectory);
134-
}
135-
136-
private String computeVersionFromInstallation(File installationDirectory) {
137-
File buildJar = new File(installationDirectory, "structure101-java-build.jar");
138-
try (JarInputStream input = new JarInputStream(new FileInputStream(buildJar))) {
139-
JarEntry entry;
140-
while ((entry = input.getNextJarEntry()) != null) {
141-
if (entry.getName().contains("structure101-build.properties")) {
142-
Properties properties = new Properties();
143-
properties.load(input);
144-
return properties.getProperty("s101-build");
145-
}
146-
}
147-
} catch (Exception ex) {
148-
throw new RuntimeException(ex);
149-
}
150-
throw new IllegalStateException("Unable to determine Structure101 version");
131+
configureProject(this.version, configurationDirectory);
151132
}
152133

153134
private boolean deleteDirectory(File directoryToBeDeleted) {
@@ -161,24 +142,8 @@ private boolean deleteDirectory(File directoryToBeDeleted) {
161142
}
162143

163144
private String installBuildTool(File installationDirectory, File configurationDirectory) {
164-
String source = "https://structure101.com/binaries/v6";
165-
try (final WebClient webClient = new WebClient()) {
166-
HtmlPage page = webClient.getPage(source);
167-
Matcher matcher = null;
168-
for (HtmlAnchor anchor : page.getAnchors()) {
169-
Matcher candidate = Pattern.compile("(structure101-build-java-all-)(.*).zip").matcher(anchor.getHrefAttribute());
170-
if (candidate.find()) {
171-
matcher = candidate;
172-
}
173-
}
174-
if (matcher == null) {
175-
return null;
176-
}
177-
copyZipToFilesystem(source, installationDirectory, matcher.group(1) + matcher.group(2));
178-
return matcher.group(2);
179-
} catch (Exception ex) {
180-
throw new RuntimeException(ex);
181-
}
145+
copyZipToFilesystem(this.repository, installationDirectory, "structure101-build-java-all-" + this.version);
146+
return this.version;
182147
}
183148

184149
private void copyZipToFilesystem(String source, File destination, String name) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,14 +17,24 @@
1717
package s101;
1818

1919
import java.io.File;
20+
import java.util.regex.Matcher;
21+
import java.util.regex.Pattern;
2022

23+
import com.gargoylesoftware.htmlunit.WebClient;
24+
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
25+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
2126
import org.gradle.api.Project;
2227
import org.gradle.api.provider.Property;
2328
import org.gradle.api.tasks.Input;
2429
import org.gradle.api.tasks.InputDirectory;
2530

2631
public class S101PluginExtension {
2732
private final Property<String> licenseId;
33+
34+
private final Property<String> repository;
35+
36+
private final Property<String> version;
37+
2838
private final Property<File> installationDirectory;
2939
private final Property<File> configurationDirectory;
3040
private final Property<String> label;
@@ -65,6 +75,24 @@ public void setLabel(String label) {
6575
this.label.set(label);
6676
}
6777

78+
@Input
79+
public Property<String> getRepository() {
80+
return repository;
81+
}
82+
83+
public void setRepository(String repository) {
84+
this.repository.set(repository);
85+
}
86+
87+
@Input
88+
public Property<String> getVersion() {
89+
return this.version;
90+
}
91+
92+
public void setVersion(String version) {
93+
this.version.set(version);
94+
}
95+
6896
public S101PluginExtension(Project project) {
6997
this.licenseId = project.getObjects().property(String.class);
7098
if (project.hasProperty("s101.licenseId")) {
@@ -78,5 +106,31 @@ public S101PluginExtension(Project project) {
78106
if (project.hasProperty("s101.label")) {
79107
setLabel((String) project.findProperty("s101.label"));
80108
}
109+
this.repository = project.getObjects().property(String.class);
110+
if (project.hasProperty("s101.repository")) {
111+
setRepository((String) project.findProperty("s101.repository"));
112+
} else {
113+
setRepository("https://structure101.com/binaries/v6");
114+
}
115+
this.version = project.getObjects().property(String.class);
116+
if (project.hasProperty("s101.version")) {
117+
setVersion((String) project.findProperty("s101.version"));
118+
} else {
119+
try (final WebClient webClient = new WebClient()) {
120+
HtmlPage page = webClient.getPage(getRepository().get());
121+
Matcher matcher = null;
122+
for (HtmlAnchor anchor : page.getAnchors()) {
123+
Matcher candidate = Pattern.compile("(structure101-build-java-all-)(.*).zip").matcher(anchor.getHrefAttribute());
124+
if (candidate.find()) {
125+
matcher = candidate;
126+
}
127+
}
128+
if (matcher != null) {
129+
setVersion(matcher.group(2));
130+
}
131+
} catch (Exception ex) {
132+
throw new RuntimeException(ex);
133+
}
134+
}
81135
}
82136
}

0 commit comments

Comments
 (0)