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.
1717package s101 ;
1818
1919import java .io .File ;
20- import java .io .FileInputStream ;
2120import java .io .FileOutputStream ;
2221import java .io .IOException ;
2322import java .io .InputStream ;
3433import java .util .LinkedHashMap ;
3534import java .util .List ;
3635import java .util .Map ;
37- import java .util .Properties ;
3836import java .util .Set ;
39- import java .util .jar .JarEntry ;
40- import java .util .jar .JarInputStream ;
41- import java .util .regex .Matcher ;
4237import java .util .regex .Pattern ;
4338import java .util .zip .ZipEntry ;
4439import 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 ;
4941import com .github .mustachejava .DefaultMustacheFactory ;
5042import com .github .mustachejava .Mustache ;
5143import 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 ) {
0 commit comments