Search in sources :

Example 1 with WrapperConfiguration

use of org.gradle.wrapper.WrapperConfiguration in project gradle by gradle.

the class DistributionFactory method getDistribution.

/**
     * Returns the distribution at the given URI.
     */
public Distribution getDistribution(URI gradleDistribution) {
    WrapperConfiguration configuration = new WrapperConfiguration();
    configuration.setDistribution(gradleDistribution);
    return new ZippedDistribution(configuration, distributionBaseDir);
}
Also used : WrapperConfiguration(org.gradle.wrapper.WrapperConfiguration)

Example 2 with WrapperConfiguration

use of org.gradle.wrapper.WrapperConfiguration in project intellij-community by JetBrains.

the class GradleUtil method getWrapperConfiguration.

/**
   * Tries to retrieve what settings should be used with gradle wrapper for the gradle project located at the given path.
   *
   * @param gradleProjectPath  target gradle project config (*.gradle) path or config file's directory path.
   * @return                   gradle wrapper settings should be used with gradle wrapper for the gradle project located at the given path
   *                           if any; <code>null</code> otherwise
   */
@Nullable
public static WrapperConfiguration getWrapperConfiguration(@Nullable String gradleProjectPath) {
    final File wrapperPropertiesFile = findDefaultWrapperPropertiesFile(gradleProjectPath);
    if (wrapperPropertiesFile == null)
        return null;
    final WrapperConfiguration wrapperConfiguration = new WrapperConfiguration();
    final Properties props = new Properties();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(wrapperPropertiesFile));
        props.load(reader);
        String distributionUrl = props.getProperty(WrapperExecutor.DISTRIBUTION_URL_PROPERTY);
        if (StringUtil.isEmpty(distributionUrl)) {
            throw new ExternalSystemException("Wrapper 'distributionUrl' property does not exist!");
        } else {
            wrapperConfiguration.setDistribution(new URI(distributionUrl));
        }
        String distributionPath = props.getProperty(WrapperExecutor.DISTRIBUTION_PATH_PROPERTY);
        if (!StringUtil.isEmpty(distributionPath)) {
            wrapperConfiguration.setDistributionPath(distributionPath);
        }
        String distPathBase = props.getProperty(WrapperExecutor.DISTRIBUTION_BASE_PROPERTY);
        if (!StringUtil.isEmpty(distPathBase)) {
            wrapperConfiguration.setDistributionBase(distPathBase);
        }
        return wrapperConfiguration;
    } catch (Exception e) {
        GradleLog.LOG.warn(String.format("I/O exception on reading gradle wrapper properties file at '%s'", wrapperPropertiesFile.getAbsolutePath()), e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    return null;
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) WrapperConfiguration(org.gradle.wrapper.WrapperConfiguration) Properties(java.util.Properties) File(java.io.File) URI(java.net.URI) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with WrapperConfiguration

use of org.gradle.wrapper.WrapperConfiguration 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)

Example 4 with WrapperConfiguration

use of org.gradle.wrapper.WrapperConfiguration in project intellij-community by JetBrains.

the class UseDistributionWithSourcesNotificationProvider method updateDefaultWrapperConfiguration.

private static void updateDefaultWrapperConfiguration(@NotNull String linkedProjectPath) {
    try {
        final File wrapperPropertiesFile = GradleUtil.findDefaultWrapperPropertiesFile(linkedProjectPath);
        if (wrapperPropertiesFile == null)
            return;
        final WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(linkedProjectPath);
        if (wrapperConfiguration == null)
            return;
        String currentDistributionUri = wrapperConfiguration.getDistribution().toString();
        if (StringUtil.endsWith(currentDistributionUri, ALL_ZIP_DISTRIBUTION_URI_SUFFIX))
            return;
        final String distributionUri = currentDistributionUri.substring(0, currentDistributionUri.lastIndexOf('-')) + ALL_ZIP_DISTRIBUTION_URI_SUFFIX;
        wrapperConfiguration.setDistribution(new URI(distributionUri));
        Properties wrapperProperties = new Properties();
        wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_URL_PROPERTY, wrapperConfiguration.getDistribution().toString());
        wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_BASE_PROPERTY, wrapperConfiguration.getDistributionBase());
        wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_PATH_PROPERTY, wrapperConfiguration.getDistributionPath());
        wrapperProperties.setProperty(WrapperExecutor.ZIP_STORE_BASE_PROPERTY, wrapperConfiguration.getZipBase());
        wrapperProperties.setProperty(WrapperExecutor.ZIP_STORE_PATH_PROPERTY, wrapperConfiguration.getZipPath());
        GUtil.saveProperties(wrapperProperties, new File(wrapperPropertiesFile.getPath()));
        LocalFileSystem.getInstance().refreshIoFiles(Collections.singletonList(wrapperPropertiesFile));
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : WrapperConfiguration(org.gradle.wrapper.WrapperConfiguration) Properties(java.util.Properties) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 5 with WrapperConfiguration

use of org.gradle.wrapper.WrapperConfiguration in project intellij-community by JetBrains.

the class UseDistributionWithSourcesNotificationProvider method showUseDistributionWithSourcesTip.

private static boolean showUseDistributionWithSourcesTip(String linkedProjectPath) {
    WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(linkedProjectPath);
    // currently only wrapped distribution takes into account
    if (wrapperConfiguration == null)
        return true;
    String distributionUri = wrapperConfiguration.getDistribution().toString();
    try {
        String host = new URI(distributionUri).getHost();
        return host != null && host.endsWith("gradle.org") && !GRADLE_SRC_DISTRIBUTION_PATTERN.matcher(distributionUri).matches();
    } catch (URISyntaxException ignore) {
    }
    return false;
}
Also used : URISyntaxException(java.net.URISyntaxException) WrapperConfiguration(org.gradle.wrapper.WrapperConfiguration) URI(java.net.URI)

Aggregations

WrapperConfiguration (org.gradle.wrapper.WrapperConfiguration)6 File (java.io.File)4 URI (java.net.URI)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Properties (java.util.Properties)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Nullable (org.jetbrains.annotations.Nullable)2 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 ZipException (java.util.zip.ZipException)1 ZipFile (java.util.zip.ZipFile)1 DistributionLocator (org.gradle.util.DistributionLocator)1 PathAssembler (org.gradle.wrapper.PathAssembler)1