Browse Source

Change some more files to paths.

The updater code is horrid. In most cases I've just bailed out by
converting to a file.

Issue #24
pull/26/head
Chris Smith 9 years ago
parent
commit
b05b3fda15

+ 4
- 2
src/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModel.java View File

39
 
39
 
40
 import com.google.common.base.Optional;
40
 import com.google.common.base.Optional;
41
 
41
 
42
+import java.nio.file.Path;
43
+
42
 import javax.inject.Inject;
44
 import javax.inject.Inject;
43
 
45
 
44
 /**
46
 /**
50
     private final ListenerList listeners;
52
     private final ListenerList listeners;
51
     private final AggregateConfigProvider config;
53
     private final AggregateConfigProvider config;
52
     private final ConnectionManager connectionManager;
54
     private final ConnectionManager connectionManager;
53
-    private final String configDirectory;
55
+    private final Path configDirectory;
54
     private Optional<String> name;
56
     private Optional<String> name;
55
     private Optional<String> email;
57
     private Optional<String> email;
56
     private Optional<String> feedback;
58
     private Optional<String> feedback;
60
     @Inject
62
     @Inject
61
     public CoreFeedbackDialogModel(@ClientModule.GlobalConfig final AggregateConfigProvider config,
63
     public CoreFeedbackDialogModel(@ClientModule.GlobalConfig final AggregateConfigProvider config,
62
             final ConnectionManager connectionManager, final FeedbackSenderFactory feedbackSenderFactory,
64
             final ConnectionManager connectionManager, final FeedbackSenderFactory feedbackSenderFactory,
63
-            @Directory(DirectoryType.BASE) final String configDirectory) {
65
+            @Directory(DirectoryType.BASE) final Path configDirectory) {
64
         this.connectionManager = connectionManager;
66
         this.connectionManager = connectionManager;
65
         this.configDirectory = configDirectory;
67
         this.configDirectory = configDirectory;
66
         this.feedbackSenderFactory = feedbackSenderFactory;
68
         this.feedbackSenderFactory = feedbackSenderFactory;

+ 5
- 3
src/com/dmdirc/updater/UpdateComponent.java View File

22
 
22
 
23
 package com.dmdirc.updater;
23
 package com.dmdirc.updater;
24
 
24
 
25
+import java.nio.file.Path;
26
+
25
 /**
27
 /**
26
  * The update component interface defines the methods needed to be implemented by updatable
28
  * The update component interface defines the methods needed to be implemented by updatable
27
  * components. The components handle determining the current version and installing updated files.
29
  * components. The components handle determining the current version and installing updated files.
62
 
64
 
63
     /**
65
     /**
64
      * Provisionally indicates if this component will require a client restart. The result of
66
      * Provisionally indicates if this component will require a client restart. The result of
65
-     * {@link #doInstall(java.lang.String)} ultimately decides if the client requires a restart.
67
+     * {@link #doInstall(Path)} ultimately decides if the client requires a restart.
66
      *
68
      *
67
      * @return True if the client requires a restart
69
      * @return True if the client requires a restart
68
      *
70
      *
89
      *
91
      *
90
      * @since 0.6.4
92
      * @since 0.6.4
91
      */
93
      */
92
-    String getManualInstructions(final String path);
94
+    String getManualInstructions(final Path path);
93
 
95
 
94
     /**
96
     /**
95
      * Installs the updated version of this component. After the update has been installed, the
97
      * Installs the updated version of this component. After the update has been installed, the
101
      *
103
      *
102
      * @throws java.lang.Exception If any error occurred
104
      * @throws java.lang.Exception If any error occurred
103
      */
105
      */
104
-    boolean doInstall(String path) throws Exception; //NOPMD
106
+    boolean doInstall(Path path) throws Exception; //NOPMD
105
 
107
 
106
 }
108
 }

+ 4
- 4
src/com/dmdirc/updater/components/ActionGroupComponent.java View File

28
 import com.dmdirc.updater.Version;
28
 import com.dmdirc.updater.Version;
29
 
29
 
30
 import java.io.IOException;
30
 import java.io.IOException;
31
-import java.nio.file.Paths;
31
+import java.nio.file.Path;
32
 
32
 
