summaryrefslogtreecommitdiff
path: root/platform/projectModel-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/projectModel-api/src')
-rw-r--r--platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java2
-rw-r--r--platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeProvider.java35
-rw-r--r--platform/projectModel-api/src/com/intellij/openapi/project/ProjectType.java59
-rw-r--r--platform/projectModel-api/src/com/intellij/openapi/project/ProjectTypeService.java61
-rw-r--r--platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java5
-rw-r--r--platform/projectModel-api/src/com/intellij/openapi/roots/PersistentOrderRootType.java8
6 files changed, 166 insertions, 4 deletions
diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java b/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java
index 765f350309bd..374423225694 100644
--- a/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java
+++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoragePathMacros.java
@@ -31,6 +31,8 @@ import org.jetbrains.annotations.NotNull;
* @since 5/2/12 12:57 PM
*/
public class StoragePathMacros {
+ @NonNls @NotNull public static final String ROOT_CONFIG = "$ROOT_CONFIG$";
+
/** Points to the application-level settings root directory. */
@NonNls @NotNull public static final String APP_CONFIG = "$APP_CONFIG$";
diff --git a/platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeProvider.java b/platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeProvider.java
new file mode 100644
index 000000000000..81887eba0f98
--- /dev/null
+++ b/platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeProvider.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * 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.intellij.openapi.project;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public abstract class DefaultProjectTypeProvider {
+
+ private final static ExtensionPointName<DefaultProjectTypeProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.defaultProjectTypeProvider");
+
+ @Nullable
+ public static ProjectType getDefaultProjectType() {
+ DefaultProjectTypeProvider[] extensions = EXTENSION_POINT_NAME.getExtensions();
+ return extensions.length > 0 ? extensions[0].getProjectType() : null;
+ }
+
+ protected abstract ProjectType getProjectType();
+}
diff --git a/platform/projectModel-api/src/com/intellij/openapi/project/ProjectType.java b/platform/projectModel-api/src/com/intellij/openapi/project/ProjectType.java
new file mode 100644
index 000000000000..f096e67c0ff5
--- /dev/null
+++ b/platform/projectModel-api/src/com/intellij/openapi/project/ProjectType.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * 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.intellij.openapi.project;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public class ProjectType {
+
+ private String id;
+
+ /**
+ * For serialization.
+ */
+ public ProjectType() {
+ }
+
+ public ProjectType(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ProjectType type = (ProjectType)o;
+
+ if (id != null ? !id.equals(type.id) : type.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+}
diff --git a/platform/projectModel-api/src/com/intellij/openapi/project/ProjectTypeService.java b/platform/projectModel-api/src/com/intellij/openapi/project/ProjectTypeService.java
new file mode 100644
index 000000000000..e43059390b19
--- /dev/null
+++ b/platform/projectModel-api/src/com/intellij/openapi/project/ProjectTypeService.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * 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.intellij.openapi.project;
+
+import com.intellij.openapi.components.*;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Dmitry Avdeev
+ */
+
+@State(
+ name = "ProjectType",
+ storages = {
+ @Storage(file = StoragePathMacros.PROJECT_FILE),
+ @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/misc.xml", scheme = StorageScheme.DIRECTORY_BASED)
+ }
+)
+public class ProjectTypeService implements PersistentStateComponent<ProjectType> {
+
+ private ProjectType myProjectType;
+
+ @Nullable
+ public static ProjectType getProjectType(@Nullable Project project) {
+ ProjectType projectType;
+ if (project != null) {
+ projectType = getInstance(project).myProjectType;
+ if (projectType != null) return projectType;
+ }
+ return DefaultProjectTypeProvider.getDefaultProjectType();
+ }
+
+ public static ProjectTypeService getInstance(@NotNull Project project) {
+ return ServiceManager.getService(project, ProjectTypeService.class);
+ }
+
+ @Nullable
+ @Override
+ public ProjectType getState() {
+ return myProjectType;
+ }
+
+ @Override
+ public void loadState(ProjectType state) {
+ myProjectType = state;
+ }
+}
diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java b/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java
index 60fccacb04c0..3230ed3ae496 100644
--- a/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java
+++ b/platform/projectModel-api/src/com/intellij/openapi/roots/OrderRootType.java
@@ -18,6 +18,7 @@ package com.intellij.openapi.roots;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.extensions.Extensions;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -111,8 +112,8 @@ public class OrderRootType {
List<PersistentOrderRootType> allTypes = new ArrayList<PersistentOrderRootType>();
Collections.addAll(allTypes, getAllPersistentTypes());
Collections.sort(allTypes, new Comparator<PersistentOrderRootType>() {
- public int compare(final PersistentOrderRootType o1, final PersistentOrderRootType o2) {
- return o1.getSdkRootName().compareTo(o2.getSdkRootName());
+ public int compare(@NotNull final PersistentOrderRootType o1, @NotNull final PersistentOrderRootType o2) {
+ return o1.name().compareToIgnoreCase(o2.name());
}
});
return allTypes;
diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/PersistentOrderRootType.java b/platform/projectModel-api/src/com/intellij/openapi/roots/PersistentOrderRootType.java
index b799e76ad351..cb8f90e35326 100644
--- a/platform/projectModel-api/src/com/intellij/openapi/roots/PersistentOrderRootType.java
+++ b/platform/projectModel-api/src/com/intellij/openapi/roots/PersistentOrderRootType.java
@@ -18,6 +18,7 @@ package com.intellij.openapi.roots;
import org.jetbrains.annotations.NonNls;
import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.Nullable;
/**
* @author yole
@@ -27,7 +28,7 @@ public class PersistentOrderRootType extends OrderRootType {
private final String myModulePathsName;
private final String myOldSdkRootName;
- protected PersistentOrderRootType(@NonNls String name, @NonNls String sdkRootName, @NonNls String modulePathsName, @NonNls final String oldSdkRootName) {
+ protected PersistentOrderRootType(@NonNls String name, @NonNls @Nullable String sdkRootName, @NonNls @Nullable String modulePathsName, @NonNls final @Nullable String oldSdkRootName) {
super(name);
mySdkRootName = sdkRootName;
myModulePathsName = modulePathsName;
@@ -37,12 +38,14 @@ public class PersistentOrderRootType extends OrderRootType {
}
/**
- * @return Element name used for storing roots of this type in JDK and library definitions.
+ * @return Element name used for storing roots of this type in JDK definitions.
*/
+ @Nullable
public String getSdkRootName() {
return mySdkRootName;
}
+ @Nullable
public String getOldSdkRootName() {
return myOldSdkRootName;
}
@@ -50,6 +53,7 @@ public class PersistentOrderRootType extends OrderRootType {
/**
* @return Element name used for storing roots of this type in module definitions.
*/
+ @Nullable
public String getModulePathsName() {
return myModulePathsName;
}