Skip to content

Commit

Permalink
follow redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 4, 2024
1 parent 34252a0 commit 8e86ce5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
40 changes: 37 additions & 3 deletions core/src/main/java/lucee/runtime/mvn/POM.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import lucee.commons.io.res.Resource;
import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.SerializableObject;
import lucee.commons.lang.StringUtil;
import lucee.commons.tree.TreeNode;
import lucee.runtime.mvn.POMReader.Dependency;
import lucee.runtime.op.Caster;
Expand Down Expand Up @@ -83,6 +84,13 @@ public static POM getInstance(Resource localDirectory, String groupId, String ar
return getInstance(localDirectory, null, groupId, artifactId, version, null, null, dependencyScope, SCOPE_ALL, log);
}

/*
* public static void main(String[] args) throws IOException { Resource dir =
* ResourcesImpl.getFileResourceProvider().getResource("/Users/mic/tmp9/mvn/"); POM pom =
* getInstance(dir, "org.apache.maven", "maven-core", "3.8.1", SCOPE_COMPILE, null); pom.getJars();
* }
*/

public static POM getInstance(Resource localDirectory, Collection<Repository> repositories, String groupId, String artifactId, String version, int dependencyScope,
int dependencyScopeManagement, Log log) {
return getInstance(localDirectory, null, groupId, artifactId, version, null, null, dependencyScope, dependencyScopeManagement, log);
Expand Down Expand Up @@ -148,13 +156,25 @@ void initXML() throws IOException {
throw ioe;
}
this.packaging = reader.getPackaging();
boolean custom = true;
this.artifactExtension = this.packaging;
if (artifactExtension == null || "bundle".equalsIgnoreCase(artifactExtension)) this.artifactExtension = "jar";
if (artifactExtension == null || "bundle".equalsIgnoreCase(artifactExtension)) {
custom = false;
this.artifactExtension = "jar";
}

this.name = reader.getName();
this.description = reader.getDescription();
this.url = reader.getURL();

if (this.artifactExtension != null && !"pom".equalsIgnoreCase(this.artifactExtension)) MavenUtil.download(this, initRepositories, artifactExtension, log);
if (this.artifactExtension != null && !"pom".equalsIgnoreCase(this.artifactExtension)) {
try {
MavenUtil.download(this, initRepositories, artifactExtension, log);
}
catch (IOException ioe) {
if (!custom) throw ioe;
}
}

isInitXML = true;
}
Expand Down Expand Up @@ -384,14 +404,28 @@ public URL getArtifact(String type, Collection<Repository> repositories) throws
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
int responseCode = connection.getResponseCode();

if (responseCode == 200) {
return url;
}
// TODO handle having more than one redirect
else if (responseCode == 301 || responseCode == 302) {
String newUrl = connection.getHeaderField("Location");
if (!StringUtil.isEmpty(newUrl, true)) {
url = new URL(newUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
responseCode = connection.getResponseCode();
if (responseCode == 200) {
return url;
}
}
}
if (sb == null) sb = new StringBuilder();
else sb.append(", ");
sb.append(url.toExternalForm());
}
throw new IOException("could not find a valid endpoint for [" + this + "], possibles endpoint are [" + sb + "]");
throw new IOException("could not find a valid endpoint [" + this + "] for type [" + type + "], possibles endpoint are [" + sb + "]");
}

@Override
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.2.0.151-SNAPSHOT"/>
<property name="version" value="6.2.0.152-SNAPSHOT"/>

<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.2.0.151-SNAPSHOT</version>
<version>6.2.0.152-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down
4 changes: 2 additions & 2 deletions test/functions/createObject.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(Observable.just("Hello").blockingFirst()).toBe("Hello");
});

/*it( title = "Checking the createObject(..,javasettings:{maven:...}) with maven-core", body = function( currentSpec ) {
it( title = "Checking the createObject(..,javasettings:{maven:...}) with maven-core", body = function( currentSpec ) {
var MavenCli=createObject("java","org.apache.maven.cli.MavenCli",{
"maven":[
{
Expand All @@ -142,7 +142,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
]
});
expect(MavenCli.getClass().getSimpleName()).toEqual("MavenCli");
});*/
});



Expand Down

0 comments on commit 8e86ce5

Please sign in to comment.