Search in sources :

Example 96 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class TalendProcessJavaProjectTest method testGetSrcFolder.

/**
     * Test method for {@link org.talend.designer.runprocess.java.TalendProcessJavaProject#getSrcFolder()}.
     */
@Test
public void testGetSrcFolder() {
    IFolder srcFolder = talendJavaProject.getSrcFolder();
    Assert.assertNotNull(srcFolder);
    Assert.assertTrue(srcFolder.exists());
    IPath projectRelativePath = srcFolder.getProjectRelativePath();
    Assert.assertEquals(MavenSystemFolders.JAVA.getPath(), projectRelativePath.toString());
}
Also used : IPath(org.eclipse.core.runtime.IPath) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 97 with IFolder

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);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) IFolder(org.eclipse.core.resources.IFolder)

Example 98 with IFolder

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);
    }
}
Also used : CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) IPath(org.eclipse.core.runtime.IPath) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 99 with IFolder

use of org.eclipse.core.resources.IFolder in project tesb-studio-se by Talend.

the class RouteResourceUtil method synchronizeRouteResource.

public static Collection<IPath> synchronizeRouteResource(final ProcessItem item) {
    final boolean routelet;
    if (item.eClass() == CamelPropertiesPackage.Literals.CAMEL_PROCESS_ITEM) {
        routelet = false;
    } else if (item.eClass() == CamelPropertiesPackage.Literals.ROUTELET_PROCESS_ITEM) {
        routelet = true;
    } else {
        return null;
    }
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return null;
    }
    final IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
    final ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
    if (talendProcessJavaProject == null) {
        return null;
    }
    final IFolder routeResourceFolder = talendProcessJavaProject.getResourcesFolder();
    final Collection<IPath> result = new ArrayList<IPath>();
    // add spring file
    if (!routelet) {
        final IFolder metaInf = routeResourceFolder.getFolder("META-INF/spring/");
        try {
            prepareFolder(metaInf);
            final IFile spring = metaInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
            final InputStream inputStream = new ByteArrayInputStream(((CamelProcessItem) item).getSpringContent().getBytes());
            if (spring.exists()) {
                spring.setContents(inputStream, 0, null);
            } else {
                spring.create(inputStream, true, null);
            }
            result.add(spring.getLocation());
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }
    for (ResourceDependencyModel model : getResourceDependencies(item)) {
        IFile file = copyResources(routeResourceFolder, model);
        if (file != null) {
            result.add(file.getLocation());
        }
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResourceDependencyModel(org.talend.designer.camel.resource.core.model.ResourceDependencyModel) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) IFolder(org.eclipse.core.resources.IFolder)

Example 100 with IFolder

use of org.eclipse.core.resources.IFolder in project sling by apache.

the class JcrNode method prune.

private void prune(IContainer folder) throws CoreException {
    if (folder == null || !(folder instanceof IFolder)) {
        return;
    }
    IFolder f = (IFolder) folder;
    IResource[] members = f.members();
    if (members != null && members.length != 0) {
        return;
    }
    f.delete(true, new NullProgressMonitor());
    prune(folder.getParent());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)237 IFile (org.eclipse.core.resources.IFile)95 IPath (org.eclipse.core.runtime.IPath)70 CoreException (org.eclipse.core.runtime.CoreException)65 IProject (org.eclipse.core.resources.IProject)64 IResource (org.eclipse.core.resources.IResource)56 File (java.io.File)35 IContainer (org.eclipse.core.resources.IContainer)33 ArrayList (java.util.ArrayList)31 Path (org.eclipse.core.runtime.Path)31 IOException (java.io.IOException)26 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 Test (org.junit.Test)18 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 InputStream (java.io.InputStream)15 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)13 URL (java.net.URL)12