Merge pull request #5381 from eelhazati/master
BAEL-1999 : Maven polyglot
This commit is contained in:
commit
2609d8b16d
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>com.baeldung.maven.polyglot</groupId>
|
||||
<artifactId>maven-polyglot-json-extension</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</extension>
|
||||
</extensions>
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"modelVersion": "4.0.0",
|
||||
"groupId": "com.baeldung.maven.polyglot",
|
||||
"artifactId": "maven-polyglot-json-app",
|
||||
"version": "1.0-SNAPSHOT",
|
||||
"name": "Json Maven Polyglot",
|
||||
"parent": {
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-starter-parent",
|
||||
"version": "2.0.5.RELEASE",
|
||||
"relativePath": null
|
||||
},
|
||||
"properties": {
|
||||
"project.build.sourceEncoding": "UTF-8",
|
||||
"project.reporting.outputEncoding": "UTF-8",
|
||||
"maven.compiler.source": "1.8",
|
||||
"maven.compiler.target": "1.8",
|
||||
"java.version": "1.8"
|
||||
},
|
||||
"dependencies": [
|
||||
{
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-starter-web"
|
||||
}
|
||||
],
|
||||
"build": {
|
||||
"plugins": [
|
||||
{
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-maven-plugin"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.maven.polyglot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@RestController
|
||||
@SpringBootApplication
|
||||
public class MavenPolyglotApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MavenPolyglotApplication.class, args);
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public String home(){
|
||||
return "Hello JSON Maven Model !";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
{
|
||||
"modules": [],
|
||||
"distributionManagement": null,
|
||||
"properties": {
|
||||
"project.reporting.outputEncoding": "UTF-8",
|
||||
"java.version": "1.8",
|
||||
"maven.compiler.source": "1.8",
|
||||
"project.build.sourceEncoding": "UTF-8",
|
||||
"maven.compiler.target": "1.8"
|
||||
},
|
||||
"dependencyManagement": null,
|
||||
"dependencies": [
|
||||
{
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-starter-web",
|
||||
"version": null,
|
||||
"type": "jar",
|
||||
"classifier": null,
|
||||
"scope": null,
|
||||
"systemPath": null,
|
||||
"exclusions": [],
|
||||
"optional": null,
|
||||
"managementKey": "org.springframework.boot:spring-boot-starter-web:jar"
|
||||
}
|
||||
],
|
||||
"repositories": [],
|
||||
"pluginRepositories": [],
|
||||
"reports": null,
|
||||
"reporting": null,
|
||||
"modelVersion": "4.0.0",
|
||||
"parent": {
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-starter-parent",
|
||||
"version": "2.0.5.RELEASE",
|
||||
"relativePath": "",
|
||||
"id": "org.springframework.boot:spring-boot-starter-parent:pom:2.0.5.RELEASE"
|
||||
},
|
||||
"groupId": "com.demo.polyglot",
|
||||
"artifactId": "maven-polyglot-app",
|
||||
"version": "1.0.1",
|
||||
"packaging": "jar",
|
||||
"name": "Json Maven Polyglot",
|
||||
"description": null,
|
||||
"url": null,
|
||||
"inceptionYear": null,
|
||||
"organization": null,
|
||||
"licenses": [],
|
||||
"developers": [],
|
||||
"contributors": [],
|
||||
"mailingLists": [],
|
||||
"prerequisites": null,
|
||||
"scm": null,
|
||||
"issueManagement": null,
|
||||
"ciManagement": null,
|
||||
"build": {
|
||||
"plugins": [
|
||||
{
|
||||
"inherited": null,
|
||||
"configuration": null,
|
||||
"inheritanceApplied": true,
|
||||
"groupId": "org.liquibase",
|
||||
"artifactId": "liquibase-maven-plugin",
|
||||
"version": "3.0.5",
|
||||
"extensions": null,
|
||||
"executions": [],
|
||||
"dependencies": [],
|
||||
"goals": null,
|
||||
"key": "org.liquibase:liquibase-maven-plugin",
|
||||
"id": "org.liquibase:liquibase-maven-plugin:3.0.5",
|
||||
"executionsAsMap": {}
|
||||
}
|
||||
],
|
||||
"pluginManagement": null,
|
||||
"defaultGoal": null,
|
||||
"resources": [],
|
||||
"testResources": [],
|
||||
"directory": null,
|
||||
"finalName": null,
|
||||
"filters": [],
|
||||
"sourceDirectory": null,
|
||||
"scriptSourceDirectory": null,
|
||||
"testSourceDirectory": null,
|
||||
"outputDirectory": null,
|
||||
"testOutputDirectory": null,
|
||||
"extensions": [],
|
||||
"pluginsAsMap": {
|
||||
"org.liquibase:liquibase-maven-plugin": {
|
||||
"inherited": null,
|
||||
"configuration": null,
|
||||
"inheritanceApplied": true,
|
||||
"groupId": "org.liquibase",
|
||||
"artifactId": "liquibase-maven-plugin",
|
||||
"version": "3.0.5",
|
||||
"extensions": null,
|
||||
"executions": [],
|
||||
"dependencies": [],
|
||||
"goals": null,
|
||||
"key": "org.liquibase:liquibase-maven-plugin",
|
||||
"id": "org.liquibase:liquibase-maven-plugin:3.0.5",
|
||||
"executionsAsMap": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"profiles": [],
|
||||
"modelEncoding": "UTF-8",
|
||||
"pomFile": null,
|
||||
"id": "com.demo.polyglot:maven-polyglot-app:jar:1.0.1",
|
||||
"projectDirectory": null
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung.maven.polyglot</groupId>
|
||||
<artifactId>maven-polyglot-json-extension</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-component-metadata</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate-metadata</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,62 @@
|
|||
package com.demo.polyglot;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.building.FileModelSource;
|
||||
import org.apache.maven.model.building.ModelProcessor;
|
||||
import org.apache.maven.model.io.ModelParseException;
|
||||
import org.apache.maven.model.io.ModelReader;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
|
||||
@Component(role = ModelProcessor.class)
|
||||
public class CustomModelProcessor implements ModelProcessor {
|
||||
|
||||
private static final String XML_POM = "pom.xml";
|
||||
private static final String JSON_POM = "pom.json";
|
||||
private static final String JSON_EXT = ".json";
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Requirement
|
||||
private ModelReader modelReader;
|
||||
|
||||
@Override
|
||||
public File locatePom(File projectDirectory) {
|
||||
File pomFile = new File(projectDirectory, JSON_POM);
|
||||
if (!pomFile.exists()) {
|
||||
pomFile = new File(projectDirectory, XML_POM);
|
||||
}
|
||||
return pomFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model read(InputStream input, Map<String, ?> options) throws IOException, ModelParseException {
|
||||
try (final Reader in = ReaderFactory.newPlatformReader(input)) {
|
||||
return read(in, options);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model read(Reader reader, Map<String, ?> options) throws IOException, ModelParseException {
|
||||
FileModelSource source = (options != null) ? (FileModelSource) options.get(SOURCE) : null;
|
||||
if (source != null && source.getLocation().endsWith(JSON_EXT)) {
|
||||
Model model = objectMapper.readValue(reader, Model.class);
|
||||
return model;
|
||||
}
|
||||
//It's a normal maven project with a pom.xml file
|
||||
return modelReader.read(reader, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model read(File input, Map<String, ?> options) throws IOException, ModelParseException {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>io.takari.polyglot</groupId>
|
||||
<artifactId>polyglot-yaml</artifactId>
|
||||
<version>0.3.1</version>
|
||||
</extension>
|
||||
</extensions>
|
|
@ -0,0 +1,7 @@
|
|||
modelVersion: 4.0.0
|
||||
groupId: com.baeldung.maven.polyglot
|
||||
artifactId: maven-polyglot-yml-app
|
||||
version: 1.0-SNAPSHOT
|
||||
name: 'YAML Demo'
|
||||
|
||||
properties: {maven.compiler.source: 1.8, maven.compiler.target: 1.8}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.maven.polyglot;
|
||||
|
||||
public class YamlDemoApplication {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello Maven Polyglot YAML !");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
{
|
||||
"modules": [],
|
||||
"distributionManagement": null,
|
||||
"properties": {
|
||||
"project.reporting.outputEncoding": "UTF-8",
|
||||
"java.version": "1.8",
|
||||
"maven.compiler.source": "1.8",
|
||||
"project.build.sourceEncoding": "UTF-8",
|
||||
"maven.compiler.target": "1.8"
|
||||
},
|
||||
"dependencyManagement": null,
|
||||
"dependencies": [
|
||||
{
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-starter-web",
|
||||
"version": null,
|
||||
"type": "jar",
|
||||
"classifier": null,
|
||||
"scope": null,
|
||||
"systemPath": null,
|
||||
"exclusions": [],
|
||||
"optional": null,
|
||||
"managementKey": "org.springframework.boot:spring-boot-starter-web:jar"
|
||||
}
|
||||
],
|
||||
"repositories": [],
|
||||
"pluginRepositories": [],
|
||||
"reports": null,
|
||||
"reporting": null,
|
||||
"modelVersion": "4.0.0",
|
||||
"parent": {
|
||||
"groupId": "org.springframework.boot",
|
||||
"artifactId": "spring-boot-starter-parent",
|
||||
"version": "2.0.5.RELEASE",
|
||||
"relativePath": "",
|
||||
"id": "org.springframework.boot:spring-boot-starter-parent:pom:2.0.5.RELEASE"
|
||||
},
|
||||
"groupId": "com.demo.polyglot",
|
||||
"artifactId": "maven-polyglot-app",
|
||||
"version": "1.0.1",
|
||||
"packaging": "jar",
|
||||
"name": "Json Maven Polyglot",
|
||||
"description": null,
|
||||
"url": null,
|
||||
"inceptionYear": null,
|
||||
"organization": null,
|
||||
"licenses": [],
|
||||
"developers": [],
|
||||
"contributors": [],
|
||||
"mailingLists": [],
|
||||
"prerequisites": null,
|
||||
"scm": null,
|
||||
"issueManagement": null,
|
||||
"ciManagement": null,
|
||||
"build": {
|
||||
"plugins": [
|
||||
{
|
||||
"inherited": null,
|
||||
"configuration": null,
|
||||
"inheritanceApplied": true,
|
||||
"groupId": "org.liquibase",
|
||||
"artifactId": "liquibase-maven-plugin",
|
||||
"version": "3.0.5",
|
||||
"extensions": null,
|
||||
"executions": [],
|
||||
"dependencies": [],
|
||||
"goals": null,
|
||||
"key": "org.liquibase:liquibase-maven-plugin",
|
||||
"id": "org.liquibase:liquibase-maven-plugin:3.0.5",
|
||||
"executionsAsMap": {}
|
||||
}
|
||||
],
|
||||
"pluginManagement": null,
|
||||
"defaultGoal": null,
|
||||
"resources": [],
|
||||
"testResources": [],
|
||||
"directory": null,
|
||||
"finalName": null,
|
||||
"filters": [],
|
||||
"sourceDirectory": null,
|
||||
"scriptSourceDirectory": null,
|
||||
"testSourceDirectory": null,
|
||||
"outputDirectory": null,
|
||||
"testOutputDirectory": null,
|
||||
"extensions": [],
|
||||
"pluginsAsMap": {
|
||||
"org.liquibase:liquibase-maven-plugin": {
|
||||
"inherited": null,
|
||||
"configuration": null,
|
||||
"inheritanceApplied": true,
|
||||
"groupId": "org.liquibase",
|
||||
"artifactId": "liquibase-maven-plugin",
|
||||
"version": "3.0.5",
|
||||
"extensions": null,
|
||||
"executions": [],
|
||||
"dependencies": [],
|
||||
"goals": null,
|
||||
"key": "org.liquibase:liquibase-maven-plugin",
|
||||
"id": "org.liquibase:liquibase-maven-plugin:3.0.5",
|
||||
"executionsAsMap": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"profiles": [],
|
||||
"modelEncoding": "UTF-8",
|
||||
"pomFile": null,
|
||||
"id": "com.demo.polyglot:maven-polyglot-app:jar:1.0.1",
|
||||
"projectDirectory": null
|
||||
}
|
Loading…
Reference in New Issue