1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Start of using Arduino package index for board packages.

Added dependency to Gson for JSON parsing and Apache Http Client
for getting the index files from the Arduino site.

Change-Id: I3d265c1037e7f74e082f36c751f5eaf780e96684
This commit is contained in:
Doug Schaefer 2015-07-20 09:36:12 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 5623c39492
commit df39cb4b09
13 changed files with 171 additions and 3 deletions

View file

@ -10,6 +10,9 @@
<unit id="org.junit.source" version="0.0.0"/>
<unit id="org.mockito" version="0.0.0"/>
<unit id="org.hamcrest.core" version="0.0.0"/>
<unit id="com.google.gson" version="0.0.0"/>
<unit id="org.apache.httpcomponents.httpclient" version="0.0.0"/>
<unit id="org.apache.httpcomponents.httpcore" version="0.0.0"/>
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20150519210750/repository/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1 @@
/bin/

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.arduino.core.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests
Bundle-SymbolicName: org.eclipse.cdt.arduino.core.tests
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.cdt.arduino.core;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.junit;bundle-version="4.12.0"

View file

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View file

@ -0,0 +1,27 @@
package org.eclipse.cdt.arduino.core.tests;
import static org.junit.Assert.assertNotNull;
import java.util.concurrent.Semaphore;
import org.eclipse.cdt.arduino.core.IArduinoBoardManager.Handler;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
import org.eclipse.cdt.arduino.core.internal.board.PackageIndex;
import org.junit.Test;
public class BoardManagerTests {
@Test
public void loadPackagesTest() throws Exception {
Semaphore semaphore = new Semaphore(0);
new ArduinoBoardManager().getPackageIndex(new Handler<PackageIndex>() {
@Override
public void handle(PackageIndex result) {
assertNotNull(result);
semaphore.release();
}
});
semaphore.acquire();
}
}

View file

@ -14,7 +14,10 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.launchbar.core,
org.eclipse.remote.core;bundle-version="2.0.0",
org.eclipse.cdt.native.serial;bundle-version="1.0.0",
org.eclipse.remote.serial.core;bundle-version="1.0.0"
org.eclipse.remote.serial.core;bundle-version="1.0.0",
com.google.gson;bundle-version="2.2.4",
org.apache.httpcomponents.httpclient;bundle-version="4.3.6",
org.apache.httpcomponents.httpcore;bundle-version="4.3.3"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: libs/freemarker-2.3.22.jar,

View file

@ -12,8 +12,22 @@ package org.eclipse.cdt.arduino.core;
import java.util.Collection;
/**
* Interface into the board package data.
*/
public interface IArduinoBoardManager {
/**
* Many of the calls into the board manager require reaching out to the web.
* In order to not block UI, these calls are asynchronous. This handler
* interface is how the results of the call are returned.
*
* @param <T>
*/
public interface Handler<T> {
void handle(T result);
}
Board getBoard(String id);
Collection<Board> getBoards();

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.arduino.core.internal;
import org.eclipse.cdt.arduino.core.IArduinoBoardManager;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoBoardManager;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoardManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;

View file

@ -8,11 +8,16 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.remote;
package org.eclipse.cdt.arduino.core.internal.board;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -23,14 +28,63 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.eclipse.cdt.arduino.core.ArduinoHome;
import org.eclipse.cdt.arduino.core.Board;
import org.eclipse.cdt.arduino.core.IArduinoBoardManager;
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import com.google.gson.Gson;
public class ArduinoBoardManager implements IArduinoBoardManager {
private Map<String, Board> boards;
// TODO make this a preference
private Path arduinoHome = Paths.get(System.getProperty("user.home"), ".arduinocdt"); //$NON-NLS-1$ //$NON-NLS-2$
public void getPackageIndex(final Handler<PackageIndex> handler) {
new Job("Fetching package index") {
// Closeable isn't API yet but it's recommended.
@SuppressWarnings("restriction")
protected IStatus run(IProgressMonitor monitor) {
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet get = new HttpGet("http://downloads.arduino.cc/packages/package_index.json"); //$NON-NLS-1$
try (CloseableHttpResponse response = client.execute(get)) {
if (response.getStatusLine().getStatusCode() >= 400) {
return new Status(IStatus.ERROR, Activator.getId(),
response.getStatusLine().getReasonPhrase());
} else {
HttpEntity entity = response.getEntity();
if (entity == null) {
return new Status(IStatus.ERROR, Activator.getId(),
"Package index missing from response");
}
Files.createDirectories(arduinoHome);
Path indexPath = arduinoHome.resolve("package_index.json"); //$NON-NLS-1$
Files.copy(entity.getContent(), indexPath, StandardCopyOption.REPLACE_EXISTING);
try (FileReader reader = new FileReader(indexPath.toFile())) {
PackageIndex index = new Gson().fromJson(reader, PackageIndex.class);
handler.handle(index);
}
}
}
} catch (IOException e) {
return new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e);
}
return Status.OK_STATUS;
}
}.schedule();
}
@Override
public Board getBoard(String id) {
init();

View file

@ -0,0 +1,12 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board;
public class PackageIndex {
}