Skip to content

Commit

Permalink
Merge pull request #4935 from maxandersen/yaml_descriptor
Browse files Browse the repository at this point in the history
Move from quarkus-extension.json to .yaml
  • Loading branch information
maxandersen authored Oct 28, 2019
2 parents 09ffe85 + 6257c4b commit 0bd8185
Show file tree
Hide file tree
Showing 162 changed files with 940 additions and 1,094 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class JarResultBuildStep {
"META-INF/quarkus-javadoc.properties",
"META-INF/quarkus-extension.properties",
"META-INF/quarkus-extension.json",
"META-INF/quarkus-extension.yaml",
"META-INF/quarkus-deployment-dependency.graph",
"META-INF/jandex.idx",
"LICENSE")));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
name: "Quarkus - Core"
metadata: {}
7 changes: 6 additions & 1 deletion devtools/platform-descriptor-json-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>


<dependency>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logging</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -44,6 +45,13 @@
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.util.ZipUtils;
import io.quarkus.dependencies.Extension;
Expand Down Expand Up @@ -208,6 +216,19 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

private JsonObject processDependency(Artifact artifact) throws IOException {
JsonNode onode = processDependencyToObjectNode(artifact);

if (onode != null) {
// TODO: this is a dirty hack to avoid redoing existing javax.json code
String json = getMapper(false).writeValueAsString(onode);
JsonReader jsonReader = Json.createReader(new StringReader(json));
return jsonReader.readObject();
} else {
return null;
}
}

