summaryrefslogtreecommitdiff
path: root/jps/standalone-builder/src/org/jetbrains/jps/idea/IdeaProjectLoader.java
blob: b392dcf150816d9ad7ac931368c61506618fc8b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package org.jetbrains.jps.idea;

import groovy.lang.Script;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author max
 */
public class IdeaProjectLoader {
  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, ".idea").exists()) {
        return home.getCanonicalPath();
      }


      home = home.getParentFile();
    }


    throw new IllegalArgumentException("Cannot guess project home from '" + uri + "'");
  }
}