Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.
*/
package org.jooby.run;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.WatchEvent.Kind;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.LongStream;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleClassLoader;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoader;
import org.jboss.modules.log.ModuleLogger;
public class Main {
private static boolean DEBUG;
private static boolean TRACE;
static {
logLevel();
}
private AppModuleLoader loader;
private ExecutorService executor;
private Watcher scanner;
private PathMatcher includes;
private PathMatcher excludes;
private volatile Object app;
private AtomicReference hash = new AtomicReference("");
private ModuleIdentifier mId;
private String mainClass;
private volatile Module module;
private List args;
private AtomicBoolean starting = new AtomicBoolean(false);
private Path[] watchDirs;
public Main(final String mId, final String mainClass, final List watchDirs,
final File... cp) throws Exception {
this.mainClass = mainClass;
loader = AppModuleLoader.build(mId, cp);
this.mId = ModuleIdentifier.create(mId);
this.watchDirs = toPath(watchDirs);
this.executor = Executors.newSingleThreadExecutor(task -> new Thread(task, "HotSwap"));
this.scanner = new Watcher(this::onChange, this.watchDirs);
includes("**/*.class" + File.pathSeparator + "**/*.conf" + File.pathSeparator
+ "**/*.properties" + File.pathSeparator + "*.js" + File.pathSeparator + "src/*.js");
excludes("");
}
private Path[] toPath(final List watchDir) throws IOException {
Set files = new LinkedHashSet<>();
files.add(new File(System.getProperty("user.dir")));
if (watchDir != null) {
files.addAll(watchDir);
}
List paths = new ArrayList<>();
for (File file : files) {
if (file.exists()) {
paths.add(file.getCanonicalFile().toPath());
}
}
return paths.toArray(new Path[paths.size()]);
}
public static void main(final String[] args) throws Exception {
List cp = new ArrayList();
List watch = new ArrayList();
String includes = null;
String excludes = null;
for (int i = 2; i < args.length; i++) {
String[] option = args[i].split("=");
if (option.length < 2) {
throw new IllegalArgumentException("Unknown option: " + args[i]);
}
String name = option[0].toLowerCase();
switch (name) {
case "includes":
includes = option[1];
break;
case "excludes":
excludes = option[1];
break;
case "props":
setSystemProperties(new File(option[1]));
break;
case "deps":
String[] deps = option[1].split(File.pathSeparator);
for (String dep : deps) {
cp.add(new File(dep));
}
break;
case "watchdirs":
String[] dirs = option[1].split(File.pathSeparator);
for (String dir : dirs) {
watch.add(new File(dir));
}
break;
default:
throw new IllegalArgumentException("Unknown option: " + args[i]);
}
}
// set log level, once we call setSystemProps
logLevel();
if (cp.isEmpty()) {
cp.add(new File(System.getProperty("user.dir")));
}
Main launcher = new Main(args[0], args[1], watch, cp.toArray(new File[cp.size()]));
if (includes != null) {
launcher.includes(includes);
}
if (excludes != null) {
launcher.excludes(excludes);
}
launcher.run();
}
private static void setSystemProperties(final File sysprops) throws IOException {
try (InputStream in = new FileInputStream(sysprops)) {
Properties properties = new Properties();
properties.load(in);
for (Entry