Skip to content

Commit b3cc21f

Browse files
author
jantje
committed
#1196 install avr platform from Arduino
1 parent fe1f4a4 commit b3cc21f

File tree

7 files changed

+85
-53
lines changed

7 files changed

+85
-53
lines changed

io.sloeber.core.nl1/OSGI-INF/l10n/bundle_it.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ toolchain.gnu.builder.name = Generatore di sketch Arduino
4040
toolChain.name = Arduino Toolchain (edizione Sloeber)
4141
provider.compoler.settings.name = Impostazioni compilatore Arduino
4242
launchConfigurationType.arduio.name = Impostazioni esecuzione Arduino
43-
builder.ino.to.cpp = Convertitore da INO a CPP
43+
builder.ino.to.cpp = Convertitore da INO a CPP
44+
No_Platform_available=The default platform (Arduino avr) was not found. Please install a platform in arduino->preferences.

io.sloeber.core.nl1/OSGI-INF/l10n/bundle_nl.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ toolchain.gnu.builder.name = Arduino sketch bouwer
4040
toolChain.name = Arduino Toolchain (Sloeber editie)
4141
provider.compoler.settings.name = Arduino compileer instellingen
4242
launchConfigurationType.arduio.name = Arduino Launch
43-
builder.ino.to.cpp = Vorm Ino bestand om naar CPP
43+
builder.ino.to.cpp = Vorm Ino bestand om naar CPP
44+
No_Platform_available=Het standaard platform (Arduino avr) is niet gevonden. Gelieve via arduino->preferences een platform te installeren.