33
 /**
33
 /**
34
  * Update component for action groups.
34
  * Update component for action groups.
72
     }
72
     }
73
 
73
 
74
     @Override
74
     @Override
75
-    public String getManualInstructions(final String path) {
75
+    public String getManualInstructions(final Path path) {
76
         return "";
76
         return "";
77
     }
77
     }
78
 
78
 
79
     @Override
79
     @Override
80
-    public boolean doInstall(final String path) throws IOException {
81
-        ActionManager.installActionPack(Paths.get(path));
80
+    public boolean doInstall(final Path path) throws IOException {
81
+        ActionManager.installActionPack(path);
82
         return false;
82
         return false;
83
     }
83
     }
84
 
84
 

+ 20
- 18
src/com/dmdirc/updater/components/ClientComponent.java View File

23
 package com.dmdirc.updater.components;
23
 package com.dmdirc.updater.components;
24
 
24
 
25
 import com.dmdirc.Main;
25
 import com.dmdirc.Main;
26
+import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27
+import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
26
 import com.dmdirc.interfaces.config.IdentityController;
28
 import com.dmdirc.interfaces.config.IdentityController;
27
 import com.dmdirc.ui.StatusMessage;
29
 import com.dmdirc.ui.StatusMessage;
28
 import com.dmdirc.ui.core.components.StatusBarManager;
30
 import com.dmdirc.ui.core.components.StatusBarManager;
30
 import com.dmdirc.updater.Version;
32
 import com.dmdirc.updater.Version;
31
 import com.dmdirc.util.io.FileUtils;
33
 import com.dmdirc.util.io.FileUtils;
32
 
34
 
33
-import java.io.File;
35
+import java.io.IOException;
36
+import java.nio.file.Files;
37
+import java.nio.file.Path;
34
 
38
 
35
 import javax.inject.Inject;
39
 import javax.inject.Inject;
36
 
40
 
43
     private final IdentityController identityController;
47
     private final IdentityController identityController;
44
     /** The manager to add status bar messages to. */
48
     /** The manager to add status bar messages to. */
45
     private final StatusBarManager statusBarManager;
49
     private final StatusBarManager statusBarManager;
50
+    /** Base directory to move updates to. */
51
+    private final Path baseDirectory;
46
 
52
 
