Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed May 30, 2022
2 parents 98cb55e + fedabff commit f892d46
Show file tree
Hide file tree
Showing 20 changed files with 384 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Contributors to the Eclipse Foundation
# Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -42,4 +42,4 @@ jobs:
- name: Verify
run: |
cd api
mvn -B -U -C -V clean verify org.glassfish.copyright:glassfish-copyright-maven-plugin:check -Poss-release,staging -Dgpg.skip=true
mvn -B -U -C -V clean verify org.glassfish.copyright:glassfish-copyright-maven-plugin:check -Poss-release,staging -Dcopyright.ignoreyear=true -Dgpg.skip=true
14 changes: 10 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
- "james.local"
containers:
- name: mail-ci
image: jakartaee/cts-javamail-base:0.1
image: jakartaee/cts-javamail-base:0.3
command:
- cat
tty: true
Expand Down Expand Up @@ -49,11 +49,17 @@ spec:
}
parameters {
string(name: 'JAF_BUNDLE_URL',
defaultValue: 'https://repo1.maven.org/maven2/com/sun/activation/jakarta.activation/2.0.0-RC3/jakarta.activation-2.0.0-RC3.jar',
defaultValue: 'https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api/2.1.0/jakarta.activation-api-2.1.0.jar',
description: 'URL required for downloading JAF API jar' )
string(name: 'ANGUS_JAF_BUNDLE_URL',
defaultValue: 'https://repo1.maven.org/maven2/org/eclipse/angus/angus-activation/1.0.0/angus-activation-1.0.0.jar',
description: 'URL required for downloading JAF implementation jar' )
string(name: 'MAIL_TCK_BUNDLE_URL',
defaultValue: 'https://ci.eclipse.org/mail/job/mail-tck/job/2.0.0/lastSuccessfulBuild/artifact/bundles/mail-tck-2.0.0-rc1.zip',
description: 'URL required for downloading Jakarta Mail TCK zip' )
string(name: 'ANGUS_MAIL_BUNDLE_URL',
defaultValue: 'https://repo1.maven.org/maven2/org/eclipse/angus/angus-mail/1.0.0/angus-mail-1.0.0.jar',
description: 'URL required for downloading Angus Mail jar' )
}
environment {
ANT_OPTS = "-Djavax.xml.accessExternalStylesheet=all -Djavax.xml.accessExternalSchema=all -Djavax.xml.accessExternalDTD=file,http"
Expand All @@ -71,8 +77,8 @@ spec:
cd ..
bash -x ${WORKSPACE}/docker/build_jakartamail.sh
"""
archiveArtifacts artifacts: 'mail/target/*.jar'
stash includes: 'mail/target/*.jar', name: 'mail-bundles'
archiveArtifacts artifacts: '**/target/*.jar'
stash includes: '**/target/*.jar', name: 'mail-bundles'
}
}
}
Expand Down
27 changes: 20 additions & 7 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<name>Jakarta Mail API</name>
<description>${project.name} ${spec.version} Specification API</description>

Expand Down Expand Up @@ -78,15 +78,20 @@
<spotbugs.threshold>Low</spotbugs.threshold>
<spotbugs.exclude>${project.basedir}/../spotbugs-exclude.xml</spotbugs.exclude>
<!--Maven plugins version-->
<spotbugs.version>4.3.0</spotbugs.version>
<spotbugs.version>4.4.2.2</spotbugs.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.0-RC1</version>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-activation</artifactId>
<version>1.0.0-M2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -106,6 +111,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-activation</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -143,7 +153,6 @@
<configuration>
<skip>${spotbugs.skip}</skip>
<threshold>${spotbugs.threshold}</threshold>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<excludeFilterFile>${spotbugs.exclude}</excludeFilterFile>
<fork>true</fork>
</configuration>
Expand Down Expand Up @@ -176,7 +185,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -350,6 +359,10 @@
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Implementation-Build-Id>${buildNumber}</Implementation-Build-Id>
<Import-Package>
!org.glassfish.hk2.osgiresourcelocator,
*
</Import-Package>
</instructions>
</configuration>
<executions>
Expand Down Expand Up @@ -379,6 +392,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<release>11</release>
<quiet>true</quiet>
<nodeprecated>false</nodeprecated>
<notimestamp>true</notimestamp>
<nosince>true</nosince>
Expand All @@ -404,8 +418,7 @@ Use is subject to <a href="{@docRoot}/doc-files/speclicense.html" target="_top">
<configuration>
<forkCount>2</forkCount>
<reuseForks>false</reuseForks>
<!-- Test service loader is not loaded if modules are enabled -->
<useModulePath>false</useModulePath>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
Expand Down
9 changes: 9 additions & 0 deletions api/src/main/java/jakarta/mail/BodyPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package jakarta.mail;

import jakarta.mail.util.StreamProvider;

/**
* This class models a Part that is contained within a Multipart.
* This is an abstract class. Subclasses provide actual implementations.<p>
Expand All @@ -36,6 +38,13 @@ public abstract class BodyPart implements Part {
*/
protected Multipart parent;

/**
* Instance of stream provider.
*
* @since JavaMail 2.1
*/
protected final StreamProvider streamProvider = StreamProvider.provider();

/**
* Creates a default {@code BodyPart}.
*/
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/java/jakarta/mail/Multipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.OutputStream;
import java.io.IOException;
import jakarta.activation.DataSource;
import jakarta.mail.util.StreamProvider;

/**
* Multipart is a container that holds multiple body parts. Multipart
Expand Down Expand Up @@ -60,6 +61,13 @@ public abstract class Multipart {
*/
protected Part parent;

/**
* Instance of stream provider.
*
* @since JavaMail 2.1
*/
protected final StreamProvider streamProvider = StreamProvider.provider();

/**
* Default constructor. An empty Multipart object is created.
*/
Expand Down
24 changes: 12 additions & 12 deletions api/src/main/java/jakarta/mail/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -203,8 +202,8 @@ public final class Session {

// Support legacy @DefaultProvider
private static final String DEFAULT_PROVIDER = "com.sun.mail.util.DefaultProvider";
public static final StreamProvider STREAM_PROVIDER;

private final StreamProvider streamProvider;
private final Properties props;
private final Authenticator authenticator;
private final Hashtable<URLName, PasswordAuthentication> authTable
Expand Down Expand Up @@ -246,13 +245,13 @@ public String run() {
// ignore any exceptions
}
confDir = dir;
STREAM_PROVIDER = getStreamProvider();
}

// Constructor is not public
private Session(Properties props, Authenticator authenticator) {
this.props = props;
this.authenticator = authenticator;
this.streamProvider = StreamProvider.provider();

if (Boolean.valueOf(props.getProperty("mail.debug")).booleanValue())
debug = true;
Expand All @@ -272,14 +271,15 @@ private Session(Properties props, Authenticator authenticator) {
q = new EventQueue((Executor)props.get("mail.event.executor"));
}

private static StreamProvider getStreamProvider() {
ServiceLoader<StreamProvider> sl = ServiceLoader.load(StreamProvider.class);
Iterator<StreamProvider> iter = sl.iterator();
if (iter.hasNext()) {
return iter.next();
} else {
throw new IllegalStateException("Not provider of " + StreamProvider.class.getName() + " was found");
}
/**
* Get the stream provider instance of the session.
*
* @return the stream provider
*
* @since JavaMail 2.1
*/
public StreamProvider getStreamProvider() {
return streamProvider;
}

private final synchronized void initLogger() {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public void load(InputStream is) throws IOException {

private void loadProvidersFromStream(InputStream is) throws IOException {
if (is != null) {
LineInputStream lis = Session.STREAM_PROVIDER.inputLineStream(is, false);
LineInputStream lis = streamProvider.inputLineStream(is, false);
String currLine;

// load and process one line at a time using LineInputStream
Expand Down
15 changes: 6 additions & 9 deletions api/src/main/java/jakarta/mail/internet/InternetHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@

package jakarta.mail.internet;

import jakarta.mail.Header;
import jakarta.mail.MessagingException;
import jakarta.mail.Session;
import jakarta.mail.util.LineInputStream;
import jakarta.mail.util.StreamProvider;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import jakarta.mail.Header;
import jakarta.mail.MessagingException;
import jakarta.mail.util.LineInputStream;
import jakarta.mail.util.StreamProvider;



/**
Expand Down Expand Up @@ -407,7 +404,7 @@ public void load(InputStream is, boolean allowutf8)
// Read header lines until a blank line. It is valid
// to have BodyParts with no header lines.
String line;
LineInputStream lis = Session.STREAM_PROVIDER.inputLineStream(is, allowutf8);
LineInputStream lis = StreamProvider.provider().inputLineStream(is, allowutf8);
String prevline = null; // the previous header line, as a string
// a buffer to accumulate the header in, when we know it's needed
StringBuilder lineBuffer = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/jakarta/mail/internet/MimeBodyPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ static void writeTo(MimePart part, OutputStream os, String[] ignoreList, boolean
} else {
Map<String, Object> params = new HashMap<>();
params.put("allowutf8", allowutf8);
los = Session.STREAM_PROVIDER.outputLineStream(os, allowutf8);
los = StreamProvider.provider().outputLineStream(os, allowutf8);
}

// First, write out the header
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/jakarta/mail/internet/MimeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public MimeMessage(MimeMessage source) throws MessagingException {
strict = source.strict;
source.writeTo(bos);
bos.close();
InputStream bis = Session.STREAM_PROVIDER.inputSharedByteArray(bos.toByteArray());
InputStream bis = session.getStreamProvider().inputSharedByteArray(bos.toByteArray());
parse(bis);
bis.close();
saved = true;
Expand Down Expand Up @@ -1425,7 +1425,7 @@ protected InputStream getContentStream() throws MessagingException {
if (contentStream != null)
return ((SharedInputStream)contentStream).newStream(0, -1);
if (content != null) {
return Session.STREAM_PROVIDER.inputSharedByteArray(content);
return session.getStreamProvider().inputSharedByteArray(content);
}
throw new MessagingException("No MimeMessage content");
}
Expand Down Expand Up @@ -1932,7 +1932,7 @@ public void writeTo(OutputStream os, String[] ignoreList)
// Else, the content is untouched, so we can just output it
// First, write out the header
Enumeration<String> hdrLines = getNonMatchingHeaderLines(ignoreList);
LineOutputStream los = Session.STREAM_PROVIDER.outputLineStream(os, allowutf8Headers);
LineOutputStream los = session.getStreamProvider().outputLineStream(os, allowutf8Headers);
while (hdrLines.hasMoreElements())
los.writeln(hdrLines.nextElement());

Expand Down
22 changes: 10 additions & 12 deletions api/src/main/java/jakarta/mail/internet/MimeMultipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

package jakarta.mail.internet;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import jakarta.activation.DataSource;
import jakarta.mail.BodyPart;
import jakarta.mail.IllegalWriteException;
Expand All @@ -25,18 +33,8 @@
import jakarta.mail.Multipart;
import jakarta.mail.MultipartDataSource;
import jakarta.mail.Session;
import jakarta.mail.internet.MimeUtility;
import jakarta.mail.util.LineInputStream;
import jakarta.mail.util.LineOutputStream;
import jakarta.mail.util.StreamProvider;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;



Expand Down Expand Up @@ -524,7 +522,7 @@ public synchronized void writeTo(OutputStream os)

String boundary = "--" +
(new ContentType(contentType)).getParameter("boundary");
LineOutputStream los = Session.STREAM_PROVIDER.outputLineStream(os, false);
LineOutputStream los = streamProvider.outputLineStream(os, false);
// if there's a preamble, write it out
if (preamble != null) {
byte[] pb = MimeUtility.getBytes(preamble);
Expand Down Expand Up @@ -605,7 +603,7 @@ protected synchronized void parse() throws MessagingException {

try {
// Skip and save the preamble
LineInputStream lin = Session.STREAM_PROVIDER.inputLineStream(in, false);
LineInputStream lin = streamProvider.inputLineStream(in, false);
StringBuilder preamblesb = null;
String line;
while ((line = lin.readLine()) != null) {
Expand Down
Loading

0 comments on commit f892d46

Please sign in to comment.