io.sloeber.core/src/io/sloeber/core/Messages.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public class Messages extends NLS {
2121
public static final String BOARD = "{BOARD}"; //$NON-NLS-1$
2222
public static final String CONFIG = "{CONFIG}"; //$NON-NLS-1$
2323
public static final String KEY = "{KEY}"; //$NON-NLS-1$
24-
public static final String FOLDER = "{FOLDER}"; //$NON-NLS-1$
25-
public static final String VERSION = "{VERSION}"; //$NON-NLS-1$
26-
public static final String HOST = "{HOST}"; //$NON-NLS-1$
24+
public static final String FOLDER = "{FOLDER}"; //$NON-NLS-1$
25+
public static final String VERSION = "{VERSION}"; //$NON-NLS-1$
26+
public static final String HOST = "{HOST}"; //$NON-NLS-1$
27+
28+
29+
2730

2831
public static String ArduinoSerial_Comport_Appeared_and_disappeared;
2932
public static String ArduinoSerial_Comport_is_not_behaving_as_expected;
@@ -99,6 +102,8 @@ public class Messages extends NLS {
99102
public static String uploader_no_reset_using_network;
100103
public static String uploader_no_reset_using_programmer;
101104
public static String BoardsManagerIsBussy;
105+
public static String No_Platform_available ;
106+
102107

103108
static {
104109
// initialize resource bundle

io.sloeber.core/src/io/sloeber/core/api/Defaults.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class Defaults {
1212
public static final String EXAMPLES_URL = "https://github.com/Sloeber/arduino-eclipse-plugin/releases/download/V4_3_2/" + EXAMPLE_PACKAGE;
1313

1414
public static final String DEFAULT_INSTALL_PLATFORM_NAME = "Arduino AVR Boards";
15+
public static final String DEFAULT_INSTALL_ARCHITECTURE= "AVR";
16+
public static final String DEFAULT_INSTALL_MAINTAINER= "Arduino";
1517
public static final String[] DEFAULT_INSTALLED_LIBRARIES = new String[] { "Ethernet", "Firmata", "GSM", "Keyboard",
1618
"LiquidCrystal", "Mouse", "SD", "Servo", "Stepper", "TFT", "WiFi", "CapacitiveSensor" };
1719
public static final String DEFAULT = "Default";

io.sloeber.core/src/io/sloeber/core/api/PackageManager.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Arrays;
1616
import java.util.Collection;
1717
import java.util.HashSet;
18+
import java.util.LinkedList;
1819
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
@@ -173,10 +174,7 @@ public static void installsubsetOfLatestPlatforms(int fromIndex, int toIndex) {
173174
* Install all the latest platforms Assumes there are less than 100000 platforms
174175
*/
175176
public static void installAllLatestPlatforms() {
176-
if (!isReady()) {
177-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.BoardsManagerIsBussy, new Exception()));
178-
return;
179-
}
177+
180178
installsubsetOfLatestPlatforms(0, 100000);
181179
}
182180

@@ -185,6 +183,7 @@ public static void installLatestPlatform(String JasonName, String packageName, S
185183
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.BoardsManagerIsBussy, new Exception()));
186184
return;
187185
}
186+
188187
platformsDirty = true;
189188
Package curPackage = InternalPackageManager.getPackage(JasonName, packageName);
190189
if (curPackage != null) {
@@ -912,4 +911,19 @@ public static void updateGlobalEnvironmentVariables() {
912911

913912
platformsDirty = false;
914913
}
914+
915+
/**
916+
* Only the latest versions of the platforms.
917+
*
918+
* @return latest platforms
919+
*/
920+
public static Collection<ArduinoPlatform> getLatestPlatforms() {
921+
Collection<ArduinoPlatform> allLatestPlatforms = new LinkedList<ArduinoPlatform>();
922+
List<Package> allPackages = InternalPackageManager.getPackages();
923+
for (Package curPackage : allPackages) {
924+
allLatestPlatforms.addAll(curPackage.getLatestPlatforms());
925+
}
926+
return allLatestPlatforms;
927+
}
928+
915929
}

io.sloeber.core/src/io/sloeber/core/managers/InternalPackageManager.java

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.file.StandardCopyOption;
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
24+
import java.util.Collection;
2425
import java.util.HashMap;
2526
import java.util.HashSet;
2627
import java.util.List;
@@ -53,7 +54,7 @@
5354

5455
public class InternalPackageManager extends PackageManager {
5556

56-
private static final String FILE = Messages.FILE;
57+
private static final String FILE = Messages.FILE;
5758
private static final String FOLDER = Messages.FOLDER;
5859
private static boolean myIsReady = false;
5960

@@ -76,31 +77,38 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
7677
if (!LibraryManager.libsAreInstalled()) {
7778
LibraryManager.InstallDefaultLibraries(monitor);
7879
}
79-
IPath examplesPath=ConfigurationPreferences.getInstallationPathExamples();
80-
if(!examplesPath.toFile().exists()) {//examples are not installed
80+
IPath examplesPath = ConfigurationPreferences.getInstallationPathExamples();
81+
if (!examplesPath.toFile().exists()) {// examples are not installed
8182
// Download arduino IDE example programs
82-
Common.log(downloadAndInstall(Defaults.EXAMPLES_URL, Defaults.EXAMPLE_PACKAGE,
83-
examplesPath, false, monitor));
83+
Common.log(
84+
downloadAndInstall(Defaults.EXAMPLES_URL, Defaults.EXAMPLE_PACKAGE, examplesPath, false, monitor));
8485
}
8586
if (allBoards.isEmpty()) { // If no boards are installed
8687

8788
MyMultiStatus mstatus = new MyMultiStatus("Failed to configer Sloeber"); //$NON-NLS-1$
8889

8990
if (mstatus.isOK()) {
9091
// if successfully installed the examples: add the boards
91-
92-
Package pkg = getPackageIndices().get(0).getPackages().get(0);
93-
if (pkg != null) {
94-
ArduinoPlatform platform = pkg.getLatestPlatform(Defaults.DEFAULT_INSTALL_PLATFORM_NAME, false);
95-
if (platform == null) {
96-
ArduinoPlatform[] platformList = new ArduinoPlatform[pkg.getLatestPlatforms().size()];
97-
pkg.getLatestPlatforms().toArray(platformList);
98-
platform = platformList[0];
99-
}
100-
if (platform != null) {
101-
mstatus.addErrors(downloadAndInstall(platform, false, monitor));
92+
ArduinoPlatform platform = null;
93+
Collection<ArduinoPlatform> latestsPlatforms = PackageManager.getLatestPlatforms();
94+
if (!latestsPlatforms.isEmpty()) {
95+
platform = latestsPlatforms.iterator().next();
96+
for (ArduinoPlatform curPlatform : latestsPlatforms) {
97+
98+
if (Defaults.DEFAULT_INSTALL_PLATFORM_NAME.equalsIgnoreCase(curPlatform.getName())
99+
&& Defaults.DEFAULT_INSTALL_ARCHITECTURE.equalsIgnoreCase(curPlatform.getArchitecture())
100+
&& Defaults.DEFAULT_INSTALL_MAINTAINER
101+
.equalsIgnoreCase(curPlatform.getParent().getMaintainer())) {
102+
platform = curPlatform;
103+
}
102104
}
103105
}
106+
if (platform == null) {
107+
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), Messages.No_Platform_available));
108+
} else {
109+
mstatus.addErrors(downloadAndInstall(platform, false, monitor));
110+
}
111+
104112
}
105113
if (!mstatus.isOK()) {
106114
StatusManager stMan = StatusManager.getManager();
@@ -125,20 +133,17 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
125133
static public synchronized IStatus downloadAndInstall(ArduinoPlatform platform, boolean forceDownload,
126134
IProgressMonitor monitor) {
127135

128-
129136
MyMultiStatus mstatus = new MyMultiStatus("Failed to install " + platform.getName()); //$NON-NLS-1$
130137
mstatus.addErrors(downloadAndInstall(platform.getUrl(), platform.getArchiveFileName(),
131138
platform.getInstallPath(), forceDownload, monitor));
132139
if (!mstatus.isOK()) {
133140
// no use going on installing tools if the boards failed installing
134141
return mstatus;
135142
}
136-
File packageFile=platform.getParent().getParent().getJsonFile();
137-
File copyToFile=platform.getInstallPath().append( packageFile.getName()).toFile();
143+
File packageFile = platform.getParent().getParent().getJsonFile();
144+
File copyToFile = platform.getInstallPath().append(packageFile.getName()).toFile();
138145
try {
139-
Files.copy(packageFile.toPath(),
140-
copyToFile.toPath(),
141-
StandardCopyOption.REPLACE_EXISTING);
146+
Files.copy(packageFile.toPath(), copyToFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
142147
} catch (IOException e) {
143148
// TODO Auto-generated catch block
144149
e.printStackTrace();
@@ -160,7 +165,7 @@ static public synchronized IStatus downloadAndInstall(ArduinoPlatform platform,
160165
}
161166
}
162167

163-
WorkAround.applyKnownWorkArounds( platform);
168+
WorkAround.applyKnownWorkArounds(platform);
164169
return mstatus;
165170

166171
}
@@ -172,7 +177,6 @@ static public List<PackageIndex> getPackageIndices() {
172177
return packageIndices;
173178
}
174179

175-
176180
static public List<Board> getBoards() {
177181
List<Board> boards = new ArrayList<>();
178182
for (PackageIndex index : getPackageIndices()) {
@@ -330,10 +334,8 @@ static public Tool getTool(String packageName, String toolName, String version)
330334
* done with processArchive so only files types supported by this method will be
331335
* properly extracted
332336
*
333-
* @param pURL
334-
* the url of the file to download
335-
* @param pArchiveFileName
336-
* the name of the file in the download folder
337+
* @param pURL the url of the file to download
338+
* @param pArchiveFileName the name of the file in the download folder
337339
* @param pInstallPath
338340
* @param pForceDownload
339341
* @param pMonitor
@@ -351,7 +353,8 @@ public static IStatus downloadAndInstall(String pURL, String pArchiveFileName, I
351353
myCopy(dl, archivePath.toFile(), true);
352354
}
353355
} catch (IOException e) {
354-
return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Failed_to_download.replace(FILE, pURL), e);
356+
return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Failed_to_download.replace(FILE, pURL),
357+
e);
355358
}
356359
return processArchive(pArchiveFileName, pInstallPath, pForceDownload, archivePath.toString(), pMonitor);
357360
}
@@ -398,7 +401,7 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
398401
// (because creating a file in a folder alters the folder's timestamp)
399402
Map<File, Long> foldersTimestamps = new HashMap<>();
400403

401-
String pathPrefix = new String();
404+
String pathPrefix = new String();
402405

403406
Map<File, File> hardLinks = new HashMap<>();
404407
Map<File, Integer> hardLinksMode = new HashMap<>();
@@ -471,8 +474,9 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
471474

472475
// Strip the common path prefix when requested
473476
if (!name.startsWith(pathPrefix)) {
474-
throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name).replace(FOLDER, pathPrefix));
475-
477+
throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name)
478+
.replace(FOLDER, pathPrefix));
479+
476480
}
477481
name = name.substring(pathPrefix.length());
478482
if (name.isEmpty()) {
@@ -483,7 +487,8 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
483487
File outputLinkedFile = null;
484488
if (isLink && linkName != null) {
485489
if (!linkName.startsWith(pathPrefix)) {
486-
throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name).replace(FOLDER, pathPrefix));
490+
throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name)
491+
.replace(FOLDER, pathPrefix));
487492
}
488493
linkName = linkName.substring(pathPrefix.length());
489494
outputLinkedFile = new File(destFolder, linkName);
@@ -492,7 +497,8 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
492497
// Symbolic links are referenced with relative paths
493498
outputLinkedFile = new File(linkName);
494499
if (outputLinkedFile.isAbsolute()) {
495-
System.err.println(Messages.Manager_archive_error_symbolic_link_to_absolute_path.replace(FILE, outputFile.toString()).replace(FOLDER, outputLinkedFile.toString()));
500+
System.err.println(Messages.Manager_archive_error_symbolic_link_to_absolute_path
501+
.replace(FILE, outputFile.toString()).replace(FOLDER, outputLinkedFile.toString()));
496502
System.err.println();
497503
}
498504
}
@@ -501,15 +507,14 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
501507
if (isDirectory) {
502508
if (outputFile.isFile() && !overwrite) {
503509
throw new IOException(
504-
Messages.Manager_Cant_create_folder_exists.replace(FILE, outputFile.getPath()) );
510+
Messages.Manager_Cant_create_folder_exists.replace(FILE, outputFile.getPath()));
505511
}
506512
} else {
507513
// - isLink
508514
// - isSymLink
509515
// - anything else
510516
if (outputFile.exists() && !overwrite) {
511-
throw new IOException(
512-
Messages.Manager_Cant_extract_file_exist.replace(FILE, outputFile.getPath()));
517+
throw new IOException(Messages.Manager_Cant_extract_file_exist.replace(FILE, outputFile.getPath()));
513518
}
514519
}
515520

