Search in sources :

Example 1 with IMPORTType

use of org.talend.designer.core.model.utils.emf.component.IMPORTType in project tdi-studio-se by Talend.

the class JavaProcessorUtilities method getNeededModulesForProcess.

public static Set<ModuleNeeded> getNeededModulesForProcess(IProcess process) {
    Set<ModuleNeeded> neededLibraries = new TreeSet<ModuleNeeded>(new Comparator<ModuleNeeded>() {

        @Override
        public int compare(ModuleNeeded m1, ModuleNeeded m2) {
            return m1.toString().compareTo(m2.toString());
        }
    });
    Set<ModuleNeeded> neededModules = LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(process.getId(), process.getVersion());
    neededLibraries.addAll(neededModules);
    if (process == null || !(process instanceof IProcess2)) {
        if (neededLibraries.isEmpty() && process != null) {
            neededLibraries = process.getNeededModules(true);
            if (neededLibraries == null) {
                neededLibraries = new HashSet<ModuleNeeded>();
            // for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
            // neededLibraries.add(moduleNeeded.getModuleName());
            // }
            }
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
        return neededLibraries;
    }
    Property property = ((IProcess2) process).getProperty();
    if (neededLibraries.isEmpty()) {
        neededLibraries = process.getNeededModules(true);
        if (neededLibraries == null) {
            neededLibraries = new HashSet<ModuleNeeded>();
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    } else {
        if (property != null && property.getItem() instanceof ProcessItem) {
            neededLibraries.addAll(ModulesNeededProvider.getModulesNeededForProcess((ProcessItem) property.getItem(), process));
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    }
    if (property != null && GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamel(property.getItem())) {
            // http://jira.talendforge.org/browse/TESB-5887 LiXiaopeng 2012-6-19
            // Synchronize Route resources
            camelService.synchronizeRouteResource((ProcessItem) property.getItem());
            try {
                for (IRepositoryViewObject object : CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().getAll(camelService.getBeansType())) {
                    Item item = object.getProperty().getItem();
                    if (item instanceof RoutineItem) {
                        RoutineItem routine = (RoutineItem) item;
                        for (Object o : routine.getImports()) {
                            IMPORTType type = (IMPORTType) o;
                            ModuleNeeded neededModule = new ModuleNeeded("camel bean dependencies", type.getMODULE(), "camel bean dependencies", true);
                            neededLibraries.add(neededModule);
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return neededLibraries;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RoutineItem(org.talend.core.model.properties.RoutineItem) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) TreeSet(java.util.TreeSet) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Property(org.talend.core.model.properties.Property)

Example 2 with IMPORTType

use of org.talend.designer.core.model.utils.emf.component.IMPORTType in project tdi-studio-se by Talend.

the class RemoveRoutineAntlrJarDependencyTask 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()) {
            return ExecutionResult.NOTHING_TO_DO;
        }
        try {
            EList<IMPORTType> imports = routineItem.getImports();
            List<IMPORTType> toRemove = new ArrayList<IMPORTType>();
            for (IMPORTType importElement : imports) {
                if ("antlr-3.3.jar".equals(importElement.getMODULE())) {
                    //$NON-NLS-1$
                    toRemove.add(importElement);
                }
            }
            if (toRemove.size() > 0) {
                imports.removeAll(toRemove);
                ProxyRepositoryFactory.getInstance().save(routineItem);
            }
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (Exception e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ArrayList(java.util.ArrayList) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) RoutineItem(org.talend.core.model.properties.RoutineItem)

Example 3 with IMPORTType

use of org.talend.designer.core.model.utils.emf.component.IMPORTType in project tdi-studio-se by Talend.

the class RemoveRoutineJarDependencyTask 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()) {
            return ExecutionResult.NOTHING_TO_DO;
        }
        try {
            EList<IMPORTType> imports = routineItem.getImports();
            List<Object> toRemove = new ArrayList<Object>();
            for (IMPORTType importElement : imports) {
                if ("org.talend.dataquality.parser.jar".equals(importElement.getMODULE())) {
                    //$NON-NLS-1$
                    toRemove.add(importElement);
                }
            }
            if (toRemove.size() > 0) {
                imports.removeAll(toRemove);
                ProxyRepositoryFactory.getInstance().save(routineItem);
            }
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (Exception e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ArrayList(java.util.ArrayList) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) RoutineItem(org.talend.core.model.properties.RoutineItem)

Example 4 with IMPORTType

use of org.talend.designer.core.model.utils.emf.component.IMPORTType in project tdi-studio-se by Talend.

the class ExportProjectsAsAction method getLinksFromProject.

/**
     * DOC zwang Comment method "getLinksFromProject".
     * 
     * @param project
     * @return
     */
private List<LinkTargetStore> getLinksFromProject(Project project) {
    List<IMPORTType> imports = null;
    String linkTarget = null;
    RootContainer<String, IRepositoryViewObject> routines = getRoutineFromProject(project);
    List<LinkTargetStore> paths = new ArrayList<LinkTargetStore>();
    String language = project.getLanguage().getName().trim();
    for (IRepositoryViewObject obj : routines.getMembers()) {
        RoutineItem routine = (RoutineItem) obj.getProperty().getItem();
        imports = routine.getImports();
        if (language != null) {
            if (project != null && ECodeLanguage.JAVA.getName().equals(language)) {
                IPath containerPath = getContainerFullPath(project.getTechnicalLabel());
                for (IMPORTType importType : imports) {
                    try {
                        LinkTargetStore store = new LinkTargetStore();
                        IPath newFilePath = containerPath.append(ExportProjectsAsAction.LIB + java.io.File.separatorChar + ECodeLanguage.JAVA.getName() + java.io.File.separatorChar + importType.getMODULE());
                        linkTarget = EXTERNAL_LIB_JAVA_PATH + java.io.File.separatorChar + importType.getMODULE();
                        URI path = new URI(linkTarget.replace(java.io.File.separatorChar, '/'));
                        store.file = ResourcesPlugin.getWorkspace().getRoot().getFile(newFilePath);
                        store.uri = path;
                        paths.add(store);
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        }
    }
    return paths;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) RoutineItem(org.talend.core.model.properties.RoutineItem) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 5 with IMPORTType

use of org.talend.designer.core.model.utils.emf.component.IMPORTType in project tdi-studio-se by Talend.

the class ImportModuleManagerTest method testGetImportTypes.

@Test
public void testGetImportTypes() {
    manager = ImportModuleManager.getInstance();
    initTestImportsType();
    List<IMPORTType> importTypes = manager.getImportTypes(testImportsType);
    assertNotNull(importTypes);
    assertTrue(importTypes.size() == 3);
    IMPORTType importType1 = importTypes.get(0);
    //$NON-NLS-1$
    assertEquals("test-jar1.jar", importType1.getMODULE());
    //$NON-NLS-1$
    assertEquals("x > 0", importType1.getREQUIREDIF());
    IMPORTType importType2 = importTypes.get(1);
    //$NON-NLS-1$
    assertEquals("test-jar2.jar", importType2.getMODULE());
    //$NON-NLS-1$
    assertEquals("y > 0", importType2.getREQUIREDIF());
    IMPORTType importType3 = importTypes.get(2);
    //$NON-NLS-1$
    assertEquals("test-jar3.jar", importType3.getMODULE());
    //$NON-NLS-1$
    assertEquals("z > 0 AND (x > y)", importType3.getREQUIREDIF());
}
Also used : IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) Test(org.junit.Test)

Aggregations

IMPORTType (org.talend.designer.core.model.utils.emf.component.IMPORTType)11 ArrayList (java.util.ArrayList)7 RoutineItem (org.talend.core.model.properties.RoutineItem)7 PersistenceException (org.talend.commons.exception.PersistenceException)4 Item (org.talend.core.model.properties.Item)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 CoreException (org.eclipse.core.runtime.CoreException)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)2 IMPORTSType (org.talend.designer.core.model.utils.emf.component.IMPORTSType)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URL (java.net.URL)1