Compare commits

...

11 Commits

20 changed files with 1044 additions and 254 deletions

View File

@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Common Runtime Plug-in
Bundle-SymbolicName: org.talend.commons.runtime
Bundle-SymbolicName: org.talend.commons.runtime;singleton:=true
Bundle-Version: 7.0.1.qualifier
Require-Bundle: org.apache.log4j;visibility:=reexport,
org.apache.commons.beanutils,
@@ -18,9 +18,11 @@ Export-Package: org.talend.commons,
org.talend.commons.i18n,
org.talend.commons.i18n.internal,
org.talend.commons.runtime.debug,
org.talend.commons.runtime.extension,
org.talend.commons.runtime.helper,
org.talend.commons.runtime.model.components,
org.talend.commons.runtime.model.emf,
org.talend.commons.runtime.model.emf.provider,
org.talend.commons.runtime.model.expressionbuilder,
org.talend.commons.runtime.model.repository,
org.talend.commons.runtime.service,

View File

@@ -7,6 +7,8 @@ bin.includes = META-INF/,\
fakejdbc_driver.jar,\
modes/,\
talend.properties,\
dist/
dist/,\
plugin.xml,\
schema/
jars.compile.order = .,\
dist/org.talend.commons.runtime.jar

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="emfResourcesProvider" name="EMF Resources Provider" schema="schema/emfResourcesProvider.exsd"/>
<extension
point="org.talend.commons.runtime.emfResourcesProvider">
<saveOption
description="UTF-8 Encoding"
id="save.option.utf8"
provider="org.talend.commons.runtime.model.emf.provider.UTF8OptionProvider">
</saveOption>
<saveOption
description="CDATA option"
id="save.option.cdata"
provider="org.talend.commons.runtime.model.emf.provider.CDATAOptionProvider">
</saveOption>
</extension>
</plugin>

View File

@@ -0,0 +1,160 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.talend.commons.runtime" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.talend.commons.runtime" id="emfResourcesProvider" name="EMF Resources Provider"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="saveOption" minOccurs="0" maxOccurs="unbounded"/>
<element ref="loadOption" minOccurs="0" maxOccurs="unbounded"/>
</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="saveOption">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="provider" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.talend.commons.runtime.model.emf.provider.EOptionProvider"/>
</appinfo>
</annotation>
</attribute>
<attribute name="override" type="string">
<annotation>
<documentation>
the override id
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="loadOption">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="provider" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.talend.commons.runtime.model.emf.provider.EOptionProvider"/>
</appinfo>
</annotation>
</attribute>
<attribute name="override" type="string">
<annotation>
<documentation>
the override id
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View File