@@ -585,14 +590,15 @@ private static void symlink(String from, File to) throws IOException, Interrupte
585590
}
586591

587592
/*
588-
* create a link file at the level of the os
589-
* using mklink /H on windows makes that no admin rights are needed
593+
* create a link file at the level of the os using mklink /H on windows makes
594+
* that no admin rights are needed
590595
*/
591596
@SuppressWarnings("nls")
592597
private static void link(File actualFile, File linkName) throws IOException, InterruptedException {
593-
String[] command = new String[] { "ln", actualFile.getAbsolutePath(), linkName.getAbsolutePath() };
598+
String[] command = new String[] { "ln", actualFile.getAbsolutePath(), linkName.getAbsolutePath() };
594599
if (SystemUtils.IS_OS_WINDOWS) {
595-
command = new String[] { "cmd","/c","mklink", "/H",linkName.getAbsolutePath(), actualFile.getAbsolutePath() };
600+
command = new String[] { "cmd", "/c", "mklink", "/H", linkName.getAbsolutePath(),
601+
actualFile.getAbsolutePath() };
596602
}
597603
Process process = Runtime.getRuntime().exec(command, null, null);
598604
process.waitFor();
@@ -637,7 +643,8 @@ private static void copyStreamToFile(InputStream in, long size, File outputFile)
637643
while (leftToWrite > 0) {
638644
int length = in.read(buffer);
639645
if (length <= 0) {
640-
throw new IOException(Messages.Manager_Failed_to_extract.replace(FILE, outputFile.getAbsolutePath()));
646+
throw new IOException(
647+
Messages.Manager_Failed_to_extract.replace(FILE, outputFile.getAbsolutePath()));
641648
}
642649
fos.write(buffer, 0, length);
643650
leftToWrite -= length;
@@ -657,7 +664,7 @@ public static void removePackageURLs(Set<String> packageUrlsToRemove) {
657664

658665
activeUrls.removeAll(packageUrlsToRemove);
659666

660-
ConfigurationPreferences.setJsonURLs(activeUrls.toArray((String[])null));
667+
ConfigurationPreferences.setJsonURLs(activeUrls.toArray((String[]) null));
661668

662669
// remove the files from disk
663670
for (String curJson : packageUrlsToRemove) {

io.sloeber.core/src/io/sloeber/core/messages.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ Upload_uploading=Uploading project "{PROJECT}" with "{UPLOADER}"
7171
uploader_Failed_to_get_upload_recipe=Failed to get the Upload recipe
7272
uploader_no_reset_using_network=no reset because we are using network upload
7373
uploader_no_reset_using_programmer=no reset because we are using a programmer
74-
BoardsManagerIsBussy=The BoardsManager is still busy, retry later.
74+
BoardsManagerIsBussy=The BoardsManager is still busy, retry later.
75+
No_Platform_available=The default platform (Arduino avr) was not found. Please install a platform in arduino->preferences.
76+

0 commit comments

Comments
 (0)