From ffc41d96641b123c30a35ff10cd6be1a09c2ded4 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Fri, 12 Jan 2024 18:30:11 +0100 Subject: [PATCH] allow to define s3 and maven update provider as system property/env var --- .../config/maven/MavenUpdateProvider.java | 65 +++++++++++++++-- .../runtime/config/s3/S3UpdateProvider.java | 70 ++++++++++++------- .../system/LuceeVersionsDetailS3.java | 2 +- .../functions/system/LuceeVersionsListS3.java | 2 +- loader/build.xml | 2 +- loader/pom.xml | 2 +- 6 files changed, 106 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/lucee/runtime/config/maven/MavenUpdateProvider.java b/core/src/main/java/lucee/runtime/config/maven/MavenUpdateProvider.java index 0a893f5e48..8d8ac8dd69 100644 --- a/core/src/main/java/lucee/runtime/config/maven/MavenUpdateProvider.java +++ b/core/src/main/java/lucee/runtime/config/maven/MavenUpdateProvider.java @@ -18,6 +18,7 @@ import org.osgi.framework.Version; import org.xml.sax.SAXException; +import lucee.commons.io.SystemUtil; import lucee.commons.lang.StringUtil; import lucee.commons.net.http.HTTPResponse; import lucee.commons.net.http.Header; @@ -30,31 +31,83 @@ public class MavenUpdateProvider { public static final int CONNECTION_TIMEOUT = 10000; - public static final String DEFAULT_LIST_PROVIDER = "https://oss.sonatype.org/service/local/lucene/search"; + private static final String DEFAULT_LIST_PROVIDER = "https://oss.sonatype.org/service/local/lucene/search"; // public static final String DEFAULT_REPOSITORY = "https://repo1.maven.org/maven2"; // public static final String DEFAULT_REPOSITORY_SNAPSHOT = // "https://oss.sonatype.org/service/local/repositories/snapshots/content"; // public static final String DEFAULT_REPOSITORY_RELEASES = // "https://oss.sonatype.org/service/local/repositories/releases/content"; - public static final String DEFAULT_REPOSITORY_SNAPSHOT = "https://oss.sonatype.org/content/repositories/snapshots/"; + private static final String DEFAULT_REPOSITORY_SNAPSHOT = "https://oss.sonatype.org/content/repositories/snapshots/"; // public static final String DEFAULT_REPOSITORY_RELEASES = // "https://oss.sonatype.org/content/repositories/releases/"; - public static final String DEFAULT_REPOSITORY_RELEASES = "https://oss.sonatype.org/service/local/repositories/releases/content/"; + private static final String DEFAULT_REPOSITORY_RELEASES = "https://oss.sonatype.org/service/local/repositories/releases/content/"; public static final String DEFAULT_GROUP = "org.lucee"; public static final String DEFAULT_ARTIFACT = "lucee"; + private static String defaultListProvider; + private static String defaultRepositoryReleases; + private static String defaultRepositorySnapshots; + private String listProvider; private String group; private String artifact; private String repoSnapshots; private String repoReleases; + public static String getDefaultListProvider() { + if (defaultListProvider == null) { + String str = SystemUtil.getSystemPropOrEnvVar("lucee.mvn.provider.list", null); + if (!StringUtil.isEmpty(str, true)) { + try { + new URL(str.trim()); + defaultListProvider = str.trim(); + } + catch (Exception e) { + } + } + if (defaultListProvider == null) defaultListProvider = DEFAULT_LIST_PROVIDER; + } + return defaultListProvider; + } + + public static String getDefaultRepositoryReleases() { + if (defaultRepositoryReleases == null) { + String str = SystemUtil.getSystemPropOrEnvVar("lucee.mvn.repo.releases", null); + if (!StringUtil.isEmpty(str, true)) { + try { + new URL(str.trim()); + defaultRepositoryReleases = str.trim(); + } + catch (Exception e) { + } + } + if (defaultRepositoryReleases == null) defaultRepositoryReleases = DEFAULT_REPOSITORY_RELEASES; + } + return defaultRepositoryReleases; + } + + public static String getDefaultRepositorySnapshots() { + if (defaultRepositorySnapshots == null) { + String str = SystemUtil.getSystemPropOrEnvVar("lucee.mvn.repo.snapshots", null); + if (!StringUtil.isEmpty(str, true)) { + try { + new URL(str.trim()); + defaultRepositorySnapshots = str.trim(); + } + catch (Exception e) { + } + } + if (defaultRepositorySnapshots == null) defaultRepositorySnapshots = DEFAULT_REPOSITORY_SNAPSHOT; + } + return defaultRepositorySnapshots; + } + public MavenUpdateProvider() { - this.listProvider = DEFAULT_LIST_PROVIDER; - this.repoSnapshots = DEFAULT_REPOSITORY_SNAPSHOT; - this.repoReleases = DEFAULT_REPOSITORY_RELEASES; + this.listProvider = getDefaultListProvider(); + this.repoSnapshots = getDefaultRepositorySnapshots(); + this.repoReleases = getDefaultRepositoryReleases(); this.group = DEFAULT_GROUP; this.artifact = DEFAULT_ARTIFACT; } diff --git a/core/src/main/java/lucee/runtime/config/s3/S3UpdateProvider.java b/core/src/main/java/lucee/runtime/config/s3/S3UpdateProvider.java index b38450bee0..7485a3247a 100644 --- a/core/src/main/java/lucee/runtime/config/s3/S3UpdateProvider.java +++ b/core/src/main/java/lucee/runtime/config/s3/S3UpdateProvider.java @@ -1,6 +1,5 @@ package lucee.runtime.config.s3; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -26,6 +25,7 @@ import org.xml.sax.helpers.DefaultHandler; import lucee.commons.io.IOUtil; +import lucee.commons.io.SystemUtil; import lucee.commons.lang.Pair; import lucee.commons.lang.StringUtil; import lucee.commons.net.http.HTTPResponse; @@ -43,17 +43,50 @@ public final class S3UpdateProvider extends DefaultHandler { public static final int CONNECTION_TIMEOUT = 1000; private static final long MAX_AGE = 10000; - // public static URL DEFAULT_PROVIDER = null; - public static URL DEFAULT_PROVIDER_LIST = null; - public static URL[] DEFAULT_PROVIDER_DETAILS = null; + + private static URL DEFAULT_PROVIDER_LIST = null; + private static URL[] DEFAULT_PROVIDER_DETAILS = null; + + private static URL defaultProviderList; + private static URL[] defaultProviderDetail; static { try { DEFAULT_PROVIDER_LIST = new URL("https://lucee-downloads.s3.amazonaws.com/"); DEFAULT_PROVIDER_DETAILS = new URL[] { new URL("https://cdn.lucee.org/"), DEFAULT_PROVIDER_LIST }; } - catch (MalformedURLException e) { + catch (Exception e) { + } + } + + public static URL getDefaultProviderList() { + if (defaultProviderList == null) { + String str = SystemUtil.getSystemPropOrEnvVar("lucee.s3.provider.list", null); + if (!StringUtil.isEmpty(str, true)) { + try { + defaultProviderList = new URL(str.trim()); + } + catch (Exception e) { + } + } + if (defaultProviderList == null) defaultProviderList = DEFAULT_PROVIDER_LIST; + } + return defaultProviderList; + } + + public static URL[] getDefaultProviderDetail() { + if (defaultProviderDetail == null) { + String str = SystemUtil.getSystemPropOrEnvVar("lucee.s3.provider.detail", null); + if (!StringUtil.isEmpty(str, true)) { + try { + defaultProviderDetail = new URL[] { new URL(str.trim()) }; + } + catch (Exception e) { + } + } + if (defaultProviderDetail == null) defaultProviderDetail = DEFAULT_PROVIDER_DETAILS; } + return defaultProviderDetail; } private XMLReader xmlReader; @@ -73,7 +106,7 @@ public final class S3UpdateProvider extends DefaultHandler { private static Map> readers = new HashMap<>(); - public S3UpdateProvider(URL list, URL[] details) throws MalformedURLException { + private S3UpdateProvider(URL list, URL[] details) throws MalformedURLException { if (!list.toExternalForm().endsWith("/")) this.url = new URL(list.toExternalForm() + "/"); else this.url = list; @@ -84,6 +117,10 @@ public S3UpdateProvider(URL list, URL[] details) throws MalformedURLException { this.details = details; } + public static S3UpdateProvider getInstance() throws MalformedURLException { + return getInstance(getDefaultProviderList(), getDefaultProviderDetail()); + } + public static S3UpdateProvider getInstance(URL list, URL[] details) throws MalformedURLException { String key = toKey(list, details); Pair pair = readers.get(key); @@ -103,27 +140,6 @@ private static String toKey(URL list, URL[] details) { return sb.toString(); } - /* - * public static void main(String[] args) throws Exception { - * print.e(ListBucketReader.getInstance(DEFAULT_PROVIDER).read().size()); - * print.e("-------------------"); - * print.e(ListBucketReader.getInstance(DEFAULT_PROVIDER).read().size()); - * print.e("-------------------"); - * print.e(ListBucketReader.getInstance(DEFAULT_PROVIDER).read().size()); - * - * } - */ - - public static void main(String[] args) throws Exception { - String path = "/Users/mic/tmp8/eeee/tmp.jar"; - IOUtil.copy(S3UpdateProvider.getInstance(DEFAULT_PROVIDER_LIST, DEFAULT_PROVIDER_DETAILS).getCore(OSGiUtil.toVersion("5.4.1.8")), new FileOutputStream(path), true, true); - String path2 = "/Users/mic/tmp8/eeee/tmp2.jar"; - IOUtil.copy(S3UpdateProvider.getInstance(DEFAULT_PROVIDER_LIST, DEFAULT_PROVIDER_DETAILS).getCore(OSGiUtil.toVersion("6.0.1.2-SNAPSHOT")), new FileOutputStream(path2), - true, true); - - // lucee-6.0.1.2-SNAPSHOT - } - public InputStream getCore(Version version) throws PageException, MalformedURLException, IOException, GeneralSecurityException, SAXException { for (Element e: read()) { if (version.equals(e.getVersion())) { diff --git a/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsDetailS3.java b/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsDetailS3.java index 1e9143c3c3..c12c16fb70 100644 --- a/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsDetailS3.java +++ b/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsDetailS3.java @@ -25,7 +25,7 @@ public static Struct call(PageContext pc, String version) throws PageException { try { Version v = OSGiUtil.toVersion(version); - S3UpdateProvider sup = S3UpdateProvider.getInstance(S3UpdateProvider.DEFAULT_PROVIDER_LIST, S3UpdateProvider.DEFAULT_PROVIDER_DETAILS); + S3UpdateProvider sup = S3UpdateProvider.getInstance(); for (Element e: sup.read()) { if (v.equals(e.getVersion())) { Struct sct = new StructImpl(); diff --git a/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsListS3.java b/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsListS3.java index 08f4fb77c2..ef35e8fe8b 100644 --- a/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsListS3.java +++ b/core/src/main/java/lucee/runtime/functions/system/LuceeVersionsListS3.java @@ -53,7 +53,7 @@ else throw new FunctionException(pc, "MavenListVersions", 1, "type", } Key ETAG = KeyImpl.init("etag"); try { - S3UpdateProvider sup = S3UpdateProvider.getInstance(S3UpdateProvider.DEFAULT_PROVIDER_LIST, S3UpdateProvider.DEFAULT_PROVIDER_DETAILS); + S3UpdateProvider sup = S3UpdateProvider.getInstance(); String key; // just the latest of every cycle if (latest) { diff --git a/loader/build.xml b/loader/build.xml index 086d1a0101..30097a1f0f 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index fcc35dbde8..7afa78a26b 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.1.0.18-ALPHA + 6.1.0.19-ALPHA jar Lucee Loader Build