Skip to content

Commit

Permalink
#1339 fix lots of todo's
Browse files Browse the repository at this point in the history
  • Loading branch information
jantje committed Nov 25, 2021
1 parent 01d8555 commit e62a7cb
Show file tree
Hide file tree
Showing 20 changed files with 867 additions and 869 deletions.
3 changes: 1 addition & 2 deletions io.sloeber.core/src/io/sloeber/core/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ private static void initializeImportantVariables() {
try {
workspace.setDescription(workspaceDesc);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, e.getMessage(), e));
}
// Make sure some important variables are being initialized
InstancePreferences.setPrivateLibraryPaths(InstancePreferences.getPrivateLibraryPaths());
Expand Down
21 changes: 9 additions & 12 deletions io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ private void ParseSection() {
public static List<BoardDescription> makeBoardDescriptors(File boardFile, Map<String, String> options) {
BoardTxtFile txtFile = new BoardTxtFile(resolvePathEnvironmentString(boardFile));
List<BoardDescription> boards = new ArrayList<>();
String[] allSectionNames = txtFile.getAllSectionNames();
for (String curboardName : allSectionNames) {
Map<String, String> boardSection = txtFile.getSection(txtFile.getIDFromNiceName(curboardName));
List<String> boardIDs = txtFile.getAllBoardIDs();
for (String curboardID : boardIDs) {
Map<String, String> boardSection = txtFile.getSection(curboardID);
if (boardSection != null) {
if (!"true".equalsIgnoreCase(boardSection.get("hide"))) { //$NON-NLS-1$ //$NON-NLS-2$
boards.add(new BoardDescription(boardFile, txtFile.getIDFromNiceName(curboardName), options));
boards.add(new BoardDescription(boardFile, curboardID, options));
}
}
}
Expand Down Expand Up @@ -571,8 +571,7 @@ public Path getreferencingPlatformPath() {
}
}

//TODO rename add core
public PlatformTxtFile getreferencedPlatformFile() {
public PlatformTxtFile getreferencedCorePlatformFile() {
updateWhenDirty();
if (myReferencedPlatformCore == null) {
return null;
Expand All @@ -584,8 +583,7 @@ public PlatformTxtFile getreferencedPlatformFile() {
return null;
}

//TODO rename add core
public IPath getReferencedLibraryPath() {
public IPath getReferencedCoreLibraryPath() {
updateWhenDirty();
if (myReferencedPlatformCore == null) {
return null;
Expand All @@ -608,8 +606,7 @@ public String getUploadPatternKey() {
return TOOLS + DOT + upLoadTool + DOT + UPLOAD + DOT + networkPrefix + PATTERN;
}

//TODO rename add core
public IPath getreferencedHardwarePath() {
public IPath getreferencedCoreHardwarePath() {
updateWhenDirty();
if (myReferencedPlatformCore == null) {
return new Path(myBoardTxtFile.getLoadedFile().toString()).removeLastSegments(1);
Expand Down Expand Up @@ -773,7 +770,7 @@ public Map<String, String> getEnvVars() {
allVars.putAll(pluginPreProcessingBoardsTxt.getBoardEnvironVars(getBoardID()));

String architecture = getArchitecture();
IPath coreHardwarePath = getreferencedHardwarePath();
IPath coreHardwarePath = getreferencedCoreHardwarePath();
allVars.put(ENV_KEY_BUILD_ARCH, architecture.toUpperCase());
allVars.put(ENV_KEY_HARDWARE_PATH, coreHardwarePath.removeLastSegments(1).toOSString());
allVars.put(ENV_KEY_BUILD_SYSTEM_PATH, coreHardwarePath.append(SYSTEM).toOSString());
Expand All @@ -793,7 +790,7 @@ public Map<String, String> getEnvVars() {
allVars.put(ENV_KEY_BUILD_VARIANT_PATH, EMPTY);
}

PlatformTxtFile referencedPlatfromFile = getreferencedPlatformFile();
PlatformTxtFile referencedPlatfromFile = getreferencedCorePlatformFile();
// process the platform file referenced by the boards.txt
if (referencedPlatfromFile != null) {
allVars.putAll(referencedPlatfromFile.getAllEnvironVars());
Expand Down
5 changes: 0 additions & 5 deletions io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,6 @@ public static void addPrivateHardwarePath(String newHardwarePath) {
InstancePreferences.setPrivateHardwarePaths(newPaths);
}

public static String[] getBoardNames(String boardFile) {
BoardTxtFile theBoardsFile = new BoardTxtFile(new File(boardFile));
return theBoardsFile.getAllSectionNames();
}

/**
* Searches for all boards.txt files from the hardware folders and the boards
* manager
Expand Down
7 changes: 3 additions & 4 deletions io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1101,19 +1101,18 @@ private IStatus BuildTarget(String targetName) {

try {
IMakeTargetManager targetManager = MakeCorePlugin.getDefault().getTargetManager();
IContainer targetResource = myProject.getFolder("Release");
IContainer targetResource = myProject.getFolder("Release"); //$NON-NLS-1$
IMakeTarget target = targetManager.findTarget(targetResource, targetName);
if (target == null) {
target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder");
target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder"); //$NON-NLS-1$
target.setBuildTarget(targetName);
targetManager.addTarget(targetResource, target);
}
if (target != null) {
target.build(new NullProgressMonitor());
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return new Status(IStatus.ERROR, CORE_PLUGIN_ID, e.getMessage(), e);
}
return Status.OK_STATUS;
}
Expand Down
7 changes: 2 additions & 5 deletions io.sloeber.core/src/io/sloeber/core/tools/Libraries.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static Map<String, IPath> findAllHarwareLibraries(ICConfigurationDescrip
SloeberProject sProject = SloeberProject.getSloeberProject(project, false);
BoardDescription boardDescriptor = sProject.getBoardDescription(confDesc.getName(), false);
// first add the referenced
IPath libPath = boardDescriptor.getReferencedLibraryPath();
IPath libPath = boardDescriptor.getReferencedCoreLibraryPath();
if (libPath != null) {
ret.putAll(findAllSubFolders(libPath));
}
Expand Down Expand Up @@ -426,10 +426,7 @@ public static void checkLibraries(IProject affectedProject) {
.getLatestInstallableLibraries(uninstalledIncludedHeaders);

if (!availableLibs.isEmpty()) {
// We now know which libraries to install
// TODO for now I just install but there should
// be some user
// interaction
// Ask the user which libs need installing
availableLibs = installHandler.selectLibrariesToInstall(availableLibs);
for (Entry<String, ArduinoLibraryVersion> curLib : availableLibs.entrySet()) {
LibraryManager.install(curLib.getValue(), new NullProgressMonitor());
Expand Down
20 changes: 16 additions & 4 deletions io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


public class BoardTxtFile extends TxtFile {

public BoardTxtFile(File boardsFile) {
Expand All @@ -28,7 +29,6 @@ private static File getActualTxtFile(File boardsFile) {
return boardsFile;
}


public String getMenuItemIDFromMenuItemName(String boardID, String menuID, String menuItemName) {

// boardid."menu".menuid.menuitemid=name
Expand Down Expand Up @@ -149,7 +149,6 @@ public Map<String, String> getMenus() {
return getSection(MENU);
}


/**
* this is public String[] getAllSectionNames (String[] toaddNames) with a empty
* toaddnames
Expand All @@ -173,7 +172,7 @@ public String[] getAllSectionNames() {
* @author Trump
*
*/
String[] getAllSectionNames(String[] toaddNames) {
public String[] getAllSectionNames(String[] toaddNames) {

HashSet<String> allNames = new HashSet<>();
for (String curName : toaddNames) {
Expand All @@ -193,6 +192,19 @@ String[] getAllSectionNames(String[] toaddNames) {
return sBoards;
}

public List<String> getAllBoardIDs() {
List<String> allBoardIDs = new LinkedList<>();
for (String curKey : myData.getChildren().keySet()) {
if ((curKey != null) && (!curKey.isEmpty())) {
String theName = myData.getValue(curKey + DOT + NAME);
if ((theName != null) && (!theName.isEmpty())) {
allBoardIDs.add(curKey);
}
}
}
return allBoardIDs;
}

/**
* Get all the key value pairs that need to be added to the environment
* variables for the given boardID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* At the time of writing 560 examples are compiled
*
*/
import static org.junit.Assert.fail;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

Expand All @@ -34,72 +35,72 @@
@SuppressWarnings({ "nls" })
@RunWith(Parameterized.class)
public class CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest {
private CodeDescription myCodeDescriptor;
private MCUBoard myBoard;
private String myProjectName;
private static int myBuildCounter = 0;
private static int myTotalFails = 0;
private static int maxFails = 50;
private static int mySkipAtStart = 0;

public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(String projectName, CodeDescription codeDescriptor,
MCUBoard board) {

myCodeDescriptor = codeDescriptor;
myBoard = board;
myProjectName = projectName;
}

@SuppressWarnings("rawtypes")
@Parameters(name = " {0}")
public static Collection examples() {
Shared.waitForAllJobsToFinish();
Preferences.setUseBonjour(false);
LinkedList<Object[]> examples = new LinkedList<>();
MCUBoard[] allBoards = Arduino.getAllBoards();

TreeMap<String, IPath> exampleFolders = LibraryManager.getAllArduinoIDEExamples();
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
String fqn = curexample.getKey().trim();
IPath examplePath = curexample.getValue();
Examples example = new Examples(fqn, examplePath);
if (!skipExample(example)) {
ArrayList<IPath> paths = new ArrayList<>();

paths.add(examplePath);
CodeDescription codeDescriptor = CodeDescription.createExample(false, paths);
for (MCUBoard curboard : allBoards) {
if (curboard.isExampleSupported(example)) {
String projectName = Shared.getProjectName(codeDescriptor, example, curboard);
Object[] theData = new Object[] { projectName, codeDescriptor, curboard };
examples.add(theData);
}
}
}
}

return examples;

}

private static boolean skipExample(Examples example) {
// skip Teensy stuff on Arduino hardware
// Teensy is so mutch more advanced that most arduino avr hardware can not
// handle it
return example.getPath().toString().contains("Teensy");
}

@Test
public void testExample() {

Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart);
Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails);

if (!Shared.BuildAndVerify(myProjectName, myBoard.getBoardDescriptor(), myCodeDescriptor,
private CodeDescription myCodeDescriptor;
private MCUBoard myBoard;
private String myProjectName;
private static int myBuildCounter = 0;
private static int myTotalFails = 0;
private static int maxFails = 50;
private static int mySkipAtStart = 0;

public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(String projectName, CodeDescription codeDescriptor,
MCUBoard board) {

myCodeDescriptor = codeDescriptor;
myBoard = board;
myProjectName = projectName;
}

@SuppressWarnings("rawtypes")
@Parameters(name = " {0}")
public static Collection examples() {
Shared.waitForAllJobsToFinish();
Preferences.setUseBonjour(false);
LinkedList<Object[]> examples = new LinkedList<>();
List<MCUBoard> allBoards = Arduino.getAllBoards();

TreeMap<String, IPath> exampleFolders = LibraryManager.getAllArduinoIDEExamples();
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
String fqn = curexample.getKey().trim();
IPath examplePath = curexample.getValue();
Example example = new Example(fqn, examplePath);
if (!skipExample(example)) {
ArrayList<IPath> paths = new ArrayList<>();

paths.add(examplePath);
CodeDescription codeDescriptor = CodeDescription.createExample(false, paths);
for (MCUBoard curboard : allBoards) {
if (curboard.isExampleSupported(example)) {
String projectName = Shared.getProjectName(codeDescriptor, example, curboard);
Object[] theData = new Object[] { projectName, codeDescriptor, curboard };
examples.add(theData);
}
}
}
}

return examples;

}

private static boolean skipExample(Example example) {
// skip Teensy stuff on Arduino hardware
// Teensy is so mutch more advanced that most arduino avr hardware can not
// handle it
return example.getPath().toString().contains("Teensy");
}

@Test
public void testExample() {

Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart);
Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails);

if (!Shared.BuildAndVerify(myProjectName, myBoard.getBoardDescriptor(), myCodeDescriptor,
new CompileDescription())) {
myTotalFails++;
fail(Shared.getLastFailMessage());
}
}
myTotalFails++;
fail(Shared.getLastFailMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static Collection examples() {
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
String fqn = curexample.getKey().trim();
IPath examplePath = curexample.getValue();
Examples example = new Examples(fqn, examplePath);
Example example = new Example(fqn, examplePath);
if (!skipExample(example)) {
ArrayList<IPath> paths = new ArrayList<>();
paths.add(examplePath);
Expand All @@ -94,7 +94,7 @@ public static Collection examples() {
}

@SuppressWarnings("unused")
private static boolean skipExample(Examples example) {
private static boolean skipExample(Example example) {
// no need to skip examples in this test
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Collection examples() {
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
String fqn = curexample.getKey().trim();
IPath examplePath = curexample.getValue();
Examples example = new Examples(fqn, examplePath);
Example example = new Example(fqn, examplePath);
if (!skipExample(example)) {
ArrayList<IPath> paths = new ArrayList<>();

Expand All @@ -78,7 +78,7 @@ public static Collection examples() {

}

private static boolean skipExample(Examples example) {
private static boolean skipExample(Example example) {
switch (example.getFQN()) {
case "example/10.StarterKit/BasicKit/p13_TouchSensorLamp":
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public static Collection boards() {

List<BoardDescription> boards = new ArrayList<>();
for (File curBoardFile : BoardsManager.getAllBoardsFiles()) {
// TOFIX these options should not be set here but in IBoard.getOptions
Map<String, String> options = null;
System.out.println("Adding boards of " + curBoardFile.toString());
boards.addAll(BoardDescription.makeBoardDescriptors(curBoardFile, options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public static Collection examples() {
CodeDescription codeDescriptor = CodeDescription.createExample(false, paths);

String fqn=curexample.getKey();
Examples example=new Examples(fqn,curexample.getValue());
Example example=new Example(fqn,curexample.getValue());
// with the current amount of examples only do one
MCUBoard board = Examples.pickBestBoard(example, myBoards);
MCUBoard board = Example.pickBestBoard(example, myBoards);
if (board != null) {
BoardDescription curBoard = board.getBoardDescriptor();
if (curBoard != null) {
Expand Down
Loading

0 comments on commit e62a7cb

Please sign in to comment.