1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package s101 ;
18
18
19
19
import java .io .File ;
20
- import java .io .FileInputStream ;
21
20
import java .io .FileOutputStream ;
22
21
import java .io .IOException ;
23
22
import java .io .InputStream ;
34
33
import java .util .LinkedHashMap ;
35
34
import java .util .List ;
36
35
import java .util .Map ;
37
- import java .util .Properties ;
38
36
import java .util .Set ;
39
- import java .util .jar .JarEntry ;
40
- import java .util .jar .JarInputStream ;
41
- import java .util .regex .Matcher ;
42
37
import java .util .regex .Pattern ;
43
38
import java .util .zip .ZipEntry ;
44
39
import java .util .zip .ZipInputStream ;
45
40
46
- import com .gargoylesoftware .htmlunit .WebClient ;
47
- import com .gargoylesoftware .htmlunit .html .HtmlAnchor ;
48
- import com .gargoylesoftware .htmlunit .html .HtmlPage ;
49
41
import com .github .mustachejava .DefaultMustacheFactory ;
50
42
import com .github .mustachejava .Mustache ;
51
43
import com .github .mustachejava .MustacheFactory ;
@@ -71,6 +63,10 @@ public class S101Configurer {
71
63
72
64
private final Path licenseDirectory ;
73
65
66
+ private final String repository ;
67
+
68
+ private final String version ;
69
+
74
70
private final Project project ;
75
71
private final Logger logger ;
76
72
@@ -90,6 +86,9 @@ public S101Configurer(Project project) {
90
86
throw new UncheckedIOException (ex );
91
87
}
92
88
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 ();
93
92
}
94
93
95
94
public void license (String licenseId ) {
@@ -129,25 +128,7 @@ public void install(File installationDirectory, File configurationDirectory) {
129
128
130
129
public void configure (File installationDirectory , File configurationDirectory ) {
131
130
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 );
151
132
}
152
133
153
134
private boolean deleteDirectory (File directoryToBeDeleted ) {
@@ -161,24 +142,8 @@ private boolean deleteDirectory(File directoryToBeDeleted) {
161
142
}
162
143
163
144
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 ;
182
147
}
183
148
184
149
private void copyZipToFilesystem (String source , File destination , String name ) {
0 commit comments