The Unified and Autonomous Development Platform
Fix the issue that packed plugin jar does not contain folder names
robin shine351a02170355
diff --git a/commons.bootstrap/src/main/java/com/gitplex/commons/bootstrap/Bootstrap.java b/commons.bootstrap/src/main/java/com/gitplex/commons/bootstrap/Bootstrap.javaindex 0c8bf2388c..160c0f9fa1 100644--- a/commons.bootstrap/src/main/java/com/gitplex/commons/bootstrap/Bootstrap.java+++ b/commons.bootstrap/src/main/java/com/gitplex/commons/bootstrap/Bootstrap.java@@ -243,7 +243,7 @@ public class Bootstrap {}private static boolean isPriorityLib(File lib) {- String entryName = "gitplex-artifact.properties";+ String entryName = "META-INF/gitplex-artifact.properties";if (lib.isDirectory()) {return new File(lib, entryName).exists();} else {diff --git a/commons.loader/src/main/java/com/gitplex/commons/loader/AppLoader.java b/commons.loader/src/main/java/com/gitplex/commons/loader/AppLoader.javaindex f1b2268e7e..bc17e3396e 100644--- a/commons.loader/src/main/java/com/gitplex/commons/loader/AppLoader.java+++ b/commons.loader/src/main/java/com/gitplex/commons/loader/AppLoader.java@@ -90,9 +90,9 @@ public class AppLoader implements Startable {for (URL url: classLoader.getURLs()) {Properties pluginProps = FileUtils.loadProperties(- new File(url.getFile()), "gitplex-plugin.properties");+ new File(url.getFile()), "META-INF/gitplex-plugin.properties");if (pluginProps != null) {- Properties productProps = FileUtils.loadProperties(new File(url.getFile()), "gitplex-product.properties");+ Properties productProps = FileUtils.loadProperties(new File(url.getFile()), "META-INF/gitplex-product.properties");String pluginId = pluginProps.getProperty("id");if (pluginModules.containsKey(pluginId))throw new RuntimeException("More than one version of plugin '" + pluginId + "' is found.");diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.javaindex b049d0d6a1..c79780c431 100644--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.java+++ b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PackageArtifactMojo.java@@ -8,7 +8,9 @@ import java.util.Collection;import java.util.HashSet;import java.util.List;import java.util.Set;-import java.util.zip.ZipOutputStream;+import java.util.jar.Attributes;+import java.util.jar.JarOutputStream;+import java.util.jar.Manifest;import org.apache.maven.artifact.Artifact;import org.apache.maven.plugin.AbstractMojo;@@ -79,10 +81,12 @@ public class PackageArtifactMojo extends AbstractMojo {* archive to avoid the "Can not override..." warning when use this archive to generate* an archetype.*/- ZipOutputStream zos = null;+ JarOutputStream jos = null;try {- zos = new ZipOutputStream(new FileOutputStream(jarFile));- zos.setLevel(9);+ Manifest manifest = new Manifest();+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");+ jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);+ jos.setLevel(9);List<File> files = new ArrayList<File>();PluginUtils.listFiles(new File(project.getBuild().getOutputDirectory()), files);@@ -90,7 +94,7 @@ public class PackageArtifactMojo extends AbstractMojo {boolean includeArchetypeResources = (project.getPlugin("org.apache.maven.plugins:maven-archetype-plugin")!=null);for (File file : files) {- PluginUtils.zipFile(zos, file, project.getBuild().getOutputDirectory().length(), includeArchetypeResources);+ PluginUtils.addFileToJar(jos, file, project.getBuild().getOutputDirectory().length(), includeArchetypeResources);}if (new File(project.getBuild().getOutputDirectory(), PluginConstants.PRODUCT_PROPERTY_FILE).exists()) {@@ -105,13 +109,13 @@ public class PackageArtifactMojo extends AbstractMojo {for (File file: files) {if (!excluded.contains(file.getName()))- PluginUtils.zipFile(zos, file, sandboxDir.getParent().length(), includeArchetypeResources);+ PluginUtils.addFileToJar(jos, file, sandboxDir.getParent().length(), includeArchetypeResources);}}} catch (IOException e) {throw new RuntimeException(e);} finally {- IOUtil.close(zos);+ IOUtil.close(jos);}project.getArtifact().setFile(jarFile);diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.javaindex 1f58c61d2c..480f9b0003 100644--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.java+++ b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginConstants.java@@ -8,13 +8,13 @@ public class PluginConstants {public static final String SANDBOX = "sandbox";- public static final String PRODUCT_PROPERTY_FILE = "gitplex-product.properties";+ public static final String PRODUCT_PROPERTY_FILE = "META-INF/gitplex-product.properties";- public static final String PLUGIN_PROPERTY_FILE = "gitplex-plugin.properties";+ public static final String PLUGIN_PROPERTY_FILE = "META-INF/gitplex-plugin.properties";- public static final String ARTIFACT_PROPERTY_FILE = "gitplex-artifact.properties";+ public static final String ARTIFACT_PROPERTY_FILE = "META-INF/gitplex-artifact.properties";- public static final String BOOTSTRAP_PROPERTY_FILE = "gitplex-bootstrap.properties";+ public static final String BOOTSTRAP_PROPERTY_FILE = "META-INF/gitplex-bootstrap.properties";public static final String ARCHETYPE_RESOURCE = "archetype-resource/";diff --git a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.java b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.javaindex fc1c279dec..7c2eb230e5 100644--- a/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.java+++ b/plugin.maven/src/main/java/com/gitplex/plugin/maven/PluginUtils.java@@ -16,9 +16,9 @@ import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;-import java.util.zip.ZipEntry;-import java.util.zip.ZipFile;-import java.util.zip.ZipOutputStream;+import java.util.jar.JarEntry;+import java.util.jar.JarFile;+import java.util.jar.JarOutputStream;import org.apache.maven.artifact.Artifact;import org.apache.maven.artifact.DefaultArtifact;@@ -45,16 +45,16 @@ public class PluginUtils {public static boolean containsFile(File file, String path) {if (file.isFile() && file.getName().endsWith(".jar")) {- ZipFile zip = null;+ JarFile jar = null;try {- zip = new ZipFile(file);- return zip.getEntry(path) != null;+ jar = new JarFile(file);+ return jar.getJarEntry(path) != null;} catch (Exception e) {throw unchecked(e);} finally {- if (zip != null) {+ if (jar != null) {try {- zip.close();+ jar.close();} catch (IOException e) {}}@@ -68,14 +68,14 @@ public class PluginUtils {public static Properties loadProperties(File file, String path) {if (file.isFile() && file.getName().endsWith(".jar")) {- ZipFile zip = null;+ JarFile jar = null;try {- zip = new ZipFile(file);- ZipEntry entry = zip.getEntry(path);+ jar = new JarFile(file);+ JarEntry entry = jar.getJarEntry(path);if (entry != null) {InputStream is = null;try {- is = zip.getInputStream(entry);+ is = jar.getInputStream(entry);Properties props = new Properties();props.load(is);return props;@@ -92,9 +92,9 @@ public class PluginUtils {} catch (Exception e) {throw unchecked(e);} finally {- if (zip != null) {+ if (jar != null) {try {- zip.close();+ jar.close();} catch (IOException e) {}}@@ -347,6 +347,8 @@ public class PluginUtils {}public static void writeProperties(File file, Properties props) {+ if (!file.getParentFile().exists())+ file.getParentFile().mkdirs();OutputStream os = null;try {os = new FileOutputStream(file);@@ -453,7 +455,7 @@ public class PluginUtils {}}- public static void zipFile(ZipOutputStream zos, File file, int offset, boolean includeArchetypeResources) {+ public static void addFileToJar(JarOutputStream jos, File file, int offset, boolean includeArchetypeResources) {String entryName = file.getAbsolutePath().substring(offset + 1);if (File.separatorChar != '/')@@ -480,7 +482,7 @@ public class PluginUtils {return;try {- zos.putNextEntry(new ZipEntry(entryName));+ jos.putNextEntry(new JarEntry(entryName));} catch (IOException e) {throw new RuntimeException(e);}@@ -490,13 +492,13 @@ public class PluginUtils {FileInputStream is = null;try {is = new FileInputStream(file);- IOUtil.copy(is, zos);+ IOUtil.copy(is, jos);} finally {IOUtil.close(is);}- zos.flush();- zos.closeEntry();+ jos.flush();+ jos.closeEntry();} catch (IOException e) {throw new RuntimeException(e);}@@ -504,13 +506,10 @@ public class PluginUtils {}public static void listFiles(File dir, List<File> fileList) {- if (dir.listFiles().length == 0)- fileList.add(dir);for (File file : dir.listFiles()) {+ fileList.add(file);if (file.isDirectory())listFiles(file, fileList);- else- fileList.add(file);}}}diff --git a/server.product/src/test/java/com/gitplex/server/product/Test.java b/server.product/src/test/java/com/gitplex/server/product/Test.javaindex 5fbb527e2b..e8b9ebf116 100644--- a/server.product/src/test/java/com/gitplex/server/product/Test.java+++ b/server.product/src/test/java/com/gitplex/server/product/Test.java@@ -1,19 +1,11 @@package com.gitplex.server.product;import java.io.IOException;-import java.net.URL;-import java.util.Enumeration;--import com.gitplex.server.rest.RestModule;public class Test {@org.junit.Testpublic void test() throws IOException {- Enumeration<URL> resources = RestModule.class.getClassLoader().getResources("com/gitplex/server/rest");- while (resources.hasMoreElements()) {- System.out.println(resources.nextElement());- }}}\ No newline at end of file