All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openl.rules.project.instantiation.SimpleProjectDependencyManager Maven / Gradle / Ivy

package org.openl.rules.project.instantiation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import org.openl.dependency.loader.IDependencyLoader;
import org.openl.rules.project.dependencies.ProjectExternalDependenciesHelper;
import org.openl.rules.project.model.Module;
import org.openl.rules.project.model.ProjectDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleProjectDependencyManager extends AbstractProjectDependencyManager {

    private final Logger log = LoggerFactory.getLogger(SimpleProjectDependencyManager.class);

    private List dependencyLoaders;

    private Collection projects;

    private Collection projectDescriptors;
    private Collection dependencyNames = null;
    
    private boolean singleModuleMode = false;
    private boolean executionMode = true;

    @Override
    public Collection getAllDependencies() {
        if (dependencyLoaders == null) {
            initDependencyLoaders();
        }
        return dependencyNames;
    }
    
    public SimpleProjectDependencyManager(Collection projects,
                                          boolean singleModuleMode,
                                          boolean executionMode) {
        super();
        if (projects == null) {
            throw new IllegalArgumentException("projects can't be null!");
        }
        this.projects = projects;
        this.singleModuleMode = singleModuleMode;
        this.executionMode = executionMode;
        this.singleModuleMode = singleModuleMode;
    }

    public SimpleProjectDependencyManager(Collection projects, boolean singleModuleMode) {
        this(projects, singleModuleMode, true);
    }
    
    @Override
    public Collection getProjectDescriptors() {
        if (dependencyLoaders == null){
            initDependencyLoaders();
        }
        return projectDescriptors;
    }

    @Override
    public List getDependencyLoaders() {
        if (dependencyLoaders == null){
            initDependencyLoaders();
        }
        return dependencyLoaders;
    }

    private synchronized void initDependencyLoaders() {
        if (projectDescriptors == null && dependencyLoaders == null) {
            dependencyLoaders = new ArrayList();
            projectDescriptors = new ArrayList();
            dependencyNames = new HashSet();
            for (ProjectDescriptor project : projects) {
                try {
                    Collection modulesOfProject = project.getModules();
                    if (!modulesOfProject.isEmpty()) {
                        for (final Module m : modulesOfProject) {
                            dependencyLoaders.add(new SimpleProjectDependencyLoader(m.getName(),
                                Arrays.asList(m),
                                singleModuleMode,
                                executionMode));
                            dependencyNames.add(m.getName());
                        }
                    }

                    String dependencyName = ProjectExternalDependenciesHelper.buildDependencyNameForProjectName(project.getName());
                    IDependencyLoader projectLoader = new SimpleProjectDependencyLoader(dependencyName,
                        project.getModules(),
                        singleModuleMode,
                        executionMode);
                    projectDescriptors.add(project);
                    dependencyLoaders.add(projectLoader);
                } catch (Exception e) {
                    log.error("Build dependency manager loaders for project {} was failed!", project.getName(), e);
                }
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy