forked from matteobaccan/owner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automation of Properties creator in build phase with a maven plugin
Feature to automate the properties file creation; Created a plugin that can be add in the pom to automatic create properties based on passed args
- Loading branch information
Showing
7 changed files
with
688 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.aeonbits.owner</groupId> | ||
<artifactId>maven-plugin-owner-creator</artifactId> | ||
<packaging>maven-plugin</packaging> | ||
<version>1.0.11-SNAPSHOT</version> | ||
<name>OWNER :: Plugin</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>3.5.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<version>3.5.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-project</artifactId> | ||
<version>2.0.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.aeonbits.owner</groupId> | ||
<artifactId>owner</artifactId> | ||
<version>1.0.11-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-artifact</artifactId> | ||
<version>2.0.8</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>3.2</version> | ||
<configuration> | ||
<!-- see http://jira.codehaus.org/browse/MNG-5346 --> | ||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>mojo-descriptor</id> | ||
<goals> | ||
<goal>descriptor</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
99 changes: 99 additions & 0 deletions
99
...eator-maven-plugin/src/main/java/org/aeonbits/owner/plugin/PropertiesFileCreatorMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2012-2015, Luigi R. Viggiano | ||
* All rights reserved. | ||
* | ||
* This software is distributable under the BSD license. | ||
* See the terms of the BSD license in the documentation provided with this software. | ||
*/ | ||
|
||
package org.aeonbits.owner.plugin; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.aeonbits.owner.creator.PropertiesFileCreator; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
import org.apache.maven.project.MavenProject; | ||
|
||
/** | ||
* | ||
* @author Luca Taddeo | ||
*/ | ||
|
||
@Mojo(name = "create", requiresDependencyResolution = ResolutionScope.RUNTIME) | ||
public class PropertiesFileCreatorMojo | ||
extends AbstractMojo { | ||
|
||
/** | ||
* Location of the output properties file. | ||
*/ | ||
@Parameter(required=true) | ||
private String outputDirectory; | ||
|
||
/** | ||
* Config class to parse. | ||
*/ | ||
@Parameter(required=true) | ||
private String packageClass; | ||
|
||
/** | ||
* Jar to include. | ||
*/ | ||
@Parameter | ||
private String jarPath; | ||
|
||
/** | ||
* Project Name. | ||
*/ | ||
@Parameter | ||
private String projectName; | ||
|
||
/** | ||
* Project description. | ||
*/ | ||
@Parameter | ||
private String projectDesription; | ||
|
||
@Component | ||
private MavenProject project; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
try { | ||
|
||
List<URL> urls = new ArrayList(); | ||
|
||
if(jarPath != null && !jarPath.isEmpty()) { | ||
System.out.println("Use passed jar [" + jarPath + "]"); | ||
File jar = new File(jarPath); | ||
urls.add(jar.toURI().toURL()); | ||
} else { | ||
System.out.println("Use classpath"); | ||
// Loading project classpath to retrieve class | ||
for (Object ele : project.getRuntimeClasspathElements()) { | ||
File jar = new File(ele.toString()); | ||
urls.add(jar.toURI().toURL()); | ||
} | ||
} | ||
|
||
URLClassLoader jarPack = new URLClassLoader(urls.toArray(new URL[urls.size()]), this.getClass().getClassLoader()); | ||
Class classToLoad = jarPack.loadClass(packageClass); | ||
|
||
// Parse class and create property file | ||
PropertiesFileCreator creator = new PropertiesFileCreator(); | ||
creator.parse(classToLoad, outputDirectory, projectName, projectDesription); | ||
System.out.println("Conversion succeded, properties saved [" + outputDirectory + "]"); | ||
} catch (Throwable ex) { | ||
throw new MojoExecutionException(ex.getMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
owner/src/main/java/org/aeonbits/owner/creator/Creator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2012-2015, Luigi R. Viggiano | ||
* All rights reserved. | ||
* | ||
* This software is distributable under the BSD license. | ||
* See the terms of the BSD license in the documentation provided with this software. | ||
*/ | ||
|
||
package org.aeonbits.owner.creator; | ||
|
||
/** | ||
* Interface to convert Config class into something else. | ||
* | ||
* @author Luca Taddeo | ||
*/ | ||
public interface Creator { | ||
boolean parse(Class clazz, String output, String headerName, String projectName) throws Exception; | ||
} |
Oops, something went wrong.