47
     /**
53
     /**
48
      * Creates a new instance of {@link ClientComponent}.
54
      * Creates a new instance of {@link ClientComponent}.
53
     @Inject
59
     @Inject
54
     public ClientComponent(
60
     public ClientComponent(
55
             final IdentityController identityController,
61
             final IdentityController identityController,
56
-            final StatusBarManager statusBarManager) {
62
+            final StatusBarManager statusBarManager,
63
+            @Directory(DirectoryType.BASE) final Path baseDirectory) {
57
         this.identityController = identityController;
64
         this.identityController = identityController;
58
         this.statusBarManager = statusBarManager;
65
         this.statusBarManager = statusBarManager;
66
+        this.baseDirectory = baseDirectory;
59
     }
67
     }
60
 
68
 
61
     @Override
69
     @Override
84
     }
92
     }
85
 
93
 
86
     @Override
94
     @Override
87
-    public String getManualInstructions(final String path) {
88
-        final File targetFile = new File(new File(path).getParent()
89
-                + File.separator + ".DMDirc.jar");
95
+    public String getManualInstructions(final Path path) {
96
+        final Path targetFile = baseDirectory.resolve(".DMDirc.jar");
90
 
97
 
91
         if (requiresManualInstall()) {
98
         if (requiresManualInstall()) {
92
             if (FileUtils.isRunningFromJar(Main.class)) {
99
             if (FileUtils.isRunningFromJar(Main.class)) {
95
                         + "not be installed automatically.\n\n"
102
                         + "not be installed automatically.\n\n"
96
                         + "To install this update manually, please replace the\n"
103
                         + "To install this update manually, please replace the\n"
97
                         + "existing DMDirc.jar file, located at:\n"
104
                         + "existing DMDirc.jar file, located at:\n"
98
-                        + " " + FileUtils.getApplicationPath(Main.class)
105
+                        + ' ' + FileUtils.getApplicationPath(Main.class)
99
                         + "\n with the following file:\n "
106
                         + "\n with the following file:\n "
100
-                        + targetFile.getAbsolutePath();
107
+                        + targetFile.toAbsolutePath();
101
             } else {
108
             } else {
102
                 return "A new version of DMDirc has been downloaded, but as you\n"
109
                 return "A new version of DMDirc has been downloaded, but as you\n"
103
                         + "do not seem to be using the DMDirc launcher, it will\n"
110
                         + "do not seem to be using the DMDirc launcher, it will\n"
104
                         + "not be installed automatically.\n\n"
111
                         + "not be installed automatically.\n\n"
105
                         + "To install this update manually, please extract the\n"
112
                         + "To install this update manually, please extract the\n"
106
                         + "new DMDirc.jar file, located at:\n"
113
                         + "new DMDirc.jar file, located at:\n"
107
-                        + " " + targetFile.getAbsolutePath() + "\n"
114
+                        + ' ' + targetFile.toAbsolutePath() + '\n'
108
                         + "over your existing DMDirc install located in:\n"
115
                         + "over your existing DMDirc install located in:\n"
109
                         + "  " + FileUtils.getApplicationPath(Main.class);
116
                         + "  " + FileUtils.getApplicationPath(Main.class);
110
             }
117
             }
118
     }
125
     }
119
 
126
 
120
     @Override
127
     @Override
121
-    public boolean doInstall(final String path) {
122
-        final File tmpFile = new File(path);
123
-        final File targetFile = new File(tmpFile.getParent() + File.separator
124
-                + ".DMDirc.jar");
128
+    public boolean doInstall(final Path path) throws IOException {
129
+        final Path targetFile = baseDirectory.resolve(".DMDirc.jar");
125
 
130
 
126
-        if (targetFile.exists()) {
127
-            targetFile.delete();
128
-        }
129
-
130
-        tmpFile.renameTo(targetFile);
131
+        Files.deleteIfExists(targetFile);
132
+        Files.move(path, targetFile);
131
 
133
 
132
         if (requiresManualInstall()) {
134
         if (requiresManualInstall()) {
133
             // @deprecated Should be removed when updater UI changes are
135
             // @deprecated Should be removed when updater UI changes are
134
             // implemented.
136
             // implemented.
135
-            final String message = this.getManualInstructions(path);
137
+            final String message = getManualInstructions(path);
136
             statusBarManager.setMessage(new StatusMessage(message,
138
             statusBarManager.setMessage(new StatusMessage(message,
137
                     identityController.getGlobalConfiguration()));
139
                     identityController.getGlobalConfiguration()));
138
         }
140
         }

+ 7
- 5
src/com/dmdirc/updater/components/DefaultsComponent.java View File

30
 import com.dmdirc.updater.Version;
30
 import com.dmdirc.updater.Version;
31
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
31
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
32
 
32
 
33
-import java.io.File;
34
 import java.io.IOException;
33
 import java.io.IOException;
34
+import java.nio.file.Files;
35
+import java.nio.file.Path;
35
 
36
 
36
 import javax.inject.Inject;
37
 import javax.inject.Inject;
37
 
38
 
97
     }
98
     }
98
 
99
 
99
     @Override
100
     @Override
100
-    public String getManualInstructions(final String path) {
101
+    public String getManualInstructions(final Path path) {
101
         return "";
102
         return "";
102
     }
103
     }
103
 
104
 
104
     @Override
105
     @Override
105
-    public boolean doInstall(final String path) throws IOException {
106
-        final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
106
+    public boolean doInstall(final Path path) throws IOException {
107
+        final ZipResourceManager ziprm =
108
+                ZipResourceManager.getInstance(path.toAbsolutePath().toString());
107
 
109
 
108
         ziprm.extractResources("", directory);
110
         ziprm.extractResources("", directory);
109
 
111
 
110
         identityController.loadUserIdentities();
112
         identityController.loadUserIdentities();
111
 
113
 
112
-        new File(path).delete();
114
+        Files.delete(path);
113
 
115
 
114
         return false;
116
         return false;
115
     }
117
     }

+ 7
- 6
src/com/dmdirc/updater/components/LauncherComponent.java View File

29
 
29
 
30
 import java.io.File;
30
 import java.io.File;
31
 import java.io.IOException;
31
 import java.io.IOException;
32
+import java.nio.file.Path;
32
 
33
 
33
 /**
34
 /**
34
  * Component for updates of DMDirc's launcher.
35
  * Component for updates of DMDirc's launcher.
104
     }
105
     }
105
 
106
 
106
     @Override
107
     @Override
107
-    public String getManualInstructions(final String path) {
108
+    public String getManualInstructions(final Path path) {
108
         return "";
109
         return "";
109
     }
110
     }
110
 
111
 
111
     @Override
112
     @Override
112
-    public boolean doInstall(final String path) throws IOException {
113
-        final File tmpFile = new File(path);
113
+    public boolean doInstall(final Path path) throws IOException {
114
+        final File tmpFile = path.toFile();
114
         if (platform.equalsIgnoreCase("Linux")
115
         if (platform.equalsIgnoreCase("Linux")
115
                 || platform.equalsIgnoreCase("unix")) {
116
                 || platform.equalsIgnoreCase("unix")) {
116
             final File targetFile = new File(tmpFile.getParent()
117
             final File targetFile = new File(tmpFile.getParent()
124
             targetFile.setExecutable(true);
125
             targetFile.setExecutable(true);
125
 
126
 
126
         } else {
127
         } else {
127
-            ZipResourceManager.getInstance(path).extractResources("",
128
-                    tmpFile.getParent() + File.separator);
129
-            new File(path).delete();
128
+            ZipResourceManager.getInstance(path.toAbsolutePath().toString())
129
+                    .extractResources("", tmpFile.getParent() + File.separator);
130
+            path.toFile().delete();
130
         }
131
         }
131
         return true;
132
         return true;
132
     }
133
     }

+ 7
- 5
src/com/dmdirc/updater/components/ModeAliasesComponent.java View File

30
 import com.dmdirc.updater.Version;
30
 import com.dmdirc.updater.Version;
31
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
31
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
32
 
32
 
33
-import java.io.File;
34
 import java.io.IOException;
33
 import java.io.IOException;
34
+import java.nio.file.Files;
35
+import java.nio.file.Path;
35
 
36
 
36
 import javax.inject.Inject;
37
 import javax.inject.Inject;
37
 
38
 
97
     }
98
     }
98
 
99
 
99
     @Override
100
     @Override
100
-    public String getManualInstructions(final String path) {
101
+    public String getManualInstructions(final Path path) {
101
         return "";
102
         return "";
102
     }
103
     }
103
 
104
 
104
     @Override
105
     @Override
105
-    public boolean doInstall(final String path) throws IOException {
106
-        final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
106
+    public boolean doInstall(final Path path) throws IOException {
107
+        final ZipResourceManager ziprm =
108
+                ZipResourceManager.getInstance(path.toAbsolutePath().toString());
107
 
109
 
108
         ziprm.extractResources("", directory);
110
         ziprm.extractResources("", directory);
109
 
111
 
110
         identityController.loadUserIdentities();
112
         identityController.loadUserIdentities();
111
 
113
 
112
-        new File(path).delete();
114
+        Files.delete(path);
113
 
115
 
114
         return false;
116
         return false;
115
     }
117
     }

+ 5
- 4
src/com/dmdirc/updater/components/PluginComponent.java View File

30
 
30
 
31
 import java.io.File;
31
 import java.io.File;
32
 import java.io.IOException;
32
 import java.io.IOException;
33
+import java.nio.file.Path;
33
 import java.util.zip.ZipFile;
34
 import java.util.zip.ZipFile;
34
 
35
 
35
 /**
36
 /**
83
     }
84
     }
84
 
85
 
85
     @Override
86
     @Override
86
-    public String getManualInstructions(final String path) {
87
+    public String getManualInstructions(final Path path) {
87
         return "";
88
         return "";
88
     }
89
     }
89
 
90
 
90
     @Override
91
     @Override
91
-    public boolean doInstall(final String path) {
92
+    public boolean doInstall(final Path path) {
92
         final File target = new File(plugin.getMetaData().getPluginUrl().getPath());
93
         final File target = new File(plugin.getMetaData().getPluginUrl().getPath());
93
 
94
 
94
         boolean returnCode = false;
95
         boolean returnCode = false;
101
         // Try and move the downloaded plugin to the new location.
102
         // Try and move the downloaded plugin to the new location.
102
         // If it doesn't work then keep the plugin in a .update file until the next restart.
103
         // If it doesn't work then keep the plugin in a .update file until the next restart.
103
         // If it does, update the metadata.
104
         // If it does, update the metadata.
104
-        final File newPlugin = new File(path);
105
+        final File newPlugin = path.toFile();
105
         if (!isValid(newPlugin)) {
106
         if (!isValid(newPlugin)) {
106
             return false;
107
             return false;
107
         }
108
         }
114
                 newTarget.delete();
115
                 newTarget.delete();
115
             }
116
             }
116
 
117
 
117
-            new File(path).renameTo(newTarget);
118
+            path.toFile().renameTo(newTarget);
118
             returnCode = true;
119
             returnCode = true;
119
         } else {
120
         } else {
120
             try {
121
             try {

+ 4
- 3
src/com/dmdirc/updater/installing/LegacyInstallationStrategy.java View File

28
 
28
 
29
 import javax.inject.Inject;
29
 import javax.inject.Inject;
30
 
30
 
31
+import org.slf4j.Logger;
31
 import org.slf4j.LoggerFactory;
32
 import org.slf4j.LoggerFactory;
32
 
33
 
33
 /**
34
 /**
34
  * An {@link UpdateInstallationStrategy} which uses the old
35
  * An {@link UpdateInstallationStrategy} which uses the old
35
- * {@link UpdateComponent#doInstall(java.lang.String)} methods to perform installation.
36
+ * {@link UpdateComponent#doInstall(java.nio.file.Path)} methods to perform installation.
36
  */
