Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ out/
*.iws
classpath.txt
version.properties
!modules/swagger-codegen-cli/src/main/resources/version.properties
.project
.classpath
lib/*
Expand Down Expand Up @@ -33,7 +34,7 @@ packages/

/target
/generated-files
/nbactions.xml
nbactions.xml

# scalatra
samples/server-generator/scalatra/output
Expand Down
1 change: 1 addition & 0 deletions modules/swagger-codegen-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
Copy link
Copy Markdown
Contributor

@ePaul ePaul Sep 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear there might have some side effects as we are filtering all the files under src/main/resources, not just the version.properties one – including all the templates.

To make sure that there are none, could you actually run all the petstore samples and see if there are any changes in the output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing anything build-wise, I think this should not be a problem because the filtering is enabled just for the swagger-codegen-cli artifact and should not apply to the resources from swagger-codegen artifact (which is where all the templates are included as resources).

Running the samples should be a good practice anyway, so I'll try to find the time to do so, however.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point, I missed this.

<excludes>
<exclude>logback.xml</exclude>
</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.codegen.cmd.Generate;
import io.swagger.codegen.cmd.Langs;
import io.swagger.codegen.cmd.Meta;
import io.swagger.codegen.cmd.Version;

/**
* User: lanwen
Expand All @@ -21,16 +22,20 @@ public class SwaggerCodegen {


public static void main(String[] args) {
String version = Version.readVersionFromResources();
@SuppressWarnings("unchecked")
Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("swagger-codegen-cli")
.withDescription("Swagger code generator CLI. More info on swagger.io")
.withDescription(String.format(
"Swagger code generator CLI (version %s). More info on swagger.io",
version))
.withDefaultCommand(Langs.class)
.withCommands(
Generate.class,
Meta.class,
Langs.class,
Help.class,
ConfigHelp.class
ConfigHelp.class,
Version.class
);

builder.build().parse(args).run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ public void run() {
"src/main/resources/META-INF/services", "io.swagger.codegen.CodegenConfig")
);

String swaggerVersion = this.getClass().getPackage().getImplementationVersion();
// if the code is running outside of the jar (i.e. from the IDE), it will not have the version available.
// let's default it with something.
if (swaggerVersion==null) {
swaggerVersion = "2.1.3";
}
String swaggerVersion = Version.readVersionFromResources();

Map<String, Object> data = new ImmutableMap.Builder<String, Object>()
.put("generatorPackage", targetPackage)
.put("generatorClass", mainClass)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.swagger.codegen.cmd;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import io.airlift.airline.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Command(name = "version", description = "Show version information")
public class Version implements Runnable {

private static final Logger LOGGER = LoggerFactory.getLogger(Meta.class);

private static final String VERSION_PLACEHOLDER = "${project.version}";

private static final String UNREADABLE_VERSION = "unreadable";
private static final String UNSET_VERSION = "unset";
private static final String UNKNOWN_VERSION = "unknown";

public static String readVersionFromResources() {
Properties versionProperties = new Properties();
try (InputStream is = Version.class.getResourceAsStream("/version.properties")) {
versionProperties.load(is);
} catch (IOException ex) {
LOGGER.error("Error loading version properties", ex);
return UNREADABLE_VERSION;
}

String version = versionProperties.getProperty("version", UNKNOWN_VERSION).trim();
if (VERSION_PLACEHOLDER.equals(version)) {
return UNSET_VERSION;
} else {
return version;
}
}

@Override
public void run() {
String version = readVersionFromResources();
System.out.println(version);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = ${project.version}