Skip to content

Contribute TypeScript repositories via an extension point #138

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

Merged
Merged
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
52 changes: 52 additions & 0 deletions core/ts.core/src/ts/repository/ITypeScriptRepositoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,70 @@

import java.io.File;

/**
* Manager for keeping track of the available TypeScript repositories. Each
* repository includes a TypeScript installation and additional software, such
* as TSLint.
*
* Each repository is automatically assigned a name according to the included
* TypeScript version. No two repositories may share the same name.
*
* One repository may be marked as the default (see
* {@link #getDefaultRepository()}).
*
*/
public interface ITypeScriptRepositoryManager {

/**
* Creates and adds a new repository. The new repository is also set as the
* default.
*
* @param baseDir
* base directory of the new repository.
* @return the created repository.
*/
ITypeScriptRepository createDefaultRepository(File baseDir) throws TypeScriptRepositoryException;

/**
* Creates and adds a new repository.
*
* @param baseDir
* base directory of the new repository.
* @return the created repository.
*/
ITypeScriptRepository createRepository(File baseDir) throws TypeScriptRepositoryException;

/**
* Removes a repository. If not present, nothing happens.
*
* @param name
* name of the repository to remove.
* @return the removed repository.
*/
ITypeScriptRepository removeRepository(String name);

/**
* Gets the current default repository.
*
* @return a repository or {@code null} if there is no default.
*/
ITypeScriptRepository getDefaultRepository();

/**
* Gets a managed repository by name.
*
* @param name
* name of the repository to retrieve.
* @return a repository or {@code null} if there is no repository with the
* requested name.
*/
ITypeScriptRepository getRepository(String name);

/**
* Gets all registered repositories.
*
* @return array of repositories.
*/
ITypeScriptRepository[] getRepositories();

}
15 changes: 15 additions & 0 deletions core/ts.core/src/ts/repository/TypeScriptRepositoryManager.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* Copyright (c) 2015-2016 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 <angelo.zerr@gmail.com> - initial API and implementation
* Lorenzo Dalla Vecchia <lorenzo.dallavecchia@webratio.com> - protected API for setting default
*/
package ts.repository;

import java.io.File;
Expand Down Expand Up @@ -26,6 +37,10 @@ public ITypeScriptRepository createDefaultRepository(File baseDir) throws TypeSc
return this.defaultRepository = createRepository(baseDir);
}

protected final void setDefaultRepository(ITypeScriptRepository repository) {
this.defaultRepository = repository;
}

