Merge pull request elastic/elasticsearch#2311 from rjernst/java9

Make java 9 work

Original commit: elastic/x-pack-elasticsearch@85fd896fec
This commit is contained in:
Ryan Ernst 2016-05-21 15:17:25 -07:00
commit d0fa5cb29a
10 changed files with 63 additions and 16 deletions

View File

@ -5,6 +5,8 @@ dependencies {
testCompile "org.elasticsearch.test:framework:${version}"
}
compactProfile = 'full'
dependencyLicenses.enabled = false
jar {

View File

@ -35,6 +35,10 @@ dependencies {
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239'
compile 'com.google.guava:guava:16.0.1' // needed by watcher for the html sanitizer and shield tests for jimfs
compile 'com.sun.mail:javax.mail:1.5.3'
// HACK: java 9 removed javax.activation from the default modules, so instead of trying to add modules, which would have
// to be conditionalized for java 8/9, we pull in the classes directly
compile 'javax.activation:activation:1.1'
testCompile 'org.subethamail:subethasmtp:3.1.7'
// needed for subethasmtp, has @GuardedBy annotation
testCompile 'com.google.code.findbugs:jsr305:3.0.1'

View File

@ -121,7 +121,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
assertNotNull(exporters);
// Wait for exporting bulks to be ready to export
assertBusy(() -> assertThat(exporters.openBulk(), notNullValue()));
Runnable busy = () -> assertThat(exporters.openBulk(), notNullValue());
assertBusy(busy);
exporters.export(collector.collect());
}

View File

@ -93,7 +93,8 @@ public class HttpExporterTemplateTests extends AbstractExporterTemplateTestCase
@Override
protected void awaitIndexExists(String index) throws Exception {
assertBusy(() -> assertThat("could not find index " + index, dispatcher.hasIndex(index), is(true)), 10, TimeUnit.SECONDS);
Runnable busy = () -> assertThat("could not find index " + index, dispatcher.hasIndex(index), is(true));
assertBusy(busy, 10, TimeUnit.SECONDS);
}
class MockServerDispatcher extends Dispatcher {

View File

@ -92,6 +92,7 @@ public class UsersToolTests extends CommandTestCase {
public static void closeJimfs() throws IOException {
if (jimfs != null) {
jimfs.close();
jimfs = null;
}
}

View File

@ -37,6 +37,8 @@ import org.elasticsearch.xpack.common.secret.SecretModule;
import org.elasticsearch.xpack.extensions.XPackExtension;
import org.elasticsearch.xpack.extensions.XPackExtensionsService;
import org.elasticsearch.xpack.notification.Notification;
import org.elasticsearch.xpack.notification.email.Account;
import org.elasticsearch.xpack.notification.email.support.BodyPartSource;
import org.elasticsearch.xpack.rest.action.RestXPackInfoAction;
import org.elasticsearch.xpack.common.text.TextTemplateModule;
import org.elasticsearch.xpack.rest.action.RestXPackUsageAction;
@ -84,6 +86,9 @@ public class XPackPlugin extends Plugin {
throw bogus; // some other bug
}
}
// some classes need to have their own clinit blocks
BodyPartSource.init();
Account.init();
}
protected final Settings settings;

View File

@ -32,13 +32,6 @@ public class Account {
static final String SMTP_PROTOCOL = "smtp";
static {
// required as java doesn't always find the correct mailcap to properly handle mime types
final MailcapCommandMap mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mailcap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mailcap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mailcap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mailcap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new SpecialPermission());
@ -46,12 +39,22 @@ public class Account {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
// required as java doesn't always find the correct mailcap to properly handle mime types
final MailcapCommandMap mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mailcap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mailcap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mailcap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mailcap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
CommandMap.setDefaultCommandMap(mailcap);
return null;
}
});
}
// exists only to allow ensuring class is initialized
public static void init() {}
static final Settings DEFAULT_SMTP_TIMEOUT_SETTINGS = Settings.builder()
.put("connection_timeout", TimeValue.timeValueMinutes(2))
.put("write_timeout", TimeValue.timeValueMinutes(2))

View File

@ -5,18 +5,30 @@
*/
package org.elasticsearch.xpack.notification.email.support;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.common.xcontent.ToXContent;
import javax.activation.CommandMap;
import javax.activation.FileTypeMap;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
*
*/
public abstract class BodyPartSource implements ToXContent {
protected static FileTypeMap fileTypeMap = FileTypeMap.getDefaultFileTypeMap();
protected static FileTypeMap fileTypeMap;
static {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new SpecialPermission());
}
fileTypeMap = AccessController.doPrivileged(
(PrivilegedAction<FileTypeMap>)() -> FileTypeMap.getDefaultFileTypeMap());
}
protected final String id;
protected final String name;
@ -46,4 +58,7 @@ public abstract class BodyPartSource implements ToXContent {
public abstract MimeBodyPart bodyPart() throws MessagingException;
// exists only to allow ensuring class is initialized
public static void init() {}
}

View File

@ -11,6 +11,8 @@ grant {
// to load the class with the application class loader
permission java.lang.RuntimePermission "setContextClassLoader";
permission java.lang.RuntimePermission "getClassLoader";
// TODO: remove use of this jar as soon as possible!!!!
permission java.lang.RuntimePermission "accessClassInPackage.com.sun.activation.registries";
// bouncy castle
permission java.security.SecurityPermission "putProviderProperty.BC";

View File

@ -6,6 +6,9 @@
package org.elasticsearch.xpack.watcher.history;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
@ -15,6 +18,9 @@ import org.elasticsearch.xpack.watcher.execution.ExecutionState;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
@ -32,15 +38,18 @@ import static org.hamcrest.Matchers.notNullValue;
* not analyzed so they can be used in aggregations
*/
public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegrationTestCase {
private static final ESLogger logger = Loggers.getLogger(HistoryTemplateEmailMappingsTests.class);
static final String USERNAME = "_user";
static final String PASSWORD = "_passwd";
private EmailServer server;
private static EmailServer server;
@After
public void cleanup() throws Exception {
@AfterClass
public static void cleanup() throws Exception {
if (server != null) {
server.stop();
}
}
@Override
protected boolean timeWarped() {
@ -52,12 +61,16 @@ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegratio
return false; // remove shield noise from this test
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
@BeforeClass
public static void setupEmailServer() {
if(server == null) {
//Need to construct the Email Server here as this happens before init()
server = EmailServer.localhost("2500-2600", USERNAME, PASSWORD, logger);
}
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))