Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Checkstyle to work on Windows #576

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
<property name="fileExtensions" value="java"/>
</module>

<module name="NewlineAtEndOfFile"/>
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf_cr_crlf"/>
</module>

<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void performsSubstitutionsByDefault() {
.unwrap();

ObjectNode expected = Node.parse(
IoUtils.readUtf8File(getClass().getResource("substitution-performed.json").getPath()))
IoUtils.readUtf8Resource(getClass(), "substitution-performed.json"))
.expectObjectNode();
OpenApiConfig config = new OpenApiConfig();
config.setService(ShapeId.from("example.smithy#MyService"));
Expand All @@ -55,7 +55,7 @@ public void pluginCanBeDisabled() {
.unwrap();

ObjectNode expected = Node.parse(
IoUtils.readUtf8File(getClass().getResource("substitution-not-performed.json").getPath()))
IoUtils.readUtf8Resource(getClass(), "substitution-not-performed.json"))
.expectObjectNode();

OpenApiConfig config = new OpenApiConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import software.amazon.smithy.build.FileManifest;
import software.amazon.smithy.build.PluginContext;
import software.amazon.smithy.build.SmithyBuildPlugin;
Expand Down Expand Up @@ -91,7 +92,9 @@ public void execute(PluginContext context) {
LOGGER.info(String.format("Skipping `%s` manifest because no Smithy sources found", projectionName));
} else {
LOGGER.fine(() -> String.format("Writing `%s` manifest", projectionName));
context.getFileManifest().writeFile("manifest", String.join("\n", names) + "\n");
// Normalize filenames to Unix style.
String manifest = names.stream().map(name -> name.replace("\\", "/")).collect(Collectors.joining("\n"));
context.getFileManifest().writeFile("manifest", manifest + "\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;

import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
Expand Down Expand Up @@ -149,6 +150,10 @@ public void rewritesArgsArrayToUnderscoreArgs() {
}

private String getResourcePath(String name) {
return SmithyBuildTest.class.getResource(name).getPath();
try {
return Paths.get(SmithyBuildTest.class.getResource(name).toURI()).toString();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConfigurableSmithyBuildPluginTest {
@Test
public void loadsConfigurationClass() {
Model model = Model.assembler()
.addImport(getClass().getResource("sources/a.smithy").getPath())
.addImport(getClass().getResource("sources/a.smithy"))
.assemble()
.unwrap();
MockManifest manifest = new MockManifest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;

import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -18,10 +19,10 @@

public class SourcesPluginTest {
@Test
public void copiesFilesForSourceProjection() {
public void copiesFilesForSourceProjection() throws URISyntaxException {
Model model = Model.assembler()
.addImport(getClass().getResource("sources/a.smithy").getPath())
.addImport(getClass().getResource("sources/b.smithy").getPath())
.addImport(getClass().getResource("sources/a.smithy"))
.addImport(getClass().getResource("sources/b.smithy"))
.addImport(getClass().getResource("sources/c/c.json"))
.addImport(getClass().getResource("notsources/d.smithy"))
.assemble()
Expand All @@ -31,10 +32,12 @@ public void copiesFilesForSourceProjection() {
.fileManifest(manifest)
.model(model)
.originalModel(model)
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").getPath()).getParent()))
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").toURI()).getParent()))
.build();
new SourcesPlugin().execute(context);
String manifestString = manifest.getFileString("manifest").get();
// Normalize for Windows.
manifestString = manifestString.replace("\\", "/");

assertThat(manifestString, containsString("a.smithy\n"));
assertThat(manifestString, containsString("b.smithy\n"));
Expand All @@ -46,9 +49,9 @@ public void copiesFilesForSourceProjection() {
}

@Test
public void copiesModelFromJarWithSourceProjection() {
public void copiesModelFromJarWithSourceProjection() throws URISyntaxException {
Model model = Model.assembler()
.addImport(getClass().getResource("sources/jar-import.jar").getPath())
.addImport(getClass().getResource("sources/jar-import.jar"))
.addImport(getClass().getResource("notsources/d.smithy"))
.assemble()
.unwrap();
Expand All @@ -57,10 +60,12 @@ public void copiesModelFromJarWithSourceProjection() {
.fileManifest(manifest)
.model(model)
.originalModel(model)
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/jar-import.jar").getPath())))
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/jar-import.jar").toURI())))
.build();
new SourcesPlugin().execute(context);
String manifestString = manifest.getFileString("manifest").get();
// Normalize for Windows.
manifestString = manifestString.replace("\\", "/");

assertThat(manifestString, containsString("jar-import/a.smithy\n"));
assertThat(manifestString, containsString("jar-import/b/b.smithy\n"));
Expand All @@ -72,9 +77,9 @@ public void copiesModelFromJarWithSourceProjection() {
}

@Test
public void copiesModelFromJarWithNonSourceProjection() {
public void copiesModelFromJarWithNonSourceProjection() throws URISyntaxException {
Model model = Model.assembler()
.addImport(getClass().getResource("sources/jar-import.jar").getPath())
.addImport(getClass().getResource("sources/jar-import.jar"))
.addImport(getClass().getResource("notsources/d.smithy"))
.assemble()
.unwrap();
Expand All @@ -85,10 +90,12 @@ public void copiesModelFromJarWithNonSourceProjection() {
.projection("foo", projection)
.model(model)
.originalModel(model)
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/jar-import.jar").getPath())))
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/jar-import.jar").toURI())))
.build();
new SourcesPlugin().execute(context);
String manifestString = manifest.getFileString("manifest").get();
// Normalize for Windows.
manifestString = manifestString.replace("\\", "/");

assertThat(manifestString, containsString("model.json"));
assertThat(manifestString, not(containsString("jar-import")));
Expand All @@ -98,11 +105,11 @@ public void copiesModelFromJarWithNonSourceProjection() {
}

@Test
public void copiesOnlyFilesFromSourcesForProjection() {
public void copiesOnlyFilesFromSourcesForProjection() throws URISyntaxException {
Model model = Model.assembler()
.addImport(getClass().getResource("sources/a.smithy").getPath())
.addImport(getClass().getResource("sources/b.smithy").getPath())
.addImport(getClass().getResource("sources/c/c.json").getPath())
.addImport(getClass().getResource("sources/a.smithy"))
.addImport(getClass().getResource("sources/b.smithy"))
.addImport(getClass().getResource("sources/c/c.json"))
.addImport(getClass().getResource("notsources/d.smithy"))
.assemble()
.unwrap();
Expand All @@ -113,7 +120,7 @@ public void copiesOnlyFilesFromSourcesForProjection() {
.fileManifest(manifest)
.model(model)
.originalModel(model)
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").getPath()).getParent()))
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").toURI()).getParent()))
.build();
new SourcesPlugin().execute(context);
String manifestString = manifest.getFileString("manifest").get();
Expand All @@ -135,7 +142,7 @@ public void copiesOnlyFilesFromSourcesForProjection() {
}

@Test
public void treatsNewlyAddedShapesAsNewSources() {
public void treatsNewlyAddedShapesAsNewSources() throws URISyntaxException {
Model originalModel = Model.assembler().assemble().unwrap();
Model newModel = Model.assembler()
.addShape(StringShape.builder().id("a.b#MyString").build())
Expand All @@ -148,7 +155,7 @@ public void treatsNewlyAddedShapesAsNewSources() {
.fileManifest(manifest)
.originalModel(originalModel)
.model(newModel)
.sources(ListUtils.of(Paths.get(getClass().getResource("sources/a.smithy").getPath()).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();
Expand All @@ -157,10 +164,10 @@ public void treatsNewlyAddedShapesAsNewSources() {
}

@Test
public void doesNotAllowConflicts() {
public void doesNotAllowConflicts() throws URISyntaxException {
Model model = Model.assembler()
.addImport(getClass().getResource("sources/a.smithy").getPath())
.addImport(getClass().getResource("conflicting/a.smithy").getPath())
.addImport(getClass().getResource("sources/a.smithy"))
.addImport(getClass().getResource("conflicting/a.smithy"))
.assemble()
.unwrap();
MockManifest manifest = new MockManifest();
Expand All @@ -169,8 +176,8 @@ public void doesNotAllowConflicts() {
.model(model)
.originalModel(model)
.sources(ListUtils.of(
Paths.get(getClass().getResource("sources/a.smithy").getPath()),
Paths.get(getClass().getResource("conflicting/a.smithy").getPath())))
Paths.get(getClass().getResource("sources/a.smithy").toURI()),
Paths.get(getClass().getResource("conflicting/a.smithy").toURI())))
.build();

Assertions.assertThrows(SourcesConflictException.class, () -> new SourcesPlugin().execute(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -38,8 +40,8 @@ public void skipsMissingConfigFiles() {
}

@Test
public void addsConfigFilesWhenFound() {
String configFile = getClass().getResource("smithy-build-a.json").getPath();
public void addsConfigFilesWhenFound() throws URISyntaxException {
String configFile = Paths.get(getClass().getResource("smithy-build-a.json").toURI()).toString();
BuildParameterBuilder.Result result = new BuildParameterBuilder()
.addConfigIfExists(configFile)
.build();
Expand Down Expand Up @@ -213,10 +215,10 @@ public void projectionBuildTaggedSourcesRemovedFromModelDiscovery() {
}

@Test
public void findsProjectionJarsWithSourceTags() {
String a = getClass().getResource("jars/a/a.jar").getPath();
String b = getClass().getResource("jars/b/b.jar").getPath();
String c = getClass().getResource("jars/c/c.jar").getPath();
public void findsProjectionJarsWithSourceTags() throws URISyntaxException {
String a = Paths.get(getClass().getResource("jars/a/a.jar").toURI()).toString();
String b = Paths.get(getClass().getResource("jars/b/b.jar").toURI()).toString();
String c = Paths.get(getClass().getResource("jars/c/c.jar").toURI()).toString();
String separator = System.getProperty("path.separator");
String buildCp = a + separator + b + separator + c;

Expand All @@ -237,14 +239,14 @@ public void findsProjectionJarsWithSourceTags() {
}

@Test
public void usesCustomSeparator() {
public void usesCustomSeparator() throws URISyntaxException {
String currentSeparator = System.getProperty("path.separator");

try {
System.setProperty("path.separator", "|");
String a = getClass().getResource("jars/a/a.jar").getPath();
String b = getClass().getResource("jars/b/b.jar").getPath();
String c = getClass().getResource("jars/c/c.jar").getPath();
String a = Paths.get(getClass().getResource("jars/a/a.jar").toURI()).toString();
String b = Paths.get(getClass().getResource("jars/b/b.jar").toURI()).toString();
String c = Paths.get(getClass().getResource("jars/c/c.jar").toURI()).toString();
String buildCp = a + "|" + b + "|" + c;

BuildParameterBuilder.Result result = new BuildParameterBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.cli.CliError;
Expand All @@ -31,7 +33,7 @@ public void usesModelDiscoveryWithCustomValidClasspath() throws Exception {
PrintStream printStream = new PrintStream(outputStream);
System.setOut(printStream);

String dir = getClass().getResource("valid.jar").getPath();
String dir = Paths.get(getClass().getResource("valid.jar").toURI()).toString();
SmithyCli.create().run("ast", "--debug", "--discover-classpath", dir);
System.setOut(out);

Expand All @@ -42,7 +44,7 @@ public void usesModelDiscoveryWithCustomValidClasspath() throws Exception {
@Test
public void usesModelDiscoveryWithCustomInvalidClasspath() {
CliError e = Assertions.assertThrows(CliError.class, () -> {
String dir = getClass().getResource("invalid.jar").getPath();
String dir = Paths.get(getClass().getResource("invalid.jar").toURI()).toString();
SmithyCli.create().run("ast", "--debug", "--discover-classpath", dir);
});

Expand All @@ -60,8 +62,8 @@ public void failsOnUnknownTrait() {
}

@Test
public void allowsUnknownTrait() {
String model = getClass().getResource("unknown-trait.smithy").getPath();
public void allowsUnknownTrait() throws URISyntaxException {
String model = Paths.get(getClass().getResource("unknown-trait.smithy").toURI()).toString();
SmithyCli.create().run("ast", "--allow-unknown-traits", model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.cli.CliError;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void dumpsOutValidationErrorsAndFails() throws Exception {
System.setOut(printStream);

CliError e = Assertions.assertThrows(CliError.class, () -> {
String model = getClass().getResource("unknown-trait.smithy").getPath();
String model = Paths.get(getClass().getResource("unknown-trait.smithy").toURI()).toString();
SmithyCli.create().run("build", model);
});

Expand All @@ -61,7 +62,7 @@ public void dumpsOutValidationErrorsAndFails() throws Exception {

@Test
public void printsSuccessfulProjections() throws Exception {
String model = getClass().getResource("valid-model.smithy").getPath();
String model = Paths.get(getClass().getResource("valid-model.smithy").toURI()).toString();

PrintStream out = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand All @@ -83,8 +84,8 @@ public void validationFailuresCausedByProjectionsAreDetected() throws Exception
System.setOut(printStream);

CliError e = Assertions.assertThrows(CliError.class, () -> {
String model = getClass().getResource("valid-model.smithy").getPath();
String config = getClass().getResource("projection-build-failure.json").getPath();
String model = Paths.get(getClass().getResource("valid-model.smithy").toURI()).toString();
String config = Paths.get(getClass().getResource("projection-build-failure.json").toURI()).toString();
SmithyCli.create().run("build", "--debug", "--config", config, model);
});

Expand Down
Loading