Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2014-10-08 00:12:02 +0000
committerWim Jongman2014-10-08 00:53:45 +0000
commitd42f18de0bd535101a7866edb94f58bba5a2819b (patch)
tree12c04116bc730957267339b36d3d8c330a2b7c28 /examples/bundles/com.mycorp.examples.githubservice.impl
parenta7a1e0ebad03d775b7c0fe81f0e6c3bd3cabd550 (diff)
downloadorg.eclipse.ecf-d42f18de0bd535101a7866edb94f58bba5a2819b.tar.gz
org.eclipse.ecf-d42f18de0bd535101a7866edb94f58bba5a2819b.tar.xz
org.eclipse.ecf-d42f18de0bd535101a7866edb94f58bba5a2819b.zip
Bug 446237 - Remote Service Example - GitHub
Created two projects. One project with the GitHub service API [1] and a locally working implementation [2]. [1] examples/bundles/com.mycorp.examples.githubservice [2] examples/bundles/com.mycorp.examples.githubservice.impl The impl project [2] contains two service interface implementations with main methods. You will need to get an access token from github and insert this token in the main methods for them to function. Change-Id: I2bdb192d7e7653d4b12bd8d445025707ff980b64 Signed-off-by: Wim Jongman <wim.jongman@remainsoftware.com>
Diffstat (limited to 'examples/bundles/com.mycorp.examples.githubservice.impl')
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/.classpath7
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/.gitignore1
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/.project34
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.pde.core.prefs3
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/META-INF/MANIFEST.MF11
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/about.html28
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/build.properties6
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubService.java89
-rw-r--r--examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubServiceAsync.java67
10 files changed, 253 insertions, 0 deletions
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/.classpath b/examples/bundles/com.mycorp.examples.githubservice.impl/.classpath
new file mode 100644
index 000000000..64c5e31b7
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/.classpath
@@ -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/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/.gitignore b/examples/bundles/com.mycorp.examples.githubservice.impl/.gitignore
new file mode 100644
index 000000000..5e56e040e
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/.project b/examples/bundles/com.mycorp.examples.githubservice.impl/.project
new file mode 100644
index 000000000..67b57b65d
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>com.mycorp.examples.githubservice.impl</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>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.jdt.core.prefs b/examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..af0f20f97
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.pde.core.prefs b/examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 000000000..f29e940a0
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/META-INF/MANIFEST.MF b/examples/bundles/com.mycorp.examples.githubservice.impl/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..9712d8a90
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/META-INF/MANIFEST.MF
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ECF RS Example GitHub Service API impl
+Bundle-SymbolicName: com.mycorp.examples.githubservice.impl
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Eclipse.org - ECF
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: com.mycorp.examples.githubservice.impl;version="1.0.0"
+Import-Package: com.mycorp.examples.githubservice
+Require-Bundle: org.eclipse.egit.github.core;bundle-version="3.6.0"
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/about.html b/examples/bundles/com.mycorp.examples.githubservice.impl/about.html
new file mode 100644
index 000000000..4c79781a5
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 25, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/build.properties b/examples/bundles/com.mycorp.examples.githubservice.impl/build.properties
new file mode 100644
index 000000000..9cbab3c13
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html
+src.includes = about.html
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubService.java b/examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubService.java
new file mode 100644
index 000000000..271966fa3
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubService.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Remain BV 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
+ *
+ * Contributors: Wim Jongman - initial API and implementation
+ ******************************************************************************/
+package com.mycorp.examples.githubservice.impl;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.egit.github.core.Issue;
+import org.eclipse.egit.github.core.Repository;
+import org.eclipse.egit.github.core.client.GitHubClient;
+import org.eclipse.egit.github.core.service.IssueService;
+import org.eclipse.egit.github.core.service.RepositoryService;
+
+import com.mycorp.examples.githubservice.IGitHubService;
+
+/**
+ * Example OSGi service for retrieving some data from GitHub.
+ *
+ * @since 1.0
+ */
+public class GitHubService implements IGitHubService {
+
+ /**
+ * Stand alone service test. To get an access token see see
+ * https://help.github.com/articles/creating-an-access-token-
+ * for-command-line-use/
+ */
+ public static void main(String[] args) {
+ String token = "your token here";
+ GitHubService service = new GitHubService();
+ String[] repos = service.getRepositories(token);
+ for (String repository : repos) {
+ System.out.println(repository);
+ System.out.println("================");
+
+ String[] issues = service
+ .getIssues(token, "wimjongman", repository);
+ if (issues.length == 0) {
+ System.out.println("*** No Issues ***");
+ }
+ for (String issue : issues) {
+ System.out.println(issue);
+ }
+ System.out.println();
+ }
+ }
+
+ public String[] getRepositories(String pAccessToken) {
+ GitHubClient client = new GitHubClient();
+ client.setOAuth2Token(pAccessToken);
+ RepositoryService service = new RepositoryService(client);
+ try {
+ List<Repository> repositories = service.getRepositories();
+ String[] result = new String[repositories.size()];
+ for (int i = 0; i < repositories.size(); i++) {
+ result[i] = repositories.get(i).getName();
+ }
+ return result;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public String[] getIssues(String pAccessToken, String owner,
+ String pRepository) {
+ GitHubClient client = new GitHubClient();
+ client.setOAuth2Token(pAccessToken);
+ IssueService issueService = new IssueService(client);
+ try {
+ List<Issue> issues = issueService.getIssues("wimjongman",
+ pRepository, null);
+ String[] result = new String[issues.size()];
+ for (int i = 0; i < issues.size(); i++) {
+ result[i] = issues.get(i).getNumber() + "::"
+ + issues.get(i).getTitle();
+ }
+ return result;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+}
diff --git a/examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubServiceAsync.java b/examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubServiceAsync.java
new file mode 100644
index 000000000..f6ab5d8d4
--- /dev/null
+++ b/examples/bundles/com.mycorp.examples.githubservice.impl/src/com/mycorp/examples/githubservice/impl/GitHubServiceAsync.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Remain BV 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
+ *
+ * Contributors: Wim Jongman - initial API and implementation
+ ******************************************************************************/
+package com.mycorp.examples.githubservice.impl;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+
+import com.mycorp.examples.githubservice.IGitHubServiceAsync;
+
+/**
+ * Example OSGi service for retrieving some data from GitHub.
+ *
+ * @since 1.0
+ */
+public class GitHubServiceAsync implements IGitHubServiceAsync {
+
+ /**
+ * Stand alone service test. To get an access token see see
+ * https://help.github.com/articles/creating-an-access-token-
+ * for-command-line-use/
+ *
+ * @throws ExecutionException
+ * @throws InterruptedException
+ */
+ public static void main(String[] args) throws InterruptedException,
+ ExecutionException {
+ String token = "your token here";
+ GitHubServiceAsync service = new GitHubServiceAsync();
+ Future<String[]> future = service.getRepositoriesAsync(token);
+ System.out.print("Z");
+ while (!future.isDone()) {
+ Thread.sleep(200);
+ System.out.print("z");
+ }
+ System.out.println();
+ System.out.println();
+ for (String repository : future.get()) {
+ System.out.println(repository);
+ }
+ }
+
+ public Future<String[]> getRepositoriesAsync(final String pAccessToken) {
+ FutureTask<String[]> future = new FutureTask<String[]>(
+ new Callable<String[]>() {
+ public String[] call() throws Exception {
+ Thread.sleep(5000);
+ GitHubService service = new GitHubService();
+ return service.getRepositories(pAccessToken);
+ }
+ });
+ ExecutorService executor = Executors.newFixedThreadPool(5);
+ executor.execute(future);
+ executor.shutdown();
+ return future;
+ }
+}

Back to the top