@@ -0,0 +1,223 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.extension;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
/**
* Template implementation of a registry reader that creates objects representing registry contents. Typically, an
* extension contains one element, but this reader handles multiple elements per extension.
*
* To start reading the extensions from the registry for an extension point, call the method <code>readRegistry</code>.
*
* To read children of an IConfigurationElement, call the method <code>readElementChildren</code> from your
* implementation of the method <code>readElement</code>, as it will not be done by default.
*
* @since 3.2
*/
public abstract class ExtensionRegistryReader {
private static Logger log = Logger.getLogger(ExtensionRegistryReader.class);
protected static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
private boolean isInitialized;
private final String extensionPointId;
private final String pluginId;
private final IExtensionRegistry registry;
/**
* DOC sgandon class global comment. Detailled comment <br/>
*
* $Id: talend.epf 55206 2011-02-15 17:32:14Z mhirt $
*
*/
public abstract class RegistrySafeRunnable implements ISafeRunnable {
@Override
public void handleException(Throwable exception) {
log.error("error reading extention registry", exception); //$NON-NLS-1$
}
}
/**
* The constructor.
*/
protected ExtensionRegistryReader(String aPluginId, String anExtensionPoint) {
this.registry = Platform.getExtensionRegistry();
this.pluginId = aPluginId;
this.extensionPointId = anExtensionPoint;
}
/**
* This method extracts description as a subelement of the given element.
*
* @return description string if defined, or empty string if not.
*/
protected String getDescription(IConfigurationElement config) {
IConfigurationElement[] children = config.getChildren(TAG_DESCRIPTION);
if (children.length >= 1) {
return children[0].getValue();
}
return "";//$NON-NLS-1$
}
/**
* Logs the error in the workbench log using the provided text and the information in the configuration element.
*/
protected static void logError(IConfigurationElement element, String text) {
IExtension extension = element.getDeclaringExtension();
StringBuffer buf = new StringBuffer();
buf.append("Plugin " + extension.getNamespaceIdentifier() + ", extension " + extension.getExtensionPointUniqueIdentifier());//$NON-NLS-2$//$NON-NLS-1$
buf.append("\n" + text);//$NON-NLS-1$
logError(0, buf.toString(), null);
}
/*
* Record an error against this plugin's log.
*
* @param aCode
*
* @param aMessage
*
* @param anException
*/
public static void logError(int aCode, String aMessage, Throwable anException) {
// Bundle bundle = FrameworkUtil.getBundle(RegistryReader.class);
log.log(Level.toLevel(aCode), aMessage, anException);
}
/**
* Logs a very common registry error when a required attribute is missing.
*/
protected static void logMissingAttribute(IConfigurationElement element, String attributeName) {
logError(element, "Required attribute '" + attributeName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a very common registry error when a required child is missing.
*/
protected static void logMissingElement(IConfigurationElement element, String elementName) {
logError(element, "Required sub element '" + elementName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a registry error when the configuration element is unknown.
*/
protected static void logUnknownElement(IConfigurationElement element) {
logError(element, "Unknown extension tag found: " + element.getName());//$NON-NLS-1$
}
/**
* Apply a reproducable order to the list of extensions provided, such that the order will not change as extensions
* are added or removed.
*/
protected IExtension[] orderExtensions(IExtension[] extensions) {
// By default, the order is based on plugin id sorted
// in ascending order. The order for a plugin providing
// more than one extension for an extension point is
// dependent in the order listed in the XML file.
IExtension[] sortedExtension = new IExtension[extensions.length];
System.arraycopy(extensions, 0, sortedExtension, 0, extensions.length);
Comparator<IExtension> comparer = new Comparator<IExtension>() {
@Override
public int compare(IExtension arg0, IExtension arg1) {
String s1 = arg0.getNamespaceIdentifier();
String s2 = arg1.getNamespaceIdentifier();
return s1.compareToIgnoreCase(s2);
}
};
Collections.sort(Arrays.asList(sortedExtension), comparer);
return sortedExtension;
}
/**
* Implement this method to read element's attributes. If children should also be read, then implementor is
* responsible for calling <code>readElementChildren</code>. Implementor is also responsible for logging missing
* attributes.
*
* @return true if element was recognized, false if not.
*/
protected abstract boolean readElement(IConfigurationElement element);
/**
* Read the element's children. This is called by the subclass' readElement method when it wants to read the
* children of the element.
*/
protected void readElementChildren(IConfigurationElement element) {
readElements(element.getChildren());
}
/**
* Read each element one at a time by calling the subclass implementation of <code>readElement</code>.
*
* Logs an error if the element was not recognized.
*/
protected void readElements(IConfigurationElement[] elements) {
for (int i = 0; i < elements.length; i++) {
if (!readElement(elements[i])) {
logUnknownElement(elements[i]);
}
}
}
/**
* Read one extension by looping through its configuration elements.
*/
protected void readExtension(IExtension extension) {
readElements(extension.getConfigurationElements());
}
/**
* Start the registry reading process using the supplied plugin ID and extension point.
*/
public void readRegistry() {
if (isInitialized) {
return;
}
synchronized (this) {
if (!isInitialized) {
IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPointId);
if (point == null) {
point = registry.getExtensionPoint(extensionPointId);
if (point == null) {
return;
}
}
IExtension[] extensions = point.getExtensions();
extensions = orderExtensions(extensions);
for (IExtension extension : extensions) {
readExtension(extension);
}
isInitialized = true;
}
}
}
}

View File

@@ -16,7 +16,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -40,6 +39,7 @@ import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
/***/
public class EmfHelper {
@@ -207,9 +207,8 @@ public class EmfHelper {
return;
}
HashMap options = new HashMap(2);
options.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
options.put(XMLResource.OPTION_ESCAPE_USING_CDATA, Boolean.TRUE);
Map options = EmfResourcesFactoryReader.INSTANCE.getSaveOptions(resource);
try {
if (outputStream == null) {
resource.save(options);

View File

@@ -0,0 +1,42 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
import org.eclipse.emf.ecore.xmi.XMLResource;
/**
* DOC ggu class global comment. Detailled comment
*/
public class CDATAOptionProvider extends OptionProvider {
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.EOptionProvider#getName()
*/
@Override
public String getName() {
return XMLResource.OPTION_ESCAPE_USING_CDATA;
}
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.EOptionProvider#getValue()
*/
@Override
public Object getValue() {
return Boolean.TRUE;
}
}

View File

@@ -0,0 +1,27 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
/**
* DOC ggu class global comment. Detailled comment
*/
public interface EOptionProvider {
String getName();
Object getValue();
boolean checkSave(Object resource);
boolean checkLoad(Object resource);
}

View File

@@ -0,0 +1,161 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.SafeRunner;
import org.talend.commons.CommonsPlugin;
import org.talend.commons.runtime.extension.ExtensionRegistryReader;
/**
* DOC ggu class global comment. Detailled comment
*/
public class EmfResourcesFactoryReader extends ExtensionRegistryReader {
public static final EmfResourcesFactoryReader INSTANCE = new EmfResourcesFactoryReader();
/*
* id==> bean
*/
private Map<String, OptionProviderBean> saveOptionsBeans = new HashMap<String, OptionProviderBean>();
private Map<String, OptionProviderBean> loadOptionsBeans = new HashMap<String, OptionProviderBean>();
/*
* id ==> provider
*/
private Map<String, EOptionProvider> saveOptionsProviders = new HashMap<String, EOptionProvider>();
private Map<String, EOptionProvider> loadOptionsProviders = new HashMap<String, EOptionProvider>();
class OptionProviderBean {
String id, description, overrideId;
EOptionProvider provider;
}
private EmfResourcesFactoryReader() {
super(CommonsPlugin.PLUGIN_ID, "emfResourcesProvider"); //$NON-NLS-1$
init();
}
void init() {
readRegistry();
cleanOverrideIds(saveOptionsProviders, saveOptionsBeans);
cleanOverrideIds(loadOptionsProviders, loadOptionsBeans);
}
private Map<String, OptionProviderBean> cleanOverrideIds(Map<String, EOptionProvider> optionsProvidersMap,
Map<String, OptionProviderBean> extensionMap) {
Set<String> ids = new HashSet<String>();
Map<String, OptionProviderBean> withoutOverrideMap = new HashMap<String, OptionProviderBean>(extensionMap);
for (Map.Entry<String, OptionProviderBean> e : withoutOverrideMap.entrySet()) {
final String overrideId = e.getValue().overrideId;
if (overrideId != null) {
ids.add(overrideId);
}
}
// remove override ids
final Iterator<String> removediterator = withoutOverrideMap.keySet().iterator();
while (removediterator.hasNext()) {
if (ids.contains(removediterator.next())) {
removediterator.remove();
}
}
for (Map.Entry<String, OptionProviderBean> entry : withoutOverrideMap.entrySet()) {
final EOptionProvider optionProvider = entry.getValue().provider;
optionsProvidersMap.put(entry.getKey(), optionProvider);
}
return withoutOverrideMap;
}
public Map<String, Object> getSaveOptions(Object resource) {
Map<String, Object> saveOptions = new HashMap<String, Object>();
for (Map.Entry<String, EOptionProvider> entry : saveOptionsProviders.entrySet()) {
final EOptionProvider provider = entry.getValue();
if (provider.checkSave(resource)) {
saveOptions.put(provider.getName(), provider.getValue());
}
}
return saveOptions;
}
public Map<String, Object> getLoadOptions(Object resource) {
Map<String, Object> loadOptions = new HashMap<String, Object>();
for (Map.Entry<String, EOptionProvider> entry : loadOptionsProviders.entrySet()) {
final EOptionProvider provider = entry.getValue();
if (provider.checkLoad(resource)) {
loadOptions.put(provider.getName(), provider.getValue());
}
}
return loadOptions;
}
public Map<String, EOptionProvider> getSaveOptionsProviders() {
return saveOptionsProviders;
}
public Map<String, EOptionProvider> getLoadOptionsProviders() {
return loadOptionsProviders;
}
@Override
protected boolean readElement(final IConfigurationElement element) {
if ("saveOption".equals(element.getName())) { //$NON-NLS-1$
SafeRunner.run(new RegistrySafeRunnable() {
@Override
public void run() throws Exception {
createProvider(saveOptionsBeans, element);
}
});
}
if ("loadOption".equals(element.getName())) { //$NON-NLS-1$
SafeRunner.run(new RegistrySafeRunnable() {
@Override
public void run() throws Exception {
createProvider(loadOptionsBeans, element);
}
});
}
return false;
}
private void createProvider(Map<String, OptionProviderBean> map, IConfigurationElement element) throws CoreException {
String id = element.getAttribute("id"); //$NON-NLS-1$
String description = element.getAttribute("description"); //$NON-NLS-1$
String overrideId = element.getAttribute("override"); //$NON-NLS-1$
EOptionProvider provider = (EOptionProvider) element.createExecutableExtension("provider");//$NON-NLS-1$
OptionProviderBean bean = new OptionProviderBean();
bean.id = id;
bean.description = description;
bean.overrideId = overrideId;
bean.provider = provider;
map.put(id, bean);
}
}

View File

@@ -0,0 +1,30 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
/**
* DOC ggu class global comment. Detailled comment
*/
public abstract class OptionProvider implements EOptionProvider {
@Override
public boolean checkSave(Object resource) {
return true; // nothing to check by default
}
@Override
public boolean checkLoad(Object resource) {
return true; // nothing to check by default
}
}

View File

@@ -0,0 +1,44 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.runtime.model.emf.provider;
import java.nio.charset.StandardCharsets;
import org.eclipse.emf.ecore.xmi.XMLResource;
/**
* DOC ggu class global comment. Detailled comment
*/
public class UTF8OptionProvider extends OptionProvider {
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.EOptionProvider#getName()
*/
@Override
public String getName() {
return XMLResource.OPTION_ENCODING;
}
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.EOptionProvider#getValue()
*/
@Override
public Object getValue() {
return StandardCharsets.UTF_8.name();
}
}

View File

@@ -699,6 +699,24 @@
</parameterHandler>
</extension>
<extension
point="org.talend.commons.runtime.emfResourcesProvider">
<loadOption
description="Use deprecated methods"
id="load.option.using_deprecated_methods"
provider="org.talend.core.repository.model.provider.UsingDeprecatedDethodsOptionProvider">
</loadOption>
<saveOption
description="Option for saving item"
id="save.option.item.resource"
provider="org.talend.core.repository.model.ItemResourceOptionProvider">
</saveOption>
<loadOption
description="Option for loading item"
id="load.option.item.resource"
provider="org.talend.core.repository.model.ItemResourceOptionProvider">
</loadOption>
</extension>
</plugin>

View File

@@ -0,0 +1,89 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.repository.model;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.talend.commons.runtime.model.emf.provider.OptionProvider;
import org.talend.core.model.properties.PropertiesPackage;
import org.talend.core.model.properties.Property;
/**
* DOC ggu class global comment. Detailled comment
*/
public class ItemResourceOptionProvider extends OptionProvider {
public static final String ITEM_VALUE = "item_value"; //$NON-NLS-1$
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.provider.EOptionProvider#getName()
*/
@Override
public String getName() {
return XMLResource.OPTION_RESOURCE_HANDLER;
}
/*
* (non-Javadoc)
*
* @see org.talend.commons.runtime.model.emf.provider.EOptionProvider#getValue()
*/
@Override
public Object getValue() {
return new XMLResource.ResourceHandler() {
@Override
public void preLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) {
//
}
@Override
public void postLoad(XMLResource resource, InputStream inputStream, Map<?, ?> options) {
//
}
@SuppressWarnings("rawtypes")
@Override
public void preSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) {
final Property prop = (Property) EcoreUtil.getObjectByType(resource.getContents(),
PropertiesPackage.eINSTANCE.getProperty());
if (prop != null) {
final Iterator iterator = prop.getAdditionalProperties().keySet().iterator();
while (iterator.hasNext()) {
if (ITEM_VALUE.equals(iterator.next())) {
iterator.remove();
}
}
}
}
@Override
public void postSave(XMLResource resource, OutputStream outputStream, Map<?, ?> options) {
//
}
};
}
}

View File

@@ -0,0 +1,33 @@
// ============================================================================
//
// Copyright (C) 2006-2017 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.repository.model.provider;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.talend.commons.runtime.model.emf.provider.OptionProvider;
/**
* DOC ggu class global comment. Detailled comment
*/
public class UsingDeprecatedDethodsOptionProvider extends OptionProvider {
@Override
public String getName() {
return XMLResource.OPTION_USE_DEPRECATED_METHODS;
}
@Override
public Object getValue() {
return Boolean.FALSE;
}
}

View File

@@ -47,6 +47,7 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.EmfHelper;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
import org.talend.commons.utils.workbench.resources.ResourceUtils;
import org.talend.core.GlobalServiceRegister;
@@ -148,41 +149,50 @@ public class XmiResourceManager {
}
public Property loadProperty(IResource iResource) {
final Map<Object, Object> oldLoadOptions = new HashMap<Object, Object>(resourceSet.getLoadOptions());
try {
Property property = null;
// force unload old version, or the UI won't be synchronized all the time to the current file.
// this is only if a user update itself a .item or .properties, or for SVN repository.
//
URIConverter theURIConverter = resourceSet.getURIConverter();
URI propertyUri = URIHelper.convert(iResource.getFullPath());
URI itemResourceURI = theURIConverter.normalize(getItemResourceURI(propertyUri));
URI screenshotResourceURI = theURIConverter.normalize(getScreenshotResourceURI(itemResourceURI));
List<Resource> resources = resourceSet.getResources();
synchronized (resources) {
for (Resource res : new ArrayList<Resource>(resources)) {
if (res != null) {
URI normalizedURI = theURIConverter.normalize(res.getURI());
if (propertyUri.equals(normalizedURI)) {
res.unload();
resourceSet.getResources().remove(res);
}
if (itemResourceURI.equals(normalizedURI)) {
res.unload();
resourceSet.getResources().remove(res);
}
if (screenshotResourceURI.equals(normalizedURI)) {
res.unload();
resourceSet.getResources().remove(res);
Property property = null;
// force unload old version, or the UI won't be synchronized all the time to the current file.
// this is only if a user update itself a .item or .properties, or for SVN repository.
//
URIConverter theURIConverter = resourceSet.getURIConverter();
URI propertyUri = URIHelper.convert(iResource.getFullPath());
URI itemResourceURI = theURIConverter.normalize(getItemResourceURI(propertyUri));
URI screenshotResourceURI = theURIConverter.normalize(getScreenshotResourceURI(itemResourceURI));
List<Resource> resources = resourceSet.getResources();
synchronized (resources) {
for (Resource res : new ArrayList<Resource>(resources)) {
if (res != null) {
URI normalizedURI = theURIConverter.normalize(res.getURI());
if (propertyUri.equals(normalizedURI)) {
res.unload();
resourceSet.getResources().remove(res);
}
if (itemResourceURI.equals(normalizedURI)) {
res.unload();
resourceSet.getResources().remove(res);
}
if (screenshotResourceURI.equals(normalizedURI)) {
res.unload();
resourceSet.getResources().remove(res);
}
}
}
}
Map options = EmfResourcesFactoryReader.INSTANCE.getLoadOptions(propertyUri);
resourceSet.getLoadOptions().putAll(options);
Resource propertyResource = resourceSet.getResource(propertyUri, true);
property = (Property) EcoreUtil.getObjectByType(propertyResource.getContents(),
PropertiesPackage.eINSTANCE.getProperty());
return property;
} finally {
resourceSet.getLoadOptions().clear();
resourceSet.getLoadOptions().putAll(oldLoadOptions);
}
Resource propertyResource = resourceSet.getResource(propertyUri, true);
property = (Property) EcoreUtil
.getObjectByType(propertyResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
return property;
}
public Property forceReloadProperty(Property property) {

View File

@@ -12,6 +12,8 @@
// ============================================================================
package org.talend.core.service;
import java.beans.PropertyChangeListener;
import org.talend.commons.exception.LoginException;
import org.talend.commons.exception.PersistenceException;
import org.talend.core.IService;
@@ -24,13 +26,17 @@ import org.talend.utils.json.JSONObject;
*/
public interface IRemoteService extends IService {
public JSONObject getLicenseKey(String user, String password, String url, String projectLabel)
throws PersistenceException, LoginException;
void addPropertyChangeListener(PropertyChangeListener listener);
public NexusServerBean getUpdateRepositoryUrl(String user, String password, String url)
throws PersistenceException, LoginException;
void removePropertyChangeListener(PropertyChangeListener listener);
public NexusServerBean getLibNexusServer(String user, String password, String url)
throws PersistenceException, LoginException, JSONException;
public JSONObject getLicenseKey(String user, String password, String url, String projectLabel) throws PersistenceException,
LoginException;
public NexusServerBean getUpdateRepositoryUrl(String user, String password, String url) throws PersistenceException,
LoginException;
public NexusServerBean getLibNexusServer(String user, String password, String url) throws PersistenceException,
LoginException, JSONException;
}

View File

@@ -12,18 +12,7 @@
// ============================================================================
package org.talend.core.utils;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
import org.talend.commons.runtime.extension.ExtensionRegistryReader;
/**
* Template implementation of a registry reader that creates objects representing registry contents. Typically, an
@@ -36,188 +25,10 @@ import org.eclipse.core.runtime.Platform;
*
* @since 3.2
*/
public abstract class RegistryReader {
public abstract class RegistryReader extends ExtensionRegistryReader {
private static Logger log = Logger.getLogger(RegistryReader.class);
protected static final String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
private boolean isInitialized;
private final String extensionPointId;
private final String pluginId;
private final IExtensionRegistry registry;
/**
* DOC sgandon class global comment. Detailled comment <br/>
*
* $Id: talend.epf 55206 2011-02-15 17:32:14Z mhirt $
*
*/
public abstract class RegistrySafeRunnable implements ISafeRunnable {
@Override
public void handleException(Throwable exception) {
log.error("error reading extention registry", exception); //$NON-NLS-1$
}
}
/**
* The constructor.
*/
protected RegistryReader(String aPluginId, String anExtensionPoint) {
this.registry = Platform.getExtensionRegistry();
this.pluginId = aPluginId;
this.extensionPointId = anExtensionPoint;
super(aPluginId, anExtensionPoint);
}
/**
* This method extracts description as a subelement of the given element.
*
* @return description string if defined, or empty string if not.
*/
protected String getDescription(IConfigurationElement config) {
IConfigurationElement[] children = config.getChildren(TAG_DESCRIPTION);
if (children.length >= 1) {
return children[0].getValue();
}
return "";//$NON-NLS-1$
}
/**
* Logs the error in the workbench log using the provided text and the information in the configuration element.
*/
protected static void logError(IConfigurationElement element, String text) {
IExtension extension = element.getDeclaringExtension();
StringBuffer buf = new StringBuffer();
buf.append("Plugin " + extension.getNamespaceIdentifier() + ", extension " + extension.getExtensionPointUniqueIdentifier());//$NON-NLS-2$//$NON-NLS-1$
buf.append("\n" + text);//$NON-NLS-1$
logError(0, buf.toString(), null);
}
/*
* Record an error against this plugin's log.
*
* @param aCode
*
* @param aMessage
*
* @param anException
*/
public static void logError(int aCode, String aMessage, Throwable anException) {
// Bundle bundle = FrameworkUtil.getBundle(RegistryReader.class);
log.log(Level.toLevel(aCode), aMessage, anException);
}
/**
* Logs a very common registry error when a required attribute is missing.
*/
protected static void logMissingAttribute(IConfigurationElement element, String attributeName) {
logError(element, "Required attribute '" + attributeName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a very common registry error when a required child is missing.
*/
protected static void logMissingElement(IConfigurationElement element, String elementName) {
logError(element, "Required sub element '" + elementName + "' not defined");//$NON-NLS-2$//$NON-NLS-1$
}
/**
* Logs a registry error when the configuration element is unknown.
*/
protected static void logUnknownElement(IConfigurationElement element) {
logError(element, "Unknown extension tag found: " + element.getName());//$NON-NLS-1$
}
/**
* Apply a reproducable order to the list of extensions provided, such that the order will not change as extensions
* are added or removed.
*/
protected IExtension[] orderExtensions(IExtension[] extensions) {
// By default, the order is based on plugin id sorted
// in ascending order. The order for a plugin providing
// more than one extension for an extension point is
// dependent in the order listed in the XML file.
IExtension[] sortedExtension = new IExtension[extensions.length];
System.arraycopy(extensions, 0, sortedExtension, 0, extensions.length);
Comparator<IExtension> comparer = new Comparator<IExtension>() {
@Override
public int compare(IExtension arg0, IExtension arg1) {
String s1 = arg0.getNamespaceIdentifier();
String s2 = arg1.getNamespaceIdentifier();
return s1.compareToIgnoreCase(s2);
}
};
Collections.sort(Arrays.asList(sortedExtension), comparer);
return sortedExtension;
}
/**
* Implement this method to read element's attributes. If children should also be read, then implementor is
* responsible for calling <code>readElementChildren</code>. Implementor is also responsible for logging missing
* attributes.
*
* @return true if element was recognized, false if not.
*/
protected abstract boolean readElement(IConfigurationElement element);
/**
* Read the element's children. This is called by the subclass' readElement method when it wants to read the
* children of the element.
*/
protected void readElementChildren(IConfigurationElement element) {
readElements(element.getChildren());
}
/**
* Read each element one at a time by calling the subclass implementation of <code>readElement</code>.
*
* Logs an error if the element was not recognized.
*/
protected void readElements(IConfigurationElement[] elements) {
for (int i = 0; i < elements.length; i++) {
if (!readElement(elements[i])) {
logUnknownElement(elements[i]);
}
}
}
/**
* Read one extension by looping through its configuration elements.
*/
protected void readExtension(IExtension extension) {
readElements(extension.getConfigurationElements());
}
/**
* Start the registry reading process using the supplied plugin ID and extension point.
*/
public void readRegistry() {
if (isInitialized) {
return;
}
synchronized (this) {
if (!isInitialized) {
IExtensionPoint point = registry.getExtensionPoint(pluginId, extensionPointId);
if (point == null) {
point = registry.getExtensionPoint(extensionPointId);
if (point == null) {
return;
}
}
IExtension[] extensions = point.getExtensions();
extensions = orderExtensions(extensions);
for (IExtension extension : extensions) {
readExtension(extension);
}
isInitialized = true;
}
}
}
}

View File

@@ -12,6 +12,8 @@
// ============================================================================
package org.talend.repository.ui.actions;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.List;
@@ -41,6 +43,10 @@ import org.eclipse.ui.views.properties.PropertySheet;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.exception.LoginException;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.provider.EOptionProvider;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.runtime.model.emf.provider.OptionProvider;
import org.talend.commons.ui.gmf.util.DisplayUtils;
import org.talend.commons.ui.swt.actions.ITreeContextualAction;
import org.talend.commons.utils.VersionUtils;
import org.talend.core.GlobalServiceRegister;
@@ -56,6 +62,7 @@ import org.talend.core.model.repository.RepositoryViewObject;
import org.talend.core.model.utils.RepositoryManagerHelper;
import org.talend.core.runtime.CoreRuntimePlugin;
import org.talend.core.runtime.i18n.Messages;
import org.talend.core.service.IRemoteService;
import org.talend.repository.ProjectManager;
import org.talend.repository.RepositoryWorkUnit;
import org.talend.repository.model.IProxyRepositoryFactory;
@@ -101,6 +108,47 @@ public abstract class AContextualAction extends Action implements ITreeContextua
private IRepositoryNode node;
private boolean invalid = false;
private static EOptionProvider usingOption = new OptionProvider() {
@Override
public String getName() {
return "ITEM_USING";
}
@Override
public Object getValue() {
return Boolean.TRUE;
}
};
private PropertyChangeListener openListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String value = null;
if (evt.getPropertyName().equals(usingOption.getName()) && evt.getNewValue() instanceof Boolean
&& !(Boolean) evt.getNewValue()) { // invalid
value = "Because the item is invalid, so can't open";
} else if (evt.getPropertyName().equals("ERR_MESSAGES") && evt.getNewValue() != null) {
value = evt.getNewValue().toString();
}
if (value != null) {
final String messages = value;
DisplayUtils.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
invalid = true;
MessageDialog.openError(DisplayUtils.getDefaultShell(), "Error", messages);
}
});
}
}
};
@Override
public boolean isEditAction() {
return editAction;
@@ -600,10 +648,24 @@ public abstract class AContextualAction extends Action implements ITreeContextua
this.avoidUnloadResources = avoidUnloadResources;
}
private IRemoteService getRemoteService() {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRemoteService.class)) {
return (IRemoteService) GlobalServiceRegister.getDefault().getService(IRemoteService.class);
}
return null;
}
@Override
public void run() {
String name = "User action : " + getText(); //$NON-NLS-1$
invalid = false;
final IRemoteService remoteService = getRemoteService();
if (remoteService != null) {
remoteService.addPropertyChangeListener(openListener);
}
EmfResourcesFactoryReader.INSTANCE.getLoadOptionsProviders().put(usingOption.getName(), usingOption);
oldItem = null;
// if (node == null) {
node = getCurrentRepositoryNode();
@@ -617,22 +679,36 @@ public abstract class AContextualAction extends Action implements ITreeContextua
}
}
}
if (invalid) {
return;
}
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {
@Override
protected void run() throws LoginException, PersistenceException {
boolean exist = false;
if (node != null && node.getObject() != null) {
Property property = node.getObject().getProperty();
// only avoid NPE if item has been deleted in svn
if (property != null) {
exist = true;
if (invalid) {
return;
}
try {
if (node != null && node.getObject() != null) {
Property property = node.getObject().getProperty();
if (invalid) {
return;
}
// only avoid NPE if item has been deleted in svn
if (property != null) {
doRun();
}
} else {
doRun();
}
} else {
doRun();
} finally {
EmfResourcesFactoryReader.INSTANCE.getLoadOptionsProviders().remove(usingOption.getName());
if (remoteService != null) {
remoteService.removePropertyChangeListener(openListener);
}
}
}
};

View File

@@ -37,6 +37,9 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.emf.provider.OptionProvider;
import org.talend.commons.runtime.model.emf.provider.EOptionProvider;
import org.talend.commons.runtime.model.emf.provider.EmfResourcesFactoryReader;
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
import org.talend.commons.ui.runtime.exception.MessageBoxExceptionHandler;
import org.talend.commons.utils.VersionUtils;
@@ -92,6 +95,19 @@ public class MigrationToolService implements IMigrationToolService {
private String taskId;
private EOptionProvider migrationOption = new OptionProvider() {
@Override
public String getName() {
return "RESOURCE_MIGRATION";
}
@Override
public Object getValue() {
return Boolean.TRUE;
}
};
public MigrationToolService() {
doneThisSession = new ArrayList<IProjectMigrationTask>();
}
@@ -106,6 +122,16 @@ public class MigrationToolService implements IMigrationToolService {
@Override
public void executeMigrationTasksForImport(Project project, Item item, List<MigrationTask> migrationTasksToApply,
final IProgressMonitor monitor) throws Exception {
try {
EmfResourcesFactoryReader.INSTANCE.getLoadOptionsProviders().put(migrationOption.getName(), migrationOption);
delegateExecuteMigrationTasksForImport(project, item, migrationTasksToApply, monitor);
} finally {
EmfResourcesFactoryReader.INSTANCE.getLoadOptionsProviders().remove(migrationOption.getName());
}
}
private void delegateExecuteMigrationTasksForImport(Project project, Item item, List<MigrationTask> migrationTasksToApply,
final IProgressMonitor monitor) throws Exception {
if (item == null || migrationTasksToApply == null) {
return;
}
@@ -166,6 +192,16 @@ public class MigrationToolService implements IMigrationToolService {
@Override
public void executeMigrationTasksForLogon(final Project project, final boolean beforeLogon, final IProgressMonitor monitorWrap) {
try {
EmfResourcesFactoryReader.INSTANCE.getLoadOptionsProviders().put(migrationOption.getName(), migrationOption);
delegateExecuteMigrationTasksForLogon(project, beforeLogon, monitorWrap);
} finally {
EmfResourcesFactoryReader.INSTANCE.getLoadOptionsProviders().remove(migrationOption.getName());
}
}
private void delegateExecuteMigrationTasksForLogon(final Project project, final boolean beforeLogon,
final IProgressMonitor monitorWrap) {
String taskDesc = "Migration tool: project [" + project.getLabel() + "] tasks"; //$NON-NLS-1$ //$NON-NLS-2$
log.trace(taskDesc);

View File

@@ -166,7 +166,6 @@ import org.talend.repository.localprovider.exceptions.IncorrectFileException;
import org.talend.repository.localprovider.i18n.Messages;
import org.talend.repository.model.IProxyRepositoryFactory;
import org.talend.repository.model.RepositoryConstants;
import orgomg.cwm.foundation.businessinformation.BusinessinformationPackage;
/**
@@ -1106,8 +1105,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
}
/**
* @see org.talend.core.model.repository.factories.IRepositoryFactory#readProject(java.lang.String, java.lang.String,
* java.lang.String)
* @see org.talend.core.model.repository.factories.IRepositoryFactory#readProject(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
public Project[] readProject() throws PersistenceException {
@@ -1649,7 +1648,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
}
@Override
public void deleteObjectPhysical(Project project, IRepositoryViewObject objToDelete, boolean isDeleteOnRemote) throws PersistenceException {
public void deleteObjectPhysical(Project project, IRepositoryViewObject objToDelete, boolean isDeleteOnRemote)
throws PersistenceException {
deleteObjectPhysical(project, objToDelete, null, isDeleteOnRemote);
}
@@ -2471,8 +2471,8 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
for (Resource referenceFileResource : referenceFileReources) {
xmiResourceManager.saveResource(referenceFileResource);
}
xmiResourceManager.saveResource(item.eResource());
xmiResourceManager.saveResource(itemResource);
xmiResourceManager.saveResource(itemResource); // need save the item first.
xmiResourceManager.saveResource(item.eResource()); // save the properties after
/* should release the refereneces of resources */
referenceFileReources = null;
if (screenshotFlag && !copyScreenshotFlag) {
@@ -2554,7 +2554,7 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
xmlResource.setID(connectionItem.getConnection(), EcoreUtil.generateUUID());
}
}
return newItem;
} catch (IOException e) {
// e.printStackTrace();
@@ -2578,7 +2578,7 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
newRefItem.setContent(byarray);
}
}
private void copyIcon(Item originalItem, Item newItem) throws PersistenceException {
if (!(newItem instanceof JobletProcessItem)) {
return;
@@ -3208,12 +3208,14 @@ public class LocalRepositoryFactory extends AbstractEMFRepositoryFactory impleme
@Override
public List<org.talend.core.model.properties.Project> getReferencedProjects(Project project) {
String parentBranch = getRepositoryContext().getFields()
.get(IProxyRepositoryFactory.BRANCH_SELECTION + "_" + getRepositoryContext().getProject().getTechnicalLabel());
String parentBranch = getRepositoryContext().getFields().get(
IProxyRepositoryFactory.BRANCH_SELECTION + "_" + getRepositoryContext().getProject().getTechnicalLabel());
List<org.talend.core.model.properties.Project> refProjectList = new ArrayList<org.talend.core.model.properties.Project>();
for (ProjectReference refProject : (List<ProjectReference>) project.getEmfProject().getReferencedProjects()) {
String rBranch = ProjectManager.getInstance().getLocalProjectReferenceBranch(project.getEmfProject(), parentBranch, refProject);
String refBranch4Local = ProjectManager.getInstance().getLocalProjectReferenceReferenceBranch(project.getEmfProject(), parentBranch, refProject);
String rBranch = ProjectManager.getInstance().getLocalProjectReferenceBranch(project.getEmfProject(), parentBranch,
refProject);
String refBranch4Local = ProjectManager.getInstance().getLocalProjectReferenceReferenceBranch(
project.getEmfProject(), parentBranch, refProject);
if (ProjectManager.validReferenceProject(parentBranch, rBranch, refBranch4Local, refProject)) {
refProjectList.add(refProject.getReferencedProject());
}