37
  */
37
 public class LegacyInstallationStrategy extends TypeSensitiveInstallationStrategy<UpdateComponent, SingleFileRetrievalResult> {
38
 public class LegacyInstallationStrategy extends TypeSensitiveInstallationStrategy<UpdateComponent, SingleFileRetrievalResult> {
38
 
39
 
39
-    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(
40
+    private static final Logger LOG = LoggerFactory.getLogger(
40
             LegacyInstallationStrategy.class);
41
             LegacyInstallationStrategy.class);
41
     /** List of registered listeners. */
42
     /** List of registered listeners. */
42
     private final ListenerList listenerList = new ListenerList();
43
     private final ListenerList listenerList = new ListenerList();
56
                 retrievalResult.getFile(), component.getName());
57
                 retrievalResult.getFile(), component.getName());
57
 
58
 
58
         try {
59
         try {
59
-            component.doInstall(retrievalResult.getFile().getAbsolutePath());
60
+            component.doInstall(retrievalResult.getFile());
60
             listenerList.getCallable(UpdateInstallationListener.class).installCompleted(component);
61
             listenerList.getCallable(UpdateInstallationListener.class).installCompleted(component);
61
         } catch (Exception ex) {
62
         } catch (Exception ex) {
62
             LOG.warn("Error installing update for {}", component.getName(), ex);
63
             LOG.warn("Error installing update for {}", component.getName(), ex);

+ 5
- 6
src/com/dmdirc/updater/retrieving/BaseSingleFileResult.java View File

24
 
24
 
25
 import com.dmdirc.updater.checking.UpdateCheckResult;
25
 import com.dmdirc.updater.checking.UpdateCheckResult;
26
 
26
 
27
-import java.io.File;
27
+import java.nio.file.Path;
28
 
28
 
29
 /**
29
 /**
30
  * Simple implementation of a {@link SingleFileRetrievalResult}.
30
  * Simple implementation of a {@link SingleFileRetrievalResult}.
33
         implements SingleFileRetrievalResult {
33
         implements SingleFileRetrievalResult {
34
 
34
 
35
     /** The file where the update is located. */
35
     /** The file where the update is located. */
36
-    private final File file;
36
+    private final Path file;
37
 
37
 
38
     /**
38
     /**
39
      * Creates a new instance of {@link BaseSingleFileResult}.
39
      * Creates a new instance of {@link BaseSingleFileResult}.
40
-     *
41
-     * @param checkResult The check result that triggered this retrieval
40
+     *  @param checkResult The check result that triggered this retrieval
42
      * @param file        The file containing the update
41
      * @param file        The file containing the update
43
      */
42
      */
44
-    public BaseSingleFileResult(final UpdateCheckResult checkResult, final File file) {
43
+    public BaseSingleFileResult(final UpdateCheckResult checkResult, final Path file) {
45
         super(checkResult, true);
44
         super(checkResult, true);
46
 
45
 
47
         this.file = file;
46
         this.file = file;
48
     }
47
     }
49
 
48
 
50
-    public File getFile() {
49
+    public Path getFile() {
51
         return file;
50
         return file;
52
     }
51
     }
53
 
52
 

+ 12
- 12
src/com/dmdirc/updater/retrieving/DownloadRetrievalStrategy.java View File

29
 import com.dmdirc.util.collections.ListenerList;
29
 import com.dmdirc.util.collections.ListenerList;
30
 import com.dmdirc.util.io.DownloadListener;
30
 import com.dmdirc.util.io.DownloadListener;
31
 import com.dmdirc.util.io.Downloader;
31
 import com.dmdirc.util.io.Downloader;
32
-import org.slf4j.LoggerFactory;
33
 
32
 
34
-import javax.inject.Inject;
35
-import java.io.File;
36
 import java.io.IOException;
33
 import java.io.IOException;
37
-import java.nio.file.Paths;
34
+import java.nio.file.Path;
35
+
36
+import javax.inject.Inject;
37
+
38
+import org.slf4j.LoggerFactory;
38
 
39
 
39
 /**
40
 /**
40
  * An {@link UpdateRetrievalStrategy} that downloads a file specified in a
41
  * An {@link UpdateRetrievalStrategy} that downloads a file specified in a
47
     /** List of registered listeners. */
48
     /** List of registered listeners. */
48
     private final ListenerList listenerList = new ListenerList();
49
     private final ListenerList listenerList = new ListenerList();
49
     /** The directory to put temporary update files in. */
50
     /** The directory to put temporary update files in. */
50
-    private final String directory;
51
+    private final Path directory;
51
     /** Downloader to download files. */
52
     /** Downloader to download files. */
52
     private final Downloader downloader;
53
     private final Downloader downloader;
53
 
54
 
59
      * @param downloader Used to download files
60
      * @param downloader Used to download files
60
      */
61
      */
61
     @Inject
62
     @Inject
62
-    public DownloadRetrievalStrategy(@Directory(DirectoryType.BASE) final String directory,
63
+    public DownloadRetrievalStrategy(@Directory(DirectoryType.BASE) final Path directory,
63
             final Downloader downloader) {
64
             final Downloader downloader) {
64
         super(DownloadableUpdate.class);
65
         super(DownloadableUpdate.class);
65
 
66
 
70
     @Override
71
     @Override
71
     protected UpdateRetrievalResult retrieveImpl(final DownloadableUpdate checkResult) {
72
     protected UpdateRetrievalResult retrieveImpl(final DownloadableUpdate checkResult) {
72
         try {
73
         try {
73
-            final String file = getFileName();
74
+            final Path file = getFile();
74
 
75
 
75
             listenerList.getCallable(UpdateRetrievalListener.class)
76
             listenerList.getCallable(UpdateRetrievalListener.class)
76
                     .retrievalProgressChanged(checkResult.getComponent(), 0);
77
                     .retrievalProgressChanged(checkResult.getComponent(), 0);
77
 
78
 
78
             LOG.debug("Downloading file from {} to {}", checkResult.getUrl(), file);
79
             LOG.debug("Downloading file from {} to {}", checkResult.getUrl(), file);
79
-            downloader.downloadPage(checkResult.getUrl().toString(), Paths.get(file),
80
+            downloader.downloadPage(checkResult.getUrl().toString(), file,
80
                     new DownloadProgressListener(checkResult.getComponent()));
81
                     new DownloadProgressListener(checkResult.getComponent()));
81
 
82
 
82
             listenerList.getCallable(UpdateRetrievalListener.class)
83
             listenerList.getCallable(UpdateRetrievalListener.class)
83
                     .retrievalCompleted(checkResult.getComponent());
84
                     .retrievalCompleted(checkResult.getComponent());
84
 
85
 
85
-            return new BaseSingleFileResult(checkResult, new File(file));
86
+            return new BaseSingleFileResult(checkResult, file);
86
         } catch (IOException ex) {
87
         } catch (IOException ex) {
87
             LOG.warn("I/O exception downloading update from {}", checkResult.getUrl(), ex);
88
             LOG.warn("I/O exception downloading update from {}", checkResult.getUrl(), ex);
88
             listenerList.getCallable(UpdateRetrievalListener.class)
89
             listenerList.getCallable(UpdateRetrievalListener.class)
97
      *
98
      *
98
      * @return The full, local path to download the remote file to
99
      * @return The full, local path to download the remote file to
99
      */
100
      */
100
-    private String getFileName() {
101
-        return directory + File.separator + "update."
102
-                + Math.round(10000 * Math.random()) + ".tmp";
101
+    private Path getFile() {
102
+        return directory.resolve("update." + Math.round(10000 * Math.random()) + ".tmp");
103
     }
103
     }
104
 
104
 
105
     @Override
105
     @Override

+ 1
- 1
src/com/dmdirc/updater/retrieving/SingleFileRetrievalResult.java View File

35
      *
35
      *
36
      * @return The file containing the retrieved update
36
      * @return The file containing the retrieved update
37
      */
37
      */
38
-    File getFile();
38
+    java.nio.file.Path getFile();
39
 
39
 
40
 }
40
 }

+ 13
- 10
test/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModelTest.java View File

28
 
28
 
29
 import com.google.common.base.Optional;
29
 import com.google.common.base.Optional;
30
 
30
 
31
+import java.nio.file.Path;
32
+
31
 import org.junit.Test;
33
 import org.junit.Test;
32
 import org.junit.runner.RunWith;
34
 import org.junit.runner.RunWith;
33
 import org.mockito.Mock;
35
 import org.mockito.Mock;
43
     @Mock private ConnectionManager connectionManager;
45
     @Mock private ConnectionManager connectionManager;
44
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
46
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
45
     @Mock private FeedbackDialogModelListener listener;
47
     @Mock private FeedbackDialogModelListener listener;
48
+    @Mock private Path path;
46
     private static final String NAME = "Bob Dole";
49
     private static final String NAME = "Bob Dole";
47
     private static final String EMAIL = "bob@dole.com";
50
     private static final String EMAIL = "bob@dole.com";
48
     private static final String FEEDBACK = "DMDirc Rocks.";
51
     private static final String FEEDBACK = "DMDirc Rocks.";
51
     public void testName() {
54
     public void testName() {
52
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
55
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
53
                 connectionManager,
56
                 connectionManager,
54
-                feedbackSenderFactory, "configDirectory");
57
+                feedbackSenderFactory, path);
55
         assertEquals("testName", Optional.absent(), instance.getName());
58
         assertEquals("testName", Optional.absent(), instance.getName());
56
         instance.setName(Optional.fromNullable(NAME));
59
         instance.setName(Optional.fromNullable(NAME));
57
         assertEquals("testName", Optional.fromNullable(NAME), instance.getName());
60
         assertEquals("testName", Optional.fromNullable(NAME), instance.getName());
61
     public void testEmail() {
64
     public void testEmail() {
62
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
65
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
63
                 connectionManager,
66
                 connectionManager,
64
-                feedbackSenderFactory, "configDirectory");
67
+                feedbackSenderFactory, path);
65
         assertEquals("testEmail", Optional.absent(), instance.getEmail());
68
         assertEquals("testEmail", Optional.absent(), instance.getEmail());
66
         instance.setEmail(Optional.fromNullable(EMAIL));
69
         instance.setEmail(Optional.fromNullable(EMAIL));
67
         assertEquals("testEmail", Optional.fromNullable(EMAIL), instance.getEmail());
70
         assertEquals("testEmail", Optional.fromNullable(EMAIL), instance.getEmail());
71
     public void testFeedback() {
74
     public void testFeedback() {
72
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
75
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
73
                 connectionManager,
76
                 connectionManager,
74
-                feedbackSenderFactory, "configDirectory");
77
+                feedbackSenderFactory, path);
75
         assertEquals("testFeedback", Optional.absent(), instance.getFeedback());
78
         assertEquals("testFeedback", Optional.absent(), instance.getFeedback());
76
         instance.setFeedback(Optional.fromNullable(FEEDBACK));
79
         instance.setFeedback(Optional.fromNullable(FEEDBACK));
77
         assertEquals("testFeedback", Optional.fromNullable(FEEDBACK), instance.getFeedback());
80
         assertEquals("testFeedback", Optional.fromNullable(FEEDBACK), instance.getFeedback());
81
     public void testServerInfo() {
84
     public void testServerInfo() {
82
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
85
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
83
                 connectionManager,
86
                 connectionManager,
84
-                feedbackSenderFactory, "configDirectory");
87
+                feedbackSenderFactory, path);
85
         assertEquals("testServerInfo", false, instance.getIncludeServerInfo());
88
         assertEquals("testServerInfo", false, instance.getIncludeServerInfo());
86
         instance.setIncludeServerInfo(true);
89
         instance.setIncludeServerInfo(true);
87
         assertEquals("testServerInfo", true, instance.getIncludeServerInfo());
90
         assertEquals("testServerInfo", true, instance.getIncludeServerInfo());
91
     public void testDMDircInfo() {
94
     public void testDMDircInfo() {
92
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
95
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
93
                 connectionManager,
96
                 connectionManager,
94
-                feedbackSenderFactory, "configDirectory");
97
+                feedbackSenderFactory, path);
95
         assertEquals("testDMDircInfo", false, instance.getIncludeDMDircInfo());
98
         assertEquals("testDMDircInfo", false, instance.getIncludeDMDircInfo());
96
         instance.setIncludeDMDircInfo(true);
99
         instance.setIncludeDMDircInfo(true);
97
         assertEquals("testDMDircInfo", true, instance.getIncludeDMDircInfo());
100
         assertEquals("testDMDircInfo", true, instance.getIncludeDMDircInfo());
106
     public void testNameListener() {
109
     public void testNameListener() {
107
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
110
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
108
                 connectionManager,
111
                 connectionManager,
109
-                feedbackSenderFactory, "configDirectory");
112
+                feedbackSenderFactory, path);
110
         instance.addListener(listener);
113
         instance.addListener(listener);
111
         instance.setName(Optional.fromNullable("Bob Dole"));
114
         instance.setName(Optional.fromNullable("Bob Dole"));
112
         verify(listener).nameChanged(Optional.fromNullable("Bob Dole"));
115
         verify(listener).nameChanged(Optional.fromNullable("Bob Dole"));
116
     public void testEmailListener() {
119
     public void testEmailListener() {
117
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
120
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
118
                 connectionManager,
121
                 connectionManager,
119
-                feedbackSenderFactory, "configDirectory");
122
+                feedbackSenderFactory, path);
120
         instance.addListener(listener);
123
         instance.addListener(listener);
121
         instance.setEmail(Optional.fromNullable("bob@dole.com"));
124
         instance.setEmail(Optional.fromNullable("bob@dole.com"));
122
         verify(listener).emailChanged(Optional.fromNullable("bob@dole.com"));
125
         verify(listener).emailChanged(Optional.fromNullable("bob@dole.com"));
126
     public void testFeedbackListener() {
129
     public void testFeedbackListener() {
127
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
130
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
128
                 connectionManager,
131
                 connectionManager,
129
-                feedbackSenderFactory, "configDirectory");
132
+                feedbackSenderFactory, path);
130
         instance.addListener(listener);
133
         instance.addListener(listener);
131
         instance.setFeedback(Optional.fromNullable("DMDirc Rocks."));
134
         instance.setFeedback(Optional.fromNullable("DMDirc Rocks."));
132
         verify(listener).feedbackChanged(Optional.fromNullable("DMDirc Rocks."));
135
         verify(listener).feedbackChanged(Optional.fromNullable("DMDirc Rocks."));
136
     public void testServerInfoListener() {
139
     public void testServerInfoListener() {
137
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
140
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
138
                 connectionManager,
141
                 connectionManager,
139
-                feedbackSenderFactory, "configDirectory");
142
+                feedbackSenderFactory, path);
140
         instance.addListener(listener);
143
         instance.addListener(listener);
141
         instance.setIncludeServerInfo(true);
144
         instance.setIncludeServerInfo(true);
142
         verify(listener).includeServerInfoChanged(true);
145
         verify(listener).includeServerInfoChanged(true);
146
     public void testDMDircInfoListener() {
149
     public void testDMDircInfoListener() {
147
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
150
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
148
                 connectionManager,
151
                 connectionManager,
149
-                feedbackSenderFactory, "configDirectory");
152
+                feedbackSenderFactory, path);
150
         instance.addListener(listener);
153
         instance.addListener(listener);
151
         instance.setIncludeDMDircInfo(true);
154
         instance.setIncludeDMDircInfo(true);
152
         verify(listener).includeDMDircInfoChanged(true);
155
         verify(listener).includeDMDircInfoChanged(true);

+ 22
- 10
test/com/dmdirc/updater/installing/LegacyInstallationStrategyTest.java View File

25
 import com.dmdirc.updater.UpdateComponent;
25
 import com.dmdirc.updater.UpdateComponent;
26
 import com.dmdirc.updater.retrieving.SingleFileRetrievalResult;
26
 import com.dmdirc.updater.retrieving.SingleFileRetrievalResult;
27
 
27
 
28
-import java.io.File;
29
 import java.io.IOException;
28
 import java.io.IOException;
29
+import java.nio.file.Path;
30
 
30
 
31
 import org.junit.Before;
31
 import org.junit.Before;
32
 import org.junit.Test;
32
 import org.junit.Test;
33
+import org.mockito.Matchers;
33
 
34
 
34
-import static org.mockito.Mockito.*;
35
+import static org.mockito.Mockito.mock;
36
+import static org.mockito.Mockito.verify;
37
+import static org.mockito.Mockito.when;
35
 
38
 
36
 public class LegacyInstallationStrategyTest {
39
 public class LegacyInstallationStrategyTest {
37
 
40
 
53
 
56
 
54
     @Test
57
     @Test
55
     public void testCallsInstallWithCorrectPath() throws Exception { // NOPMD
58
     public void testCallsInstallWithCorrectPath() throws Exception { // NOPMD
56
-        final File file = mock(File.class);
57
-        when(file.getAbsolutePath()).thenReturn("/my/path");
59
+        final Path file = mock(Path.class);
60
+        final Path absoluteFile = mock(Path.class);
61
+        when(file.toString()).thenReturn("path");
62
+        when(file.toAbsolutePath()).thenReturn(absoluteFile);
63
+        when(absoluteFile.toString()).thenReturn("/my/path");
58
         when(result.getFile()).thenReturn(file);
64
         when(result.getFile()).thenReturn(file);
59
         strategy.installImpl(component, result);
65
         strategy.installImpl(component, result);
60
-        verify(component).doInstall("/my/path");
66
+        verify(component).doInstall(file);
61
     }
67
     }
62
 
68
 
63
     @Test
69
     @Test
64
     public void testRaisesCompletedEvent() throws Exception { // NOPMD
70
     public void testRaisesCompletedEvent() throws Exception { // NOPMD
65
-        final File file = mock(File.class);
66
-        when(result.getFile()).thenReturn(file);
71
+        final Path file = mock(Path.class);
72
+        final Path absoluteFile = mock(Path.class);
73
+        when(file.toString()).thenReturn("path");
74
+        when(file.toAbsolutePath()).thenReturn(absoluteFile);
75
+        when(absoluteFile.toString()).thenReturn("/my/path");
67
         strategy.addUpdateInstallationListener(listener);
76
         strategy.addUpdateInstallationListener(listener);
68
         strategy.installImpl(component, result);
77
         strategy.installImpl(component, result);
69
         verify(listener).installCompleted(component);
78
         verify(listener).installCompleted(component);
71
 
80
 
72
     @Test
81
     @Test
73
     public void testRaisesFailedEvent() throws Exception { // NOPMD
82
     public void testRaisesFailedEvent() throws Exception { // NOPMD
74
-        final File file = mock(File.class);
75
-        when(result.getFile()).thenReturn(file);
76
-        when(component.doInstall(anyString())).thenThrow(new IOException());
83
+        final Path file = mock(Path.class);
84
+        final Path absoluteFile = mock(Path.class);
85
+        when(file.toString()).thenReturn("path");
86
+        when(file.toAbsolutePath()).thenReturn(absoluteFile);
87
+        when(absoluteFile.toString()).thenReturn("/my/path");
88
+        when(component.doInstall(Matchers.<Path>anyObject())).thenThrow(new IOException());
77
         strategy.addUpdateInstallationListener(listener);
89
         strategy.addUpdateInstallationListener(listener);
78
         strategy.installImpl(component, result);
90
         strategy.installImpl(component, result);
79
         verify(listener).installFailed(component);
91
         verify(listener).installFailed(component);

Loading…
Cancel
Save