Skip to content
Open
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
7 changes: 7 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.classpath
.project
.settings
target
bin
src/test/java/org/jboss/shrinkwrap/descriptor/api
src/test/java/org/jboss/shrinkwrap/descriptor/impl
604 changes: 604 additions & 0 deletions cli/log.txt

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>1.2.0-alpha-2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<artifactId>shrinkwrap-descriptors-cli</artifactId>
<name>ShrinkWrap Descriptors CLI</name>
<description>Command Line Interface for generating the ShrinkWrap Descriptors</description>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>

<!-- builds 1 jar including all dependencies. Enter mvn assembly:assembly -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.jboss.shrinkwrap.descriptor.cli.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<!-- Executes the ironjacamar descriptor code generation as part of the test phase.
The ironjacamar classes are generated in target/ironjacamar. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.jboss.shrinkwrap.descriptor.cli.Main</mainClass>
<arguments>
<argument>-c</argument>
<argument>src/test/resources/ironjacamar.properties</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

<!-- Adds additional sorce and test folders.
This is required for testing what we know is used by others but it is not included in our jars.
An example will be ironjacamar, they want to use the generated classes but not via descriptor jars. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/ironjacamar/src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>target/ironjacamar/src/test/java</source>
</sources>
</configuration>
</execution>

</executions>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Run in Java5; be build with a JDK6 compiler so ensure we don't
use any JDK6 libs -->
<jvm>${env.JAVA5_HOME}/bin/java</jvm>
<!-- Speeeeeeed -->
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
</build>


<dependencies>

<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-api-base</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-impl-base</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-impl-base</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-gen</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>uk.co.flamingpenguin.jewelcli</groupId>
<artifactId>jewelcli</artifactId>
<version>0.6</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jboss.shrinkwrap.descriptor.cli;

import uk.co.flamingpenguin.jewel.cli.CommandLineInterface;
import uk.co.flamingpenguin.jewel.cli.Option;

@CommandLineInterface(application="sdcli")
public interface CommandLineOptions
{
@Option(shortName="c", description="Path to the configuration file")
public String getConfiguration();

@Option(shortName="t", description="Logs the stack trace in case of an exception")
public String getTrace();

public boolean isTrace();
}
89 changes: 89 additions & 0 deletions cli/src/main/java/org/jboss/shrinkwrap/descriptor/cli/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.jboss.shrinkwrap.descriptor.cli;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import uk.co.flamingpenguin.jewel.cli.ArgumentValidationException;
import uk.co.flamingpenguin.jewel.cli.Cli;
import uk.co.flamingpenguin.jewel.cli.CliFactory;

