-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache template directory in init command (#1896)
Adds caching of smithy init template directory in the default system temp directory. This greatly speeds up subsequent executions of both the list and create template subcommands of the smithy init.
- Loading branch information
Showing
8 changed files
with
330 additions
and
49 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
45 changes: 45 additions & 0 deletions
45
smithy-cli/src/main/java/software/amazon/smithy/cli/commands/CliCache.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,45 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.cli.commands; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import software.amazon.smithy.cli.CliError; | ||
import software.amazon.smithy.utils.IoUtils; | ||
|
||
interface CliCache { | ||
Path DEFAULT_TEMP_DIR = Paths.get(System.getProperty("java.io.tmpdir")); | ||
Path ROOT_CACHE_DIR = DEFAULT_TEMP_DIR.resolve("smithy-cache"); | ||
|
||
static CliCache getTemplateCache() { | ||
return () -> ROOT_CACHE_DIR.resolve("templates"); | ||
} | ||
|
||
Path getPath(); | ||
|
||
default boolean clear() { | ||
return IoUtils.rmdir(getPath()); | ||
} | ||
|
||
default Path get() { | ||
Path cachePath = getPath(); | ||
if (Files.exists(cachePath)) { | ||
return cachePath; | ||
} | ||
// If cache dir does not exist, create it and all required parent directories | ||
try { | ||
return Files.createDirectories(cachePath); | ||
} catch (IOException e) { | ||
throw new CliError("Could not create cache at path: " + cachePath); | ||
} | ||
} | ||
|
||
static boolean clearAll() { | ||
return IoUtils.rmdir(ROOT_CACHE_DIR); | ||
} | ||
} |
Oops, something went wrong.