Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXF-8700: Eliminate the java.compiler dependency from cxf-core #946

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@
<artifactId>cxf-tools-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Copy link
Member

@reta reta May 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should add this dependency to cxf-core (which could be excluded on demand) to not break existing applications if anyone is using Compiler class (since this is public API).

<groupId>org.apache.cxf</groupId>
<artifactId>cxf-tools-compiler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-tools-corba</artifactId>
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,18 @@ private AttachmentUtil() {
}

static {
COMMAND_MAP.addMailcap("image/*;;x-java-content-handler="
+ ImageDataContentHandler.class.getName());
String imageDataContentHandlerClassName = "org.apache.cxf.management.attachment.image.ImageDataContentHandler";

try {
Class<?> imageDataContentHandlerClass = Class.forName(
imageDataContentHandlerClassName);

COMMAND_MAP.addMailcap("image/*;;x-java-content-handler="
+ imageDataContentHandlerClass.getName());
} catch (ReflectiveOperationException e) {
LOG.warning(() -> imageDataContentHandlerClassName.concat(
" cannot be found. Is cxf-rt-attachment-image present?"));
}
}

public static CommandMap getCommandMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.cxf.bus.osgi;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Dictionary;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -30,6 +28,8 @@
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
import org.apache.cxf.workqueue.WorkQueueManager;
import org.apache.cxf.workqueue.WorkqueueEvent;
import org.apache.cxf.workqueue.WorkqueueEventListener;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.ConfigurationException;
Expand All @@ -39,7 +39,7 @@
/**
* List of work queues that can be managed using the OSGi configuration admin service
*/
public class ManagedWorkQueueList implements ManagedServiceFactory, PropertyChangeListener {
public class ManagedWorkQueueList implements ManagedServiceFactory, WorkqueueEventListener {
public static final String FACTORY_PID = "org.apache.cxf.workqueues";
private static final Logger LOG = LogUtils.getL7dLogger(ManagedWorkQueueList.class);

Expand Down Expand Up @@ -76,9 +76,9 @@ public void deleted(String pid) {
/*
* On property changes of queue settings we update the config admin service pid of the queue
*/
public void propertyChange(PropertyChangeEvent evt) {
public void processEvent(WorkqueueEvent workqueueEvent) {
try {
AutomaticWorkQueueImpl queue = (AutomaticWorkQueueImpl)evt.getSource();
AutomaticWorkQueueImpl queue = (AutomaticWorkQueueImpl)workqueueEvent.getSource();
ConfigurationAdmin configurationAdmin = configAdminTracker.getService();
if (configurationAdmin != null) {
Configuration selectedConfig = findConfigForQueueName(queue, configurationAdmin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import org.w3c.dom.Document;

import org.apache.cxf.common.util.ClassHelper;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.common.xmlschema.SchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaElement;
Expand Down Expand Up @@ -135,7 +136,7 @@ public Object getBeanInfo(Class<?> cls) {
String name = xre == null ? "##default" : xre.name();
String namespace = xre == null ? "##default" : xre.namespace();
if ("##default".equals(name)) {
name = java.beans.Introspector.decapitalize(cls.getSimpleName());
name = ClassHelper.decapitalizedSimpleName(cls);
}
if ("##default".equals(namespace) && cls.getPackage() != null) {
XmlSchema sc = cls.getPackage().getAnnotation(XmlSchema.class);
Expand Down Expand Up @@ -199,7 +200,7 @@ private QName getTypeQName(Class<?> cls, String namespace) {
String tn = xtype == null ? "##default" : xtype.name();
String tns = xtype == null ? "##default" : xtype.namespace();
if ("##default".equals(tn)) {
tn = java.beans.Introspector.decapitalize(cls.getSimpleName());
tn = ClassHelper.decapitalizedSimpleName(cls);
}
if ("##default".equals(tns) || StringUtils.isEmpty(tns)) {
tns = JAXBUtils.getPackageNamespace(cls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.imageio.ImageIO;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.cxf.common.classloader.ClassLoaderUtils;
Expand Down Expand Up @@ -101,7 +100,9 @@ public static void doHacks() {
try {
//Trigger a call to sun.awt.AppContext.getAppContext()
if (!skipHack("org.apache.cxf.JDKBugHacks.imageIO", "true")) {
ImageIO.getCacheDirectory();
Class<?> imageIOClass = Class.forName("javax.imageio.ImageIO");
Method getCacheDirectoryMethod = imageIOClass.getDeclaredMethod("getCacheDirectory");
getCacheDirectoryMethod.invoke(null);
}
} catch (Throwable t) {
//ignore
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/org/apache/cxf/common/util/ClassHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ private Object getRealObjectInternal(Object o) {
return o instanceof Proxy ? Proxy.getInvocationHandler(o) : o;
}

public static String decapitalizedSimpleName(Class<?> clazz) {
if (clazz == null) {
return null;
}
String name = clazz.getSimpleName();
if (name == null || name.isEmpty()) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1))
&& Character.isUpperCase(name.charAt(0))) {
return name;
}
char[] chars = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}

public static Class<?> getRealClass(Object o) {
return getRealClass(null, o);
}
Expand Down
65 changes: 0 additions & 65 deletions core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,18 @@

package org.apache.cxf.common.util;

import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;

import org.apache.cxf.common.classloader.ClassLoaderUtils;

public final class ReflectionUtil {

private static Method springBeanUtilsDescriptorFetcher;
private static boolean springChecked;

private ReflectionUtil() {
// intentionally empty
}
Expand Down Expand Up @@ -195,61 +185,6 @@ public T run() {
});
}

/**
* create own array of property descriptors to:
* <pre>
* - prevent memory leaks by Introspector's cache
* - get correct type for generic properties from superclass
* that are limited to a specific type in beanClass
* see http://bugs.sun.com/view_bug.do?bug_id=6528714
* we cannot use BeanUtils.getPropertyDescriptors because of issue SPR-6063
* </pre>
* @param refClass calling class for class loading.
* @param beanInfo Bean in question
* @param beanClass class for bean in question
* @param propertyDescriptors raw descriptors
*/
public static PropertyDescriptor[] getPropertyDescriptorsAvoidSunBug(Class<?> refClass,
BeanInfo beanInfo,
Class<?> beanClass,
PropertyDescriptor[] propertyDescriptors) {
if (!springChecked) {
try {
springChecked = true;
Class<?> cls = ClassLoaderUtils
.loadClass("org.springframework.beans.BeanUtils", refClass);
springBeanUtilsDescriptorFetcher
= cls.getMethod("getPropertyDescriptor", Class.class, String.class);
} catch (Exception e) {
//ignore - just assume it's an unsupported/unknown annotation
}
}

if (springBeanUtilsDescriptorFetcher != null) {
if (propertyDescriptors != null) {
List<PropertyDescriptor> descriptors = new ArrayList<>(propertyDescriptors.length);
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
try {
propertyDescriptor = (PropertyDescriptor)springBeanUtilsDescriptorFetcher.invoke(null,
beanClass,
propertyDescriptor.getName());
if (propertyDescriptor != null) {
descriptors.add(propertyDescriptor);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getCause());
}
}
return descriptors.toArray(new PropertyDescriptor[0]);
}
return null;
}
return beanInfo.getPropertyDescriptors();
}

/**
* Look for a specified annotation on a method. If there, return it. If not, search it's containing class.
* Assume that the annotation is marked @Inherited.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.apache.cxf.workqueue;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
Expand Down Expand Up @@ -78,7 +76,7 @@ public class AutomaticWorkQueueImpl implements AutomaticWorkQueue {
boolean shared;
int sharedCount;

private List<PropertyChangeListener> changeListenerList;
private List<WorkqueueEventListener> workqueueEventListeners;

public AutomaticWorkQueueImpl() {
this(DEFAULT_MAX_QUEUE_SIZE);
Expand Down Expand Up @@ -116,20 +114,20 @@ public AutomaticWorkQueueImpl(int mqs,
this.lowWaterMark = -1 == lowWaterMark ? Integer.MAX_VALUE : lowWaterMark;
this.dequeueTimeout = dequeueTimeout;
this.name = name;
this.changeListenerList = new ArrayList<>();
this.workqueueEventListeners = new ArrayList<>();
}

public void addChangeListener(PropertyChangeListener listener) {
this.changeListenerList.add(listener);
public void addChangeListener(WorkqueueEventListener listener) {
this.workqueueEventListeners.add(listener);
}

public void removeChangeListener(PropertyChangeListener listener) {
this.changeListenerList.remove(listener);
public void removeChangeListener(WorkqueueEventListener listener) {
this.workqueueEventListeners.remove(listener);
}

public void notifyChangeListeners(PropertyChangeEvent event) {
for (PropertyChangeListener listener : changeListenerList) {
listener.propertyChange(event);
public void notifyChangeListeners(WorkqueueEvent workqueueEvent) {
for (WorkqueueEventListener listener : workqueueEventListeners) {
listener.processEvent(workqueueEvent);
}
}

Expand Down Expand Up @@ -530,7 +528,7 @@ public int getInitialSize() {
public void setHighWaterMark(int hwm) {
highWaterMark = hwm < 0 ? Integer.MAX_VALUE : hwm;
if (executor != null) {
notifyChangeListeners(new PropertyChangeEvent(this, "highWaterMark",
notifyChangeListeners(new WorkqueueEvent(this, "highWaterMark",
this.executor.getMaximumPoolSize(), hwm));
executor.setMaximumPoolSize(highWaterMark);
}
Expand All @@ -539,24 +537,24 @@ public void setHighWaterMark(int hwm) {
public void setLowWaterMark(int lwm) {
lowWaterMark = lwm < 0 ? 0 : lwm;
if (executor != null) {
notifyChangeListeners(new PropertyChangeEvent(this, "lowWaterMark",
notifyChangeListeners(new WorkqueueEvent(this, "lowWaterMark",
this.executor.getCorePoolSize(), lwm));
executor.setCorePoolSize(lowWaterMark);
}
}

public void setInitialSize(int initialSize) {
notifyChangeListeners(new PropertyChangeEvent(this, "initialSize", this.initialThreads, initialSize));
notifyChangeListeners(new WorkqueueEvent(this, "initialSize", this.initialThreads, initialSize));
this.initialThreads = initialSize;
}

public void setQueueSize(int size) {
notifyChangeListeners(new PropertyChangeEvent(this, "queueSize", this.maxQueueSize, size));
notifyChangeListeners(new WorkqueueEvent(this, "queueSize", this.maxQueueSize, size));
this.maxQueueSize = size;
}

public void setDequeueTimeout(long l) {
notifyChangeListeners(new PropertyChangeEvent(this, "dequeueTimeout", this.dequeueTimeout, l));
notifyChangeListeners(new WorkqueueEvent(this, "dequeueTimeout", this.dequeueTimeout, l));
this.dequeueTimeout = l;
}

Expand Down
60 changes: 60 additions & 0 deletions core/src/main/java/org/apache/cxf/workqueue/WorkqueueEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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.
*/

package org.apache.cxf.workqueue;

import java.util.EventObject;

public class WorkqueueEvent extends EventObject {
private static final long serialVersionUID = 2445723027847701801L;

private final Object newValue;
private final Object oldValue;
private final String propertyName;

public WorkqueueEvent(
Object source, String propertyName, Object oldValue, Object newValue) {
super(source);
this.propertyName = propertyName;
this.newValue = newValue;
this.oldValue = oldValue;
}

public String getPropertyName() {
return propertyName;
}

public Object getNewValue() {
return newValue;
}

public Object getOldValue() {
return oldValue;
}

public String toString() {
StringBuilder sb = new StringBuilder(getClass().getName());
sb.append("[propertyName=").append(getPropertyName());
sb.append("; oldValue=").append(getOldValue());
sb.append("; newValue=").append(getNewValue());
sb.append("; source=").append(getSource());
return sb.append(']').toString();
}

}
Loading