Ver código fonte

give a parent to plugin class loaders, and exclude provided jars when package

zqq90 8 anos atrás
pai
commit
4584f881b3

+ 1 - 1
bin/package-hdata.bat

@@ -28,7 +28,7 @@ copy "%HDATA_HOME%\readme.md" "%HDATA_BUILD_HDATA_DIR%"
 
 
 
-call mvn clean package dependency:copy-dependencies 
+call mvn clean package -Pcopy-dependency
 
 copy /y %HDATA_HOME%\hdata-core\target\hdata-core-*.jar %HDATA_BUILD_HDATA_DIR%\lib
 copy /y %HDATA_HOME%\hdata-core\target\dependency\*.jar %HDATA_BUILD_HDATA_DIR%\lib

+ 1 - 1
bin/package-hdata.sh

@@ -31,7 +31,7 @@ mkdir -p $HDATA_BUILD_HDATA_DIR/plugins
 cp $HDATA_HOME/bin/hdata $HDATA_BUILD_HDATA_DIR/bin/
 cp -r $HDATA_HOME/conf $HDATA_BUILD_HDATA_DIR/
 
-mvn clean package dependency:copy-dependencies
+mvn clean package -Pcopy-dependency
 
 cp $HDATA_HOME/hdata-core/target/hdata-core-*.jar $HDATA_BUILD_HDATA_DIR/lib
 cp $HDATA_HOME/hdata-core/target/dependency/*.jar $HDATA_BUILD_HDATA_DIR/lib

+ 2 - 13
hdata-core/src/main/java/com/github/stuxuhai/hdata/core/PluginClassLoader.java

@@ -5,18 +5,7 @@ import java.net.URLClassLoader;
 
 public class PluginClassLoader extends URLClassLoader {
 
-    public PluginClassLoader(URL[] urls, ClassLoader parent) {
-        super(urls, parent);
+    public PluginClassLoader(URL[] urls) {
+        super(urls, PluginClassLoader.class.getClassLoader());
     }
-
-    @Override
-    public Class<?> loadClass(String name) throws ClassNotFoundException {
-        if (name.startsWith("com.github.stuxuhai.hdata.api.") || name.startsWith("org.apache.logging.") || name.startsWith("org.apache.log4j.")
-                || name.startsWith("org.slf4j.") || name.startsWith("org.apache.commons.logging.")) {
-            return getClass().getClassLoader().loadClass(name);
-        } else {
-            return super.loadClass(name);
-        }
-    }
-
 }

+ 1 - 1
hdata-core/src/main/java/com/github/stuxuhai/hdata/util/PluginUtils.java

@@ -40,7 +40,7 @@ public class PluginUtils {
         List<URL> list = listFileByPluginName(pluginName);
         PluginClassLoader classLoader = cache.get(pluginName);
         if (classLoader == null) {
-            classLoader = new PluginClassLoader(list.toArray(new URL[list.size()]), null);
+            classLoader = new PluginClassLoader(list.toArray(new URL[list.size()]));
             cache.put(pluginName, classLoader);
         }
         return classLoader.loadClass(className);

+ 2 - 0
hdata-csv/pom.xml

@@ -12,10 +12,12 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-core</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.commons</groupId>

+ 1 - 0
hdata-excel/pom.xml

@@ -12,6 +12,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.google.guava</groupId>

+ 1 - 0
hdata-ftp/pom.xml

@@ -12,6 +12,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.commons</groupId>

+ 1 - 0
hdata-hbase/pom.xml

@@ -17,6 +17,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.hadoop</groupId>

+ 1 - 0
hdata-hdfs/pom.xml

@@ -16,6 +16,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.hadoop</groupId>

+ 1 - 0
hdata-hive/pom.xml

@@ -17,6 +17,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.anarres.lzo</groupId>

+ 1 - 0
hdata-http/pom.xml

@@ -12,6 +12,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.google.guava</groupId>

+ 2 - 0
hdata-jdbc/pom.xml

@@ -12,10 +12,12 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-core</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.google.guava</groupId>

+ 1 - 0
hdata-kafka/pom.xml

@@ -12,6 +12,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.kafka</groupId>

+ 1 - 0
hdata-mongodb/pom.xml

@@ -12,6 +12,7 @@
 		<dependency>
 			<groupId>com.github.stuxuhai</groupId>
 			<artifactId>hdata-api</artifactId>
+      <scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.mongodb</groupId>

+ 30 - 0
pom.xml

@@ -28,6 +28,31 @@
     </dependencies>
   </dependencyManagement>
 
+  <profiles>
+    <profile>
+      <id>copy-dependency</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-dependency-plugin</artifactId>
+            <configuration>
+              <includeScope>runtime</includeScope>
+            </configuration>
+            <executions>
+              <execution>
+                <phase>package</phase>
+                <goals>
+                  <goal>copy-dependencies</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
   <build>
     <pluginManagement>
       <plugins>
@@ -41,6 +66,11 @@
           <artifactId>maven-jar-plugin</artifactId>
           <version>2.6</version>
         </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-dependency-plugin</artifactId>
+          <version>2.10</version>
+        </plugin>
       </plugins>
     </pluginManagement>
   </build>