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);
}
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;
}
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();
}
}
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);
}
}
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;
}
Aggregations