Skip to content
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ script:
- sh -c "if $TRAVIS_SECURE_ENV_VARS; then echo Travis SECURE available -- Deploy; else echo Travis SECURE NOT available -- Verify; fi"

#Execute the maven commands depending on SECURE availabilty and print the elapsed time out periodically.
- sh -c "if $TRAVIS_SECURE_ENV_VARS; then ./travis_exec_and_print_time.sh 'mvn deploy -Dtest=RegressionTest --quiet --settings settings.xml'; else ./travis_exec_and_print_time.sh 'mvn verify -Dtest=RegressionTest --quiet --settings settings.xml'; fi"
- sh -c "if $TRAVIS_SECURE_ENV_VARS; then ./travis_exec_and_print_time.sh 'mvn verify -Dtest=RegressionTest --quiet --settings settings.xml'; else ./travis_exec_and_print_time.sh 'mvn verify -Dtest=RegressionTest --quiet --settings settings.xml'; fi"

#Several usernames and passwords/tokens are required for deployment.
#When testing on your local/remote setup then you need to set/export env. variables:
Expand Down
174 changes: 83 additions & 91 deletions io.sloeber.core/src/io/sloeber/core/managers/WorkAround.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,30 @@
import io.sloeber.core.tools.Version;

/**
* A class to apply workarounds to installed packages
* workaround are done after installation
* at usage of boards.txt file
* at usage of platform.txt file
* A class to apply workarounds to installed packages workaround are done after
* installation at usage of boards.txt file at usage of platform.txt file
*
* The first line of the worked around files contain a key
* A newer version of sloeber that has a different workaround shuld change the key
* in this way the worked around files can be persisted and updated when needed
* The first line of the worked around files contain a key A newer version of
* sloeber that has a different workaround shuld change the key in this way the
* worked around files can be persisted and updated when needed
*
* @author jan
*
*/
@SuppressWarnings("nls")
public class WorkAround {
//Each time this class is touched consider changing the String below to enforce updates
// Each time this class is touched consider changing the String below to enforce
// updates
private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 3";


/**
* workarounds done at installation time.
* I try to keep those at a minimum but none platform.txt and boards.txt
* workarounds need to be doine during install time
* workarounds done at installation time. I try to keep those at a minimum but
* none platform.txt and boards.txt workarounds need to be doine during install
* time
*
* @param platform
*/
static public void applyKnownWorkArounds(ArduinoPlatform platform) {
static synchronized public void applyKnownWorkArounds(ArduinoPlatform platform) {

/*
* for STM32 V1.8 and later #include "SrcWrapper.h" to Arduino.h remove the
Expand All @@ -70,105 +68,101 @@ static public void applyKnownWorkArounds(ArduinoPlatform platform) {
MakeBoardsSloeberTxt(platform.getBoardsFile());

}



/**
* create a workedaround boards.txt and return that filz
*
*
* @param requestedFileToWorkAround
*
* @return the worked around file or requestedFileToWorkAround is it does not exist or error
* @return the worked around file or requestedFileToWorkAround is it does not
* exist or error
*/
static public File MakeBoardsSloeberTxt(File requestedFileToWorkAround) {
if(!requestedFileToWorkAround.exists()) {
static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAround) {
if (!requestedFileToWorkAround.exists()) {
return requestedFileToWorkAround;
}
String inFile=requestedFileToWorkAround.toString();
String actualFileToLoad=inFile.replace(Const.BOARDS_FILE_NAME,"boards.sloeber.txt");
if(inFile.equals(actualFileToLoad)) {
String inFile = requestedFileToWorkAround.toString();
String actualFileToLoad = inFile.replace(Const.BOARDS_FILE_NAME, "boards.sloeber.txt");
if (inFile.equals(actualFileToLoad)) {
Common.log(new Status(IStatus.ERROR, Activator.getId(),
"Boards.txt file is not recognized " + requestedFileToWorkAround.toString()));
return requestedFileToWorkAround;
}
File boardsSloeberTXT=new File(actualFileToLoad);
if(boardsSloeberTXT.exists()) {
//delete if outdated
File boardsSloeberTXT = new File(actualFileToLoad);
if (boardsSloeberTXT.exists()) {
// delete if outdated
String firstLine = null;
try(BufferedReader Buff = new BufferedReader(new FileReader(boardsSloeberTXT));) {
try (BufferedReader Buff = new BufferedReader(new FileReader(boardsSloeberTXT));) {
firstLine = Buff.readLine();
} catch (Exception e) {
//ignore and delete the file
}
if(!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
// ignore and delete the file
}
if (!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
boardsSloeberTXT.delete();
}
}
if(!boardsSloeberTXT.exists()) {
if (requestedFileToWorkAround.exists()) {
try {
if (SystemUtils.IS_OS_WINDOWS) {
String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE+"\n";
boardsTXT += FileUtils.readFileToString(requestedFileToWorkAround, Charset.defaultCharset());
boardsTXT = boardsTXT.replace("\r\n", "\n");


// replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
// with circuitplay32u4cat.build.usb_manufacturer=Adafruit
boardsTXT = boardsTXT.replaceAll("(\\S+\\.build\\.usb\\S+)=\\\"(.+)\\\"", "$1=$2");


FileUtils.write(boardsSloeberTXT, boardsTXT, Charset.defaultCharset());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (!boardsSloeberTXT.exists()) {
try {
String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n";
boardsTXT += FileUtils.readFileToString(requestedFileToWorkAround, Charset.defaultCharset());
boardsTXT = boardsTXT.replace("\r\n", "\n");

if (SystemUtils.IS_OS_WINDOWS) {
// replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
// with circuitplay32u4cat.build.usb_manufacturer=Adafruit
boardsTXT = boardsTXT.replaceAll("(\\S+\\.build\\.usb\\S+)=\\\"(.+)\\\"", "$1=$2");
}
FileUtils.write(boardsSloeberTXT, boardsTXT, Charset.defaultCharset());
} catch (IOException e) {
Common.log(new Status(IStatus.WARNING, Activator.getId(),
"Failed to apply work arounds to " + requestedFileToWorkAround.toString(), e));
return requestedFileToWorkAround;
}
}
return boardsSloeberTXT;
}



/**
* create a workedaround platform.txt and return that filz
*
*
* @param requestedFileToWorkAround
*
* @return the worked around file or requestedFileToWorkAround is it does not exist or error
* @return the worked around file or requestedFileToWorkAround is it does not
* exist or error
*/
public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
if(!requestedFileToWorkAround.exists()) {
public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
if (!requestedFileToWorkAround.exists()) {
return requestedFileToWorkAround;
}
String inFile=requestedFileToWorkAround.toString();
String actualFileToLoad=inFile.replace(Const.PLATFORM_FILE_NAME,"platform.sloeber.txt");
if(inFile.equals(actualFileToLoad)) {
String inFile = requestedFileToWorkAround.toString();
String actualFileToLoad = inFile.replace(Const.PLATFORM_FILE_NAME, "platform.sloeber.txt");
if (inFile.equals(actualFileToLoad)) {
Common.log(new Status(IStatus.ERROR, Activator.getId(),
"platform.txt file is not recognized " + requestedFileToWorkAround.toString()));
return requestedFileToWorkAround;
}
File platformSloeberTXT=new File(actualFileToLoad);
if(platformSloeberTXT.exists()) {
//delete if outdated
File platformSloeberTXT = new File(actualFileToLoad);
if (platformSloeberTXT.exists()) {
// delete if outdated
String firstLine = null;
try(BufferedReader Buff = new BufferedReader(new FileReader(platformSloeberTXT));) {
try (BufferedReader Buff = new BufferedReader(new FileReader(platformSloeberTXT));) {
firstLine = Buff.readLine();
} catch (Exception e) {
//ignore and delete the file
}
if(!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
// ignore and delete the file
}
if (!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
platformSloeberTXT.delete();
}
}
if (!platformSloeberTXT.exists()) {
try {
String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE+"\n";
String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n";
platformTXT += FileUtils.readFileToString(requestedFileToWorkAround, Charset.defaultCharset());
platformTXT = platformTXT.replace("\r\n", "\n");
//Arduino treats core differently so we need to change the location of directly
//referenced files this manifestates only in the combine recipe
int inCombineStartIndex=platformTXT.indexOf("\nrecipe.c.combine.pattern")+1;

// Arduino treats core differently so we need to change the location of directly
// referenced files this manifestates only in the combine recipe
int inCombineStartIndex = platformTXT.indexOf("\nrecipe.c.combine.pattern") + 1;
if (inCombineStartIndex > 0) {
int inCombineEndIndex = platformTXT.indexOf("\n", inCombineStartIndex) - 1;
if (inCombineEndIndex > 0) {
Expand All @@ -180,15 +174,14 @@ public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
}
}


// workaround for infineon arm v1.4.0 overwriting the default to a wrong value
platformTXT = platformTXT.replace("\nbuild.core.path", "\n#line removed by Sloeber build.core.path");

Path platformTXTPath= new Path (requestedFileToWorkAround.toString());
int totalSegments= platformTXTPath.segmentCount();
String platformVersion= platformTXTPath.segment(totalSegments-2);
String platformArchitecture= platformTXTPath.segment(totalSegments-3);
String platformName= platformTXTPath.segment(totalSegments-5);
Path platformTXTPath = new Path(requestedFileToWorkAround.toString());
int totalSegments = platformTXTPath.segmentCount();
String platformVersion = platformTXTPath.segment(totalSegments - 2);
String platformArchitecture = platformTXTPath.segment(totalSegments - 3);
String platformName = platformTXTPath.segment(totalSegments - 5);
if (Version.compare("1.8.0", platformVersion) != 1) {
if ("stm32".equals(platformArchitecture)) {
if ("STM32".equals(platformName)) {
Expand All @@ -198,30 +191,29 @@ public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
}
}


//for adafruit nfr
platformTXT = platformTXT.replace("-DARDUINO_BSP_VERSION=\"{version}\"", "\"-DARDUINO_BSP_VERSION=\\\"{version}\\\"\"");
// for adafruit nfr
platformTXT = platformTXT.replace("-DARDUINO_BSP_VERSION=\"{version}\"",
"\"-DARDUINO_BSP_VERSION=\\\"{version}\\\"\"");

if (SystemUtils.IS_OS_WINDOWS) {
// replace FI '-DUSB_PRODUCT={build.usb_product}' with
// "-DUSB_PRODUCT=\"{build.usb_product}\""
platformTXT = platformTXT.replaceAll("\\'-D(\\S+)=\\{(\\S+)}\\'", "\"-D$1=\\\\\"{$2}\\\\\"\"");


//quoting fixes for embedutils
platformTXT = platformTXT.replaceAll("\"?(-DMBEDTLS_\\S+)=\\\\?\"(mbedtls\\S+)\"\\\\?\"*", "\"$1=\\\\\"$2\\\\\"\"");

//Sometimes "-DUSB_MANUFACTURER={build.usb_manufacturer}" "-DUSB_PRODUCT={build.usb_product}"
//is used fi LinKit smart
platformTXT = platformTXT.replace("\"-DUSB_MANUFACTURER={build.usb_manufacturer}\"",

// quoting fixes for embedutils
platformTXT = platformTXT.replaceAll("\"?(-DMBEDTLS_\\S+)=\\\\?\"(mbedtls\\S+)\"\\\\?\"*",
"\"$1=\\\\\"$2\\\\\"\"");

// Sometimes "-DUSB_MANUFACTURER={build.usb_manufacturer}"
// "-DUSB_PRODUCT={build.usb_product}"
// is used fi LinKit smart
platformTXT = platformTXT.replace("\"-DUSB_MANUFACTURER={build.usb_manufacturer}\"",
"\"-DUSB_MANUFACTURER=\\\"{build.usb_manufacturer}\\\"\"");
platformTXT = platformTXT.replace("\"-DUSB_PRODUCT={build.usb_product}\"",
platformTXT = platformTXT.replace("\"-DUSB_PRODUCT={build.usb_product}\"",
"\"-DUSB_PRODUCT=\\\"{build.usb_product}\\\"\"");
platformTXT = platformTXT.replace(" -DARDUINO_BOARD=\"{build.board}\" ",
platformTXT = platformTXT.replace(" -DARDUINO_BOARD=\"{build.board}\" ",
" \"-DARDUINO_BOARD=\\\"{build.board}\\\"\" ");



}
FileUtils.write(platformSloeberTXT, platformTXT, Charset.defaultCharset());
} catch (IOException e) {
Expand Down
13 changes: 11 additions & 2 deletions io.sloeber.core/src/io/sloeber/core/tools/TxtFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,21 @@ public TxtFile(File boardsFileName, boolean workAround) {

this.mLastLoadedTxtFile =boardsFileName;
File actuallyLoadedTxtFile = mLastLoadedTxtFile;
// If the file doesn't exist ignore it.
if (!boardsFileName.exists()) {
return ;
}

if(workAround) {
actuallyLoadedTxtFile =WorkAround.MakeBoardsSloeberTxt(boardsFileName);
}
// If the file doesn't exist ignore it.
if (!actuallyLoadedTxtFile.exists())

if (!actuallyLoadedTxtFile.exists()) {
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
"Worked around file " +actuallyLoadedTxtFile.toString() + " does not exist.")); //$NON-NLS-1$ //$NON-NLS-2$
return ;
}


this.fileContent.clear();

Expand Down
10 changes: 3 additions & 7 deletions io.sloeber.tests/src/io/sloeber/core/RegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.sloeber.providers.ESP8266;
import io.sloeber.providers.MCUBoard;

@SuppressWarnings("nls")
@SuppressWarnings({"nls","static-method"})
public class RegressionTest {
private static final boolean reinstall_boards_and_libraries = false;

Expand Down Expand Up @@ -64,14 +64,15 @@ public static void installAdditionalBoards() {
* make sure when switching between a board with variant file and without
* the build still succeeds
*/
@SuppressWarnings("static-method")
@Test
public void issue555() {
if (MySystem.getTeensyPlatform().isEmpty()) {
//skip test due to no teensy install folder provided
//do not fail as this will always fail on travis
System.out.println("skipping the test because teensy is not installed.");
return;
}
System.out.println("Teensy is installed at "+MySystem.getTeensyPlatform());
Map<String, String> unoOptions = new HashMap<>();
BoardDescriptor unoBoardid = PackageManager.getBoardDescriptor("package_index.json", "arduino", "Arduino AVR Boards",
"uno", unoOptions);
Expand Down Expand Up @@ -121,7 +122,6 @@ public void issue555() {
* support void loop{};
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
public void issue687() throws Exception {
Arduino.installLatestAVRBoards();
Expand Down Expand Up @@ -155,7 +155,6 @@ public void issue687() throws Exception {
* support void loop{};
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
public void issue1047_Board_Names_Can_Be_used_as_Strings() throws Exception {
MCUBoard unoBoard = ESP8266.nodeMCU();
Expand Down Expand Up @@ -189,7 +188,6 @@ public void issue1047_Board_Names_Can_Be_used_as_Strings() throws Exception {
* code checks whether these defines are set properly
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
public void are_jantjes_options_taken_into_account() throws Exception {
Arduino.installLatestAVRBoards();
Expand Down Expand Up @@ -232,7 +230,6 @@ public void are_jantjes_options_taken_into_account() throws Exception {
* properly by the ino to cpp parser
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
public void are_defines_before_includes_taken_into_account() throws Exception {
Arduino.installLatestAVRBoards();
Expand Down Expand Up @@ -269,7 +266,6 @@ public void are_defines_before_includes_taken_into_account() throws Exception {
* be handled properly by the ino to cpp parser
* @throws Exception
*/
@SuppressWarnings("static-method")
@Test
public void is_extern_C_taken_into_account() throws Exception {
Arduino.installLatestAVRBoards();
Expand Down