Skip to content

Commit

Permalink
Incorporate PR feedback on run plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Mar 16, 2023
1 parent 17dc64b commit b2b952a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
19 changes: 14 additions & 5 deletions docs/source-2.0/guides/building-models/build-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ or include parameters and operations that are available to only a subset of
their customers.

Projections are defined in the smithy-build.json file in the ``projections``
property. Projection names MUST match the following pattern: ``^[A-Za-z0-9\-_.]+$``.
property. Projection names MUST match the following pattern:

.. code-block::
^[A-Za-z0-9]+[A-Za-z0-9\\-_.]*$
A projection accepts the following configuration:

Expand Down Expand Up @@ -1662,7 +1666,11 @@ every projection. Projections that define plugins of the same name as a
top-level plugin completely overwrite the top-level plugin for that projection;
projection settings are not merged in any way.

Plugin names MUST match the following pattern: ``^[A-Za-z0-9\-_.]+$``.
Plugin names MUST match the following pattern:

.. code-block::
^[A-Za-z0-9]+[A-Za-z0-9\\-_.]*(::[A-Za-z0-9]+[A-Za-z0-9\\-_.]*)?$
smithy-build will attempt to resolve plugin names using `Java SPI`_
to locate an instance of ``software.amazon.smithy.build.SmithyBuildPlugin``
Expand Down Expand Up @@ -1752,9 +1760,10 @@ The ``run`` plugin supports the following properties:
- **REQUIRED** The name of the program to run, followed by an optional
list of arguments. If the command uses a relative path, Smithy will
first check if the command can be found relative to the current working
directory. Otherwise, the program must be available on the ``$PATH`` or
use an absolute path. No arguments are sent other than the arguments
configured in the ``command`` setting.
directory. Otherwise, the program must use an absolute path or be
available on the user's ``$PATH`` if Unix-like environments or its
equivalent in other operating systems. No arguments are sent other
than the arguments configured in the ``command`` setting.
* - env
- ``Map<String, String>``
- A map of environment variables to send to the process. The process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void loadsFromNodeIgnoringBadSourceLocations() throws IOException {
.expectObjectNode();
SmithyBuildConfig config = SmithyBuildConfig.fromNode(value);

Path cwd = Paths.get(".").normalize().toAbsolutePath();
Path cwd = SmithyBuildUtils.getCurrentWorkingDirectory();

assertThat(config.getImports(), contains(cwd.resolve("foo.json").toString()));
assertThat(config.getProjections().get("a").getImports(), contains(cwd.resolve("baz.json").toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public final class IoUtils {

private static final Logger LOGGER = Logger.getLogger(IoUtils.class.getName());
private static final int BUFFER_SIZE = 1024 * 4;
private static final int BUFFER_SIZE = 1024 * 8;

private IoUtils() {}

Expand Down Expand Up @@ -276,7 +276,7 @@ public static int runCommand(
if (input != null) {
OutputStream outputStream = process.getOutputStream();
copyInputToOutput(input, outputStream);
closeAndFlushStream(args, outputStream);
quietlyCloseStream(args, outputStream);
}

try (BufferedReader bufferedStdoutReader = new BufferedReader(
Expand All @@ -295,20 +295,18 @@ public static int runCommand(

// Can be replaced with InputStream#transferTo in Java 9+.
private static void copyInputToOutput(InputStream source, OutputStream sink) throws IOException {
byte[] buffer = new byte[8192];
byte[] buffer = new byte[BUFFER_SIZE];
int read;
while ((read = source.read(buffer, 0, 8192)) >= 0) {
while ((read = source.read(buffer, 0, BUFFER_SIZE)) >= 0) {
sink.write(buffer, 0, read);
}
}

private static void closeAndFlushStream(List<String> args, OutputStream outputStream) {
private static void quietlyCloseStream(List<String> args, OutputStream outputStream) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
// TODO: Why is this necessary?
LOGGER.log(Level.WARNING, "Unable to close and flush outputStream for " + args, e);
LOGGER.log(Level.WARNING, "Unable to close outputStream for " + args, e);
}
}

Expand Down

0 comments on commit b2b952a

Please sign in to comment.