Skip to content

Commit

Permalink
Load repository.json from HTTP. See
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Dec 5, 2014
1 parent 8133c39 commit 69c1ae3
Show file tree
Hide file tree
Showing 33 changed files with 507 additions and 114 deletions.
1 change: 1 addition & 0 deletions core/tern.core.tests/src/tern/TernRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Assert;
import org.junit.Test;

import tern.repository.TernRepository;
import tern.server.ITernModule;
import tern.server.nodejs.process.PathHelper;

Expand Down
5 changes: 5 additions & 0 deletions core/tern.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Export-Package: tern,
tern.doc,
tern.internal.resources;x-internal:=true,
tern.metadata,
tern.repository,
tern.resources,
tern.scriptpath,
tern.scriptpath.impl,
Expand All @@ -30,6 +31,10 @@ Export-Package: tern,
tern.server.protocol.type,
tern.utils
Import-Package: com.eclipsesource.json,
org.apache.http;resolution:=optional,
org.apache.http.client;resolution:=optional,
org.apache.http.client.methods;resolution:=optional,
org.apache.http.impl.client;resolution:=optional,
org.osgi.framework
Bundle-Activator: tern.Activator
Bundle-ActivationPolicy: lazy
1 change: 1 addition & 0 deletions core/tern.core/src/tern/ITernProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.w3c.dom.Node;

import tern.repository.ITernRepository;
import tern.scriptpath.ITernScriptPath;
import tern.server.ITernDef;
import tern.server.ITernPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern;
package tern.repository;

import java.io.File;

import tern.TernException;
import tern.server.ITernModule;

/**
* Tern repository is a base dir which contains the tern.js JS files :
* Tern repository is a local base dir which contains the tern.js JS files :
*
* <ul>
* <li>bin folder</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* Contributors:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern;
package tern.repository;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import tern.TernException;
import tern.server.ITernModule;
import tern.utils.ExtensionUtils;
import tern.utils.TernModuleHelper;
Expand Down
2 changes: 1 addition & 1 deletion core/tern.core/src/tern/resources/TernProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import tern.ITernFile;
import tern.ITernFileSynchronizer;
import tern.ITernProject;
import tern.ITernRepository;
import tern.TernException;
import tern.internal.resources.InternalTernResourcesManager;
import tern.repository.ITernRepository;
import tern.scriptpath.ITernScriptPath;
import tern.scriptpath.impl.dom.DOMElementsScriptPath;
import tern.server.ITernDef;
Expand Down
85 changes: 85 additions & 0 deletions core/tern.core/src/tern/utils/TernRepositoryHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2013-2014 Angelo ZERR.
* 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:
* Angelo Zerr <[email protected]> - initial API and implementation
*/
package tern.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import tern.TernException;
import tern.server.BasicTernPlugin;
import tern.server.ITernModule;

import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonObject.Member;

/**
* Helper for tern repository.
*
*/
public class TernRepositoryHelper {

/**
* Default tern repository.json URL
*/
public static final String DEFAULT_TERN_REPOSITORY_URL = "https://raw.githubusercontent.com/angelozerr/tern.java/master/eclipse/tern.eclipse.ide.tools.ui/TO_DELETE/repository.json";

/**
* Load tern modules coming from the given repository.json URL.
*
* @param repositoryURL
* repository URL.
* @return
* @throws IOException
* @throws ClientProtocolException
* @throws TernException
*/
public static List<ITernModule> loadModules(String repositoryURL)
throws IOException, TernException {
// load repository.json with HTTP client.
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(repositoryURL);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
InputStream in = entity.getContent();
// Check the status
StatusLine statusLine = httpResponse.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
String message = IOUtils.toString(in);
if (StringUtils.isEmpty(message)) {
throw new TernException(statusLine.toString());
}
throw new TernException(message);
}

// read JSON and create tern modules list
JsonObject repository = JsonObject.readFrom(new InputStreamReader(in));
ITernModule module = null;
List<ITernModule> modules = new ArrayList<ITernModule>();
for (Member member : repository) {
module = new BasicTernPlugin(member.getName());
modules.add(module);
}
return modules;
}
}
2 changes: 1 addition & 1 deletion core/tern.server.nodejs/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Bundle-SymbolicName: tern.server.nodejs;singleton:=true
Bundle-Version: 0.8.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: tern.server.nodejs,tern.server.nodejs.process
Require-Bundle: tern.core;bundle-version="0.2.0"
Require-Bundle: tern.core
Bundle-ClassPath: .
Import-Package: com.eclipsesource.json,
org.apache.commons.logging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package tern.server.nodejs;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -88,8 +89,11 @@ public static JsonObject makeRequest(String baseURL, TernDoc doc,
}

