diff --git a/src/main/java/de/idrinth/stellaris/modtools/gui/FXMLController.java b/src/main/java/de/idrinth/stellaris/modtools/gui/FXMLController.java index cec6100..89ff434 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/gui/FXMLController.java +++ b/src/main/java/de/idrinth/stellaris/modtools/gui/FXMLController.java @@ -17,12 +17,6 @@ package de.idrinth.stellaris.modtools.gui; import de.idrinth.stellaris.modtools.process.FillerThread; -import de.idrinth.stellaris.modtools.gui.ClickableTableView; -import de.idrinth.stellaris.modtools.gui.CollisionTableView; -import de.idrinth.stellaris.modtools.gui.FileDataRow; -import de.idrinth.stellaris.modtools.gui.ModDataRow; -import de.idrinth.stellaris.modtools.gui.ModTableView; -import de.idrinth.stellaris.modtools.gui.Progress; import java.awt.Desktop; import java.io.IOException; import java.net.URI; @@ -62,7 +56,7 @@ public class FXMLController implements Initializable { private Button button; @FXML - private Progress test; + private ProgressElementGroup test; private Stage popup; diff --git a/src/main/java/de/idrinth/stellaris/modtools/gui/Progress.java b/src/main/java/de/idrinth/stellaris/modtools/gui/Progress.java index f3a210d..5372e58 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/gui/Progress.java +++ b/src/main/java/de/idrinth/stellaris/modtools/gui/Progress.java @@ -23,7 +23,7 @@ import javafx.scene.control.Tooltip; import javafx.scene.layout.AnchorPane; -public class Progress extends AnchorPane { +public class Progress extends AnchorPane implements ProgressElementGroup { private final ArrayList sets = new ArrayList<>(); private int setNum = 0; @@ -39,10 +39,12 @@ public Progress(ArrayList stepLabels) { this.setVisible(true); } + @Override public void addToStepLabels(String text) { stepLabels.add(text); } + @Override public void update(int current, int maximum) { Platform.runLater(() -> { if (sets.size() <= setNum || null == sets.get(setNum)) { diff --git a/src/main/java/de/idrinth/stellaris/modtools/gui/ProgressElementGroup.java b/src/main/java/de/idrinth/stellaris/modtools/gui/ProgressElementGroup.java new file mode 100644 index 0000000..cc75feb --- /dev/null +++ b/src/main/java/de/idrinth/stellaris/modtools/gui/ProgressElementGroup.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2017 Björn Büttner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.idrinth.stellaris.modtools.gui; + +public interface ProgressElementGroup { + + void addToStepLabels(String text); + + void update(int current, int maximum); + +} diff --git a/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java b/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java index 7ae4ad4..60eb9db 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java @@ -16,7 +16,7 @@ */ package de.idrinth.stellaris.modtools.process; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import java.util.ArrayList; import java.util.ConcurrentModificationException; import java.util.List; @@ -33,16 +33,16 @@ abstract public class AbstractQueue implements Runnable { private final List> futures = new ArrayList<>(); private final List known = new ArrayList<>(); private final Callable callable; - private final Progress progress; + private final ProgressElementGroup progress; - public AbstractQueue(Callable callable, Progress progress, String label, ExecutorService executor) { + public AbstractQueue(Callable callable, ProgressElementGroup progress, String label, ExecutorService executor) { this.callable = callable; this.progress = progress; this.progress.addToStepLabels(label); this.executor = executor; } - public AbstractQueue(Callable callable, Progress progress, String label) { + public AbstractQueue(Callable callable, ProgressElementGroup progress, String label) { this(callable, progress, label, Executors.newFixedThreadPool(20)); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process/FillerThread.java b/src/main/java/de/idrinth/stellaris/modtools/process/FillerThread.java index 19beef3..d0fd9db 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process/FillerThread.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process/FillerThread.java @@ -17,7 +17,7 @@ package de.idrinth.stellaris.modtools.process; import de.idrinth.stellaris.modtools.gui.ClickableTableView; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.ArrayList; import java.util.LinkedList; @@ -29,7 +29,7 @@ public class FillerThread implements Runnable, Callable { private final ArrayList list; private final LinkedList tasks = new LinkedList<>(); - public FillerThread(ArrayList list, Progress progress) { + public FillerThread(ArrayList list, ProgressElementGroup progress) { this.list = list; tasks.add(new de.idrinth.stellaris.modtools.process1datacollection.Queue(this, progress)); tasks.add(new de.idrinth.stellaris.modtools.process2prepatchcleaning.Queue(this, progress)); diff --git a/src/main/java/de/idrinth/stellaris/modtools/process1datacollection/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process1datacollection/Queue.java index 9e71cb1..654aa32 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process1datacollection/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process1datacollection/Queue.java @@ -18,7 +18,7 @@ import de.idrinth.stellaris.modtools.process.FillerThread; import de.idrinth.stellaris.modtools.service.DirectoryLookup; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; import java.io.File; import java.io.IOException; @@ -28,7 +28,7 @@ public class Queue extends AbstractQueue { - public Queue(FillerThread c, Progress progress) { + public Queue(FillerThread c, ProgressElementGroup progress) { super(c, progress, "Collecting data", Executors.newFixedThreadPool(20)); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java index 238d971..c570e25 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java @@ -17,14 +17,14 @@ package de.idrinth.stellaris.modtools.process2prepatchcleaning; import de.idrinth.stellaris.modtools.entity.Original; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; import de.idrinth.stellaris.modtools.process.FillerThread; import de.idrinth.stellaris.modtools.service.PersistenceProvider; public class Queue extends AbstractQueue { - public Queue(FillerThread c, Progress progress) { + public Queue(FillerThread c, ProgressElementGroup progress) { super(c, progress, "Removing manually patched"); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java index 145c49f..bb527a3 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java @@ -17,14 +17,14 @@ package de.idrinth.stellaris.modtools.process3filepatch; import de.idrinth.stellaris.modtools.entity.Patch; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.concurrent.Callable; public class Queue extends AbstractQueue { - public Queue(Callable callable, Progress progress) { + public Queue(Callable callable, ProgressElementGroup progress) { super(callable, progress, "Creating patches"); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java index 320e007..f998ea6 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java @@ -17,14 +17,14 @@ package de.idrinth.stellaris.modtools.process4applypatch; import de.idrinth.stellaris.modtools.entity.Original; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.concurrent.Callable; public class Queue extends AbstractQueue { - public Queue(Callable callable, Progress progress) { + public Queue(Callable callable, ProgressElementGroup progress) { super(callable, progress, "Merging patches"); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process5modcreation/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process5modcreation/Queue.java index 06e11cd..a15d425 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process5modcreation/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process5modcreation/Queue.java @@ -16,14 +16,14 @@ */ package de.idrinth.stellaris.modtools.process5modcreation; -import de.idrinth.stellaris.modtools.gui.Progress; +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; import java.util.concurrent.Callable; import java.util.concurrent.Executors; public class Queue extends AbstractQueue { - public Queue(Callable callable, Progress progress) { + public Queue(Callable callable, ProgressElementGroup progress) { super(callable, progress, "Building Mod", Executors.newSingleThreadExecutor()); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/service/DirectoryLookup.java b/src/main/java/de/idrinth/stellaris/modtools/service/DirectoryLookup.java index caa1266..89745bc 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/service/DirectoryLookup.java +++ b/src/main/java/de/idrinth/stellaris/modtools/service/DirectoryLookup.java @@ -21,6 +21,7 @@ import com.github.sarxos.winreg.WindowsRegistry; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import org.apache.commons.lang3.SystemUtils; public class DirectoryLookup { @@ -48,15 +49,12 @@ public static File getSteamDir() throws RegistryException, IOException { } else if(SystemUtils.IS_OS_MAC) { steamDir = test(new File("~/Library/Application Support/Steam")); } else if(SystemUtils.IS_OS_LINUX) { - try { - steamDir = test(new File("~/.steam/steam")); - } catch(IOException exio1) { - try { - steamDir = test(new File("~/.local/share/Steam")); - } catch(IOException exio2) { - throw new IOException(exio1.getMessage()+exio2.getMessage()); - } - } + ArrayList fl = new ArrayList<>(); + fl.add(new File("~/.steam/steam")); + fl.add(new File("~/.steam/Steam")); + fl.add(new File("~/.local/share/steam")); + fl.add(new File("~/.local/share/Steam")); + steamDir = test(fl); } } return steamDir; @@ -68,4 +66,16 @@ private static File test(File file) throws IOException { } return file; } + + private static File test(ArrayList files) throws IOException { + StringBuilder sb = new StringBuilder(); + for(File file:files) { + try { + return test(file); + } catch(IOException e) { + sb.append(e.getMessage()); + } + } + throw new IOException(sb.toString()); + } } diff --git a/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java b/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java new file mode 100644 index 0000000..6924a7e --- /dev/null +++ b/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2017 Björn Büttner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.idrinth.stellaris.modtools.process; + +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; +import java.util.concurrent.Callable; +import junit.framework.Assert; +import org.junit.Test; + +public class AbstractQueueTest { + + public AbstractQueueTest() { + } + + /** + * Test of add method, of class AbstractQueue. + */ + @Test + public void testAdd() { + System.out.println("add"); + AbstractQueueImpl queue = new AbstractQueueImpl(); + queue.addList(); + queue.add(new TestRunnable(queue)); + queue.add(new TestRunnable(queue,"ääää")); + queue.run(); + Assert.assertEquals(2, queue.increment); + } + + /** + * Test of run method, of class AbstractQueue. + */ + @Test + public void testRun() { + System.out.println("run"); + AbstractQueueImpl queue = new AbstractQueueImpl(); + queue.addList(); + queue.run(); + Assert.assertEquals(1, queue.increment); + } + + private class AbstractQueueImpl extends AbstractQueue { + public volatile int increment=0; + public AbstractQueueImpl() { + super(new TestCallable(), new TestProgressElementGroup(), ""); + } + + @Override + public void addList() { + add(new TestRunnable(this)); + } + } + private class TestProgressElementGroup implements ProgressElementGroup { + + @Override + public void addToStepLabels(String text) { + //done + } + + @Override + public void update(int current, int maximum) { + //done + } + + } + private class TestCallable implements Callable { + @Override + public Object call() { + return null;//nothing to do; + } + } + private class TestRunnable extends Task { + private final String identifier; + public TestRunnable(AbstractQueueImpl queue, String identifier) { + super(queue); + this.identifier = identifier; + } + public TestRunnable(AbstractQueueImpl queue) { + this(queue, "-"); + } + @Override + public void run() { + fill(); + } + @Override + protected void fill() { + ((AbstractQueueImpl) queue).increment++; + } + + @Override + protected String getIdentifier() { + return identifier; + } + } +} diff --git a/src/test/java/de/idrinth/stellaris/modtools/process/FillerThreadTest.java b/src/test/java/de/idrinth/stellaris/modtools/process/FillerThreadTest.java new file mode 100644 index 0000000..82a1abc --- /dev/null +++ b/src/test/java/de/idrinth/stellaris/modtools/process/FillerThreadTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 Björn Büttner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.idrinth.stellaris.modtools.process; + +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; +import java.util.ArrayList; +import java.util.concurrent.Callable; +import org.junit.Assert; +import org.junit.Test; + +public class FillerThreadTest { + + public FillerThreadTest() { + } + + /** + * Test of run method, of class FillerThread. + */ + @Test + public void testRun() { + System.out.println("run"); + Assert.assertTrue("Is not a runnable", Runnable.class.isInstance(new FillerThread(new ArrayList<>(), new TestProgressElementGroup()))); + } + + /** + * Test of call method, of class FillerThread. + */ + @Test + public void testCall() throws Exception { + System.out.println("call"); + Assert.assertTrue("Is not a callable", Callable.class.isInstance(new FillerThread(new ArrayList<>(), new TestProgressElementGroup()))); + } + + private class TestProgressElementGroup implements ProgressElementGroup { + + @Override + public void addToStepLabels(String text) { + //done + } + + @Override + public void update(int current, int maximum) { + //done + } + + } +} diff --git a/src/test/java/de/idrinth/stellaris/modtools/process/TaskTest.java b/src/test/java/de/idrinth/stellaris/modtools/process/TaskTest.java new file mode 100644 index 0000000..02a5705 --- /dev/null +++ b/src/test/java/de/idrinth/stellaris/modtools/process/TaskTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 Björn Büttner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.idrinth.stellaris.modtools.process; + +import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; +import java.io.IOException; +import java.util.ArrayList; +import org.junit.Assert; +import org.junit.Test; + +public class TaskTest { + + public TaskTest() { + } + + /** + * Test of run method, of class Task. + */ + @Test + public void testRun() { + System.out.println("run"); + Assert.assertTrue( + "Is not a runnable", + Runnable.class.isInstance(new FillerThread(new ArrayList<>(), new TestProgressElementGroup())) + ); + } + + /** + * Test of getFullIdentifier method, of class Task. + */ + @Test + public void testGetFullIdentifier() { + System.out.println("getFullIdentifier"); + Assert.assertEquals( + "Full Identifier is not correct", + TaskImpl.class.getName()+"@abc", + new TaskImpl().getFullIdentifier() + ); + } + + public class TaskImpl extends Task { + + public TaskImpl() { + super(null); + } + + @Override + public void fill() throws IOException { + } + + @Override + public String getIdentifier() { + return "abc"; + } + } + private class TestProgressElementGroup implements ProgressElementGroup { + + @Override + public void addToStepLabels(String text) { + //done + } + + @Override + public void update(int current, int maximum) { + //done + } + + } +}