<unit id="org.junit.source" version="0.0.0"/>\r
<unit id="org.mockito" version="0.0.0"/>\r
<unit id="org.hamcrest.core" version="0.0.0"/>\r
+<unit id="com.google.gson" version="0.0.0"/>\r
+<unit id="org.apache.httpcomponents.httpclient" version="0.0.0"/>\r
+<unit id="org.apache.httpcomponents.httpcore" version="0.0.0"/>\r
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20150519210750/repository/"/>\r
</location>\r
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">\r
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+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
--- /dev/null
+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"
--- /dev/null
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
--- /dev/null
+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();
+ }
+
+}
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,
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();
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;
* 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;
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();
--- /dev/null
+/*******************************************************************************
+ * 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 {
+
+}