blob: c3a9bf42af2b5a0592d115d4aa462676337b4f56 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*******************************************************************************
* Copyright (c) 2015, 2016 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class ArduinoTool {
private String name;
private String version;
private List<ArduinoToolSystem> systems;
private transient ArduinoPackage pkg;
public ArduinoPackage getPackage() {
return pkg;
}
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public List<ArduinoToolSystem> getSystems() {
return systems;
}
void init(ArduinoPackage pkg) {
this.pkg = pkg;
for (ArduinoToolSystem system : systems) {
system.setOwner(this);
}
}
public Path getInstallPath() {
// TODO remove migration in Neon
Path oldPath = ArduinoPreferences.getArduinoHome().resolve("tools").resolve(pkg.getName()).resolve(name) //$NON-NLS-1$
.resolve(version);
Path newPath = getPackage().getInstallPath().resolve("tools").resolve(name).resolve(version); //$NON-NLS-1$
if (Files.exists(oldPath)) {
try {
Files.createDirectories(newPath.getParent());
Files.move(oldPath, newPath);
for (Path parent = oldPath.getParent(); parent != null; parent = parent.getParent()) {
if (Files.newDirectoryStream(parent).iterator().hasNext()) {
break;
} else {
Files.delete(parent);
}
}
} catch (IOException e) {
Activator.log(e);
}
}
return newPath;
}
public boolean isInstalled() {
return getInstallPath().toFile().exists();
}
public void install(IProgressMonitor monitor) throws CoreException {
if (isInstalled()) {
return;
}
for (ArduinoToolSystem system : systems) {
if (system.isApplicable()) {
system.install(monitor);
}
}
// No valid system
throw new CoreException(
new Status(IStatus.ERROR, Activator.getId(), String.format("No valid system found for %s", name))); //$NON-NLS-1$
}
public Properties getToolProperties() {
Properties properties = new Properties();
properties.put("runtime.tools." + name + ".path", ArduinoBuildConfiguration.pathString(getInstallPath())); //$NON-NLS-1$//$NON-NLS-2$
properties.put("runtime.tools." + name + '-' + version + ".path", //$NON-NLS-1$//$NON-NLS-2$
ArduinoBuildConfiguration.pathString(getInstallPath())); //$NON-NLS-1$
return properties;
}
}
|