use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class BuildJobHandler method addDQDependencies.
private void addDQDependencies(IFolder parentFolder, List<Item> items) throws Exception {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
ITDQItemService tdqItemService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
for (Item item : items) {
if (tdqItemService != null && tdqItemService.hasProcessItemDependencies(Arrays.asList(new Item[] { item }))) {
setNeedItemDependencies(true);
// add .Talend.definition file
//$NON-NLS-1$
String defIdxFolderName = "TDQ_Libraries";
//$NON-NLS-1$
String defIdxFileName = ".Talend.definition";
Project pro = getProject(processItem);
IFolder itemsProjectFolder = parentFolder.getFolder(pro.getTechnicalLabel().toLowerCase());
File itemsFolderDir = new File(parentFolder.getLocation().toFile().getAbsolutePath());
IProject project = ReponsitoryContextBridge.getRootProject();
String defIdxRelativePath = defIdxFolderName + PATH_SEPARATOR + defIdxFileName;
IFile defIdxFile = project.getFile(defIdxRelativePath);
if (defIdxFile.exists()) {
File defIdxFileSource = new File(project.getLocation().makeAbsolute().append(defIdxFolderName).append(defIdxFileName).toFile().toURI());
File defIdxFileTarget = new File(itemsProjectFolder.getFile(defIdxRelativePath).getLocation().toFile().getAbsolutePath());
FilesUtils.copyFile(defIdxFileSource, defIdxFileTarget);
}
// add report header image & template files
//$NON-NLS-1$
String reportingBundlePath = PluginChecker.getBundlePath("org.talend.dataquality.reporting");
//$NON-NLS-1$
File imageFolder = new File(reportingBundlePath + PATH_SEPARATOR + "images");
if (imageFolder.exists()) {
FilesUtils.copyDirectory(imageFolder, itemsFolderDir);
}
//$NON-NLS-1$
File templateFolder = new File(reportingBundlePath + PATH_SEPARATOR + "reports");
if (templateFolder.exists() && templateFolder.isDirectory()) {
FilesUtils.copyDirectory(templateFolder, itemsFolderDir);
}
}
}
// maven command 'include-survivorship-rules' to export.
if (!isOptionChoosed(ExportChoice.needJobItem)) {
ExportFileResource resouece = new ExportFileResource();
BuildExportManager.getInstance().exportDependencies(resouece, processItem);
if (!resouece.getAllResources().isEmpty()) {
final Iterator<String> relativepath = resouece.getRelativePathList().iterator();
//$NON-NLS-1$
String pathStr = "metadata/survivorship";
IFolder targetFolder = talendProcessJavaProject.getResourcesFolder();
if (targetFolder.exists()) {
IFolder survFolder = targetFolder.getFolder(new Path(pathStr));
// only copy self job rules, clear the 'survivorship' folder before copy.
if (survFolder.exists()) {
survFolder.delete(true, null);
}
while (relativepath.hasNext()) {
String relativePath = relativepath.next();
Set<URL> sources = resouece.getResourcesByRelativePath(relativePath);
for (URL sourceUrl : sources) {
File currentResource = new File(org.talend.commons.utils.io.FilesUtils.getFileRealPath(sourceUrl.getPath()));
if (currentResource.exists()) {
FilesUtils.copyDirectory(currentResource, new File(targetFolder.getLocation().toPortableString() + File.separator + pathStr));
}
}
}
}
}
parentFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
}
}
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class BuildJobHandler method generateTestReports.
@Override
public void generateTestReports(IProgressMonitor monitor) throws Exception {
if (!isOptionChoosed(ExportChoice.includeTestSource)) {
return;
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
List<IFile> reports = new ArrayList<IFile>();
List<ProcessItem> testsItems = testContainerService.getAllTestContainers(processItem);
for (ProcessItem testItem : testsItems) {
List<IFile> testReportFiles = testContainerService.getTestReportFiles(testItem);
if (testReportFiles.size() > 0) {
reports.add(testReportFiles.get(0));
}
}
IFolder testsFolder = talendProcessJavaProject.getTestsFolder();
talendProcessJavaProject.cleanFolder(monitor, testsFolder);
IFolder parentFolder = talendProcessJavaProject.createSubFolder(monitor, testsFolder, processItem.getProperty().getLabel());
for (IFile report : reports) {
report.copy(parentFolder.getFile(report.getName()).getFullPath(), true, monitor);
}
}
}
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class OSGIJavaScriptForESBWithMavenManager method addMavenBuildScripts.
@Override
protected void addMavenBuildScripts(ExportFileResource[] processes, List<URL> scriptsUrls, Map<String, String> mavenPropertiesMap) {
if (!PluginChecker.isPluginLoaded(PluginChecker.EXPORT_JOB_PLUGIN_ID)) {
return;
}
try {
//
Item item = processes[0].getItem();
File templateFile = null;
if (item != null) {
IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(item.getProperty());
IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(item.getProperty());
if (itemLocationPath != null && objectTypeFolder != null) {
IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
templateFile = PomUtil.getTemplateFile(objectTypeFolder, itemRelativePath, IProjectSettingTemplateConstants.OSGI_POM_FILE_NAME);
}
}
final Map<String, Object> templateParameters = PomUtil.getTemplateParameters(item.getProperty());
String mavenScript = MavenTemplateManager.getTemplateContent(templateFile, IProjectSettingPreferenceConstants.TEMPLATE_OSGI_BUNDLE_POM, PluginChecker.MAVEN_JOB_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_OSGI_BUNDLE + '/' + IProjectSettingTemplateConstants.POM_JOB_TEMPLATE_FILE_NAME, templateParameters);
// .getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_OSGI_BUNDLE_POM);
if (mavenScript == null) {
return;
}
File mavenBuildFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.POM_FILE_NAME);
FileOutputStream mavenBuildFileOutputStream = null;
try {
mavenBuildFileOutputStream = new FileOutputStream(mavenBuildFile);
mavenBuildFileOutputStream.write(mavenScript.getBytes());
} finally {
if (mavenBuildFileOutputStream != null) {
mavenBuildFileOutputStream.close();
}
}
updateMavenBuildFileContent(mavenBuildFile, mavenPropertiesMap, true, false);
scriptsUrls.add(mavenBuildFile.toURL());
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method addRoutinesSourceCodes.
protected void addRoutinesSourceCodes(ExportFileResource[] process, ExportFileResource resource, ITalendProcessJavaProject talendProcessJavaProject, boolean useBeans) throws Exception {
List<IRepositoryViewObject> collectRoutines = new ArrayList<IRepositoryViewObject>();
String include;
if (useBeans) {
include = USER_BEANS_PATH;
} else {
include = USER_ROUTINES_PATH;
}
collectRoutines.addAll(collectRoutines(process, include));
collectRoutines.addAll(collectRoutines(process, USER_PIGUDF_PATH));
Set<String> dependedRoutines = new HashSet<String>();
for (IRepositoryViewObject obj : collectRoutines) {
dependedRoutines.add(//$NON-NLS-1$
obj.getLabel() + "." + ECodeLanguage.JAVA.getExtension());
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IFolder folder = null;
if (useBeans) {
folder = srcFolder.getFolder(USER_BEANS_PATH);
} else {
folder = srcFolder.getFolder(JavaUtils.JAVA_ROUTINES_DIRECTORY);
}
List<URL> userRoutinesFileUrls = new ArrayList<URL>();
if (folder.exists()) {
for (IResource fileResource : folder.members()) {
if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension()) && dependedRoutines.contains(((IFile) fileResource).getName())) {
userRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
}
}
if (useBeans) {
resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + USER_BEANS_PATH, userRoutinesFileUrls);
} else {
resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + JavaUtils.JAVA_ROUTINES_DIRECTORY, userRoutinesFileUrls);
}
}
}
use of org.eclipse.core.resources.IFolder in project tesb-studio-se by Talend.
the class KarafJavaScriptForESBWithMavenManager method addMavenBuildScripts.
@Override
protected void addMavenBuildScripts(ExportFileResource[] processes, List<URL> scriptsUrls, Map<String, String> mavenPropertiesMap) {
if (!PluginChecker.isPluginLoaded(PluginChecker.EXPORT_ROUTE_PLUGIN_ID)) {
return;
}
Item item = processes[0].getItem();
File templatePomFile = null, templateBundleFile = null, templateFeatureFile = null, templateParentFile = null;
if (item != null) {
IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(item.getProperty());
IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(item.getProperty());
if (itemLocationPath != null && objectTypeFolder != null) {
IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
templatePomFile = PomUtil.getTemplateFile(objectTypeFolder, itemRelativePath, TalendMavenConstants.POM_FILE_NAME);
if (FilesUtils.allInSameFolder(templatePomFile, IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME, IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME, IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME)) {
templateBundleFile = new File(templatePomFile.getParentFile(), IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME);
templateFeatureFile = new File(templatePomFile.getParentFile(), IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME);
templateParentFile = new File(templatePomFile.getParentFile(), IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME);
} else {
// don't use template file from repository.
// other files is not init, so no need set null at all.
templatePomFile = null;
}
}
}
File mavenBuildFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.POM_FILE_NAME);
File mavenBuildBundleFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME);
File mavenBuildFeatureFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME);
File mavenBuildParentFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME);
try {
final Map<String, Object> templateParameters = PomUtil.getTemplateParameters(item.getProperty());
String mavenScript = MavenTemplateManager.getTemplateContent(templatePomFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_POM, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + TalendMavenConstants.POM_FILE_NAME, templateParameters);
if (mavenScript != null) {
createMavenBuildFileFromTemplate(mavenBuildFile, mavenScript);
updateMavenBuildFileContent(mavenBuildFile, mavenPropertiesMap, false, true);
scriptsUrls.add(mavenBuildFile.toURI().toURL());
}
mavenScript = MavenTemplateManager.getTemplateContent(templateBundleFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_BUNDLE, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME, templateParameters);
if (mavenScript != null) {
createMavenBuildFileFromTemplate(mavenBuildBundleFile, mavenScript);
updateMavenBuildFileContent(mavenBuildBundleFile, mavenPropertiesMap, true, false);
scriptsUrls.add(mavenBuildBundleFile.toURI().toURL());
}
mavenScript = MavenTemplateManager.getTemplateContent(templateFeatureFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_FEATURE, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME, templateParameters);
if (mavenScript != null) {
createMavenBuildFileFromTemplate(mavenBuildFeatureFile, mavenScript);
updateMavenBuildFileContent(mavenBuildFeatureFile, mavenPropertiesMap);
scriptsUrls.add(mavenBuildFeatureFile.toURI().toURL());
}
mavenScript = MavenTemplateManager.getTemplateContent(templateParentFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_PARENT, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME, templateParameters);
if (mavenScript != null) {
createMavenBuildFileFromTemplate(mavenBuildParentFile, mavenScript);
updateMavenBuildFileContent(mavenBuildParentFile, mavenPropertiesMap);
scriptsUrls.add(mavenBuildParentFile.toURI().toURL());
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
Aggregations