diff --git a/jps/standalone-builder/src/org/jetbrains/jps/idea/IdeaProjectLoader.java b/jps/standalone-builder/src/org/jetbrains/jps/idea/IdeaProjectLoader.java new file mode 100644 index 000000000000..ef369ae8510b --- /dev/null +++ b/jps/standalone-builder/src/org/jetbrains/jps/idea/IdeaProjectLoader.java @@ -0,0 +1,36 @@ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.jps.idea; + +import groovy.lang.Script; +import org.jetbrains.jps.model.serialization.PathMacroUtil; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * @author max + */ +public class IdeaProjectLoader { + /** + * This method is still used in some *.gant scripts via jps-build-script-dependencies-bootstrap library + */ + @SuppressWarnings("unused") + public static String guessHome(Script script) throws IOException, URISyntaxException { + String uri = (String)script.getProperty("gant.file"); + File home = new File(new URI(uri).getSchemeSpecificPart()); + + while (home != null) { + if (home.isDirectory() && new File(home, PathMacroUtil.DIRECTORY_STORE_NAME).exists()) { + return home.getCanonicalPath(); + } + + + home = home.getParentFile(); + } + + + throw new IllegalArgumentException("Cannot guess project home from '" + uri + "'"); + } +}