use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class RowGeneratorComponentDocumentation method getHTMLFile.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.process.IComponentDocumentation#getHTMLFile()
*/
@Override
public URL getHTMLFile() {
String xmlFilepath = this.tempFolderPath + File.separatorChar + this.componentName + IHTMLDocConstants.XML_FILE_SUFFIX;
String htmlFilePath = this.tempFolderPath + File.separatorChar + this.componentName + IHTMLDocConstants.HTML_FILE_SUFFIX;
final Bundle b = Platform.getBundle(PluginUtils.PLUGIN_ID);
URL xslFileUrl = null;
try {
xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(IHTMLDocConstants.TROWGENERATOR_XSL_FILE_PATH), null));
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
ExceptionHandler.process(e);
}
String xslFilePath = xslFileUrl.getPath();
generateXMLInfo(getExternalNode());
XMLHandler.generateXMLFile(tempFolderPath, xmlFilepath, document);
HTMLHandler.generateHTMLFile(this.tempFolderPath, xslFilePath, xmlFilepath, htmlFilePath);
File htmlFile = new File(htmlFilePath);
if (htmlFile.exists()) {
try {
return htmlFile.toURL();
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
}
}
return null;
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class ScdComponentDocumentation method getHTMLFile.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.process.IComponentDocumentation#getHTMLFile()
*/
public URL getHTMLFile() {
String xmlFilepath = this.tempFolderPath + File.separatorChar + this.componentName + IHTMLDocConstants.XML_FILE_SUFFIX;
String htmlFilePath = this.tempFolderPath + File.separatorChar + this.componentName + IHTMLDocConstants.HTML_FILE_SUFFIX;
final Bundle b = Platform.getBundle(ScdPlugin.PLUGIN_ID);
URL xslFileUrl = null;
try {
//$NON-NLS-1$
xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path("resources/tScd.xsl"), null));
} catch (IOException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
String xslFilePath = xslFileUrl.getPath();
generateXMLInfo();
XMLHandler.generateXMLFile(tempFolderPath, xmlFilepath, document);
HTMLHandler.generateHTMLFile(this.tempFolderPath, xslFilePath, xmlFilepath, htmlFilePath);
File htmlFile = new File(htmlFilePath);
if (htmlFile.exists()) {
try {
return htmlFile.toURL();
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
}
}
return null;
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class CustomComponentSettingPage method finish.
private void finish(IProgressMonitor... monitorWrap) {
IProgressMonitor monitor = null;
if (monitorWrap != null && monitorWrap.length == 1) {
monitor = monitorWrap[0];
}
final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor subMonitor) throws CoreException {
ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
File componentFolder = new File(targetRoot);
URL url = null;
try {
if (!componentFolder.exists()) {
FilesUtils.createFoldersIfNotExists(targetRoot, false);
}
Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
String sourceRoot = url.getFile();
// delete share
for (IComponent component : backAdded.keySet()) {
String componentFullPath = targetRoot + File.separator + component.getName();
if (service.isSVNProject(pro)) {
service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
if (subMonitor != null) {
subMonitor.worked(10);
}
} else {
File file = new File(componentFullPath);
if (file != null && file.exists()) {
org.talend.utils.io.FilesUtils.deleteFolder(file, true);
}
}
}
if (!backAdded.isEmpty()) {
getCustomComponentSettings().removeAll(backAdded.values());
}
FileFilter ff = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (FilesUtils.isSVNFolder(pathname)) {
return false;
}
return true;
}
};
// share
for (IComponent component : sharedAdded.keySet()) {
String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
File sourceFile = new File(sourcePath);
String targetPath = targetRoot + File.separatorChar + component.getName();
File targetFile = new File(targetPath);
FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
if (subMonitor != null) {
subMonitor.worked(10);
}
}
} catch (Exception e) {
resetCustomComponentSetting();
ExceptionHandler.process(e);
}
try {
prf.saveProject(pro);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
try {
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
throw new PersistenceException(e.getCause());
}
}
};
repositoryWorkUnit.setRefreshRepository(false);
repositoryWorkUnit.setForceTransaction(true);
prf.executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (monitor != null) {
monitor.done();
}
// refresh again after the gui closed .
try {
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class Component method getModulesNeeded.
@Override
public List<ModuleNeeded> getModulesNeeded(INode node) {
List<ModuleNeeded> componentImportNeedsList = new ArrayList<>();
ConnectorTopology topology = null;
if (node != null) {
boolean hasInput = !NodeUtil.getIncomingConnections(node, IConnectionCategory.DATA).isEmpty();
boolean hasOutput = !NodeUtil.getOutgoingConnections(node, IConnectionCategory.DATA).isEmpty();
if (hasInput && hasOutput) {
topology = ConnectorTopology.INCOMING_AND_OUTGOING;
} else if (hasInput) {
topology = ConnectorTopology.INCOMING;
} else if (hasOutput) {
topology = ConnectorTopology.OUTGOING;
} else {
topology = ConnectorTopology.NONE;
}
} else {
Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
if (!topologies.isEmpty()) {
topology = topologies.iterator().next();
}
}
RuntimeInfo runtimeInfo = null;
try {
runtimeInfo = componentDefinition.getRuntimeInfo(ExecutionEngine.DI, node == null ? null : node.getComponentProperties(), topology);
} catch (Exception e) {
if (node == null) {
// not handled, must because the runtime info must have a node configuration (properties are null)
} else {
ExceptionHandler.process(e);
}
}
if (runtimeInfo != null) {
if (runtimeInfo instanceof JarRuntimeInfo) {
JarRuntimeInfo currentRuntimeInfo = (JarRuntimeInfo) runtimeInfo;
JarRuntimeInfo localRuntimeInfo = new JarRuntimeInfo(//$NON-NLS-1$
currentRuntimeInfo.getJarUrl().toString().replace(//$NON-NLS-1$
"mvn:", //$NON-NLS-1$ //$NON-NLS-2$
"mvn:" + MavenConstants.LOCAL_RESOLUTION_URL + "!"), currentRuntimeInfo.getDepTxtPath(), currentRuntimeInfo.getRuntimeClassName());
runtimeInfo = localRuntimeInfo;
}
final Bundle bundle = FrameworkUtil.getBundle(componentDefinition.getClass());
for (URL mvnUri : runtimeInfo.getMavenUrlDependencies()) {
//$NON-NLS-1$
ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, mvnUri.toString());
componentImportNeedsList.add(moduleNeeded);
if (bundle != null) {
// update module location
try {
final MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(moduleNeeded.getMavenUri());
final String moduleFileName = artifact.getFileName();
final File bundleFile = BundleFileUtil.getBundleFile(bundle, moduleFileName);
if (bundleFile != null && bundleFile.exists()) {
// FIXME, better install the embed jars from bundle directly in this way.
moduleNeeded.setModuleLocaion(ExtensionModuleManager.URIPATH_PREFIX + bundle.getSymbolicName() + '/' + moduleFileName);
}
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
}
}
ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/slf4j-log4j12-1.7.2/6.0.0");
componentImportNeedsList.add(moduleNeeded);
moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/talend-codegen-utils/0.17.0-SNAPSHOT");
componentImportNeedsList.add(moduleNeeded);
return componentImportNeedsList;
}
use of org.osgi.framework.Bundle in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateDocumentation.
/*
* This method is used for generating HTML file base on an instance of <code>ExportFileResource</code> (non-Javadoc)
*
* @see
* org.talend.repository.documentation.generation.IDocumentationGenerator#generateDocumentation(org.talend.repository
* .documentation.ExportFileResource, java.lang.String, java.lang.String[])
*/
@Override
public void generateDocumentation(ExportFileResource resource, String targetPath, String... jobVersion) throws Exception {
// Store all pictures' path.
List<URL> picList = new ArrayList<URL>(5);
String jobName = resource.getItem().getProperty().getLabel();
String jobPath = resource.getItem().getProperty().getItem().getState().getPath();
// Used for generating/updating all jobs' documentaiton only.
String typePath = new Path(this.repositoryObjectType.getFolder()).lastSegment();
if (jobName != null && !(jobName).equals(typePath.toLowerCase()) && targetPath.endsWith(typePath.toLowerCase())) {
targetPath = targetPath + IPath.SEPARATOR + jobPath + IPath.SEPARATOR + jobName;
}
//$NON-NLS-1$
String version = "";
// Checks if the job's version is specified, see it on "Export documentation" Dialog:
if (jobVersion != null && jobVersion.length == 1) {
version = jobVersion[0];
} else {
version = resource.getItem().getProperty().getVersion();
}
//$NON-NLS-1$
targetPath = targetPath + "_" + version;
File file = new File(targetPath);
// Delete if folde is existing.
if (file.exists()) {
FilesUtils.removeFolder(file, true);
}
file.mkdirs();
handleXMLFile(resource, targetPath, jobVersion);
String picFolderPath = checkPicDirIsExists(resource, targetPath);
// Gets the "org.talend.repository" plug-in:
//$NON-NLS-1$
final Bundle b = Platform.getBundle("org.talend.repository");
final URL xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(IHTMLDocConstants.MAIN_XSL_FILE_PATH), null));
// final URL logoFileUrl = FileLocator.toFileURL(FileLocator.find(b,
// new Path(IHTMLDocConstants.LOGO_FILE_PATH), null));
File logoFile = new File(picFolderPath + File.separatorChar + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
saveLogoImage(SWT.IMAGE_JPEG, logoFile);
String xslFilePath = xslFileUrl.getPath();
// String logoFilePath = logoFileUrl.getPath();
// FileCopyUtils.copy(logoFilePath, picFolderPath + File.separatorChar
// + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
// if set css file in preference.
boolean isCheck = CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.USE_CSS_TEMPLATE);
String cssFile = CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.CSS_FILE_PATH);
String temXslPath = null;
if (isCheck && cssFile != null && !cssFile.equals("")) {
//$NON-NLS-1$
String tempFolderPath = checkTempDirIsExists(resource);
temXslPath = tempFolderPath + File.separator + (new File(xslFilePath)).getName();
File temXslFile = new File(temXslPath);
if (temXslFile.exists()) {
temXslFile.delete();
}
generateXslFile(xslFilePath, temXslPath, cssFile, null);
}
// if no new xls generated, use default xsl
if (temXslPath != null) {
File temFile = new File(temXslPath);
if (!temFile.exists()) {
temXslPath = xslFilePath;
}
} else {
temXslPath = xslFilePath;
}
picList.add(logoFile.toURL());
// Property property = item.getProperty();
// String jobName = property.getLabel();
// String jobVersion = property.getVersion();
byte[] innerContent = null;
ProcessType processType = null;
if (resource.getItem() instanceof ProcessItem) {
processType = ((ProcessItem) resource.getItem()).getProcess();
//$NON-NLS-1$
innerContent = (byte[]) processType.getScreenshots().get("process");
} else if (resource.getItem() instanceof JobletProcessItem) {
processType = ((JobletProcessItem) resource.getItem()).getJobletProcess();
//$NON-NLS-1$
innerContent = (byte[]) processType.getScreenshots().get("process");
;
}
if (innerContent != null) {
//$NON-NLS-1$
String picName = jobName + "_" + version + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
ImageUtils.save(innerContent, picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
// need to generate another pic for pdf
ByteArrayInputStream bais = new ByteArrayInputStream(innerContent);
Image pdfImage = new Image(null, bais);
int width = pdfImage.getImageData().width;
int percent = 22 * 32 * 100 / width;
//$NON-NLS-1$
ImageUtils.save(//$NON-NLS-1$
ImageUtils.scale(pdfImage, percent), //$NON-NLS-1$
picFolderPath + File.separatorChar + "pdf_" + picName, SWT.IMAGE_PNG);
//$NON-NLS-1$
picList.add(new File(picFolderPath + File.separatorChar + "pdf_" + picName).toURL());
pdfImage.dispose();
}
if (processType != null) {
for (NodeType node : (List<NodeType>) processType.getNode()) {
//$NON-NLS-1$
String uniqueName = "";
for (Object o : node.getElementParameter()) {
if (o instanceof ElementParameterType) {
if ("UNIQUE_NAME".equals(((ElementParameterType) o).getName())) {
//$NON-NLS-1$
uniqueName = ((ElementParameterType) o).getValue();
break;
}
}
}
byte[] screenshot = (byte[]) processType.getScreenshots().get(uniqueName);
if (screenshot != null && screenshot.length != 0) {
String picName = IHTMLDocConstants.EXTERNAL_NODE_PREVIEW + uniqueName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
ImageUtils.save(screenshot, picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
// need to generate externalNode pic for pdf
ByteArrayInputStream bais = new ByteArrayInputStream(screenshot);
Image pdfImage = new Image(null, bais);
int width = pdfImage.getImageData().width;
int percent = 22 * 32 * 100 / width;
//$NON-NLS-1$
ImageUtils.save(//$NON-NLS-1$
ImageUtils.scale(pdfImage, percent), //$NON-NLS-1$
picFolderPath + File.separatorChar + "pdf_" + picName, SWT.IMAGE_PNG);
picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
pdfImage.dispose();
}
}
}
Set keySet = picFilePathMap.keySet();
for (Object key : keySet) {
String value = picFilePathMap.get(key);
FileCopyUtils.copy(value, picFolderPath + File.separatorChar + key);
picList.add(new File(picFolderPath + File.separatorChar + key).toURL());
}
//$NON-NLS-1$
List<URL> resultFiles = parseXml2HtmlPdf(targetPath, jobName + "_" + version, temXslPath);
resource.addResources(resultFiles);
resource.addResources(IHTMLDocConstants.PIC_FOLDER_NAME, picList);
HTMLDocUtils.deleteTempFiles();
// List<URL> externalList = getExternalHtmlPath();
// resource.addResources(IHTMLDocConstants.EXTERNAL_FOLDER_NAME, externalList);
targetConnectionMap = null;
sourceConnectionMap = null;
}
Aggregations