summaryrefslogtreecommitdiff
path: root/platform/projectModel-api/src/com/intellij/openapi/project
diff options
context:
space:
mode:
Diffstat (limited to 'platform/projectModel-api/src/com/intellij/openapi/project')
-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
3 files changed, 155 insertions, 0 deletions
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;
+ }
+}