use of org.gradle.wrapper.PathAssembler in project intellij-community by JetBrains.
the class GradleInstallationManager method getWrappedGradleHome.
private File getWrappedGradleHome(String linkedProjectPath, @Nullable final WrapperConfiguration wrapperConfiguration) {
if (wrapperConfiguration == null) {
return null;
}
File gradleSystemDir;
if ("PROJECT".equals(wrapperConfiguration.getDistributionBase())) {
gradleSystemDir = new File(linkedProjectPath, ".gradle");
} else {
gradleSystemDir = StartParameter.DEFAULT_GRADLE_USER_HOME;
}
if (!gradleSystemDir.isDirectory()) {
return null;
}
PathAssembler.LocalDistribution localDistribution = new PathAssembler(gradleSystemDir).getDistribution(wrapperConfiguration);
if (localDistribution.getDistributionDir() == null) {
return null;
}
File[] distFiles = localDistribution.getDistributionDir().listFiles(f -> f.isDirectory() && StringUtil.startsWith(f.getName(), "gradle-"));
return distFiles == null || distFiles.length == 0 ? null : distFiles[0];
}
use of org.gradle.wrapper.PathAssembler in project intellij-community by JetBrains.
the class GradleImportingTestCase method configureWrapper.
private void configureWrapper() throws IOException, URISyntaxException {
final URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion));
myProjectSettings.setDistributionType(DistributionType.DEFAULT_WRAPPED);
final VirtualFile wrapperJarFrom = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(wrapperJar());
assert wrapperJarFrom != null;
final VirtualFile wrapperJarFromTo = createProjectSubFile("gradle/wrapper/gradle-wrapper.jar");
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
wrapperJarFromTo.setBinaryContent(wrapperJarFrom.contentsToByteArray());
}
}.execute().throwException();
Properties properties = new Properties();
properties.setProperty("distributionBase", "GRADLE_USER_HOME");
properties.setProperty("distributionPath", "wrapper/dists");
properties.setProperty("zipStoreBase", "GRADLE_USER_HOME");
properties.setProperty("zipStorePath", "wrapper/dists");
properties.setProperty("distributionUrl", distributionUri.toString());
StringWriter writer = new StringWriter();
properties.store(writer, null);
createProjectSubFile("gradle/wrapper/gradle-wrapper.properties", writer.toString());
WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(getProjectPath());
PathAssembler.LocalDistribution localDistribution = new PathAssembler(StartParameter.DEFAULT_GRADLE_USER_HOME).getDistribution(wrapperConfiguration);
File zip = localDistribution.getZipFile();
try {
if (zip.exists()) {
ZipFile zipFile = new ZipFile(zip);
zipFile.close();
}
} catch (ZipException e) {
e.printStackTrace();
System.out.println("Corrupted file will be removed: " + zip.getPath());
FileUtil.delete(zip);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations