Java源码示例:org.gradle.wrapper.PathAssembler
示例1
@Override
public void setUp() throws Exception {
assumeThat(gradleVersion, versionMatcherRule.getMatcher());
myJdkHome = IdeaTestUtil.requireRealJdkHome();
super.setUp();
WriteAction.runAndWait(() -> {
Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
if (oldJdk != null) {
ProjectJdkTable.getInstance().removeJdk(oldJdk);
}
VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
JavaSdk javaSdk = JavaSdk.getInstance();
SdkType javaSdkType = javaSdk == null ? SimpleJavaSdkType.getInstance() : javaSdk;
Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, javaSdkType, true, null, GRADLE_JDK_NAME);
assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
ProjectJdkTable.getInstance().addJdk(jdk);
});
myProjectSettings = new GradleProjectSettings().withQualifiedModuleNames();
System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
PathAssembler.LocalDistribution distribution = configureWrapper();
List<String> allowedRoots = new ArrayList<>();
collectAllowedRoots(allowedRoots, distribution);
if (!allowedRoots.isEmpty()) {
VfsRootAccess.allowRootAccess(myTestFixture.getTestRootDisposable(), ArrayUtil.toStringArray(allowedRoots));
}
}
示例2
private File distributionBaseDir() {
WrapperConfiguration conf = new WrapperConfiguration();
conf.setDistribution(downloadLocation);
PathAssembler pa = new PathAssembler(gradleUserHome);
PathAssembler.LocalDistribution dist = pa.getDistribution(conf);
return dist.getDistributionDir();
}
示例3
@Messages({
"# {0} - The downloading GradleVersion ",
"TIT_Install_Gradle_Failed=Failed installing {0}",
})
@Override
public void run() {
try {
WrapperConfiguration conf = new WrapperConfiguration();
conf.setDistribution(version.getDownloadLocation());
PathAssembler pa = new PathAssembler(gradleUserHome);
Install install = new Install(new Logger(true), this, pa);
install.createDist(conf);
version.fireVersionAvailable();
} catch (Exception ex) {
//Happens if something goes wrong with the download.
//TODO: Is it ok to let id silently die?
NotificationDisplayer.getDefault().notify(
Bundle.TIT_Install_Gradle_Failed(version.getVersion()),
NbGradleProject.getWarningIcon(),
ex.getLocalizedMessage(),
null,
NotificationDisplayer.Priority.HIGH,
NotificationDisplayer.Category.WARNING);
} finally {
handle.finish();
notification.clear();
}
}
示例4
protected void collectAllowedRoots(final List<String> roots, PathAssembler.LocalDistribution distribution) {
}
示例5
private PathAssembler.LocalDistribution 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");
WriteAction.runAndWait(() -> wrapperJarFromTo.setBinaryContent(wrapperJarFrom.contentsToByteArray()));
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();
}
return localDistribution;
}