Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #166 from vania-pooh/master
Browse files Browse the repository at this point in the history
Added allure-cli module with Allure Command Line client implementation
  • Loading branch information
just-boris committed Mar 4, 2014
2 parents c9b663f + 8d0366e commit 7cca62c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 0 deletions.
File renamed without changes.
118 changes: 118 additions & 0 deletions allure-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-core</artifactId>
<version>1.3.3-SNAPSHOT</version>
</parent>
<artifactId>allure-cli</artifactId>
<packaging>jar</packaging>

<name>Allure Command Line Client</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>unpack</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-report-face</artifactId>
<version>${version}</version>
<overWrite>true</overWrite>
<outputDirectory>
${project.build.outputDirectory}/allure-report-face
</outputDirectory>
<type>war</type>
<excludes>**\/*.jar,**/META-INF/**,**/WEB-INF/**</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>ru.yandex.qatools.allure.AllureCli</mainClass>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>airline</artifactId>
<version>0.6</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-report-data</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
97 changes: 97 additions & 0 deletions allure-cli/src/main/java/ru/yandex/qatools/allure/AllureCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package ru.yandex.qatools.allure;

import io.airlift.command.*;
import io.airlift.command.Cli.CliBuilder;
import ru.yandex.qatools.allure.data.AllureReportGenerator;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarFile;
import java.util.Enumeration;
import java.util.jar.JarEntry;

public class AllureCli {

private static final String DEFAULT_OUTPUT_PATH = "output";
private static final String REPORT_FACE_DIRECTORY = "allure-report-face";

public static void main(String[] args) {

final CliBuilder<Runnable> builder = Cli.<Runnable>builder("allure")
.withDescription("Allure command line client")
.withDefaultCommand(Help.class)
.withCommands(Help.class, GenerateCommand.class);

final Cli<Runnable> parser = builder.build();

parser.parse(args).run();

}

@Command(name = "generate", description = "Generate HTML report from XML files")
public static class GenerateCommand implements Runnable {

@Option(type = OptionType.COMMAND, name = {"-o", "--outputPath"}, description = "Directory to output report files to (default is \"" + DEFAULT_OUTPUT_PATH + "\")")
public String outputPath = DEFAULT_OUTPUT_PATH;

@Arguments(title = "inputPaths", description = "A list of input directories to be processed")
public List<String> inputPaths;

public void run() {

try {
final File outputDirectory = new File(outputPath);
if (!outputDirectory.exists()) {
outputDirectory.mkdir();
}
final List<File> inputDirectories = new ArrayList<>();
for (final String inputDirectory : inputPaths) {
inputDirectories.add(new File(inputDirectory));
}
final AllureReportGenerator generator = new AllureReportGenerator(inputDirectories.toArray(new File[inputDirectories.size()]));
generator.generate(outputDirectory);
final String reportFaceWildcard = REPORT_FACE_DIRECTORY + File.separator + ".*";
copyStaticReportData(getCurrentJarFilePath(), outputDirectory, reportFaceWildcard);
System.out.println("Successfully generated report to " + outputDirectory.getAbsolutePath() + ".");
} catch (Exception e) {
throw new RuntimeException(e);
}

}

private static void copyStaticReportData(final File currentJarFile, final File outputDirectory, final String wildcard) throws IOException {
final JarFile jar = new java.util.jar.JarFile(currentJarFile);
final Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
final JarEntry file = (java.util.jar.JarEntry) entries.nextElement();
if (file.getName().matches(wildcard)) {
final String newFileName = file.getName().replace(REPORT_FACE_DIRECTORY + File.separator, "");
if (newFileName.length() > 0) {
final String newFilePath = outputDirectory + File.separator + newFileName;
final File f = new File(newFilePath);
if (file.isDirectory() && !f.exists()) {
f.mkdir();
continue;
}
final InputStream inputStream = jar.getInputStream(file);
final FileOutputStream fileOutputStream = new FileOutputStream(f);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
}
fileOutputStream.close();
inputStream.close();
}
}
}
}

private static File getCurrentJarFilePath() {
return new File(AllureCli.class.getProtectionDomain().getCodeSource().getLocation().getPath());
}
}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<module>allure-testng</module>
<module>allure-report</module>
<module>allure-e2e</module>
<module>allure-cli</module>
</modules>

<organization>
Expand Down

0 comments on commit 7cca62c

Please sign in to comment.