Search in sources :

Example 6 with ComponentConfig

use of org.apache.ofbiz.base.component.ComponentConfig in project ofbiz-framework by apache.

the class ComponentContainer method loadComponentsInDirectory.

/**
 * Load all components in a directory because it does not contain
 * a load-components.xml file. The components are sorted alphabetically
 * for loading purposes
 *
 * @param directoryPath the absolute path of the directory
 * @throws IOException
 */
private void loadComponentsInDirectory(File directoryPath) throws IOException {
    String[] sortedComponentNames = directoryPath.list();
    if (sortedComponentNames == null) {
        throw new IllegalArgumentException("sortedComponentNames is null, directory path is invalid " + directoryPath.getPath());
    }
    Arrays.sort(sortedComponentNames);
    for (String componentName : sortedComponentNames) {
        File componentPath = FileUtil.getFile(directoryPath.getCanonicalPath() + File.separator + componentName);
        String componentLocation = componentPath.getCanonicalPath();
        File configFile = FileUtil.getFile(componentLocation.concat(File.separator).concat(ComponentConfig.OFBIZ_COMPONENT_XML_FILENAME));
        if (componentPath.isDirectory() && !componentName.startsWith(".") && configFile.exists()) {
            ComponentConfig config = retrieveComponentConfig(null, componentLocation);
            if (config != null) {
                loadComponent(config);
            }
        }
    }
}
Also used : ComponentConfig(org.apache.ofbiz.base.component.ComponentConfig) File(java.io.File)

Example 7 with ComponentConfig

use of org.apache.ofbiz.base.component.ComponentConfig in project ofbiz-framework by apache.

the class ComponentContainer method buildClasspathFromComponentConfig.

/**
 * Construct a <code>Classpath</code> object for a certain component based
 * on its configuration defined in <code>ComponentConfig</code>
 *
 * @param config the component configuration
 * @return the constructed classpath
 * @throws IOException
 */
private Classpath buildClasspathFromComponentConfig(ComponentConfig config) throws IOException {
    Classpath classPath = new Classpath();
    String configRoot = config.getRootLocation().replace('\\', '/');
    configRoot = configRoot.endsWith("/") ? configRoot : configRoot + "/";
    List<ComponentConfig.ClasspathInfo> classpathInfos = config.getClasspathInfos();
    for (ComponentConfig.ClasspathInfo cp : classpathInfos) {
        String location = cp.location.replace('\\', '/');
        if (!"jar".equals(cp.type) && !"dir".equals(cp.type)) {
            Debug.logError("Classpath type '" + cp.type + "' is not supported; '" + location + "' not loaded", module);
            continue;
        }
        location = location.startsWith("/") ? location.substring(1) : location;
        String dirLoc = location.endsWith("/*") ? location.substring(0, location.length() - 2) : location;
        File path = FileUtil.getFile(configRoot + dirLoc);
        if (path.exists()) {
            classPath.addComponent(configRoot + location);
            if (path.isDirectory() && "dir".equals(cp.type)) {
                classPath.addFilesFromPath(path);
            }
        } else {
            Debug.logWarning("Location '" + configRoot + dirLoc + "' does not exist", module);
        }
    }
    return classPath;
}
Also used : ComponentConfig(org.apache.ofbiz.base.component.ComponentConfig) Classpath(org.apache.ofbiz.base.start.Classpath) File(java.io.File)

Aggregations

ComponentConfig (org.apache.ofbiz.base.component.ComponentConfig)7 File (java.io.File)3 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 Future (java.util.concurrent.Future)1 Classpath (org.apache.ofbiz.base.start.Classpath)1 Delegator (org.apache.ofbiz.entity.Delegator)1 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)1 GenericValue (org.apache.ofbiz.entity.GenericValue)1 GenericHelperInfo (org.apache.ofbiz.entity.datasource.GenericHelperInfo)1 DatabaseUtil (org.apache.ofbiz.entity.jdbc.DatabaseUtil)1 ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)1