Skip to content

Commit 4e4f460

Browse files
author
jantje
committed
Support for different versions of the same platform
I also got rid of the eclipse_plugin.txt for this.
1 parent 8791530 commit 4e4f460

File tree

9 files changed

+153
-228
lines changed

9 files changed

+153
-228
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/ConfigurationPreferences.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,4 @@ public static Path getPathExtensionPath() {
109109

110110
}
111111

112-
public static File getPlugin_Platform_File() {
113-
return getInstallationPath().append(Const.PLATFORM_PLUGIN_FILE_NAME).toFile();
114-
}
115-
116112
}

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Const.java

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class Const {
7676
public static final String PLATFORM_FILE_NAME = "platform.txt";//$NON-NLS-1$
7777
public static final String VARIANTS_FOLDER_NAME = "variants";//$NON-NLS-1$
7878
public static final String PACKAGES_FOLDER_NAME = "packages";//$NON-NLS-1$
79-
public static final String PLATFORM_PLUGIN_FILE_NAME = "eclipse_plugin.txt"; //$NON-NLS-1$
8079

8180
// tags to interpret the arduino input files
8281
public static final String BoardNameKeyTAG = "name";//$NON-NLS-1$
@@ -148,106 +147,7 @@ public class Const {
148147
public static final String ENV_KEY_JANTJE_BUILD_CORE = ENV_KEY_JANTJE_START + "BUILD_CORE";//$NON-NLS-1$
149148
public static final String ENV_KEY_JANTJE_BUILD_VARIANT = ENV_KEY_JANTJE_START + "BUILD_VARIANT";//$NON-NLS-1$
150149
public static final String ENV_KEY_JANTJE_PACKAGE_NAME = ENV_KEY_JANTJE_START + "PACKAGE.NAME";//$NON-NLS-1$
151-
public static final String ENV_KEY_JANTJE_MAKE_LOCATION = ENV_KEY_JANTJE_START + "MAKE_LOCATION";//$NON-NLS-1$ place
152-
// $NON-NLS-1$
153-
// $NON-NLS-1$
154-
// $NON-NLS-1$
155-
// $NON-NLS-1$
156-
// $NON-NLS-1$
157-
// $NON-NLS-1$
158-
// $NON-NLS-1$
159-
// $NON-NLS-1$
160-
// $NON-NLS-1$
161-
// $NON-NLS-1$
162-
// $NON-NLS-1$
163-
//$NON-NLS-1$ where
164-
// $NON-NLS-1$
165-
// $NON-NLS-1$
166-
// $NON-NLS-1$
167-
// $NON-NLS-1$
168-
// $NON-NLS-1$
169-
// $NON-NLS-1$
170-
// $NON-NLS-1$
171-
// $NON-NLS-1$
172-
// $NON-NLS-1$
173-
// $NON-NLS-1$
174-
// $NON-NLS-1$
175-
//$NON-NLS-1$ make
176-
// $NON-NLS-1$
177-
// $NON-NLS-1$
178-
// $NON-NLS-1$
179-
// $NON-NLS-1$
180-
// $NON-NLS-1$
181-
// $NON-NLS-1$
182-
// $NON-NLS-1$
183-
// $NON-NLS-1$
184-
// $NON-NLS-1$
185-
// $NON-NLS-1$
186-
// $NON-NLS-1$
187-
//$NON-NLS-1$ is
188-
// $NON-NLS-1$
189-
// $NON-NLS-1$
190-
// $NON-NLS-1$
191-
// $NON-NLS-1$
192-
// $NON-NLS-1$
193-
// $NON-NLS-1$
194-
// $NON-NLS-1$
195-
// $NON-NLS-1$
196-
// $NON-NLS-1$
197-
// $NON-NLS-1$
198-
// $NON-NLS-1$
199-
//$NON-NLS-1$ located
200-
// $NON-NLS-1$
201-
// $NON-NLS-1$
202-
// $NON-NLS-1$
203-
// $NON-NLS-1$
204-
// $NON-NLS-1$
205-
// $NON-NLS-1$
206-
// $NON-NLS-1$
207-
// $NON-NLS-1$
208-
// $NON-NLS-1$
209-
// $NON-NLS-1$
210-
// $NON-NLS-1$
211-
//$NON-NLS-1$ only
212-
// $NON-NLS-1$
213-
// $NON-NLS-1$
214-
// $NON-NLS-1$
215-
// $NON-NLS-1$
216-
// $NON-NLS-1$
217-
// $NON-NLS-1$
218-
// $NON-NLS-1$
219-
// $NON-NLS-1$
220-
// $NON-NLS-1$
221-
// $NON-NLS-1$
222-
// $NON-NLS-1$
223-
//$NON-NLS-1$ used
224-
// $NON-NLS-1$
225-
// $NON-NLS-1$
226-
// $NON-NLS-1$
227-
// $NON-NLS-1$
228-
// $NON-NLS-1$
229-
// $NON-NLS-1$
230-
// $NON-NLS-1$
231-
// $NON-NLS-1$
232-
// $NON-NLS-1$
233-
// $NON-NLS-1$
234-
// $NON-NLS-1$
235-
//$NON-NLS-1$ in
236-
// $NON-NLS-1$
237-
// $NON-NLS-1$
238-
// $NON-NLS-1$
239-
// $NON-NLS-1$
240-
// $NON-NLS-1$
241-
// $NON-NLS-1$
242-
// $NON-NLS-1$
243-
// $NON-NLS-1$
244-
// $NON-NLS-1$
245-
// $NON-NLS-1$
246-
// $NON-NLS-1$
247-
//$NON-NLS-1$ windows
248-
// public static final String ENV_KEY_JANTJE_PLATFORM_NAME =
249-
// ENV_KEY_JANTJE_START + "PLATFORM.NAME";//$NON-NLS-1$
250-
150+
public static final String ENV_KEY_JANTJE_MAKE_LOCATION = ENV_KEY_JANTJE_START + "MAKE_LOCATION";//$NON-NLS-1$
251151
//
252152
// template Sketch information
253153

it.baeyens.arduino.core/src/it/baeyens/arduino/managers/ArduinoPlatform.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.eclipse.core.runtime.IStatus;
2828
import org.eclipse.core.runtime.Status;
2929

30-
import it.baeyens.arduino.common.Const;
3130
import it.baeyens.arduino.common.ConfigurationPreferences;
31+
import it.baeyens.arduino.common.Const;
3232
import it.baeyens.arduino.ui.Activator;
3333

3434
public class ArduinoPlatform {
@@ -101,7 +101,7 @@ public List<Board> getBoards() throws CoreException {
101101
boardProps.load(reader);
102102
} catch (IOException e) {
103103
throw new CoreException(
104-
new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoPlatform_loading_boards, e));
104+
new Status(IStatus.ERROR, Activator.getId(), Messages.Platform_loading_boards, e));
105105
}
106106

107107
this.boardsFile = new HierarchicalProperties(boardProps);
@@ -155,7 +155,7 @@ public Properties getPlatformProperties() throws CoreException {
155155
}
156156
} catch (IOException e) {
157157
throw new CoreException(
158-
new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoPlatform_loading_platform, e));
158+
new Status(IStatus.ERROR, Activator.getId(), Messages.Platform_loading_platform, e));
159159
}
160160
}
161161
return this.platformProperties;

