Skip to content

Commit 2532ecf

Browse files
Merge branch 'release-2.0'
2 parents 12c741a + cb75f08 commit 2532ecf

File tree

49 files changed

+2559
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2559
-439
lines changed

.gitlab-ci.yml

+18-6
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ cache:
1515
- .gradle/wrapper
1616
- .gradle/caches
1717

18-
job_build_develop:
18+
job_build:
1919
stage: build
2020
script:
21-
- ./gradlew clean build
22-
only:
23-
- develop
21+
- ./gradlew clean build shadowJar
22+
except:
23+
- maseter
2424
tags:
2525
- docker
2626

2727
job_build_master:
2828
stage: build
2929
script:
30-
- ./gradlew clean build -Prelease=true
30+
- ./gradlew clean build shadowJar -Prelease=true
3131
only:
3232
- master
3333
tags:
@@ -36,12 +36,22 @@ job_build_master:
3636
job_analyze_develop:
3737
stage: analyze
3838
script:
39-
- ./gradlew jacocoTestReport sonarqube
39+
- ./gradlew jacocoTestReport sonarqube -Dsonar.issuesReport.console.enable=true -Dsonar.gitlab.commit_sha=$CI_BUILD_REF -Dsonar.gitlab.ref=$CI_BUILD_REF_NAME
4040
only:
4141
- develop
4242
tags:
4343
- docker
4444

