Search in sources :

Example 1 with PathAssembler

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];
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PathAssembler(org.gradle.wrapper.PathAssembler)

Example 2 with PathAssembler

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();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DistributionLocator(org.jetbrains.plugins.gradle.tooling.builder.AbstractModelBuilderTest.DistributionLocator) WriteAction(com.intellij.openapi.application.WriteAction) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Properties(java.util.Properties) WrapperConfiguration(org.gradle.wrapper.WrapperConfiguration) URI(java.net.URI) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) PathAssembler(org.gradle.wrapper.PathAssembler) StringWriter(java.io.StringWriter) ZipFile(java.util.zip.ZipFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 PathAssembler (org.gradle.wrapper.PathAssembler)2 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 Properties (java.util.Properties)1 ZipException (java.util.zip.ZipException)1 ZipFile (java.util.zip.ZipFile)1 WrapperConfiguration (org.gradle.wrapper.WrapperConfiguration)1 NotNull (org.jetbrains.annotations.NotNull)1 DistributionLocator (org.jetbrains.plugins.gradle.tooling.builder.AbstractModelBuilderTest.DistributionLocator)1