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

Remove redundant parsing method in bootstrap plugin #20338

Merged
merged 1 commit into from
Sep 23, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ public void execute() throws MojoExecutionException {
ObjectMapper mapper = null;
if (extensionFile.exists()) {
mapper = getMapper(extensionFile.toString().endsWith(".yaml"));
extObject = readJsonNode(extensionFile.toPath(), mapper);
extObject = readExtensionDescriptorFile(extensionFile.toPath(), mapper);
} else {
mapper = getMapper(true);
extObject = getMapper(true).createObjectNode();
}

transformLegacyToNew(output, extObject, mapper);
transformLegacyToNew(extObject, mapper);

ensureArtifactCoords(extObject);

Expand Down Expand Up @@ -418,11 +418,11 @@ private static String getRealValueOrNull(String s, String propertyExpr) {
return s != null && !s.isBlank() && !s.equals(propertyExpr) ? s : null;
}

private ObjectNode readJsonNode(Path extensionFile, ObjectMapper mapper) throws MojoExecutionException {
try {
return readExtensionYaml(extensionFile, mapper);
} catch (IOException e) {
throw new MojoExecutionException("Failed to parse " + extensionFile, e);
private ObjectNode readExtensionDescriptorFile(Path extensionFile, ObjectMapper mapper) throws MojoExecutionException {
try (InputStream is = Files.newInputStream(extensionFile)) {
return mapper.readValue(is, ObjectNode.class);
} catch (IOException io) {
throw new MojoExecutionException("Failed to parse " + extensionFile, io);
}
}

Expand Down Expand Up @@ -942,8 +942,7 @@ private boolean isJarFile(final File f) {
return f != null && f.getName().endsWith(".jar") && f.exists() && !f.isDirectory();
}

private void transformLegacyToNew(final Path output, ObjectNode extObject, ObjectMapper mapper)
throws MojoExecutionException {
private void transformLegacyToNew(ObjectNode extObject, ObjectMapper mapper) {
ObjectNode metadata = null;

// Note: groupId and artifactId shouldn't normally be in the source json but
Expand Down Expand Up @@ -985,18 +984,6 @@ private void transformLegacyToNew(final Path output, ObjectNode extObject, Objec

}

/**
* parse yaml or json and then return jackson JSonNode for furhter processing
***/
private ObjectNode readExtensionYaml(Path descriptor, ObjectMapper mapper)
throws IOException {
try (InputStream is = Files.newInputStream(descriptor)) {
return mapper.readValue(is, ObjectNode.class);
} catch (IOException io) {
throw new IOException("Failed to parse " + descriptor, io);
}
}

private ObjectMapper getMapper(boolean yaml) {

if (yaml) {
Expand Down