private JsonNode processDependencyToObjectNode(Artifact artifact) throws IOException {
final Path path = artifact.getFile().toPath();
if (Files.isDirectory(path)) {
return processMetaInfDir(artifact, path.resolve(BootstrapConstants.META_INF));
Expand All @@ -218,37 +239,70 @@ private JsonObject processDependency(Artifact artifact) throws IOException {
}
}

private JsonObject processMetaInfDir(Artifact artifact, Path metaInfDir)
/**
* Load and return javax.jsonObject based on yaml, json or properties file.
*
* @param artifact
* @param metaInfDir
* @return
* @throws IOException
*/
private JsonNode processMetaInfDir(Artifact artifact, Path metaInfDir)
throws IOException {

ObjectMapper mapper = null;

if (!Files.exists(metaInfDir)) {
return null;
}
final Path p = metaInfDir.resolve(BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME);
if (!Files.exists(p)) {
final Path props = metaInfDir.resolve(BootstrapConstants.DESCRIPTOR_FILE_NAME);
if (Files.exists(props)) {
return Json.createObjectBuilder()
.add(Extension.ARTIFACT_ID, artifact.getArtifactId())
.add(Extension.GROUP_ID, artifact.getGroupId())
.add("version", artifact.getVersion())
.add("name", artifact.getArtifactId())
.build();
Path jsonOrYaml = null;

Path yaml = metaInfDir.resolve(BootstrapConstants.QUARKUS_EXTENSION_FILE_NAME);
if (Files.exists(yaml)) {
mapper = getMapper(true);
jsonOrYaml = yaml;
} else {
Path json = metaInfDir.resolve(BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME);
if (!Files.exists(json)) {
final Path props = metaInfDir.resolve(BootstrapConstants.DESCRIPTOR_FILE_NAME);
if (Files.exists(props)) {
return mapper.createObjectNode()
.put(Extension.ARTIFACT_ID, artifact.getArtifactId())
.put(Extension.GROUP_ID, artifact.getGroupId())
.put("version", artifact.getVersion())
.put("name", artifact.getArtifactId());
} else {
return null;
}
} else {
jsonOrYaml = json;
mapper = getMapper(false);
}
return null;
}
return processPlatformArtifact(artifact, p);
return processPlatformArtifact(artifact, jsonOrYaml, mapper);
}

private JsonObject processPlatformArtifact(Artifact artifact, Path descriptor)
private JsonNode processPlatformArtifact(Artifact artifact, Path descriptor, ObjectMapper mapper)
throws IOException {
try (InputStream is = Files.newInputStream(descriptor)) {
try (JsonReader reader = Json.createReader(is)) {
final JsonObject object = reader.readObject();
debug("Adding Quarkus extension %s:%s", object.get(Extension.GROUP_ID), object.get(Extension.ARTIFACT_ID));
return object;
}
} catch (IOException e) {
throw new IOException("Failed to parse " + descriptor, e);
JsonNode object = mapper.readTree(is);
debug("Adding Quarkus extension %s:%s", object.get(Extension.GROUP_ID), object.get(Extension.ARTIFACT_ID));
return object;
} catch (IOException io) {
throw new IOException("Failed to parse " + descriptor, io);
}
}

private ObjectMapper getMapper(boolean yaml) {

if (yaml) {
YAMLFactory yf = new YAMLFactory();
return new ObjectMapper(yf)
.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
} else {
return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)
.enable(JsonParser.Feature.ALLOW_COMMENTS).enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS)
.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,35 @@ private void analyzeArtifact(Artifact artifact, Map<String, Artifact> extensions
if (!file.exists()) {
throw new MojoExecutionException("Failed to locate " + artifact + " at " + file);
}

if (!doesDescriptorExistAndCanBeRead(artifact, extensions, file, BootstrapConstants.QUARKUS_EXTENSION_FILE_NAME) &&
!doesDescriptorExistAndCanBeRead(artifact, extensions, file,
BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME)) {

throw new MojoExecutionException("Failed to locate and read neither "
+ BootstrapConstants.QUARKUS_EXTENSION_FILE_NAME
+ " or " + BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME
+ " for '" + artifact + "' in " + file);
}
}

private boolean doesDescriptorExistAndCanBeRead(Artifact artifact, Map<String, Artifact> extensions, final File file,
String descriptorName)
throws MojoExecutionException {
if (file.isDirectory()) {
processExtensionDescriptor(artifact, file.toPath().resolve(BootstrapConstants.META_INF)
.resolve(BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME), extensions);
.resolve(descriptorName), extensions);
} else {
try (FileSystem fs = FileSystems.newFileSystem(file.toPath(), null)) {
processExtensionDescriptor(artifact,
fs.getPath("/", BootstrapConstants.META_INF, BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME),
fs.getPath("/", BootstrapConstants.META_INF, descriptorName),
extensions);
} catch (IOException e) {
throw new MojoExecutionException("Failed to read " + file, e);
getLog().debug("Failed to read " + file, e);
return false;
}
}
return true;
}

private void processExtensionDescriptor(Artifact artifact, Path p, Map<String, Artifact> extensions) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: "Agroal - Database connection pool"
metadata:
keywords:
- "agroal"
- "database-connection-pool"
categories:
- "data"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: "Amazon DynamoDB client"
metadata:
keywords:
- "dynamodb"
- "dynamo"
- "aws"
- "amazon"
categories:
- "data"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: "AWS Lambda"
metadata:
keywords:
- "lambda"
- "aws"
- "amazon"
categories:
- "cloud"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: "ArC"
short-name: "CDI"
metadata:
keywords:
- "arc"
- "cdi"
- "dependency-injection"
- "di"
guide: "https://quarkus.io/guides/cdi-reference"
categories:
- "core"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: "Artemis Core"
metadata:
keywords:
- "artemis-core"
- "artemis"
categories:
- "messaging"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: "Artemis JMS"
metadata:
keywords:
- "artemis-jms"
- "artemis"
categories:
- "messaging"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: "Elytron Security JDBC Realm"
metadata:
keywords:
- "security"
- "jdbc"
guide: "https://quarkus.io/guides/security-jdbc-guide"
categories:
- "security"

This file was deleted.

Loading

0 comments on commit 0bd8185

Please sign in to comment.