Răsfoiți Sursa

修改部署方式

roo00 7 ani în urmă
părinte
comite
56ef113d7e

+ 0 - 6
o2server/x_base_core_project/src/main/java/com/x/base/core/entity/StorageObject.java

@@ -36,12 +36,6 @@ public abstract class StorageObject extends SliceJpaObject {
 			synchronized (StorageObject.class) {
 				if (FILESYSTEMANAGERINSTANCE == null) {
 					StandardFileSystemManager fs = new StandardFileSystemManager();
-					// DefaultFileSystemManager fs = new
-					// DefaultFileSystemManager();
-					// File file = new File(Config.base(), "local/temp/vfs");
-					// FileUtils.forceMkdir(file);
-					// fs.setTemporaryFileStore(new
-					// DefaultFileReplicator(file));
 					fs.setFilesCache(new NullFilesCache());
 					fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
 					fs.init();

+ 32 - 14
o2server/x_base_core_project/src/main/java/com/x/base/core/project/Context.java

@@ -8,7 +8,6 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletRequest;
 
-import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.openjpa.enhance.PCRegistry;
 import org.quartz.CronScheduleBuilder;
 import org.quartz.DateBuilder;
@@ -26,7 +25,6 @@ import org.quartz.impl.matchers.EverythingMatcher;
 
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.JpaObject;
-import com.x.base.core.entity.StorageType;
 import com.x.base.core.project.config.Config;
 import com.x.base.core.project.config.DataMappings;
 import com.x.base.core.project.config.StorageMappings;
@@ -97,13 +95,33 @@ public class Context extends AbstractContext {
 		return this.clazz;
 	}
 
-	/** 随机令牌 */
+	private Deployable clazzInstance;
+
+	public Deployable clazzInstance() {
+		return this.clazzInstance;
+	}
+
+	/* 随机令牌 */
 	private volatile String token;
 
 	public String token() {
 		return this.token;
 	}
 
+	/* contextPath */
+	private volatile String contextPath;
+
+	public String contextPath() {
+		return this.contextPath;
+	}
+
+	/* title */
+	private volatile String name;
+
+	public String name() {
+		return this.name;
+	}
+
 	/* Storage资源 */
 	private volatile StorageMappings storageMappings;
 
@@ -170,15 +188,17 @@ public class Context extends AbstractContext {
 	}
 
 	public static Context concrete(ServletContextEvent servletContextEvent) throws Exception {
-		/** 强制忽略ssl服务器认证 */
-		// HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
+		/* 强制忽略ssl服务器认证 */
 		SslTools.ignoreSsl();
 		ServletContext servletContext = servletContextEvent.getServletContext();
 		Context context = new Context();
+		context.contextPath = servletContext.getContextPath();
+		context.clazz = Class.forName(servletContext.getInitParameter(INITPARAMETER_PORJECT));
+		context.clazzInstance = (Deployable) context.clazz.newInstance();
+		context.name = getName(context.clazz);
 		context.path = servletContext.getRealPath("");
 		context.servletContext = servletContext;
 		context.servletContextName = servletContext.getServletContextName();
-		context.clazz = Class.forName(Packages.com_x_base_core_project_dot + context.servletContextName);
 		context.weight = Config.currentNode().getApplication().weight(context.clazz);
 		context.sslEnable = Config.currentNode().getApplication().getSslEnable();
 		context.initDatasFromCenters();
@@ -262,10 +282,9 @@ public class Context extends AbstractContext {
 	}
 
 	private void initDatasFromCenters() throws Exception {
-		@SuppressWarnings("unchecked")
-		List<String> containerEntities = (List<String>) FieldUtils.readStaticField(clazz, "containerEntities");
-		if (ListTools.isNotEmpty(containerEntities)) {
-			logger.print("{} loading datas, entity size:{}.", this.clazz.getName(), containerEntities.size());
+		if (ListTools.isNotEmpty(clazzInstance.dependency.containerEntities)) {
+			logger.print("{} loading datas, entity size:{}.", this.clazz.getName(),
+					clazzInstance.dependency.containerEntities.size());
 			DataMappings dataMappings = null;
 			do {
 				try {
@@ -282,10 +301,9 @@ public class Context extends AbstractContext {
 	}
 
 	private void initStoragesFromCenters() throws Exception {
-		@SuppressWarnings("unchecked")
-		List<StorageType> usedStorageTypes = (List<StorageType>) FieldUtils.readStaticField(clazz, "usedStorageTypes");
-		if (ListTools.isNotEmpty(usedStorageTypes)) {
-			logger.print("{} loading storages, type size:{}.", this.clazz.getName(), usedStorageTypes.size());
+		if (ListTools.isNotEmpty(clazzInstance.dependency.storageTypes)) {
+			logger.print("{} loading storages, type size:{}.", this.clazz.getName(),
+					clazzInstance.dependency.storageTypes.size());
 			StorageMappings storageMappings = null;
 			do {
 				try {

+ 1 - 165
o2server/x_base_core_project/src/main/java/com/x/base/core/project/ServiceA.java

@@ -1,169 +1,5 @@
 package com.x.base.core.project;
 
-import java.io.File;
-import java.util.Collection;
-import java.util.TreeMap;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.WildcardFileFilter;
-import org.apache.commons.lang3.StringUtils;
-
-import com.x.base.core.project.gson.XGsonBuilder;
-import com.x.base.core.project.tools.JarTools;
-
 public abstract class ServiceA extends Deployable {
-	private File concreteStructure(String distPath, String repositoryPath) throws Exception {
-		File dir = new File(distPath, this.getName());
-		FileUtils.forceMkdir(dir);
-		FileUtils.cleanDirectory(dir);
-		File webInf = new File(dir, "WEB-INF");
-		FileUtils.forceMkdir(webInf);
-		File lib = new File(webInf, "lib");
-		FileUtils.forceMkdir(lib);
-		File classes = new File(webInf, "classes");
-		FileUtils.forceMkdir(classes);
-		File metaInf = new File(classes, "META-INF");
-		FileUtils.forceMkdir(metaInf);
-		this.copyPersistence(metaInf, repositoryPath);
-		this.copyJar_independent(lib, repositoryPath);
-		this.extractJar(classes, repositoryPath);
-		this.extractZip(dir, repositoryPath);
-		this.createWebXml(webInf);
-		return dir;
-	}
-
-	private void createCenterServerFile(File metaInf, String host, Integer port, String cipher) throws Exception {
-		TreeMap<String, Object> map = new TreeMap<>();
-		map.put("host", StringUtils.trimToEmpty(host));
-		map.put("port", null != port ? port : 20080);
-		map.put("cipher", cipher);
-		FileUtils.writeStringToFile(new File(metaInf, "centerServer.json"), XGsonBuilder.toJson(map));
-	}
-
-	private void createConfigFile(File metaInf, String configApplicationServer) throws Exception {
-		TreeMap<String, Object> map = new TreeMap<>();
-		map.put("applicationServer", StringUtils.trimToEmpty(configApplicationServer));
-		FileUtils.writeStringToFile(new File(metaInf, "config.json"), XGsonBuilder.toJson(map));
-	}
-
-	private void copyJar_independent(File lib, String repositoryPath) throws Exception {
-		File repositoryLib = new File(repositoryPath);
-		FileUtils.copyDirectory(repositoryLib, lib, new WildcardFileFilter("x_base_core*.jar"));
-		FileUtils.copyDirectory(repositoryLib, lib, new WildcardFileFilter("x_common_core*.jar"));
-		FileUtils.copyDirectory(new File(repositoryLib, "openjpa"), lib, new WildcardFileFilter("*.jar"));
-		FileUtils.copyDirectory(new File(repositoryLib, "ehcache"), lib, new WildcardFileFilter("*.jar"));
-		FileUtils.copyDirectory(new File(repositoryLib, "slf4j"), lib, new WildcardFileFilter("*.jar"));
-	}
-
-	private void copyPersistence(File metaInf, String repositoryPath) throws Exception {
-		FileUtils.copyFile(new File(repositoryPath, "x_persistence_" + this.getName() + ".xml"),
-				new File(metaInf, "x_persistence.xml"), false);
-	}
-
-	private void createWebXml(File webInf) throws Exception {
-		String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<web-app id=\"" + this.getName()
-				+ "\" metadata-complete=\"false\" version=\"3.0\">" + "<display-name>" + this.getName()
-				+ "</display-name>";
-		xml += druid_servlet;
-		xml += druid_servlet_mapping;
-		xml += druid_filter;
-		xml += druid_filter_mapping;
-		xml += "</web-app>";
-		File file = new File(webInf, "web.xml");
-		FileUtils.writeStringToFile(file, xml, "UTF-8");
-	}
-
-	private void extractJar(File classes, String repositoryPath) throws Exception {
-		File repositoryLib = new File(repositoryPath);
-		Collection<File> files = FileUtils.listFiles(repositoryLib, new WildcardFileFilter(this.getName() + "*.jar"),
-				null);
-		JarTools.unjar(files.iterator().next(), "", classes, true);
-	}
-
-	private void extractZip(File dir, String repositoryPath) throws Exception {
-		File file = new File(repositoryPath, this.getName() + ".zip");
-		JarTools.unjar(file, "", dir, true);
-	}
-
-	@Override
-	public String pack(String distPath, String repositoryPath) throws Exception {
-		File dir = this.concreteStructure(distPath, repositoryPath);
-		custom(dir, repositoryPath);
-		File war = new File(distPath, this.getName() + ".war");
-		JarTools.jar(dir, war);
-		return war.getAbsolutePath();
-	}
-
-	protected abstract void custom(File dir, String repositoryPath) throws Exception;
-
-	protected String getName() {
-		return StringUtils.replace(this.getClass().getSimpleName(), ".", "_");
-	}
-
-	public class Argument {
-		private String distPath;
-		private String repositoryPath;
-		private String resourcesPath;
-		private String centerHost;
-		private Integer centerPort;
-		private String centerCipher;
-		private String configApplicationServer;
-
-		public String getDistPath() {
-			return distPath;
-		}
-
-		public void setDistPath(String distPath) {
-			this.distPath = distPath;
-		}
-
-		public String getRepositoryPath() {
-			return repositoryPath;
-		}
-
-		public void setRepositoryPath(String repositoryPath) {
-			this.repositoryPath = repositoryPath;
-		}
-
-		public String getResourcesPath() {
-			return resourcesPath;
-		}
-
-		public void setResourcesPath(String resourcesPath) {
-			this.resourcesPath = resourcesPath;
-		}
-
-		public String getCenterHost() {
-			return centerHost;
-		}
-
-		public void setCenterHost(String centerHost) {
-			this.centerHost = centerHost;
-		}
-
-		public Integer getCenterPort() {
-			return centerPort;
-		}
-
-		public void setCenterPort(Integer centerPort) {
-			this.centerPort = centerPort;
-		}
-
-		public String getCenterCipher() {
-			return centerCipher;
-		}
-
-		public void setCenterCipher(String centerCipher) {
-			this.centerCipher = centerCipher;
-		}
-
-		public String getConfigApplicationServer() {
-			return configApplicationServer;
-		}
-
-		public void setConfigApplicationServer(String configApplicationServer) {
-			this.configApplicationServer = configApplicationServer;
-		}
-
-	}
+ 
 }

+ 5 - 0
o2server/x_collaboration_service_message/src/main/webapp/WEB-INF/web.xml

@@ -2,4 +2,9 @@
 <web-app id="x_collaboration_service_message"
 	metadata-complete="false" version="3.0">
 	<display-name>x_collaboration_service_message</display-name>
+	<context-param>
+		<param-name>project</param-name>
+		<param-value>com.x.base.core.project.x_collaboration_service_message
+		</param-value>
+	</context-param>
 </web-app>

+ 7 - 2
o2server/x_component_assemble_control/src/main/webapp/WEB-INF/web.xml

@@ -1,5 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<web-app id="x_component_assemble_control" metadata-complete="false"
-	version="3.0">
+<web-app id="x_component_assemble_control"
+	metadata-complete="false" version="3.0">
 	<display-name>x_component_assemble_control</display-name>
+	<context-param>
+		<param-name>project</param-name>
+		<param-value>com.x.base.core.project.x_component_assemble_control
+		</param-value>
+	</context-param>
 </web-app>