diff --git a/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts b/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts index 4f17a1082e5..d207b018c79 100644 --- a/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts @@ -21,7 +21,7 @@ spotless { removeUnusedImports() importOrder("\\#", "") // Ignore generated code for formatter check - targetExclude("**/build/**/*.*") + targetExclude("*/build/**/*.*") } // Formatting for build.gradle.kts files diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java b/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java index fb80521d1ec..c1f3b1a947d 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/DefaultFileManifest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.io.BufferedReader; @@ -62,8 +51,8 @@ public Path addFile(Path path) { try { Files.createDirectories(parent); } catch (IOException e) { - throw new SmithyBuildException(String.format( - "Error create directory `%s`: %s", parent, e.getMessage())); + throw new SmithyBuildException( + String.format("Error create directory `%s`: %s", parent, e.getMessage())); } } @@ -76,7 +65,7 @@ public Path writeFile(Path path, Reader fileContentsReader) { path = addFile(path); try (BufferedReader bufferedReader = new BufferedReader(fileContentsReader); - BufferedWriter writer = Files.newBufferedWriter(path)) { + BufferedWriter writer = Files.newBufferedWriter(path)) { int len; char[] buffer = new char[4096]; while ((len = bufferedReader.read(buffer)) != -1) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java b/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java index 810cce10829..029a49ae8a1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/FileManifest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.io.IOException; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java b/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java index 83f03755d7c..0bed7e893fc 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/JsonSubstitutions.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.Map; @@ -93,7 +82,9 @@ protected Node getDefault(Node value) { @Override public Node arrayNode(ArrayNode node) { - return node.getElements().stream().map(element -> element.accept(this)).collect(ArrayNode.collect()); + return node.getElements().stream() + .map(element -> element.accept(this)) + .collect(ArrayNode.collect()); } @Override diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java b/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java index 83c05d78d85..20d6bd4959a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/MockManifest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.io.ByteArrayOutputStream; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java b/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java index f2408bd58a7..85fe3223adf 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/PluginContext.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; @@ -210,7 +199,8 @@ public Set getSources() { * @return Returns true if this shape is considered a source shape. */ public boolean isSourceShape(ToShapeId shape) { - return originalModel == null || isSource(originalModel.getShape(shape.toShapeId()).orElse(null)); + return originalModel == null + || isSource(originalModel.getShape(shape.toShapeId()).orElse(null)); } /** @@ -223,7 +213,8 @@ public boolean isSourceShape(ToShapeId shape) { * @return Returns true if this metadata is considered a source entry. */ public boolean isSourceMetadata(String metadataKey) { - return originalModel == null || isSource(originalModel.getMetadataProperty(metadataKey).orElse(null)); + return originalModel == null + || isSource(originalModel.getMetadataProperty(metadataKey).orElse(null)); } private boolean isSource(FromSourceLocation sourceLocation) { @@ -254,7 +245,7 @@ private int findOffsetFromStart(String location) { @Override public Builder toBuilder() { - Builder builder = builder() + Builder builder = builder() .model(model) .events(events) .settings(settings) diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java b/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java index ca71f9eab1d..f1aa3ba66cd 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/PluginId.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.Objects; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java index 32fba746d0b..18d0aa18d78 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.List; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java index beac1186a97..954a951c5ca 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/ProjectionTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.HashMap; @@ -75,8 +64,7 @@ static Function> createServiceFactory() * @return Returns the created factory. */ static Function> createServiceFactory( - Iterable transformers - ) { + Iterable transformers) { Map map = new HashMap<>(); for (ProjectionTransformer transformer : transformers) { map.put(transformer.getName(), transformer); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java index 6c6429eca48..6fa014a4136 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.FileSystems; @@ -138,7 +127,9 @@ public SmithyBuildResult build() { message.append(System.lineSeparator()).append(System.lineSeparator()); for (Map.Entry e : errors.entrySet()) { - message.append("(").append(e.getKey()).append("): ") + message.append("(") + .append(e.getKey()) + .append("): ") .append(e.getValue()) .append(System.lineSeparator()); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java index ff665ee93b6..3c153f66283 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java index 6488aafd448..c7b60e2f512 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildImpl.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; @@ -57,8 +46,7 @@ final class SmithyBuildImpl { private static final Pattern PATTERN = Pattern.compile("^" + PATTERN_PART + "$"); // Must start with letter/number. Allows for optional artifact name: plugin-name::artifact-name - private static final Pattern PLUGIN_PATTERN = Pattern - .compile("^" + PATTERN_PART + "(::" + PATTERN_PART + ")?$"); + private static final Pattern PLUGIN_PATTERN = Pattern.compile("^" + PATTERN_PART + "(::" + PATTERN_PART + ")?$"); private final SmithyBuildConfig config; private final Function fileManifestFactory; @@ -89,24 +77,17 @@ private static final class ResolvedPlugin { SmithyBuildImpl(SmithyBuild builder) { config = prepareConfig(SmithyBuilder.requiredState("config", builder.config)); sources = builder.sources; - fileManifestFactory = builder.fileManifestFactory != null - ? builder.fileManifestFactory - : FileManifest::create; - modelAssemblerSupplier = builder.modelAssemblerSupplier != null - ? builder.modelAssemblerSupplier - : Model::assembler; - modelTransformer = builder.modelTransformer != null - ? builder.modelTransformer - : ModelTransformer.create(); + fileManifestFactory = builder.fileManifestFactory != null ? builder.fileManifestFactory : FileManifest::create; + modelAssemblerSupplier = + builder.modelAssemblerSupplier != null ? builder.modelAssemblerSupplier : Model::assembler; + modelTransformer = builder.modelTransformer != null ? builder.modelTransformer : ModelTransformer.create(); transformFactory = builder.transformFactory != null ? builder.transformFactory : ProjectionTransformer.createServiceFactory(getClass().getClassLoader()); pluginFactory = builder.pluginFactory != null ? builder.pluginFactory : SmithyBuildPlugin.createServiceFactory(getClass().getClassLoader()); - model = builder.model != null - ? builder.model - : Model.builder().build(); + model = builder.model != null ? builder.model : Model.builder().build(); if (builder.outputDirectory != null) { outputDirectory = builder.outputDirectory; @@ -146,8 +127,10 @@ private static SmithyBuildConfig prepareConfig(SmithyBuildConfig config) { for (Map.Entry entry : config.getProjections().entrySet()) { String projectionName = entry.getKey(); if (!PATTERN.matcher(projectionName).matches()) { - throw new SmithyBuildException(String.format("Invalid Smithy build projection name `%s`. " - + "Projection names must match the following regex: %s", projectionName, PATTERN)); + throw new SmithyBuildException(String.format( + "Invalid Smithy build projection name `%s`. " + + "Projection names must match the following regex: %s", + projectionName, PATTERN)); } entry.getValue().getPlugins().keySet().forEach(p -> validatePluginName(entry.getKey(), p)); entry.getValue().getTransforms().forEach(t -> validateTransformName(entry.getKey(), t.getName())); @@ -158,8 +141,10 @@ private static SmithyBuildConfig prepareConfig(SmithyBuildConfig config) { private static void validateTransformName(String projection, String transformName) { if (!PATTERN.matcher(transformName).matches()) { - throw new SmithyBuildException(String.format("Invalid transform name `%s` found in the `%s` projection. " - + " Transform names must match the following regex: %s", transformName, projection, PATTERN)); + throw new SmithyBuildException(String.format( + "Invalid transform name `%s` found in the `%s` projection. " + + " Transform names must match the following regex: %s", + transformName, projection, PATTERN)); } } @@ -167,14 +152,14 @@ private static void validatePluginName(String projection, String plugin) { if (!PLUGIN_PATTERN.matcher(plugin).matches()) { throw new SmithyBuildException(String.format( "Invalid plugin name `%s` found in the `%s` projection. " - + " Plugin names must match the following regex: %s", plugin, projection, PLUGIN_PATTERN)); + + " Plugin names must match the following regex: %s", + plugin, projection, PLUGIN_PATTERN)); } } void applyAllProjections( Consumer projectionResultConsumer, - BiConsumer projectionExceptionConsumer - ) { + BiConsumer projectionExceptionConsumer) { ValidatedResult resolvedModel = createBaseModel(); // Some plugins need things like file locks and can't be run in parallel with other plugins. @@ -194,12 +179,22 @@ void applyAllProjections( List resolvedPlugins = resolvePlugins(projectionName, config); if (areAnyResolvedPluginsSerial(resolvedPlugins)) { - executeSerialProjection(resolvedModel, projectionName, config, resolvedPlugins, - projectionResultConsumer, projectionExceptionConsumer); + executeSerialProjection( + resolvedModel, + projectionName, + config, + resolvedPlugins, + projectionResultConsumer, + projectionExceptionConsumer); } else { parallelProjections.add(() -> { - executeSerialProjection(resolvedModel, projectionName, config, resolvedPlugins, - projectionResultConsumer, projectionExceptionConsumer); + executeSerialProjection( + resolvedModel, + projectionName, + config, + resolvedPlugins, + projectionResultConsumer, + projectionExceptionConsumer); }); } } @@ -216,7 +211,8 @@ private List resolvePlugins(String projectionName, ProjectionCon Set seenArtifactNames = new HashSet<>(); List resolvedPlugins = new ArrayList<>(); - for (Map.Entry pluginEntry : getCombinedPlugins(config).entrySet()) { + for (Map.Entry pluginEntry : + getCombinedPlugins(config).entrySet()) { PluginId id = PluginId.from(pluginEntry.getKey()); if (!seenArtifactNames.add(id.getArtifactName())) { throw new SmithyBuildException(String.format( @@ -245,8 +241,8 @@ private Optional createPlugin(String projectionName, PluginId } String message = "Unable to find a plugin for `" + id + "` in the `" + projectionName + "` " - + "projection. Is this the correct spelling? Are you missing a dependency? Is your " - + "classpath configured correctly?"; + + "projection. Is this the correct spelling? Are you missing a dependency? Is your " + + "classpath configured correctly?"; if (config.isIgnoreMissingPlugins()) { LOGGER.severe(message); @@ -271,8 +267,7 @@ private void executeSerialProjection( ProjectionConfig config, List resolvedPlugins, Consumer projectionResultConsumer, - BiConsumer projectionExceptionConsumer - ) { + BiConsumer projectionExceptionConsumer) { // Errors that occur while invoking the result callback must not // cause the exception callback to be invoked. ProjectionResult result = null; @@ -302,8 +297,8 @@ private ProjectionResult applyProjection( String projectionName, ProjectionConfig projection, ValidatedResult baseModel, - List resolvedPlugins - ) throws Throwable { + List resolvedPlugins) + throws Throwable { Model resolvedModel = baseModel.unwrap(); LOGGER.fine(() -> String.format("Creating the `%s` projection", projectionName)); @@ -319,8 +314,7 @@ private ProjectionResult applyProjection( // Fail if the model can't be merged with the imports. if (baseModel.isBroken() || !baseModel.getResult().isPresent()) { LOGGER.severe(String.format( - "The model could not be merged with the following imports: [%s]", - projection.getImports())); + "The model could not be merged with the following imports: [%s]", projection.getImports())); return ProjectionResult.builder() // Create an empty model so that ProjectionResult can be created when // the Model can't be assembled. @@ -342,10 +336,14 @@ private ProjectionResult applyProjection( // Don't do another round of validation and transforms if there are no transforms. // This is the case on the source projection, for example. if (!projection.getTransforms().isEmpty()) { - LOGGER.fine(() -> String.format("Applying transforms to projection %s: %s", projectionName, - projection.getTransforms().stream().map(TransformConfig::getName).collect(Collectors.toList()))); - projectedModel = applyProjectionTransforms( - baseModel, resolvedModel, projectionName, Collections.emptySet()); + LOGGER.fine(() -> String.format( + "Applying transforms to projection %s: %s", + projectionName, + projection.getTransforms().stream() + .map(TransformConfig::getName) + .collect(Collectors.toList()))); + projectedModel = + applyProjectionTransforms(baseModel, resolvedModel, projectionName, Collections.emptySet()); modelResult = modelAssemblerSupplier.get().addModel(projectedModel).assemble(); } else { LOGGER.fine(() -> String.format("No transforms to apply for projection %s", projectionName)); @@ -361,8 +359,15 @@ private ProjectionResult applyProjection( for (ResolvedPlugin resolvedPlugin : resolvedPlugins) { if (pluginFilter.test(resolvedPlugin.id.getArtifactName())) { try { - applyPlugin(projectionName, projection, baseProjectionDir, resolvedPlugin, - projectedModel, resolvedModel, modelResult, resultBuilder); + applyPlugin( + projectionName, + projection, + baseProjectionDir, + resolvedPlugin, + projectedModel, + resolvedModel, + modelResult, + resultBuilder); } catch (Throwable e) { if (firstPluginError == null) { firstPluginError = e; @@ -382,11 +387,7 @@ private ProjectionResult applyProjection( } private Model applyProjectionTransforms( - ValidatedResult baseModel, - Model currentModel, - String projectionName, - Set visited - ) { + ValidatedResult baseModel, Model currentModel, String projectionName, Set visited) { Model originalModel = baseModel.unwrap(); for (Pair transformerBinding : transformers.get(projectionName)) { @@ -415,8 +416,7 @@ private void applyPlugin( Model projectedModel, Model resolvedModel, ValidatedResult modelResult, - ProjectionResult.Builder resultBuilder - ) { + ProjectionResult.Builder resultBuilder) { PluginId id = resolvedPlugin.id; // Create the manifest where plugin artifacts are stored. @@ -424,12 +424,11 @@ private void applyPlugin( FileManifest manifest = fileManifestFactory.apply(pluginBaseDir); if (resolvedPlugin.plugin.requiresValidModel() && modelResult.isBroken()) { - LOGGER.fine(() -> String.format("Skipping `%s` plugin for `%s` projection because the model is broken", - id, projectionName)); + LOGGER.fine(() -> String.format( + "Skipping `%s` plugin for `%s` projection because the model is broken", id, projectionName)); } else { LOGGER.info(() -> String.format("Applying `%s` plugin to `%s` projection", id, projectionName)); - resolvedPlugin.plugin - .execute(PluginContext.builder() + resolvedPlugin.plugin.execute(PluginContext.builder() .model(projectedModel) .originalModel(resolvedModel) .projection(projectionName, projection) @@ -447,17 +446,17 @@ private void applyPlugin( // Creates pairs where the left value is the configuration arguments of the // transformer, and the right value is the instantiated transformer. private List> createTransformers( - String projectionName, - ProjectionConfig config - ) { - List> resolved = new ArrayList<>(config.getTransforms().size()); + String projectionName, ProjectionConfig config) { + List> resolved = + new ArrayList<>(config.getTransforms().size()); for (TransformConfig transformConfig : config.getTransforms()) { String name = transformConfig.getName(); - ProjectionTransformer transformer = transformFactory.apply(name) + ProjectionTransformer transformer = transformFactory + .apply(name) .orElseThrow(() -> new UnknownTransformException(String.format( "Unable to find a transform named `%s` in the `%s` projection. Is this the correct " - + "spelling? Are you missing a dependency? Is your classpath configured correctly?", + + "spelling? Are you missing a dependency? Is your classpath configured correctly?", name, projectionName))); resolved.add(Pair.of(transformConfig.getArgs(), transformer)); } @@ -465,10 +464,8 @@ private List> createTransformers( return resolved; } - private Model applyQueuedProjections(Collection queuedProjections, - TransformContext context, - Model currentModel, - Set visited) { + private Model applyQueuedProjections( + Collection queuedProjections, TransformContext context, Model currentModel, Set visited) { LOGGER.fine(() -> String.format("Applying queued projections: %s", queuedProjections)); for (String projectionTarget : queuedProjections) { Set updatedVisited = new LinkedHashSet<>(visited); @@ -486,8 +483,9 @@ private Model applyQueuedProjections(Collection queuedProjections, updatedVisited.add(projectionTarget); currentModel = applyProjectionTransforms( - new ValidatedResult<>(context.getOriginalModel().orElse(currentModel), - context.getOriginalModelValidationEvents()), + new ValidatedResult<>( + context.getOriginalModel().orElse(currentModel), + context.getOriginalModelValidationEvents()), currentModel, projectionTarget, updatedVisited); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java index 27db5646549..d7c34ff3e75 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.util.ArrayList; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java index e9d80bd3688..c8a86b007d1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildResult.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java b/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java index 7d560ce4bcb..123f499ab37 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SourcesConflictException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java b/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java index 3450beebd8e..cd992c119de 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/TransformContext.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import java.nio.file.Path; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java index e8c24ea8500..f81d073a2e2 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownProjectionException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java index 6465fe42725..0a7c1e93e93 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/UnknownTransformException.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java index 3089abf827c..9a50d3a5a9a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.util.Collection; @@ -32,7 +21,7 @@ public final class MavenConfig implements ToSmithyBuilder { private MavenConfig(Builder builder) { this.dependencies = builder.dependencies.copy(); - this.repositories = builder.repositories.copy(); + this.repositories = builder.repositories.copy(); } public static MavenConfig fromNode(Node node) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java index 13b556b51c2..912fc67fa23 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/MavenRepository.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.util.Arrays; @@ -93,8 +82,7 @@ public boolean equals(Object o) { return false; } MavenRepository mavenRepo = (MavenRepository) o; - return - Objects.equals(id, mavenRepo.id) + return Objects.equals(id, mavenRepo.id) && Objects.equals(url, mavenRepo.url) && Objects.equals(httpCredentials, mavenRepo.httpCredentials); } @@ -130,15 +118,15 @@ public Builder proxyHost(String proxyHost) { public Builder proxyCredentials(String proxyCredentials) { this.proxyCredentials = proxyCredentials; - validateColonSeparatedValue(proxyCredentials, - "Invalid proxyCredentials: expected in the format of user:pass"); + validateColonSeparatedValue( + proxyCredentials, "Invalid proxyCredentials: expected in the format of user:pass"); return this; } public Builder httpCredentials(String httpCredentials) { this.httpCredentials = httpCredentials; - validateColonSeparatedValue(httpCredentials, - "Invalid httpCredentials: expected in the format of user:pass"); + validateColonSeparatedValue( + httpCredentials, "Invalid httpCredentials: expected in the format of user:pass"); return this; } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java index 30c4bc52063..da25c90156f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/ProjectionConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.nio.file.Path; @@ -67,12 +56,13 @@ static ProjectionConfig fromNode(Node node, Path basePath) { Builder builder = ProjectionConfig.builder(); node.expectObjectNode() .getBooleanMember("abstract", builder::setAbstract) - .getArrayMember("imports", s -> SmithyBuildUtils.resolveImportPath(basePath, s), - builder::imports) + .getArrayMember("imports", s -> SmithyBuildUtils.resolveImportPath(basePath, s), builder::imports) .getArrayMember("transforms", TransformConfig::fromNode, builder::transforms) .getObjectMember("plugins", plugins -> { for (Map.Entry entry : plugins.getStringMap().entrySet()) { - builder.plugins.get().put(entry.getKey(), entry.getValue().expectObjectNode()); + builder.plugins + .get() + .put(entry.getKey(), entry.getValue().expectObjectNode()); } }); return builder.build(); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java index 29acd3a966a..7acde2a9c0a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.nio.file.Path; @@ -298,14 +287,17 @@ private Builder loadNode(Path basePath, Node node) { node.expectObjectNode() .expectStringMember("version", this::version) .getStringMember("outputDirectory", this::outputDirectory) - .getArrayMember("sources", s -> SmithyBuildUtils.resolveImportPath(basePath, s), - values -> sources.get().addAll(values)) - .getArrayMember("imports", s -> SmithyBuildUtils.resolveImportPath(basePath, s), - values -> imports.get().addAll(values)) + .getArrayMember( + "sources", s -> SmithyBuildUtils.resolveImportPath(basePath, s), values -> sources.get() + .addAll(values)) + .getArrayMember( + "imports", s -> SmithyBuildUtils.resolveImportPath(basePath, s), values -> imports.get() + .addAll(values)) .getObjectMember("projections", v -> { for (Map.Entry entry : v.getStringMap().entrySet()) { - projections.get().put(entry.getKey(), ProjectionConfig - .fromNode(entry.getValue(), basePath)); + projections + .get() + .put(entry.getKey(), ProjectionConfig.fromNode(entry.getValue(), basePath)); } }) .getObjectMember("plugins", v -> { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java index 5a6e10d1154..4e5af5f0ff1 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/SmithyBuildUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.nio.file.Path; @@ -101,7 +90,9 @@ public Node arrayNode(ArrayNode node) { public Node objectNode(ObjectNode node) { Map result = new LinkedHashMap<>(node.size()); for (Map.Entry entry : node.getMembers().entrySet()) { - result.put(entry.getKey().accept(this).expectStringNode(), entry.getValue().accept(this)); + result.put( + entry.getKey().accept(this).expectStringNode(), + entry.getValue().accept(this)); } return new ObjectNode(result, node.getSourceLocation()); } @@ -137,13 +128,14 @@ private static String expand(SourceLocation sourceLocation, String variable) { return SmithyBuildUtils.getCurrentWorkingDirectory().toString(); } - String replacement = Optional.ofNullable(System.getProperty(variable)) - .orElseGet(() -> System.getenv(variable)); + String replacement = + Optional.ofNullable(System.getProperty(variable)).orElseGet(() -> System.getenv(variable)); if (replacement == null) { throw new SmithyBuildException(String.format( "Unable to expand variable `" + variable + "` to an environment variable or system " - + "property: %s", sourceLocation)); + + "property: %s", + sourceLocation)); } return replacement; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java b/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java index daa861d493d..44b66f9c16b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/model/TransformConfig.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import java.util.function.Function; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java index 67926c16553..0778136ed85 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfo.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.util.Collections; @@ -160,21 +149,29 @@ public boolean equals(Object o) { BuildInfo buildInfo = (BuildInfo) o; return Objects.equals(getVersion(), buildInfo.getVersion()) - && Objects.equals(getProjectionName(), buildInfo.getProjectionName()) - && Objects.equals(getProjection(), buildInfo.getProjection()) - && Objects.equals(getValidationEvents(), buildInfo.getValidationEvents()) - && Objects.equals(getTraitNames(), buildInfo.getTraitNames()) - && Objects.equals(getTraitDefNames(), buildInfo.getTraitDefNames()) - && Objects.equals(getServiceShapeIds(), buildInfo.getServiceShapeIds()) - && Objects.equals(getOperationShapeIds(), buildInfo.getOperationShapeIds()) - && Objects.equals(getResourceShapeIds(), buildInfo.getResourceShapeIds()) - && Objects.equals(getMetadata(), buildInfo.getMetadata()); + && Objects.equals(getProjectionName(), buildInfo.getProjectionName()) + && Objects.equals(getProjection(), buildInfo.getProjection()) + && Objects.equals(getValidationEvents(), buildInfo.getValidationEvents()) + && Objects.equals(getTraitNames(), buildInfo.getTraitNames()) + && Objects.equals(getTraitDefNames(), buildInfo.getTraitDefNames()) + && Objects.equals(getServiceShapeIds(), buildInfo.getServiceShapeIds()) + && Objects.equals(getOperationShapeIds(), buildInfo.getOperationShapeIds()) + && Objects.equals(getResourceShapeIds(), buildInfo.getResourceShapeIds()) + && Objects.equals(getMetadata(), buildInfo.getMetadata()); } @Override public int hashCode() { - return Objects.hash(getVersion(), getProjectionName(), getProjection(), getValidationEvents(), - getTraitNames(), getTraitDefNames(), getServiceShapeIds(), getOperationShapeIds(), - getResourceShapeIds(), getMetadata()); + return Objects.hash( + getVersion(), + getProjectionName(), + getProjection(), + getValidationEvents(), + getTraitNames(), + getTraitDefNames(), + getServiceShapeIds(), + getOperationShapeIds(), + getResourceShapeIds(), + getMetadata()); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java index 3d8b26c2990..6f0cc81a5e7 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/BuildInfoPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.util.ArrayList; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java index f68438b7cf4..e21629cda67 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import software.amazon.smithy.build.PluginContext; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java index 854dcfbbc29..08285f135b5 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import software.amazon.smithy.build.PluginContext; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java index 4eb97e9afb0..98762bbc25c 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/NullabilityReportPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import software.amazon.smithy.build.PluginContext; @@ -63,18 +52,20 @@ private static Node serializeReport(PluginContext context) { for (MemberShape member : structure.getAllMembers().values()) { ObjectNode.Builder entry = Node.objectNodeBuilder(); entry.withMember("v1", index.isNullable(member)); - entry.withMember("v1-via-box", member.getMemberTrait(model, BoxTrait.class).isPresent()); - entry.withMember("v2-client", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT)); - entry.withMember("v2-client-careful", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_CAREFUL)); - entry.withMember("v2-client-zero-value", - index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1)); - entry.withMember("v2-client-zero-value-no-input", - index.isMemberNullable(member, - NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT)); - entry.withMember("v2-server", - index.isMemberNullable(member, NullableIndex.CheckMode.SERVER)); + entry.withMember( + "v1-via-box", + member.getMemberTrait(model, BoxTrait.class).isPresent()); + entry.withMember("v2-client", index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT)); + entry.withMember( + "v2-client-careful", + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_CAREFUL)); + entry.withMember( + "v2-client-zero-value", + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1)); + entry.withMember( + "v2-client-zero-value-no-input", + index.isMemberNullable(member, NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1_NO_INPUT)); + entry.withMember("v2-server", index.isMemberNullable(member, NullableIndex.CheckMode.SERVER)); struct.withMember(member.getMemberName(), entry.build()); } root.withMember(structure.getId().toString(), struct.build()); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java index 485d1863a64..169b20f84ea 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/RunPlugin.java @@ -1,18 +1,7 @@ /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.io.ByteArrayInputStream; @@ -117,21 +106,23 @@ private void runCommand(String artifactName, PluginContext context, Settings set InputStream inputStream = serializeModel(settings, context.getModel()); Appendable appendable = new StringBuilder(); - LOGGER.fine(() -> "Running command for artifact " - + context.getArtifactName().orElse(getName()) - + ": " + command); + LOGGER.fine(() -> + "Running command for artifact " + context.getArtifactName().orElse(getName()) + ": " + command); int result; try { result = IoUtils.runCommand(command, baseDir, inputStream, appendable, env); } catch (RuntimeException e) { - throw new SmithyBuildException("Error running process `" + String.join(" ", command) + "` for '" - + artifactName + "': " + e.getMessage(), e); + throw new SmithyBuildException( + "Error running process `" + String.join(" ", command) + "` for '" + artifactName + "': " + + e.getMessage(), + e); } if (result != 0) { - throw new SmithyBuildException(("Error exit code " + result + " returned from: `" - + String.join(" ", command) + "`: " + appendable).trim()); + throw new SmithyBuildException( + ("Error exit code " + result + " returned from: `" + String.join(" ", command) + "`: " + appendable) + .trim()); } LOGGER.fine(() -> command.get(0) + " output: " + appendable); @@ -151,7 +142,8 @@ private void useProjectRelativeCommandIfPossible(List command) { private Map prepareEnvironment(PluginContext context, Settings settings) { Map env = new HashMap<>(settings.env); env.putIfAbsent("SMITHY_ROOT_DIR", root.toString()); - env.putIfAbsent("SMITHY_PLUGIN_DIR", context.getFileManifest().getBaseDir().toString()); + env.putIfAbsent( + "SMITHY_PLUGIN_DIR", context.getFileManifest().getBaseDir().toString()); env.putIfAbsent("SMITHY_PROJECTION_NAME", context.getProjectionName()); env.putIfAbsent("SMITHY_ARTIFACT_NAME", context.getArtifactName().orElse("")); env.putIfAbsent("SMITHY_INCLUDES_PRELUDE", String.valueOf(settings.sendPrelude())); @@ -159,9 +151,8 @@ private Map prepareEnvironment(PluginContext context, Settings s } private InputStream serializeModel(Settings settings, Model model) { - ModelSerializer serializer = ModelSerializer.builder() - .includePrelude(settings.sendPrelude()) - .build(); + ModelSerializer serializer = + ModelSerializer.builder().includePrelude(settings.sendPrelude()).build(); String jsonModel = Node.printJson(serializer.serialize(model)); return new ByteArrayInputStream(jsonModel.getBytes(StandardCharsets.UTF_8)); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java index 6fe3e46b455..df7544b1b16 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.plugins; import java.io.File; @@ -78,8 +67,7 @@ public void execute(PluginContext context) { if (projectionName.equals("source")) { // Copy sources directly. names = copySources(context); - LOGGER.fine(() -> String.format("Copying source files to the sources of %s: %s", - projectionName, names)); + LOGGER.fine(() -> String.format("Copying source files to the sources of %s: %s", projectionName, names)); } else { // Extract source shapes, traits, and metadata from the projected model. LOGGER.fine(() -> String.format( @@ -118,7 +106,8 @@ private static void copyDirectory(List names, FileManifest manifest, Pat if (current.toString().endsWith(".jar")) { // Account for just a simple file vs recursing into directories. String jarRoot = root.equals(current) - ? "" : (root.relativize(current).toString() + File.separator); + ? "" + : (root.relativize(current).toString() + File.separator); // Copy Smithy models out of the JAR. copyModelsFromJar(names, manifest, jarRoot, current); } else { @@ -141,10 +130,10 @@ private static void copyFile(List names, FileManifest manifest, Path tar if (manifest.hasFile(target)) { throw new SourcesConflictException( "Source file conflict found when attempting to add `" + target + "` to the `sources` plugin " - + "output. All sources must have unique filenames relative to the directories marked as a " - + "'source'. The files and directories that make up sources are flattened into a single " - + "directory and conflicts are not allowed. The manifest has the following files: " - + ValidationUtils.tickedList(manifest.getFiles())); + + "output. All sources must have unique filenames relative to the directories marked as a " + + "'source'. The files and directories that make up sources are flattened into a single " + + "directory and conflicts are not allowed. The manifest has the following files: " + + ValidationUtils.tickedList(manifest.getFiles())); } String filename = target.toString(); @@ -163,8 +152,7 @@ private static void projectSources(PluginContext context) { Model updatedModel = context.getModel(); // New shapes, trait definitions, and metadata are considered "sources". - ObjectNode serialized = ModelSerializer - .builder() + ObjectNode serialized = ModelSerializer.builder() .shapeFilter(context::isSourceShape) .metadataFilter(context::isSourceMetadata) .build() diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java b/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java index 3ea6dcb63fb..92dc5bc9e1b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/processor/SmithyAnnotationProcessor.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.processor; import java.io.IOException; @@ -102,15 +101,18 @@ public synchronized void init(ProcessingEnvironment processingEnv) { public boolean process(Set annotations, RoundEnvironment roundEnv) { Set elements = roundEnv.getElementsAnnotatedWith(getAnnotationClass()); if (elements.size() > 1) { - messager.printMessage(Diagnostic.Kind.ERROR, - "Only one package can have the " + getAnnotationClass() + " annotation."); + messager.printMessage( + Diagnostic.Kind.ERROR, "Only one package can have the " + getAnnotationClass() + " annotation."); } else if (elements.size() == 1) { - messager.printMessage(Diagnostic.Kind.NOTE, + messager.printMessage( + Diagnostic.Kind.NOTE, "Executing processor: " + this.getClass().getSimpleName() + "..."); String packageName = getPackageName(elements.iterator().next()); SmithyBuildConfig config = createBuildConfig(getAnnotation(elements), packageName); - executeSmithyBuild(config).allArtifacts() - .filter(path -> path.toString().contains(getPluginName()) && path.toString().contains("source")) + executeSmithyBuild(config) + .allArtifacts() + .filter(path -> path.toString().contains(getPluginName()) + && path.toString().contains("source")) .forEach(this::writeArtifact); } @@ -168,21 +170,21 @@ private SmithyBuildResult executeSmithyBuild(SmithyBuildConfig config) { private void writeArtifact(Path path) { String pathStr = path.toString(); - final String outputPath = pathStr.substring(pathStr.lastIndexOf(getPluginName()) - + getPluginName().length() + 1); + final String outputPath = pathStr.substring( + pathStr.lastIndexOf(getPluginName()) + getPluginName().length() + 1); try { // Resources are written to the class output if (outputPath.startsWith("META-INF")) { - try (Writer writer = filer - .createResource(StandardLocation.CLASS_OUTPUT, "", convertOutputPath(outputPath)) - .openWriter() - ) { + try (Writer writer = filer.createResource( + StandardLocation.CLASS_OUTPUT, "", convertOutputPath(outputPath)) + .openWriter()) { writer.write(IoUtils.readUtf8File(path)); } // All other Java files are written to the source output } else if (outputPath.endsWith(".java")) { // The filer needs to use a namespace convention of `.` rather than the default separator for paths. - String javaPath = outputPath.replace(FileSystems.getDefault().getSeparator(), ".") + String javaPath = outputPath + .replace(FileSystems.getDefault().getSeparator(), ".") .substring(0, outputPath.lastIndexOf(".java")); try (Writer writer = filer.createSourceFile(javaPath).openWriter()) { writer.write(IoUtils.readUtf8File(path)); @@ -200,13 +202,15 @@ private A getAnnotation(Set elements) { return elements.stream() .findFirst() .map(element -> element.getAnnotation(getAnnotationClass())) - .orElseThrow(() -> new IllegalStateException("No annotation of type " - + getAnnotationClass() + " found on element.")); + .orElseThrow(() -> new IllegalStateException( + "No annotation of type " + getAnnotationClass() + " found on element.")); } private URL getManifestUrl() { try { - return filer.getResource(StandardLocation.CLASS_PATH, "", MANIFEST_PATH).toUri().toURL(); + return filer.getResource(StandardLocation.CLASS_PATH, "", MANIFEST_PATH) + .toUri() + .toURL(); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -222,8 +226,8 @@ private String getPackageName(Element element) { PackageElement packageElement = (PackageElement) element; return packageElement.getQualifiedName().toString(); } else { - throw new IllegalStateException("Expected Annotation to be applied to package element " - + "but found : " + element); + throw new IllegalStateException( + "Expected Annotation to be applied to package element " + "but found : " + element); } } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java index 433481c0f19..67f768bb06f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/Apply.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.List; @@ -83,5 +72,4 @@ protected Model transformWithConfig(TransformContext context, Config config) { protected Optional>> getAdditionalProjectionsFunction() { return Optional.of((context, config) -> ListUtils.copyOf(config.getProjections())); } - } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java index 094389e661f..df1330e4529 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/BackwardCompatHelper.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.List; @@ -120,7 +109,6 @@ public List getAdditionalProjections(TransformContext context) { // short-circuit updating the context if additional projections are not supported .map(unused -> super.getAdditionalProjections(updateContextIfNecessary(context))) .orElseGet(ListUtils::of); - } private TransformContext updateContextIfNecessary(TransformContext context) { @@ -132,10 +120,13 @@ private TransformContext updateContextIfNecessary(TransformContext context) { LOGGER.warning(() -> String.format( "Deprecated projection transform arguments detected for `%s`; change this list of strings " - + "to an object with a property named `%s`", getName(), getBackwardCompatibleNameMapping())); + + "to an object with a property named `%s`", + getName(), getBackwardCompatibleNameMapping())); ObjectNode updated = original.toBuilder() - .withMember(getBackwardCompatibleNameMapping(), original.getMember(ARGS).get()) + .withMember( + getBackwardCompatibleNameMapping(), + original.getMember(ARGS).get()) .withoutMember(ARGS) .build(); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java index eb33129ef23..b42bd17e31e 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import software.amazon.smithy.build.TransformContext; @@ -55,7 +44,6 @@ public String getName() { @Override protected Model transformWithConfig(TransformContext context, Config config) { - return context.getTransformer().changeStringEnumsToEnumShapes( - context.getModel(), config.getSynthesizeNames()); + return context.getTransformer().changeStringEnumsToEnumShapes(context.getModel(), config.getSynthesizeNames()); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java index 9b47c0cb645..1feefceb5ec 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ChangeTypes.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.LinkedHashMap; @@ -82,12 +71,11 @@ protected Model transformWithConfig(TransformContext context, Config config) { } if (config.getSynthesizeEnumNames()) { - return context.getTransformer().changeShapeType( - context.getModel(), config.getShapeTypes(), - ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES); + return context.getTransformer() + .changeShapeType( + context.getModel(), config.getShapeTypes(), ChangeShapeTypeOption.SYNTHESIZE_ENUM_NAMES); } - return context.getTransformer().changeShapeType( - context.getModel(), config.getShapeTypes()); + return context.getTransformer().changeShapeType(context.getModel(), config.getShapeTypes()); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java index 7cb830d189c..c2e98c88a27 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ConfigurableProjectionTransformer.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.List; @@ -69,11 +58,13 @@ public Model transform(TransformContext context) { @Override public List getAdditionalProjections(TransformContext context) { - return getAdditionalProjectionsFunction().map(fn -> { - NodeMapper mapper = new NodeMapper(); - T config = mapper.deserialize(context.getSettings(), getConfigType()); - return fn.apply(context, config); - }).orElseGet(ListUtils::of); + return getAdditionalProjectionsFunction() + .map(fn -> { + NodeMapper mapper = new NodeMapper(); + T config = mapper.deserialize(context.getSettings(), getConfigType()); + return fn.apply(context, config); + }) + .orElseGet(ListUtils::of); } /** diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java index ad41576be4e..c0e5d17ef86 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java index 4adfe00804c..bed5bc1116b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Set; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java index 65c3bea469a..fd436f6bf1f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java index bb6002fc66e..8b170e7574b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesByTrait.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java index 2064cb22518..8596520212a 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTags.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java index b39e40a1973..daacabf4f12 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java index eaf2edfc285..c433a791c91 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collection; @@ -82,9 +71,7 @@ protected Model transformWithConfig(TransformContext context, Config config) { } private boolean removeIfPredicate(Shape shape, Collection tags) { - return !Prelude.isPreludeShape(shape) - && shape.hasTrait(TraitDefinition.class) - && hasAnyTag(shape, tags); + return !Prelude.isPreludeShape(shape) && shape.hasTrait(TraitDefinition.class) && hasAnyTag(shape, tags); } private boolean hasAnyTag(Tagged tagged, Collection tags) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java index 108446d9167..af502044923 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FilterSuppressions.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.ArrayList; @@ -207,14 +196,16 @@ public String getName() { @Override protected Model transformWithConfig(TransformContext context, Config config) { - if (!config.getEventIdAllowList().isEmpty() && !config.getEventIdDenyList().isEmpty()) { + if (!config.getEventIdAllowList().isEmpty() + && !config.getEventIdDenyList().isEmpty()) { throw new SmithyBuildException(getName() + ": cannot set both eventIdAllowList values and " - + "eventIdDenyList values at the same time"); + + "eventIdDenyList values at the same time"); } - if (!config.getNamespaceAllowList().isEmpty() && !config.getNamespaceDenyList().isEmpty()) { + if (!config.getNamespaceAllowList().isEmpty() + && !config.getNamespaceDenyList().isEmpty()) { throw new SmithyBuildException(getName() + ": cannot set both namespaceAllowList values and " - + "namespaceDenyList values at the same time"); + + "namespaceDenyList values at the same time"); } Model model = context.getModel(); @@ -237,7 +228,8 @@ private Set getRemovedValidators(TransformContext context, Config config return Collections.emptySet(); } - Set originalValidators = getValidatorNames(context.getOriginalModel().get()); + Set originalValidators = + getValidatorNames(context.getOriginalModel().get()); Set updatedValidators = getValidatorNames(context.getModel()); if (originalValidators.equals(updatedValidators)) { @@ -248,17 +240,16 @@ private Set getRemovedValidators(TransformContext context, Config config if (config.getRemoveUnused()) { LOGGER.info(() -> "Detected the removal of the following validators: " - + originalValidators - + ". Suppressions that refer to these validators will be removed."); + + originalValidators + + ". Suppressions that refer to these validators will be removed."); } return originalValidators; } private Set getValidatorNames(Model model) { - ArrayNode validators = model.getMetadata() - .getOrDefault("validators", Node.arrayNode()) - .expectArrayNode(); + ArrayNode validators = + model.getMetadata().getOrDefault("validators", Node.arrayNode()).expectArrayNode(); Set metadataSuppressions = new HashSet<>(); for (Node validator : validators) { ObjectNode validatorObject = validator.expectObjectNode(); @@ -272,11 +263,7 @@ private Set getValidatorNames(Model model) { } private Model filterSuppressionTraits( - Model model, - Config config, - List suppressedEvents, - ModelTransformer transformer - ) { + Model model, Config config, List suppressedEvents, ModelTransformer transformer) { List replacementShapes = new ArrayList<>(); // First filter and '@suppress' traits that didn't suppress anything. @@ -288,30 +275,31 @@ private Model filterSuppressionTraits( // Only keep IDs that actually acted to suppress an event. if (config.getRemoveUnused()) { Set matchedEvents = suppressedEvents.stream() - .filter(event -> Objects.equals(shape.getId(), event.getShapeId().orElse(null))) + .filter(event -> + Objects.equals(shape.getId(), event.getShapeId().orElse(null))) .collect(Collectors.toSet()); allowed.removeIf(value -> matchedEvents.stream().noneMatch(event -> event.containsId(value))); } if (allowed.isEmpty()) { - replacementShapes.add(Shape.shapeToBuilder(shape).removeTrait(SuppressTrait.ID).build()); + replacementShapes.add(Shape.shapeToBuilder(shape) + .removeTrait(SuppressTrait.ID) + .build()); } else if (!allowed.equals(trait.getValues())) { trait = trait.toBuilder().values(allowed).build(); - replacementShapes.add(Shape.shapeToBuilder(shape).addTrait(trait).build()); + replacementShapes.add( + Shape.shapeToBuilder(shape).addTrait(trait).build()); } } return transformer.replaceShapes(model, replacementShapes); } private Model filterMetadata( - Model model, - Config config, - List suppressedEvents, - Set removedValidators - ) { + Model model, Config config, List suppressedEvents, Set removedValidators) { // Next remove metadata suppressions that didn't suppress anything. ArrayNode suppressionsNode = model.getMetadata() - .getOrDefault("suppressions", Node.arrayNode()).expectArrayNode(); + .getOrDefault("suppressions", Node.arrayNode()) + .expectArrayNode(); List updatedMetadataSuppressions = new ArrayList<>(); for (Node suppressionNode : suppressionsNode) { @@ -352,7 +340,6 @@ && isAllowed(namespace, config.getNamespaceAllowList(), config.getNamespaceDenyL } private boolean isAllowed(String value, Collection allowList, Collection denyList) { - return (allowList.isEmpty() || allowList.contains(value)) - && (denyList.isEmpty() || !denyList.contains(value)); + return (allowList.isEmpty() || allowList.contains(value)) && (denyList.isEmpty() || !denyList.contains(value)); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java index 6c46377959b..3fd81a2d9da 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/FlattenNamespaces.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -132,8 +121,7 @@ protected Model transformWithConfig(TransformContext context, Config config) { // Remove service renames since they've now been applied, so consumers don't fail service shape validation ShapeId updatedServiceId = shapesToRename.get(config.getService()); - ServiceShape updatedService = model.expectShape(updatedServiceId, ServiceShape.class) - .toBuilder() + ServiceShape updatedService = model.expectShape(updatedServiceId, ServiceShape.class).toBuilder() .clearRename() .build(); return context.getTransformer().replaceShapes(model, ListUtils.of(updatedService)); @@ -162,7 +150,8 @@ private Map getRenamedShapes(Config config, Model model) { private ShapeId updateNamespace(ShapeId shapeId, String namespace) { if (shapeId.getMember().isPresent()) { - return ShapeId.fromParts(namespace, shapeId.getName(), shapeId.getMember().get()); + return ShapeId.fromParts( + namespace, shapeId.getName(), shapeId.getMember().get()); } return ShapeId.fromParts(namespace, shapeId.getName()); } @@ -179,7 +168,8 @@ private Map getRenamedShapesConnectedToService(Config config, private Pair applyServiceRenames(ShapeId fromId, ShapeId toId, ServiceShape service) { if (service.getRename().containsKey(fromId)) { - ShapeId newId = ShapeId.fromParts(toId.getNamespace(), service.getRename().get(fromId)); + ShapeId newId = + ShapeId.fromParts(toId.getNamespace(), service.getRename().get(fromId)); return Pair.of(fromId, newId); } return Pair.of(fromId, toId); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java index 34e313d6d09..a80b50e7a73 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeMetadata.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java index 911700f9d22..0011f732811 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeNamespaces.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -74,7 +63,8 @@ protected Model transformWithConfig(TransformContext context, Config config) { Model model = context.getModel(); ModelTransformer transformer = context.getTransformer(); return transformer.filterShapes(model, shape -> { - return Prelude.isPreludeShape(shape) || namespaces.contains(shape.getId().getNamespace()); + return Prelude.isPreludeShape(shape) + || namespaces.contains(shape.getId().getNamespace()); }); } } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java index c86160e09f5..35fa778e24f 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeServices.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java index ea1d240a843..9b5042a3b2c 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Set; @@ -64,7 +53,6 @@ public String getName() { return "includeShapesBySelector"; } - @Override protected Model transformWithConfig(TransformContext context, Config config) { Selector selector = config.getSelector(); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java index 86e9dfe7da7..56af8012376 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java index 4260ca3055e..a7e0c15ae9b 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTags.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java index ced9521048e..f326ba97f09 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraits.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java index 3b4b0282e7e..fe15f6eefab 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/IncludeTraitsByTag.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collection; @@ -82,9 +71,7 @@ protected Model transformWithConfig(TransformContext context, Config config) { } private boolean removeIfPredicate(Shape shape, Collection tags) { - return !Prelude.isPreludeShape(shape) - && shape.hasTrait(TraitDefinition.class) - && !hasAnyTag(shape, tags); + return !Prelude.isPreludeShape(shape) && shape.hasTrait(TraitDefinition.class) && !hasAnyTag(shape, tags); } private boolean hasAnyTag(Tagged tagged, Collection tags) { diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java index afab58be77b..24aff333ded 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/MakeIdempotencyTokensClientOptional.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import software.amazon.smithy.build.ProjectionTransformer; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java index c0b08ab8713..3a72e49d1d0 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapes.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import software.amazon.smithy.build.TransformContext; diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java index 5a48813f03f..486ca8b262c 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitions.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -70,7 +59,8 @@ public Class getConfigType() { protected Model transformWithConfig(TransformContext context, Config config) { Model model = context.getModel(); ModelTransformer transformer = context.getTransformer(); - Predicate keepTraitDefsByTag = trait -> config.getExportTagged().stream().noneMatch(trait::hasTag); + Predicate keepTraitDefsByTag = + trait -> config.getExportTagged().stream().noneMatch(trait::hasTag); return transformer.getModelWithoutTraitShapes(model, keepTraitDefsByTag); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java index fafd6dd4d19..ed4ec4ba53c 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RemoveUnusedShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collections; @@ -77,8 +66,10 @@ public String getBackwardCompatibleNameMapping() { @Override protected Model transformWithConfig(TransformContext context, Config config) { - Predicate keepShapesByTag = shape -> config.getExportTagged().stream().noneMatch(shape::hasTag); - Predicate keepTraitDefsByTag = trait -> config.getExportTagged().stream().noneMatch(trait::hasTag); + Predicate keepShapesByTag = + shape -> config.getExportTagged().stream().noneMatch(shape::hasTag); + Predicate keepTraitDefsByTag = + trait -> config.getExportTagged().stream().noneMatch(trait::hasTag); Model model = context.getModel(); ModelTransformer transformer = context.getTransformer(); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java index 105f094e41d..43eb463fecb 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/RenameShapes.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.HashMap; @@ -68,8 +57,7 @@ public Class getConfigType() { @Override protected Model transformWithConfig(TransformContext context, Config config) { if (config.getRenamed() == null || config.getRenamed().isEmpty()) { - throw new SmithyBuildException( - "'renamed' property must be set and non-empty on renameShapes transformer."); + throw new SmithyBuildException("'renamed' property must be set and non-empty on renameShapes transformer."); } Model model = context.getModel(); @@ -87,8 +75,7 @@ private Map getShapeIdsToRename(Config config, Model model) { ShapeId fromShapeId = getShapeIdFromString(fromShape); if (!model.getShape(fromShapeId.toShapeId()).isPresent()) { throw new SmithyBuildException( - String.format("'%s' to be renamed does not exist in model.", fromShapeId) - ); + String.format("'%s' to be renamed does not exist in model.", fromShapeId)); } shapeIdMap.put(fromShapeId, getShapeIdFromString(config.getRenamed().get(fromShape))); } diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java index a410e0d4379..057792d2644 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TagUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.Collection; @@ -40,11 +29,7 @@ static Model includeShapeTags(ModelTransformer transformer, Model model, Set tags, - boolean exclude - ) { + ModelTransformer transformer, Model model, Set tags, boolean exclude) { return transformer.mapShapes(model, shape -> intersectIfChanged(shape.getTags(), tags, exclude) .map(intersection -> { TagsTrait.Builder builder = TagsTrait.builder(); @@ -55,10 +40,7 @@ private static Model includeExcludeShapeTags( } private static Optional> intersectIfChanged( - Collection subject, - Collection other, - boolean exclude - ) { + Collection subject, Collection other, boolean exclude) { Set temp = new HashSet<>(subject); if (exclude) { temp.removeAll(other); diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java index bc1ddefb735..53b75a20937 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/transforms/TraitRemovalUtils.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import java.util.HashSet; @@ -45,6 +34,7 @@ static Pair, Set> parseTraits(Set ids) { } static boolean matchesTraitDefinition(Shape traitShape, Set traitNames, Set traitNamespaces) { - return traitNames.contains(traitShape.getId()) || traitNamespaces.contains(traitShape.getId().getNamespace()); + return traitNames.contains(traitShape.getId()) + || traitNamespaces.contains(traitShape.getId().getNamespace()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java index 5f6f7640e7f..25abc5c6347 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/FileManifestTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -45,7 +34,10 @@ public void before() throws IOException { @AfterEach public void after() throws IOException { - Files.walk(outputDirectory).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + Files.walk(outputDirectory) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); } @Test diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java index cb3b57eb1ec..9173fb162c1 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/JsonSubstitutionsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,7 +19,8 @@ public void replacesValuesInObjectNode() { Map mappings = new HashMap<>(); mappings.put("FOO_BAR", Node.from("Hi!")); JsonSubstitutions substitutions = JsonSubstitutions.create(mappings); - ObjectNode node = Node.parse("{\"a\": \"FOO_BAR\", \"b\": \"FOO_BAR baz\"}").expectObjectNode(); + ObjectNode node = + Node.parse("{\"a\": \"FOO_BAR\", \"b\": \"FOO_BAR baz\"}").expectObjectNode(); ObjectNode result = substitutions.apply(node).expectObjectNode(); assertThat(result.expectMember("a").expectStringNode().getValue(), equalTo("Hi!")); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java index 04eea88fabc..3b1809b8bcf 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/MockManifestTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -71,8 +60,9 @@ public void findsFilesUnderPrefix() { a.writeFile("foo/bar/b", "hello"); a.writeFile("foo/bam/qux", "hello"); - assertThat(a.getFilesIn("foo"), contains( - Paths.get("/foo/bam/qux"), Paths.get("/foo/bar/a"), Paths.get("/foo/bar/b"))); + assertThat( + a.getFilesIn("foo"), + contains(Paths.get("/foo/bam/qux"), Paths.get("/foo/bar/a"), Paths.get("/foo/bar/b"))); assertThat(a.getFilesIn("foo/bam"), contains(Paths.get("/foo/bam/qux"))); assertThat(a.getFilesIn("foo/bar"), contains(Paths.get("/foo/bar/a"), Paths.get("/foo/bar/b"))); assertThat(a.getFilesIn("foo/bam"), contains(Paths.get("/foo/bam/qux"))); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java index b021f705eb6..dbbe10732ee 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/PluginArtifactIdTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java index f70e7724be9..b34481ec8e8 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/PluginContextTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java index 168e89b4569..c5586e64c10 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionConfigTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java index 9df599497d0..f4464deb7ee 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/ProjectionResultTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -33,7 +22,8 @@ public void checksIfBrokenBasedOnError() { .severity(Severity.ERROR) .id("abc") .build()) - .build().isBroken()); + .build() + .isBroken()); } @Test @@ -46,6 +36,7 @@ public void checksIfBrokenBasedOnDanger() { .severity(Severity.DANGER) .id("abc") .build()) - .build().isBroken()); + .build() + .isBroken()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java index 652a32705db..7cafe6fb15d 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildResultTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,18 +24,21 @@ public void checksIfAnyFailed() { .projectionName("foo") .model(Model.builder().build()) .addEvent(ValidationEvent.builder() - .message("foo") - .severity(Severity.ERROR) - .id("abc") - .build()) + .message("foo") + .severity(Severity.ERROR) + .id("abc") + .build()) .build()) - .build().anyBroken()); + .build() + .anyBroken()); assertFalse(SmithyBuildResult.builder() .addProjectionResult(ProjectionResult.builder() .model(Model.builder().build()) - .projectionName("foo").build()) - .build().anyBroken()); + .projectionName("foo") + .build()) + .build() + .anyBroken()); } @Test diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java index ad941ffeb86..4f6a4dc2c7e 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; import static org.hamcrest.MatcherAssert.assertThat; @@ -83,19 +72,23 @@ public void before() throws IOException { @AfterEach public void after() throws IOException { - Files.walk(outputDirectory).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + Files.walk(outputDirectory) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); } @Test public void loadsEmptyObject() throws Exception { - SmithyBuildConfig.load(Paths.get(getClass().getResource("empty-config.json").toURI())); + SmithyBuildConfig.load( + Paths.get(getClass().getResource("empty-config.json").toURI())); } @Test public void throwsForUnknownTransform() throws Exception { Assertions.assertThrows(UnknownTransformException.class, () -> { - SmithyBuildConfig config = SmithyBuildConfig - .load(Paths.get(getClass().getResource("unknown-transform.json").toURI())); + SmithyBuildConfig config = SmithyBuildConfig.load( + Paths.get(getClass().getResource("unknown-transform.json").toURI())); new SmithyBuild().config(config).build(); }); } @@ -156,32 +149,33 @@ public void createsEmptyManifest() throws Exception { .load(Paths.get(getClass().getResource("empty-config.json").toURI())) .outputDirectory(outputDirectory.toString()) .build(); - Model model = Model.assembler() - .assemble() - .unwrap(); + Model model = Model.assembler().assemble().unwrap(); SmithyBuild builder = new SmithyBuild().config(config).model(model); SmithyBuildResult results = builder.build(); List files = results.allArtifacts().collect(Collectors.toList()); assertThat(files, hasItem(outputDirectory.resolve("source/sources/manifest"))); - assertThat("\n", equalTo(IoUtils.readUtf8File(results.allArtifacts() - .filter(path -> path.toString().endsWith(System.getProperty("file.separator") + "manifest")) - .findFirst() - .get()))); + assertThat( + "\n", + equalTo(IoUtils.readUtf8File(results.allArtifacts() + .filter(path -> path.toString().endsWith(System.getProperty("file.separator") + "manifest")) + .findFirst() + .get()))); } @Test public void modeExcludePreludeShapes() throws Exception { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("exclude-prelude-shapes.json").toURI())) + .load(Paths.get( + getClass().getResource("exclude-prelude-shapes.json").toURI())) .outputDirectory(outputDirectory.toString()) .build(); - Model model = Model.assembler() - .assemble() - .unwrap(); - SmithyBuildResult results = new SmithyBuild().config(config).model(model).build(); + Model model = Model.assembler().assemble().unwrap(); + SmithyBuildResult results = + new SmithyBuild().config(config).model(model).build(); String content = IoUtils.readUtf8File(results.allArtifacts() - .filter(path -> path.toString().endsWith("withoutPrelude" + System.getProperty("file.separator") + "model.json")) + .filter(path -> path.toString() + .endsWith("withoutPrelude" + System.getProperty("file.separator") + "model.json")) .findFirst() .get()); assertThat(Files.isRegularFile(outputDirectory.resolve("source/withoutPrelude/model.json")), is(true)); @@ -192,15 +186,16 @@ public void modeExcludePreludeShapes() throws Exception { @Test public void modeIncludePreludeShapes() throws Exception { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("include-prelude-shapes.json").toURI())) + .load(Paths.get( + getClass().getResource("include-prelude-shapes.json").toURI())) .outputDirectory(outputDirectory.toString()) .build(); - Model model = Model.assembler() - .assemble() - .unwrap(); - SmithyBuildResult results = new SmithyBuild().config(config).model(model).build(); + Model model = Model.assembler().assemble().unwrap(); + SmithyBuildResult results = + new SmithyBuild().config(config).model(model).build(); String content = IoUtils.readUtf8File(results.allArtifacts() - .filter(path -> path.toString().endsWith("withPrelude" + System.getProperty("file.separator") + "model.json")) + .filter(path -> + path.toString().endsWith("withPrelude" + System.getProperty("file.separator") + "model.json")) .findFirst() .get()); assertThat(Files.isRegularFile(outputDirectory.resolve("source/withPrelude/model.json")), is(true)); @@ -211,11 +206,13 @@ public void modeIncludePreludeShapes() throws Exception { @Test public void doesNotCopyErroneousModelsToBuildOutput() throws Exception { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("resource-model-config.json").toURI())) + .load(Paths.get( + getClass().getResource("resource-model-config.json").toURI())) .outputDirectory(outputDirectory.toString()) .build(); Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("resource-model.json").toURI())) + .addImport( + Paths.get(getClass().getResource("resource-model.json").toURI())) .assemble() .unwrap(); SmithyBuild builder = new SmithyBuild(config).model(model); @@ -236,18 +233,21 @@ public void doesNotCopyErroneousModelsToBuildOutput() throws Exception { String contents = IoUtils.readUtf8File(outputDirectory.resolve("source/build-info/smithy-build-info.json")); ObjectNode badBuildInfo = Node.parse(contents).expectObjectNode(); assertTrue(badBuildInfo.expectMember("version").isStringNode()); - assertThat(badBuildInfo.expectMember("projectionName").expectStringNode().getValue(), equalTo("source")); + assertThat( + badBuildInfo.expectMember("projectionName").expectStringNode().getValue(), equalTo("source")); badBuildInfo.expectMember("validationEvents").expectArrayNode(); } @Test public void canIgnoreUnknownPlugins() throws Exception { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("unknown-plugin-ignored.json").toURI())) + .load(Paths.get( + getClass().getResource("unknown-plugin-ignored.json").toURI())) .outputDirectory(outputDirectory.toString()) .build(); Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("resource-model.json").toURI())) + .addImport( + Paths.get(getClass().getResource("resource-model.json").toURI())) .assemble() .unwrap(); SmithyBuild builder = new SmithyBuild(config).model(model); @@ -261,7 +261,8 @@ public void failsByDefaultForUnknownPlugins() throws Exception { .outputDirectory(outputDirectory.toString()) .build(); Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("resource-model.json").toURI())) + .addImport( + Paths.get(getClass().getResource("resource-model.json").toURI())) .assemble() .unwrap(); @@ -287,18 +288,19 @@ public void defersFailureUntilAfterAllPluginsApplied() throws Exception { plugins.put("broken", new SmithyBuildPlugin() { @Override public String getName() { - return "broken"; - } + return "broken"; + } + @Override public void execute(PluginContext context) { - throw canned; - } + throw canned; + } }); plugins.put("test1Serial", new Test1SerialPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); // Because the build will fail, we need a way to access the file manifests List manifests = new ArrayList<>(); @@ -317,16 +319,17 @@ public void execute(PluginContext context) { // "broken" plugin produces the error that causes the build to fail assertThat(e.getMessage(), containsString("java.lang.RuntimeException: broken")); - assertThat(e.getSuppressed(), equalTo(new Throwable[]{canned})); - - List files = manifests.stream() - .flatMap(fm -> fm.getFiles().stream()) - .collect(Collectors.toList()); - assertThat(files, containsInAnyOrder( - outputDirectory.resolve("source/sources/manifest"), - outputDirectory.resolve("source/model/model.json"), - outputDirectory.resolve("source/build-info/smithy-build-info.json"), - outputDirectory.resolve("source/test1Serial/hello1Serial"))); + assertThat(e.getSuppressed(), equalTo(new Throwable[] {canned})); + + List files = + manifests.stream().flatMap(fm -> fm.getFiles().stream()).collect(Collectors.toList()); + assertThat( + files, + containsInAnyOrder( + outputDirectory.resolve("source/sources/manifest"), + outputDirectory.resolve("source/model/model.json"), + outputDirectory.resolve("source/build-info/smithy-build-info.json"), + outputDirectory.resolve("source/test1Serial/hello1Serial"))); } @Test @@ -334,9 +337,13 @@ public void cannotSetFiltersOrMappersOnSourceProjection() { Throwable thrown = Assertions.assertThrows(SmithyBuildException.class, () -> { SmithyBuildConfig config = SmithyBuildConfig.builder() .version(SmithyBuild.VERSION) - .projections(MapUtils.of("source", ProjectionConfig.builder() - .transforms(ListUtils.of(TransformConfig.builder().name("foo").build())) - .build())) + .projections(MapUtils.of( + "source", + ProjectionConfig.builder() + .transforms(ListUtils.of(TransformConfig.builder() + .name("foo") + .build())) + .build())) .build(); new SmithyBuild().config(config).build(); }); @@ -347,8 +354,10 @@ public void cannotSetFiltersOrMappersOnSourceProjection() { @Test public void loadsImports() throws Exception { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("imports/smithy-build.json").toURI())) - .load(Paths.get(getClass().getResource("otherimports/smithy-build.json").toURI())) + .load(Paths.get( + getClass().getResource("imports/smithy-build.json").toURI())) + .load(Paths.get( + getClass().getResource("otherimports/smithy-build.json").toURI())) .outputDirectory(outputDirectory.toString()) .build(); SmithyBuild builder = new SmithyBuild(config); @@ -358,44 +367,90 @@ public void loadsImports() throws Exception { Model resultB = results.getProjectionResult("b").get().getModel(); Model resultC = results.getProjectionResult("c").get().getModel(); - assertTrue(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(SensitiveTrait.class).isPresent()); - assertFalse(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).isPresent()); - assertTrue(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).isPresent()); - assertThat(resultA.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).get().getValues().get(0), equalTo("multi-import")); - - assertTrue(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(SensitiveTrait.class).isPresent()); - assertTrue(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).isPresent()); - assertThat(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).get().getValue(), equalTo("b.json")); - assertTrue(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).isPresent()); - assertThat(resultB.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).get().getValues().get(0), equalTo("multi-import")); - - assertTrue(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(SensitiveTrait.class).isPresent()); - assertTrue(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).isPresent()); - assertThat(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(DocumentationTrait.class).get().getValue(), equalTo("c.json")); - assertTrue(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).isPresent()); - assertThat(resultC.getShape(ShapeId.from("com.foo#String")).get() - .getTrait(TagsTrait.class).get().getValues().get(0), equalTo("multi-import")); + assertTrue(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(SensitiveTrait.class) + .isPresent()); + assertFalse(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .isPresent()); + assertTrue(resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .isPresent()); + assertThat( + resultA.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .get() + .getValues() + .get(0), + equalTo("multi-import")); + + assertTrue(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(SensitiveTrait.class) + .isPresent()); + assertTrue(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .isPresent()); + assertThat( + resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .get() + .getValue(), + equalTo("b.json")); + assertTrue(resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .isPresent()); + assertThat( + resultB.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .get() + .getValues() + .get(0), + equalTo("multi-import")); + + assertTrue(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(SensitiveTrait.class) + .isPresent()); + assertTrue(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .isPresent()); + assertThat( + resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(DocumentationTrait.class) + .get() + .getValue(), + equalTo("c.json")); + assertTrue(resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .isPresent()); + assertThat( + resultC.getShape(ShapeId.from("com.foo#String")) + .get() + .getTrait(TagsTrait.class) + .get() + .getValues() + .get(0), + equalTo("multi-import")); } @Test public void appliesPlugins() throws Exception { Map plugins = MapUtils.of("test1", new Test1Plugin(), "test2", new Test2Plugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); @@ -435,13 +490,14 @@ public void appliesSerialPlugins() throws Exception { plugins.put("test2Parallel", new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("applies-serial-plugins.json").toURI())) + .load(Paths.get( + getClass().getResource("applies-serial-plugins.json").toURI())) .outputDirectory("/foo") .build()); @@ -468,16 +524,17 @@ public void appliesGlobalSerialPlugins() throws Exception { Map plugins = MapUtils.of( "test1Serial", new Test1SerialPlugin(), "test1Parallel", new Test1ParallelPlugin(), - "test2Parallel", new Test2ParallelPlugin() - ); + "test2Parallel", new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("applies-global-serial-plugins.json").toURI())) + .load(Paths.get(getClass() + .getResource("applies-global-serial-plugins.json") + .toURI())) .outputDirectory("/foo") .build()); @@ -491,11 +548,13 @@ public void appliesGlobalSerialPlugins() throws Exception { } private long getPluginFileContents(ProjectionResult projection, String pluginName) { - MockManifest manifest = (MockManifest) projection.getPluginManifest(pluginName).get(); - return Long.parseLong(manifest.getFileString(manifest.getFiles().iterator().next()).get()); + MockManifest manifest = + (MockManifest) projection.getPluginManifest(pluginName).get(); + return Long.parseLong( + manifest.getFileString(manifest.getFiles().iterator().next()).get()); } - private void assertPluginPresent(String pluginName, String outputFileName, ProjectionResult...results) { + private void assertPluginPresent(String pluginName, String outputFileName, ProjectionResult... results) { for (ProjectionResult result : results) { assertTrue(result.getPluginManifest(pluginName).isPresent()); assertTrue(result.getPluginManifest(pluginName).get().hasFile(outputFileName)); @@ -522,18 +581,20 @@ public void buildCanOverrideConfigOutputDirectory() throws Exception { SmithyBuildResult results = builder.build(); List files = results.allArtifacts().collect(Collectors.toList()); - assertThat(files, containsInAnyOrder( - outputDirectory.resolve("source/sources/manifest"), - outputDirectory.resolve("source/model/model.json"), - outputDirectory.resolve("source/build-info/smithy-build-info.json"), - outputDirectory.resolve("a/sources/manifest"), - outputDirectory.resolve("a/sources/model.json"), - outputDirectory.resolve("a/model/model.json"), - outputDirectory.resolve("a/build-info/smithy-build-info.json"), - outputDirectory.resolve("b/sources/manifest"), - outputDirectory.resolve("b/sources/model.json"), - outputDirectory.resolve("b/model/model.json"), - outputDirectory.resolve("b/build-info/smithy-build-info.json"))); + assertThat( + files, + containsInAnyOrder( + outputDirectory.resolve("source/sources/manifest"), + outputDirectory.resolve("source/model/model.json"), + outputDirectory.resolve("source/build-info/smithy-build-info.json"), + outputDirectory.resolve("a/sources/manifest"), + outputDirectory.resolve("a/sources/model.json"), + outputDirectory.resolve("a/model/model.json"), + outputDirectory.resolve("a/build-info/smithy-build-info.json"), + outputDirectory.resolve("b/sources/manifest"), + outputDirectory.resolve("b/sources/model.json"), + outputDirectory.resolve("b/model/model.json"), + outputDirectory.resolve("b/build-info/smithy-build-info.json"))); } @Test @@ -552,20 +613,25 @@ public void detectsCyclesInApplyProjection() throws Exception { public void detectsMissingApplyProjection() throws Exception { Throwable thrown = Assertions.assertThrows(SmithyBuildException.class, () -> { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-invalid-projection.json").toURI())) + .load(Paths.get(getClass() + .getResource("apply-invalid-projection.json") + .toURI())) .build(); new SmithyBuild().config(config).build(); }); - assertThat(thrown.getMessage(), - containsString("Unable to find projection named `bar` referenced by the `foo` projection")); + assertThat( + thrown.getMessage(), + containsString("Unable to find projection named `bar` referenced by the `foo` projection")); } @Test public void detectsDirectlyRecursiveApply() throws Exception { Throwable thrown = Assertions.assertThrows(SmithyBuildException.class, () -> { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-direct-recursion.json").toURI())) + .load(Paths.get(getClass() + .getResource("apply-direct-recursion.json") + .toURI())) .build(); new SmithyBuild().config(config).build(); }); @@ -580,11 +646,11 @@ public void appliesProjections() throws Exception { .assemble() .unwrap(); - SmithyBuild builder = new SmithyBuild() - .model(model) - .fileManifestFactory(MockManifest::new); + SmithyBuild builder = new SmithyBuild().model(model).fileManifestFactory(MockManifest::new); builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-multiple-projections.json").toURI())) + .load(Paths.get(getClass() + .getResource("apply-multiple-projections.json") + .toURI())) .outputDirectory("/foo") .build()); @@ -610,8 +676,9 @@ public void pluginsMustHaveValidNames() { new SmithyBuild().config(config).build(); }); - assertThat(thrown.getMessage(), containsString( - "Invalid plugin name `!invalid` found in the `[top-level]` projection")); + assertThat( + thrown.getMessage(), + containsString("Invalid plugin name `!invalid` found in the `[top-level]` projection")); } @Test @@ -626,7 +693,9 @@ public void canFilterProjections() throws URISyntaxException { .fileManifestFactory(MockManifest::new) .projectionFilter(name -> name.equals("a")); builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-multiple-projections.json").toURI())) + .load(Paths.get(getClass() + .getResource("apply-multiple-projections.json") + .toURI())) .outputDirectory("/foo") .build()); @@ -647,7 +716,9 @@ public void canFilterPlugins() throws URISyntaxException { .fileManifestFactory(MockManifest::new) .pluginFilter(name -> name.equals("build-info")); builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-multiple-projections.json").toURI())) + .load(Paths.get(getClass() + .getResource("apply-multiple-projections.json") + .toURI())) .outputDirectory("/foo") .build()); @@ -661,7 +732,8 @@ public void canFilterPlugins() throws URISyntaxException { @Test public void throwsWhenErrorsOccur() throws Exception { - Path badConfig = Paths.get(getClass().getResource("trigger-plugin-error.json").toURI()); + Path badConfig = + Paths.get(getClass().getResource("trigger-plugin-error.json").toURI()); Model model = Model.assembler() .addImport(getClass().getResource("simple-model.json")) .assemble() @@ -682,8 +754,8 @@ public void execute(PluginContext context) { }); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild() .model(model) @@ -694,21 +766,22 @@ public void execute(PluginContext context) { SmithyBuildException e = Assertions.assertThrows(SmithyBuildException.class, builder::build); assertThat(e.getMessage(), containsString("1 Smithy build projections failed")); assertThat(e.getMessage(), containsString("(exampleProjection): java.lang.RuntimeException: Hi")); - assertThat(e.getSuppressed(), equalTo(new Throwable[]{canned})); + assertThat(e.getSuppressed(), equalTo(new Throwable[] {canned})); } /* - This test causes SmithyBuild to fail in a way that it's unable to create Model as part of the - projection while using imports. This trigger a specific code path that needs to be able to create - a ProjectionResult with no model, so an empty model is provided. To achieve this, a test trait is - used with a custom trait factory that always throws when toNode is called on the trait (this is - something that's used for lots of stuff like trait hash code and equality). Smithy's model - assembler will catch the thrown SourceException, turn it into a validation event, and then bail - on trying to finish to build the model, triggering the code path under test here. - */ + This test causes SmithyBuild to fail in a way that it's unable to create Model as part of the + projection while using imports. This trigger a specific code path that needs to be able to create + a ProjectionResult with no model, so an empty model is provided. To achieve this, a test trait is + used with a custom trait factory that always throws when toNode is called on the trait (this is + something that's used for lots of stuff like trait hash code and equality). Smithy's model + assembler will catch the thrown SourceException, turn it into a validation event, and then bail + on trying to finish to build the model, triggering the code path under test here. + */ @Test public void projectionsThatCannotCreateModelsFailGracefully() throws URISyntaxException { - Path config = Paths.get(getClass().getResource("test-bad-trait-serializer-config.json").toURI()); + Path config = Paths.get( + getClass().getResource("test-bad-trait-serializer-config.json").toURI()); Model model = Model.assembler() .addImport(getClass().getResource("test-bad-trait-serializer.smithy")) .assemble() @@ -721,14 +794,13 @@ public void projectionsThatCannotCreateModelsFailGracefully() throws URISyntaxEx .fileManifestFactory(MockManifest::new) .modelAssemblerSupplier(() -> { // Hook in a TraitFactory that knows about our custom, failing trait. - return Model.assembler() - .traitFactory((id, target, node) -> { - if (id.equals(badId)) { - return Optional.of(new BadCustomTrait()); - } else { - return baseFactory.createTrait(id, target, node); - } - }); + return Model.assembler().traitFactory((id, target, node) -> { + if (id.equals(badId)) { + return Optional.of(new BadCustomTrait()); + } else { + return baseFactory.createTrait(id, target, node); + } + }); }); SmithyBuildResult result = builder.build(); @@ -737,7 +809,8 @@ public void projectionsThatCannotCreateModelsFailGracefully() throws URISyntaxEx assertTrue(result.anyBroken()); // Now validate that we got the failure to serialize the model. - List events = result.getProjectionResultsMap().get("foo").getEvents(); + List events = + result.getProjectionResultsMap().get("foo").getEvents(); assertThat(events, not(empty())); assertThat(events.get(0).getSeverity(), is(Severity.ERROR)); assertThat(events.get(0).getMessage(), containsString("Unable to serialize trait")); @@ -758,11 +831,12 @@ public Node toNode() { @Test public void canRunMultiplePluginsWithDifferentArtifactNames() throws URISyntaxException { - Map plugins = MapUtils.of("test1", new Test1SerialPlugin(), - "test2", new Test2ParallelPlugin()); + Map plugins = MapUtils.of( + "test1", new Test1SerialPlugin(), + "test2", new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); SmithyBuild builder = new SmithyBuild().pluginFactory(composed); builder.fileManifestFactory(MockManifest::new); @@ -791,7 +865,10 @@ public void runsCommand() throws Exception { String output = runPosixTestAndGetOutput("run-plugin/run-plugin-test.json", "test-process"); assertThat(output, containsString("argv1: a")); - assertThat(output, containsString("SMITHY_ROOT_DIR: " + Paths.get(".").toAbsolutePath().normalize())); + assertThat( + output, + containsString( + "SMITHY_ROOT_DIR: " + Paths.get(".").toAbsolutePath().normalize())); assertThat(output, containsString("SMITHY_PLUGIN_DIR: " + outputDirectory.toString())); assertThat(output, containsString("SMITHY_PROJECTION_NAME: source")); assertThat(output, containsString("SMITHY_ARTIFACT_NAME: test-process")); @@ -835,7 +912,8 @@ private String runPosixTestAndGetOutput(String buildFile, String artifactName) t SmithyBuildResult results = builder.build(); ProjectionResult result = results.getProjectionResultsMap().get("source"); - Path outputFile = result.getPluginManifest(artifactName).get().getBaseDir().resolve("output.txt"); + Path outputFile = + result.getPluginManifest(artifactName).get().getBaseDir().resolve("output.txt"); return IoUtils.readUtf8File(outputFile); } @@ -864,9 +942,8 @@ public void exitsNonZero() { Assumptions.assumeTrue(isPosix()); SmithyBuildException e = Assertions.assertThrows( - SmithyBuildException.class, - () -> runPosixTestAndGetOutput("run-plugin/invalid-exit-code.json", "invalid-exit-code") - ); + SmithyBuildException.class, + () -> runPosixTestAndGetOutput("run-plugin/invalid-exit-code.json", "invalid-exit-code")); assertThat(e.getMessage(), containsString("Error exit code 2 returned from: `sh return-error.sh 2`")); } @@ -888,10 +965,12 @@ public void detectsConflictingArtifactNames() throws Exception { "test1", new Test1SerialPlugin(), "test2", new Test2ParallelPlugin()); Function> factory = SmithyBuildPlugin.createServiceFactory(); - Function> composed = name -> OptionalUtils.or( - Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); + Function> composed = + name -> OptionalUtils.or(Optional.ofNullable(plugins.get(name)), () -> factory.apply(name)); - URI build = getClass().getResource("run-plugin/invalid-conflicting-artifact-names.json").toURI(); + URI build = getClass() + .getResource("run-plugin/invalid-conflicting-artifact-names.json") + .toURI(); SmithyBuild builder = new SmithyBuild() .pluginFactory(composed) .fileManifestFactory(MockManifest::new) @@ -899,8 +978,9 @@ public void detectsConflictingArtifactNames() throws Exception { SmithyBuildException e = Assertions.assertThrows(SmithyBuildException.class, builder::build); - assertThat(e.getMessage(), containsString("Multiple plugins use the same artifact name 'foo' in " - + "the 'source' projection")); + assertThat( + e.getMessage(), + containsString("Multiple plugins use the same artifact name 'foo' in " + "the 'source' projection")); } @ParameterizedTest @@ -917,36 +997,41 @@ public void ignoreUnrecognizedModels(List models) throws URISyntaxExceptio // Apply multiple projections to ensure that sources are filtered even in projections. builder.config(SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("apply-multiple-projections.json").toURI())) - .outputDirectory("/foo") - .build()); + .load(Paths.get(getClass() + .getResource("apply-multiple-projections.json") + .toURI())) + .outputDirectory("/foo") + .build()); SmithyBuildResult results = builder.build(); assertTrue(results.getProjectionResult("source").isPresent()); assertTrue(results.getProjectionResult("a").isPresent()); ProjectionResult sourceResult = results.getProjectionResult("source").get(); - MockManifest sourceManifest = (MockManifest) sourceResult.getPluginManifest("sources").get(); - String sourceSourcesManifestText = sourceManifest.getFileString("manifest").get(); + MockManifest sourceManifest = + (MockManifest) sourceResult.getPluginManifest("sources").get(); + String sourceSourcesManifestText = + sourceManifest.getFileString("manifest").get(); assertThat(sourceSourcesManifestText, containsString("a.smithy")); assertThat(sourceSourcesManifestText, not(containsString("foo.md"))); ProjectionResult aResult = results.getProjectionResult("source").get(); - MockManifest aManifest = (MockManifest) aResult.getPluginManifest("sources").get(); + MockManifest aManifest = + (MockManifest) aResult.getPluginManifest("sources").get(); String aSourcesManifestText = aManifest.getFileString("manifest").get(); assertThat(aSourcesManifestText, not(containsString("foo.md"))); } public static List unrecognizedModelPaths() throws URISyntaxException { - Path rootPath = Paths.get(SmithyBuildTest.class.getResource("plugins/sources-ignores-unrecognized-files") - .toURI()); + Path rootPath = Paths.get(SmithyBuildTest.class + .getResource("plugins/sources-ignores-unrecognized-files") + .toURI()); return ListUtils.of( - // Test that crawling the directory works. - Arguments.of(ListUtils.of(rootPath)), - // Test that passing explicit files works too. - Arguments.of(ListUtils.of(rootPath.resolve("a.smithy"), rootPath.resolve("foo.md"))) - ); + // Test that crawling the directory works. + Arguments.of(ListUtils.of(rootPath)), + // Test that passing explicit files works too. + Arguments.of(ListUtils.of(rootPath.resolve("a.smithy"), rootPath.resolve("foo.md")))); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java index 05b192d7c1c..3a1259b3e8b 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test1ParallelPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test1ParallelPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java index 12058bb5058..3e4284ac949 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test1Plugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; public final class Test1Plugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java index a3d02b1f8f5..80bb5eb7c4c 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test1SerialPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test1SerialPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java index 13b5683c406..ea607ddc291 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test2ParallelPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test2ParallelPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java index 04edf6693e1..8751dbdfb39 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test2Plugin.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build; public final class Test2Plugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java index 1998af91293..4a1f47ca31e 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/Test2SerialPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build; public class Test2SerialPlugin implements SmithyBuildPlugin { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java index a3e2977fa3c..3765733cff4 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenConfigTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,9 +63,11 @@ public void mergesConfigs() { .build()); MavenConfig config2 = MavenConfig.fromNode(Node.objectNodeBuilder() .withMember("dependencies", Node.fromStrings("g:a:v", "a:a:a")) - .withMember("repositories", Node.fromNodes( - Node.objectNode().withMember("url", "https://example.com"), - Node.objectNode().withMember("url", "https://m2.example.com"))) + .withMember( + "repositories", + Node.fromNodes( + Node.objectNode().withMember("url", "https://example.com"), + Node.objectNode().withMember("url", "https://m2.example.com"))) .build()); MavenConfig merged = config1.merge(config2); @@ -73,9 +79,9 @@ public void mergesConfigs() { dependencies.add("a:a:a"); MavenConfig expectedMerge = MavenConfig.builder() - .repositories(repos) - .dependencies(dependencies) - .build(); + .repositories(repos) + .dependencies(dependencies) + .build(); assertThat(merged, equalTo(expectedMerge)); } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java index 288b0e51697..2d9c8f8ef01 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/model/MavenRepositoryTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -12,21 +16,30 @@ public class MavenRepositoryTest { @Test public void validatesHttpCredentialsValidColon() { Assertions.assertThrows(IllegalArgumentException.class, () -> { - MavenRepository.builder().url("https://example.com").httpCredentials(":").build(); + MavenRepository.builder() + .url("https://example.com") + .httpCredentials(":") + .build(); }); } @Test public void validatesHttpCredentialsHasColon() { Assertions.assertThrows(IllegalArgumentException.class, () -> { - MavenRepository.builder().url("https://example.com").httpCredentials("foo").build(); + MavenRepository.builder() + .url("https://example.com") + .httpCredentials("foo") + .build(); }); } @Test public void validatesHttpCredentialsColonNotAtBeginning() { Assertions.assertThrows(IllegalArgumentException.class, () -> { - MavenRepository.builder().url("https://example.com").httpCredentials(":foo").build(); + MavenRepository.builder() + .url("https://example.com") + .httpCredentials(":foo") + .build(); }); } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java index 6829346dbf5..c5b71bca8cf 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/model/SmithyBuildConfigTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.model; import static org.hamcrest.MatcherAssert.assertThat; @@ -68,8 +57,7 @@ public void requiresVersion() { @Test public void canBeAbstract() { - SmithyBuildConfig config = SmithyBuildConfig.load( - Paths.get(getResourcePath("config-with-abstract.json"))); + SmithyBuildConfig config = SmithyBuildConfig.load(Paths.get(getResourcePath("config-with-abstract.json"))); assertThat(config.getProjections().get("abstract").isAbstract(), is(true)); } @@ -102,8 +90,8 @@ public void canAddImports() { @Test public void canAddImportsAndOutputDirViaJson() { - SmithyBuildConfig config = SmithyBuildConfig.load( - Paths.get(getResourcePath("config-with-imports-and-output-dir.json"))); + SmithyBuildConfig config = + SmithyBuildConfig.load(Paths.get(getResourcePath("config-with-imports-and-output-dir.json"))); assertThat(config.getOutputDirectory(), not(Optional.empty())); assertThat(config.getImports(), not(empty())); @@ -111,9 +99,8 @@ public void canAddImportsAndOutputDirViaJson() { @Test public void addsBuiltinPlugins() { - SmithyBuildConfig config = SmithyBuildConfig.builder() - .version(SmithyBuild.VERSION) - .build(); + SmithyBuildConfig config = + SmithyBuildConfig.builder().version(SmithyBuild.VERSION).build(); assertThat(config.getPlugins(), hasKey("build-info")); assertThat(config.getPlugins(), hasKey("model")); @@ -125,15 +112,16 @@ public void expandsEnvironmentVariables() { System.setProperty("FOO", "Hi"); System.setProperty("BAR", "TagFromEnv"); System.setProperty("NAME_KEY", "name"); - SmithyBuildConfig config = SmithyBuildConfig.load( - Paths.get(getResourcePath("config-with-env.json"))); - TransformConfig transform = config.getProjections().get("a").getTransforms().get(0); + SmithyBuildConfig config = SmithyBuildConfig.load(Paths.get(getResourcePath("config-with-env.json"))); + TransformConfig transform = + config.getProjections().get("a").getTransforms().get(0); // Did the key expand? assertThat(transform.getName(), equalTo("includeShapesByTag")); // Did the array and string values in it expand? - assertThat(transform.getArgs(), equalTo(Node.objectNode() - .withMember("tags", Node.fromStrings("Hi", "compoundTagFromEnv", "${BAZ}")))); + assertThat( + transform.getArgs(), + equalTo(Node.objectNode().withMember("tags", Node.fromStrings("Hi", "compoundTagFromEnv", "${BAZ}")))); } @Test @@ -145,9 +133,9 @@ public void throwsForUnknownEnvironmentVariables() { @Test public void rewritesArgsArrayToUnderscoreArgs() { - SmithyBuildConfig config = SmithyBuildConfig.load( - Paths.get(getResourcePath("rewrites-args-array.json"))); - ObjectNode node = config.getProjections().get("rewrite").getTransforms().get(0).getArgs(); + SmithyBuildConfig config = SmithyBuildConfig.load(Paths.get(getResourcePath("rewrites-args-array.json"))); + ObjectNode node = + config.getProjections().get("rewrite").getTransforms().get(0).getArgs(); ObjectNode expected = Node.objectNode().withMember("__args", Node.fromStrings("sensitive")); Node.assertEquals(node, expected); @@ -186,46 +174,55 @@ public void mergingTakesIgnoreMissingPluginsFromEither() { @Test public void loadsFromNode() throws IOException { Path root = Paths.get("/"); - ObjectNode value = Node.parse(getClass().getResource("loads-from-node.json").openStream()) - .expectObjectNode() - .toBuilder() - .sourceLocation(new SourceLocation( - root.resolve("hello").resolve("smithy-build.json").toString(), 1, 1)) - .build(); + ObjectNode value = + Node.parse(getClass().getResource("loads-from-node.json").openStream()).expectObjectNode().toBuilder() + .sourceLocation(new SourceLocation( + root.resolve("hello") + .resolve("smithy-build.json") + .toString(), + 1, + 1)) + .build(); SmithyBuildConfig config = SmithyBuildConfig.fromNode(value); - assertThat(config.getImports(), contains(root.resolve("hello").resolve("foo.json").toString())); - assertThat(config.getProjections().get("a").getImports(), - contains(root.resolve("hello").resolve("baz.json").toString())); + assertThat( + config.getImports(), + contains(root.resolve("hello").resolve("foo.json").toString())); + assertThat( + config.getProjections().get("a").getImports(), + contains(root.resolve("hello").resolve("baz.json").toString())); } @Test public void loadsFromNodeIgnoringBadSourceLocations() throws IOException { - ObjectNode value = Node.parse(getClass().getResource("loads-from-node.json").openStream()) + ObjectNode value = Node.parse( + getClass().getResource("loads-from-node.json").openStream()) .expectObjectNode(); SmithyBuildConfig config = SmithyBuildConfig.fromNode(value); 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())); + assertThat( + config.getProjections().get("a").getImports(), + contains(cwd.resolve("baz.json").toString())); } @Test public void outputDirCannotBeEmpty() throws IOException { Assertions.assertThrows(IllegalArgumentException.class, () -> { - SmithyBuildConfig.builder() - .version("1.0") - .outputDirectory("") - .build(); + SmithyBuildConfig.builder().version("1.0").outputDirectory("").build(); }); } @Test public void mergingTakesOtherMavenConfigWhenHasNone() { SmithyBuildConfig a = SmithyBuildConfig.builder().version("1").build(); - SmithyBuildConfig b = SmithyBuildConfig.builder().version("1") - .maven(MavenConfig.builder().dependencies(ListUtils.of("a:b:1.0.0")).build()) + SmithyBuildConfig b = SmithyBuildConfig.builder() + .version("1") + .maven(MavenConfig.builder() + .dependencies(ListUtils.of("a:b:1.0.0")) + .build()) .build(); assertThat(a.toBuilder().merge(b).build().getMaven(), equalTo(b.getMaven())); @@ -233,8 +230,11 @@ public void mergingTakesOtherMavenConfigWhenHasNone() { @Test public void mergingTakesSelfMavenConfigWhenOtherHasNone() { - SmithyBuildConfig a = SmithyBuildConfig.builder().version("1") - .maven(MavenConfig.builder().dependencies(ListUtils.of("a:b:1.0.0")).build()) + SmithyBuildConfig a = SmithyBuildConfig.builder() + .version("1") + .maven(MavenConfig.builder() + .dependencies(ListUtils.of("a:b:1.0.0")) + .build()) .build(); SmithyBuildConfig b = SmithyBuildConfig.builder().version("1").build(); @@ -243,14 +243,20 @@ public void mergingTakesSelfMavenConfigWhenOtherHasNone() { @Test public void mergingCombinesMavenConfigsWhenBothPresent() { - SmithyBuildConfig a = SmithyBuildConfig.builder().version("1") - .maven(MavenConfig.builder().dependencies(ListUtils.of("c:d:1.0.0")).build()) + SmithyBuildConfig a = SmithyBuildConfig.builder() + .version("1") + .maven(MavenConfig.builder() + .dependencies(ListUtils.of("c:d:1.0.0")) + .build()) .build(); - SmithyBuildConfig b = SmithyBuildConfig.builder().version("1") - .maven(MavenConfig.builder().dependencies(ListUtils.of("a:b:1.0.0", "c:d:1.0.0")).build()) + SmithyBuildConfig b = SmithyBuildConfig.builder() + .version("1") + .maven(MavenConfig.builder() + .dependencies(ListUtils.of("a:b:1.0.0", "c:d:1.0.0")) + .build()) .build(); - assertThat(a.toBuilder().merge(b).build().getMaven().get().getDependencies(), - contains("c:d:1.0.0", "a:b:1.0.0")); + assertThat( + a.toBuilder().merge(b).build().getMaven().get().getDependencies(), contains("c:d:1.0.0", "a:b:1.0.0")); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java index 4b4c7ff7a68..e6c45069739 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/BuildInfoPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,13 +34,14 @@ public void testFiltersSyntheticEnumTrait() throws URISyntaxException { .model(model) .originalModel(model) .projection("TEST", ProjectionConfig.builder().build()) - .sources(ListUtils.of(Paths.get(getClass().getResource(testPath).toURI()).getParent())) + .sources(ListUtils.of( + Paths.get(getClass().getResource(testPath).toURI()).getParent())) .build(); new BuildInfoPlugin().execute(context); - String buildInfo = manifest.getFileString(BuildInfoPlugin.BUILD_INFO_PATH).get(); + String buildInfo = + manifest.getFileString(BuildInfoPlugin.BUILD_INFO_PATH).get(); assertThat(buildInfo, not(containsString("smithy.synthetic#enum"))); } - } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java index b3801c0971e..21dd7ae63f0 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/ConfigurableSmithyBuildPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; @@ -20,9 +24,9 @@ public void loadsConfigurationClass() { MockManifest manifest = new MockManifest(); PluginContext context = PluginContext.builder() .settings(Node.objectNode() - .withMember("foo", "hello") - .withMember("bar", 10) - .withMember("baz", true)) + .withMember("foo", "hello") + .withMember("bar", 10) + .withMember("baz", true)) .fileManifest(manifest) .model(model) .originalModel(model) diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java index d907702a5a0..aad20728e02 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/NullabilityReportPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,11 +38,13 @@ public void generatesReport() throws URISyntaxException { .model(model) .originalModel(model) .projection("TEST", ProjectionConfig.builder().build()) - .sources(ListUtils.of(Paths.get(getClass().getResource(testPath).toURI()).getParent())) + .sources(ListUtils.of( + Paths.get(getClass().getResource(testPath).toURI()).getParent())) .build(); new NullabilityReportPlugin().execute(context); - String report = manifest.getFileString(NullabilityReportPlugin.NULLABILITY_REPORT_PATH).get(); + String report = manifest.getFileString(NullabilityReportPlugin.NULLABILITY_REPORT_PATH) + .get(); ObjectNode reportNode = Node.parse(report).expectObjectNode(); Map isNullable = new LinkedHashMap<>(); @@ -80,9 +86,10 @@ public void generatesReport() throws URISyntaxException { isNullable.forEach((pointer, expectedIsNullable) -> { NodePointer nodePointer = NodePointer.parse(pointer); - boolean actualIsNull = nodePointer.getValue(reportNode).expectBooleanNode().getValue(); - assertThat("Expected " + pointer + " to be " + expectedIsNullable, - actualIsNull, equalTo(expectedIsNullable)); + boolean actualIsNull = + nodePointer.getValue(reportNode).expectBooleanNode().getValue(); + assertThat( + "Expected " + pointer + " to be " + expectedIsNullable, actualIsNull, equalTo(expectedIsNullable)); }); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java index 28eca8dff7d..ce43a6659f6 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/plugins/SourcesPluginTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.plugins; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,7 +40,9 @@ public void copiesFilesForSourceProjection() throws URISyntaxException { .fileManifest(manifest) .model(model) .originalModel(model) - .sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").toURI()).getParent())) + .sources(ListUtils.of( + Paths.get(getClass().getResource("sources/a.smithy").toURI()) + .getParent())) .build(); new SourcesPlugin().execute(context); String manifestString = manifest.getFileString("manifest").get(); @@ -64,7 +70,8 @@ public void copiesModelFromJarWithSourceProjection() throws URISyntaxException { .fileManifest(manifest) .model(model) .originalModel(model) - .sources(ListUtils.of(Paths.get(getClass().getResource("sources/jar-import.jar").toURI()))) + .sources(ListUtils.of(Paths.get( + getClass().getResource("sources/jar-import.jar").toURI()))) .build(); new SourcesPlugin().execute(context); String manifestString = manifest.getFileString("manifest").get(); @@ -94,7 +101,8 @@ public void copiesModelFromJarWithNonSourceProjection() throws URISyntaxExceptio .projection("foo", projection) .model(model) .originalModel(model) - .sources(ListUtils.of(Paths.get(getClass().getResource("sources/jar-import.jar").toURI()))) + .sources(ListUtils.of(Paths.get( + getClass().getResource("sources/jar-import.jar").toURI()))) .build(); new SourcesPlugin().execute(context); String manifestString = manifest.getFileString("manifest").get(); @@ -124,7 +132,9 @@ public void copiesOnlyFilesFromSourcesForProjection() throws URISyntaxException .fileManifest(manifest) .model(model) .originalModel(model) - .sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").toURI()).getParent())) + .sources(ListUtils.of( + Paths.get(getClass().getResource("sources/a.smithy").toURI()) + .getParent())) .build(); new SourcesPlugin().execute(context); String manifestString = manifest.getFileString("manifest").get(); @@ -159,7 +169,9 @@ public void treatsNewlyAddedShapesAsNewSources() throws URISyntaxException { .fileManifest(manifest) .originalModel(originalModel) .model(newModel) - .sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").toURI()).getParent())) + .sources(ListUtils.of( + Paths.get(getClass().getResource("sources/a.smithy").toURI()) + .getParent())) .build(); new SourcesPlugin().execute(context); String modelString = manifest.getFileString("model.json").get(); @@ -190,15 +202,16 @@ public void doesNotAllowConflicts() throws URISyntaxException { @Test public void copiesModelsDefinedInConfigAsSources() throws URISyntaxException { SmithyBuildConfig config = SmithyBuildConfig.builder() - .load(Paths.get(getClass().getResource("sources/copiesModelsDefinedInConfigAsSources.json").toURI())) + .load(Paths.get(getClass() + .getResource("sources/copiesModelsDefinedInConfigAsSources.json") + .toURI())) .build(); SmithyBuild b = new SmithyBuild(); b.fileManifestFactory(p -> new MockManifest()); b.config(config); SmithyBuildResult result = b.build(); - MockManifest manifest = (MockManifest) result - .getProjectionResult("source") + MockManifest manifest = (MockManifest) result.getProjectionResult("source") .get() .getPluginManifest("sources") .get(); @@ -222,7 +235,9 @@ public void omitsUnsupportedFilesFromManifest() throws URISyntaxException { .fileManifest(manifest) .model(model) .originalModel(model) - .sources(ListUtils.of(Paths.get(getClass().getResource("sources-ignores-unrecognized-files").toURI()))) + .sources(ListUtils.of(Paths.get(getClass() + .getResource("sources-ignores-unrecognized-files") + .toURI()))) .build(); new SourcesPlugin().execute(context); String manifestString = manifest.getFileString("manifest").get(); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java index 7b85362c8b8..a68a8e64ac4 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/AnnotationProcessorTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import com.google.testing.compile.Compilation; @@ -8,21 +12,18 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static com.google.testing.compile.CompilationSubject.assertThat; - /** * Test the {@link SmithyAnnotationProcessor} */ public class AnnotationProcessorTest { - private static final Compiler compiler = Compiler.javac() - .withProcessors(new TestProcessorImplementation()); + private static final Compiler compiler = Compiler.javac().withProcessors(new TestProcessorImplementation()); private static Compilation compilation; @BeforeAll static void compile() { - compilation = compiler.compile(JavaFileObjects.forResource( - "software/amazon/smithy/build/processor/package-info.java")); + compilation = compiler.compile( + JavaFileObjects.forResource("software/amazon/smithy/build/processor/package-info.java")); CompilationSubject.assertThat(compilation).succeeded(); } @@ -45,7 +46,8 @@ void generatesMetaInfFiles() { @Test void ignoresFile() { - CompilationSubject.assertThat(compilation).hadNoteContaining("Executing processor: TestProcessorImplementation..."); + CompilationSubject.assertThat(compilation) + .hadNoteContaining("Executing processor: TestProcessorImplementation..."); CompilationSubject.assertThat(compilation).hadNoteContaining("Ignoring generated file: "); CompilationSubject.assertThat(compilation).hadNoteContaining("Ignored.ignored"); } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java index 30cbe2c5faf..7ccb1755d19 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestBuildPlugin.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import java.nio.file.Paths; @@ -23,18 +27,15 @@ public void execute(PluginContext context) { String pathifiedNamespace = settings.packageName.replace(".", "/"); // Write an empty java class - fileManifest.writeFile(pathifiedNamespace + "/Empty.java", - getEmptyClass(settings.packageName)); + fileManifest.writeFile(pathifiedNamespace + "/Empty.java", getEmptyClass(settings.packageName)); // Write a META-INF metadata file fileManifest.writeFile( Paths.get(META_INF_LOCATION + "com.example.spi.impl.Example").normalize(), - settings.packageName + "." + "Empty" - ); + settings.packageName + "." + "Empty"); // Write a non-java file we expect to be ignored - fileManifest.writeFile(pathifiedNamespace + "/Ignored.ignored", - "ignore me. I dont compile!"); + fileManifest.writeFile(pathifiedNamespace + "/Ignored.ignored", "ignore me. I dont compile!"); // Require that expected smithy shapes were correctly loaded context.getModel().expectShape(ShapeId.from("com.testing.smithy#StructyMcStructFace")); @@ -42,15 +43,19 @@ public void execute(PluginContext context) { public static String getEmptyClass(String namespace) { StringBuilder builder = new StringBuilder(); - builder.append("package ").append(namespace).append(";").append(System.lineSeparator()) + builder.append("package ") + .append(namespace) + .append(";") .append(System.lineSeparator()) - .append("public final class Empty {").append(System.lineSeparator()) .append(System.lineSeparator()) - .append("}").append(System.lineSeparator()); + .append("public final class Empty {") + .append(System.lineSeparator()) + .append(System.lineSeparator()) + .append("}") + .append(System.lineSeparator()); return builder.toString(); } - private static final class Settings { private final String packageName; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java index c67c4690f06..afd6b547478 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorAnnotation.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import java.lang.annotation.ElementType; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java index 229cd8dc146..d3ddcd27800 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/processor/TestProcessorImplementation.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.processor; import javax.annotation.processing.SupportedAnnotationTypes; @@ -21,8 +25,6 @@ protected Class getAnnotationClass() { @Override protected ObjectNode createPluginNode(TestProcessorAnnotation annotation, String packageName) { - return Node.objectNodeBuilder() - .withMember("packageName", packageName) - .build(); + return Node.objectNodeBuilder().withMember("packageName", packageName).build(); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java index 443be0b8b39..e9894bc5819 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeStringEnumsToEnumShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,10 +25,7 @@ public class ChangeStringEnumsToEnumShapesTest { @Test public void canFindEnumsToConvert() { EnumTrait compatibleTrait = EnumTrait.builder() - .addEnum(EnumDefinition.builder() - .name("foo") - .value("bar") - .build()) + .addEnum(EnumDefinition.builder().name("foo").value("bar").build()) .build(); ShapeId compatibleStringId = ShapeId.fromParts("ns.foo", "CompatibleString"); StringShape compatibleString = StringShape.builder() @@ -49,9 +35,7 @@ public void canFindEnumsToConvert() { // This won't have a name synthesized because that setting is disabled EnumTrait incompatibleTrait = EnumTrait.builder() - .addEnum(EnumDefinition.builder() - .value("bar") - .build()) + .addEnum(EnumDefinition.builder().value("bar").build()) .build(); ShapeId incompatibleStringId = ShapeId.fromParts("ns.foo", "IncompatibleString"); StringShape incompatibleString = StringShape.builder() @@ -62,7 +46,8 @@ public void canFindEnumsToConvert() { Model model = Model.assembler() .addShape(compatibleString) .addShape(incompatibleString) - .assemble().unwrap(); + .assemble() + .unwrap(); TransformContext context = TransformContext.builder() .model(model) @@ -73,11 +58,13 @@ public void canFindEnumsToConvert() { assertThat(result.expectShape(compatibleStringId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(compatibleStringId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(compatibleStringId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(compatibleStringId.withMember("foo")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("bar").build()) - .build())); + assertThat( + result.expectShape(compatibleStringId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(compatibleStringId.withMember("foo")) + .target(UnitTypeTrait.UNIT) + .addTrait(EnumValueTrait.builder().stringValue("bar").build()) + .build())); assertThat(result.expectShape(incompatibleStringId).getType(), Matchers.is(ShapeType.STRING)); assertThat(result.expectShape(incompatibleStringId).members(), Matchers.hasSize(0)); @@ -86,34 +73,29 @@ public void canFindEnumsToConvert() { @Test public void canSynthesizeNames() { EnumTrait trait = EnumTrait.builder() - .addEnum(EnumDefinition.builder() - .value("foo:bar") - .build()) + .addEnum(EnumDefinition.builder().value("foo:bar").build()) .build(); ShapeId shapeId = ShapeId.fromParts("ns.foo", "ConvertableShape"); - StringShape initialShape = StringShape.builder() - .id(shapeId) - .addTrait(trait) - .build(); + StringShape initialShape = + StringShape.builder().id(shapeId).addTrait(trait).build(); - Model model = Model.assembler() - .addShape(initialShape) - .assemble().unwrap(); + Model model = Model.assembler().addShape(initialShape).assemble().unwrap(); ObjectNode config = Node.parse("{\"synthesizeNames\": true}").expectObjectNode(); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Model result = new ChangeStringEnumsToEnumShapes().transform(context); assertThat(result.expectShape(shapeId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(shapeId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(shapeId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(shapeId.withMember("foo_bar")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) - .build())); + assertThat( + result.expectShape(shapeId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(shapeId.withMember("foo_bar")) + .target(UnitTypeTrait.UNIT) + .addTrait( + EnumValueTrait.builder().stringValue("foo:bar").build()) + .build())); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java index 65a6722de08..716f58369bd 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ChangeTypesTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -27,9 +31,12 @@ public void changesShapeTypes() { Model model = Model.assembler().addShapes(a, b).assemble().unwrap(); TransformContext context = TransformContext.builder() .model(model) - .settings(Node.objectNode().withMember("shapeTypes", Node.objectNode() - .withMember("ns.foo#a", "boolean") - .withMember("ns.foo#b", "union"))) + .settings(Node.objectNode() + .withMember( + "shapeTypes", + Node.objectNode() + .withMember("ns.foo#a", "boolean") + .withMember("ns.foo#b", "union"))) .build(); Model result = new ChangeTypes().transform(context); @@ -40,36 +47,31 @@ public void changesShapeTypes() { @Test public void canSynthesizeEnumNames() { EnumTrait trait = EnumTrait.builder() - .addEnum(EnumDefinition.builder() - .value("foo:bar") - .build()) + .addEnum(EnumDefinition.builder().value("foo:bar").build()) .build(); ShapeId shapeId = ShapeId.fromParts("ns.foo", "ConvertableShape"); - StringShape initialShape = StringShape.builder() - .id(shapeId) - .addTrait(trait) - .build(); + StringShape initialShape = + StringShape.builder().id(shapeId).addTrait(trait).build(); - Model model = Model.assembler() - .addShape(initialShape) - .assemble().unwrap(); + Model model = Model.assembler().addShape(initialShape).assemble().unwrap(); ObjectNode settings = Node.objectNode() .withMember("shapeTypes", Node.objectNode().withMember(shapeId.toString(), "enum")) .withMember("synthesizeEnumNames", true); - TransformContext context = TransformContext.builder() - .model(model) - .settings(settings) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(settings).build(); Model result = new ChangeTypes().transform(context); assertThat(result.expectShape(shapeId).getType(), Matchers.is(ShapeType.ENUM)); assertThat(result.expectShape(shapeId).members(), Matchers.hasSize(1)); - assertThat(result.expectShape(shapeId).members().iterator().next(), Matchers.equalTo(MemberShape.builder() - .id(shapeId.withMember("foo_bar")) - .target(UnitTypeTrait.UNIT) - .addTrait(EnumValueTrait.builder().stringValue("foo:bar").build()) - .build())); + assertThat( + result.expectShape(shapeId).members().iterator().next(), + Matchers.equalTo(MemberShape.builder() + .id(shapeId.withMember("foo_bar")) + .target(UnitTypeTrait.UNIT) + .addTrait( + EnumValueTrait.builder().stringValue("foo:bar").build()) + .build())); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java index bcb76784a29..9c3e8e2e246 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -31,9 +20,7 @@ public void removesMetadataInList() { Map metadata = new HashMap<>(); metadata.put("a", Node.arrayNode()); metadata.put("b", Node.objectNode().withMember("foo", Node.objectNode())); - Model model = Model.builder() - .metadata(metadata) - .build(); + Model model = Model.builder().metadata(metadata).build(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("keys", Node.fromStrings("a"))) diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java index d9d5bf812b4..0c777d34a16 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelectorTest.java @@ -1,25 +1,16 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import org.junit.jupiter.api.Test; + import java.nio.file.Paths; import java.util.Set; import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; import software.amazon.smithy.build.TransformContext; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.node.Node; @@ -37,60 +28,62 @@ public void excludesByOperationsThatUseEventStreams() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetBar", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetBar", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -102,32 +95,34 @@ public void excludesByServiceFoo() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#GetBar"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#GetBar"))); } @Test @@ -139,42 +134,44 @@ public void excludesByServiceBar() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -186,7 +183,7 @@ public void excludesNotByService() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( "smithy.example#BarService"))); + assertThat(exampleIds(result), is(SetUtils.of("smithy.example#BarService"))); } @Test @@ -198,63 +195,67 @@ public void excludesOnlyEnumMembersWithTags() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new ExcludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetBar", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetBar", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } Model testModel() { try { return Model.assembler() - .addImport(Paths.get(getClass().getResource("transform-by-selector.smithy").toURI())) + .addImport(Paths.get(getClass() + .getResource("transform-by-selector.smithy") + .toURI())) .assemble() .unwrap(); } catch (Exception e) { @@ -263,8 +264,7 @@ Model testModel() { } static Set exampleIds(Model model) { - return model.getShapeIds() - .stream() + return model.getShapeIds().stream() .filter(id -> id.getNamespace().equals("smithy.example")) .map(ShapeId::toString) .collect(Collectors.toSet()); diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java index 8400a796abc..61be9d0ba83 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -52,9 +41,7 @@ public void removesTraitsNotInList() { .id("ns.foo#bar") .addTrait(TagsTrait.builder().addValue("qux").build()) .build(); - Model model = Model.builder() - .addShapes(stringA, stringB) - .build(); + Model model = Model.builder().addShapes(stringA, stringB).build(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("tags", Node.fromStrings("foo"))) @@ -68,7 +55,8 @@ public void removesTraitsNotInList() { @Test public void filtersMembers() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("filter-by-tags.smithy").toURI())) + .addImport(Paths.get( + getClass().getResource("filter-by-tags.smithy").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() @@ -91,42 +79,71 @@ public void filtersMembers() throws Exception { @Test public void classesWithMixinsFilteredWithoutCycleError() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("mixin-cycle-test.smithy").toURI())) - .assemble() - .unwrap(); + .addImport(Paths.get( + getClass().getResource("mixin-cycle-test.smithy").toURI())) + .assemble() + .unwrap(); TransformContext context = TransformContext.builder() - .model(model) - .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) - .build(); + .model(model) + .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) + .build(); Model result = new ExcludeShapesByTag().transform(context); - ResourceShape resourceShape = result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); - assertFalse(resourceShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(resourceShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - - OperationShape operationShape = result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); - assertFalse(operationShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(operationShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - - StructureShape structureShape = result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); - assertFalse(structureShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(structureShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + ResourceShape resourceShape = + result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); + assertFalse(resourceShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(resourceShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); + + OperationShape operationShape = + result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); + assertFalse(operationShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(operationShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); + + StructureShape structureShape = + result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); + assertFalse(structureShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(structureShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); UnionShape unionShape = result.expectShape(ShapeId.from("smithy.example#UnionWithMixin"), UnionShape.class); - assertFalse(unionShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(unionShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse(unionShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(unionShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); MapShape mapShape = result.expectShape(ShapeId.from("smithy.example#MapWithMixin"), MapShape.class); - assertFalse(mapShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(mapShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse( + mapShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); + assertTrue(mapShape.findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); ListShape listShape = result.expectShape(ShapeId.from("smithy.example#ListWithMixin"), ListShape.class); - assertFalse(listShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(listShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse(listShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(listShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); StringShape stringShape = result.expectShape(ShapeId.from("smithy.example#StringWithMixin"), StringShape.class); - assertFalse(stringShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(stringShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - + assertFalse(stringShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(stringShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java index 14b3db24990..e5c7b1f70b7 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeShapesByTraitTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -42,7 +46,6 @@ public static List traitValues() { // Relative IDs are assumed to be in "smithy.api". "internal", // Absolute IDs are used as-is. - "smithy.api#internal" - ); + "smithy.api#internal"); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java index 5fb27e1b859..231bb58d365 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -41,7 +30,8 @@ public class ExcludeTraitsByTagTest { @Test public void removesTraitsByTagInList() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("tree-shaking-traits.json").toURI())) + .addImport(Paths.get( + getClass().getResource("tree-shaking-traits.json").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() @@ -57,8 +47,8 @@ public void removesTraitsByTagInList() throws Exception { assertTrue(traits.contains(ShapeId.from("ns.foo#bar"))); // Mixin members are retained, but tagged traits are excluded. - MemberShape mixedMember = result.expectShape(ShapeId.from("ns.foo#MyOperationInput$mixedMember"), - MemberShape.class); + MemberShape mixedMember = + result.expectShape(ShapeId.from("ns.foo#MyOperationInput$mixedMember"), MemberShape.class); assertFalse(mixedMember.findMemberTrait(result, "ns.foo#corge").isPresent()); assertTrue(mixedMember.findMemberTrait(result, "ns.foo#bar").isPresent()); } @@ -66,48 +56,78 @@ public void removesTraitsByTagInList() throws Exception { @Test public void classesWithMixinsFilteredWithoutCycleError() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("mixin-cycle-test.smithy").toURI())) - .assemble() - .unwrap(); + .addImport(Paths.get( + getClass().getResource("mixin-cycle-test.smithy").toURI())) + .assemble() + .unwrap(); TransformContext context = TransformContext.builder() - .model(model) - .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) - .build(); + .model(model) + .settings(Node.objectNode().withMember("tags", Node.fromStrings("filter"))) + .build(); Model result = new ExcludeTraitsByTag().transform(context); Set traits = result.getShapesWithTrait(TraitDefinition.class).stream() - .map(Shape::getId) - .collect(Collectors.toSet()); + .map(Shape::getId) + .collect(Collectors.toSet()); assertFalse(traits.contains(ShapeId.from("smithy.example#filteredTrait"))); assertTrue(traits.contains(ShapeId.from("smithy.example#unfilteredTrait"))); - ResourceShape resourceShape = result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); - assertFalse(resourceShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(resourceShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - - OperationShape operationShape = result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); - assertFalse(operationShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(operationShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); - - StructureShape structureShape = result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); - assertFalse(structureShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(structureShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + ResourceShape resourceShape = + result.expectShape(ShapeId.from("smithy.example#ResourceWithMixin"), ResourceShape.class); + assertFalse(resourceShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(resourceShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); + + OperationShape operationShape = + result.expectShape(ShapeId.from("smithy.example#OperationWithMixin"), OperationShape.class); + assertFalse(operationShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(operationShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); + + StructureShape structureShape = + result.expectShape(ShapeId.from("smithy.example#StructureWithMixin"), StructureShape.class); + assertFalse(structureShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(structureShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); UnionShape unionShape = result.expectShape(ShapeId.from("smithy.example#UnionWithMixin"), UnionShape.class); - assertFalse(unionShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(unionShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse(unionShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(unionShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); MapShape mapShape = result.expectShape(ShapeId.from("smithy.example#MapWithMixin"), MapShape.class); - assertFalse(mapShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(mapShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse( + mapShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); + assertTrue(mapShape.findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); ListShape listShape = result.expectShape(ShapeId.from("smithy.example#ListWithMixin"), ListShape.class); - assertFalse(listShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(listShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse(listShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(listShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); StringShape stringShape = result.expectShape(ShapeId.from("smithy.example#StringWithMixin"), StringShape.class); - assertFalse(stringShape.findMemberTrait(result, "smithy.example#filteredTrait").isPresent()); - assertTrue(stringShape.findMemberTrait(result, "smithy.example#unfilteredTrait").isPresent()); + assertFalse(stringShape + .findMemberTrait(result, "smithy.example#filteredTrait") + .isPresent()); + assertTrue(stringShape + .findMemberTrait(result, "smithy.example#unfilteredTrait") + .isPresent()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java index 690b9b6b222..97a648bb198 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/ExcludeTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -40,20 +29,19 @@ public void removesTraitsInList() { .addTrait(new SensitiveTrait()) .addTrait(new DocumentationTrait("docs", SourceLocation.NONE)) .build(); - Model model = Model.assembler() - .addShape(stringShape) - .assemble() - .unwrap(); + Model model = Model.assembler().addShape(stringShape).assemble().unwrap(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("traits", Node.fromStrings("documentation"))) .build(); Model result = new ExcludeTraits().transform(context); - assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), - is(Optional.empty())); - assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), - not(Optional.empty())); - assertFalse(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")).isPresent()); + assertThat( + result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), + is(Optional.empty())); + assertThat( + result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), not(Optional.empty())); + assertFalse(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")) + .isPresent()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java index 1577ea57c4c..62c2f43d58c 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FilterSuppressionsTest.java @@ -1,3 +1,7 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -75,13 +79,12 @@ public void runTransformTests(String modelFile, String testName) throws Exceptio .assemble() .unwrap(); - SmithyBuild builder = new SmithyBuild() - .model(model) - .fileManifestFactory(MockManifest::new); + SmithyBuild builder = new SmithyBuild().model(model).fileManifestFactory(MockManifest::new); SmithyBuildConfig.Builder configBuilder = SmithyBuildConfig.builder(); - configBuilder.load(Paths.get( - getClass().getResource("filtersuppressions/" + modelFile + "." + testName + ".json").toURI())); + configBuilder.load(Paths.get(getClass() + .getResource("filtersuppressions/" + modelFile + "." + testName + ".json") + .toURI())); configBuilder.outputDirectory("/mocked/is/not/used"); builder.config(configBuilder.build()); @@ -89,9 +92,13 @@ public void runTransformTests(String modelFile, String testName) throws Exceptio assertTrue(results.getProjectionResult("foo").isPresent()); ProjectionResult projectionResult = results.getProjectionResult("foo").get(); - MockManifest manifest = (MockManifest) projectionResult.getPluginManifest("model").get(); + MockManifest manifest = + (MockManifest) projectionResult.getPluginManifest("model").get(); String modelText = manifest.getFileString("model.json").get(); - Model resultModel = Model.assembler().addUnparsedModel("/model.json", modelText).assemble().unwrap(); + Model resultModel = Model.assembler() + .addUnparsedModel("/model.json", modelText) + .assemble() + .unwrap(); Model expectedModel = Model.assembler() .addImport(getClass().getResource("filtersuppressions/" + modelFile + "." + testName + ".smithy")) .assemble() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java index 4f530e21092..1a3b0a5404a 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/FlattenNamespacesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -45,16 +34,15 @@ public class FlattenNamespacesTest { @Test public void flattenNamespacesOfShapesConnectedToSpecifiedService() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("flatten-namespaces.json").toURI())) + .addImport(Paths.get( + getClass().getResource("flatten-namespaces.json").toURI())) .assemble() .unwrap(); ObjectNode config = Node.objectNode() .withMember("namespace", Node.from("ns.qux")) .withMember("service", Node.from("ns.foo#MyService")); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Model result = new FlattenNamespaces().transform(context); List ids = result.shapes() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) @@ -62,26 +50,38 @@ public void flattenNamespacesOfShapesConnectedToSpecifiedService() throws Except .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#MyOperation", "ns.qux#MyOperationOutput", - "ns.qux#MyOperationOutput$foo", "ns.corge#UnconnectedFromService", "ns.grault#MyOperationOutput")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.bar#MyOperation", "ns.baz#MyOperationOutput", - "ns.baz#MyOperationOutput$foo", "ns.qux#UnconnectedFromService"))); + assertThat( + ids, + containsInAnyOrder( + "ns.qux#MyService", + "ns.qux#MyOperation", + "ns.qux#MyOperationOutput", + "ns.qux#MyOperationOutput$foo", + "ns.corge#UnconnectedFromService", + "ns.grault#MyOperationOutput")); + assertThat( + ids, + not(containsInAnyOrder( + "ns.foo#MyService", + "ns.bar#MyOperation", + "ns.baz#MyOperationOutput", + "ns.baz#MyOperationOutput$foo", + "ns.qux#UnconnectedFromService"))); } @Test public void includesAdditionalTaggedShapes() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("flatten-namespaces.json").toURI())) + .addImport(Paths.get( + getClass().getResource("flatten-namespaces.json").toURI())) .assemble() .unwrap(); ObjectNode config = Node.objectNode() .withMember("namespace", Node.from("ns.qux")) .withMember("service", Node.from("ns.foo#MyService")) .withMember("includeTagged", Node.arrayNode().withValue(Node.from("included"))); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Model result = new FlattenNamespaces().transform(context); List ids = result.shapes() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) @@ -89,26 +89,38 @@ public void includesAdditionalTaggedShapes() throws Exception { .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#MyOperation", "ns.qux#MyOperationOutput", - "ns.qux#MyOperationOutput$foo", "ns.qux#UnconnectedFromService", "ns.grault#MyOperationOutput")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.bar#MyOperation", "ns.baz#MyOperationOutput", - "ns.baz#MyOperationOutput$foo", "ns.corge#UnconnectedFromService"))); + assertThat( + ids, + containsInAnyOrder( + "ns.qux#MyService", + "ns.qux#MyOperation", + "ns.qux#MyOperationOutput", + "ns.qux#MyOperationOutput$foo", + "ns.qux#UnconnectedFromService", + "ns.grault#MyOperationOutput")); + assertThat( + ids, + not(containsInAnyOrder( + "ns.foo#MyService", + "ns.bar#MyOperation", + "ns.baz#MyOperationOutput", + "ns.baz#MyOperationOutput$foo", + "ns.corge#UnconnectedFromService"))); } @Test public void doesNotIncludeAdditionalTaggedShapesWhenTheyConflict() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("flatten-namespaces.json").toURI())) + .addImport(Paths.get( + getClass().getResource("flatten-namespaces.json").toURI())) .assemble() .unwrap(); ObjectNode config = Node.objectNode() .withMember("namespace", Node.from("ns.qux")) .withMember("service", Node.from("ns.foo#MyService")) .withMember("includeTagged", Node.arrayNode().withValue(Node.from("conflicting"))); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Model result = new FlattenNamespaces().transform(context); List ids = result.shapes() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) @@ -116,25 +128,38 @@ public void doesNotIncludeAdditionalTaggedShapesWhenTheyConflict() throws Except .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#MyOperation", "ns.qux#MyOperationOutput", - "ns.qux#MyOperationOutput$foo", "ns.corge#UnconnectedFromService", "ns.grault#MyOperationOutput")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.bar#MyOperation", "ns.baz#MyOperationOutput", - "ns.baz#MyOperationOutput$foo", "ns.qux#UnconnectedFromService"))); + assertThat( + ids, + containsInAnyOrder( + "ns.qux#MyService", + "ns.qux#MyOperation", + "ns.qux#MyOperationOutput", + "ns.qux#MyOperationOutput$foo", + "ns.corge#UnconnectedFromService", + "ns.grault#MyOperationOutput")); + assertThat( + ids, + not(containsInAnyOrder( + "ns.foo#MyService", + "ns.bar#MyOperation", + "ns.baz#MyOperationOutput", + "ns.baz#MyOperationOutput$foo", + "ns.qux#UnconnectedFromService"))); } @Test public void supportsRenamesOnService() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("flatten-namespaces-with-renames.json").toURI())) + .addImport(Paths.get(getClass() + .getResource("flatten-namespaces-with-renames.json") + .toURI())) .assemble() .unwrap(); ObjectNode config = Node.objectNode() .withMember("namespace", Node.from("ns.qux")) .withMember("service", Node.from("ns.foo#MyService")); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Model result = new FlattenNamespaces().transform(context); List ids = result.shapes() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) @@ -142,11 +167,24 @@ public void supportsRenamesOnService() throws Exception { .map(Object::toString) .collect(Collectors.toList()); - assertThat(ids, containsInAnyOrder("ns.qux#MyService", "ns.qux#GetSomething", "ns.qux#GetSomethingOutput", - "ns.qux#GetSomethingOutput$widget1", "ns.qux#GetSomethingOutput$fooWidget", "ns.qux#Widget", - "ns.qux#FooWidget")); - assertThat(ids, not(containsInAnyOrder("ns.foo#MyService", "ns.foo#GetSomething", "ns.foo#GetSomethingOutput", - "ns.bar#Widget", "foo.example#Widget"))); + assertThat( + ids, + containsInAnyOrder( + "ns.qux#MyService", + "ns.qux#GetSomething", + "ns.qux#GetSomethingOutput", + "ns.qux#GetSomethingOutput$widget1", + "ns.qux#GetSomethingOutput$fooWidget", + "ns.qux#Widget", + "ns.qux#FooWidget")); + assertThat( + ids, + not(containsInAnyOrder( + "ns.foo#MyService", + "ns.foo#GetSomething", + "ns.foo#GetSomethingOutput", + "ns.bar#Widget", + "foo.example#Widget"))); } @Test @@ -157,9 +195,7 @@ public void removesServiceRenames() { .unwrap(); TransformContext context = TransformContext.builder() .model(model) - .settings(Node.objectNode() - .withMember("namespace", "ns.qux") - .withMember("service", "ns.foo#MyService")) + .settings(Node.objectNode().withMember("namespace", "ns.qux").withMember("service", "ns.foo#MyService")) .build(); Model result = new FlattenNamespaces().transform(context); @@ -177,15 +213,12 @@ public void serviceShapeIsValidAfterTransform() { .unwrap(); TransformContext context = TransformContext.builder() .model(model) - .settings(Node.objectNode() - .withMember("namespace", "ns.qux") - .withMember("service", "ns.foo#MyService")) + .settings(Node.objectNode().withMember("namespace", "ns.qux").withMember("service", "ns.foo#MyService")) .build(); Model result = new FlattenNamespaces().transform(context); - ValidatedResult validatedResult = Model.assembler() - .addModel(result) - .assemble(); + ValidatedResult validatedResult = + Model.assembler().addModel(result).assemble(); List validationEventShapeIds = validatedResult.getValidationEvents().stream() .map(ValidationEvent::getShapeId) .filter(Optional::isPresent) @@ -230,26 +263,24 @@ public void throwsWhenServiceCannotBeFoundInModel() { ObjectNode config = Node.objectNode() .withMember("namespace", Node.from("ns.qux")) .withMember("service", Node.from("ns.foo#MyService")); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Assertions.assertThrows(SmithyBuildException.class, () -> new FlattenNamespaces().transform(context)); } @Test public void throwsWhenServiceIsInvalidInModel() { Model model = Model.assembler() - .addUnparsedModel("N/A", "{ \"smithy\": \"1.0\", \"shapes\": { \"ns.foo#InvalidService\": { \"type\": \"string\" } } }") + .addUnparsedModel( + "N/A", + "{ \"smithy\": \"1.0\", \"shapes\": { \"ns.foo#InvalidService\": { \"type\": \"string\" } } }") .assemble() .unwrap(); ObjectNode config = Node.objectNode() .withMember("namespace", Node.from("ns.qux")) .withMember("service", Node.from("ns.foo#InvalidService")); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Assertions.assertThrows(ExpectationNotMetException.class, () -> new FlattenNamespaces().transform(context)); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java index 7c05af36625..b5647afb261 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeMetadataTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -31,9 +20,7 @@ public void removesMetadataNotInList() { Map metadata = new HashMap<>(); metadata.put("a", Node.arrayNode()); metadata.put("b", Node.objectNode().withMember("foo", Node.objectNode())); - Model model = Model.builder() - .metadata(metadata) - .build(); + Model model = Model.builder().metadata(metadata).build(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("keys", Node.fromStrings("b"))) diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java index d0bd1c39011..c48d080c328 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeNamespacesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,7 +23,8 @@ public void removesShapesNotInNamespaces() { StringShape string2 = StringShape.builder().id("ns.foo#qux").build(); StringShape string3 = StringShape.builder().id("ns.bar#yuck").build(); StringShape string4 = StringShape.builder().id("ns.qux#yuck").build(); - Model model = Model.builder().addShapes(string1, string2, string3, string4).build(); + Model model = + Model.builder().addShapes(string1, string2, string3, string4).build(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("namespaces", Node.fromStrings("ns.foo", "ns.bar"))) diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java index 3325d42fd9c..12a1aa67ce3 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeServicesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,8 +20,10 @@ public class IncludeServicesTest { @Test public void removesTraitsNotInList() { - ServiceShape serviceA = ServiceShape.builder().id("ns.foo#baz").version("1").build(); - ServiceShape serviceB = ServiceShape.builder().id("ns.foo#bar").version("1").build(); + ServiceShape serviceA = + ServiceShape.builder().id("ns.foo#baz").version("1").build(); + ServiceShape serviceB = + ServiceShape.builder().id("ns.foo#bar").version("1").build(); StringShape string = StringShape.builder().id("ns.foo#yuck").build(); Model model = Model.builder().addShapes(serviceA, serviceB, string).build(); TransformContext context = TransformContext.builder() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java index d74af9be642..47c41cc72c3 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesBySelectorTest.java @@ -1,25 +1,16 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import org.junit.jupiter.api.Test; + import java.nio.file.Paths; import java.util.Set; import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; import software.amazon.smithy.build.TransformContext; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.node.Node; @@ -37,35 +28,37 @@ public void includesByServiceFoo() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -77,25 +70,27 @@ public void includesByServiceBar() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarService", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#GetBar"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarService", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#GetBar"))); } @Test @@ -107,60 +102,62 @@ public void includesNotByService() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooService", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#GetBar", - "smithy.example#GetFoo", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessages", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooService", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#GetBar", + "smithy.example#GetFoo", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessages", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } @Test @@ -172,13 +169,15 @@ public void includesOnlyEnumMembersWithTags() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$FOO", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$FOO"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$FOO", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$FOO"))); } @Test @@ -190,15 +189,17 @@ public void includesOnlyEnums() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO"))); } @Test @@ -210,63 +211,66 @@ public void includesStructsAndForwardRecursiveNeighbors() { .settings(Node.objectNode().withMember("selector", selector)) .build(); Model result = new IncludeShapesBySelector().transform(context); - assertThat(exampleIds(result), is(SetUtils.of( - "smithy.example#BarEnum", - "smithy.example#BarEnum$BAR", - "smithy.example#BarEnum$BAZ", - "smithy.example#BarEnum$FOO", - "smithy.example#BarInteger", - "smithy.example#BarStruct", - "smithy.example#BarStruct$intVal", - "smithy.example#BarStruct$stringVal", - "smithy.example#BarStruct$unionVal", - "smithy.example#BarStructInput", - "smithy.example#BarStructInput$intVal", - "smithy.example#BarStructInput$stringVal", - "smithy.example#BarStructOutput", - "smithy.example#BarStructOutput$intVal", - "smithy.example#BarStructOutput$stringVal", - "smithy.example#BarStructOutput$unionVal", - "smithy.example#BarUnion", - "smithy.example#BarUnion$fooEnum", - "smithy.example#BarUnion$fooInteger", - "smithy.example#BarUnion$fooString", - "smithy.example#FooEnum", - "smithy.example#FooEnum$BAR", - "smithy.example#FooEnum$BAZ", - "smithy.example#FooEnum$FOO", - "smithy.example#FooInteger", - "smithy.example#FooStruct", - "smithy.example#FooStruct$intVal", - "smithy.example#FooStruct$stringVal", - "smithy.example#FooStruct$unionVal", - "smithy.example#FooStructInput", - "smithy.example#FooStructInput$intVal", - "smithy.example#FooStructInput$stringVal", - "smithy.example#FooStructOutput", - "smithy.example#FooStructOutput$intVal", - "smithy.example#FooStructOutput$stringVal", - "smithy.example#FooStructOutput$unionVal", - "smithy.example#FooUnion", - "smithy.example#FooUnion$fooEnum", - "smithy.example#FooUnion$fooInteger", - "smithy.example#FooUnion$fooString", - "smithy.example#LeaveEvent", - "smithy.example#Message", - "smithy.example#Message$message", - "smithy.example#PublishEvents", - "smithy.example#PublishEvents$leave", - "smithy.example#PublishEvents$message", - "smithy.example#PublishMessagesInput", - "smithy.example#PublishMessagesInput$messages", - "smithy.example#PublishMessagesInput$room"))); + assertThat( + exampleIds(result), + is(SetUtils.of( + "smithy.example#BarEnum", + "smithy.example#BarEnum$BAR", + "smithy.example#BarEnum$BAZ", + "smithy.example#BarEnum$FOO", + "smithy.example#BarInteger", + "smithy.example#BarStruct", + "smithy.example#BarStruct$intVal", + "smithy.example#BarStruct$stringVal", + "smithy.example#BarStruct$unionVal", + "smithy.example#BarStructInput", + "smithy.example#BarStructInput$intVal", + "smithy.example#BarStructInput$stringVal", + "smithy.example#BarStructOutput", + "smithy.example#BarStructOutput$intVal", + "smithy.example#BarStructOutput$stringVal", + "smithy.example#BarStructOutput$unionVal", + "smithy.example#BarUnion", + "smithy.example#BarUnion$fooEnum", + "smithy.example#BarUnion$fooInteger", + "smithy.example#BarUnion$fooString", + "smithy.example#FooEnum", + "smithy.example#FooEnum$BAR", + "smithy.example#FooEnum$BAZ", + "smithy.example#FooEnum$FOO", + "smithy.example#FooInteger", + "smithy.example#FooStruct", + "smithy.example#FooStruct$intVal", + "smithy.example#FooStruct$stringVal", + "smithy.example#FooStruct$unionVal", + "smithy.example#FooStructInput", + "smithy.example#FooStructInput$intVal", + "smithy.example#FooStructInput$stringVal", + "smithy.example#FooStructOutput", + "smithy.example#FooStructOutput$intVal", + "smithy.example#FooStructOutput$stringVal", + "smithy.example#FooStructOutput$unionVal", + "smithy.example#FooUnion", + "smithy.example#FooUnion$fooEnum", + "smithy.example#FooUnion$fooInteger", + "smithy.example#FooUnion$fooString", + "smithy.example#LeaveEvent", + "smithy.example#Message", + "smithy.example#Message$message", + "smithy.example#PublishEvents", + "smithy.example#PublishEvents$leave", + "smithy.example#PublishEvents$message", + "smithy.example#PublishMessagesInput", + "smithy.example#PublishMessagesInput$messages", + "smithy.example#PublishMessagesInput$room"))); } - Model testModel() { try { return Model.assembler() - .addImport(Paths.get(getClass().getResource("transform-by-selector.smithy").toURI())) + .addImport(Paths.get(getClass() + .getResource("transform-by-selector.smithy") + .toURI())) .assemble() .unwrap(); } catch (Exception e) { @@ -275,11 +279,9 @@ Model testModel() { } static Set exampleIds(Model model) { - return model.getShapeIds() - .stream() + return model.getShapeIds().stream() .filter(id -> id.getNamespace().equals("smithy.example")) .map(ShapeId::toString) .collect(Collectors.toSet()); } - } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java index 39b4ad01f78..bfb384bf09a 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeShapesByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -39,9 +28,7 @@ public void removesTraitsNotInList() { .id("ns.foo#bar") .addTrait(TagsTrait.builder().addValue("qux").build()) .build(); - Model model = Model.builder() - .addShapes(stringA, stringB) - .build(); + Model model = Model.builder().addShapes(stringA, stringB).build(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("tags", Node.fromStrings("foo"))) diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java index ff4adb9d196..7e6e6e6268f 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTagsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java index b7db69e978a..1fbafab4e0a 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsByTagTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -33,7 +22,8 @@ public class IncludeTraitsByTagTest { @Test public void removesTraitsNoFoundWithTags() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("tree-shaking-traits.json").toURI())) + .addImport(Paths.get( + getClass().getResource("tree-shaking-traits.json").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java index 7216f680a68..4747aff5e71 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/IncludeTraitsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -41,23 +30,22 @@ public void removesTraitsNotInList() { .addTrait(new SensitiveTrait()) .addTrait(new DocumentationTrait("docs")) .build(); - Model model = Model.assembler() - .addShape(stringShape) - .assemble() - .unwrap(); + Model model = Model.assembler().addShape(stringShape).assemble().unwrap(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("traits", Node.fromStrings("documentation"))) .build(); Model result = new IncludeTraits().transform(context); - assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), - not(Optional.empty())); - assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), - is(Optional.empty())); + assertThat( + result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), + not(Optional.empty())); + assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), is(Optional.empty())); - assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")).isPresent()); - assertFalse(result.getTraitDefinition(ShapeId.from("smithy.api#sensitive")).isPresent()); + assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")) + .isPresent()); + assertFalse( + result.getTraitDefinition(ShapeId.from("smithy.api#sensitive")).isPresent()); } @Test @@ -67,21 +55,21 @@ public void includesBuiltinTraits() { .addTrait(new SensitiveTrait()) .addTrait(new DocumentationTrait("docs", SourceLocation.NONE)) .build(); - Model model = Model.assembler() - .addShape(stringShape) - .assemble() - .unwrap(); + Model model = Model.assembler().addShape(stringShape).assemble().unwrap(); TransformContext context = TransformContext.builder() .model(model) .settings(Node.objectNode().withMember("traits", Node.fromStrings("smithy.api#"))) .build(); Model result = new IncludeTraits().transform(context); - assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), - not(Optional.empty())); - assertThat(result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), - not(Optional.empty())); - assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")).isPresent()); - assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#sensitive")).isPresent()); + assertThat( + result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(DocumentationTrait.class), + not(Optional.empty())); + assertThat( + result.expectShape(ShapeId.from("ns.foo#baz")).getTrait(SensitiveTrait.class), not(Optional.empty())); + assertTrue(result.getTraitDefinition(ShapeId.from("smithy.api#documentation")) + .isPresent()); + assertTrue( + result.getTraitDefinition(ShapeId.from("smithy.api#sensitive")).isPresent()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java index 4e9fa5d9f32..70ec7e3e151 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveDeprecatedShapesTest.java @@ -2,7 +2,6 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -19,7 +18,8 @@ public class RemoveDeprecatedShapesTest { @Test public void removesAllDeprecatedShapes() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("remove-deprecated.smithy").toURI())) + .addImport(Paths.get( + getClass().getResource("remove-deprecated.smithy").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() @@ -31,15 +31,21 @@ public void removesAllDeprecatedShapes() throws Exception { Model result = new RemoveDeprecatedShapes().transform(context); // Deprecated by date removed - assertFalse(result.getShape(ShapeId.from("smithy.example#FilteredBeforeHyphens")).isPresent()); - assertFalse(result.getShape(ShapeId.from("smithy.example#FilteredVersionBefore")).isPresent()); + assertFalse(result.getShape(ShapeId.from("smithy.example#FilteredBeforeHyphens")) + .isPresent()); + assertFalse(result.getShape(ShapeId.from("smithy.example#FilteredVersionBefore")) + .isPresent()); // Equal to the filter retained - assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredDateEquals")).isPresent()); - assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredVersionEquals")).isPresent()); + assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredDateEquals")) + .isPresent()); + assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredVersionEquals")) + .isPresent()); // After filter retained - assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredDateAfter")).isPresent()); - assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredVersionAfter")).isPresent()); + assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredDateAfter")) + .isPresent()); + assertTrue(result.getShape(ShapeId.from("smithy.example#NotFilteredVersionAfter")) + .isPresent()); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java index 7d9cc3259a1..06baae22b73 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveTraitDefinitionsTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -31,7 +20,8 @@ public class RemoveTraitDefinitionsTest { @Test public void removesAllTraitDefinitions() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("remove-trait-definitions.json").toURI())) + .addImport(Paths.get( + getClass().getResource("remove-trait-definitions.json").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() @@ -51,7 +41,9 @@ public void removesAllTraitDefinitions() throws Exception { @Test public void retainsTaggedTraitDefinitions() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("retain-tagged-trait-definitions.json").toURI())) + .addImport(Paths.get(getClass() + .getResource("retain-tagged-trait-definitions.json") + .toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java index f7ac5139497..ce31287c0e4 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RemoveUnusedShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -57,7 +46,8 @@ public void treeShakerWithExports() throws Exception { @Test public void shouldRetainUsedTraitsAndShapesUsedBySaidTraits() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("tree-shaking-traits.json").toURI())) + .addImport(Paths.get( + getClass().getResource("tree-shaking-traits.json").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() @@ -69,13 +59,15 @@ public void shouldRetainUsedTraitsAndShapesUsedBySaidTraits() throws Exception { assertTrue(result.getTraitDefinition(ShapeId.from("ns.foo#bar")).isPresent()); assertTrue(result.getShape(ShapeId.from("ns.foo#bar")).isPresent()); assertTrue(result.getShape(ShapeId.from("ns.foo#BarTraitShapeMember")).isPresent()); - assertFalse(result.getTraitDefinition(ShapeId.from("ns.foo#QuuxTraitShapeMember")).isPresent()); + assertFalse(result.getTraitDefinition(ShapeId.from("ns.foo#QuuxTraitShapeMember")) + .isPresent()); } @Test public void shouldPruneUnusedTraitsAndShapesUsedBySaidTraits() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("tree-shaking-traits.json").toURI())) + .addImport(Paths.get( + getClass().getResource("tree-shaking-traits.json").toURI())) .assemble() .unwrap(); TransformContext context = TransformContext.builder() diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java index f0300483811..9e7b04a0298 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/transforms/RenameShapesTest.java @@ -1,18 +1,7 @@ /* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ - package software.amazon.smithy.build.transforms; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,18 +27,15 @@ public class RenameShapesTest { @Test public void renameShapes() throws Exception { Model model = Model.assembler() - .addImport(Paths.get(getClass().getResource("rename-shapes.json").toURI())) + .addImport( + Paths.get(getClass().getResource("rename-shapes.json").toURI())) .assemble() .unwrap(); - ObjectNode renamed = Node.objectNode() - .withMember("ns.foo#Bar", "ns.foo#Baz") - .withMember("ns.foo#Qux", "ns.foo#Corge"); - ObjectNode config = Node.objectNode() - .withMember("renamed", renamed); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + ObjectNode renamed = + Node.objectNode().withMember("ns.foo#Bar", "ns.foo#Baz").withMember("ns.foo#Qux", "ns.foo#Corge"); + ObjectNode config = Node.objectNode().withMember("renamed", renamed); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Model result = new RenameShapes().transform(context); List ids = result.shapes() .filter(FunctionalUtils.not(Prelude::isPreludeShape)) @@ -93,14 +79,10 @@ public void throwsWhenShapeToBeRenamedIsNotFound() { .addUnparsedModel("N/A", "{ \"smithy\": \"1.0\" }") .assemble() .unwrap(); - ObjectNode renamed = Node.objectNode() - .withMember("ns.foo#Bar", "ns.foo#Baz"); - ObjectNode config = Node.objectNode() - .withMember("renamed", renamed); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + ObjectNode renamed = Node.objectNode().withMember("ns.foo#Bar", "ns.foo#Baz"); + ObjectNode config = Node.objectNode().withMember("renamed", renamed); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Assertions.assertThrows(SmithyBuildException.class, () -> new RenameShapes().transform(context)); } @@ -110,14 +92,10 @@ public void throwsWhenFromShapeIsInvalid() { .addUnparsedModel("N/A", "{ \"smithy\": \"1.0\" }") .assemble() .unwrap(); - ObjectNode renamed = Node.objectNode() - .withMember("Bar", "ns.foo#Baz"); - ObjectNode config = Node.objectNode() - .withMember("renamed", renamed); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + ObjectNode renamed = Node.objectNode().withMember("Bar", "ns.foo#Baz"); + ObjectNode config = Node.objectNode().withMember("renamed", renamed); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Assertions.assertThrows(SmithyBuildException.class, () -> new RenameShapes().transform(context)); } @@ -127,14 +105,10 @@ public void throwsWhenToShapeIsInvalid() { .addUnparsedModel("N/A", "{ \"smithy\": \"1.0\" }") .assemble() .unwrap(); - ObjectNode renamed = Node.objectNode() - .withMember("ns.foo#Bar", "Baz"); - ObjectNode config = Node.objectNode() - .withMember("renamed", renamed); - TransformContext context = TransformContext.builder() - .model(model) - .settings(config) - .build(); + ObjectNode renamed = Node.objectNode().withMember("ns.foo#Bar", "Baz"); + ObjectNode config = Node.objectNode().withMember("renamed", renamed); + TransformContext context = + TransformContext.builder().model(model).settings(config).build(); Assertions.assertThrows(SmithyBuildException.class, () -> new RenameShapes().transform(context)); } }