private Module loadModule(String moduleName) { File jarFile = findJar(moduleName); if (jarFile != null) { Set<File> implementationClasspath = new LinkedHashSet<File>(); implementationClasspath.add(jarFile); Properties properties = loadModuleProperties(moduleName, jarFile); return module(moduleName, properties, implementationClasspath); } String resourceName = String.format("%s-classpath.properties", moduleName); Set<File> implementationClasspath = new LinkedHashSet<File>(); findImplementationClasspath(moduleName, implementationClasspath); for (File file : implementationClasspath) { if (file.isDirectory()) { File propertiesFile = new File(file, resourceName); if (propertiesFile.isFile()) { Properties properties = GUtil.loadProperties(propertiesFile); return module(moduleName, properties, implementationClasspath); } } } if (gradleDistributionLocator.getGradleHome() == null) { throw new UnknownModuleException( String.format("Cannot locate manifest for module '%s' in classpath.", moduleName)); } throw new UnknownModuleException( String.format( "Cannot locate JAR for module '%s' in distribution directory '%s'.", moduleName, gradleDistributionLocator.getGradleHome())); }
private static GradleDistribution findGradleInstallFromGradleRunner() { GradleDistributionLocator gradleDistributionLocator = new DefaultGradleDistributionLocator(GradleRunner.class); File gradleHome = gradleDistributionLocator.getGradleHome(); if (gradleHome == null) { String messagePrefix = "Could not find a Gradle runtime to use based on the location of the GradleRunner class"; try { File classpathForClass = ClasspathUtil.getClasspathForClass(GradleRunner.class); messagePrefix += ": " + classpathForClass.getAbsolutePath(); } catch (Exception ignore) { // ignore } throw new InvalidRunnerConfigurationException( messagePrefix + ". Please specify a Gradle runtime to use via GradleRunner.withGradleVersion() or similar."); } return new InstalledGradleDistribution(gradleHome); }
private File findDependencyJar(String module, String name) { File jarFile = classpathJars.get(name); if (jarFile != null) { return jarFile; } if (gradleDistributionLocator.getGradleHome() == null) { throw new IllegalArgumentException( String.format( "Cannot find JAR '%s' required by module '%s' using classpath.", name, module)); } for (File libDir : gradleDistributionLocator.getLibDirs()) { jarFile = new File(libDir, name); if (jarFile.isFile()) { return jarFile; } } throw new IllegalArgumentException( String.format( "Cannot find JAR '%s' required by module '%s' using classpath or distribution directory '%s'", name, module, gradleDistributionLocator.getGradleHome())); }
public Module getExternalModule(String name) { File externalJar = findJar(name); if (externalJar == null) { throw new UnknownModuleException( String.format( "Cannot locate JAR for module '%s' in distribution directory '%s'.", name, gradleDistributionLocator.getGradleHome())); } return new DefaultModule( name, Collections.singleton(externalJar), Collections.<File>emptySet(), Collections.<Module>emptySet()); }
private File findJar(String name) { Pattern pattern = Pattern.compile(Pattern.quote(name) + "-\\d.+\\.jar"); for (File libDir : gradleDistributionLocator.getLibDirs()) { for (File file : libDir.listFiles()) { if (pattern.matcher(file.getName()).matches()) { return file; } } } for (File file : classpath) { if (pattern.matcher(file.getName()).matches()) { return file; } } return null; }
@Override public ClassPath getAdditionalClassPath() { return gradleDistributionLocator.getGradleHome() == null ? new DefaultClassPath(classpath) : new DefaultClassPath(); }