From 4aaeed56866b5fdea364579508502779d1c8564a Mon Sep 17 00:00:00 2001 From: Denghui Dong Date: Mon, 16 Oct 2023 14:50:40 +0800 Subject: [PATCH] fix: test failure --- .../org/eclipse/jifa/server/Launcher.java | 54 --------------- .../eclipse/jifa/server/ReadyListener.java | 68 +++++++++++++++++++ 2 files changed, 68 insertions(+), 54 deletions(-) create mode 100644 server/src/main/java/org/eclipse/jifa/server/ReadyListener.java diff --git a/server/src/main/java/org/eclipse/jifa/server/Launcher.java b/server/src/main/java/org/eclipse/jifa/server/Launcher.java index e0a66b75..311370bc 100644 --- a/server/src/main/java/org/eclipse/jifa/server/Launcher.java +++ b/server/src/main/java/org/eclipse/jifa/server/Launcher.java @@ -12,23 +12,12 @@ ********************************************************************************/ package org.eclipse.jifa.server; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.jifa.server.enums.FileType; -import org.eclipse.jifa.server.enums.Role; -import org.eclipse.jifa.server.service.AnalysisApiService; -import org.eclipse.jifa.server.service.FileService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.EnableTransactionManagement; -import java.io.IOException; -import java.nio.file.Path; - @SpringBootApplication @EnableConfigurationProperties({Configuration.class}) @EnableTransactionManagement @@ -38,47 +27,4 @@ public class Launcher { public static void main(String[] args) { SpringApplication.run(Launcher.class, args); } - - @Component - @Slf4j - static class ReadyListener extends ConfigurationAccessor { - - private final AnalysisApiService analysisApiService; - - private final FileService fileService; - - ReadyListener(AnalysisApiService analysisApiService, FileService fileService) { - this.analysisApiService = analysisApiService; - this.fileService = fileService; - } - - @EventListener(ApplicationReadyEvent.class) - public void fireReadyEvent() { - //noinspection HttpUrlsUsage - log.info("Jifa Server: http://{}:{}", "localhost", config.getPort()); - - if (config.getRole() == Role.STANDALONE_WORKER) { - Path[] paths = config.getInputFiles(); - if (paths != null) { - for (Path path : paths) { - try { - FileType type = analysisApiService.deduceFileType(path); - if (type != null) { - String uniqueName = fileService.handleLocalFileRequest(type, path); - //noinspection HttpUrlsUsage - log.info("{}: http://{}:{}/{}/{}", - path.getFileName(), - "localhost", - config.getPort(), - type.getAnalysisUrlPath(), - uniqueName); - } - } catch (IOException e) { - log.error("Failed to handle input file '{}': {}", path, e.getMessage()); - } - } - } - } - } - } } \ No newline at end of file diff --git a/server/src/main/java/org/eclipse/jifa/server/ReadyListener.java b/server/src/main/java/org/eclipse/jifa/server/ReadyListener.java new file mode 100644 index 00000000..0e702961 --- /dev/null +++ b/server/src/main/java/org/eclipse/jifa/server/ReadyListener.java @@ -0,0 +1,68 @@ +/******************************************************************************** + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ +package org.eclipse.jifa.server; + +import lombok.extern.slf4j.Slf4j; +import org.eclipse.jifa.server.enums.FileType; +import org.eclipse.jifa.server.enums.Role; +import org.eclipse.jifa.server.service.AnalysisApiService; +import org.eclipse.jifa.server.service.FileService; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.nio.file.Path; + +@Component +@Slf4j +class ReadyListener extends ConfigurationAccessor { + + private final AnalysisApiService analysisApiService; + + private final FileService fileService; + + ReadyListener(AnalysisApiService analysisApiService, FileService fileService) { + this.analysisApiService = analysisApiService; + this.fileService = fileService; + } + + @EventListener(ApplicationReadyEvent.class) + public void fireReadyEvent() { + //noinspection HttpUrlsUsage + log.info("Jifa Server: http://{}:{}", "localhost", config.getPort()); + + if (config.getRole() == Role.STANDALONE_WORKER) { + Path[] paths = config.getInputFiles(); + if (paths != null) { + for (Path path : paths) { + try { + FileType type = analysisApiService.deduceFileType(path); + if (type != null) { + String uniqueName = fileService.handleLocalFileRequest(type, path); + //noinspection HttpUrlsUsage + log.info("{}: http://{}:{}/{}/{}", + path.getFileName(), + "localhost", + config.getPort(), + type.getAnalysisUrlPath(), + uniqueName); + } + } catch (IOException e) { + log.error("Failed to handle input file '{}': {}", path, e.getMessage()); + } + } + } + } + } +}