You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/06/19 06:04:28 UTC

[skywalking] branch master updated: Check disallowed imports in agent instrumentation classes (#2908)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 4883534  Check disallowed imports in agent instrumentation classes (#2908)
4883534 is described below

commit 48835348bb4794485328671a11809692416106f4
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Wed Jun 19 14:04:22 2019 +0800

    Check disallowed imports in agent instrumentation classes (#2908)
    
    * Check disallowed imports in agent instrumentation classes
    
    * Remove check script
    
    * Remove script
---
 Jenkinsfile                                        |  8 ------
 .../main/resources/skywalking => }/CHECKSTYLE_HEAD |  0
 .../main/resources/skywalking => }/checkStyle.xml  |  7 ++++-
 apm-checkstyle/{pom.xml => importControl.xml}      | 23 ++++++----------
 pom.xml                                            | 14 ++--------
 tools/check/agent/plugin/PluginImportedCheck.sh    | 32 ----------------------
 6 files changed, 18 insertions(+), 66 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 06c86a1..c142573 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -58,14 +58,6 @@ pipeline {
                             }
                         }
 
-                        stage('Check agent plugin instrumentation imports') {
-                            steps {
-                                sh './tools/check/agent/plugin/PluginImportedCheck.sh apm-sdk-plugin'
-                                sh './tools/check/agent/plugin/PluginImportedCheck.sh apm-toolkit-activation'
-                                sh './tools/check/agent/plugin/PluginImportedCheck.sh optional-plugins'
-                            }
-                        }
-
                         stage('Test & Report') {
                             steps {
                                 sh './mvnw -P"agent,backend,ui,dist,CI-with-IT" org.jacoco:jacoco-maven-plugin:0.8.3:prepare-agent clean install org.jacoco:jacoco-maven-plugin:0.8.3:report coveralls:report'
diff --git a/apm-checkstyle/src/main/resources/skywalking/CHECKSTYLE_HEAD b/apm-checkstyle/CHECKSTYLE_HEAD
similarity index 100%
rename from apm-checkstyle/src/main/resources/skywalking/CHECKSTYLE_HEAD
rename to apm-checkstyle/CHECKSTYLE_HEAD
diff --git a/apm-checkstyle/src/main/resources/skywalking/checkStyle.xml b/apm-checkstyle/checkStyle.xml
similarity index 94%
rename from apm-checkstyle/src/main/resources/skywalking/checkStyle.xml
rename to apm-checkstyle/checkStyle.xml
index 913484e..b1dda82 100644
--- a/apm-checkstyle/src/main/resources/skywalking/checkStyle.xml
+++ b/apm-checkstyle/checkStyle.xml
@@ -19,7 +19,7 @@
 
 <!DOCTYPE module PUBLIC
     "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
-    "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
+    "http://checkstyle.org/dtds/configuration_1_3.dtd">
 <!--Refer http://checkstyle.sourceforge.net/reports/google-java-style.html#s2.2-file-encoding -->
 <module name="Checker">
 
@@ -104,5 +104,10 @@
         <module name="ParenPad"/>
         <module name="TypecastParenPad"/>
         <module name="TypecastParenPad"/>
+
+        <module name="ImportControl">
+            <property name="file" value="apm-checkstyle/importControl.xml" />
+            <property name="path" value="apm-sniffer/apm-sdk-plugin/.+/src/main/.+Instrumentation.java$" />
+        </module>
     </module>
 </module>
diff --git a/apm-checkstyle/pom.xml b/apm-checkstyle/importControl.xml
similarity index 56%
rename from apm-checkstyle/pom.xml
rename to apm-checkstyle/importControl.xml
index 5466fa0..940ea1e 100644
--- a/apm-checkstyle/pom.xml
+++ b/apm-checkstyle/importControl.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0"?>
 <!--
   ~ Licensed to the Apache Software Foundation (ASF) under one or more
   ~ contributor license agreements.  See the NOTICE file distributed with
@@ -17,17 +17,12 @@
   ~
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <groupId>org.apache</groupId>
-        <artifactId>apache</artifactId>
-        <version>19</version>
-        <relativePath />
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
+<!DOCTYPE import-control PUBLIC
+        "-//Puppy Crawl//DTD Import Control 1.4//EN"
+        "https://checkstyle.org/dtds/import_control_1_4.dtd">
 
-    <groupId>org.apache.skywalking</groupId>
-    <artifactId>apm-checkstyle</artifactId>
-    <version>6.1.0</version>
-    <description>Module to hold Checkstyle for SkyWalking.</description>
-</project>
+<import-control pkg="org.apache.skywalking.apm.plugin">
+    <allow pkg="java"/>
+    <allow pkg="org.apache.skywalking"/>
+    <allow pkg="net.bytebuddy"/>
+</import-control>
diff --git a/pom.xml b/pom.xml
index dd88547..ee9b07c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,6 @@
     <modules>
         <module>apm-commons</module>
         <module>apm-protocol</module>
-        <module>apm-checkstyle</module>
     </modules>
     <packaging>pom</packaging>
 
@@ -205,7 +204,7 @@
         <maven-source-plugin.version>3.0.1</maven-source-plugin.version>
         <versions-maven-plugin.version>2.5</versions-maven-plugin.version>
         <coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
-        <maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
+        <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
         <jacoco-maven-plugin.version>0.8.3</jacoco-maven-plugin.version>
         <jmh.version>1.21</jmh.version>
         <gmaven-plugin.version>1.5</gmaven-plugin.version>
@@ -498,16 +497,9 @@
             <plugin>
                 <artifactId>maven-checkstyle-plugin</artifactId>
                 <version>${maven-checkstyle-plugin.version}</version>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.apache.skywalking</groupId>
-                        <artifactId>apm-checkstyle</artifactId>
-                        <version>6.0.0-GA</version>
-                    </dependency>
-                </dependencies>
                 <configuration>
-                    <configLocation>skywalking/checkStyle.xml</configLocation>
-                    <headerLocation>skywalking/CHECKSTYLE_HEAD</headerLocation>
+                    <configLocation>apm-checkstyle/checkStyle.xml</configLocation>
+                    <headerLocation>apm-checkstyle/CHECKSTYLE_HEAD</headerLocation>
                     <encoding>UTF-8</encoding>
                     <consoleOutput>true</consoleOutput>
                     <includeTestSourceDirectory>true</includeTestSourceDirectory>
diff --git a/tools/check/agent/plugin/PluginImportedCheck.sh b/tools/check/agent/plugin/PluginImportedCheck.sh
deleted file mode 100755
index 5084491..0000000
--- a/tools/check/agent/plugin/PluginImportedCheck.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-# ----------------------------------------------------------------------------
-# 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.
-# ----------------------------------------------------------------------------
-
-plugin_dir=$1
-for dir in `ls "./apm-sniffer/$plugin_dir/"`; do
-	echo "Scanning $dir"
-	for f in `find ./apm-sniffer/$plugin_dir/$dir -name *Instrumentation.java `; do
-		NUM=`head -400 $f | grep ^import |grep -Ev "^import\s+(static\s+)*net.bytebuddy\\." \
-			| grep -Ev "^import\s+(static\s+)*org.apache.skywalking\\." |grep -Ev "^import\s+(static\s+)*java\\." | wc -l`
-		if [ $NUM -gt 0 ] ; then
-			echo "Plugin: $dir($f),  only allow to import JDK and ByteBuddy classes in Instrumentation definition.";
-			exit 1;
-		fi
-	done
-done