use of org.gradle.api.GradleException in project meecrowave by apache.
the class MeecrowaveTask method doRun.
private void doRun() {
final Thread thread = Thread.currentThread();
final ClassLoader loader = thread.getContextClassLoader();
final AtomicBoolean running = new AtomicBoolean(false);
Thread hook = null;
AutoCloseable container;
try {
final Class<?> containerClass = loader.loadClass("org.apache.meecrowave.Meecrowave");
final Class<?> configClass = loader.loadClass("org.apache.meecrowave.Meecrowave$Builder");
final Object config = getConfig(configClass);
running.set(true);
container = AutoCloseable.class.cast(containerClass.getConstructor(configClass).newInstance(config));
final AutoCloseable finalContainer = container;
hook = new Thread() {
@Override
public void run() {
if (running.compareAndSet(true, false)) {
final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
thread.setContextClassLoader(loader);
try {
finalContainer.close();
} catch (final NoClassDefFoundError noClassDefFoundError) {
// debug cause it is too late to shutdown properly so don't pollute logs
getLogger().debug("can't stop Meecrowave", noClassDefFoundError);
} catch (final Exception e) {
getLogger().error("can't stop Meecrowave", e);
} finally {
thread.setContextClassLoader(old);
}
}
}
};
hook.setName("Meecrowave-Embedded-ShutdownHook");
Runtime.getRuntime().addShutdownHook(hook);
containerClass.getMethod("start").invoke(container);
final String fixedContext = ofNullable(context).orElse("");
if (webapp == null) {
containerClass.getMethod("deployClasspath", String.class).invoke(container, fixedContext);
} else {
containerClass.getMethod("deployWebapp", String.class, File.class).invoke(container, fixedContext, webapp);
}
getLogger().info("Meecrowave started on " + configClass.getMethod("getHost").invoke(config) + ":" + configClass.getMethod("getHttpPort").invoke(config));
} catch (final Exception e) {
ofNullable(hook).ifPresent(h -> {
try {
h.run();
} finally {
Runtime.getRuntime().removeShutdownHook(h);
}
});
throw new GradleException(e.getMessage(), e);
}
try {
String line;
final Scanner scanner = new Scanner(System.in);
while ((line = scanner.nextLine()) != null) {
final String cmd = line.trim().toLowerCase(Locale.ENGLISH);
switch(cmd) {
case "exit":
case "quit":
running.set(false);
try {
hook.run();
} finally {
Runtime.getRuntime().removeShutdownHook(hook);
}
return;
default:
getLogger().warn("Unknown: '" + cmd + "', use 'exit' or 'quit'");
}
}
} catch (final Exception e) {
Thread.interrupted();
} finally {
thread.setContextClassLoader(loader);
}
}
use of org.gradle.api.GradleException in project cayenne by apache.
the class DbGenerateTask method generateDb.
@TaskAction
public void generateDb() throws GradleException {
dataSource.validate();
getLogger().info("connection settings - [driver: {}, url: {}, username: {}]", dataSource.getDriver(), dataSource.getUrl(), dataSource.getUsername());
getLogger().info("generator options - " + "[dropTables: {}, dropPK: {}, createTables: {}, createPK: {}, createFK: {}]", dropTables, dropPK, createTables, createPK, createFK);
Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()));
try {
DbGenerator generator = createGenerator(loadDataMap(injector));
generator.runGenerator(createDataSource());
} catch (Exception ex) {
Throwable th = Util.unwindException(ex);
String message = "Error generating database";
if (th.getLocalizedMessage() != null) {
message += ": " + th.getLocalizedMessage();
}
getLogger().error(message);
throw new GradleException(message, th);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class DefaultTestReport method generateFiles.
private void generateFiles(AllTestResults model, final TestResultsProvider resultsProvider, final File reportDir) {
try {
HtmlReportRenderer htmlRenderer = new HtmlReportRenderer();
buildOperationExecutor.run(new RunnableBuildOperation() {
@Override
public void run(BuildOperationContext context) {
// Clean-up old HTML report directories
GFileUtils.deleteQuietly(new File(reportDir, "packages"));
GFileUtils.deleteQuietly(new File(reportDir, "classes"));
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName("Delete old HTML results");
}
});
htmlRenderer.render(model, new ReportRenderer<AllTestResults, HtmlReportBuilder>() {
@Override
public void render(final AllTestResults model, final HtmlReportBuilder output) throws IOException {
buildOperationExecutor.runAll(new Action<BuildOperationQueue<HtmlReportFileGenerator<? extends CompositeTestResults>>>() {
@Override
public void execute(BuildOperationQueue<HtmlReportFileGenerator<? extends CompositeTestResults>> queue) {
queue.add(generator("index.html", model, new OverviewPageRenderer(), output));
for (PackageTestResults packageResults : model.getPackages()) {
queue.add(generator(packageResults.getBaseUrl(), packageResults, new PackagePageRenderer(), output));
for (ClassTestResults classResults : packageResults.getClasses()) {
queue.add(generator(classResults.getBaseUrl(), classResults, new ClassPageRenderer(resultsProvider), output));
}
}
}
});
}
}, reportDir);
} catch (Exception e) {
throw new GradleException(String.format("Could not generate test report to '%s'.", reportDir), e);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class AbstractTestFrameworkDetector method classVisitor.
protected TestClassVisitor classVisitor(final File testClassFile) {
final TestClassVisitor classVisitor = createClassVisitor();
InputStream classStream = null;
try {
classStream = new BufferedInputStream(new FileInputStream(testClassFile));
final ClassReader classReader = new PatchedClassReader(IOUtils.toByteArray(classStream));
classReader.accept(classVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
} catch (Throwable e) {
throw new GradleException("failed to read class file " + testClassFile.getAbsolutePath(), e);
} finally {
IOUtils.closeQuietly(classStream);
}
return classVisitor;
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class TestNGTestClassProcessor method runTests.
private void runTests() {
TestNG testNg = new TestNG();
testNg.setOutputDirectory(testReportDir.getAbsolutePath());
testNg.setDefaultSuiteName(options.getDefaultSuiteName());
testNg.setDefaultTestName(options.getDefaultTestName());
if (options.getParallel() != null) {
testNg.setParallel(options.getParallel());
}
if (options.getThreadCount() > 0) {
testNg.setThreadCount(options.getThreadCount());
}
invokeVerifiedMethod(testNg, "setConfigFailurePolicy", String.class, options.getConfigFailurePolicy(), DEFAULT_CONFIG_FAILURE_POLICY);
invokeVerifiedMethod(testNg, "setPreserveOrder", boolean.class, options.getPreserveOrder(), false);
invokeVerifiedMethod(testNg, "setGroupByInstances", boolean.class, options.getGroupByInstances(), false);
testNg.setUseDefaultListeners(options.getUseDefaultListeners());
testNg.setVerbose(0);
testNg.setGroups(CollectionUtils.join(",", options.getIncludeGroups()));
testNg.setExcludedGroups(CollectionUtils.join(",", options.getExcludeGroups()));
// this way, custom listeners are more powerful and, for example, they can change test status.
for (String listenerClass : options.getListeners()) {
try {
testNg.addListener(applicationClassLoader.loadClass(listenerClass).newInstance());
} catch (Throwable e) {
throw new GradleException(String.format("Could not add a test listener with class '%s'.", listenerClass), e);
}
}
if (!options.getIncludedTests().isEmpty() || !options.getIncludedTestsCommandLine().isEmpty()) {
testNg.addListener(new SelectedTestsFilter(options.getIncludedTests(), options.getIncludedTestsCommandLine()));
}
if (!suiteFiles.isEmpty()) {
testNg.setTestSuites(GFileUtils.toPaths(suiteFiles));
} else {
testNg.setTestClasses(testClasses.toArray(new Class[0]));
}
testNg.addListener((Object) adaptListener(new TestNGTestResultProcessorAdapter(resultProcessor, idGenerator, clock)));
testNg.run();
}
Aggregations