Make java 9 work

This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#18496
Most of the changes here are related to javax.activation.

Original commit: elastic/x-pack-elasticsearch@2a47f94ab5
This commit is contained in:
Ryan Ernst 2016-05-21 11:54:09 -07:00
parent c754f7cf08
commit f5bbe1858c
10 changed files with 62 additions and 16 deletions

View File

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

View File

@ -35,6 +35,10 @@ dependencies {
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239' 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.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' 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' testCompile 'org.subethamail:subethasmtp:3.1.7'
// needed for subethasmtp, has @GuardedBy annotation // needed for subethasmtp, has @GuardedBy annotation
testCompile 'com.google.code.findbugs:jsr305:3.0.1' testCompile 'com.google.code.findbugs:jsr305:3.0.1'

View File

@ -121,7 +121,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
assertNotNull(exporters); assertNotNull(exporters);
// Wait for exporting bulks to be ready to export // 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()); exporters.export(collector.collect());
} }

View File

@ -93,7 +93,8 @@ public class HttpExporterTemplateTests extends AbstractExporterTemplateTestCase
@Override @Override
protected void awaitIndexExists(String index) throws Exception { 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 { class MockServerDispatcher extends Dispatcher {

View File

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

View File

@ -35,6 +35,8 @@ import org.elasticsearch.xpack.common.secret.SecretModule;
import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtension;
import org.elasticsearch.xpack.extensions.XPackExtensionsService; import org.elasticsearch.xpack.extensions.XPackExtensionsService;
import org.elasticsearch.xpack.notification.Notification; 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.rest.action.RestXPackInfoAction;
import org.elasticsearch.xpack.common.text.TextTemplateModule; import org.elasticsearch.xpack.common.text.TextTemplateModule;
import org.elasticsearch.xpack.watcher.Watcher; import org.elasticsearch.xpack.watcher.Watcher;
@ -81,6 +83,9 @@ public class XPackPlugin extends Plugin {
throw bogus; // some other bug throw bogus; // some other bug
} }
} }
// some classes need to have their own clinit blocks
BodyPartSource.init();
Account.init();
} }
protected final Settings settings; protected final Settings settings;

View File

@ -32,13 +32,6 @@ public class Account {
static final String SMTP_PROTOCOL = "smtp"; static final String SMTP_PROTOCOL = "smtp";
static { 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(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(new SpecialPermission()); sm.checkPermission(new SpecialPermission());
@ -46,12 +39,22 @@ public class Account {
AccessController.doPrivileged(new PrivilegedAction<Void>() { AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override @Override
public Void run() { 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); CommandMap.setDefaultCommandMap(mailcap);
return null; return null;
} }
}); });
} }
// exists only to allow ensuring class is initialized
public static void init() {}
static final Settings DEFAULT_SMTP_TIMEOUT_SETTINGS = Settings.builder() static final Settings DEFAULT_SMTP_TIMEOUT_SETTINGS = Settings.builder()
.put("connection_timeout", TimeValue.timeValueMinutes(2)) .put("connection_timeout", TimeValue.timeValueMinutes(2))
.put("write_timeout", TimeValue.timeValueMinutes(2)) .put("write_timeout", TimeValue.timeValueMinutes(2))

View File

@ -5,18 +5,30 @@
*/ */
package org.elasticsearch.xpack.notification.email.support; package org.elasticsearch.xpack.notification.email.support;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import javax.activation.CommandMap;
import javax.activation.FileTypeMap; import javax.activation.FileTypeMap;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeBodyPart;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* *
*/ */
public abstract class BodyPartSource implements ToXContent { 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 id;
protected final String name; protected final String name;
@ -46,4 +58,7 @@ public abstract class BodyPartSource implements ToXContent {
public abstract MimeBodyPart bodyPart() throws MessagingException; public abstract MimeBodyPart bodyPart() throws MessagingException;
// exists only to allow ensuring class is initialized
public static void init() {}
} }

View File

@ -11,6 +11,7 @@ grant {
// to load the class with the application class loader // to load the class with the application class loader
permission java.lang.RuntimePermission "setContextClassLoader"; permission java.lang.RuntimePermission "setContextClassLoader";
permission java.lang.RuntimePermission "getClassLoader"; permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "accessClassInPackage.com.sun.activation.registries";
// bouncy castle // bouncy castle
permission java.security.SecurityPermission "putProviderProperty.BC"; permission java.security.SecurityPermission "putProviderProperty.BC";

View File

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