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
5 changes: 0 additions & 5 deletions modules/swagger-codegen-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@
<artifactId>airline</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>com.googlecode.lambdaj</groupId>
<artifactId>lambdaj</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.swagger.codegen.cmd;

import ch.lambdaj.collection.LambdaIterable;
import io.airlift.airline.Command;
import io.swagger.codegen.CodegenConfig;

import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.collection.LambdaCollections.with;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static java.util.ServiceLoader.load;

/**
Expand All @@ -15,8 +16,9 @@
public class Langs implements Runnable {
@Override
public void run() {
LambdaIterable<String> langs =
with(load(CodegenConfig.class)).extract(on(CodegenConfig.class).getName());
List<String> langs = StreamSupport.stream(load(CodegenConfig.class).spliterator(), false)
.map(CodegenConfig::getName)
.collect(Collectors.toList());
System.out.printf("Available languages: %s%n", langs);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.swagger.codegen.cmd;

import ch.lambdaj.function.convert.Converter;
import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -20,7 +19,6 @@
import java.util.List;
import java.util.Map;

import static ch.lambdaj.collection.LambdaCollections.with;
import static com.google.common.base.Joiner.on;

/**
Expand Down Expand Up @@ -79,51 +77,44 @@ public void run() {
.put("swaggerCodegenVersion", swaggerVersion).build();


with(supportingFiles).convert(processFiles(targetDir, data));
DefaultGenerator generator = new DefaultGenerator();
supportingFiles.forEach(f -> processFile(generator, f, targetDir, data));
}

/**
* Converter method to process supporting files: execute with mustache, or simply copy to
* destination directory
* Processes a supporting file: execute with mustache, or simply copy to destination directory
*
* @param generator - generator used to read templates
* @param support - supporting file to process
* @param targetDir - destination directory
* @param data - map with additional params needed to process templates
* @return converter object to pass to lambdaj
*/
private static Converter<SupportingFile, File> processFiles(final File targetDir,
final Map<String, Object> data) {
return new Converter<SupportingFile, File>() {
private DefaultGenerator generator = new DefaultGenerator();

@Override
public File convert(SupportingFile support) {
try {
File destinationFolder =
new File(new File(targetDir.getAbsolutePath()), support.folder);
File outputFile = new File(destinationFolder, support.destinationFilename);

String template =
generator.readTemplate(new File(TEMPLATE_DIR_CLASSPATH,
support.templateFile).getPath());
String formatted = template;

if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) {
LOGGER.info("writing file to {}", outputFile.getAbsolutePath());
formatted =
Mustache.compiler().withLoader(loader(generator)).defaultValue("")
.compile(template).execute(data);
} else {
LOGGER.info("copying file to {}", outputFile.getAbsolutePath());
}

FileUtils.writeStringToFile(outputFile, formatted, StandardCharsets.UTF_8);
return outputFile;

} catch (IOException e) {
throw new RuntimeException("Can't generate project", e);
}
private static void processFile(DefaultGenerator generator, SupportingFile support,
final File targetDir, final Map<String, Object> data) {
try {
File destinationFolder =
new File(new File(targetDir.getAbsolutePath()), support.folder);
File outputFile = new File(destinationFolder, support.destinationFilename);

String template =
generator.readTemplate(new File(TEMPLATE_DIR_CLASSPATH,
support.templateFile).getPath());
String formatted = template;

if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) {
LOGGER.info("writing file to {}", outputFile.getAbsolutePath());
formatted =
Mustache.compiler().withLoader(loader(generator)).defaultValue("")
.compile(template).execute(data);
} else {
LOGGER.info("copying file to {}", outputFile.getAbsolutePath());
}
};

FileUtils.writeStringToFile(outputFile, formatted, StandardCharsets.UTF_8);

} catch (IOException e) {
throw new RuntimeException("Can't generate project", e);
}
}

/**
Expand Down
48 changes: 8 additions & 40 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,50 +62,10 @@
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<!-- Uncomment this to format before checkstyle -->
<!-- <executions>
<execution>
<id>format</id>
<phase>validate</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions> -->
<configuration>
<lineEnding>LF</lineEnding>
</configuration>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>google_checkstyle.xml</configLocation>
Don't include generated sources a la http://stackoverflow.com/a/30406454
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.19</version>
</dependency>
</dependencies>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -178,6 +138,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin-version}</version>
<configuration>
<!-- Resources (mainly templates) already ship in the main jar; keep only Java sources -->
<excludeResources>true</excludeResources>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
Expand Down Expand Up @@ -218,6 +182,10 @@
<autoPublish>true</autoPublish>
<waitUntil>published</waitUntil>
<waitMaxTime>3600</waitMaxTime>
<excludeArtifacts>
<!-- The WAR is only consumed by the swagger-generator Docker images, which are built from target/ -->
<excludeArtifact>swagger-generator</excludeArtifact>
</excludeArtifacts>
</configuration>
</plugin>
</plugins>
Expand Down
Loading