Skip to content

Commit

Permalink
Merge branch 'master' into ENUNCIATE-660
Browse files Browse the repository at this point in the history
  • Loading branch information
stoicflame committed Aug 3, 2012
2 parents d39731f + 75fff18 commit 14a7508
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 15 deletions.
@@ -0,0 +1,23 @@
package org.codehaus.enunciate.jaxrs;

/**
* Documents an expected response header for a resource or resource method.
*
* @author Ryan Heaton
*/
public @interface ResponseHeader {

/**
* The name of the response header.
*
* @return The name of the response header.
*/
String name();

/**
* The description of the response header.
*
* @return The description of the response header.
*/
String description();
}
@@ -0,0 +1,19 @@
package org.codehaus.enunciate.jaxrs;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Documents expected response headers for a resource or resource method.
*
* @author Ryan Heaton
*/
@Retention ( RetentionPolicy.RUNTIME )
@Target ({ ElementType.TYPE, ElementType.METHOD })
public @interface ResponseHeaders {

ResponseHeader[] value();

}
Expand Up @@ -25,9 +25,7 @@
import net.sf.jelly.apt.decorations.type.DecoratedClassType;
import net.sf.jelly.apt.decorations.type.DecoratedTypeMirror;
import org.codehaus.enunciate.contract.validation.ValidationException;
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.codehaus.enunciate.jaxrs.TypeHint;
import org.codehaus.enunciate.jaxrs.Warnings;
import org.codehaus.enunciate.jaxrs.*;
import org.codehaus.enunciate.rest.MimeType;

