提交 76d6c103 编写于 作者: Z zhourui

增加lib目录支持

上级 69b92500
......@@ -16,6 +16,7 @@ import javax.persistence.Query;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
......@@ -38,6 +39,7 @@ import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.NumberTools;
import com.x.base.core.project.tools.StringTools;
public class EntityManagerContainer extends EntityManagerContainerBasic {
......@@ -1905,4 +1907,30 @@ public class EntityManagerContainer extends EntityManagerContainerBasic {
return list;
}
public <T extends JpaObject> Long clean(Class<T> cls, Integer batchSize) throws Exception {
Long count = 0L;
EntityManager em = this.get(cls);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<T> root = cq.from(cls);
cq.select(root.get(JpaObject.id_FIELDNAME));
List<String> ids;
do {
ids = em.createQuery(cq).setMaxResults(NumberTools.nullOrLessThan(batchSize, 1) ? 500 : batchSize)
.getResultList();
if (!ids.isEmpty()) {
em.getTransaction().begin();
for (String id : ids) {
T t = em.find(cls, id);
if (null != t) {
em.remove(t);
count++;
}
}
em.getTransaction().commit();
}
} while (!ids.isEmpty());
return count;
}
}
\ No newline at end of file
package com.x.server.console.server;
import java.io.File;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
......@@ -65,7 +70,7 @@ public abstract class JettySeverTools {
FileUtils.cleanDirectory(dir);
}
protected static String calculateExtraClassPath(Class<?> cls) throws Exception {
protected static String calculateExtraClassPath(Class<?> cls, Path... paths) throws Exception {
List<String> jars = new ArrayList<>();
jars.addAll(calculateExtraClassPathDefault());
Module module = cls.getAnnotation(Module.class);
......@@ -87,6 +92,15 @@ public abstract class JettySeverTools {
jars.add(file.getAbsolutePath());
}
}
for (Path path : paths) {
if (Files.exists(path) && Files.isDirectory(path)) {
try (Stream<Path> stream = Files.walk(path, FileVisitOption.FOLLOW_LINKS)) {
stream.filter(Files::isRegularFile)
.filter(p -> p.toAbsolutePath().toString().toLowerCase().endsWith(".jar"))
.forEach(p -> jars.add(p.toAbsolutePath().toString()));
}
}
}
return StringUtils.join(jars, ";");
}
......
......@@ -2,6 +2,7 @@ package com.x.server.console.server.application;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
......@@ -22,6 +23,7 @@ import javax.xml.xpath.XPathFactory;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.eclipse.jetty.quickstart.QuickStartWebApp;
......@@ -65,7 +67,6 @@ import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType;
import com.x.base.core.project.config.ApplicationServer;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
......@@ -126,7 +127,7 @@ public class ApplicationServerTools extends JettySeverTools {
webApp.setResourceBase(dir.getAbsolutePath());
webApp.setDescriptor(new File(dir, "WEB-INF/web.xml").getAbsolutePath());
webApp.setExtraClasspath(calculateExtraClassPath(clz));
//webApp.getMimeTypes().addMimeMapping("wcss", "application/json");
// webApp.getMimeTypes().addMimeMapping("wcss", "application/json");
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", "true");
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
......@@ -161,12 +162,12 @@ public class ApplicationServerTools extends JettySeverTools {
webApp.setContextPath("/" + name);
webApp.setResourceBase(dir.getAbsolutePath());
webApp.setDescriptor(dir + "/WEB-INF/web.xml");
webApp.setExtraClasspath(calculateExtraClassPath(cls));
webApp.setExtraClasspath(calculateExtraClassPath(cls, dir.toPath().resolve("WEB-INF/lib")));
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", "true");
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
/* stat */
if (applicationServer.getStatEnable()) {
if (BooleanUtils.isTrue(applicationServer.getStatEnable())) {
FilterHolder statFilterHolder = new FilterHolder(new WebStatFilter());
statFilterHolder.setInitParameter("exclusions", applicationServer.getStatExclusions());
webApp.addFilter(statFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
......@@ -187,7 +188,7 @@ public class ApplicationServerTools extends JettySeverTools {
Server server = new Server(threadPool);
server.setAttribute("maxFormContentSize", applicationServer.getMaxFormContent() * 1024 * 1024);
if (applicationServer.getSslEnable()) {
if (BooleanUtils.isTrue(applicationServer.getSslEnable())) {
addHttpsConnector(server, applicationServer.getPort());
} else {
addHttpConnector(server, applicationServer.getPort());
......@@ -292,7 +293,7 @@ public class ApplicationServerTools extends JettySeverTools {
}
}
private static void modified(File war, File dir) throws Exception {
private static void modified(File war, File dir) throws IOException {
File lastModified = new File(dir, "WEB-INF/lastModified");
if ((!lastModified.exists()) || lastModified.isDirectory() || (war.lastModified() != NumberUtils
.toLong(FileUtils.readFileToString(lastModified, DefaultCharset.charset_utf_8), 0))) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册