This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 830ce6c5a26 Remove useless codes for agent (#30262)
830ce6c5a26 is described below
commit 830ce6c5a269ed610934da619505fc264c84ded3
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 24 14:21:23 2024 +0800
Remove useless codes for agent (#30262)
---
.../agent/core/ShardingSphereAgent.java | 3 +-
.../shardingsphere/agent/core/path/AgentPath.java | 2 +-
.../AgentPreconditions.java | 2 +-
.../agent/core/spi/AgentServiceLoader.java | 2 +-
.../agent/core/util/AgentReflectionUtils.java | 99 ----------------------
.../agent/core/yaml/AgentYamlConstructor.java | 2 +-
.../core/builder/AgentBuilderFactoryTest.java | 6 +-
.../{ => agent/core}/fixture/advice/BarAdvice.java | 2 +-
.../{ => agent/core}/fixture/advice/FooAdvice.java | 2 +-
.../fixture/agent/AgentServiceEmptySPIFixture.java | 2 +-
.../fixture/agent/AgentServiceSPIFixture.java | 2 +-
.../agent/impl/AgentServiceSPIFixtureImpl.java | 4 +-
.../fixture/targeted/TargetObjectFixture.java | 2 +-
.../agent/core/spi/AgentServiceLoaderTest.java | 6 +-
...gent.core.fixture.agent.AgentServiceSPIFixture} | 2 +-
15 files changed, 19 insertions(+), 119 deletions(-)
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
index a9537697935..18747d69527 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
@@ -52,9 +52,8 @@ public final class ShardingSphereAgent {
File rootPath = AgentPath.getRootPath();
Map<String, PluginConfiguration> pluginConfigs =
PluginConfigurationLoader.load(rootPath);
Collection<JarFile> pluginJars = PluginJarLoader.load(rootPath);
- boolean isEnhancedForProxy = isEnhancedForProxy();
Map<String, AdvisorConfiguration> advisorConfigs =
AdvisorConfigurationLoader.load(pluginJars, pluginConfigs.keySet());
- AgentBuilderFactory.create(pluginConfigs, pluginJars, advisorConfigs,
isEnhancedForProxy).installOn(instrumentation);
+ AgentBuilderFactory.create(pluginConfigs, pluginJars, advisorConfigs,
isEnhancedForProxy()).installOn(instrumentation);
}
private static boolean isEnhancedForProxy() {
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
index 6bf9a13a4c9..3bc3c7be6cb 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/path/AgentPath.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.agent.core.path;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.agent.core.util.AgentPreconditions;
+import org.apache.shardingsphere.agent.core.preconditions.AgentPreconditions;
import java.io.File;
import java.net.MalformedURLException;
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/util/AgentPreconditions.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/preconditions/AgentPreconditions.java
similarity index 96%
rename from
agent/core/src/main/java/org/apache/shardingsphere/agent/core/util/AgentPreconditions.java
rename to
agent/core/src/main/java/org/apache/shardingsphere/agent/core/preconditions/AgentPreconditions.java
index e521e87174e..86ddcf2e969 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/util/AgentPreconditions.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/preconditions/AgentPreconditions.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.util;
+package org.apache.shardingsphere.agent.core.preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
index eddec9cca04..23834ea855a 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoader.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.core.spi;
import lombok.Getter;
-import org.apache.shardingsphere.agent.core.util.AgentPreconditions;
+import org.apache.shardingsphere.agent.core.preconditions.AgentPreconditions;
import java.util.Collection;
import java.util.LinkedList;
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/util/AgentReflectionUtils.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/util/AgentReflectionUtils.java
deleted file mode 100644
index fb073e9d2a4..00000000000
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/util/AgentReflectionUtils.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.shardingsphere.agent.core.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Optional;
-
-/**
- * Agent reflection utility class.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class AgentReflectionUtils {
-
- /**
- * Get field value.
- *
- * @param target target
- * @param fieldName field name
- * @param <T> type of field value
- * @return field value
- * @throws IllegalStateException illegal state exception
- */
- public static <T> T getFieldValue(final Object target, final String
fieldName) {
- Optional<Field> field = findField(fieldName, target.getClass());
- if (field.isPresent()) {
- return getFieldValue(target, field.get());
- }
- throw new IllegalStateException(String.format("Can not find field name
`%s` in class %s.", fieldName, target.getClass()));
- }
-
- @SuppressWarnings("unchecked")
- @SneakyThrows(IllegalAccessException.class)
- private static <T> T getFieldValue(final Object target, final Field field)
{
- boolean accessible = field.isAccessible();
- if (!accessible) {
- field.setAccessible(true);
- }
- T result = (T) field.get(target);
- if (!accessible) {
- field.setAccessible(false);
- }
- return result;
- }
-
- private static Optional<Field> findField(final String fieldName, final
Class<?> targetClass) {
- Class<?> currentTargetClass = targetClass;
- while (Object.class != currentTargetClass) {
- try {
- return
Optional.of(currentTargetClass.getDeclaredField(fieldName));
- } catch (final NoSuchFieldException ignored) {
- currentTargetClass = currentTargetClass.getSuperclass();
- }
- }
- return Optional.empty();
- }
-
- /**
- * Invoke method.
- *
- * @param method method
- * @param target target
- * @param args arguments
- * @param <T> type of invoke result
- * @return invoke result
- */
- @SuppressWarnings("unchecked")
- @SneakyThrows(ReflectiveOperationException.class)
- public static <T> T invokeMethod(final Method method, final Object target,
final Object... args) {
- boolean accessible = method.isAccessible();
- if (!accessible) {
- method.setAccessible(true);
- }
- T result = (T) method.invoke(target, args);
- if (!accessible) {
- method.setAccessible(false);
- }
- return result;
- }
-}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/AgentYamlConstructor.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/AgentYamlConstructor.java
index 002f57d43a6..be5d3e14fb6 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/AgentYamlConstructor.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/yaml/AgentYamlConstructor.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.agent.core.yaml;
-import org.apache.shardingsphere.agent.core.util.AgentPreconditions;
+import org.apache.shardingsphere.agent.core.preconditions.AgentPreconditions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.constructor.Constructor;
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
index e51306b373d..daf0e03d204 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java
@@ -23,9 +23,9 @@ import
net.bytebuddy.agent.builder.ResettableClassFileTransformer;
import net.bytebuddy.matcher.ElementMatchers;
import
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
import
org.apache.shardingsphere.agent.core.advisor.config.MethodAdvisorConfiguration;
-import org.apache.shardingsphere.fixture.advice.BarAdvice;
-import org.apache.shardingsphere.fixture.advice.FooAdvice;
-import org.apache.shardingsphere.fixture.targeted.TargetObjectFixture;
+import org.apache.shardingsphere.agent.core.fixture.advice.BarAdvice;
+import org.apache.shardingsphere.agent.core.fixture.advice.FooAdvice;
+import
org.apache.shardingsphere.agent.core.fixture.targeted.TargetObjectFixture;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/BarAdvice.java
similarity index 98%
rename from
agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/BarAdvice.java
index 87cbf574d7a..d7972339f1c 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/BarAdvice.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/BarAdvice.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.fixture.advice;
+package org.apache.shardingsphere.agent.core.fixture.advice;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.ConstructorAdvice;
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/FooAdvice.java
similarity index 98%
rename from
agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/FooAdvice.java
index 04baee22f7f..bf3ec60921e 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/advice/FooAdvice.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/FooAdvice.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.fixture.advice;
+package org.apache.shardingsphere.agent.core.fixture.advice;
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.ConstructorAdvice;
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/AgentServiceEmptySPIFixture.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/AgentServiceEmptySPIFixture.java
similarity index 93%
rename from
agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/AgentServiceEmptySPIFixture.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/AgentServiceEmptySPIFixture.java
index 37f480b6071..1364f90107b 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/AgentServiceEmptySPIFixture.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/AgentServiceEmptySPIFixture.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.fixture.agent;
+package org.apache.shardingsphere.agent.core.fixture.agent;
public interface AgentServiceEmptySPIFixture {
}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/AgentServiceSPIFixture.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/AgentServiceSPIFixture.java
similarity index 93%
rename from
agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/AgentServiceSPIFixture.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/AgentServiceSPIFixture.java
index f129ca3eb7d..bb4281526a6 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/AgentServiceSPIFixture.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/AgentServiceSPIFixture.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.fixture.agent;
+package org.apache.shardingsphere.agent.core.fixture.agent;
public interface AgentServiceSPIFixture {
}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/impl/AgentServiceSPIFixtureImpl.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/impl/AgentServiceSPIFixtureImpl.java
similarity index 85%
rename from
agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/impl/AgentServiceSPIFixtureImpl.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/impl/AgentServiceSPIFixtureImpl.java
index b0d13d8056a..cdde4e12e06 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/agent/impl/AgentServiceSPIFixtureImpl.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/agent/impl/AgentServiceSPIFixtureImpl.java
@@ -15,9 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.fixture.agent.impl;
+package org.apache.shardingsphere.agent.core.fixture.agent.impl;
-import org.apache.shardingsphere.fixture.agent.AgentServiceSPIFixture;
+import
org.apache.shardingsphere.agent.core.fixture.agent.AgentServiceSPIFixture;
public class AgentServiceSPIFixtureImpl implements AgentServiceSPIFixture {
}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/targeted/TargetObjectFixture.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/TargetObjectFixture.java
similarity index 96%
rename from
agent/core/src/test/java/org/apache/shardingsphere/fixture/targeted/TargetObjectFixture.java
rename to
agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/TargetObjectFixture.java
index e707a5e2f1a..644b2c33828 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/fixture/targeted/TargetObjectFixture.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/TargetObjectFixture.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.fixture.targeted;
+package org.apache.shardingsphere.agent.core.fixture.targeted;
import java.util.List;
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
index 3d25685aef3..5f0debf6ca3 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/spi/AgentServiceLoaderTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.agent.core.spi;
-import org.apache.shardingsphere.fixture.agent.AgentServiceEmptySPIFixture;
-import org.apache.shardingsphere.fixture.agent.AgentServiceSPIFixture;
-import org.apache.shardingsphere.fixture.agent.impl.AgentServiceSPIFixtureImpl;
+import
org.apache.shardingsphere.agent.core.fixture.agent.AgentServiceEmptySPIFixture;
+import
org.apache.shardingsphere.agent.core.fixture.agent.AgentServiceSPIFixture;
+import
org.apache.shardingsphere.agent.core.fixture.agent.impl.AgentServiceSPIFixtureImpl;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
diff --git
a/agent/core/src/test/resources/META-INF/services/org.apache.shardingsphere.fixture.agent.AgentServiceSPIFixture
b/agent/core/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.core.fixture.agent.AgentServiceSPIFixture
similarity index 90%
rename from
agent/core/src/test/resources/META-INF/services/org.apache.shardingsphere.fixture.agent.AgentServiceSPIFixture
rename to
agent/core/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.core.fixture.agent.AgentServiceSPIFixture
index 8eaa2a1f329..31c24cadb27 100644
---
a/agent/core/src/test/resources/META-INF/services/org.apache.shardingsphere.fixture.agent.AgentServiceSPIFixture
+++
b/agent/core/src/test/resources/META-INF/services/org.apache.shardingsphere.agent.core.fixture.agent.AgentServiceSPIFixture
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.fixture.agent.impl.AgentServiceSPIFixtureImpl
+org.apache.shardingsphere.agent.core.fixture.agent.impl.AgentServiceSPIFixtureImpl