Skip to content

Commit

Permalink
allow to define s3 and maven update provider as system property/env var
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jan 12, 2024
1 parent 620bacf commit ffc41d9
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
70 changes: 43 additions & 27 deletions core/src/main/java/lucee/runtime/config/s3/S3UpdateProvider.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -73,7 +106,7 @@ public final class S3UpdateProvider extends DefaultHandler {

private static Map<String, Pair<Long, S3UpdateProvider>> 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;
Expand All @@ -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<Long, S3UpdateProvider> pair = readers.get(key);
Expand All @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.0.18-ALPHA"/>
<property name="version" value="6.1.0.19-ALPHA"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.0.18-ALPHA</version>
<version>6.1.0.19-ALPHA</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit ffc41d9

Please sign in to comment.