import javax.ws.rs.*;
Expand Down Expand Up @@ -56,6 +54,7 @@ public class ResourceMethod extends DecoratedMethodDeclaration {
private final Map<String, Object> metaData = new HashMap<String, Object>();
private final List<? extends ResponseCode> statusCodes;
private final List<? extends ResponseCode> warnings;
private final Map<String, String> responseHeaders = new HashMap<String, String>();
private final ResourceRepresentationMetadata representationMetadata;

public ResourceMethod(MethodDeclaration delegate, Resource parent) {
Expand Down Expand Up @@ -224,6 +223,20 @@ else if (parameterDeclaration.getAnnotation(Context.class) == null) {
}
}

ResponseHeaders responseHeaders = parent.getAnnotation(ResponseHeaders.class);
if (responseHeaders != null) {
for (ResponseHeader header : responseHeaders.value()) {
this.responseHeaders.put(header.name(), header.description());
}
}

responseHeaders = getAnnotation(ResponseHeaders.class);
if (responseHeaders != null) {
for (ResponseHeader header : responseHeaders.value()) {
this.responseHeaders.put(header.name(), header.description());
}
}

this.entityParameter = entityParameter;
this.resourceParameters = resourceParameters;
this.subpath = subpath;
Expand Down Expand Up @@ -582,4 +595,12 @@ public void putMetaData(String name, Object data) {
this.metaData.put(name, data);
}

/**
* The response headers that are expected on this resource method.
*
* @return The response headers that are expected on this resource method.
*/
public Map<String, String> getResponseHeaders() {
return responseHeaders;
}
}
11 changes: 11 additions & 0 deletions core/src/main/java/org/codehaus/enunciate/main/Enunciate.java
Expand Up @@ -97,6 +97,7 @@ public enum Target {
private final Set<File> additionalSourceRoots = new TreeSet<File>();
private final Set<WebAppFragment> webAppFragments = new TreeSet<WebAppFragment>(new WebAppFragmentComparator());
private final List<ClasspathHandler> classpathHandlers = new ArrayList<ClasspathHandler>();
private final List<String> configuredJavacArguments = new ArrayList<String>();

public static void main(String[] args) throws Exception {
Main.main(args);
Expand Down Expand Up @@ -857,6 +858,7 @@ public void invokeJavac(String classpath, String version, File compileDir, List<
args.add("-d");
args.add(compileDir.getAbsolutePath());
args.addAll(additionalArgs);
args.addAll(this.configuredJavacArguments);
args.addAll(Arrays.asList(sourceFiles));

if (isDebug()) {
Expand Down Expand Up @@ -1644,6 +1646,15 @@ public boolean isModuleEnabled(String moduleName) {
return false;
}

/**
* Configured arguments to pass to the Enunciate java compiler.
*
* @return Configured arguments to pass to the Enunciate java compiler.
*/
public List<String> getConfiguredJavacArguments() {
return configuredJavacArguments;
}

/**
* Set the configuration for the mechanism.
*
Expand Down
46 changes: 44 additions & 2 deletions core/src/main/java/org/codehaus/enunciate/main/EnunciateTask.java
Expand Up @@ -59,6 +59,7 @@ public class EnunciateTask extends MatchingTask {
private File flexHome;
private Enunciate.Target target;
private final ArrayList<Export> exports = new ArrayList<Export>();
private final ArrayList<JavacArgument> javacArguments = new ArrayList<JavacArgument>();

/**
* Executes the enunciate task.
Expand Down Expand Up @@ -355,6 +356,17 @@ public Export createExport() {
return export;
}

/**
* Creates a nested javac argument.
*
* @return the nested javac argument.
*/
public JavacArgument createJavacArgument() {
JavacArgument export = new JavacArgument();
this.javacArguments.add(export);
return export;
}

/**
* A nested export task.
*/
Expand Down Expand Up @@ -400,6 +412,32 @@ public void setDestination(File destination) {
}
}

/**
* A nested javac argument task.
*/
public static class JavacArgument {

private String argument;

/**
* The argument.
*
* @return The argument
*/
public String getArgument() {
return argument;
}

/**
* The argument.
*
* @param argument The javac argument.
*/
public void setArgument(String argument) {
this.argument = argument;
}
}

/**
* An Enunciate mechanism that leverages Ant's logging capabilities, too.
*/
Expand All @@ -411,12 +449,16 @@ public AntLoggingEnunciate(String[] sourceFiles) {

@Override
public void debug(String message, Object... formatArgs) {
getProject().log(String.format(message, formatArgs), Project.MSG_VERBOSE);
if (debug) {
getProject().log(String.format(message, formatArgs), Project.MSG_VERBOSE);
}
}

@Override
public void info(String message, Object... formatArgs) {
getProject().log(String.format(message, formatArgs), Project.MSG_INFO);
if (verbose) {
getProject().log(String.format(message, formatArgs), Project.MSG_INFO);
}
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/codehaus/enunciate/main/Main.java
Expand Up @@ -100,6 +100,7 @@ public enum Option {
debug("vv", "Print debug-level output to the console."),
disableDebugInfo("xg", "Disable compilation with debug info."),
javacCheck("Xc", "Do a javac check before invoking Enunciate."),
javacArguments("Xa", "argument", "Extra arguments to pass to javac. May be repeated."),
configFile("f", "file", "The enunciate xml config file."),
generateDir("g", "dir", "The output directory for the \"generate\" step."),
compileDir("c", "dir", "The output directory for the \"compile\" step."),
Expand Down Expand Up @@ -295,6 +296,10 @@ public boolean handle(String option, String value, Enunciate enunciate) {
enunciate.addExport(option.substring(1), new File(value));
return true;

case javacArguments:
enunciate.getConfiguredJavacArguments().add(value);
return true;

default:
return false;
}
Expand Down
Expand Up @@ -775,7 +775,7 @@
[/#list]
[#list operation.warning as warning]
[#if warning_index = 0]
<h3>Possible Warnings</h3>
<h3>Warnings</h3>
<table>
<tr>
<th>code</th>
Expand All @@ -790,6 +790,23 @@
</table>
[/#if]
[/#list]
[#list operation.responseHeader as responseHeader]
[#if responseHeader_index = 0]
<h3>Response Headers</h3>
<table>
<tr>
<th>name</th>
<th>description</th>
</tr>
[/#if]
<tr>
<td>${responseHeader.name}</td>
<td>${responseHeader.documentation}</td>
</tr>
[#if !responseHeader_has_next]
</table>
[/#if]
[/#list]
[/#list]
[/#macro]
[#macro processEndpointInterface endpointInterface]
Expand Down
Expand Up @@ -385,6 +385,12 @@
<![CDATA[${warning.condition!""}]]>
</warning>
[/#list]
[#list resource.responseHeaders?keys as responseHeader]
<responseHeader>
<name>${responseHeader}</name>
<documentation><![CDATA[${(resource.responseHeaders[responseHeader])!""}]]></documentation>
</responseHeader>
[/#list]
</operation>
[#--[/#if]--]
[/#if]
Expand Down
Expand Up @@ -635,6 +635,7 @@
<xs:element name="outValue" type="entity" minOccurs="0" maxOccurs="1"/>
<xs:element name="statusCode" type="restStatusCode" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="warning" type="restStatusCode" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="responseHeader" type="responseHeader" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="type" type="restOp"/>
Expand All @@ -643,6 +644,13 @@
</xs:complexContent>
</xs:complexType>

<xs:complexType name="responseHeader">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="documentation" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="restOp">
<xs:restriction base="xs:string">
<xs:enumeration value="create"/>
Expand Down
10 changes: 9 additions & 1 deletion documentation/executables.html
Expand Up @@ -259,6 +259,11 @@ <h2>Configuration</h2>
<td>boolean</td>
<td class="last">Whether to compile with debug information.</td>
</tr>
<tr>
<td>javacArguments</td>
<td>array</td>
<td class="last">List of additional arguments passed to Enunciate's Java compiler when compiling client-side code.</td>
</tr>
</table>

<h2>Example</h2>
Expand Down Expand Up @@ -418,11 +423,13 @@ <h2>Enunciate Task Attributes</h2>
<h2>Nested Elements</h2>

<p>In addition to the nested elements of a <a href="http://ant.apache.org/manual/api/org/apache/tools/ant/taskdefs/MatchingTask.html">MatchingTask</a>
that are used to select the source files on which to invoke Enunciate, the EnunciateTask supports two additional nested elements.</p>
that are used to select the source files on which to invoke Enunciate, the EnunciateTask supports additional nested elements.</p>

<ul>
<li>The <b>classpath</b> element is a <a href="http://ant.apache.org/manual/using.html#path">path-like structure</a> used to specify the
Enunciate classpath for execution.</li>
<li>The <b>javacArgument</b> element is used to configure extra argument(s) to apply when Enunciate compiles client-side artifacts. It supports an "argument"
attribute to pass in the value of the argument.</li>
<li>The <b>export</b> element is used to specify an export. Here are its attributes:</li>
</ul>

Expand Down Expand Up @@ -470,6 +477,7 @@ <h2>Example</h2>
&lt;include name="**/*.java"/&gt;
&lt;classpath refid="enunciate.classpath"/&gt;
&lt;export artifactId="war.file" destination="${tomcat.home}/webapps/myapp.war"/&gt;
&lt;javacArgument argument="-g"/&gt;
&lt;/enunciate&gt;

...
Expand Down
Expand Up @@ -18,7 +18,7 @@ import org.codehaus.enunciate.modules.gwt.*;
* @author Ryan Heaton
*/
@java.lang.SuppressWarnings( {"all"} )
public [#if type.abstract]abstract [/#if][#if type.final]final [/#if]class ${type.simpleName}GWTMapper [#if baseobject]extends BaseGWTMapper [#else]extends ${type.superclass.declaration.package.qualifiedName + ".gwt." + type.superclass.declaration.simpleName}GWTMapper [/#if]implements GWTMapper {
public [#if type.abstract]abstract [/#if][#if type.final]final [/#if]class ${type.simpleName}GWTMapper [#if baseobject]extends BaseGWTMapper [#else]extends ${type.superclass.declaration.package.qualifiedName + ".gwt." + type.superclass.declaration.simpleName}GWTMapper [/#if] {

public ${type.simpleName}GWTMapper() {
super(${type.qualifiedName}.class, ${classname}.class[#list type.attributes as attribute], "${attribute.simpleName}"[/#list][#if type.value?exists], "${type.value.simpleName}"[#else][#list type.elements as element], "${element.simpleName}"[/#list][/#if]);
Expand Down
Expand Up @@ -18,9 +18,7 @@

import com.sun.jersey.multipart.FormDataParam;
import org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.codehaus.enunciate.jaxrs.Warnings;
import org.codehaus.enunciate.jaxrs.*;
import org.codehaus.enunciate.samples.genealogy.data.Person;
import org.codehaus.enunciate.samples.genealogy.data.PersonExt;
import org.codehaus.enunciate.samples.genealogy.data.RootElementMapWrapper;
Expand Down Expand Up @@ -57,6 +55,9 @@ public interface PersonService {
)
@PUT
@Path ("/pedigree/person")
@ResponseHeaders (
@ResponseHeader( name = "Location", description = "The location of the person stored.")
)
Person storePerson(Person person);

@GET
Expand Down
Expand Up @@ -74,10 +74,10 @@
*
* <h3>Content Negotiation</h3>
*
* <p>Enuncite provides content type negotiation (conneg) to Jersey that conforms to the <a href="module_rest.html#contentTypes">content type negotiation of
* the Enunciate REST module</a>. This means that each resource is mounted from the REST subcontext (see above) but ALSO from a subcontext that conforms to the
* id of each content type that the resource supports. So, if the content type id of the "application/xml" content type is "xml" then the resource at path
* "mypath" will be mounted at both "/rest/mypath" and "/xml/mypath".</p>
* <p>Enuncite provides a special content negotiation (conneg) to Jersey such that that each resource is mounted from the REST subcontext (see above) but
* ALSO from a subcontext that conforms to the id of each content type that the resource supports. So, if the content type id of the "application/xml"
* content type is "xml" then the resource at path "mypath" will be mounted at both "/rest/mypath" and "/xml/mypath". You can disable this path-based content
* negotiation feature by setting <tt>usePathBasedConneg="false"</tt>.</p>
*
* <p>The content types for each JAX-RS resource are declared by the @Produces annotation. The content type ids are customized with the
* "enunciate/services/rest/content-types" element in the Enunciate configuration. Enunciate supplies providers for the "application/xml" and "application/json"
Expand Down
Expand Up @@ -172,6 +172,13 @@ public class ConfigMojo extends AbstractMojo {
*/
private String[] excludeProjectExtensions;

/**
* List of extra arguments to Enunciate's javac.
*
* @parameter
*/
private String[] javacArguments;

/**
* Whether to include reference trail information in validation errors.
*
Expand Down Expand Up @@ -595,6 +602,9 @@ public MavenSpecificEnunciate(Collection<File> rootDirs) {

setSourceFiles(sources.toArray(new String[sources.size()]));
setEncoding(compilationEncoding);
if (javacArguments != null) {
getConfiguredJavacArguments().addAll(Arrays.asList(javacArguments));
}
}

public void loadMavenConfiguration() throws IOException {
Expand Down

0 comments on commit 14a7508

Please sign in to comment.