From 1c3aec7bc32a2bb9a2c4d22f3db39151063604b7 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 2 Mar 2017 20:11:05 +0300 Subject: [PATCH] build scripts cleanup: removed files which aren't used by new build scripts --- .../build/MacDistributionBuilder.groovy | 203 ----------------- .../intellij/build/WinInstallerBuilder.groovy | 195 ---------------- build/lib/NsiFiles.jar | Bin 4277 -> 0 bytes .../internalUtilities/ant/NsiFiles.java | 215 ------------------ 4 files changed, 613 deletions(-) delete mode 100644 build/groovy/org/jetbrains/intellij/build/MacDistributionBuilder.groovy delete mode 100644 build/groovy/org/jetbrains/intellij/build/WinInstallerBuilder.groovy delete mode 100644 build/lib/NsiFiles.jar delete mode 100644 build/src/com/intellij/internalUtilities/ant/NsiFiles.java diff --git a/build/groovy/org/jetbrains/intellij/build/MacDistributionBuilder.groovy b/build/groovy/org/jetbrains/intellij/build/MacDistributionBuilder.groovy deleted file mode 100644 index f260ada69166..000000000000 --- a/build/groovy/org/jetbrains/intellij/build/MacDistributionBuilder.groovy +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.intellij.build - -import com.intellij.util.PathUtilRt -import org.apache.tools.ant.types.Path -import org.apache.tools.ant.util.SplitClassLoader -import org.codehaus.gant.GantBuilder -import org.jetbrains.jps.gant.JpsGantProjectBuilder - -/** - * @deprecated use {@link BuildTasks} instead. - */ -class MacDistributionBuilder { - GantBuilder ant - JpsGantProjectBuilder projectBuilder - MacHostProperties macHostProperties - /** - * Path to a directory where IntelliJ IDEA community sources are located - */ - String communityHome - /** - * Unique number for the current build (e.g. IC-142.239 for IDEA Community), it is used to create unique file name for files transferred to Mac host - */ - String fullBuildNumber - /** - * Path to a directory where artifacts are stored - */ - String artifactsPath - /** - * Path to the JDK 8 tar file to be bundled with the application - */ - String customJDKTarPath - /** - * Path to an image which will be injected into .dmg file - */ - String dmgImagePath - - - private String remoteDir - /** - * Converts ${targetFileName}.mac.zip file to ${targetFileName}.dmg installer with signed application inside - * @return path to created .dmg file - */ - String signAndBuildDmg(String targetFileName) { - defineTasks() - remoteDir = "intellij-builds/$fullBuildNumber" - def sitFilePath = "$artifactsPath/${targetFileName}.sit" - ant.copy(file: "$artifactsPath/${targetFileName}.mac.zip", tofile: sitFilePath) - ftpAction("mkdir") { - } - signMacZip(targetFileName, sitFilePath) - return buildDmg(targetFileName) - } - - private String buildDmg(String sitFileName) { - projectBuilder.stage("building .dmg") - def dmgImageCopy = "$artifactsPath/${fullBuildNumber}.png" - ant.copy(file: dmgImagePath, tofile: dmgImageCopy) - ftpAction("put") { - ant.fileset(file: dmgImageCopy) - } - ant.delete(file: dmgImageCopy) - - ftpAction("put", false, "777") { - ant.fileset(dir: "$communityHome/platform/build-scripts/tools/mac/scripts") { - include(name: "makedmg.sh") - include(name: "makedmg.pl") - } - } - - sshExec("$remoteDir/makedmg.sh ${sitFileName} ${fullBuildNumber}") - ftpAction("get", true, null, 3) { - ant.fileset(dir: artifactsPath) { - include(name: "${sitFileName}.dmg") - } - } - ftpAction("delete") { - ant.fileset() { - include(name: "**") - } - } - ftpAction("rmdir", true, null, 0, PathUtilRt.getParentPath(remoteDir)) { - ant.fileset() { - include(name: "${PathUtilRt.getFileName(remoteDir)}/**") - } - } - def dmgFilePath = "$artifactsPath/${sitFileName}.dmg" - if (!new File(dmgFilePath).exists()) { - projectBuilder.error("Failed to build .dmg file.") - } - return dmgFilePath - } - - private def signMacZip(String sitFileName, String sitFilePath) { - projectBuilder.stage("signing .mac.zip") - - if (new File(customJDKTarPath).exists()) { - ftpAction("put") { - ant.fileset(file: customJDKTarPath) - } - } - else { - projectBuilder.info("Custom JDK won't be bundled: $customJDKTarPath doesn't exist") - } - - projectBuilder.info("Sending $sitFilePath") - ftpAction("put") { - ant.fileset(file: sitFilePath) - } - ant.delete(file: sitFilePath) - ftpAction("put", false, "777") { - ant.fileset(dir: "$communityHome/platform/build-scripts/tools/mac/scripts") { - include(name: "signapp.sh") - } - } - - sshExec( - "$remoteDir/signapp.sh ${sitFileName} ${fullBuildNumber} ${macHostProperties.userName} ${macHostProperties.password} \"${macHostProperties.codesignString}\" \"${PathUtilRt.getFileName(customJDKTarPath)}\"") - ftpAction("get", true, null, 3) { - ant.fileset(dir: artifactsPath) { - include(name: "${sitFileName}.sit") - } - } - if (!new File(sitFilePath).exists()) { - projectBuilder.error("Failed to build .sit file") - } - } - - static boolean tasksDefined - - private def defineTasks() { - if (tasksDefined) return - tasksDefined = true - - /* - We need this to ensure that FTP task class isn't loaded by the main Ant classloader, otherwise Ant will try to load FTPClient class - by the main Ant classloader as well and fail because 'commons-net-*.jar' isn't included to Ant classpath. - Probably we could call FTPClient directly to avoid this hack. - */ - def ftpTaskLoaderRef = "FTP_TASK_CLASS_LOADER"; - Path ftpPath = new Path(ant.project) - ftpPath.createPathElement().setLocation(new File("$communityHome/lib/commons-net-3.3.jar")) - ftpPath.createPathElement().setLocation(new File("$communityHome/lib/ant/lib/ant-commons-net.jar")) - ant.project.addReference(ftpTaskLoaderRef, new SplitClassLoader(ant.project.getClass().getClassLoader(), ftpPath, ant.project, - ["FTP", "FTPTaskConfig"] as String[])) - ant.taskdef(name: "ftp", classname: "org.apache.tools.ant.taskdefs.optional.net.FTP", loaderRef: ftpTaskLoaderRef) - - def sshTaskLoaderRef = "SSH_TASK_CLASS_LOADER"; - Path pathSsh = new Path(ant.project) - pathSsh.createPathElement().setLocation(new File("$communityHome/lib/jsch-0.1.54.jar")) - pathSsh.createPathElement().setLocation(new File("$communityHome/lib/ant/lib/ant-jsch.jar")) - ant.project.addReference(sshTaskLoaderRef, new SplitClassLoader(ant.project.getClass().getClassLoader(), pathSsh, ant.project, - ["SSHExec", "SSHBase", "LogListener", "SSHUserInfo"] as String[])) - ant.taskdef(name: "sshexec", classname: "org.apache.tools.ant.taskdefs.optional.ssh.SSHExec", loaderRef: sshTaskLoaderRef) - } - - private void sshExec(String command) { - ant.sshexec( - host: macHostProperties.host, - username: macHostProperties.userName, - password: macHostProperties.password, - trust: "yes", - command: command - ) - } - - def ftpAction( - String action, - boolean binary = true, - String chmod = null, - int retriesAllowed = 0, - String overrideRemoteDir = null, - Closure filesets) { - Map args = [ - server : macHostProperties.host, - userid : macHostProperties.userName, - password : macHostProperties.password, - action : action, - remotedir : overrideRemoteDir ?: remoteDir, - binary : binary ? "yes" : "no", - passive : "yes", - retriesallowed: "$retriesAllowed" - ] - if (chmod != null) { - args["chmod"] = chmod - } - ant.ftp(args, filesets) - } -} diff --git a/build/groovy/org/jetbrains/intellij/build/WinInstallerBuilder.groovy b/build/groovy/org/jetbrains/intellij/build/WinInstallerBuilder.groovy deleted file mode 100644 index 7e7d954bbd18..000000000000 --- a/build/groovy/org/jetbrains/intellij/build/WinInstallerBuilder.groovy +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.intellij.build - -import com.intellij.openapi.util.SystemInfoRt -import org.codehaus.gant.GantBuilder -import org.jetbrains.jps.gant.JpsGantProjectBuilder - -/** - * @deprecated use {@link BuildTasks} instead. - */ -class WinInstallerBuilder { - GantBuilder ant - JpsGantProjectBuilder projectBuilder - ApplicationInfoProperties applicationInfo - /** - * Path to a directory where project sources are located. It will be used to replace 'BASE_DIR' in *.nsi files. - */ - String baseDirectory - /** - * Path to a directory where IntelliJ IDEA community sources are located - */ - String communityHome - /** - * Path to a directory where artifacts are stored - */ - String artifactsPath - /** - * Path to a directory where temporary files can be stored - */ - String sandboxPath - /** - * Prefix for the output file name. The value of buildNumber will be appended to this prefix. - */ - String outNamePrefix - /** - * Short build number without product code (e.g. 142.239) - */ - String buildNumber - /** - * Name which will be used for default config/system paths, should include the product name and version. E.g. for IntelliJ Ultimate 16 it is - * 'IntelliJIdea16', so the settings and system files will be stored in $USER_HOME/.IntelliJIdea16 by default. - */ - String systemSelector - /** - * Determines whether tools.jar should be included to the bundled JDK - */ - boolean includeToolsJar = true - boolean associateIpr = true - /** - * Path to a JDK 8 zip file which should be bundled with the application - */ - String winJDKZipPath - - /** - * Builds .exe installer. If build/lib/jet-sign.jar exists in baseDirectory it will be used to sign the created .exe file. - * - * @param pathsToInclude list of paths to directories which contents should be included to the product distribution - * @param stringsFile path to *.nsi file where installers variables are defined (use build/conf/nsis/stringsCE.nsi as a reference) - * @param pathsFile path to *.nsi file where installers path variables are defined (use build/conf/nsis/pathsCE.nsi as a reference) - * @return path to the created installer file - */ - def buildInstaller(List pathsToInclude, String stringsFile, String pathsFile) { - if (!SystemInfoRt.isWindows && !SystemInfoRt.isLinux) { - projectBuilder.warning("Windows installer can be built only under Windows or Linux") - return null - } - - projectBuilder.stage("Building Windows installer") - String outFileName = "${outNamePrefix}${buildNumber}" - ant.taskdef(name: "nsis", classname: "com.intellij.internalUtilities.ant.NsiFiles", classpath: "$communityHome/build/lib/NsiFiles.jar") - - def box = sandboxPath - ant.mkdir(dir: "$box/bin") - ant.mkdir(dir: "$box/nsiconf") - - if (winJDKZipPath != null) { - ant.unzip(dest: "$box", src: winJDKZipPath) - - ant.copy(todir: "$box/bin") { - fileset(dir: "$box/jre/bin") { - include(name: "msvcr120.dll") - } - } - } - - ant.copy(todir: "$box/nsiconf") { - fileset(dir: "$communityHome/build/conf/nsis") { - include(name: "*") - exclude(name: "version*") - exclude(name: "strings*") - exclude(name: "paths*") - } - } - - if (applicationInfo.isEAP) { - ant.copy(file: "$communityHome/build/conf/nsis/version.eap.nsi", - tofile: "$box/nsiconf/version.nsi", overwrite: true) - } - else { - ant.copy(file: "$communityHome/build/conf/nsis/version.nsi", - tofile: "$box/nsiconf/version.nsi", overwrite: true) - } - ant.copy(file: pathsFile, toFile: "$box/nsiconf/paths.nsi", overwrite: true) - - ant.nsis(instfile: "$box/nsiconf/idea_win.nsh", uninstfile: "$box/nsiconf/unidea_win.nsh") { - pathsToInclude.each { - ant.fileset(dir: it, includes: "**/*") { - exclude(name: "**/idea.properties") - exclude(name: "**/*.vmoptions") - } - } - ant.fileset(dir: box, includes: "bin/msvcr71.dll") - if (winJDKZipPath != null) { - ant.fileset(dir: box, includes: "jre/**/*") - if (includeToolsJar) { - ant.fileset(dir: box) { - include(name: "jre/lib/tools.jar") - } - } - } - } - - ant.copy(file: stringsFile, toFile: "$box/nsiconf/strings.nsi", overwrite: true) - ant.replace(file: "$box/nsiconf/strings.nsi") { - replacefilter(token: "__VERSION_MAJOR__", value: applicationInfo.majorVersion) - replacefilter(token: "__VERSION_MINOR__", value: applicationInfo.minorVersion) - } - - ant.replace(file: "$box/nsiconf/version.nsi") { - replacefilter(token: "__BUILD_NUMBER__", value: buildNumber) - replacefilter(token: "__VERSION_MAJOR__", value: applicationInfo.majorVersion) - replacefilter(token: "__VERSION_MINOR__", value: applicationInfo.minorVersion) - replacefilter(token: "__PRODUCT_PATHS_SELECTOR__", value: systemSelector) - } - - ant.unzip(src: "$communityHome/build/tools/NSIS.zip", dest: box) - if (SystemInfoRt.isWindows) { - ant.exec(command: "\"${box}/NSIS/makensis.exe\"" + - " /DBASE_DIR=\"$baseDirectory\"" + - " /DCOMMUNITY_DIR=\"$communityHome\"" + - " /DIPR=\"${associateIpr}\"" + - " /DOUT_FILE=\"${outFileName}\"" + - " /DOUT_DIR=\"$artifactsPath\"" + - " \"${box}/nsiconf/idea.nsi\"") - } - else if (SystemInfoRt.isLinux) { - ant.exec(command: "makensis" + - " '-X!AddPluginDir \"${box}/NSIS/Plugins\"'" + - " '-X!AddIncludeDir \"${box}/NSIS/Include\"'" + - " -DBASE_DIR=\"$baseDirectory\"" + - " -DCOMMUNITY_DIR=\"$communityHome\"" + - " -DIPR=\"${associateIpr}\"" + - " -DOUT_FILE=\"${outFileName}\"" + - " -DOUT_DIR=\"$artifactsPath\"" + - " \"${box}/nsiconf/idea.nsi\"") - } - - def installerPath = "$artifactsPath/${outFileName}.exe" - if (!new File(installerPath).exists()) { - projectBuilder.error("Installer wasn't created.") - } - - def signJarPath = "$baseDirectory/build/lib/jet-sign.jar" - if (new File(signJarPath).exists()) { - projectBuilder.stage("Signing $installerPath") - ant.taskdef(name: "jet-sign", classname: "jetbrains.sign.JetSignTask") { - classpath(path: signJarPath) - } - ant."jet-sign"() { - ant.fileset(dir: artifactsPath) { - include(name: "${outFileName}.exe") - } - } - projectBuilder.stage("Signing done") - } - else { - projectBuilder.warning("$signJarPath not found, installer won't be signed") - } - return installerPath - } -} \ No newline at end of file diff --git a/build/lib/NsiFiles.jar b/build/lib/NsiFiles.jar deleted file mode 100644 index db8cb4e076667712e3a1c882a41fa550bb56c9f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4277 zcma)kzb@!Wjzuj4P_dIv*bMDMJ=l`D(l$wTt;=%%XXf= ze;;6{prSZSfls5-%Rh*!XFEqhksVhFBr8Ps1~F z-$-XpnGM&XFGvAGmquwAOm*E}86fEmOkCjhW#(R2 zLX#XR&W;?uQ`~U%(2;}P*f(G%+dANJX#MTVm_yaM<~O;eBSOdhk_TZ2A*)J5rwVhq zUada|P!tlTW`gfxh=3n~R07I;#L)*GZJG3%O{txC&aJCvBU~7Lk z20Xcz5>9-%yaNLNaHcwqInALyz07rDW_4^p)!MCR@l!&*$^_gb6zs(~1_UvDz_7!x zX)kWZib|WB3xK6Q5AHU@+j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Kk4t@yy59&-RQeDU zV(N!_2?CiRr?Ecu(9c9+WViLkm76AQ3+2rc#Zh-uK)?z|+R{jP%Np^cZbKI9T z9Xz1@R*9|~9)G6pjzP=;&CCXXi*=R6tyOpD%a}ez^|j;%?NZb0D=AC3e?m>gc02V9;tdM~QQva^x&6V9iAV_lY`vb!+KahA@yVLm=RUCK#dl2gEBg^+E0svRa8xiqjLeAi~?jF6)hP7r@4G-9ox+o;n)j_(}5 z&l%yX^T@l5Iy6a7<9o-WOT>pAn%Ig2Oj|mFw=D2+tK%(()dr!-F(=9bdwx`_+%&z6 z$};*@UbM;1(k5Z5CBRi=;`zqp+9{DEN~*Ggp)-eUU-CX=j!Gry$w#d(T7+lBkKpL& z2hM*EiZlw0Q*g6aI%=YwK!^1xzj<`k4C0Tijf2t%yR$HJA4W##To2*16YiceFI82k zT!E!{LlSSK1lBSAxwH3$r5mv96>{{qy1uKq^qzhwN&{!{he0rsEAek1l@O8I5~ t%h*4Fo05v1;?Kzak3s%lzoGwa@Sg$P2zrM0_r#fBpC{!nif8`)`Wpm!jc5P> diff --git a/build/src/com/intellij/internalUtilities/ant/NsiFiles.java b/build/src/com/intellij/internalUtilities/ant/NsiFiles.java deleted file mode 100644 index 437a3d894e39..000000000000 --- a/build/src/com/intellij/internalUtilities/ant/NsiFiles.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.internalUtilities.ant; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.taskdefs.MatchingTask; -import org.apache.tools.ant.types.FileSet; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.*; -import java.util.regex.Matcher; - -/** - * @deprecated replaced by {@link org.jetbrains.intellij.build.impl.NsisFileListGenerator}; this class will be removed together with {@link org.jetbrains.intellij.build.WinInstallerBuilder} - */ -@SuppressWarnings("UnusedDeclaration") -public class NsiFiles extends MatchingTask { - private File myInstFile; - private File myUnInstFile; - private File myBaseDir; - private final List myFileSets = new ArrayList<>(); - private final Map> myDirToFiles = new LinkedHashMap<>(); - private final Map myAbsoluteToRelative = new HashMap<>(); - - /** - * The file to create; required - * @param nsiFile new file to generate file install list to. - */ - public void setInstFile(File nsiFile) { - myInstFile = nsiFile; - } - - /** - * The file to create; required - * @param nsiFile new file to generate file uninstall list to. - */ - public void setUninstFile(File nsiFile) { - myUnInstFile = nsiFile; - } - - /** - * ;optional - * @param fileSet to be included in processing - */ - public void addFileSet(FileSet fileSet) { - myFileSets.add(fileSet); - } - - /** - * ;optional - * @param baseDir of the files to be processed. - */ - public void setBaseDir(File baseDir) { - myBaseDir = baseDir; - } - - public void execute() throws BuildException { - if (myInstFile == null) throw new BuildException("Specify required isntFile attribute."); - if (myUnInstFile == null) throw new BuildException("Specify required unisntFile attribute."); - - if (myBaseDir == null && myFileSets.size() == 0) { - throw new BuildException("basedir attribute must be set, " - + "or at least " - + "one fileset must be given!"); - } - - try { - if (myBaseDir != null) { - FileSet fs = (FileSet) getImplicitFileSet().clone(); - fs.setDir(myBaseDir); - processFileSet(fs); - } - - for (FileSet fileSet : myFileSets) { - processFileSet(fileSet); - } - - generateInstFile(); - generateUninstFile(); - } - catch (IOException e) { - throw new BuildException(e); - } - finally { - cleanup(); - } - } - - private void generateUninstFile() throws IOException { - BufferedWriter uninstWriter = new BufferedWriter(new FileWriter(myUnInstFile)); - try { - List allFiles = new ArrayList<>(); - final Collection> lists = myDirToFiles.values(); - for (final List list : lists) { - allFiles.addAll(list); - } - - Collections.sort(allFiles); - for (String file : allFiles) { - uninstWriter.newLine(); - final String relPath = myAbsoluteToRelative.get(file); - uninstWriter.write("Delete \"$INSTDIR\\" + toWinPath(relPath) + "\""); - if (relPath.endsWith(".py")) { - uninstWriter.newLine(); - uninstWriter.write("Delete \"$INSTDIR\\" + toWinPath(relPath) + "c\""); // .pyc - } - } - - uninstWriter.newLine(); - List dirs = new ArrayList<>(myDirToFiles.keySet()); - Collections.sort(dirs); - for (int i = dirs.size() - 1; i >= 0; i--) { - final String dir = dirs.get(i); - if (dir.length() == 0) continue; - uninstWriter.newLine(); - uninstWriter.write("RmDir /r \"$INSTDIR\\" + toWinPath(dir) + "\\__pycache__\""); - uninstWriter.newLine(); - uninstWriter.write("RmDir \"$INSTDIR\\" + toWinPath(dir) + "\""); - } - uninstWriter.newLine(); - uninstWriter.write("RmDir \"$INSTDIR\""); - } - finally{ - uninstWriter.close(); - } - } - - private void generateInstFile() throws IOException { - BufferedWriter instWriter = new BufferedWriter(new FileWriter(myInstFile)); - try { - Collection dirs = myDirToFiles.keySet(); - for (String dir : dirs) { - final List files = myDirToFiles.get(dir); - if (files.size() == 0) continue; - instWriter.newLine(); - instWriter.newLine(); - if (dir.length() > 0) { - instWriter.write("SetOutPath \"$INSTDIR" + "\\" + toWinPath(dir) + "\""); - } - else { - instWriter.write("SetOutPath \"$INSTDIR\""); - } - - for (String file : files) { - instWriter.newLine(); - instWriter.write("File \"" + file + "\""); - } - } - } - finally { - instWriter.close(); - } - } - - private static String toWinPath(String dir) { - return File.separatorChar == '\\' ? dir : dir.replaceAll(File.separator, Matcher.quoteReplacement("\\")); - } - - private void processFileSet(final FileSet fileSet) throws IOException { - final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject()); - final String[] files = scanner.getIncludedFiles(); - String base = fileSet.getDir(getProject()).getCanonicalPath() + File.separator; - for (String file : files) { - String lastDir = ""; - getDirFileList(lastDir); - int idx = -1; - do { - idx = file.indexOf(File.separator, idx + 1); - if (idx == -1) break; - lastDir = file.substring(0, idx); - getDirFileList(lastDir); - } - while (true); - - List fileList = getDirFileList(lastDir); - final String absolute = base + file; - fileList.add(absolute); - myAbsoluteToRelative.put(absolute, file); - } - } - - private List getDirFileList(final String dir) { - List fileList = myDirToFiles.get(dir); - if (fileList == null) { - fileList = new ArrayList<>(); - myDirToFiles.put(dir, fileList); - } - return fileList; - } - - private void cleanup() { - myBaseDir = null; - myInstFile = null; - myFileSets.clear(); - myDirToFiles.clear(); - myAbsoluteToRelative.clear(); - } -}