forked from keycloak/keycloak-web
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (keycloak#499)
Closes keycloak#492 Signed-off-by: Jon Koops <[email protected]>
- Loading branch information
Showing
15 changed files
with
294 additions
and
66 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
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,23 @@ | ||
package org.keycloak.webbuilder.npm; | ||
|
||
import org.keycloak.webbuilder.utils.JsonParser; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/keycloak/webbuilder/npm/SemanticVersion.java
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,44 @@ | ||
package org.keycloak.webbuilder.npm; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class SemanticVersion { | ||
private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)$"); | ||
|
||
private final int major; | ||
private final int minor; | ||
private final int patch; | ||
|
||
private SemanticVersion(int major, int minor, int patch) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = patch; | ||
} | ||
|
||
public int getMajor() { | ||
return major; | ||
} | ||
|
||
public int getMinor() { | ||
return minor; | ||
} | ||
|
||
public int getPatch() { | ||
return patch; | ||
} | ||
|
||
public static SemanticVersion fromString(String versionString) { | ||
Matcher matcher = VERSION_PATTERN.matcher(versionString); | ||
|
||
if (!matcher.matches()) { | ||
return null; | ||
} | ||
|
||
int major = Integer.parseInt(matcher.group(1)); | ||
int minor = Integer.parseInt(matcher.group(2)); | ||
int patch = Integer.parseInt(matcher.group(3)); | ||
|
||
return new SemanticVersion(major, minor, patch); | ||
} | ||
} |
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,71 @@ | ||
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("version") | ||
private String version; | ||
|
||
@JsonProperty("main") | ||
private String main; | ||
|
||
@JsonProperty("exports") | ||
private Map<String, Export> exports; | ||
|
||
@JsonProperty("dist") | ||
private Dist dist; | ||
|
||
public SemanticVersion getSemanticVersion() { | ||
return SemanticVersion.fromString(version); | ||
} | ||
|
||
public Dist getDist() { | ||
return dist; | ||
} | ||
|
||
public String resolveEntryPoint(boolean useLegacy) { | ||
if (useLegacy) { | ||
return main; | ||
} | ||
|
||
Export defaultExport = exports.get("."); | ||
return defaultExport != null ? defaultExport.getDefaultPath() : null; | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public static class Export { | ||
@JsonProperty("default") | ||
private String defaultPath; | ||
|
||
public String getDefaultPath() { | ||
return defaultPath; | ||
} | ||
} | ||
|
||
@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()) | ||
) | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.