issue #2878 add an aggregated javadoc jar excluding some tests packages

+ force attach and use default phase bind (package)
+ fixing some dependencies to build aggregate javadoc jar
+ configure release plugin to build aggregated javadoc jar
+ test javadoc build with jdk11 including aggregated javadoc
+ Fixing bad javadoc
+ Excluding tests from aggregate-javadoc
+ Cannot aggregate-javadoc on CI (requires clean build of snapshot to work)
+ standardizing javadoc config

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
olivier lamy 2019-02-04 12:25:46 +10:00 committed by Joakim Erdfelt
parent 0e7a2738d5
commit aec2ebd27d
5 changed files with 211 additions and 47 deletions

2
Jenkinsfile vendored
View File

@ -54,7 +54,7 @@ pipeline {
agent { node { label 'linux' } }
options { timeout(time: 30, unit: 'MINUTES') }
steps {
mavenBuild("jdk8", "install javadoc:javadoc -DskipTests", "maven3", true)
mavenBuild("jdk11", "install javadoc:javadoc -DskipTests", "maven3", true)
warnings consoleParsers: [[parserName: 'Maven'], [parserName: 'JavaDoc'], [parserName: 'Java']]
}
}

View File

@ -94,12 +94,6 @@
<artifactId>jetty-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>

View File

@ -18,9 +18,18 @@
package org.eclipse.jetty.http.jmh;
import org.eclipse.jetty.http.MultiPartCaptureTest.MultipartExpectations;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.eclipse.jetty.http.MultiPartFormInputStream;
import org.eclipse.jetty.toolchain.test.Hex;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.hamcrest.Matchers;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
@ -40,16 +49,25 @@ import org.openjdk.jmh.runner.options.OptionsBuilder;
import javax.servlet.MultipartConfigElement;
import javax.servlet.http.Part;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
@State(Scope.Benchmark)
@Threads(4)
@ -277,6 +295,191 @@ public class MultiPartBenchmark
new Runner(opt).run();
}
public static class MultipartExpectations
{
public final String contentType;
public final int partCount;
public final List<NameValue> partFilenames = new ArrayList<>();
public final List<NameValue> partSha1sums = new ArrayList<>();
public final List<NameValue> partContainsContents = new ArrayList<>();
public MultipartExpectations(Path expectationsPath) throws IOException
{
String parsedContentType = null;
String parsedPartCount = "-1";
try (BufferedReader reader = Files.newBufferedReader(expectationsPath))
{
String line;
while ((line = reader.readLine()) != null)
{
line = line.trim();
if (StringUtil.isBlank(line) || line.startsWith("#"))
{
// skip blanks and comments
continue;
}
String split[] = line.split("\\|");
switch (split[0])
{
case "Request-Header":
if(split[1].equalsIgnoreCase("Content-Type"))
{
parsedContentType = split[2];
}
break;
case "Content-Type":
parsedContentType = split[1];
break;
case "Parts-Count":
parsedPartCount = split[1];
break;
case "Part-ContainsContents":
{
NameValue pair = new NameValue();
pair.name = split[1];
pair.value = split[2];
partContainsContents.add(pair);
break;
}
case "Part-Filename":
{
NameValue pair = new NameValue();
pair.name = split[1];
pair.value = split[2];
partFilenames.add(pair);
break;
}
case "Part-Sha1sum":
{
NameValue pair = new NameValue();
pair.name = split[1];
pair.value = split[2];
partSha1sums.add(pair);
break;
}
default:
throw new IOException("Bad Line in " + expectationsPath + ": " + line);
}
}
}
Objects.requireNonNull(parsedContentType, "Missing required 'Content-Type' declaration: " + expectationsPath);
this.contentType = parsedContentType;
this.partCount = Integer.parseInt(parsedPartCount);
}
private void checkParts(Collection<Part> parts, Function<String, Part> getPart) throws Exception
{
// Evaluate Count
if (partCount >= 0)
{
assertThat("Mulitpart.parts.size", parts.size(), is(partCount));
}
String defaultCharset = UTF_8.toString();
Part charSetPart = getPart.apply("_charset_");
if(charSetPart != null)
{
defaultCharset = org.eclipse.jetty.util.IO.toString(charSetPart.getInputStream());
}
// Evaluate expected Contents
for (NameValue expected : partContainsContents)
{
Part part = getPart.apply(expected.name);
assertThat("Part[" + expected.name + "]", part, is(notNullValue()));
try (InputStream partInputStream = part.getInputStream())
{
String charset = getCharsetFromContentType(part.getContentType(), defaultCharset);
String contents = org.eclipse.jetty.util.IO.toString(partInputStream, charset);
assertThat("Part[" + expected.name + "].contents", contents, containsString(expected.value));
}
}
// Evaluate expected filenames
for (NameValue expected : partFilenames)
{
Part part = getPart.apply(expected.name);
assertThat("Part[" + expected.name + "]", part, is(notNullValue()));
assertThat("Part[" + expected.name + "]", part.getSubmittedFileName(), is(expected.value));
}
// Evaluate expected contents checksums
for (NameValue expected : partSha1sums)
{
Part part = getPart.apply(expected.name);
assertThat("Part[" + expected.name + "]", part, is(notNullValue()));
MessageDigest digest = MessageDigest.getInstance("SHA1");
try (InputStream partInputStream = part.getInputStream();
NoOpOutputStream noop = new NoOpOutputStream();
DigestOutputStream digester = new DigestOutputStream(noop, digest))
{
org.eclipse.jetty.util.IO.copy(partInputStream, digester);
String actualSha1sum = Hex.asHex(digest.digest()).toLowerCase(Locale.US);
assertThat("Part[" + expected.name + "].sha1sum", actualSha1sum, Matchers.equalToIgnoringCase(expected.value));
}
}
}
private String getCharsetFromContentType(String contentType, String defaultCharset)
{
if(StringUtil.isBlank(contentType))
{
return defaultCharset;
}
QuotedStringTokenizer tok = new QuotedStringTokenizer(contentType, ";", false, false);
while(tok.hasMoreTokens())
{
String str = tok.nextToken().trim();
if(str.startsWith("charset="))
{
return str.substring("charset=".length());
}
}
return defaultCharset;
}
}
static class NoOpOutputStream extends OutputStream
{
@Override
public void write(byte[] b) throws IOException
{
}
@Override
public void write(byte[] b, int off, int len) throws IOException
{
}
@Override
public void flush() throws IOException
{
}
@Override
public void close() throws IOException
{
}
@Override
public void write(int b) throws IOException
{
}
}
public static class NameValue
{
public String name;
public String value;
}
}