it.baeyens.arduino.core/src/it/baeyens/arduino/managers/Manager.java

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313

1414
import java.io.File;
1515
import java.io.FileInputStream;
16-
import java.io.FileNotFoundException;
1716
import java.io.FileOutputStream;
1817
import java.io.FileReader;
1918
import java.io.IOException;
2019
import java.io.InputStream;
21-
import java.io.PrintWriter;
2220
import java.io.Reader;
23-
import java.io.UnsupportedEncodingException;
2421
import java.net.URL;
2522
import java.nio.file.Files;
2623
import java.nio.file.Path;
@@ -165,49 +162,15 @@ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean force
165162
}
166163

167164
} catch (IOException e) {
168-
mstatus.add(
169-
new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoManager_Downloading_make_exe, e));
165+
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Downloading_make_exe, e));
170166
}
171167
}
172168

173-
mstatus.add(make_eclipse_plugin_txt_file(platform));
169+
// mstatus.add(make_eclipse_plugin_txt_file(platform));
174170
return mstatus.getChildren().length == 0 ? Status.OK_STATUS : mstatus;
175171

176172
}
177173

178-
static public IStatus make_eclipse_plugin_txt_file(ArduinoPlatform platform) {
179-
180-
// make a platform_plugin.txt file to store the tool paths
181-
File pluginFile = ConfigurationPreferences.getPlugin_Platform_File();
182-
183-
try (PrintWriter writer = new PrintWriter(pluginFile, "UTF-8");) {
184-
185-
writer.println("#This is a automatically generated file by the Arduino eclipse plugin"); //$NON-NLS-1$
186-
writer.println("#only edit if you know what you are doing"); //$NON-NLS-1$
187-
writer.println("#Have fun"); //$NON-NLS-1$
188-
writer.println("#Jantje"); //$NON-NLS-1$
189-
writer.println();
190-
191-
// TODO there should be a get tools and then loop over the tools as
192-
// this implementation returns the tools several times
193-
for (ArduinoPlatform curplatform : getPlatforms()) {
194-
for (ToolDependency tool : curplatform.getToolsDependencies()) {
195-
if (writer != null) {
196-
writer.println("runtime.tools." + tool.getName() + ".path=" + tool.getTool().getInstallPath());//$NON-NLS-1$ //$NON-NLS-2$
197-
writer.println("runtime.tools." + tool.getName() + tool.getVersion() + ".path=" //$NON-NLS-1$ //$NON-NLS-2$
198-
+ tool.getTool().getInstallPath());
199-
}
200-
}
201-
}
202-
} catch (FileNotFoundException | UnsupportedEncodingException e) {
203-
return new Status(IStatus.WARNING, Activator.getId(), Messages.ArduinoManager_unable_to_create_file
204-
+ pluginFile + '\n' + platform.getName() + Messages.ArduinoManager_will_not_work, e);
205-
}
206-
207-
return Status.OK_STATUS;
208-
209-
}
210-
211174
static public void loadIndices(boolean immediatly) {
212175
if (immediatly) {
213176
internalLoadIndices();
@@ -287,8 +250,7 @@ static public LibraryIndex getLibraryIndex() {
287250
return libraryIndex;
288251
}
289252

290-
static public Board getBoard(String boardName, String platformName, String packageName)
291-
throws CoreException {
253+
static public Board getBoard(String boardName, String platformName, String packageName) throws CoreException {
292254
for (PackageIndex index : packageIndices) {
293255
Package pkg = index.getPackage(packageName);
294256
if (pkg != null) {
@@ -326,6 +288,21 @@ public static List<ArduinoPlatform> getPlatforms() {
326288
return platforms;
327289
}
328290

291+
public static ArduinoPlatform getPlatform(String PlatformTxt) {
292+
String searchString = new File(PlatformTxt).toString();
293+
for (PackageIndex index : packageIndices) {
294+
for (Package pkg : index.getPackages()) {
295+
for (ArduinoPlatform curPlatform : pkg.getPlatforms()) {
296+
String curFile = curPlatform.getPlatformFile().toString();
297+
if (searchString.equals(curFile)) {
298+
return curPlatform;
299+
}
300+
}
301+
}
302+
}
303+
return null;
304+
}
305+
329306
static public List<Board> getInstalledBoards() throws CoreException {
330307
List<Board> boards = new ArrayList<>();
331308
for (PackageIndex index : packageIndices) {
@@ -400,15 +377,15 @@ public static IStatus downloadAndInstall(String pURL, String pArchiveFileName, P
400377
Files.copy(dl.openStream(), Paths.get(archivePath.toString()), StandardCopyOption.REPLACE_EXISTING);
401378
}
402379
} catch (IOException e) {
403-
return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoManager_Failed_to_download + pURL, e);
380+
return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Failed_to_download + pURL, e);
404381
}
405382
return processArchive(pArchiveFileName, pInstallPath, pForceDownload, archiveFullFileName, pMonitor);
406383
}
407384

408385
private static IStatus processArchive(String pArchiveFileName, Path pInstallPath, boolean pForceDownload,
409386
String pArchiveFullFileName, IProgressMonitor pMonitor) {
410387
// Create an ArchiveInputStream with the correct archiving algorithm
411-
String faileToExtractMessage = Messages.ArduinoManager_Failed_to_extract + pArchiveFullFileName;
388+
String faileToExtractMessage = Messages.Manager_Failed_to_extract + pArchiveFullFileName;
412389
if (pArchiveFileName.endsWith("tar.bz2")) { //$NON-NLS-1$
413390
try (ArchiveInputStream inStream = new TarArchiveInputStream(
414391
new BZip2CompressorInputStream(new FileInputStream(pArchiveFullFileName)))) {
@@ -436,7 +413,7 @@ private static IStatus processArchive(String pArchiveFileName, Path pInstallPath
436413
return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e);
437414
}
438415
} else {
439-
return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoManager_Format_not_supported);
416+
return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Format_not_supported);
440417
}
441418
}
442419

@@ -510,7 +487,7 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
510487
while (localstripPath > 0) {
511488
slash = name.indexOf("/", slash); //$NON-NLS-1$
512489
if (slash == -1) {
513-
throw new IOException(Messages.ArduinoManager_no_single_root_folder);
490+
throw new IOException(Messages.Manager_no_single_root_folder);
514491
}
515492
slash++;
516493
localstripPath--;
@@ -520,8 +497,8 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
520497

521498
// Strip the common path prefix when requested
522499
if (!name.startsWith(pathPrefix)) {
523-
throw new IOException(Messages.ArduinoManager_no_single_root_folder_while_file + name
524-
+ Messages.ArduinoManager_is_outside + pathPrefix);
500+
throw new IOException(Messages.Manager_no_single_root_folder_while_file + name
501+
+ Messages.Manager_is_outside + pathPrefix);
525502
}
526503
name = name.substring(pathPrefix.length());
527504
if (name.isEmpty()) {
@@ -532,8 +509,8 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
532509
File outputLinkedFile = null;
533510
if (isLink && linkName != null) {
534511
if (!linkName.startsWith(pathPrefix)) {
535-
throw new IOException(Messages.ArduinoManager_no_single_root_folder_while_file + linkName
536-
+ Messages.ArduinoManager_is_outside + pathPrefix);
512+
throw new IOException(Messages.Manager_no_single_root_folder_while_file + linkName
513+
+ Messages.Manager_is_outside + pathPrefix);
537514
}
538515
linkName = linkName.substring(pathPrefix.length());
539516
outputLinkedFile = new File(destFolder, linkName);
@@ -542,32 +519,32 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
542519
// Symbolic links are referenced with relative paths
543520
outputLinkedFile = new File(linkName);
544521
if (outputLinkedFile.isAbsolute()) {
545-
System.err.println(Messages.ArduinoManager_Warning_file + outputFile
546-
+ Messages.ArduinoManager_links_to_absolute_path + outputLinkedFile);
522+
System.err.println(Messages.Manager_Warning_file + outputFile
523+
+ Messages.Manager_links_to_absolute_path + outputLinkedFile);
547524
System.err.println();
548525
}
549526
}
550527

551528
// Safety check
552529
if (isDirectory) {
553530
if (outputFile.isFile() && !overwrite) {
554-
throw new IOException(Messages.ArduinoManager_Cant_create_folder + outputFile
555-
+ Messages.ArduinoManager_File_exists);
531+
throw new IOException(
532+
Messages.Manager_Cant_create_folder + outputFile + Messages.Manager_File_exists);
556533
}
557534
} else {
558535
// - isLink
559536
// - isSymLink
560537
// - anything else
561538
if (outputFile.exists() && !overwrite) {
562-
throw new IOException(Messages.ArduinoManager_Cant_extract_file + outputFile
563-
+ Messages.ArduinoManager_File_already_exists);
539+
throw new IOException(
540+
Messages.Manager_Cant_extract_file + outputFile + Messages.Manager_File_already_exists);
564541
}
565542
}
566543

567544
// Extract the entry
568545
if (isDirectory) {
569546
if (!outputFile.exists() && !outputFile.mkdirs()) {
570-
throw new IOException(Messages.ArduinoManager_Cant_create_folder + outputFile);
547+
throw new IOException(Messages.Manager_Cant_create_folder + outputFile);
571548
}
572549
foldersTimestamps.put(outputFile, modifiedTime);
573550
} else if (isLink) {
@@ -670,7 +647,7 @@ private static void copyStreamToFile(InputStream in, long size, File outputFile)
670647
while (leftToWrite > 0) {
671648
int length = in.read(buffer);
672649
if (length <= 0) {
673-
throw new IOException(Messages.ArduinoManager_Failed_to_extract + outputFile.getAbsolutePath());
650+
throw new IOException(Messages.Manager_Failed_to_extract + outputFile.getAbsolutePath());
674651
}
675652
fos.write(buffer, 0, length);
676653
leftToWrite -= length;

0 commit comments

Comments
 (0)