public class Main
{
private final static Log log = LogFactory.getLog(Main.class);

public static void main(String[] args)
{
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");

try
{
PropertyHandler properties = getConfiguration(args);

if (properties != null)
{
WorkingDirHandler workingDirHandler = new WorkingDirHandler(properties);

// initialize the map which will overwrite global parameters defined in metadata.xsl
Map<String, String> xsltParameters = new HashMap<String, String>();
xsltParameters.put("gOutputFolder", properties.getResultDirImpl(workingDirHandler.getWorkingDir() + "/src/main/java"));
xsltParameters.put("gOutputFolderApi", properties.getResultDirApi(workingDirHandler.getWorkingDir() + "/src/main/java"));
xsltParameters.put("gOutputFolderTest", properties.getResultDirTest(workingDirHandler.getWorkingDir() + "/src/test/java"));

// transform context xml to metadata.xml
XsltTransformer.simpleTransform(properties.getPathToContextXml(),
workingDirHandler.getPathToMetaDataXml(),
workingDirHandler.getWorkingDir() + "/metadata.xml",
xsltParameters);

// generate java classes based on metadata.xml
XsltTransformer.simpleTransform(workingDirHandler.getWorkingDir() + "/metadata.xml",
workingDirHandler.getPathToDDJavaXml(),
workingDirHandler.getWorkingDir() + "/ddJava.xml",
xsltParameters);
}
}
catch(Exception ex)
{
log.error(ex.getMessage(), ex);
}
}

/**
* Returns a <code>PropertyHandler</code> based on the path specified on the command line.
* @param args
* @return
*/
private static PropertyHandler getConfiguration(final String[] args)
{
PropertyHandler propertyHandler = null;
boolean isTrace = false;

try
{
CommandLineOptions options = CliFactory.parseArguments(CommandLineOptions.class, args);
isTrace = options.isTrace();
propertyHandler = new PropertyHandler(options.getConfiguration());
}
catch (ArgumentValidationException ex)
{
final Cli<CommandLineOptions> cli = CliFactory.createCli(CommandLineOptions.class);
log.error(ex.getMessage());
log.info(cli.getHelpMessage());
}
catch (Exception ex)
{
final Cli<CommandLineOptions> cli = CliFactory.createCli(CommandLineOptions.class);
log.error(ex.getMessage());
log.info(cli.getHelpMessage());
if (isTrace) {
log.error("Trace:\n" + ex.getMessage(), ex);
}
}

return propertyHandler;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.jboss.shrinkwrap.descriptor.cli;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
* Class which allows the load and retrieve application specific properties.
* @author bfr
*
*/
public class PropertyHandler
{
public static final String CLI_PROP_WORKING_DIR = "descriptor.cli.working.dir";
public static final String CLI_PROP_RESULT_DIR_API = "descriptor.cli.result.dir.api";
public static final String CLI_PROP_RESULT_DIR_IMPL = "descriptor.cli.result.dir.impl";
public static final String CLI_PROP_RESULT_DIR_TEST = "descriptor.cli.result.dir.test";
public static final String CLI_PROP_PATH_CONTEXT_XML = "descriptor.cli.path.context.xml";
public static final String CLI_PROP_PATH_EX_METADATA_XML = "descriptor.cli.path.ext.metadata.xml";
public static final String CLI_PROP_PATH_EX_DDJAVA_XML = "descriptor.cli.path.ext.ddjava.xml";

private final Properties prop = new Properties();

/**
* Creates a new instance of the class.
* @param pathToPropertiesFile - path to a readable properties file.
* @throws FileNotFoundException - thrown, if the file doesn't exist.
* @throws IOException - thrown, if an IO error occurs.
*/
public PropertyHandler(final String pathToPropertiesFile) throws FileNotFoundException, IOException
{
prop.load(new FileInputStream(pathToPropertiesFile));
checkMandatoryProperties();
}

public String getWorkingDir(final String defaultDir)
{
return prop.getProperty(CLI_PROP_WORKING_DIR, defaultDir);
}

public String getResultDirApi(final String defaultDir)
{
return prop.getProperty(CLI_PROP_RESULT_DIR_API, defaultDir);
}

public String getResultDirImpl(final String defaultDir)
{
return prop.getProperty(CLI_PROP_RESULT_DIR_IMPL, defaultDir);
}

public String getResultDirTest(final String defaultDir)
{
return prop.getProperty(CLI_PROP_RESULT_DIR_TEST, defaultDir);
}

public String getPathToExternalMetadataXml(final String defaultFile)
{
return prop.getProperty(CLI_PROP_PATH_EX_METADATA_XML, defaultFile);
}

public String getPathToExternalDDJavaXml(final String defaultFile)
{
return prop.getProperty(CLI_PROP_PATH_EX_DDJAVA_XML, defaultFile);
}

public String getPathToContextXml()
{
return prop.getProperty(CLI_PROP_PATH_CONTEXT_XML);
}

//------------------------------------------------------------------------------------------------------------------||
//--- Private Methods ----------------------------------------------------------------------------------------------||
//------------------------------------------------------------------------------------------------------------------||

private void checkMandatoryProperties()
{
if (getPathToContextXml() == null)
{
throw new RuntimeException("Context XML file not specified in configuration file!");
}
}

}
Loading