43
pom.xml
View File

@ -280,8 +280,8 @@
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<goals>deploy</goals>
<arguments>-Peclipse-release</arguments>
<goals>javadoc:aggregate-jar deploy</goals>
<arguments>-Peclipse-release -Paggregate-javadoc-jar</arguments>
<preparationGoals>clean install</preparationGoals>
<mavenExecutorId>forked-path</mavenExecutorId>
</configuration>
@ -537,10 +537,8 @@
<detectLinks>false</detectLinks>
<detectJavaApiLink>false</detectJavaApiLink>
<show>protected</show>
<excludePackageNames>com.acme.*;org.slf4j.*;org.mortbay.*</excludePackageNames>
<links>
<link>https://docs.oracle.com/javase/8/docs/api/</link>
</links>
<attach>true</attach>
<excludePackageNames>com.acme,org.slf4j*,org.mortbay*,*.jmh*,org.eclipse.jetty.embedded*,org.eclipse.jetty.example.asyncrest*,org.eclipse.jetty.test*</excludePackageNames>
</configuration>
</plugin>
<plugin>
@ -1222,6 +1220,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
@ -1282,38 +1281,6 @@
</plugins>
</build>
</profile>
<!--
Usage:
Javadoc aggregation for Jetty website
> mvn clean install -Dtest=foo
> mvn -Paggregate-site javadoc:aggregate -Dtest=foo
-->
<profile>
<id>aggregate-site</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>com.acme,*.jmh</excludePackageNames>
<links>
<link>http://docs.oracle.com/javase/8/docs/api/</link>
<link>http://docs.oracle.com/javaee/7/api</link>
<link>http://junit.sourceforge.net/javadoc/</link>
</links>
<tags>
<tag>
<name>org.apache.xbean.XBean</name>
<placement>X</placement>
<head />
</tag>
</tags>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>compact3</id>
<modules>

View File

@ -185,7 +185,7 @@ public class DistributionTester
/**
* Resolves an artifact given its Maven coordinates.
*
* @param coordinates <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
* @param coordinates &lt;groupId>:&lt;artifactId>[:&lt;extension>[:&lt;classifier>]]:&lt;version>
* @return the artifact
* @see #installWarFile(File, String)
*/