Index: lucene/common-build.xml =================================================================== --- lucene/common-build.xml (revision 1380239) +++ lucene/common-build.xml (working copy) @@ -799,7 +799,7 @@ - + Index: lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (revision 0) +++ lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (working copy) @@ -0,0 +1,58 @@ +package org.apache.lucene.util; + +import java.util.Arrays; +import java.util.Iterator; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A {@link SecurityManager} that prevents {@link System#exit(int)}. + * @lucene.internal + */ +public final class TestSecurityManager extends SecurityManager { + + public TestSecurityManager() { + super(); + // just paranoid: + if (System.getProperty("java.security.policy") == null) + throw new SecurityException("For text-framework to work correctly, you must use the tests.policy file with -Djava.security.policy"); + } + + @Override + public void checkExit(int status) { + final SecurityException se = new SecurityException("Hey, don't kill the holy test runner!"); + final Iterator it = Arrays.asList(se.getStackTrace()).iterator(); + // search for stack trace element that is inside System.exit() to walk over JVM-specific things + while (it.hasNext()) { + StackTraceElement e = it.next(); + if (System.class.getName().equals(e.getClassName()) && + "exit".equals(e.getMethodName())) { + // next stack trace element must be TestRunner itsself + e = it.next(); + if ("com.carrotsearch.ant.tasks.junit4.slave.SlaveMain".equals(e.getClassName()) && + "main".equals(e.getMethodName())) { + // this is the only valid exit point, delegate to original SecurityManager! + super.checkExit(status); + return; + } + } + } + throw se; + } + +} Index: lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (revision 0) +++ lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (working copy) Property changes on: lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property