Skip to content

Commit

Permalink
Merge branch 'release/7.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Jul 3, 2022
2 parents e47e6c5 + e592d4b commit d9ebdd0
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 88 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ It is a **Maven plugin** that generates **project's documentation directly to co
> * [Usage](http://bsorrentino.github.io/maven-confluence-plugin/usage.html)
> * [Use YAML Site Definition](http://bsorrentino.github.io/maven-confluence-plugin/site_yaml_guide.html)
> * [Use XML Site Definition](http://bsorrentino.github.io/maven-confluence-plugin/site_xml_guide.html)
> * [Use JSON Site Definition](http://bsorrentino.github.io/maven-confluence-plugin/site_json_guide.html)
### Format
> * [Markdown Syntax Support](http://bsorrentino.github.io/maven-confluence-plugin/markdown_guide.html)
> * [Storage Format Support](http://bsorrentino.github.io/maven-confluence-plugin/storageformat_guide.html)
Expand All @@ -29,7 +30,8 @@ For pratical samples refer to folder/module [test-publishing](https://github.com

Date | Release | Info
--- |-----------------------------------------------------------------------------------------------------| ---
**Jun 3, 2022** | [Release 7.6](https://github.com/bsorrentino/maven-confluence-plugin/releases/tag/v7.6) | Merged PR [#201](https://github.com/bsorrentino/maven-confluence-plugin/pull/267) "**added function to define jira instance baseurl**", that fix issue [#136](https://github.com/bsorrentino/maven-confluence-plugin/issues/136). Thanks to [tspindler](https://github.com/tspindler) for contribution
**Jul 3, 2022** | [Release 7.7](https://github.com/bsorrentino/maven-confluence-plugin/releases/tag/v7.7) | Merged PR [#266](https://github.com/bsorrentino/maven-confluence-plugin/pull/266) "**Adding JSON Support**". Thanks to [jksevend](https://github.com/jksevend) for contribution.
**Jun 3, 2022** | [Release 7.6](https://github.com/bsorrentino/maven-confluence-plugin/releases/tag/v7.6) | Merged PR [#267](https://github.com/bsorrentino/maven-confluence-plugin/pull/267) "**added function to define jira instance baseurl**", that fix issue [#136](https://github.com/bsorrentino/maven-confluence-plugin/issues/136). Thanks to [tspindler](https://github.com/tspindler) for contribution
**Apr 1, 2022** | [Release 7.5](https://github.com/bsorrentino/maven-confluence-plugin/releases/tag/v7.5) | Fix empty table cell not handled properly. Refer to [#264](https://github.com/bsorrentino/maven-confluence-plugin/issues/264).
**Jan 10, 2022** | [Release 7.4](https://github.com/bsorrentino/maven-confluence-plugin/releases/tag/v7.4) | Fix problem with **encoding**. Refer to [#261](https://github.com/bsorrentino/maven-confluence-plugin/issues/261).
**Aug 09, 2021** | [Release 7.3.2](https://github.com/bsorrentino/maven-confluence-plugin/releases/tag/v7.3.2) | Fix problem with **ReadTimeout** & **WriteTimeout**. Refer to [#256](https://github.com/bsorrentino/maven-confluence-plugin/issues/256). see the PR [#257](https://github.com/bsorrentino/maven-confluence-plugin/pull/257) for details. Thanks to [qwazer](https://github.com/qwazer) for contribution
Expand Down
2 changes: 1 addition & 1 deletion addon-scrollversions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>maven-confluence-parent</artifactId>
<groupId>org.bsc.maven</groupId>
<version>7.6</version>
<version>7.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>maven-confluence-parent</artifactId>
<groupId>org.bsc.maven</groupId>
<version>7.6</version>
<version>7.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
132 changes: 68 additions & 64 deletions core/src/main/java/org/bsc/confluence/model/SiteFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.bsc.confluence.model;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
Expand All @@ -23,107 +24,110 @@
import static java.lang.String.format;

/**
*
* @author bsorrentino
*/
public interface SiteFactory {

@Log
final class LogHolder {}


@Log
final class LogHolder {
}

interface Folder {

Site createSiteFromFolder();

}

interface Model {

Site createSiteFromModel(Map<String, Object> variables);

/**
*
* @param siteDescriptor
* @param variables
* @return
* @throws Exception
*/
default Site createFrom( java.io.File siteDescriptor, Map<String, Object> variables ) throws Exception {
default Site createFrom(java.io.File siteDescriptor, Map<String, Object> variables) throws Exception {

if (variables == null)
throw new java.lang.IllegalArgumentException("variables is null!");
final String ext =

final String ext =
Optional.ofNullable(FilenameUtils.getExtension(siteDescriptor.getName()))
.map( v -> v.toLowerCase() )
.orElse("");
.map(v -> v.toLowerCase())
.orElse("");

// _createSite lambda function
final Function<String,CompletableFuture<Site>> _createSite = ( String preprocessedDescriptor ) -> {
final Function<String, CompletableFuture<Site>> _createSite = (String preprocessedDescriptor) -> {

final CompletableFuture<Site> result = new CompletableFuture<>();

switch( ext ) {
case "xml":
{
try {
final ObjectMapper mapper = new ObjectMapper(new XmlFactory());
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
result.complete( mapper.readValue( preprocessedDescriptor, Site.class ) );
}
catch( Exception e ) {
result.completeExceptionally(e);
}

break;
}
case "yml":
case "yaml":
{
try {

final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
result.complete( mapper.readValue( preprocessedDescriptor, Site.class ) );
}
catch( Exception e ) {
result.completeExceptionally(e);
switch (ext) {
case "xml": {
try {
final ObjectMapper mapper = new ObjectMapper(new XmlFactory());
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
result.complete(mapper.readValue(preprocessedDescriptor, Site.class));
} catch (Exception e) {
result.completeExceptionally(e);
}

break;
}
case "yml":
case "yaml": {
try {

break;
}
default:
result.completeExceptionally(new IllegalArgumentException(
format("file extension [%s] not supported! Currently only '.xml' and '.yaml' are valid", ext)));
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
result.complete(mapper.readValue(preprocessedDescriptor, Site.class));
} catch (Exception e) {
result.completeExceptionally(e);
}

break;
}
case "json":
try {
final ObjectMapper mapper = new ObjectMapper(new JsonFactory());
result.complete(mapper.readValue(preprocessedDescriptor, Site.class));
} catch (Exception e) {
result.completeExceptionally(e);
}
default:
result.completeExceptionally(new IllegalArgumentException(
format("file extension [%s] not supported! Currently only '.xml', '.yaml' and '.json'" +
"are valid", ext)));
}

return result;
}; // end lambda function

byte[] siteDescriptorBytes;
try( java.io.InputStream is = new FileInputStream(siteDescriptor.toPath().toFile()) ) {
siteDescriptorBytes = IOUtils.toByteArray( is );
try (java.io.InputStream is = new FileInputStream(siteDescriptor.toPath().toFile())) {
siteDescriptorBytes = IOUtils.toByteArray(is);
}
// JAVA 11
// siteDescriptorBytes = Files.readAllBytes(siteDescriptor.toPath());

final String content = new String(siteDescriptorBytes, StandardCharsets.UTF_8);

final Optional<SiteProcessorService> siteProcessor = SiteProcessorService.getDefaultPreprocessorService();

final CompletableFuture<Site> future =
siteProcessor.map( p -> p.process(content, variables)
.thenCompose( _createSite )
// uncomment if you want process source content ignoring preprocess exception
//.exceptionally( e -> _createSite.apply(content).join() )
)
.orElseGet( () -> {
LogHolder.log.fine( format("a Preprocessor service is not configurated") );
return _createSite.apply(content);
});
siteProcessor.map(p -> p.process(content, variables)
.thenCompose(_createSite)
// uncomment if you want process source content ignoring preprocess exception
//.exceptionally( e -> _createSite.apply(content).join() )
)
.orElseGet(() -> {
LogHolder.log.fine(format("a Preprocessor service is not configurated"));
return _createSite.apply(content);
});

return future.join();


}
}
}
38 changes: 33 additions & 5 deletions core/src/test/kotlin/org/bsc/confluence/model/SiteLoadTest.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package org.bsc.confluence.model

import com.fasterxml.jackson.databind.DeserializationConfig
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.xml.XmlFactory
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import java.nio.file.Files
import java.nio.file.Paths
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule




class SiteLoadTest {
Expand All @@ -39,6 +36,15 @@ class SiteLoadTest {
}
}

private fun loadFromJSON(resource: String, c: ( site:Site ) -> Unit = {}) {
val mapper = JsonMapper() //ObjectMapper(XmlFactory())
javaClass.classLoader.getResourceAsStream(resource).use { `is` ->
val site = mapper.readValue(`is`, Site::class.java)
assertNotNull(site)
c(site)
}
}

@Test
fun testIssue182() = assertThrows(JsonMappingException::class.java) {
loadFromYAML("site-issue182.yaml")
Expand Down Expand Up @@ -93,5 +99,27 @@ class SiteLoadTest {
}
}

@Test
fun testLoadFromJSON() {
val tempDirectory = Files.createTempDirectory(null)

loadFromJSON("site.json") { site ->

val basedir = Paths.get(tempDirectory.toString())
site.basedir = basedir

assertNotNull(site.home)
val uri = Paths.get(basedir.toString(), "encoding.confluence").toUri()
assertEquals( uri, site.home.uri)
val children = site.home.children
assertNotNull(children)
assertEquals(2, children.size)
val attachments = site.home.attachments
assertNotNull(attachments)
assertEquals(1, attachments.size)
val labels = site.labels
assertNotNull(labels)
assertEquals(2, labels.size)
}
}
}
37 changes: 37 additions & 0 deletions core/src/test/resources/site.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"home": {
"uri": "encoding.confluence",
"children": [
{
"name": "page 1",
"uri": "page1.md"
},
{
"name": "page 2",
"uri": "page2.md",
"attachments": [
{
"name": "attach1.png",
"uri": "attach1.png",
"comment": "attach1_comment",
"contentType": "image/png",
"version": 1
}
]
}
],
"attachments": [
{
"name": "home.png",
"uri": "home.png",
"comment": "home_comment",
"contentType": "image/png",
"version": 1
}
]
},
"labels": [
"encoding",
"test"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
<version>3.0.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
<version>3.0.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
2 changes: 1 addition & 1 deletion gitlog+jira/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>maven-confluence-parent</artifactId>
<groupId>org.bsc.maven</groupId>
<version>7.6</version>
<version>7.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion plugin-reporting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>maven-confluence-parent</artifactId>
<groupId>org.bsc.maven</groupId>
<version>7.6</version>
<version>7.7</version>
</parent>

<prerequisites>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,12 @@ private ReportingResolutionListener resolveProject() {
artifactMetadataSource, null,
Collections.singletonList(listener));
} catch (Exception e) {
getLog().warn("An error occurred while resolving project dependencies.", e);
if( getLog().isDebugEnabled() ) {
getLog().warn("An error occurred while resolving project dependencies.", e);
}
else {
getLog().warn(format("An error occurred while resolving project dependencies.\n%s", e.getMessage()) );
}
}

return listener;
Expand Down
Loading

0 comments on commit d9ebdd0

Please sign in to comment.