2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 08:17:11 -07:00

Added support for getting bld snapshot distributions from the sonatype snapshots repo

This commit is contained in:
Geert Bevin 2023-05-10 22:13:17 -04:00
parent a04e441ada
commit c213e3df7d
5 changed files with 45 additions and 15 deletions

View file

2
.idea/modules.xml generated
View file

@ -2,8 +2,8 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/app.iml" filepath="$PROJECT_DIR$/.idea/app.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/bld.iml" filepath="$PROJECT_DIR$/.idea/bld.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/bld.iml" filepath="$PROJECT_DIR$/.idea/bld.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/framework.iml" filepath="$PROJECT_DIR$/.idea/framework.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View file

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Tests" type="JUnit" factoryName="JUnit"> <configuration default="false" name="Run Tests" type="JUnit" factoryName="JUnit">
<module name="framework" /> <module name="app" />
<option name="PACKAGE_NAME" value="rife" /> <option name="PACKAGE_NAME" value="rife" />
<option name="MAIN_CLASS_NAME" value="" /> <option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" /> <option name="METHOD_NAME" value="" />

View file

@ -4,6 +4,7 @@
*/ */
package rife.bld.dependencies; package rife.bld.dependencies;
import rife.bld.BldVersion;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException; import rife.tools.exceptions.FileUtilsErrorException;
@ -100,6 +101,7 @@ public abstract class ArtifactRetriever {
try { try {
var connection = new URL(artifact.location()).openConnection(); var connection = new URL(artifact.location()).openConnection();
connection.setUseCaches(false); connection.setUseCaches(false);
connection.setRequestProperty("User-Agent", "bld " + BldVersion.getVersion());
if (artifact.repository().username() != null && artifact.repository().password() != null) { if (artifact.repository().username() != null && artifact.repository().password() != null) {
connection.setRequestProperty( connection.setRequestProperty(
HEADER_AUTHORIZATION, HEADER_AUTHORIZATION,

View file

@ -31,7 +31,9 @@ import static rife.tools.FileUtils.JAVA_FILE_PATTERN;
*/ */
public class Wrapper { public class Wrapper {
static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/"; static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
static final String SONATYPE_SNAPSHOTS = "https://s01.oss.sonatype.org/content/repositories/snapshots/";
static final String DOWNLOAD_LOCATION = MAVEN_CENTRAL + "com/uwyn/rife2/bld/${version}/"; static final String DOWNLOAD_LOCATION = MAVEN_CENTRAL + "com/uwyn/rife2/bld/${version}/";
static final String DOWNLOAD_LOCATION_SNAPSHOT = SONATYPE_SNAPSHOTS + "com/uwyn/rife2/bld/${version}/";
static final String BLD_FILENAME = "bld-${version}.jar"; static final String BLD_FILENAME = "bld-${version}.jar";
static final String BLD_SOURCES_FILENAME = "bld-${version}-sources.jar"; static final String BLD_SOURCES_FILENAME = "bld-${version}-sources.jar";
static final String BLD_VERSION = "BLD_VERSION"; static final String BLD_VERSION = "BLD_VERSION";
@ -49,6 +51,7 @@ public class Wrapper {
static final String PROPERTY_DOWNLOAD_EXTENSION_JAVADOC = "bld.downloadExtensionJavadoc"; static final String PROPERTY_DOWNLOAD_EXTENSION_JAVADOC = "bld.downloadExtensionJavadoc";
static final File BLD_USER_DIR = new File(System.getProperty("user.home"), ".bld"); static final File BLD_USER_DIR = new File(System.getProperty("user.home"), ".bld");
static final File DISTRIBUTIONS_DIR = new File(BLD_USER_DIR, "dist"); static final File DISTRIBUTIONS_DIR = new File(BLD_USER_DIR, "dist");
static final Pattern META_DATA_SNAPSHOT_VERSION = Pattern.compile("<snapshotVersion>.*?<value>([^<]+)</value>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
private File currentDir_ = new File(System.getProperty("user.dir")); private File currentDir_ = new File(System.getProperty("user.dir"));
@ -340,16 +343,24 @@ public class Wrapper {
return wrapperProperties_.getProperty(BLD_PROPERTY_VERSION, getVersion()); return wrapperProperties_.getProperty(BLD_PROPERTY_VERSION, getVersion());
} }
private String getWrapperDownloadLocation() { private boolean isSnapshot(String version) {
var location = wrapperProperties_.getProperty(BLD_PROPERTY_DOWNLOAD_LOCATION, DOWNLOAD_LOCATION); return version.endsWith("-SNAPSHOT");
if (location.trim().isBlank()) { }
return DOWNLOAD_LOCATION;
private String getWrapperDownloadLocation(String version) {
var default_location = DOWNLOAD_LOCATION;
if (isSnapshot(version)) {
default_location = DOWNLOAD_LOCATION_SNAPSHOT;
} }
return location; var location = wrapperProperties_.getProperty(BLD_PROPERTY_DOWNLOAD_LOCATION, default_location);
if (location.trim().isBlank()) {
location = default_location;
}
return replaceVersion(location, version);
} }
private String downloadUrl(String version, String fileName) { private String downloadUrl(String version, String fileName) {
var location = replaceVersion(getWrapperDownloadLocation(), version); var location = getWrapperDownloadLocation(version);
var result = new StringBuilder(location); var result = new StringBuilder(location);
if (!location.endsWith("/")) { if (!location.endsWith("/")) {
result.append("/"); result.append("/");
@ -386,16 +397,33 @@ public class Wrapper {
System.err.println("Failed to retrieve wrapper version number."); System.err.println("Failed to retrieve wrapper version number.");
throw e; throw e;
} }
var filename = bldFileName(version);
var distribution_file = new File(DISTRIBUTIONS_DIR, filename); var download_version = version;
if (!distribution_file.exists()) { if (isSnapshot(version)) {
downloadDistribution(distribution_file, downloadUrl(version, filename)); var mata_data_url = downloadUrl(version, "maven-metadata.xml");
String meta_data;
var meta_data_connection = new URL(mata_data_url).openConnection();
meta_data_connection.setUseCaches(false);
meta_data_connection.setRequestProperty("User-Agent", "bld " + version);
try (var in = meta_data_connection.getInputStream()) {
meta_data = new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
var matcher = META_DATA_SNAPSHOT_VERSION.matcher(meta_data);
if (matcher.find()) {
download_version = matcher.group(1);
}
} }
var sources_filename = bldSourcesFileName(version);
var distribution_sources_file = new File(DISTRIBUTIONS_DIR, sources_filename); var distribution_file = new File(DISTRIBUTIONS_DIR, bldFileName(version));
if (!distribution_file.exists()) {
downloadDistribution(distribution_file, downloadUrl(version, bldFileName(download_version)));
}
var distribution_sources_file = new File(DISTRIBUTIONS_DIR, bldSourcesFileName(version));
if (!distribution_sources_file.exists()) { if (!distribution_sources_file.exists()) {
try { try {
downloadDistribution(distribution_sources_file, downloadUrl(version, sources_filename)); downloadDistribution(distribution_sources_file, downloadUrl(version, bldSourcesFileName(download_version)));
} catch (IOException e) { } catch (IOException e) {
// this is not critical, ignore // this is not critical, ignore
} }