2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.jetbrains
.idea
.maven
.utils
;
19 import com
.intellij
.ide
.highlighter
.XmlFileType
;
20 import com
.intellij
.openapi
.application
.ApplicationManager
;
21 import com
.intellij
.openapi
.application
.PathMacros
;
22 import com
.intellij
.openapi
.components
.ApplicationComponent
;
23 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.idea
.maven
.embedder
.MavenEmbedderFactory
;
29 public class MavenEnvironmentRegistrar
implements ApplicationComponent
{
30 private static final String MAVEN_REPOSITORY
= "MAVEN_REPOSITORY";
33 public String
getComponentName() {
34 return MavenEnvironmentRegistrar
.class.getName();
37 public void initComponent() {
39 registerPathVariable();
42 private void registerFileTypes() {
43 // we should not change file types in unit test mode
44 if (ApplicationManager
.getApplication().isUnitTestMode()) return;
45 FileTypeManager
.getInstance().associateExtension(XmlFileType
.INSTANCE
, MavenConstants
.POM_EXTENSION
);
48 private void registerPathVariable() {
49 File repository
= MavenEmbedderFactory
.resolveLocalRepository(null, null, null);
50 PathMacros macros
= PathMacros
.getInstance();
52 for (String each
: macros
.getAllMacroNames()) {
53 String path
= macros
.getValue(each
);
54 if (path
== null) continue;
55 if (new File(path
).equals(repository
)) return;
57 macros
.setMacro(MAVEN_REPOSITORY
, repository
.getPath());
60 public void disposeComponent() {