@Override
public ITypeScriptRepository createRepository(File baseDir) throws TypeScriptRepositoryException {
synchronized (repositories) {
Expand Down
3 changes: 2 additions & 1 deletion core/ts.repository/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: ts.repository
Bundle-SymbolicName: ts.repository;singleton:=true
Bundle-Version: 1.2.0.qualifier
Eclipse-BundleShape: dir
Import-Package: org.osgi.framework
Bundle-Activator: ts.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: ts.eclipse.ide.core
3 changes: 2 additions & 1 deletion core/ts.repository/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
node_modules/
node_modules/,\
plugin.xml
17 changes: 17 additions & 0 deletions core/ts.repository/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="ts.eclipse.ide.core.typeScriptRepositories">
<repository
baseDir="archives/1.8.10">
</repository>
<repository
baseDir="archives/2.0.10">
</repository>
<repository
baseDir=".">
</repository>
</extension>

</plugin>
1 change: 0 additions & 1 deletion eclipse/ts.eclipse.ide.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Bundle-Version: 1.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
ts.repository,
ts.core,
ts.eclipse,
org.eclipse.jface.text,
Expand Down
1 change: 1 addition & 0 deletions eclipse/ts.eclipse.ide.core/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ TypeScriptBuilder.name=TypeScript Builder
# Extension Points
nodeJSInstallsContribution.name=Node.js Installations
typeScriptConsoleConnectors.name=TypeScript Console Connector Extension Points
typeScriptRepositoriesContribution.name=TypeScript Repositories

# Launch
TypeScriptCompilerLaunchConfigurationDelegate.label=TypeScript Compile
1 change: 1 addition & 0 deletions eclipse/ts.eclipse.ide.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<extension-point id="nodeJSInstalls"
name="%nodeJSInstallsContribution.name"
schema="schema/nodeJSInstalls.exsd" />
<extension-point id="typeScriptRepositories" name="%typeScriptRepositoriesContribution.name" schema="schema/typeScriptRepositories.exsd"/>

<extension point="org.eclipse.core.runtime.contentTypes">
<content-type
Expand Down
92 changes: 92 additions & 0 deletions eclipse/ts.eclipse.ide.core/schema/typeScriptRepositories.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="ts.eclipse.ide.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="ts.eclipse.ide.core" id="typescriptRepositories" name="Embed TypeScript Repository"/>
</appInfo>
<documentation>
Extension point to provided embedded TypeScript Repositories.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="repository"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="repository">
<annotation>
<documentation>
This extension point allows developers to supply a repository containing a TypeScript installation as well as the TSLint tool.
&lt;p&gt;
A repository is represented by a root directory containing a &lt;i&gt;node_modules&lt;/i&gt; directory, itself containing the &lt;i&gt;typescript&lt;/i&gt; and &lt;i&gt;tslit&lt;/i&gt; packages.
&lt;p&gt;
The version of TypeScript embedded in the repository directory is detected automatically. On first startup, the repository containing the most recent version is selected as active repository. The user is always free to change the active repository.
</documentation>
</annotation>
<complexType>
<attribute name="baseDir" type="string" use="required">
<annotation>
<documentation>
The base directory of the repository inside the contributing bundle.
</documentation>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
2.0
</documentation>
</annotation>



<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
This plugin itself does not have any predefined repositories
</documentation>
</annotation>


</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
*/
package ts.eclipse.ide.core;

import java.io.File;
import java.io.IOException;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
Expand Down Expand Up @@ -57,16 +52,6 @@ public void start(BundleContext context) throws Exception {
resourceManager.setTypeScriptResourcesManagerDelegate(IDEResourcesManager.getInstance());
}

/**
* Returns the TypeScript repository base directory.
*
* @return the TypeScript repository base directory.
* @throws IOException
*/
public static File getTypeScriptRepositoryBaseDir() throws IOException {
return FileLocator.getBundleFile(Platform.getBundle("ts.repository"));
}

@Override
public void stop(BundleContext context) throws Exception {
ResourcesWatcher.getInstance().dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

import ts.repository.ITypeScriptRepositoryManager;

/**
* TypeScript repository manager for use in the Eclipse IDE.
*
* In addition to the repositories registered manually, this manager will also
* pick up any repository contributed to the {@code typeScriptRepositories}
* extension point.
*/
public interface IIDETypeScriptRepositoryManager extends ITypeScriptRepositoryManager {

String generateFileName(IResource resource, IProject project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
*/
package ts.eclipse.ide.internal.core.preferences;

import java.io.File;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.osgi.service.prefs.BackingStoreException;
Expand Down Expand Up @@ -45,26 +41,10 @@ public void initializeDefaultPreferences() {
initializeNodejsPreferences(node);

try {
File tsRepositoryBaseDir = FileLocator.getBundleFile(Platform.getBundle("ts.repository"));
ITypeScriptRepository defaultRepository = TypeScriptCorePlugin.getTypeScriptRepositoryManager()
.createDefaultRepository(tsRepositoryBaseDir);

// Loop for archives of TypeScript (1.8.10, etc)
File archivesDir = new File(tsRepositoryBaseDir, "archives");
if (archivesDir.exists()) {
File[] oldRepostoryBaseDirs = archivesDir.listFiles();
File oldRepostoryBaseDir = null;
for (int i = 0; i < oldRepostoryBaseDirs.length; i++) {
oldRepostoryBaseDir = oldRepostoryBaseDirs[i];
if (oldRepostoryBaseDir.isDirectory()) {
try {
TypeScriptCorePlugin.getTypeScriptRepositoryManager().createRepository(oldRepostoryBaseDir);
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error while getting an archived TypeScript repository", e);
}
}
}

.getDefaultRepository();
if (defaultRepository == null) {
Trace.trace(Trace.WARNING, "No default TypeScript repository is available");
}

// Initialize TypeScript runtime preferences
Expand Down Expand Up @@ -126,8 +106,12 @@ private static boolean useBundledNodeJsEmbedded(IEclipsePreferences node) {

private void initializeTypeScriptRuntimePreferences(IEclipsePreferences node,
ITypeScriptRepository defaultRepository) {
node.put(TypeScriptCorePreferenceConstants.EMBEDDED_TYPESCRIPT_ID, defaultRepository.getName());
node.putBoolean(TypeScriptCorePreferenceConstants.USE_EMBEDDED_TYPESCRIPT, true);
if (defaultRepository != null) {
node.put(TypeScriptCorePreferenceConstants.EMBEDDED_TYPESCRIPT_ID, defaultRepository.getName());
node.putBoolean(TypeScriptCorePreferenceConstants.USE_EMBEDDED_TYPESCRIPT, true);
} else {
node.putBoolean(TypeScriptCorePreferenceConstants.USE_EMBEDDED_TYPESCRIPT, false);
}
node.put(TypeScriptCorePreferenceConstants.INSTALLED_TYPESCRIPT_PATH, "");
}

Expand All @@ -152,8 +136,12 @@ private void initializeTypeScriptBuildPath(IEclipsePreferences node) {
private void initializeTslintPreferences(IEclipsePreferences node, ITypeScriptRepository defaultRepository) {
node.put(TypeScriptCorePreferenceConstants.TSLINT_STRATEGY, TslintSettingsStrategy.DisableTslint.name());
node.put(TypeScriptCorePreferenceConstants.TSLINT_USE_CUSTOM_TSLINTJSON_FILE, "");
node.put(TypeScriptCorePreferenceConstants.TSLINT_EMBEDDED_TYPESCRIPT_ID, defaultRepository.getName());
node.putBoolean(TypeScriptCorePreferenceConstants.TSLINT_USE_EMBEDDED_TYPESCRIPT, true);
if (defaultRepository != null) {
node.put(TypeScriptCorePreferenceConstants.TSLINT_EMBEDDED_TYPESCRIPT_ID, defaultRepository.getName());
node.putBoolean(TypeScriptCorePreferenceConstants.TSLINT_USE_EMBEDDED_TYPESCRIPT, true);
} else {
node.putBoolean(TypeScriptCorePreferenceConstants.TSLINT_USE_EMBEDDED_TYPESCRIPT, false);
}
node.put(TypeScriptCorePreferenceConstants.TSLINT_INSTALLED_TYPESCRIPT_PATH, "");
}

Expand Down
Loading