mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
Merge branch 'custom-di'
This commit is contained in:
commit
52219eddae
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
- name: Deps
|
||||
run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install wine32
|
||||
- name: Build
|
||||
run: xvfb-run -a ./gradlew test all
|
||||
run: xvfb-run -a ./gradlew --info test all
|
||||
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
|
||||
3
.idea/gradle.xml
generated
3
.idea/gradle.xml
generated
@ -4,7 +4,8 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="disableWrapperSourceDistributionNotification" value="true" />
|
||||
<option name="delegatedBuild" value="false" />
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
|
||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="FieldMayBeFinal" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
||||
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
</project>
|
||||
@ -38,8 +38,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.google.dagger:dagger:2.19'
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.19'
|
||||
// compile with current platform's SWT, but bundle a different one for each binary
|
||||
compileOnly files("lib/swt-${platform}.jar")
|
||||
compileOnly files('lib/jna.jar')
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
package net.azib.ipscan;
|
||||
|
||||
import net.azib.ipscan.config.*;
|
||||
import net.azib.ipscan.di.Injector;
|
||||
import net.azib.ipscan.gui.GUI;
|
||||
import net.azib.ipscan.gui.InfoDialog;
|
||||
import net.azib.ipscan.gui.MacApplicationMenu;
|
||||
import net.azib.ipscan.util.GoogleAnalytics;
|
||||
|
||||
import java.security.Security;
|
||||
@ -49,13 +51,13 @@ public class Main {
|
||||
Labels.initialize(locale);
|
||||
LOG.finer("Labels and Config initialized after " + (System.currentTimeMillis() - startTime));
|
||||
|
||||
MainComponent mainComponent = DaggerMainComponent.create();
|
||||
if (Platform.MAC_OS) mainComponent.createMacApplicationMenu();
|
||||
Injector injector = new ComponentRegistry().init();
|
||||
if (Platform.MAC_OS) injector.require(MacApplicationMenu.class);
|
||||
LOG.finer("Components initialized after " + (System.currentTimeMillis() - startTime));
|
||||
|
||||
processCommandLine(args, mainComponent);
|
||||
processCommandLine(args, injector);
|
||||
|
||||
gui.showMainWindow(mainComponent);
|
||||
gui.showMainWindow(injector);
|
||||
|
||||
Config.getConfig().store();
|
||||
gui.close();
|
||||
@ -100,9 +102,9 @@ public class Main {
|
||||
Security.setProperty("networkaddress.cache.negative.ttl", "0");
|
||||
}
|
||||
|
||||
private static void processCommandLine(String[] args, MainComponent mainComponent) {
|
||||
private static void processCommandLine(String[] args, Injector injector) {
|
||||
if (args.length != 0) {
|
||||
CommandLineProcessor cli = mainComponent.createCommandLineProcessor();
|
||||
CommandLineProcessor cli = injector.require(CommandLineProcessor.class);
|
||||
try {
|
||||
cli.parse(args);
|
||||
}
|
||||
|
||||
@ -17,8 +17,6 @@ import net.azib.ipscan.exporters.ExporterRegistry;
|
||||
import net.azib.ipscan.feeders.FeederCreator;
|
||||
import net.azib.ipscan.feeders.FeederRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@ -26,9 +24,8 @@ import java.io.File;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class CommandLineProcessor implements CommandProcessor, StateTransitionListener {
|
||||
private final FeederRegistry<? extends FeederCreator> feederRegistry;
|
||||
private final FeederRegistry feederRegistry;
|
||||
private final ExporterRegistry exporters;
|
||||
private StateMachine stateMachine;
|
||||
private ScanningResultList scanningResults;
|
||||
@ -42,12 +39,12 @@ public class CommandLineProcessor implements CommandProcessor, StateTransitionLi
|
||||
boolean autoQuit;
|
||||
boolean appendToFile;
|
||||
|
||||
CommandLineProcessor(FeederRegistry<? extends FeederCreator> feederCreators, ExporterRegistry exporters) {
|
||||
CommandLineProcessor(FeederRegistry feederCreators, ExporterRegistry exporters) {
|
||||
this.feederRegistry = feederCreators;
|
||||
this.exporters = exporters;
|
||||
}
|
||||
|
||||
@Inject public CommandLineProcessor(FeederRegistry<? extends FeederCreator> feederCreators, ExporterRegistry exporters, StateMachine stateMachine, ScanningResultList scanningResults) {
|
||||
public CommandLineProcessor(FeederRegistry feederCreators, ExporterRegistry exporters, StateMachine stateMachine, ScanningResultList scanningResults) {
|
||||
this(feederCreators, exporters);
|
||||
this.stateMachine = stateMachine;
|
||||
this.scanningResults = scanningResults;
|
||||
|
||||
@ -10,8 +10,6 @@ import net.azib.ipscan.core.ScanningResult;
|
||||
import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.fetchers.MACFetcher;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.net.InetAddress;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
@ -20,11 +18,10 @@ import java.util.prefs.Preferences;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class CommentsConfig {
|
||||
private Preferences preferences;
|
||||
|
||||
@Inject public CommentsConfig(Preferences preferences) {
|
||||
public CommentsConfig(Preferences preferences) {
|
||||
// use a separate node for comments - they can get large
|
||||
this.preferences = preferences.node("comments");
|
||||
}
|
||||
|
||||
@ -5,101 +5,55 @@
|
||||
*/
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import net.azib.ipscan.core.Plugin;
|
||||
import net.azib.ipscan.core.PluginLoader;
|
||||
import net.azib.ipscan.core.state.StateMachine;
|
||||
import net.azib.ipscan.exporters.*;
|
||||
import net.azib.ipscan.feeders.FeederCreator;
|
||||
import net.azib.ipscan.di.Injector;
|
||||
import net.azib.ipscan.exporters.CSVExporter;
|
||||
import net.azib.ipscan.exporters.IPListExporter;
|
||||
import net.azib.ipscan.exporters.TXTExporter;
|
||||
import net.azib.ipscan.exporters.XMLExporter;
|
||||
import net.azib.ipscan.feeders.FeederRegistry;
|
||||
import net.azib.ipscan.fetchers.*;
|
||||
import net.azib.ipscan.gui.SWTAwareStateMachine;
|
||||
import net.azib.ipscan.gui.feeders.*;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
/**
|
||||
* This class is the dependency injection configuration using Dagger2.
|
||||
* This class is the dependency injection configuration
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Module
|
||||
public class ComponentRegistry {
|
||||
|
||||
@Provides @Singleton public Display getDisplay() {
|
||||
return Display.getDefault();
|
||||
public void register(Injector i) {
|
||||
Display display = Display.getDefault();
|
||||
i.register(Display.class, display);
|
||||
Shell shell = new Shell();
|
||||
i.register(Shell.class, shell);
|
||||
i.register(Menu.class, new Menu(shell, SWT.BAR));
|
||||
i.register(FeederSelectionCombo.class, new FeederSelectionCombo(i.require(ControlsArea.class)));
|
||||
i.register(Button.class, new Button(i.require(ControlsArea.class), SWT.NONE));
|
||||
SWTAwareStateMachine stateMachine = new SWTAwareStateMachine(display);
|
||||
i.register(SWTAwareStateMachine.class, stateMachine);
|
||||
i.register(StateMachine.class, stateMachine);
|
||||
i.register(RangeFeederGUI.class, RandomFeederGUI.class, FileFeederGUI.class);
|
||||
i.register(TXTExporter.class, CSVExporter.class, XMLExporter.class, IPListExporter.class);
|
||||
i.register(IPFetcher.class, PingFetcher.class, PingTTLFetcher.class, HostnameFetcher.class, PortsFetcher.class,
|
||||
FilteredPortsFetcher.class, WebDetectFetcher.class, HTTPSenderFetcher.class, CommentFetcher.class,
|
||||
NetBIOSInfoFetcher.class, PacketLossFetcher.class, HTTPProxyFetcher.class);
|
||||
i.register(MACFetcher.class, Platform.WINDOWS ? new WinMACFetcher() : new UnixMACFetcher());
|
||||
i.register(MACVendorFetcher.class);
|
||||
i.register(FeederRegistry.class, i.require(FeederGUIRegistry.class));
|
||||
}
|
||||
|
||||
@Provides @Singleton public Shell mainShell() {
|
||||
return new Shell();
|
||||
}
|
||||
|
||||
@Provides @Named("mainMenu") @Singleton public Menu mainMenu(Shell mainShell) {
|
||||
return new Menu(mainShell, SWT.BAR);
|
||||
}
|
||||
|
||||
@Provides @Named("feederArea") @Singleton public Composite feederArea(Shell mainShell) {
|
||||
return new Composite(mainShell, SWT.NONE);
|
||||
}
|
||||
|
||||
@Provides @Named("controlsArea") @Singleton public Composite controlsArea(Shell mainShell) {
|
||||
return new Composite(mainShell, SWT.NONE);
|
||||
}
|
||||
|
||||
@Provides @Named("startStopButton") @Singleton public Button startStopButton(@Named("controlsArea") Composite controlsArea) {
|
||||
return new Button(controlsArea, SWT.NONE);
|
||||
}
|
||||
|
||||
@Provides @Named("feederSelectionCombo") @Singleton public Combo feederSelectionCombo(@Named("controlsArea") Composite controlsArea) {
|
||||
return new Combo(controlsArea, SWT.READ_ONLY);
|
||||
}
|
||||
|
||||
@Provides @Singleton StateMachine stateMachine(SWTAwareStateMachine stateMachine) {
|
||||
return stateMachine;
|
||||
}
|
||||
|
||||
@Provides @Singleton FeederRegistry<? extends FeederCreator> feederRegistry(FeederGUIRegistry feederRegistry) {
|
||||
return feederRegistry;
|
||||
}
|
||||
|
||||
@Provides @Singleton public List<AbstractFeederGUI> feeders(RangeFeederGUI f1, RandomFeederGUI f2, FileFeederGUI f3) {
|
||||
return asList(f1, f2, f3);
|
||||
}
|
||||
|
||||
@Provides @Singleton public List<Exporter> exporters(List<Class<? extends Plugin>> plugins, TXTExporter e1, CSVExporter e2, XMLExporter e3, IPListExporter e4) {
|
||||
return addPlugins(asList(e1, e2, e3, e4), Exporter.class, plugins);
|
||||
}
|
||||
|
||||
@Provides @Singleton public List<Fetcher> fetchers(List<Class<? extends Plugin>> plugins,
|
||||
IPFetcher f1, PingFetcher f2, PingTTLFetcher f3, HostnameFetcher f4, PortsFetcher f5, FilteredPortsFetcher f6,
|
||||
WebDetectFetcher f7, HTTPSenderFetcher f8, CommentFetcher f9, NetBIOSInfoFetcher f10, MACFetcher f11, MACVendorFetcher f12,
|
||||
PacketLossFetcher f13, HTTPProxyFetcher f14) {
|
||||
return addPlugins(asList(f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14), Fetcher.class, plugins);
|
||||
}
|
||||
|
||||
@Provides @Singleton MACFetcher selectMacFetcher() {
|
||||
return Platform.WINDOWS ? new WinMACFetcher() : new UnixMACFetcher();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Plugin> List<T> addPlugins(List<T> original, Class<T> type, List<Class<? extends Plugin>> classes) {
|
||||
List<T> result = new ArrayList<>(original);
|
||||
for (Class clazz: classes) {
|
||||
try {
|
||||
if (type.isAssignableFrom(clazz))
|
||||
result.add((T)clazz.newInstance());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Cannot instantiate plugin with default constructor: " + clazz.getName());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
public Injector init() {
|
||||
Injector i = new Injector();
|
||||
new ConfigModule().register(i);
|
||||
new ComponentRegistry().register(i);
|
||||
new PluginLoader().getClasses().forEach(i::require);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,37 +1,18 @@
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import net.azib.ipscan.di.Injector;
|
||||
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
@Module
|
||||
public class ConfigModule {
|
||||
@Provides Config getConfig() {
|
||||
return Config.getConfig();
|
||||
}
|
||||
|
||||
@Provides Labels getLabels() {
|
||||
return Labels.getInstance();
|
||||
}
|
||||
|
||||
@Provides public Preferences getPreferences() {
|
||||
return getConfig().getPreferences();
|
||||
}
|
||||
|
||||
@Provides public ScannerConfig forScanner() {
|
||||
return getConfig().forScanner();
|
||||
}
|
||||
|
||||
@Provides public OpenersConfig forOpeners() {
|
||||
return getConfig().forOpeners();
|
||||
}
|
||||
|
||||
@Provides public FavoritesConfig forFavorites() {
|
||||
return getConfig().forFavorites();
|
||||
}
|
||||
|
||||
@Provides public GUIConfig forGUI() {
|
||||
return getConfig().forGUI();
|
||||
public void register(Injector i) {
|
||||
Config config = Config.getConfig();
|
||||
i.register(Config.class, config);
|
||||
i.register(Labels.class, Labels.getInstance());
|
||||
i.register(Preferences.class, config.getPreferences());
|
||||
i.register(ScannerConfig.class, config.forScanner());
|
||||
i.register(OpenersConfig.class, config.forOpeners());
|
||||
i.register(FavoritesConfig.class, config.forFavorites());
|
||||
i.register(GUIConfig.class, config.forGUI());
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,6 @@ public class GUIConfig {
|
||||
|
||||
public enum DisplayMethod {ALL, ALIVE, PORTS}
|
||||
|
||||
// package local constructor
|
||||
GUIConfig(Preferences preferences) {
|
||||
this.preferences = preferences;
|
||||
load();
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import dagger.Component;
|
||||
import net.azib.ipscan.core.PluginLoader;
|
||||
import net.azib.ipscan.gui.MacApplicationMenu;
|
||||
import net.azib.ipscan.gui.MainWindow;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Component(modules = {
|
||||
ConfigModule.class,
|
||||
PluginLoader.class,
|
||||
ComponentRegistry.class
|
||||
})
|
||||
@Singleton
|
||||
public interface MainComponent {
|
||||
MainWindow createMainWindow();
|
||||
MacApplicationMenu createMacApplicationMenu();
|
||||
CommandLineProcessor createCommandLineProcessor();
|
||||
}
|
||||
@ -1,10 +1,7 @@
|
||||
package net.azib.ipscan.core;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import net.azib.ipscan.config.LoggerFactory;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
@ -31,11 +28,9 @@ import java.util.logging.Logger;
|
||||
* </ul>
|
||||
* In either way, all plugins must implement {@link net.azib.ipscan.core.Plugin} and one or more of the concrete interfaces.
|
||||
*/
|
||||
@Module
|
||||
public class PluginLoader {
|
||||
private static final Logger LOG = LoggerFactory.getLogger();
|
||||
|
||||
@Provides @Singleton
|
||||
public List<Class<? extends Plugin>> getClasses() {
|
||||
List<Class<? extends Plugin>> container = new ArrayList<>();
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ import net.azib.ipscan.core.values.NotScanned;
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
@ -27,7 +26,7 @@ public class Scanner {
|
||||
private FetcherRegistry fetcherRegistry;
|
||||
private Map<Long, Fetcher> activeFetchers = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject public Scanner(FetcherRegistry fetcherRegistry) {
|
||||
public Scanner(FetcherRegistry fetcherRegistry) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
}
|
||||
|
||||
|
||||
@ -9,9 +9,6 @@ import net.azib.ipscan.config.ScannerConfig;
|
||||
import net.azib.ipscan.core.state.StateMachine;
|
||||
import net.azib.ipscan.feeders.Feeder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* ScannerThreadFactory.
|
||||
*
|
||||
@ -19,7 +16,6 @@ import javax.inject.Singleton;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class ScannerDispatcherThreadFactory {
|
||||
|
||||
private ScanningResultList scanningResults;
|
||||
@ -27,7 +23,7 @@ public class ScannerDispatcherThreadFactory {
|
||||
private StateMachine stateMachine;
|
||||
private ScannerConfig scannerConfig;
|
||||
|
||||
@Inject public ScannerDispatcherThreadFactory(ScanningResultList scanningResults, Scanner scanner, StateMachine stateMachine, ScannerConfig scannerConfig) {
|
||||
public ScannerDispatcherThreadFactory(ScanningResultList scanningResults, Scanner scanner, StateMachine stateMachine, ScannerConfig scannerConfig) {
|
||||
this.scanningResults = scanningResults;
|
||||
this.scanner = scanner;
|
||||
this.stateMachine = stateMachine;
|
||||
|
||||
@ -14,8 +14,6 @@ import net.azib.ipscan.feeders.Feeder;
|
||||
import net.azib.ipscan.fetchers.Fetcher;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
@ -24,7 +22,6 @@ import java.util.*;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class ScanningResultList implements Iterable<ScanningResult> {
|
||||
|
||||
private static final int RESULT_LIST_INITIAL_SIZE = 1024;
|
||||
@ -50,7 +47,7 @@ public class ScanningResultList implements Iterable<ScanningResult> {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
}
|
||||
|
||||
@Inject public ScanningResultList(FetcherRegistry fetcherRegistry, StateMachine stateMachine) {
|
||||
public ScanningResultList(FetcherRegistry fetcherRegistry, StateMachine stateMachine) {
|
||||
this(fetcherRegistry);
|
||||
stateMachine.addTransitionListener(new StopScanningListener());
|
||||
}
|
||||
|
||||
@ -11,8 +11,6 @@ import net.azib.ipscan.config.ScannerConfig;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.fetchers.FetcherException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
@ -27,7 +25,6 @@ import static java.util.logging.Level.SEVERE;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class PingerRegistry {
|
||||
private static final Logger LOG = LoggerFactory.getLogger();
|
||||
|
||||
@ -36,7 +33,7 @@ public class PingerRegistry {
|
||||
/** All available Pinger implementations */
|
||||
Map<String, Class<? extends Pinger>> pingers;
|
||||
|
||||
@Inject public PingerRegistry(ScannerConfig scannerConfig) {
|
||||
public PingerRegistry(ScannerConfig scannerConfig) {
|
||||
this.scannerConfig = scannerConfig;
|
||||
|
||||
pingers = new LinkedHashMap<>();
|
||||
|
||||
11
src/net/azib/ipscan/di/InjectException.java
Normal file
11
src/net/azib/ipscan/di/InjectException.java
Normal file
@ -0,0 +1,11 @@
|
||||
package net.azib.ipscan.di;
|
||||
|
||||
public class InjectException extends RuntimeException {
|
||||
public InjectException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
||||
public InjectException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
65
src/net/azib/ipscan/di/Injector.java
Normal file
65
src/net/azib/ipscan/di/Injector.java
Normal file
@ -0,0 +1,65 @@
|
||||
package net.azib.ipscan.di;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.Comparator.comparing;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Injector {
|
||||
private final Map<Class<?>, Object> instances = new LinkedHashMap<>();
|
||||
|
||||
public <T> void register(Class<T> type, T impl) {
|
||||
instances.put(type, impl);
|
||||
}
|
||||
|
||||
public <T> T require(Class<T> type) {
|
||||
// unfortunately, HashMap.computeIfAbsent() doesn't put values properly in a recursive scenario
|
||||
T value = (T) instances.get(type);
|
||||
if (value == null) instances.put(type, value = createInstance(type));
|
||||
return value;
|
||||
}
|
||||
|
||||
public void register(Class<?> ... types) {
|
||||
stream(types).forEach(this::require);
|
||||
}
|
||||
|
||||
public <T> List<T> requireAll(Class<T> type) {
|
||||
return instances.entrySet().stream().filter(e -> type.isAssignableFrom(e.getKey())).map(e -> (T) e.getValue()).collect(toList());
|
||||
}
|
||||
|
||||
private <T> T createInstance(Class<T> type) {
|
||||
Constructor<T> constructor = (Constructor<T>) stream(type.getConstructors())
|
||||
.max(comparing(Constructor::getParameterCount))
|
||||
.orElseThrow(() -> new InjectException("No public constructors"));
|
||||
try {
|
||||
return constructor.newInstance(resolveDeps(constructor));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throw new InjectException("Cannot create " + type.getName() + ", deps: " + Arrays.toString(constructor.getGenericParameterTypes()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] resolveDeps(Constructor<?> constructor) {
|
||||
return stream(constructor.getGenericParameterTypes()).map(t -> isCollection(t) ?
|
||||
requireAll(collectionItemType(t)) : require(toClass(t))).toArray();
|
||||
}
|
||||
|
||||
private Class<?> toClass(Type type) {
|
||||
if (type instanceof Class) return (Class<?>) type;
|
||||
else if (type instanceof ParameterizedType) return (Class<?>) ((ParameterizedType) type).getRawType();
|
||||
else throw new InjectException(type + " is not supported");
|
||||
}
|
||||
|
||||
private boolean isCollection(Type type) {
|
||||
return type instanceof ParameterizedType && Collection.class.isAssignableFrom(toClass(type));
|
||||
}
|
||||
|
||||
private Class<?> collectionItemType(Type type) {
|
||||
return (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,7 @@ public abstract class AbstractExporter implements Exporter {
|
||||
nextAdressResults(results); // for backwards-compatibility
|
||||
}
|
||||
|
||||
@Override public void nextAdressResults(Object[] results) throws IOException {
|
||||
@Override public void nextAdressResults(Object[] results) {
|
||||
}
|
||||
|
||||
public Exporter clone() {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@ -15,7 +14,7 @@ public class CSVExporter extends AbstractExporter {
|
||||
/* Delimiter escaping character (if data contains DELIMETER) */
|
||||
static final char DELIMETER_ESCAPED = '.';
|
||||
|
||||
@Inject public CSVExporter() {}
|
||||
public CSVExporter() {}
|
||||
|
||||
public String getId() {
|
||||
return "exporter.csv";
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -18,13 +16,11 @@ import java.util.Map;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class ExporterRegistry implements Iterable<Exporter> {
|
||||
|
||||
/** All available Exporter implementations, Map of Exporter instances (prototypes) */
|
||||
private Map<String, Exporter> exporters;
|
||||
|
||||
@Inject public ExporterRegistry(List<Exporter> registeredExporters) {
|
||||
public ExporterRegistry(List<Exporter> registeredExporters) {
|
||||
exporters = new LinkedHashMap<>();
|
||||
|
||||
for (Exporter exporter : registeredExporters) {
|
||||
|
||||
@ -6,7 +6,6 @@ import net.azib.ipscan.core.values.NumericRangeList;
|
||||
import net.azib.ipscan.fetchers.IPFetcher;
|
||||
import net.azib.ipscan.fetchers.PortsFetcher;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@ -22,7 +21,7 @@ public class IPListExporter extends AbstractExporter {
|
||||
private int ipFetcherIndex;
|
||||
private int portsFetcherIndex;
|
||||
|
||||
@Inject public IPListExporter() {}
|
||||
public IPListExporter() {}
|
||||
|
||||
public String getId() {
|
||||
return "exporter.ipList";
|
||||
|
||||
@ -8,7 +8,6 @@ import net.azib.ipscan.fetchers.PingFetcher;
|
||||
import net.azib.ipscan.fetchers.PortsFetcher;
|
||||
import net.azib.ipscan.gui.feeders.AbstractFeederGUI;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
@ -33,7 +32,7 @@ import static net.azib.ipscan.util.InetAddressUtils.increment;
|
||||
public class TXTExporter extends AbstractExporter {
|
||||
int[] padLengths;
|
||||
|
||||
@Inject public TXTExporter() {}
|
||||
public TXTExporter() {}
|
||||
|
||||
public String getId() {
|
||||
return "exporter.txt";
|
||||
|
||||
@ -7,7 +7,6 @@ package net.azib.ipscan.exporters;
|
||||
|
||||
import net.azib.ipscan.config.Version;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@ -20,7 +19,7 @@ import java.util.Date;
|
||||
public class XMLExporter extends AbstractExporter {
|
||||
static final String ENCODING = "UTF-8";
|
||||
|
||||
@Inject public XMLExporter() {}
|
||||
public XMLExporter() {}
|
||||
|
||||
private int ipFetcherIndex;
|
||||
private String[] fetcherNames;
|
||||
|
||||
@ -11,6 +11,6 @@ package net.azib.ipscan.feeders;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public interface FeederRegistry<T extends FeederCreator> extends Iterable<T> {
|
||||
public interface FeederRegistry extends Iterable<FeederCreator> {
|
||||
void select(String feederId);
|
||||
}
|
||||
|
||||
@ -7,8 +7,6 @@ package net.azib.ipscan.fetchers;
|
||||
import net.azib.ipscan.config.CommentsConfig;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* A fetcher for displaying of user-defined comments about every IP address.
|
||||
*
|
||||
@ -19,7 +17,7 @@ public class CommentFetcher extends AbstractFetcher {
|
||||
|
||||
private CommentsConfig commentsConfig;
|
||||
|
||||
@Inject public CommentFetcher(CommentsConfig commentsConfig) {
|
||||
public CommentFetcher(CommentsConfig commentsConfig) {
|
||||
this.commentsConfig = commentsConfig;
|
||||
}
|
||||
|
||||
|
||||
@ -7,8 +7,6 @@ package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.gui.PreferencesDialog;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
import java.util.prefs.Preferences;
|
||||
@ -19,7 +17,6 @@ import java.util.prefs.Preferences;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class FetcherRegistry {
|
||||
static final String PREFERENCE_SELECTED_FETCHERS = "selectedFetchers";
|
||||
|
||||
@ -35,7 +32,7 @@ public class FetcherRegistry {
|
||||
/** A collection of update listeners - observers of FetcherRegistry */
|
||||
private List<FetcherRegistryUpdateListener> updateListeners = new ArrayList<>();
|
||||
|
||||
@Inject public FetcherRegistry(List<Fetcher> fetchers, Preferences preferences, PreferencesDialog preferencesDialog) {
|
||||
public FetcherRegistry(List<Fetcher> fetchers, Preferences preferences, PreferencesDialog preferencesDialog) {
|
||||
this.preferences = preferences;
|
||||
this.preferencesDialog = preferencesDialog;
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.core.values.NotScanned;
|
||||
import net.azib.ipscan.core.values.NumericRangeList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
@ -20,7 +19,7 @@ import java.util.SortedSet;
|
||||
*/
|
||||
public class FilteredPortsFetcher extends PortsFetcher {
|
||||
|
||||
@Inject public FilteredPortsFetcher(ScannerConfig scannerConfig) {
|
||||
public FilteredPortsFetcher(ScannerConfig scannerConfig) {
|
||||
super(scannerConfig);
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@ package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.config.ScannerConfig;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
@ -17,7 +16,7 @@ import java.util.regex.Matcher;
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class HTTPProxyFetcher extends PortTextFetcher {
|
||||
@Inject public HTTPProxyFetcher(ScannerConfig scannerConfig) {
|
||||
public HTTPProxyFetcher(ScannerConfig scannerConfig) {
|
||||
super(scannerConfig, 3128, "HEAD http://www.google.com HTTP/1.0\r\n\r\n", "^(HTTP/[\\d\\.]+ [23].*)$");
|
||||
this.scanOpenPorts = true;
|
||||
}
|
||||
|
||||
@ -8,15 +8,13 @@ package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.config.ScannerConfig;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* HTTPSenderFetcher - allows sending of arbitrary info port and showing the result.
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class HTTPSenderFetcher extends PortTextFetcher {
|
||||
@Inject public HTTPSenderFetcher(ScannerConfig scannerConfig) {
|
||||
public HTTPSenderFetcher(ScannerConfig scannerConfig) {
|
||||
super(scannerConfig, 80, "HEAD / HTTP/1.0\r\n\r\n", "Date: (.*)$");
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@ import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.util.MDNSResolver;
|
||||
import net.azib.ipscan.util.NetBIOSResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -47,7 +46,7 @@ public class HostnameFetcher extends AbstractFetcher {
|
||||
|
||||
public static final String ID = "fetcher.hostname";
|
||||
|
||||
@Inject public HostnameFetcher() {}
|
||||
public HostnameFetcher() {}
|
||||
|
||||
public String getId() {
|
||||
return ID;
|
||||
|
||||
@ -7,8 +7,6 @@ package net.azib.ipscan.fetchers;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.core.values.InetAddressHolder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Dummy fetcher, which is able to return the textual representation
|
||||
* of the passed IP address.
|
||||
@ -16,7 +14,7 @@ import javax.inject.Inject;
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class IPFetcher extends AbstractFetcher {
|
||||
@Inject public IPFetcher() {}
|
||||
public IPFetcher() {}
|
||||
|
||||
public static final String ID = "fetcher.ip";
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@ -14,7 +13,7 @@ public class MACVendorFetcher extends AbstractFetcher {
|
||||
private static Map<String, String> vendors = new HashMap<>();
|
||||
private MACFetcher macFetcher;
|
||||
|
||||
@Inject public MACVendorFetcher(MACFetcher macFetcher) {
|
||||
public MACVendorFetcher(MACFetcher macFetcher) {
|
||||
this.macFetcher = macFetcher;
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ import net.azib.ipscan.config.LoggerFactory;
|
||||
import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.util.NetBIOSResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
@ -24,7 +23,7 @@ import static java.util.logging.Level.WARNING;
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class NetBIOSInfoFetcher extends AbstractFetcher {
|
||||
@Inject public NetBIOSInfoFetcher() {}
|
||||
public NetBIOSInfoFetcher() {}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger();
|
||||
|
||||
|
||||
@ -5,8 +5,6 @@ import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.core.net.PingResult;
|
||||
import net.azib.ipscan.core.net.PingerRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static net.azib.ipscan.core.ScanningResult.ResultType.ALIVE;
|
||||
import static net.azib.ipscan.core.ScanningResult.ResultType.DEAD;
|
||||
|
||||
@ -18,7 +16,7 @@ import static net.azib.ipscan.core.ScanningResult.ResultType.DEAD;
|
||||
*/
|
||||
public class PacketLossFetcher extends PingFetcher {
|
||||
|
||||
@Inject public PacketLossFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) {
|
||||
public PacketLossFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) {
|
||||
super(pingerRegistry, scannerConfig);
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,6 @@ import net.azib.ipscan.core.net.PingerRegistry;
|
||||
import net.azib.ipscan.core.values.IntegerWithUnit;
|
||||
import net.azib.ipscan.gui.fetchers.PingFetcherPrefs;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
@ -42,7 +41,7 @@ public class PingFetcher extends AbstractFetcher {
|
||||
/** The registry used for creation of Pinger instances */
|
||||
private PingerRegistry pingerRegistry;
|
||||
|
||||
@Inject public PingFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) {
|
||||
public PingFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) {
|
||||
this.pingerRegistry = pingerRegistry;
|
||||
this.config = scannerConfig;
|
||||
}
|
||||
|
||||
@ -10,8 +10,6 @@ import net.azib.ipscan.core.ScanningSubject;
|
||||
import net.azib.ipscan.core.net.PingResult;
|
||||
import net.azib.ipscan.core.net.PingerRegistry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* PingTTLFetcher shares pinging results with PingFetcher
|
||||
* and returns the TTL field of the last received packet.
|
||||
@ -20,7 +18,7 @@ import javax.inject.Inject;
|
||||
*/
|
||||
public class PingTTLFetcher extends PingFetcher {
|
||||
|
||||
@Inject public PingTTLFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) {
|
||||
public PingTTLFetcher(PingerRegistry pingerRegistry, ScannerConfig scannerConfig) {
|
||||
super(pingerRegistry, scannerConfig);
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@ import net.azib.ipscan.gui.fetchers.PortsFetcherPrefs;
|
||||
import net.azib.ipscan.util.SequenceIterator;
|
||||
import net.azib.ipscan.util.ThreadResourceBinder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -45,7 +44,7 @@ public class PortsFetcher extends AbstractFetcher {
|
||||
private PortIterator portIteratorPrototype;
|
||||
protected boolean displayAsRanges = true; // TODO: make configurable
|
||||
|
||||
@Inject public PortsFetcher(ScannerConfig scannerConfig) {
|
||||
public PortsFetcher(ScannerConfig scannerConfig) {
|
||||
this.config = scannerConfig;
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package net.azib.ipscan.fetchers;
|
||||
import net.azib.ipscan.config.Platform;
|
||||
import net.azib.ipscan.util.IOUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
@ -13,7 +12,7 @@ import java.util.Enumeration;
|
||||
public class UnixMACFetcher extends MACFetcher {
|
||||
private String arp;
|
||||
|
||||
@Inject public UnixMACFetcher() {
|
||||
public UnixMACFetcher() {
|
||||
if (Platform.LINUX)
|
||||
arp = "arp -an "; // use BSD-style output
|
||||
else
|
||||
|
||||
@ -8,8 +8,6 @@ package net.azib.ipscan.fetchers;
|
||||
|
||||
import net.azib.ipscan.config.ScannerConfig;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* WebDetectFetcher - detects the Web server software running on scanned hosts.
|
||||
*
|
||||
@ -17,7 +15,7 @@ import javax.inject.Inject;
|
||||
*/
|
||||
public class WebDetectFetcher extends PortTextFetcher {
|
||||
|
||||
@Inject public WebDetectFetcher(ScannerConfig scannerConfig) {
|
||||
public WebDetectFetcher(ScannerConfig scannerConfig) {
|
||||
super(scannerConfig, 80, "HEAD /robots.txt HTTP/1.0\r\n\r\n", "^[Ss]erver:\\s+(.*)$");
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package net.azib.ipscan.fetchers;
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
|
||||
@ -11,7 +10,7 @@ import static net.azib.ipscan.core.net.WinIpHlp.toIpAddr;
|
||||
import static net.azib.ipscan.core.net.WinIpHlpDll.dll;
|
||||
|
||||
public class WinMACFetcher extends MACFetcher {
|
||||
@Inject public WinMACFetcher() {}
|
||||
public WinMACFetcher() {}
|
||||
|
||||
@Override public String resolveMAC(InetAddress address) {
|
||||
if (!(address instanceof Inet4Address)) return null; // TODO IPv6 support
|
||||
|
||||
@ -9,12 +9,9 @@ import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static net.azib.ipscan.config.Version.*;
|
||||
|
||||
public class AboutDialog extends AbstractModalDialog {
|
||||
@Inject
|
||||
public AboutDialog() {}
|
||||
|
||||
@Override
|
||||
|
||||
@ -17,25 +17,23 @@ import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* The "Show IP Details" Window
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class DetailsWindow extends AbstractModalDialog {
|
||||
@Inject CommentsConfig commentsConfig;
|
||||
|
||||
private GUIConfig guiConfig;
|
||||
private CommentsConfig commentsConfig;
|
||||
private ResultTable resultTable;
|
||||
private ScanningResultList scanningResults;
|
||||
|
||||
int resultIndex;
|
||||
private Text commentsText;
|
||||
|
||||
@Inject public DetailsWindow(GUIConfig guiConfig, ResultTable resultTable, ScanningResultList scanningResults) {
|
||||
public DetailsWindow(GUIConfig guiConfig, CommentsConfig commentsConfig, ResultTable resultTable, ScanningResultList scanningResults) {
|
||||
this.guiConfig = guiConfig;
|
||||
this.commentsConfig = commentsConfig;
|
||||
this.resultTable = resultTable;
|
||||
this.scanningResults = scanningResults;
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package net.azib.ipscan.gui;
|
||||
|
||||
import net.azib.ipscan.config.LoggerFactory;
|
||||
import net.azib.ipscan.config.MainComponent;
|
||||
import net.azib.ipscan.config.Platform;
|
||||
import net.azib.ipscan.config.Version;
|
||||
import net.azib.ipscan.core.UserErrorException;
|
||||
import net.azib.ipscan.di.Injector;
|
||||
import net.azib.ipscan.util.GoogleAnalytics;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.SWTError;
|
||||
@ -41,9 +41,8 @@ public class GUI implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public void showMainWindow(MainComponent mainComponent) {
|
||||
// create the main window using dependency injection
|
||||
mainWindow = mainComponent.createMainWindow();
|
||||
public void showMainWindow(Injector injector) {
|
||||
mainWindow = injector.require(MainWindow.class);
|
||||
if (Platform.MAC_OS) setMacDarkAppearanceIfNeeded();
|
||||
|
||||
LOG.fine("Main window created: " + (System.currentTimeMillis() - startTime));
|
||||
@ -92,7 +91,8 @@ public class GUI implements AutoCloseable {
|
||||
|
||||
public void showMessage(int flags, String title, String localizedMessage) {
|
||||
Shell parent = Display.getDefault().getActiveShell();
|
||||
if (parent == null) parent = mainWindow.getShell();
|
||||
if (parent == null && mainWindow != null) parent = mainWindow.getShell();
|
||||
if (parent == null) parent = new Shell();
|
||||
MessageBox messageBox = new MessageBox(parent, SWT.OK | SWT.SHEET | flags);
|
||||
messageBox.setText(title);
|
||||
messageBox.setMessage(localizedMessage);
|
||||
|
||||
@ -9,19 +9,21 @@ import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Mac-specific application menu handler
|
||||
* in order to conform better to Mac standards.
|
||||
*/
|
||||
public class MacApplicationMenu {
|
||||
@Inject AboutDialog aboutDialog;
|
||||
@Inject PreferencesDialog preferencesDialog;
|
||||
@Inject SelectFetchersDialog selectFetchersDialog;
|
||||
@Inject CheckVersion checkVersionListener;
|
||||
private AboutDialog aboutDialog;
|
||||
private PreferencesDialog preferencesDialog;
|
||||
private SelectFetchersDialog selectFetchersDialog;
|
||||
private CheckVersion checkVersion;
|
||||
|
||||
@Inject public MacApplicationMenu(final Display display) {
|
||||
public MacApplicationMenu(Display display, AboutDialog aboutDialog, PreferencesDialog preferencesDialog, SelectFetchersDialog selectFetchersDialog, CheckVersion checkVersion) {
|
||||
this.aboutDialog = aboutDialog;
|
||||
this.preferencesDialog = preferencesDialog;
|
||||
this.selectFetchersDialog = selectFetchersDialog;
|
||||
this.checkVersion = checkVersion;
|
||||
display.syncExec(() -> initApplicationMenu(display));
|
||||
}
|
||||
|
||||
@ -58,7 +60,7 @@ public class MacApplicationMenu {
|
||||
checkVersion.setText(Labels.getLabel("menu.help.checkVersion"));
|
||||
checkVersion.addSelectionListener(new SelectionAdapter() {
|
||||
@Override public void widgetSelected(SelectionEvent e) {
|
||||
checkVersionListener.check(true);
|
||||
MacApplicationMenu.this.checkVersion.check(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -16,29 +16,22 @@ import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* MainMenu
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class MainMenu {
|
||||
|
||||
@Inject
|
||||
public MainMenu(Shell parent, @Named("mainMenu") Menu mainMenu,
|
||||
ScanMenu scanMenu,
|
||||
GotoMenu gotoMenu,
|
||||
CommandsMenu commandsMenu,
|
||||
FavoritesMenu favoritesMenu,
|
||||
ToolsMenu toolsMenu,
|
||||
HelpMenu helpMenu,
|
||||
ResultsContextMenu resultsContextMenu,
|
||||
StateMachine stateMachine) {
|
||||
|
||||
public MainMenu(Shell parent, Menu mainMenu,
|
||||
ScanMenu scanMenu,
|
||||
GotoMenu gotoMenu,
|
||||
CommandsMenu commandsMenu,
|
||||
FavoritesMenu favoritesMenu,
|
||||
ToolsMenu toolsMenu,
|
||||
HelpMenu helpMenu,
|
||||
ResultsContextMenu resultsContextMenu,
|
||||
StateMachine stateMachine
|
||||
) {
|
||||
parent.setMenuBar(mainMenu);
|
||||
|
||||
addMenuItem(mainMenu, scanMenu);
|
||||
|
||||
@ -14,7 +14,10 @@ import net.azib.ipscan.core.state.StateMachine.Transition;
|
||||
import net.azib.ipscan.core.state.StateTransitionListener;
|
||||
import net.azib.ipscan.gui.actions.StartStopScanningAction;
|
||||
import net.azib.ipscan.gui.actions.ToolsActions;
|
||||
import net.azib.ipscan.gui.feeders.ControlsArea;
|
||||
import net.azib.ipscan.gui.feeders.FeederArea;
|
||||
import net.azib.ipscan.gui.feeders.FeederGUIRegistry;
|
||||
import net.azib.ipscan.gui.feeders.FeederSelectionCombo;
|
||||
import net.azib.ipscan.gui.menu.ResultsContextMenu;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
@ -25,9 +28,6 @@ import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.*;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import static net.azib.ipscan.gui.util.LayoutHelper.formData;
|
||||
import static net.azib.ipscan.gui.util.LayoutHelper.icon;
|
||||
|
||||
@ -57,10 +57,9 @@ public class MainWindow {
|
||||
/**
|
||||
* Creates and initializes the main window.
|
||||
*/
|
||||
@Inject
|
||||
public MainWindow(Shell shell, GUIConfig guiConfig, @Named("feederArea") Composite feederArea,
|
||||
@Named("controlsArea") Composite controlsArea, @Named("feederSelectionCombo") Combo feederSelectionCombo,
|
||||
@Named("startStopButton") Button startStopButton, StartStopScanningAction startStopScanningAction,
|
||||
public MainWindow(Shell shell, GUIConfig guiConfig, FeederArea feederArea,
|
||||
ControlsArea controlsArea, FeederSelectionCombo feederSelectionCombo,
|
||||
Button startStopButton, StartStopScanningAction startStopScanningAction,
|
||||
ResultTable resultTable, StatusBar statusBar, ResultsContextMenu resultsContextMenu,
|
||||
FeederGUIRegistry feederGUIRegistry, final StateMachine stateMachine,
|
||||
ToolsActions.Preferences preferencesListener, ToolsActions.ChooseFetchers chooseFetchersListener,
|
||||
|
||||
@ -25,15 +25,11 @@ import org.eclipse.swt.layout.RowData;
|
||||
import org.eclipse.swt.layout.RowLayout;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Preferences Dialog
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class PreferencesDialog extends AbstractModalDialog {
|
||||
private final PingerRegistry pingerRegistry;
|
||||
private final Config globalConfig;
|
||||
@ -68,7 +64,7 @@ public class PreferencesDialog extends AbstractModalDialog {
|
||||
private Button askConfirmationCheckbox;
|
||||
private Combo languageCombo;
|
||||
|
||||
@Inject public PreferencesDialog(PingerRegistry pingerRegistry, Config globalConfig, ScannerConfig scannerConfig, GUIConfig guiConfig) {
|
||||
public PreferencesDialog(PingerRegistry pingerRegistry, Config globalConfig, ScannerConfig scannerConfig, GUIConfig guiConfig) {
|
||||
this.pingerRegistry = pingerRegistry;
|
||||
this.globalConfig = globalConfig;
|
||||
this.scannerConfig = scannerConfig;
|
||||
|
||||
@ -23,8 +23,6 @@ import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
import static net.azib.ipscan.core.ScanningResult.ResultType.*;
|
||||
@ -35,9 +33,7 @@ import static net.azib.ipscan.gui.util.LayoutHelper.icon;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class ResultTable extends Table implements FetcherRegistryUpdateListener, StateTransitionListener {
|
||||
|
||||
private ScanningResultList scanningResults;
|
||||
private GUIConfig guiConfig;
|
||||
private FetcherRegistry fetcherRegistry;
|
||||
@ -48,7 +44,7 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener,
|
||||
|
||||
private Listener columnResizeListener;
|
||||
|
||||
@Inject public ResultTable(Shell parent, GUIConfig guiConfig, FetcherRegistry fetcherRegistry,
|
||||
public ResultTable(Shell parent, GUIConfig guiConfig, FetcherRegistry fetcherRegistry,
|
||||
ScanningResultList scanningResultList, StateMachine stateMachine,
|
||||
ColumnsActions.ColumnClick columnClickListener, ColumnsActions.ColumnResize columnResizeListener) {
|
||||
super(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
|
||||
|
||||
@ -10,9 +10,6 @@ import net.azib.ipscan.core.state.StateMachine;
|
||||
import net.azib.ipscan.core.state.StateTransitionListener;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Extends the generic {@link StateMachine} in order to run state transition notifications
|
||||
* in the SWT user-interface thread. This will allow {@link StateTransitionListener}s to call SWT methods without
|
||||
@ -20,11 +17,10 @@ import javax.inject.Singleton;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class SWTAwareStateMachine extends StateMachine {
|
||||
private Display display;
|
||||
|
||||
@Inject public SWTAwareStateMachine(Display display) {
|
||||
public SWTAwareStateMachine(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,6 @@ import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.FormAttachment;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
@ -33,7 +32,7 @@ public class SelectFetchersDialog extends AbstractModalDialog {
|
||||
private List registeredFetchersList;
|
||||
Map<String, String> registeredFetcherIdsByNames = new HashMap<>();
|
||||
|
||||
@Inject public SelectFetchersDialog(FetcherRegistry fetcherRegistry) {
|
||||
public SelectFetchersDialog(FetcherRegistry fetcherRegistry) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
}
|
||||
|
||||
|
||||
@ -4,19 +4,21 @@ import net.azib.ipscan.config.GUIConfig;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.config.Platform;
|
||||
import net.azib.ipscan.config.Version;
|
||||
import net.azib.ipscan.gui.actions.HelpMenuActions;
|
||||
import net.azib.ipscan.gui.actions.HelpMenuActions.CheckVersion;
|
||||
import net.azib.ipscan.util.GoogleAnalytics;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class Startup {
|
||||
@Inject Shell shell;
|
||||
@Inject GUIConfig guiConfig;
|
||||
@Inject HelpMenuActions.CheckVersion checkVersion;
|
||||
private Shell shell;
|
||||
private GUIConfig guiConfig;
|
||||
private CheckVersion checkVersion;
|
||||
|
||||
@Inject public Startup() {}
|
||||
public Startup(Shell shell, GUIConfig guiConfig, CheckVersion checkVersion) {
|
||||
this.shell = shell;
|
||||
this.guiConfig = guiConfig;
|
||||
this.checkVersion = checkVersion;
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
if (guiConfig.isFirstRun) {
|
||||
|
||||
@ -11,7 +11,6 @@ import net.azib.ipscan.core.ScanningResultList;
|
||||
import net.azib.ipscan.core.ScanningResultList.ScanInfo;
|
||||
import net.azib.ipscan.core.UserErrorException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
@ -24,7 +23,7 @@ public class StatisticsDialog extends InfoDialog {
|
||||
|
||||
private final ScanningResultList scanningResults;
|
||||
|
||||
@Inject public StatisticsDialog(ScanningResultList scanningResults) {
|
||||
public StatisticsDialog(ScanningResultList scanningResults) {
|
||||
super(Labels.getLabel("title.statistics"), null);
|
||||
this.scanningResults = scanningResults;
|
||||
}
|
||||
|
||||
@ -20,9 +20,6 @@ import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.layout.FormAttachment;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static net.azib.ipscan.config.GUIConfig.DisplayMethod.PORTS;
|
||||
import static net.azib.ipscan.gui.util.LayoutHelper.formData;
|
||||
|
||||
@ -31,7 +28,6 @@ import static net.azib.ipscan.gui.util.LayoutHelper.formData;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class StatusBar {
|
||||
private Composite composite;
|
||||
private Label statusText;
|
||||
@ -45,7 +41,7 @@ public class StatusBar {
|
||||
private StateMachine stateMachine;
|
||||
private ResultTable resultTable;
|
||||
|
||||
@Inject public StatusBar(Shell shell, GUIConfig guiConfig, ScannerConfig scannerConfig, ResultTable resultTable, StateMachine stateMachine) {
|
||||
public StatusBar(Shell shell, GUIConfig guiConfig, ScannerConfig scannerConfig, ResultTable resultTable, StateMachine stateMachine) {
|
||||
this.guiConfig = guiConfig;
|
||||
this.scannerConfig = scannerConfig;
|
||||
this.stateMachine = stateMachine;
|
||||
|
||||
@ -18,8 +18,6 @@ import net.azib.ipscan.gui.menu.ColumnsMenu;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* ColumnsActions
|
||||
*
|
||||
@ -30,7 +28,7 @@ public class ColumnsActions {
|
||||
public static final class ColumnResize implements Listener {
|
||||
private GUIConfig guiConfig;
|
||||
|
||||
@Inject public ColumnResize(GUIConfig guiConfig) {
|
||||
public ColumnResize(GUIConfig guiConfig) {
|
||||
this.guiConfig = guiConfig;
|
||||
}
|
||||
|
||||
@ -51,7 +49,7 @@ public class ColumnsActions {
|
||||
private final Menu columnsMenu;
|
||||
private final StateMachine stateMachine;
|
||||
|
||||
@Inject public ColumnClick(ColumnsMenu columnsMenu, StateMachine stateMachine) {
|
||||
public ColumnClick(ColumnsMenu columnsMenu, StateMachine stateMachine) {
|
||||
this.columnsMenu = columnsMenu;
|
||||
this.stateMachine = stateMachine;
|
||||
}
|
||||
@ -93,7 +91,6 @@ public class ColumnsActions {
|
||||
public static final class SortBy implements Listener {
|
||||
private final ScanningResultList scanningResultList;
|
||||
|
||||
@Inject
|
||||
public SortBy(ScanningResultList scanningResultList) {
|
||||
this.scanningResultList = scanningResultList;
|
||||
}
|
||||
@ -120,7 +117,7 @@ public class ColumnsActions {
|
||||
public static final class FetcherPreferences implements Listener {
|
||||
private final FetcherRegistry fetcherRegistry;
|
||||
|
||||
@Inject public FetcherPreferences(FetcherRegistry fetcherRegistry) {
|
||||
public FetcherPreferences(FetcherRegistry fetcherRegistry) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
}
|
||||
|
||||
@ -138,7 +135,7 @@ public class ColumnsActions {
|
||||
}
|
||||
|
||||
public static final class AboutFetcher implements Listener {
|
||||
@Inject public AboutFetcher() {}
|
||||
public AboutFetcher() {}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
// retrieve the clicked column (see ColumnClick above)
|
||||
|
||||
@ -25,27 +25,32 @@ import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Commands and Context menu Actions.
|
||||
* All these operate on the items, selected in the results list.
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class CommandsMenuActions {
|
||||
@Inject public Details details;
|
||||
@Inject public Delete delete;
|
||||
@Inject public Rescan rescan;
|
||||
@Inject public CopyIP copyIP;
|
||||
@Inject public CopyIPDetails copyIPDetails;
|
||||
@Inject public ShowOpenersMenu showOpenersMenu;
|
||||
@Inject public EditOpeners editOpeners;
|
||||
@Inject public SelectOpener selectOpener;
|
||||
public Details details;
|
||||
public Delete delete;
|
||||
public Rescan rescan;
|
||||
public CopyIP copyIP;
|
||||
public CopyIPDetails copyIPDetails;
|
||||
public ShowOpenersMenu showOpenersMenu;
|
||||
public EditOpeners editOpeners;
|
||||
public SelectOpener selectOpener;
|
||||
|
||||
@Inject public CommandsMenuActions() {}
|
||||
public CommandsMenuActions(Details details, Delete delete, Rescan rescan, CopyIP copyIP, CopyIPDetails copyIPDetails, ShowOpenersMenu showOpenersMenu, EditOpeners editOpeners, SelectOpener selectOpener) {
|
||||
this.details = details;
|
||||
this.delete = delete;
|
||||
this.rescan = rescan;
|
||||
this.copyIP = copyIP;
|
||||
this.copyIPDetails = copyIPDetails;
|
||||
this.showOpenersMenu = showOpenersMenu;
|
||||
this.editOpeners = editOpeners;
|
||||
this.selectOpener = selectOpener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that there is at least one item selected in the results list.
|
||||
@ -64,7 +69,7 @@ public class CommandsMenuActions {
|
||||
private final ResultTable resultTable;
|
||||
private final DetailsWindow detailsWindow;
|
||||
|
||||
@Inject public Details(ResultTable resultTable, DetailsWindow detailsWindow) {
|
||||
public Details(ResultTable resultTable, DetailsWindow detailsWindow) {
|
||||
this.resultTable = resultTable;
|
||||
this.detailsWindow = detailsWindow;
|
||||
resultTable.addListener(SWT.Traverse, this);
|
||||
@ -85,7 +90,7 @@ public class CommandsMenuActions {
|
||||
private final ResultTable resultTable;
|
||||
private final StateMachine stateMachine;
|
||||
|
||||
@Inject public Delete(ResultTable resultTable, StateMachine stateMachine) {
|
||||
public Delete(ResultTable resultTable, StateMachine stateMachine) {
|
||||
this.resultTable = resultTable;
|
||||
this.stateMachine = stateMachine;
|
||||
}
|
||||
@ -111,7 +116,6 @@ public class CommandsMenuActions {
|
||||
private final ResultTable resultTable;
|
||||
private final StateMachine stateMachine;
|
||||
|
||||
@Inject
|
||||
public Rescan(ResultTable resultTable, StateMachine stateMachine) {
|
||||
this.resultTable = resultTable;
|
||||
this.stateMachine = stateMachine;
|
||||
@ -130,7 +134,6 @@ public class CommandsMenuActions {
|
||||
public static final class CopyIP implements Listener {
|
||||
private final ResultTable resultTable;
|
||||
|
||||
@Inject
|
||||
public CopyIP(ResultTable resultTable) {
|
||||
this.resultTable = resultTable;
|
||||
}
|
||||
@ -154,7 +157,6 @@ public class CommandsMenuActions {
|
||||
public static final class CopyIPDetails implements Listener {
|
||||
private final ResultTable resultTable;
|
||||
|
||||
@Inject
|
||||
public CopyIPDetails(ResultTable resultTable) {
|
||||
this.resultTable = resultTable;
|
||||
}
|
||||
@ -172,7 +174,6 @@ public class CommandsMenuActions {
|
||||
private final Listener openersSelectListener;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
@Inject
|
||||
public ShowOpenersMenu(OpenersConfig openersConfig, SelectOpener selectOpener) {
|
||||
this.openersConfig = openersConfig;
|
||||
this.openersSelectListener = selectOpener;
|
||||
@ -209,7 +210,6 @@ public class CommandsMenuActions {
|
||||
private final FetcherRegistry fetcherRegistry;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
@Inject
|
||||
public EditOpeners(FetcherRegistry fetcherRegistry, OpenersConfig openersConfig) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
this.openersConfig = openersConfig;
|
||||
@ -227,7 +227,6 @@ public class CommandsMenuActions {
|
||||
private final OpenerLauncher openerLauncher;
|
||||
private final OpenersConfig openersConfig;
|
||||
|
||||
@Inject
|
||||
public SelectOpener(OpenersConfig openersConfig, StatusBar statusBar, ResultTable resultTable, OpenerLauncher openerLauncher) {
|
||||
this.openersConfig = openersConfig;
|
||||
this.statusBar = statusBar;
|
||||
|
||||
@ -22,8 +22,6 @@ import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* FavoritesActions
|
||||
*
|
||||
@ -35,7 +33,6 @@ public class FavoritesMenuActions {
|
||||
private final FeederGUIRegistry feederRegistry;
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
|
||||
@Inject
|
||||
public Add(FavoritesConfig favoritesConfig, FeederGUIRegistry feederRegistry) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
this.feederRegistry = feederRegistry;
|
||||
@ -63,7 +60,6 @@ public class FavoritesMenuActions {
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
private final StartStopScanningAction startStopAction;
|
||||
|
||||
@Inject
|
||||
public Select(FavoritesConfig favoritesConfig, FeederGUIRegistry feederRegistry, StartStopScanningAction startStopAction) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
this.feederRegistry = feederRegistry;
|
||||
@ -90,7 +86,6 @@ public class FavoritesMenuActions {
|
||||
public static final class Edit implements Listener {
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
|
||||
@Inject
|
||||
public Edit(FavoritesConfig favoritesConfig) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
}
|
||||
@ -105,7 +100,6 @@ public class FavoritesMenuActions {
|
||||
private final FavoritesConfig favoritesConfig;
|
||||
private final StateMachine stateMachine;
|
||||
|
||||
@Inject
|
||||
public ShowMenu(FavoritesConfig favoritesConfig, Select favoritesSelectListener, StateMachine stateMachine) {
|
||||
this.favoritesConfig = favoritesConfig;
|
||||
// the listener for favorites selections from the menu
|
||||
|
||||
@ -18,8 +18,6 @@ import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* GotoActions
|
||||
*
|
||||
@ -88,42 +86,36 @@ public class GotoMenuActions {
|
||||
}
|
||||
|
||||
public static final class NextAliveHost extends NextHost {
|
||||
@Inject
|
||||
public NextAliveHost(ResultTable resultTable) {
|
||||
super(resultTable, ResultType.ALIVE);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NextDeadHost extends NextHost {
|
||||
@Inject
|
||||
public NextDeadHost(ResultTable resultTable) {
|
||||
super(resultTable, ResultType.DEAD);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NextHostWithInfo extends NextHost {
|
||||
@Inject
|
||||
public NextHostWithInfo(ResultTable resultTable) {
|
||||
super(resultTable, ResultType.WITH_PORTS);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PrevAliveHost extends PrevHost {
|
||||
@Inject
|
||||
public PrevAliveHost(ResultTable resultTable) {
|
||||
super(resultTable, ResultType.ALIVE);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PrevDeadHost extends PrevHost {
|
||||
@Inject
|
||||
public PrevDeadHost(ResultTable resultTable) {
|
||||
super(resultTable, ResultType.DEAD);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PrevHostWithInfo extends PrevHost {
|
||||
@Inject
|
||||
public PrevHostWithInfo(ResultTable resultTable) {
|
||||
super(resultTable, ResultType.WITH_PORTS);
|
||||
}
|
||||
@ -135,7 +127,6 @@ public class GotoMenuActions {
|
||||
private final StatusBar statusBar;
|
||||
private String lastText = "";
|
||||
|
||||
@Inject
|
||||
public Find(StatusBar statusBar, ResultTable resultTable) {
|
||||
this.statusBar = statusBar;
|
||||
this.resultTable = resultTable;
|
||||
|
||||
@ -18,7 +18,6 @@ import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
@ -31,7 +30,7 @@ import static net.azib.ipscan.util.IOUtils.closeQuietly;
|
||||
public class HelpMenuActions {
|
||||
|
||||
public static final class GettingStarted implements Listener {
|
||||
@Inject public GettingStarted() {}
|
||||
public GettingStarted() {}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
new GettingStartedDialog().open();
|
||||
@ -41,7 +40,7 @@ public class HelpMenuActions {
|
||||
public static final class CommandLineUsage implements Listener {
|
||||
private CommandLineProcessor cli;
|
||||
|
||||
@Inject public CommandLineUsage(CommandLineProcessor cli) {
|
||||
public CommandLineUsage(CommandLineProcessor cli) {
|
||||
this.cli = cli;
|
||||
}
|
||||
|
||||
@ -55,7 +54,7 @@ public class HelpMenuActions {
|
||||
public static final class About implements Listener {
|
||||
private AboutDialog aboutDialog;
|
||||
|
||||
@Inject public About(AboutDialog aboutDialog) {
|
||||
public About(AboutDialog aboutDialog) {
|
||||
this.aboutDialog = aboutDialog;
|
||||
}
|
||||
|
||||
@ -65,7 +64,7 @@ public class HelpMenuActions {
|
||||
}
|
||||
|
||||
public static final class Website implements Listener {
|
||||
@Inject public Website() {}
|
||||
public Website() {}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
BrowserLauncher.openURL(Version.WEBSITE);
|
||||
@ -73,7 +72,7 @@ public class HelpMenuActions {
|
||||
}
|
||||
|
||||
public static final class FAQ implements Listener {
|
||||
@Inject public FAQ() {}
|
||||
public FAQ() {}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
BrowserLauncher.openURL(Version.FAQ_URL);
|
||||
@ -81,7 +80,7 @@ public class HelpMenuActions {
|
||||
}
|
||||
|
||||
public static final class Issues implements Listener {
|
||||
@Inject public Issues() {}
|
||||
public Issues() {}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
BrowserLauncher.openURL(Version.ISSUES_URL);
|
||||
@ -89,7 +88,7 @@ public class HelpMenuActions {
|
||||
}
|
||||
|
||||
public static final class Plugins implements Listener {
|
||||
@Inject public Plugins() {}
|
||||
public Plugins() {}
|
||||
|
||||
public void handleEvent(Event event) {
|
||||
BrowserLauncher.openURL(Version.PLUGINS_URL);
|
||||
@ -99,7 +98,7 @@ public class HelpMenuActions {
|
||||
public static final class CheckVersion implements Listener {
|
||||
private final StatusBar statusBar;
|
||||
|
||||
@Inject public CheckVersion(StatusBar statusBar) {
|
||||
public CheckVersion(StatusBar statusBar) {
|
||||
this.statusBar = statusBar;
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,6 @@ import net.azib.ipscan.core.values.Empty;
|
||||
import net.azib.ipscan.fetchers.FetcherRegistry;
|
||||
import net.azib.ipscan.fetchers.HostnameFetcher;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
@ -31,7 +30,7 @@ public class OpenerLauncher {
|
||||
private final FetcherRegistry fetcherRegistry;
|
||||
private final ScanningResultList scanningResults;
|
||||
|
||||
@Inject public OpenerLauncher(FetcherRegistry fetcherRegistry, ScanningResultList scanningResults) {
|
||||
public OpenerLauncher(FetcherRegistry fetcherRegistry, ScanningResultList scanningResults) {
|
||||
this.fetcherRegistry = fetcherRegistry;
|
||||
this.scanningResults = scanningResults;
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -48,7 +47,6 @@ public class ScanMenuActions {
|
||||
private final ResultTable resultTable;
|
||||
private final StateMachine stateMachine;
|
||||
|
||||
@Inject
|
||||
public LoadFromFile(TXTExporter txtExporter, ExporterRegistry exporterRegistry, FeederGUIRegistry feederRegistry, ScanningResultList scanningResults, ResultTable resultTable, StateMachine stateMachine) {
|
||||
this.txtExporter = txtExporter;
|
||||
this.exporterRegistry = exporterRegistry;
|
||||
@ -202,21 +200,18 @@ public class ScanMenuActions {
|
||||
}
|
||||
|
||||
public static final class SaveAll extends SaveResults {
|
||||
@Inject
|
||||
public SaveAll(ExporterRegistry exporterRegistry, ResultTable resultTable, StatusBar statusBar, StateMachine stateMachine) {
|
||||
super(exporterRegistry, resultTable, statusBar, stateMachine, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SaveSelection extends SaveResults {
|
||||
@Inject
|
||||
public SaveSelection(ExporterRegistry exporterRegistry, ResultTable resultTable, StatusBar statusBar, StateMachine stateMachine) {
|
||||
super(exporterRegistry, resultTable, statusBar, stateMachine, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Quit implements Listener {
|
||||
@Inject
|
||||
public Quit() {
|
||||
}
|
||||
|
||||
|
||||
@ -25,9 +25,6 @@ import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import static net.azib.ipscan.core.state.ScanningState.*;
|
||||
@ -39,9 +36,7 @@ import static net.azib.ipscan.gui.util.LayoutHelper.icon;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class StartStopScanningAction implements SelectionListener, ScanningProgressCallback, StateTransitionListener {
|
||||
|
||||
private ScannerDispatcherThreadFactory scannerThreadFactory;
|
||||
private ScannerDispatcherThread scannerThread;
|
||||
private GUIConfig guiConfig;
|
||||
@ -83,10 +78,9 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
buttonTexts[KILLING.ordinal()] = Labels.getLabel("button.kill");
|
||||
}
|
||||
|
||||
@Inject
|
||||
public StartStopScanningAction(ScannerDispatcherThreadFactory scannerThreadFactory, StateMachine stateMachine, ResultTable resultTable,
|
||||
StatusBar statusBar, FeederGUIRegistry feederRegistry, PingerRegistry pingerRegistry,
|
||||
@Named("startStopButton") Button startStopButton, GUIConfig guiConfig) {
|
||||
Button startStopButton, GUIConfig guiConfig) {
|
||||
this(startStopButton.getDisplay());
|
||||
|
||||
this.scannerThreadFactory = scannerThreadFactory;
|
||||
@ -205,7 +199,6 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
statusBar.setStatusText(Labels.getLabel("state.killingThreads"));
|
||||
break;
|
||||
}
|
||||
// change button image
|
||||
button.setImage(buttonImages[state.ordinal()]);
|
||||
button.setText(buttonTexts[state.ordinal()]);
|
||||
}
|
||||
|
||||
@ -20,8 +20,6 @@ import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static net.azib.ipscan.core.ScanningResult.ResultType.*;
|
||||
|
||||
/**
|
||||
@ -37,7 +35,7 @@ public class ToolsActions {
|
||||
private final ResultTable resultTable;
|
||||
private final StatusBar statusBar;
|
||||
|
||||
@Inject public Preferences(PreferencesDialog preferencesDialog, ResultTable resultTable, StatusBar statusBar) {
|
||||
public Preferences(PreferencesDialog preferencesDialog, ResultTable resultTable, StatusBar statusBar) {
|
||||
this.preferencesDialog = preferencesDialog;
|
||||
this.resultTable = resultTable;
|
||||
this.statusBar = statusBar;
|
||||
@ -57,7 +55,7 @@ public class ToolsActions {
|
||||
public static final class ChooseFetchers implements Listener {
|
||||
private final SelectFetchersDialog selectFetchersDialog;
|
||||
|
||||
@Inject public ChooseFetchers(SelectFetchersDialog selectFetchersDialog) {
|
||||
public ChooseFetchers(SelectFetchersDialog selectFetchersDialog) {
|
||||
this.selectFetchersDialog = selectFetchersDialog;
|
||||
}
|
||||
|
||||
@ -72,7 +70,6 @@ public class ToolsActions {
|
||||
private final StatisticsDialog statisticsDialog;
|
||||
private final GUIConfig guiConfig;
|
||||
|
||||
@Inject
|
||||
public ScanStatistics(GUIConfig guiConfig, StatisticsDialog statisticsDialog, StateMachine stateMachine, CommandLineProcessor commandProcessor) {
|
||||
this.guiConfig = guiConfig;
|
||||
this.statisticsDialog = statisticsDialog;
|
||||
@ -143,7 +140,6 @@ public class ToolsActions {
|
||||
}
|
||||
|
||||
public static final class SelectAlive extends SelectDesired {
|
||||
@Inject
|
||||
public SelectAlive(ResultTable resultTable) {
|
||||
super(resultTable);
|
||||
}
|
||||
@ -154,7 +150,6 @@ public class ToolsActions {
|
||||
}
|
||||
|
||||
public static final class SelectDead extends SelectDesired {
|
||||
@Inject
|
||||
public SelectDead(ResultTable resultTable) {
|
||||
super(resultTable);
|
||||
}
|
||||
@ -165,7 +160,6 @@ public class ToolsActions {
|
||||
}
|
||||
|
||||
public static final class SelectWithPorts extends SelectDesired {
|
||||
@Inject
|
||||
public SelectWithPorts(ResultTable resultTable) {
|
||||
super(resultTable);
|
||||
}
|
||||
@ -176,7 +170,6 @@ public class ToolsActions {
|
||||
}
|
||||
|
||||
public static final class SelectWithoutPorts extends SelectDesired {
|
||||
@Inject
|
||||
public SelectWithoutPorts(ResultTable resultTable) {
|
||||
super(resultTable);
|
||||
}
|
||||
@ -212,7 +205,6 @@ public class ToolsActions {
|
||||
public static final class SelectInvert implements Listener {
|
||||
private final ResultTable resultTable;
|
||||
|
||||
@Inject
|
||||
public SelectInvert(ResultTable resultTable) {
|
||||
this.resultTable = resultTable;
|
||||
}
|
||||
|
||||
13
src/net/azib/ipscan/gui/feeders/ControlsArea.java
Normal file
13
src/net/azib/ipscan/gui/feeders/ControlsArea.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.azib.ipscan.gui.feeders;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class ControlsArea extends Composite {
|
||||
public ControlsArea(Shell parent) {
|
||||
super(parent, SWT.NONE);
|
||||
}
|
||||
|
||||
@Override protected void checkSubclass() {}
|
||||
}
|
||||
13
src/net/azib/ipscan/gui/feeders/FeederArea.java
Normal file
13
src/net/azib/ipscan/gui/feeders/FeederArea.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.azib.ipscan.gui.feeders;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class FeederArea extends Composite {
|
||||
public FeederArea(Shell parent) {
|
||||
super(parent, SWT.NONE);
|
||||
}
|
||||
|
||||
@Override protected void checkSubclass() {}
|
||||
}
|
||||
@ -6,17 +6,11 @@
|
||||
package net.azib.ipscan.gui.feeders;
|
||||
|
||||
import net.azib.ipscan.config.GUIConfig;
|
||||
import net.azib.ipscan.feeders.Feeder;
|
||||
import net.azib.ipscan.feeders.FeederException;
|
||||
import net.azib.ipscan.feeders.FeederRegistry;
|
||||
import net.azib.ipscan.feeders.RescanFeeder;
|
||||
import net.azib.ipscan.feeders.*;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -25,9 +19,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class FeederGUIRegistry implements FeederRegistry<AbstractFeederGUI> {
|
||||
|
||||
public class FeederGUIRegistry implements FeederRegistry {
|
||||
private final List<AbstractFeederGUI> feederGUIList;
|
||||
private final Combo feederSelectionCombo;
|
||||
private final GUIConfig guiConfig;
|
||||
@ -35,7 +27,7 @@ public class FeederGUIRegistry implements FeederRegistry<AbstractFeederGUI> {
|
||||
Feeder lastFeeder;
|
||||
private AbstractFeederGUI currentFeederGUI;
|
||||
|
||||
@Inject public FeederGUIRegistry(List<AbstractFeederGUI> allTheFeeders, @Named("feederSelectionCombo") Combo feederSelectionCombo, GUIConfig guiConfig) {
|
||||
public FeederGUIRegistry(List<AbstractFeederGUI> allTheFeeders, FeederSelectionCombo feederSelectionCombo, GUIConfig guiConfig) {
|
||||
this.feederGUIList = allTheFeeders;
|
||||
this.feederSelectionCombo = feederSelectionCombo;
|
||||
for (AbstractFeederGUI feederGUI : feederGUIList) {
|
||||
@ -65,8 +57,9 @@ public class FeederGUIRegistry implements FeederRegistry<AbstractFeederGUI> {
|
||||
currentFeederGUI.setVisible(true);
|
||||
}
|
||||
|
||||
public Iterator<AbstractFeederGUI> iterator() {
|
||||
return feederGUIList.iterator();
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Iterator<FeederCreator> iterator() {
|
||||
return (Iterator) feederGUIList.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
13
src/net/azib/ipscan/gui/feeders/FeederSelectionCombo.java
Normal file
13
src/net/azib/ipscan/gui/feeders/FeederSelectionCombo.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.azib.ipscan.gui.feeders;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
public class FeederSelectionCombo extends Combo {
|
||||
public FeederSelectionCombo(Composite parent) {
|
||||
super(parent, SWT.READ_ONLY);
|
||||
}
|
||||
|
||||
@Override protected void checkSubclass() {}
|
||||
}
|
||||
@ -12,11 +12,10 @@ import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import static net.azib.ipscan.config.Labels.getLabel;
|
||||
|
||||
@ -25,11 +24,10 @@ import static net.azib.ipscan.config.Labels.getLabel;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class FileFeederGUI extends AbstractFeederGUI {
|
||||
private Text fileNameText;
|
||||
|
||||
@Inject public FileFeederGUI(@Named("feederArea") Composite parent) {
|
||||
public FileFeederGUI(FeederArea parent) {
|
||||
super(parent);
|
||||
feeder = new FileFeeder();
|
||||
}
|
||||
|
||||
@ -13,10 +13,6 @@ import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static net.azib.ipscan.config.Labels.getLabel;
|
||||
|
||||
/**
|
||||
@ -24,15 +20,12 @@ import static net.azib.ipscan.config.Labels.getLabel;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class RandomFeederGUI extends AbstractFeederGUI {
|
||||
private Text ipPrototypeText;
|
||||
private Combo ipMaskCombo;
|
||||
private Text hostnameText;
|
||||
private Button ipUpButton;
|
||||
private Spinner countSpinner;
|
||||
|
||||
@Inject public RandomFeederGUI(@Named("feederArea") Composite parent) {
|
||||
public RandomFeederGUI(FeederArea parent) {
|
||||
super(parent);
|
||||
feeder = new RandomFeeder();
|
||||
}
|
||||
@ -45,8 +38,8 @@ public class RandomFeederGUI extends AbstractFeederGUI {
|
||||
Label ipMaskLabel = new Label(this, SWT.NONE);
|
||||
ipMaskCombo = new Combo(this, SWT.NONE);
|
||||
Label hostnameLabel = new Label(this, SWT.NONE);
|
||||
hostnameText = new Text(this, SWT.BORDER);
|
||||
ipUpButton = new Button(this, SWT.NONE);
|
||||
Text hostnameText = new Text(this, SWT.BORDER);
|
||||
Button ipUpButton = new Button(this, SWT.NONE);
|
||||
Label countLabel = new Label(this, SWT.NONE);
|
||||
countSpinner = new Spinner(this, SWT.BORDER);
|
||||
|
||||
|
||||
@ -16,9 +16,6 @@ import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@ -31,18 +28,16 @@ import static net.azib.ipscan.util.InetAddressUtils.*;
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
@Singleton
|
||||
public class RangeFeederGUI extends AbstractFeederGUI {
|
||||
private Text startIPText;
|
||||
private Text endIPText;
|
||||
private Text hostnameText;
|
||||
private Button ipUpButton;
|
||||
private Combo netmaskCombo;
|
||||
|
||||
private boolean isEndIPUnedited = true;
|
||||
private boolean modifyListenersDisabled = false;
|
||||
|
||||
@Inject public RangeFeederGUI(@Named("feederArea") Composite parent) {
|
||||
public RangeFeederGUI(FeederArea parent) {
|
||||
super(parent);
|
||||
feeder = new RangeFeeder();
|
||||
}
|
||||
@ -56,7 +51,7 @@ public class RangeFeederGUI extends AbstractFeederGUI {
|
||||
endIPText = new Text(this, SWT.BORDER);
|
||||
Label hostnameLabel = new Label(this, SWT.NONE);
|
||||
hostnameText = new Text(this, SWT.BORDER);
|
||||
ipUpButton = new Button(this, SWT.NONE);
|
||||
Button ipUpButton = new Button(this, SWT.NONE);
|
||||
netmaskCombo = new Combo(this, SWT.NONE);
|
||||
|
||||
// the longest possible IP
|
||||
|
||||
@ -5,17 +5,11 @@ import net.azib.ipscan.gui.actions.ToolsActions;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* ColumnsMenu wrapper for type-safety.
|
||||
* This is the menu when clicking on a column header.
|
||||
*/
|
||||
@Singleton
|
||||
public class ColumnsMenu extends ExtendableMenu {
|
||||
|
||||
@Inject
|
||||
public ColumnsMenu(Shell parent,
|
||||
ColumnsActions.SortBy sortByListener,
|
||||
ColumnsActions.AboutFetcher aboutListener,
|
||||
|
||||
@ -7,13 +7,9 @@ import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class CommandsMenu extends AbstractMenu {
|
||||
|
||||
@Inject public CommandsMenu(Shell parent, CommandsMenuActions actions, OpenersMenu openersMenu) {
|
||||
public CommandsMenu(Shell parent, CommandsMenuActions actions, OpenersMenu openersMenu) {
|
||||
this(parent, SWT.DROP_DOWN, actions, openersMenu);
|
||||
}
|
||||
|
||||
|
||||
@ -4,16 +4,10 @@ import net.azib.ipscan.gui.actions.FavoritesMenuActions;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* FavoritesMenu wrapper for type-safety
|
||||
*/
|
||||
@Singleton
|
||||
public class FavoritesMenu extends AbstractMenu {
|
||||
|
||||
@Inject
|
||||
public FavoritesMenu(Shell parent,
|
||||
FavoritesMenuActions.Add addListener,
|
||||
FavoritesMenuActions.Edit editListener,
|
||||
|
||||
@ -4,13 +4,7 @@ import net.azib.ipscan.gui.actions.GotoMenuActions;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class GotoMenu extends AbstractMenu {
|
||||
|
||||
@Inject
|
||||
public GotoMenu(Shell parent,
|
||||
GotoMenuActions.NextAliveHost nextAliveHost,
|
||||
GotoMenuActions.NextHostWithInfo nextHostWithInfo,
|
||||
|
||||
@ -5,13 +5,7 @@ import net.azib.ipscan.gui.actions.HelpMenuActions;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class HelpMenu extends AbstractMenu {
|
||||
|
||||
@Inject
|
||||
public HelpMenu(Shell parent,
|
||||
HelpMenuActions.GettingStarted gettingStarted,
|
||||
HelpMenuActions.Website website,
|
||||
|
||||
@ -5,14 +5,11 @@ import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* OpenersMenu wrapper for type-safety
|
||||
*/
|
||||
public class OpenersMenu extends AbstractMenu {
|
||||
|
||||
@Inject
|
||||
public OpenersMenu(Shell parent,
|
||||
CommandsMenuActions.EditOpeners editOpenersListener,
|
||||
CommandsMenuActions.ShowOpenersMenu showOpenersMenuListener) {
|
||||
|
||||
@ -4,13 +4,9 @@ import net.azib.ipscan.gui.actions.CommandsMenuActions;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ResultsContextMenu extends CommandsMenu {
|
||||
|
||||
@Inject public ResultsContextMenu(Shell parent, CommandsMenuActions actions, OpenersMenu openersMenu) {
|
||||
public ResultsContextMenu(Shell parent, CommandsMenuActions actions, OpenersMenu openersMenu) {
|
||||
super(parent, SWT.POP_UP, actions, openersMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,13 +5,8 @@ import net.azib.ipscan.gui.actions.ScanMenuActions;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ScanMenu extends AbstractMenu {
|
||||
|
||||
@Inject
|
||||
public ScanMenu(Shell parent,
|
||||
ScanMenuActions.LoadFromFile loadFromFile,
|
||||
ScanMenuActions.SaveAll saveAll,
|
||||
|
||||
@ -8,14 +8,8 @@ import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ToolsMenu extends AbstractMenu {
|
||||
|
||||
@Inject
|
||||
public ToolsMenu(Shell parent,
|
||||
public ToolsMenu(Shell parent,
|
||||
ToolsActions.Preferences preferences,
|
||||
ToolsActions.ChooseFetchers chooseFetchers,
|
||||
ToolsActions.ScanStatistics scanStatistics,
|
||||
@ -24,7 +18,6 @@ public class ToolsMenu extends AbstractMenu {
|
||||
ToolsActions.SelectWithPorts selectWithPorts,
|
||||
ToolsActions.SelectWithoutPorts selectWithoutPorts,
|
||||
ToolsActions.SelectInvert selectInvert) {
|
||||
|
||||
super(parent);
|
||||
|
||||
initMenuItem(this, "menu.tools.preferences", "Ctrl+Shift+P", SWT.MOD1 | (Platform.MAC_OS ? ',' : SWT.MOD2 | 'P'), preferences, true);
|
||||
|
||||
@ -1,32 +1,20 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.angryip.org/ for more information.
|
||||
* Licensed under GPLv2.
|
||||
*/
|
||||
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import net.azib.ipscan.exporters.Exporter;
|
||||
import net.azib.ipscan.exporters.ExporterRegistry;
|
||||
import net.azib.ipscan.feeders.FeederCreator;
|
||||
import net.azib.ipscan.feeders.FeederRegistry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.azib.ipscan.exporters.Exporter;
|
||||
import net.azib.ipscan.exporters.ExporterRegistry;
|
||||
import net.azib.ipscan.feeders.FeederCreator;
|
||||
import net.azib.ipscan.feeders.FeederRegistry;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* CommandLineProcessorTest
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class CommandLineProcessorTest {
|
||||
private CommandLineProcessor processor;
|
||||
private FeederCreator feederCreator;
|
||||
@ -40,7 +28,7 @@ public class CommandLineProcessorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringGeneratesUsageHelp() throws Exception {
|
||||
public void toStringGeneratesUsageHelp() {
|
||||
when(feederCreator.getFeederId()).thenReturn("feeder.range");
|
||||
when(feederCreator.serializePartsLabels()).thenReturn(new String[] {"feeder.range.to"});
|
||||
Exporter exporter = mock(Exporter.class);
|
||||
@ -58,7 +46,7 @@ public class CommandLineProcessorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minimal() throws Exception {
|
||||
public void minimal() {
|
||||
when(feederCreator.getFeederId()).thenReturn("feeder.feeder");
|
||||
when(feederCreator.serializePartsLabels()).thenReturn(new String[] {"1st", "2nd"});
|
||||
Exporter txtExporter = mock(Exporter.class);
|
||||
@ -74,11 +62,11 @@ public class CommandLineProcessorTest {
|
||||
assertFalse(processor.appendToFile);
|
||||
assertTrue("specifying exporter should enable autoStart", processor.autoStart);
|
||||
|
||||
verify(feederCreator).unserialize(new String[] {"arg1", "arg2"});
|
||||
verify(feederCreator).unserialize("arg1", "arg2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void options() throws Exception {
|
||||
public void options() {
|
||||
when(feederCreator.getFeederId()).thenReturn("feeder.mega");
|
||||
when(feederCreator.serializePartsLabels()).thenReturn(new String[0]);
|
||||
|
||||
@ -89,48 +77,45 @@ public class CommandLineProcessorTest {
|
||||
assertTrue(processor.autoStart);
|
||||
assertTrue(processor.appendToFile);
|
||||
|
||||
verify(feederCreator).unserialize(new String[0]);
|
||||
verify(feederCreator).unserialize();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void missingRequiredFeeder() throws Exception {
|
||||
public void missingRequiredFeeder() {
|
||||
processor.parse("-o", "exporter");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void inexistentExporter() throws Exception {
|
||||
public void inexistentExporter() {
|
||||
processor.parse("-o", "blah");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void inexistentFeeder() throws Exception {
|
||||
public void inexistentFeeder() {
|
||||
processor.parse("-f:blah");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void extraExporter() throws Exception {
|
||||
public void extraExporter() {
|
||||
processor.parse("-f:feeder", "-o", "exporter.txt", "-o", "exporter.xml");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void extraFeeder() throws Exception {
|
||||
public void extraFeeder() {
|
||||
processor.parse("-f:feeder", "-o", "exporter.xml", "-f:feeder");
|
||||
}
|
||||
|
||||
public static class MockFeederRegistry implements FeederRegistry<FeederCreator> {
|
||||
|
||||
public static class MockFeederRegistry implements FeederRegistry {
|
||||
private List<FeederCreator> list;
|
||||
|
||||
public MockFeederRegistry(FeederCreator ... creators) {
|
||||
list = Arrays.asList(creators);
|
||||
}
|
||||
|
||||
public void select(String feederId) {
|
||||
}
|
||||
public void select(String feederId) { }
|
||||
|
||||
public Iterator<FeederCreator> iterator() {
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
18
test/net/azib/ipscan/config/ComponentRegistryTest.java
Normal file
18
test/net/azib/ipscan/config/ComponentRegistryTest.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import net.azib.ipscan.di.Injector;
|
||||
import net.azib.ipscan.gui.MacApplicationMenu;
|
||||
import net.azib.ipscan.gui.MainWindow;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ComponentRegistryTest {
|
||||
@Test
|
||||
public void mainClassesCanBeCreated() {
|
||||
Injector injector = new ComponentRegistry().init();
|
||||
assertNotNull(injector.require(CommandLineProcessor.class));
|
||||
assertNotNull(injector.require(MainWindow.class));
|
||||
assertNotNull(injector.require(MacApplicationMenu.class));
|
||||
}
|
||||
}
|
||||
@ -19,6 +19,7 @@ public class PluginLoaderTest {
|
||||
System.setProperty("ipscan.plugins", DummyFetcher.class.getName());
|
||||
loader.loadPluginsSpecifiedInSystemProperties(container);
|
||||
assertEquals(DummyFetcher.class, container.get(0));
|
||||
System.getProperties().remove("ipscan.plugins");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
63
test/net/azib/ipscan/di/InjectorTest.java
Normal file
63
test/net/azib/ipscan/di/InjectorTest.java
Normal file
@ -0,0 +1,63 @@
|
||||
package net.azib.ipscan.di;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.Temporal;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class InjectorTest {
|
||||
private Injector injector = new Injector();
|
||||
|
||||
@Test
|
||||
public void require() {
|
||||
assertNotNull(injector.require(Dummy.class));
|
||||
assertNotNull(injector.require(WithDeps.class).dummy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedRequire() {
|
||||
injector.register(String.class, "mega-name");
|
||||
assertEquals("mega-name", injector.require(WithNamedDeps.class).name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requireAll() {
|
||||
injector.register(LocalDate.class, LocalDate.now());
|
||||
injector.register(LocalTime.class, LocalTime.now());
|
||||
injector.register(LocalDateTime.class, LocalDateTime.now());
|
||||
|
||||
List<Temporal> temporals = injector.requireAll(Temporal.class);
|
||||
assertEquals(3, temporals.size());
|
||||
assertEquals(temporals, injector.require(WithListDeps.class).list);
|
||||
}
|
||||
|
||||
static class Dummy {
|
||||
public Dummy() {}
|
||||
}
|
||||
|
||||
static class WithDeps {
|
||||
Dummy dummy;
|
||||
public WithDeps() {}
|
||||
public WithDeps(Dummy dummy) { this.dummy = dummy; }
|
||||
}
|
||||
|
||||
static class WithNamedDeps {
|
||||
String name;
|
||||
public WithNamedDeps(Dummy dummy, String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
static class WithListDeps {
|
||||
List<Temporal> list;
|
||||
public WithListDeps(List<Temporal> list, Dummy dummy) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,7 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.angryip.org/ for more information.
|
||||
* Licensed under GPLv2.
|
||||
*/
|
||||
package net.azib.ipscan.gui.feeders;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.feeders.Feeder;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.junit.After;
|
||||
@ -20,23 +13,17 @@ import java.util.Collections;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* FeederGUIRegistryTest
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class FeederGUIRegistryTest {
|
||||
|
||||
private Composite parent;
|
||||
private FeederArea parent;
|
||||
private FeederGUIRegistry registry;
|
||||
private Combo feederSelectionCombo;
|
||||
private FeederSelectionCombo feederSelectionCombo;
|
||||
private RangeFeederGUI feederGUI;
|
||||
|
||||
@Before
|
||||
public void createRegistry() {
|
||||
parent = new Shell();
|
||||
parent = new FeederArea(new Shell());
|
||||
|
||||
feederSelectionCombo = mock(Combo.class);
|
||||
feederSelectionCombo = mock(FeederSelectionCombo.class);
|
||||
|
||||
feederGUI = new RangeFeederGUI(parent);
|
||||
feederGUI.initialize();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user