45+
job_analyze_pull:
46+
stage: analyze
47+
script:
48+
- ./gradlew jacocoTestReport sonarqube -Dsonar.analysis.mode=preview -Dsonar.issuesReport.console.enable=true -Dsonar.gitlab.commit_sha=$CI_BUILD_REF -Dsonar.gitlab.ref=$CI_BUILD_REF_NAME
49+
except:
50+
- develop
51+
- master
52+
tags:
53+
- docker
54+
4555
job_publish_develop:
4656
stage: publish
4757
only:
@@ -50,6 +60,7 @@ job_publish_develop:
5060
- ./gradlew publish
5161
artifacts:
5262
paths:
63+
- swagger-confluence-cli/build/libs/*.jar
5364
- swagger-confluence-core/build/libs/*.jar
5465
- swagger-confluence-gradle-plugin/build/libs/*.jar
5566
tags:
@@ -63,6 +74,7 @@ job_publish_master:
6374
- ./gradlew publish -Prelease=true
6475
artifacts:
6576
paths:
77+
- swagger-confluence-cli/build/libs/*.jar
6678
- swagger-confluence-core/build/libs/*.jar
6779
- swagger-confluence-gradle-plugin/build/libs/*.jar
6880
tags:

README.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,40 @@ This project uses the following flow to publish to Confluence:
1616

1717
Your Swagger Schema -> Swagger2Markup -> AsciiDoctorJ -> XHTML -> Confluence REST API
1818

19+
20+
1921
This project requires the use of Java 7 or later.
2022

21-
## Documentation & Usage
23+
## Components
24+
25+
The project is current broken into three components
26+
27+
- **swagger-confluence-core:** a core shared library to handle converting and publishing the swagger schema to confluence. This shared library should be reusable by other projects
28+
- **swagger-confluence-gradle-plugin:** a gradle plugin to provide seamless conversion and publishing
29+
- **swagger-confluence-cli:** a command line executor for publishing to swagger docs to confluence
30+
31+
## Documentation & Usage Guide
2232

2333
You can view the documentation and usage guide [here](https://cloud.slkdev.net/swagger-confluence)
2434

35+
## Live Demo
36+
37+
You can view a live demo of Swagger Confluence [here on my Confluence Server](https://cloud.slkdev.net/confluence/display/DEMO/Swagger+Confluence+Demos)
38+
2539
## Contributing
2640

2741
### Community contributions
2842

43+
Pull requests are welcome. The primary source repository for this project is hosted on my [GitLab CE Instance](https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence).
2944

30-
Pull requests are welcome. Please submit via my [GitLab Instance](https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence)
3145

46+
It is preferred that if you wish to contribute, you submit there as this is where I have CI, SonarQube, etc set up. GitLab CE officially provides OmniAuth integration to make this easy, or you can of course sign up manually as well.
3247

3348

49+
GitLab CE is open source software. If you are unfamiliar with it, you can read more about it [here](https://about.gitlab.com/) on their official web site.
50+
51+
52+
If you are not comfortable with this, you may submit via the GitHub mirror, and I will merge it back manually.
3453

3554
### Questions, Bugs, or Enhacement Requests
3655

@@ -48,6 +67,10 @@ If you would like an enhancement to be made to the Swagger Confluence, pull requ
4867

4968

5069

70+
## Static Code Analysis + Coverage
71+
72+
See [SonarQube](https://cloud.slkdev.net/sonar/overview?id=30) for this project
73+
5174
## Special Thanks
5275

5376

@@ -66,11 +89,9 @@ conjunction with the above projects and their respective gradle plugins before s
6689
* [asciidoctor-confluence](https://github.com/gscheibel/asciidoctor-confluence)
6790
* [asciidoc2confluence](https://github.com/rdmueller/asciidoc2confluence)
6891

69-
The XHTML->Confluence REST API portion of this library was inspired by the
92+
The XHTML->Confluence REST API portion of this library was originally inspired by the
7093
asciidoc2confluence groovy script
7194

72-
73-
7495
## License
7596

7697
Copyright 2016 Aaron Knight

build.gradle

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
maven {
5+
url "https://plugins.gradle.org/m2/"
6+
}
7+
jcenter()
8+
mavenCentral()
9+
}
10+
dependencies {
11+
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2"
12+
}
13+
}
14+
15+
tasks.withType(JavaExec) {
16+
systemProperties System.properties
17+
}
18+
19+
apply plugin: 'org.sonarqube'
20+
21+
sonarqube {
22+
properties {
23+
property "sonar.host.url", "$System.env.SONAR_URL"
24+
property "sonar.login", "$System.env.SONAR_USER"
25+
property "sonar.password", "$System.env.SONAR_PASS"
26+
property "sonar.sourceEncoding", "UTF-8"
27+
property "sonar.java.source", "1.7"
28+
property "sonar.java.target", "1.7"
29+
}
30+
}
31+
132
allprojects {
233
apply plugin: 'idea'
334
apply plugin: 'eclipse'
@@ -6,7 +37,7 @@ allprojects {
637
subprojects {
738
group 'net.slkdev.swagger.confluence'
839

9-
version '1.0'
40+
version '2.0'
1041

1142
if (project.hasProperty("release")) {
1243
version += '-RELEASE'

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
ASCIIDOCTORJ_VERSION=1.5.4
2+
COMMONS_CLI=1.3.1
23
JSONPATH_VERSION=2.2.0
4+
JSOUP_VERSION=1.8.3
35
JUNIT_VERSION=4.12
46
LOG4J2_VERSION=2.5
57
MOCKITO_VERSION=1.10.19

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
rootProject.name = 'swagger-confluence'
2-
include 'swagger-confluence-core', 'swagger-confluence-gradle-plugin'
2+
include 'swagger-confluence-core', 'swagger-confluence-gradle-plugin', 'swagger-confluence-cli'
33

swagger-confluence-cli/build.gradle

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
maven {
5+
url "https://plugins.gradle.org/m2/"
6+
}
7+
jcenter()
8+
mavenCentral()
9+
}
10+
dependencies {
11+
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
12+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
13+
}
14+
}
15+
16+
apply plugin: 'java'
17+
apply plugin: 'com.github.johnrengelman.shadow'
18+
apply plugin: 'com.jfrog.bintray'
19+
20+
defaultTasks 'shadowJar'
21+
22+
jar {
23+
manifest {
24+
attributes 'Main-Class': 'net.slkdev.swagger.confluence.cli.SwaggerConfluence'
25+
}
26+
}
27+
28+
shadowJar {
29+
baseName = 'swagger-confluence-cli-all'
30+
classifier = ''
31+
mergeServiceFiles()
32+
append('NOTICE')
33+
}
34+
35+
bintray {
36+
user = "$System.env.BINTRAY_USER"
37+
key = "$System.env.BINTRAY_PASS"
38+
publications = ['myPublication']
39+
pkg {
40+
version {
41+
name = project.version
42+
}
43+
repo = "$System.env.BINTRAY_REPO"
44+
name = 'swagger-confluence-cli'
45+
userOrg = "$System.env.BINTRAY_USER"
46+
licenses = ['Apache-2.0']
47+
vcsUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence'
48+
websiteUrl = 'https://cloud.slkdev.net/swagger-confluence'
49+
issueTrackerUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/issues'
50+
labels = ['swagger','confluence']
51+
}
52+
}
53+
54+
evaluationDependsOn(':swagger-confluence-core')
55+
56+
dependencies {
57+
compile (project(':swagger-confluence-core'))
58+
compile "commons-cli:commons-cli:$COMMONS_CLI"
59+
60+
testCompile "junit:junit:$JUNIT_VERSION"
61+
testCompile "org.mockito:mockito-core:$MOCKITO_VERSION"
62+
}
63+
64+
publishing {
65+
publications {
66+
myPublication(MavenPublication) {
67+
from components.java
68+
artifactId = 'swagger-confluence-cli'
69+
}
70+
myShadowPublication(MavenPublication) {
71+
from components.shadow
72+
artifactId = 'swagger-confluence-cli-all'
73+
}
74+
}
75+
}
76+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright 2016 Aaron Knight
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.slkdev.swagger.confluence.cli;
17+
18+
import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig;
19+
import net.slkdev.swagger.confluence.context.SwaggerConfluenceContextConfig;
20+
import net.slkdev.swagger.confluence.exception.SwaggerConfluenceConfigurationException;
21+
import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService;
22+
import org.apache.commons.cli.*;
23+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
24+
25+
import static org.apache.commons.lang3.Validate.notNull;
26+
27+
public class SwaggerConfluence {
28+
29+
private SwaggerToConfluenceService swaggerToConfluenceService;
30+
31+
public SwaggerConfluence(final SwaggerToConfluenceService swaggerToConfluenceService){
32+
notNull(swaggerToConfluenceService, "SwaggerToConfluenceService Cannot Be Null!");
33+
this.swaggerToConfluenceService = swaggerToConfluenceService;
34+
}
35+
36+
public static void main(final String[] args){
37+
final SwaggerToConfluenceService swaggerToConfluenceService = bootSwaggerConfluence();
38+
final SwaggerConfluence swaggerConfluence = new SwaggerConfluence(swaggerToConfluenceService);
39+
swaggerConfluence.runCLI(args);
40+
}
41+
42+
private static SwaggerToConfluenceService bootSwaggerConfluence(){
43+
final AnnotationConfigApplicationContext annotationConfigApplicationContext =
44+
new AnnotationConfigApplicationContext(SwaggerConfluenceContextConfig.class);
45+
return annotationConfigApplicationContext.getBean(SwaggerToConfluenceService.class);
46+
}
47+
48+
public void runCLI(final String args[]){
49+
final Options options = buildOptions();
50+
final CommandLine commandLine = parseCommandLineOptions(options, args);
51+
52+
if(commandLine.hasOption("h") || args.length == 0){
53+
final HelpFormatter formatter = new HelpFormatter();
54+
formatter.printHelp("swagger-confluence-cli", options);
55+
}
56+
else {
57+
final SwaggerConfluenceConfig swaggerConfluenceConfig =
58+
buildSwaggerConfluenceConfig(commandLine);
59+
swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig);
60+
}
61+
}
62+
63+
private static Options buildOptions(){
64+
final Options options = new Options();
65+
66+
options.addOption("a", "ancestor-id", true, "ancestor id to use for the published api doc");
67+
options.addOption("b", "authentication", true, "base64 encoded user:pass pair for authentication");
68+
options.addOption("g", "generate-numeric-prefixes", true, "boolean flag to indicate whether to " +
69+
"generate numeric prefixes for titles");
70+
options.addOption("h", "help", false, "Print help message with usage information");
71+
options.addOption("i", "include-toc-on-single", true, "Include table of contents on single page mode");
72+
options.addOption("k", "space-key", true, "Space Key to publish api doc to");
73+
options.addOption("m", "pagination-mode", true, "Pagination mode to use: [single, category, individual]");
74+
options.addOption("s", "swagger-schema", true, "Swagger Schema name. Absolute, relative, or classpath location");
75+
options.addOption("p", "prefix", true, "Prefix to use for article titles to ensure uniqueness");
76+
options.addOption("t", "title", true, "Base title to use for the root article of the API doc");
77+
options.addOption("u", "confluence-rest-api-url", true, "URL to the confluence REST API");
78+
79+
return options;
80+
}
81+
82+
private static CommandLine parseCommandLineOptions(final Options options, final String[] args){
83+
final CommandLineParser commandLineParser = new DefaultParser();
84+
85+
try {
86+
return commandLineParser.parse(options, args);
87+
88+
} catch (ParseException e) {
89+
throw new SwaggerConfluenceConfigurationException(
90+
"Error Parsing Command Line Arguments!", e);
91+
}
92+
}
93+
94+
private static SwaggerConfluenceConfig buildSwaggerConfluenceConfig(final CommandLine commandLine){
95+
final SwaggerConfluenceConfig swaggerConfluenceConfig = new SwaggerConfluenceConfig();
96+
final String ancestorIdString = commandLine.getOptionValue("a");
97+
final Integer ancestorId;
98+
99+
if(ancestorIdString == null){
100+
ancestorId = null;
101+
}
102+
else {
103+
ancestorId = Integer.valueOf(ancestorIdString);
104+
}
105+
106+
swaggerConfluenceConfig.setAncestorId(ancestorId);
107+
swaggerConfluenceConfig.setAuthentication(commandLine.getOptionValue("b"));
108+
swaggerConfluenceConfig.setConfluenceRestApiUrl(commandLine.getOptionValue("u"));
109+
swaggerConfluenceConfig.setGenerateNumericPrefixes(
110+
Boolean.valueOf(commandLine.getOptionValue("g", "true"))
111+
);
112+
swaggerConfluenceConfig.setIncludeTableOfContentsOnSinglePage(
113+
Boolean.valueOf(commandLine.getOptionValue("i", "true"))
114+
);
115+
swaggerConfluenceConfig.setPaginationMode(commandLine.getOptionValue("m","single"));
116+
117+
final String prefix = commandLine.getOptionValue("p");
118+
119+
if(prefix != null){
120+
swaggerConfluenceConfig.setPrefix(prefix);
121+
}
122+
123+
swaggerConfluenceConfig.setSpaceKey(commandLine.getOptionValue("k"));
124+
swaggerConfluenceConfig.setSwaggerSchema(commandLine.getOptionValue("s"));
125+
swaggerConfluenceConfig.setTitle(commandLine.getOptionValue("t"));
126+
127+
return swaggerConfluenceConfig;
128+
}
129+
130+
}

0 commit comments

Comments
 (0)