-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve Keycloak JS from NPM package metadata
Closes #492 Signed-off-by: Jon Koops <[email protected]>
- Loading branch information
Showing
11 changed files
with
150 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
src/main/java/org/keycloak/webbuilder/misc/NpmPackageInfo.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.keycloak.webbuilder.npm; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Map; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Package { | ||
@JsonProperty("dist-tags") | ||
private Map<String, String> distTags; | ||
|
||
@JsonProperty("versions") | ||
private Map<String, Version> versions; | ||
|
||
public Version getVersionByTag(String tag) { | ||
String versionName = distTags.get(tag); | ||
return versions.get(versionName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.keycloak.webbuilder.npm; | ||
|
||
import org.keycloak.webbuilder.utils.JsonParser; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
public class Registry { | ||
public static URI REGISTRY_URI; | ||
|
||
static { | ||
try { | ||
REGISTRY_URI = new URI("https://registry.npmjs.org"); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static Package getPackage(String name) throws MalformedURLException { | ||
return JsonParser.read(REGISTRY_URI.resolve("./" + name).toURL(), Package.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.keycloak.webbuilder.npm; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.apache.commons.compress.archivers.ArchiveInputStream; | ||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; | ||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; | ||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Version { | ||
@JsonProperty("dist") | ||
private Dist dist; | ||
|
||
@JsonProperty("module") | ||
private String module; | ||
|
||
@JsonProperty | ||
private Map<String, Export> exports; | ||
|
||
public Dist getDist() { | ||
return dist; | ||
} | ||
|
||
public String resolveEntryPoint() { | ||
if (module != null) { | ||
return module; | ||
} | ||
|
||
Export defaultExport = exports.get("."); | ||
return defaultExport != null ? defaultExport.getDefaultPath() : null; | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public static class Dist { | ||
@JsonProperty("tarball") | ||
private String tarball; | ||
|
||
public ArchiveInputStream<TarArchiveEntry> getTarballStream() throws IOException { | ||
URL url = new URL(tarball); | ||
|
||
return new TarArchiveInputStream( | ||
new GzipCompressorInputStream( | ||
new BufferedInputStream(url.openStream()) | ||
) | ||
); | ||
} | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public static class Export { | ||
@JsonProperty("default") | ||
private String defaultPath; | ||
|
||
public String getDefaultPath() { | ||
return defaultPath; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters