diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java index 42646dc7171f..6eb29444500f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java @@ -49,6 +49,7 @@ import com.intellij.util.xml.NanoXmlUtil; import gnu.trove.THashSet; import icons.MavenIcons; import org.jdom.Element; +import org.jdom.JDOMException; import org.jdom.Namespace; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -743,11 +744,7 @@ public class MavenUtil { @Nullable public static String getRepositoryFromSettings(final File file) { try { - Element fileElement = JDOMUtil.load(file); - Element repository = fileElement.getChild("localRepository"); - if (repository == null) { - repository = fileElement.getChild("localRepository", Namespace.getNamespace("http://maven.apache.org/SETTINGS/1.0.0")); - } + Element repository = getRepositoryElement(file); if (repository == null) { return null; @@ -763,6 +760,19 @@ public class MavenUtil { } } + private static Element getRepositoryElement(File file) throws JDOMException, IOException { + Element fileElement = JDOMUtil.load(file); + + Element repository = fileElement.getChild("localRepository"); + if (repository == null) { + repository = fileElement.getChild("localRepository", Namespace.getNamespace("http://maven.apache.org/SETTINGS/1.0.0")); + } + if (repository == null) { + repository = fileElement.getChild("localRepository", Namespace.getNamespace("http://maven.apache.org/SETTINGS/1.1.0")); + } + return repository; + } + public static String expandProperties(String text, Properties props) { if (StringUtil.isEmptyOrSpaces(text)) return text; for (Map.Entry each : props.entrySet()) { diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/utils/MavenUtilTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/utils/MavenUtilTest.java index 21ff3db47f94..d3a08288a943 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/utils/MavenUtilTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/utils/MavenUtilTest.java @@ -9,7 +9,7 @@ import java.io.IOException; public class MavenUtilTest extends MavenTestCase { - public void testFindLocalRepo() throws IOException { + public void testFindLocalRepoSchema10() throws IOException { VirtualFile file = createProjectSubFile("testsettings.xml", "\n" + "\n" + + "" + + " mytestpath" + + ""); + assertEquals("mytestpath", MavenUtil.getRepositoryFromSettings(new File(file.getPath()))); + } + public void testFindLocalRepoWithoutXmls() throws IOException { VirtualFile file = createProjectSubFile("testsettings.xml", "\n" + "" +