use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.
the class ExportItemUtil method exportItems2.
private Map<File, IPath> exportItems2(Collection<Item> items, File destinationDirectory, boolean projectFolderStructure, IProgressMonitor progressMonitor) throws Exception {
Map<File, IPath> toExport = new HashMap<File, IPath>();
//$NON-NLS-1$
progressMonitor.beginTask("Export Items", items.size() + 1);
final boolean oldMeasureActived = TimeMeasure.measureActive;
if (!oldMeasureActived) {
// not active before.
TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
}
//$NON-NLS-1$
final String idTimer = "exportItems";
TimeMeasure.begin(idTimer);
try {
// store item and its corresponding project
Map<Item, Project> itemProjectMap = new HashMap<Item, Project>();
Collection<Item> allItems = new ArrayList<Item>(items);
items.clear();
// ycbai added for TDI-21387
if (allItems.isEmpty()) {
addTalendProjectFile(toExport, destinationDirectory);
return toExport;
}
allItems = sortItemsByProject(allItems, itemProjectMap);
ITransformService tdmService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITransformService.class)) {
tdmService = (ITransformService) GlobalServiceRegister.getDefault().getService(ITransformService.class);
}
itemProjectMap.clear();
Set<String> jarNameList = new HashSet<String>();
Iterator<Item> iterator = allItems.iterator();
Set<String> projectHasTdm = new HashSet<String>();
while (iterator.hasNext()) {
Item item = iterator.next();
project = pManager.getProject(item);
String label = item.getProperty().getLabel();
// project
addTalendProjectFile(toExport, destinationDirectory);
// tdm .settings/com.oaklandsw.base.projectProps
String technicalLabel = project.getTechnicalLabel();
if (tdmService != null && !projectHasTdm.contains(technicalLabel) && tdmService.isTransformItem(item)) {
projectHasTdm.add(technicalLabel);
IPath propsSourcePath = getProjectLocationPath(technicalLabel).append(FileConstants.TDM_PROPS_PATH);
IPath tdmPropsPath = getProjectOutputPath().append(FileConstants.TDM_PROPS_PATH);
IPath propsTargetPath = new Path(destinationDirectory.getAbsolutePath()).append(tdmPropsPath);
File source = new File(propsSourcePath.toPortableString());
if (source.exists()) {
copyAndAddResource(toExport, propsSourcePath, propsTargetPath, tdmPropsPath);
}
}
// tdm simple files
if (item.getProperty() instanceof FakePropertyImpl) {
FakePropertyImpl fakeProperty = (FakePropertyImpl) item.getProperty();
IPath itemResPath = fakeProperty.getItemPath().makeRelative();
IPath itemSourcePath = getProjectLocationPath(technicalLabel).removeLastSegments(1).append(itemResPath);
// replace the project segment
IPath outputRelativeItemPath = getProjectOutputPath().append(itemResPath.removeFirstSegments(1));
IPath itemTargetPath = new Path(destinationDirectory.getAbsolutePath()).append(outputRelativeItemPath);
copyAndAddResource(toExport, itemSourcePath, itemTargetPath, outputRelativeItemPath);
continue;
}
// property and related resources eg:item, reference files
XmiResourceManager localRepositoryManager = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager();
IPath propertyPath = null;
for (Resource curResource : localRepositoryManager.getAffectedResources(item.getProperty())) {
URI uri = curResource.getURI();
IPath relativeItemPath = URIHelper.convert(uri).makeRelative();
Project project = ProjectManager.getInstance().getProject(item);
IPath sourcePath = getProjectLocationPath(project.getTechnicalLabel()).removeLastSegments(1).append(relativeItemPath);
// replace the project segment
IPath outputRelativeItemPath = getProjectOutputPath().append(relativeItemPath.removeFirstSegments(1));
IPath targetPath = new Path(destinationDirectory.getAbsolutePath()).append(outputRelativeItemPath);
copyAndAddResource(toExport, sourcePath, targetPath, outputRelativeItemPath);
if (uri.lastSegment() != null && uri.lastSegment().endsWith(FileConstants.PROPERTIES_FILE_SUFFIX)) {
propertyPath = targetPath;
}
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
List<IResource> dataFileList = testContainerService.getDataFiles(item);
for (IResource dataFile : dataFileList) {
IPath relativeItemPath = dataFile.getFullPath();
IPath sourcePath = getProjectLocationPath(project.getTechnicalLabel()).removeLastSegments(1).append(relativeItemPath);
// replace the project segment
IPath outputRelativeItemPath = getProjectOutputPath().append(relativeItemPath.removeFirstSegments(1));
IPath targetPath = new Path(destinationDirectory.getAbsolutePath()).append(outputRelativeItemPath);
copyAndAddResource(toExport, sourcePath, targetPath, outputRelativeItemPath);
}
}
}
if (propertyPath == null) {
return toExport;
}
if (item instanceof RoutineItem) {
List list = ((RoutineItem) item).getImports();
for (int i = 0; i < list.size(); i++) {
String jarName = ((IMPORTTypeImpl) list.get(i)).getMODULE();
jarNameList.add(jarName.toString());
}
}
boolean needChangeItem = false;
needChangeItem = needChangeItem || item.getState().isLocked();
// keep the same as function fixItem()
needChangeItem = needChangeItem || !item.getProperty().getLabel().replace(' ', '_').equals(item.getProperty().getLabel());
if (needChangeItem) {
// load in memory, fix the item and save it
XmiResourceManager xmiMamanger = new XmiResourceManager();
// loadProject
IPath proRelativePath = getProjectOutputPath().append(FileConstants.LOCAL_PROJECT_FILENAME);
IPath proTargetPath = new Path(destinationDirectory.getAbsolutePath()).append(proRelativePath);
Resource loadProject = projectResourcMap.get(proTargetPath);
if (loadProject == null) {
URI projectUri = URI.createFileURI(proTargetPath.toPortableString());
loadProject = xmiMamanger.resourceSet.getResource(projectUri, true);
projectResourcMap.put(proTargetPath, loadProject);
}
URI propertyUri = URI.createFileURI(propertyPath.toPortableString());
Resource propertyResource = xmiMamanger.resourceSet.getResource(propertyUri, true);
Property loadProperty = (Property) EcoreUtil.getObjectByType(propertyResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
Item newItem = loadProperty.getItem();
fixItem(newItem);
fixItemLockState(newItem);
saveResources(xmiMamanger.resourceSet);
}
iterator.remove();
TimeMeasure.step(idTimer, "export item: " + label);
progressMonitor.worked(1);
}
ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
// add the routines of the jars at the end, to add them only once in the export.
IPath libPath = getProjectOutputPath().append(JavaUtils.JAVA_LIB_DIRECTORY);
String libAbsPath = new Path(destinationDirectory.toString()).append(libPath.toString()).toPortableString();
for (String jarName : jarNameList) {
if (repositoryBundleService.contains(jarName)) {
repositoryBundleService.retrieve(jarName, libAbsPath, new NullProgressMonitor());
toExport.put(new File(libAbsPath, jarName), libPath.append(jarName));
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
TimeMeasure.end(idTimer);
// if active before, not disable and active still.
if (!oldMeasureActived) {
TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
}
}
return toExport;
}
use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.
the class EditRoutineAction method init.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
* org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
super.init(viewer, selection);
boolean canWork = !selection.isEmpty() && selection.size() == 1;
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (factory.isUserReadOnlyOnCurrentProject()) {
canWork = false;
}
RepositoryNode node = (RepositoryNode) selection.getFirstElement();
if (canWork) {
if (node.getObjectType() != ERepositoryObjectType.ROUTINES || !ProjectManager.getInstance().isInCurrentMainProject(node) || !isLastVersion(node)) {
canWork = false;
} else {
Item item = node.getObject().getProperty().getItem();
if (item instanceof RoutineItem) {
canWork = !((RoutineItem) item).isBuiltIn();
}
}
}
if (canWork) {
canWork = (factory.getStatus(node.getObject()) != ERepositoryStatus.DELETED);
}
setEnabled(canWork);
}
use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method getExternalLibraries.
/**
* Gets required java jars.
*
* @param process
*
* @param boolean1
* @return
*/
protected List<URL> getExternalLibraries(boolean needLibraries, ExportFileResource[] process, final Set<String> neededLibraries) {
List<URL> list = new ArrayList<URL>();
if (!needLibraries) {
return list;
}
IFolder libFolder = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
libFolder = talendProcessJavaProject.getLibFolder();
}
}
if (libFolder == null) {
return list;
}
File file = libFolder.getLocation().toFile();
File[] files = file.listFiles(FilesUtils.getAcceptModuleFilesFilter());
// Lists all the needed jar files
Set<String> listModulesReallyNeeded = new HashSet<String>();
if (neededLibraries == null) {
// in case export as been done with option "not recompile", then libraires can't be retrieved when build.
IDesignerCoreService designerService = RepositoryPlugin.getDefault().getDesignerCoreService();
for (ExportFileResource resource : process) {
ProcessItem item = (ProcessItem) resource.getItem();
String version = item.getProperty().getVersion();
if (!isMultiNodes() && this.getSelectedJobVersion() != null) {
version = this.getSelectedJobVersion();
}
ProcessItem selectedProcessItem;
if (resource.getNode() != null) {
selectedProcessItem = ItemCacheManager.getProcessItem(resource.getNode().getRoot().getProject(), item.getProperty().getId(), version);
} else {
// if no node given, take in the current project only
selectedProcessItem = ItemCacheManager.getProcessItem(item.getProperty().getId(), version);
}
IProcess iProcess = designerService.getProcessFromProcessItem(selectedProcessItem);
Set<String> processNeededLibraries = iProcess.getNeededLibraries(true);
if (processNeededLibraries != null) {
listModulesReallyNeeded.addAll(processNeededLibraries);
}
}
} else {
listModulesReallyNeeded.addAll(neededLibraries);
}
// jar from routines
List<IRepositoryViewObject> collectRoutines = new ArrayList<IRepositoryViewObject>();
boolean useBeans = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
if (camelService.isInstanceofCamel(process[0].getItem())) {
useBeans = true;
}
}
String include = null;
if (useBeans) {
include = USER_BEANS_PATH;
} else {
include = USER_ROUTINES_PATH;
}
collectRoutines.addAll(collectRoutines(process, include));
collectRoutines.addAll(collectRoutines(process, USER_PIGUDF_PATH));
for (IRepositoryViewObject object : collectRoutines) {
Item item = object.getProperty().getItem();
if (item instanceof RoutineItem) {
RoutineItem routine = (RoutineItem) item;
EList imports = routine.getImports();
for (Object o : imports) {
IMPORTType type = (IMPORTType) o;
listModulesReallyNeeded.add(type.getMODULE());
}
}
}
if (Log4jPrefsSettingManager.getInstance().isLog4jEnable()) {
addLog4jToJarList(listModulesReallyNeeded);
}
for (File tempFile : files) {
try {
if (listModulesReallyNeeded.contains(tempFile.getName())) {
list.add(tempFile.toURL());
}
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
}
}
return list;
// List<URL> libraries = new ArrayList<URL>();
// if (needLibraries) {
// try {
// ILibrariesService service = CorePlugin.getDefault().getLibrariesService();
// libraries = service.getTalendRoutines();
// } catch (Exception e) {
// ExceptionHandler.process(e);
// }
// }
// return libraries;
}
use of org.talend.core.model.properties.RoutineItem in project tdi-studio-se by Talend.
the class RenameRoutinesClassName method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (getProject().getLanguage() == ECodeLanguage.JAVA) {
RoutineItem routineItem = (RoutineItem) item;
if (routineItem.isBuiltIn()) {
// if it's a system routine, no migration needed.
return ExecutionResult.NOTHING_TO_DO;
}
try {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
ByteArray content = routineItem.getContent();
String str = new String(content.getInnerContent());
String string = item.getProperty().getLabel();
//$NON-NLS-1$
str = str.replaceAll("__CLASS_NAME__", string);
content.setInnerContent(str.getBytes());
routineItem.setContent(content);
factory.save(routineItem);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
Aggregations