Improve maven plugin
@@ -52,9 +52,6 @@ import org.apache.maven.shared.utils.StringUtils;
*/
@Mojo(name = "generate-metadata", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresProject = true, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class GenerateMetadataMojo extends AbstractMojo {
-
- public static final String METADATA_DESTINATION = "META-INF/syndesis/extension-definition.json";
-
@Parameter(readonly = true, defaultValue = "${project}")
private MavenProject project;
@@ -79,6 +76,9 @@ public class GenerateMetadataMojo extends AbstractMojo {
@Parameter
private String tags;
+ @Parameter(readonly = true, defaultValue = "${project.build.directory}/classes/META-INF/syndesis/extension-definition.json")
+ private String metadataDestination;
+
/**
* Partial Extension JSON descriptor to augment
*/
@@ -101,6 +101,7 @@ public class GenerateMetadataMojo extends AbstractMojo {
protected void processAnnotations() throws MojoExecutionException {
String directory = project.getModel().getBuild().getDirectory();
Path dir = Paths.get(directory, "generated-sources", "annotations");
+ if (Files.exists(dir)) {
getLog().info("Looking in for annotated classes in: " + dir);
try {
Files.find(dir, Integer.MAX_VALUE, (path, basicFileAttributes) -> String.valueOf(path).endsWith(".properties")).forEach(path -> {
@@ -116,6 +117,9 @@ public class GenerateMetadataMojo extends AbstractMojo {
} catch (IOException e) {
throw new MojoExecutionException("Error checking annotations.", e);
}
+ } else {
+ getLog().debug("Path " + dir + " does not exists");
+ }
}
protected void assignProperties(Properties p) {
@@ -172,14 +176,26 @@ public class GenerateMetadataMojo extends AbstractMojo {
*/
protected void tryImportingPartialJSON() throws MojoExecutionException {
if(StringUtils.isNotEmpty(source)){
- TechExtension techExtension = null;
+ TechExtension techExtension ;
try {
techExtension = objectMapper.readValue(new File(source), TechExtension.class);
- getLog().info("Loaded base parital metadata configuration file: " + source);
+ getLog().info("Loaded base partial metadata configuration file: " + source);
} catch (IOException e) {
throw new MojoExecutionException("Invalid input json: " + source, e );
}
techExtensionBuilder = techExtensionBuilder.createFrom(techExtension);
+ } else {
+ File targetFile = new File(metadataDestination);
+ if (targetFile.exists()) {
+ TechExtension techExtension;
+ try {
+ techExtension = objectMapper.readValue(targetFile, TechExtension.class);
+ getLog().info("Loaded base partial metadata configuration file: " + targetFile.getAbsolutePath());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Invalid input json: " + targetFile.getAbsolutePath(), e );
+ }
+ techExtensionBuilder = techExtensionBuilder.createFrom(techExtension);
+ }
}
}
@@ -227,7 +243,7 @@ public class GenerateMetadataMojo extends AbstractMojo {
}
protected void saveExtensionMetaData(TechExtension jsonObject) throws MojoExecutionException {
- File targetFile = new File(METADATA_DESTINATION);
+ File targetFile = new File(metadataDestination);
if (!targetFile.getParentFile().exists() &&
!targetFile.getParentFile().mkdirs()) {
throw new MojoExecutionException("Cannot create directory " + targetFile.getParentFile());
@@ -236,7 +252,7 @@ public class GenerateMetadataMojo extends AbstractMojo {
objectMapper.writerWithDefaultPrettyPrinter().writeValue(targetFile, jsonObject);
getLog().info("Created file " + targetFile.getAbsolutePath());
} catch (IOException e) {
- throw new MojoExecutionException("Cannot write to file: " + METADATA_DESTINATION, e);
+ throw new MojoExecutionException("Cannot write to file: " + metadataDestination, e);
}
}
}
