use of org.jetbrains.plugins.gradle.tooling.builder.AbstractModelBuilderTest.DistributionLocator 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