try {

byte[] bytes = IOUtils.toByteArray(in);
System.err.println(IOUtils.toString(bytes));
JsonObject response = JsonObject
.readFrom(new InputStreamReader(in));
.readFrom(new InputStreamReader(new ByteArrayInputStream(bytes)));
if (interceptors != null) {
for (IInterceptor interceptor : interceptors) {
interceptor.handleResponse(response, server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.eclipse.core.resources.IProject;

import tern.ITernRepository;
import tern.repository.ITernRepository;

public interface ITernRepositoryManager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.preferences.InstanceScope;

import tern.ITernRepository;
import tern.TernException;
import tern.TernRepository;
import tern.eclipse.ide.core.ITernRepositoryManager;
import tern.eclipse.ide.core.TernCorePlugin;
import tern.eclipse.ide.core.preferences.TernCorePreferenceConstants;
import tern.eclipse.ide.internal.core.preferences.TernCorePreferencesSupport;
import tern.repository.ITernRepository;
import tern.repository.TernRepository;
import tern.utils.StringUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.Platform;

import tern.ITernRepository;
import tern.TernException;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.core.ITernServerPreferencesListener;
import tern.eclipse.ide.core.ITernServerType;
import tern.eclipse.ide.core.ITernServerTypeManager;
import tern.eclipse.ide.core.TernCorePlugin;
import tern.repository.ITernRepository;
import tern.server.ITernDef;
import tern.server.ITernModule;
import tern.server.ITernPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
*/
package tern.eclipse.ide.internal.core.builder;

import java.util.Date;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -34,6 +37,9 @@ protected IProject[] build(int kind, Map<String, String> args,
if (currentProject == null || !currentProject.isAccessible())
return EMPTY_PROJECT;

/*if (DEBUG)
System.out.println("\nJavaBuilder: Starting build of " + currentProject.getName() //$NON-NLS-1$
+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
/*
* if (IDETernProject.hasTernNature(currentProject)) { try { long start
* = System.currentTimeMillis();
Expand All @@ -43,5 +49,40 @@ protected IProject[] build(int kind, Map<String, String> args,
*/
return EMPTY_PROJECT;
}

protected IProject[] buildOLD(int kind, Map args, IProgressMonitor monitor) {
if (kind == IncrementalProjectBuilder.FULL_BUILD) {
fullBuild(monitor);
} else {
IResourceDelta delta = getDelta(getProject());
if (delta == null) {
fullBuild(monitor);
} else {
incrementalBuild(delta, monitor);
}
}
return null;
}

private void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {
System.out.println("incremental build on " + delta);
try {
delta.accept(new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) {
System.out.println("changed: "
+ delta.getResource().getRawLocation());
return true; // visit children too
}
});
} catch (CoreException e) {
e.printStackTrace();
}
}

private void fullBuild(IProgressMonitor monitor) {
System.out.println("full build");
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import tern.ITernFile;
import tern.ITernProject;
import tern.ITernRepository;
import tern.TernResourcesManager;
import tern.eclipse.ide.core.IIDETernProject;
import tern.eclipse.ide.core.ITernConsoleConnector;
Expand All @@ -46,6 +45,7 @@
import tern.eclipse.ide.internal.core.Trace;
import tern.eclipse.ide.internal.core.preferences.TernCorePreferencesSupport;
import tern.eclipse.ide.internal.core.scriptpath.FolderScriptPath;
import tern.repository.ITernRepository;
import tern.resources.TernProject;
import tern.scriptpath.ITernScriptPath;
import tern.scriptpath.ITernScriptPath.ScriptPathsType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;

import tern.ITernRepository;
import tern.eclipse.ide.tools.core.generator.Options;
import tern.eclipse.ide.tools.internal.core.TernToolsCorePlugin;
import tern.repository.ITernRepository;
import tern.server.ITernDef;
import tern.server.ITernModule;
import tern.server.ITernPlugin;
Expand Down
4 changes: 2 additions & 2 deletions eclipse/tern.eclipse.ide.tools.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui.ide,
tern.eclipse.ide.core,
tern.core,
tern.eclipse.ide.ui
tern.eclipse.ide.ui,
tern.core
Bundle-Activator: tern.eclipse.ide.tools.internal.ui.TernToolsUIPlugin
Bundle-ActivationPolicy: lazy
Import-Package: com.eclipsesource.json
3 changes: 3 additions & 0 deletions eclipse/tern.eclipse.ide.tools.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ providerName=Angelo ZERR
TernWizard.name=Tern
NewTernDefWizard.name=Tern JSON type definition
NewTernPluginWizard.name=Tern Server Plugin
DownloadTernModulesWizard.name=Download Tern modules

# Web browser wizard
WebBrowserWizard.name= Web Browser
NewCodeMirrorWizard.name=CodeMirror
NewAceWizard.name=Ace
Expand Down
7 changes: 7 additions & 0 deletions eclipse/tern.eclipse.ide.tools.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
class="tern.eclipse.ide.tools.internal.ui.wizards.NewTernPluginWizard"
id="tern.eclipse.ide.tools.internal.ui.wizards.NewTernPluginWizard">
</wizard>
<wizard
name="%DownloadTernModulesWizard.name"
icon="icons/full/etool16/plugin.gif"
category="tern.eclipse.ide.ui.wizard"
class="tern.eclipse.ide.tools.internal.ui.wizards.DownloadTernModulesWizard"
id="tern.eclipse.ide.tools.internal.ui.wizards.DownloadTernModulesWizard">
</wizard>
</extension>

<!-- =================================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class TernToolsUIMessages extends NLS {

// Buttons
public static String Button_browse;
public static String Button_refresh;

// Wizard
public static String NewFileWizardPage_name_text;
Expand Down Expand Up @@ -64,7 +65,14 @@ public final class TernToolsUIMessages extends NLS {

public static String DownloadTernModulesWizard_taskLabel;
public static String DownloadTernModulesSelectionWizardPage_title;
public static String DownloadTernModulesSelectionWizardPage_repositoryURL_text;
public static String DownloadTernModulesSelectionWizardPage_localRespositoryName_text;
public static String DownloadTernModulesSelectionWizardPage_description;
public static String DownloadTernModulesSelectionWizardPage_errorMessage;
public static String DownloadTernModulesSelectionWizardPage_errorTitle;
public static String DownloadTernModulesSelectionWizardPage_modules_selection_validation;
public static String RefreshRepositoryJob_name;
public static String RefreshRepositoryJob_loading;

private TernToolsUIMessages() {
}
Expand Down
Loading

0 comments on commit 69c1ae3

Please sign in to comment.