mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	Merge branch '5.8.x' into 6.1.x
Closes gh-14638
This commit is contained in:
		
						commit
						d80fade8b1
					
				| @ -106,5 +106,7 @@ tasks.register('cloneRepository', IncludeRepoTask) { | ||||
| } | ||||
| 
 | ||||
| s101 { | ||||
| 	repository = 'https://s101-pickup.s3.amazonaws.com' | ||||
| 	version = '7.0.24375' | ||||
| 	configurationDirectory = project.file("etc/s101") | ||||
| } | ||||
|  | ||||
| @ -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) { | ||||
|  | ||||
| @ -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. | ||||
|  | ||||
| @ -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<String> licenseId; | ||||
| 
 | ||||
| 	private final Property<String> repository; | ||||
| 
 | ||||
| 	private final Property<String> version; | ||||
| 
 | ||||
| 	private final Property<File> installationDirectory; | ||||
| 	private final Property<File> configurationDirectory; | ||||
| 	private final Property<String> label; | ||||
| @ -65,6 +75,24 @@ public class S101PluginExtension { | ||||
| 		this.label.set(label); | ||||
| 	} | ||||
| 
 | ||||
| 	@Input | ||||
| 	public Property<String> getRepository() { | ||||
| 		return repository; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setRepository(String repository) { | ||||
| 		this.repository.set(repository); | ||||
| 	} | ||||
| 
 | ||||
| 	@Input | ||||
| 	public Property<String> 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); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user