Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to version and path parsing to support windows #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions src/com/microchip/mplab/nbide/embedded/arduino/Bundle.properties
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

OpenIDE-Module-Display-Category=MPLAB IDE (Optional)
OpenIDE-Module-Long-Description=\
<html>\nThis plugin contains an import wizard that can be launched from File->Import->Import Arduino Project. \n\
The wizard will allow you to select a sketch file (*.ino) that was created in Arduino IDE. \n\
Next, it will convert the sketch into an MPLAB X Makefile project. \n\
With this project you will be able to build and debug the Arduino sketch in MPLAB X.\
<br><br>A complete set of Help documentation is included. \
Note that the wizard can import a project in two ways:<br>\n1) Copying all source code and libraries, in order to create a stand-alone MPLAB X project which is logically separate from the original (default mode) or<br>2) Retaining links to external source code and libraries that exist in the Arduino environment.\
<br><br>The Arduino Import Plugin requires the following software to be installed: <br>- MPLAB X v4.10 or later<br>- Arduino IDE v1.81 or later<br>- Relevant toolchains configured in MPLAB X<br><br><br><br></html>
OpenIDE-Module-Name=Arduino Import Plugin
OpenIDE-Module-Short-Description=A wizard that allows importing Arduino projects
# Copyright (c) 2017 Microchip Technology Inc. and its subsidiaries (Microchip). All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

OpenIDE-Module-Display-Category=MPLAB IDE (Optional)
OpenIDE-Module-Long-Description=\
<html>\nThis plugin contains an import wizard that can be launched from File->Import->Import Arduino Project. \n\
The wizard will allow you to select a sketch file (*.ino) that was created in Arduino IDE. \n\
Next, it will convert the sketch into an MPLAB X Makefile project. \n\
With this project you will be able to build and debug the Arduino sketch in MPLAB X.\
<br><br>A complete set of Help documentation is included. \
Note that the wizard can import a project in two ways:<br>\n1) Copying all source code and libraries, in order to create a stand-alone MPLAB X project which is logically separate from the original (default mode) or<br>2) Retaining links to external source code and libraries that exist in the Arduino environment.\
<br><br>The Arduino Import Plugin requires the following software to be installed: <br>- MPLAB X v5.30 or later<br>- Arduino IDE v1.81 or later<br>- Relevant toolchains configured in MPLAB X<br><br><br><br>\n\nNote: This is a patch build that fixes issues to support virtualbreadboard on windows until the core project can be updated. \
See www.virtualbreadboard.com for info.\n\
</html>
OpenIDE-Module-Name=Arduino Import Plugin
OpenIDE-Module-Short-Description=A wizard that allows importing Arduino projects
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,22 @@ public boolean isValidArduinoInstallPath(Path path) {
Path p = findArduinoBuilderPath(path);
return Files.exists(p);
}


//new Version("0.0.0");
//new Version("00.000.0000");
private String getVersion(String version){
version = version.substring(9);
int index = 0;
for(int i = 0; i < 3; i++){
index = version.indexOf('.', index + 1);
}
version = version.substring(0,index);
return version;
}

public Optional<Version> findCurrentVersion() {
return findHighestArduinoVersionLine().map(
line -> new Version( line.split("=")[0].substring(9, 14) )
line -> new Version( getVersion( line.split("=")[0] ) )
);
}

