GP-1907: Removing ContinuesInterceptor and associated API

This commit is contained in:
Ryan Kurtz 2022-04-11 01:05:30 -04:00
parent 2db3a6be15
commit 96674d4f62
208 changed files with 1125 additions and 3387 deletions

View file

@ -1,4 +1,3 @@
MODULE FILE LICENSE: lib/cglib-nodep-2.2.jar Apache License 2.0
MODULE FILE LICENSE: lib/guava-19.0.jar Apache License 2.0
MODULE FILE LICENSE: lib/jdom-legacy-1.1.3.jar JDOM License
MODULE FILE LICENSE: lib/log4j-api-2.17.1.jar Apache License 2.0

View file

@ -26,7 +26,6 @@ eclipse.project.name = 'Framework Generic'
dependencies {
api project(':Utility')
api "cglib:cglib-nodep:2.2"
api "com.google.guava:guava:19.0"
api "org.jdom:jdom-legacy:1.1.3"
api "org.apache.logging.log4j:log4j-api:2.17.1"

View file

@ -1,64 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed 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.
*/
package generic.continues;
import java.lang.reflect.Constructor;
import net.sf.cglib.proxy.Enhancer;
public class ContinuesFactory implements GenericFactory {
private static final boolean enabled = Boolean.getBoolean("ContinuesInterceptor.enabled");
private ExceptionHandler exceptionHandler;
public ContinuesFactory(ExceptionHandler exceptionHandler) {
if (exceptionHandler == null) {
throw new IllegalArgumentException("exceptionHandler == null not allowed");
}
this.exceptionHandler = exceptionHandler;
}
@Override
public Object create(Class<?> type, Object... args) {
try {
Object thing;
if (!enabled) {
Constructor<?> c = type.getConstructor(new Class<?>[0]);
thing = c.newInstance(args);
}
else {
ContinuesInterceptor interceptor = new ContinuesInterceptor(exceptionHandler);
Enhancer e = new Enhancer();
e.setSuperclass(type);
e.setCallback(interceptor);
thing = e.create();
}
return thing;
}
catch (Throwable e) {
try {
exceptionHandler.handle(e);
}
catch (Throwable t) {
// let the handler supplant the original exception if need be
e = t;
}
// wrap so clients don't need try/catch everywhere
throw new RuntimeException(e);
}
}
}

View file

@ -1,47 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package generic.continues;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
class ContinuesInterceptor implements MethodInterceptor {
private final ExceptionHandler handler;
ContinuesInterceptor(ExceptionHandler handler) {
this.handler = handler;
}
@Override
public Object intercept(Object obj, Method method, Object[] args,
MethodProxy proxy) throws Throwable {
Object retValFromSuper = null;
if (method.getAnnotation(DoNotContinue.class) != null) {
retValFromSuper = proxy.invokeSuper(obj, args);
} else {
try {
retValFromSuper = proxy.invokeSuper(obj, args);
}
catch (Exception e) {
handler.handle(e);
}
}
return retValFromSuper;
}
}

View file

@ -1,28 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package generic.continues;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DoNotContinue {
// marker interface
}

View file

@ -1,21 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package generic.continues;
public interface ExceptionHandler {
public void handle(Throwable e) throws Throwable;
}

View file

@ -1,21 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package generic.continues;
public interface GenericFactory {
public Object create(Class<?> type, Object... args);
}

View file

@ -1,25 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package generic.continues;
public class RethrowContinuesFactory extends ContinuesFactory {
public static final RethrowContinuesFactory INSTANCE = new RethrowContinuesFactory();
private RethrowContinuesFactory() {
super(RethrowExceptionHandler.INSTANCE);
}
}

View file

@ -1,28 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package generic.continues;
public class RethrowExceptionHandler implements ExceptionHandler {
public static final RethrowExceptionHandler INSTANCE = new RethrowExceptionHandler();
private RethrowExceptionHandler() {}
@Override
public void handle(Throwable e) throws Throwable {
throw e;
}
}

View file

@ -1,28 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed 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.
*/
package ghidra.app.util.importer;
import generic.continues.*;
public class MessageLogContinuesFactory {
public static ContinuesFactory create(MessageLog log) {
if (log == null) {
throw new IllegalArgumentException("log == null not allowed");
}
return new ContinuesFactory(new MessageLogExceptionHandler(log));
}
}

View file

@ -1,51 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed 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.
*/
package ghidra.app.util.importer;
import generic.continues.ExceptionHandler;
import ghidra.util.Msg;
public class MessageLogExceptionHandler implements ExceptionHandler {
private MessageLog messageLog;
public MessageLogExceptionHandler() {
this.messageLog = new MessageLog();
}
public MessageLogExceptionHandler(MessageLog messageLog) {
this.messageLog = messageLog;
}
public MessageLog getMessageLog() {
return messageLog;
}
public void setMessageLog(MessageLog messageLog) {
this.messageLog = messageLog;
}
@Override
public void handle(Throwable t) throws Throwable {
if ((t instanceof Exception) && !(t instanceof RuntimeException)) {
throw t; // original code must have handler for this
}
if (messageLog != null) {
messageLog.appendException(t);
Msg.warn(this, t.getMessage(), t);
}
}
}