use of org.talend.core.ILibraryManagerService in project tdi-studio-se by Talend.
the class JavaProcessorUtilities method sortClasspath.
// // see bug 3914, make the order of the jar files consistent with the
// command
// // line in run mode
private static void sortClasspath(Set<ModuleNeeded> jobModuleList, IProcess process, Set<ModuleNeeded> alreadyRetrievedModules) throws CoreException, ProcessorException {
ITalendProcessJavaProject jProject = getTalendJavaProject();
if (jProject == null) {
return;
}
Set<ModuleNeeded> listModulesReallyNeeded = new HashSet<ModuleNeeded>();
listModulesReallyNeeded.addAll(jobModuleList);
Set<ModuleNeeded> optionalJarsOnlyForRoutines = new HashSet<ModuleNeeded>();
// only for wizards or additional jars only to make the java project compile without any error.
for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getSystemRunningModules()) {
optionalJarsOnlyForRoutines.add(moduleNeeded);
}
// list contains all routines linked to job as well as routines not used in the job
// rebuild the list to have only the libs linked to routines "not used".
optionalJarsOnlyForRoutines.removeAll(listModulesReallyNeeded);
// only to be able to compile java project without error.
for (ModuleNeeded jar : optionalJarsOnlyForRoutines) {
listModulesReallyNeeded.add(jar);
}
addLog4jToModuleList(listModulesReallyNeeded);
listModulesReallyNeeded.removeAll(alreadyRetrievedModules);
alreadyRetrievedModules.addAll(listModulesReallyNeeded);
String missingJars = null;
Set<String> missingJarsForRoutinesOnly = new HashSet<String>();
Set<String> missingJarsForProcessOnly = new HashSet<String>();
File libDir = getJavaProjectLibFolder();
ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
if ((libDir != null) && (libDir.isDirectory())) {
Set<ModuleNeeded> jarsNeedRetrieve = new HashSet<ModuleNeeded>();
for (ModuleNeeded moduleNeeded : listModulesReallyNeeded) {
jarsNeedRetrieve.add(moduleNeeded);
}
if (!jarsNeedRetrieve.isEmpty()) {
repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath(), true);
if (process instanceof IProcess2) {
((IProcess2) process).checkProcess();
}
}
Set<ModuleNeeded> exist = new HashSet<ModuleNeeded>();
for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
for (ModuleNeeded module : jarsNeedRetrieve) {
if (externalLib.getName().equals(module.getModuleName())) {
exist.add(module);
}
}
}
jarsNeedRetrieve.removeAll(exist);
Set<String> jarStringListNeededByProcess = new HashSet<String>();
for (ModuleNeeded moduleNeeded : jobModuleList) {
jarStringListNeededByProcess.add(moduleNeeded.getModuleName());
}
for (ModuleNeeded jar : jarsNeedRetrieve) {
if (jobModuleList.contains(jar)) {
missingJarsForProcessOnly.add(jar.getModuleName());
} else {
missingJarsForRoutinesOnly.add(jar.getModuleName());
}
if (missingJars == null) {
//$NON-NLS-1$
missingJars = Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess") + jar;
} else {
//$NON-NLS-1$
missingJars = missingJars + ", " + jar;
}
}
}
repositoryBundleService.deployModules(listModulesReallyNeeded, null);
if (missingJars != null) {
handleMissingJarsForProcess(missingJarsForRoutinesOnly, missingJarsForProcessOnly, missingJars);
}
}
use of org.talend.core.ILibraryManagerService 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.ILibraryManagerService in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method getLib.
protected List<URL> getLib(List<ModuleNeeded> libs, Boolean needLib) {
List<URL> list = new ArrayList<URL>();
if (!needLib) {
return list;
}
try {
org.talend.core.model.general.Project projecdddt = ProjectManager.getInstance().getCurrentProject();
IProject fsProject = null;
try {
fsProject = ResourceUtils.getProject(projecdddt);
} catch (PersistenceException e2) {
ExceptionHandler.process(e2);
}
//$NON-NLS-1$
IPath temPath = fsProject.getLocation().append(File.separator + "temp");
ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
if (repositoryBundleService != null) {
repositoryBundleService.retrieve(new HashSet<ModuleNeeded>(libs), temPath.toString(), true);
}
File file = temPath.toFile();
File[] files = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(FileConstants.JAR_FILE_SUFFIX) || name.toLowerCase().endsWith(FileConstants.PROPERTIES_FILE_SUFFIX) || name.toLowerCase().endsWith(FileConstants.ZIP_FILE_SUFFIX) ? true : false;
}
});
Set<String> moduleNames = new HashSet<String>();
for (ModuleNeeded m : libs) {
moduleNames.add(m.getModuleName());
}
for (File tempFile : files) {
try {
if (moduleNames.contains(tempFile.getName())) {
list.add(tempFile.toURL());
}
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
return list;
}
Aggregations