Expand All @@ -107,7 +119,7 @@ private Optional<String> findHighestArduinoVersionLine() {

for ( String line : hardwarePathLines ) {
// e.g: last.ide.1.8.2.hardwarepath=...
Version v = new Version( line.substring(9, 14) );
Version v = new Version( getVersion( line ) );
if ( v.compareTo(highestVersion) > 0 ) {
highestVersion = v;
highestVersionLine = line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,33 @@ public boolean isValidPlatformRootPath(Path rootPath) {

private static Platform createPlatformFromFile(Platform rootPlatform, Path platformFilePath) {
// Pattern: /home/user/.arduino15/packages/{vendor}/hardware/{architecture}/x.x.x/platform.txt
// Pattern: Program Files(x86)/Arduino/hardware/arduino/avr/platform.txt

int hardwareIndex = -1;
int arduino15Index = -1;

for (int i = platformFilePath.getNameCount() - 1; i >= 0; i--) {
if ("arduino15".equalsIgnoreCase(platformFilePath.getName(i).toString())) {
arduino15Index = i;
}
if ("hardware".equalsIgnoreCase(platformFilePath.getName(i).toString())) {
hardwareIndex = i;
break;
}
}
String vendor = platformFilePath.getName(hardwareIndex - 1).toString();
String architecture = platformFilePath.getName(hardwareIndex + 1).toString();


String vendor ;
String architecture ;

if( arduino15Index == -1){
//Windows
vendor = platformFilePath.getName(hardwareIndex + 1).toString();
architecture = platformFilePath.getName(hardwareIndex + 2).toString();
}else{
vendor = platformFilePath.getName(hardwareIndex - 1).toString();
architecture = platformFilePath.getName(hardwareIndex + 1).toString();
}

try {
if (architecture.equalsIgnoreCase("pic32")) {
return new PIC32Platform(rootPlatform, vendor, platformFilePath.getParent());
Expand All @@ -99,6 +116,7 @@ private static Platform createPlatformFromFile(Platform rootPlatform, Path platf

}


private static Platform createRootPlatform() throws IOException {
Path arduinoPlatformPath = ArduinoConfig.getInstance().getDefaultArduinoPlatformPath().get();
return new Platform(null, ROOT_PLATFORM_VENDOR, ROOT_PLATFORM_ARCH, arduinoPlatformPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ public void readSettings(WizardDescriptor settings) {

}
}
if (currentPlatform != null) {
view.platformCombo.setSelectedItem( currentPlatform );
onPlatformChanged();
}


// Platform Location
File platformCoreDir = (File) wizardDescriptor.getProperty(ARDUINO_PLATFORM_DIR.key());
Expand All @@ -311,6 +308,15 @@ public void readSettings(WizardDescriptor settings) {
view.platformLocationField.setText( currentPlatform.getRootPath().toString() );
}

if( currentPlatform==null){
resolvePlatformFromPath();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether I understand the reason for this change. If the "currentPlatform" isn't non-null at this point, we are risking a NPE a few lines above (308). We could however move this logic to the line right after line 306 where we set the text for view.platformLocationField.

}

if (currentPlatform != null) {
view.platformCombo.setSelectedItem( currentPlatform );
onPlatformChanged();
}

// Target Device:
String boardName = (String) wizardDescriptor.getProperty(BOARD_NAME.key());
loadBoardsToCombo();
Expand Down Expand Up @@ -691,18 +697,20 @@ private void checkForExistingProject() {
}

private void loadBoardsToCombo() {
String currentlySelectedBoardName = (view.boardCombo.getSelectedItem() != null) ? view.boardCombo.getSelectedItem().toString() : null;
boardIdLookup = currentPlatform.getBoardNamesToIDsLookup();
List<String> boardNames = new ArrayList<>(boardIdLookup.keySet());
// Sort the board names list in alphabetical order:
Collections.sort(boardNames);
// Set up the combo box:
DefaultComboBoxModel<String> cbm = new DefaultComboBoxModel<>(boardNames.toArray(new String[boardNames.size()]));
view.boardCombo.setModel(cbm);
// TODO: Verify whether calling TypeAheadComboBox.enable many times does not have adverse effects
TypeAheadComboBox.enable(view.boardCombo);
if ( currentlySelectedBoardName != null && boardNames.contains(currentlySelectedBoardName) ) {
view.boardCombo.setSelectedItem(currentlySelectedBoardName);
if( currentPlatform!=null){
String currentlySelectedBoardName = (view.boardCombo.getSelectedItem() != null) ? view.boardCombo.getSelectedItem().toString() : null;
boardIdLookup = currentPlatform.getBoardNamesToIDsLookup();
List<String> boardNames = new ArrayList<>(boardIdLookup.keySet());
// Sort the board names list in alphabetical order:
Collections.sort(boardNames);
// Set up the combo box:
DefaultComboBoxModel<String> cbm = new DefaultComboBoxModel<>(boardNames.toArray(new String[boardNames.size()]));
view.boardCombo.setModel(cbm);
// TODO: Verify whether calling TypeAheadComboBox.enable many times does not have adverse effects
TypeAheadComboBox.enable(view.boardCombo);
if ( currentlySelectedBoardName != null && boardNames.contains(currentlySelectedBoardName) ) {
view.boardCombo.setSelectedItem(currentlySelectedBoardName);
}
}
}

Expand Down