code: public static ComponentManager initialize(File permanentDirectory, File resourceDirectory, File temporaryDirectory,
          ClassLoader classLoader)
      {
          // Step 1: Initialize Component system
          EmbeddableComponentManager ecm = new EmbeddableComponentManager();
          ecm.initialize(classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader);
  
          // Step 2: Initialize Environment
          StandardEnvironment environment;
          try {
              environment = ecm.getInstance(Environment.class);
          } catch (ComponentLookupException e) {
              throw new RuntimeException("Failed to find Standard Environment", e);
          }
          environment.setPermanentDirectory(permanentDirectory);
          environment.setResourceDirectory(resourceDirectory);
          environment.setTemporaryDirectory(temporaryDirectory);
  
          return ecm;
      }
docs: Initialize the full XWiki system (ie Component Manager and Environment).
  
  @param permanentDirectory see {@link org.xwiki.environment.Environment#getPermanentDirectory()}
  @param resourceDirectory see
  {@link org.xwiki.environment.internal.StandardEnvironment#setResourceDirectory(java.io.File)}
  @param temporaryDirectory see {@link org.xwiki.environment.Environment#getTemporaryDirectory()}
  @param classLoader see {@link EmbeddableComponentManager#initialize(ClassLoader)}
  @return the initialized Component Manager
  @see #dispose(ComponentManager)