-
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.
Remove legacy code for older versions of Keycloak JS
Closes #500 Signed-off-by: Jon Koops <[email protected]>
- Loading branch information
Showing
14 changed files
with
148 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.keycloak.webbuilder; | ||
|
||
import org.keycloak.webbuilder.utils.JsonParser; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ImportMap { | ||
private final String FILE_NAME = "import-map.json"; | ||
|
||
private Path targetDir = null; | ||
private String value; | ||
|
||
public ImportMap(Path targetDir) { | ||
this.targetDir = targetDir; | ||
} | ||
|
||
public String getValue() throws Exception { | ||
// Return cached value if present. | ||
if (value != null) { | ||
return value; | ||
} | ||
|
||
// Read import map from disk and cache. | ||
Path source = targetDir.resolve(FILE_NAME); | ||
value = Files.readString(source); | ||
return value; | ||
} | ||
|
||
public void writeValue(Map<String, String> imports) throws Exception { | ||
// Create target directory if needed. | ||
Files.createDirectories(targetDir); | ||
|
||
// Build import map from installed packages. | ||
Map<String, Map<String, String>> importMap = new HashMap<>(); | ||
importMap.put("imports", imports); | ||
|
||
// Write import map to disk. | ||
Path target = targetDir.resolve(FILE_NAME); | ||
JsonParser.write(target.toFile(), importMap); | ||
} | ||
} |
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
51 changes: 0 additions & 51 deletions
51
src/main/java/org/keycloak/webbuilder/builders/AppBuilder.java
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
src/main/java/org/keycloak/webbuilder/builders/VendorBuilder.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,80 @@ | ||
package org.keycloak.webbuilder.builders; | ||
|
||
import org.apache.commons.compress.archivers.ArchiveEntry; | ||
import org.apache.commons.compress.archivers.ArchiveInputStream; | ||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; | ||
import org.keycloak.webbuilder.npm.Package; | ||
import org.keycloak.webbuilder.npm.Registry; | ||
import org.keycloak.webbuilder.npm.Version; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class VendorBuilder extends AbstractBuilder { | ||
private final Set<String> ALLOWED_EXTENSIONS = Set.of("js"); | ||
|
||
private final Map<String, String> imports = new HashMap<>(); | ||
|
||
@Override | ||
protected void build() throws Exception { | ||
// Install packages. | ||
installPackage("keycloak-js", "latest"); | ||
// Write import map to disk. | ||
context.getImportMap().writeValue(imports); | ||
} | ||
|
||
private void installPackage(String name, String version) throws Exception { | ||
// Resolve installation path and create directories. | ||
Path installationPath = context.getTargetDir().toPath().resolve("vendor").resolve(name); | ||
Files.createDirectories(installationPath); | ||
|
||
// Get package contents as tarball stream. | ||
Package packageInfo = Registry.getPackage(name); | ||
Version latestVersion = packageInfo.getVersionByTag(version); | ||
ArchiveInputStream<TarArchiveEntry> tarball = latestVersion.getDist().getTarballStream(); | ||
|
||
// Copy package contents to installation path. | ||
ArchiveEntry entry; | ||
while ((entry = tarball.getNextEntry()) != null) { | ||
// Skip any files not part of the package contents. | ||
String packagePrefix = "package"; | ||
if (!entry.getName().startsWith(packagePrefix)) { | ||
continue; | ||
} | ||
|
||
// Resolve path without 'package' prefix. | ||
Path entryPath = Path.of(packagePrefix).relativize(Path.of(entry.getName())); | ||
|
||
// Skip file if it's extension is not permitted. | ||
String extension = getFileExtension(entryPath.getFileName().toString()); | ||
if(!ALLOWED_EXTENSIONS.contains(extension)) { | ||
continue; | ||
} | ||
|
||
// Resolve target path and copy file. | ||
Path targetPath = installationPath.resolve(entryPath); | ||
Files.createDirectories(targetPath.getParent()); | ||
Files.copy(tarball, targetPath); | ||
} | ||
|
||
// Add package to the imports so it can be written to the import map later. | ||
Path importPath = Path.of("/vendor", name, latestVersion.resolveEntryPoint()).normalize(); | ||
imports.put(name, importPath.toString()); | ||
} | ||
|
||
private String getFileExtension(String filename) { | ||
int dotIndex = filename.lastIndexOf("."); | ||
if (dotIndex >= 0) { | ||
return filename.substring(dotIndex + 1); | ||
} | ||
return ""; | ||
} | ||
|
||
@Override | ||
protected String getTitle() { | ||
return "Vendor"; | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
src/main/java/org/keycloak/webbuilder/npm/SemanticVersion.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
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
Oops, something went wrong.