/*
 * Copyright 2010 Jon S Akhtar (Sylvanaar)
 *  
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.sylvanaar.idea.Lua.module;

import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.ide.util.projectWizard.SourcePathsBuilder;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

class LuaModuleBuilder extends ModuleBuilder implements SourcePathsBuilder {

    @Nullable
    private String myContentRootPath = null;
    @Nullable
    private Sdk mySdk = null;

    public void setupRootModel(@NotNull final ModifiableRootModel rootModel) throws ConfigurationException {
        if (mySdk != null) {
            rootModel.setSdk(mySdk);
        } else {
            rootModel.inheritSdk();
        }
        if (myContentRootPath != null) {
            final LocalFileSystem lfs = LocalFileSystem.getInstance();
            //noinspection ConstantConditions
            final VirtualFile moduleContentRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(myContentRootPath));
            if (moduleContentRoot != null) {
                rootModel.addContentEntry(moduleContentRoot);
            }
        }
    }

    @NotNull
    public ModuleType getModuleType() {
        return LuaModuleType.getInstance();
    }

    @Nullable
    public String getContentEntryPath() {
        return myContentRootPath;
    }

    public void setContentEntryPath(@Nullable final String contentRootPath) {
        myContentRootPath = contentRootPath;
    }

    public void setSdk(@Nullable final Sdk sdk) {
        mySdk = sdk;
    }

    public List<Pair<String, String>> getSourcePaths() {
        throw new UnsupportedOperationException();
    }

    public void setSourcePaths(final List<Pair<String, String>> sourcePaths) {
        throw new UnsupportedOperationException();
    }

    public void addSourcePath(final Pair<String, String> sourcePathInfo) {
        throw new UnsupportedOperationException();
    }
}

@@ -727,85 +727,9 @@
 ard.
-ModuleBuilder;%0D%0Aimport com.intellij.ide.util.projectWizard.SourcePathsBuilder
+*
 ;%0D%0Ai
@@ -762,26 +762,17 @@
 .module.
-ModuleType
+*
 ;%0D%0Aimpor
@@ -802,38 +802,17 @@
 options.
-ConfigurationException
+*
 ;%0D%0Aimpor
@@ -847,19 +847,17 @@
 ctRoots.
-Sdk
+*
 ;%0D%0Aimpor
@@ -885,35 +885,17 @@
 i.roots.
-ModifiableRootModel
+*
 ;%0D%0Aimpor
@@ -922,20 +922,17 @@
 pi.util.
-Pair
+*
 ;%0D%0Aimpor
@@ -962,24 +962,17 @@
 util.io.
-FileUtil
+*
 ;%0D%0Aimpor
@@ -1002,156 +1002,46 @@
 vfs.
-LocalFileSystem;%0D%0Aimport com.intellij.openapi.vfs.VirtualFile;%0D%0Aimport org.jetbrains.annotations.NotNull;%0D%0Aimport org.jetbrains.annotations.Nullable
+*;%0D%0Aimport org.jetbrains.annotations.*
 ;%0D%0A%0D
@@ -1058,20 +1058,17 @@
 va.util.
-List
+*
 ;%0D%0A%0D%0Acla
@@ -1113,37 +1113,8 @@
 der 
-implements SourcePathsBuilder
  %7B%0D%0A
@@ -2335,405 +2335,8 @@
   %7D%0D
-%0A%0D%0A    public List%3CPair%3CString, String%3E%3E getSourcePaths() %7B%0D%0A        throw new UnsupportedOperationException();%0D%0A    %7D%0D%0A%0D%0A    public void setSourcePaths(final List%3CPair%3CString, String%3E%3E sourcePaths) %7B%0D%0A        throw new UnsupportedOperationException();%0D%0A    %7D%0D%0A%0D%0A    public void addSourcePath(final Pair%3CString, String%3E sourcePathInfo) %7B%0D%0A        throw new UnsupportedOperationException();%0D%0A    %7D%0D
 %0A%7D%0D%0A

fix another NCDF for Lua modules in directory projects