mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
added method to delete temp files when build is finished
This commit is contained in:
@@ -4,9 +4,8 @@ import org.jetbrains.jps.ModuleBuildState
|
||||
import org.jetbrains.jps.ModuleBuilder
|
||||
import org.jetbrains.jps.ModuleChunk
|
||||
import org.jetbrains.jps.Project
|
||||
import org.jetbrains.jps.builders.BuildUtil
|
||||
|
||||
/**
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class GwtModuleBuilder implements ModuleBuilder {
|
||||
@@ -41,9 +40,7 @@ class GwtModuleBuilder implements ModuleBuilder {
|
||||
return
|
||||
}
|
||||
|
||||
String baseDir = project.targetFolder != null ? project.targetFolder : "."
|
||||
String dirName = BuildUtil.suggestFileName(facet.module.name)
|
||||
String outputDir = new File(baseDir, "__temp_gwt_output_$dirName").absolutePath
|
||||
String outputDir = project.builder.getTempDirectoryPath("GWT_Output_$facet.module.name")
|
||||
facet.tempOutputDir = outputDir
|
||||
|
||||
def ant = project.binding.ant
|
||||
|
||||
@@ -173,6 +173,10 @@ class Project {
|
||||
builder.clean()
|
||||
}
|
||||
|
||||
def deleteTempFiles() {
|
||||
builder.deleteTempFiles()
|
||||
}
|
||||
|
||||
def ClasspathItem resolve(Object dep) {
|
||||
if (dep instanceof ClasspathItem) {
|
||||
return dep
|
||||
|
||||
@@ -34,9 +34,12 @@ class ProjectBuilder {
|
||||
boolean useInProcessJavac
|
||||
boolean compressJars = true
|
||||
|
||||
private final TempFileContainer tempFileContainer
|
||||
|
||||
def ProjectBuilder(GantBinding binding, Project project) {
|
||||
this.project = project
|
||||
this.binding = binding
|
||||
tempFileContainer = new TempFileContainer(project, "__build_temp__")
|
||||
sourceGeneratingBuilders << new GroovyStubGenerator(project)
|
||||
translatingBuilders << new JavacBuilder()
|
||||
translatingBuilders << new GroovycBuilder(project)
|
||||
@@ -111,6 +114,14 @@ class ProjectBuilder {
|
||||
return makeModuleWithDependencies(module, true);
|
||||
}
|
||||
|
||||
def deleteTempFiles() {
|
||||
tempFileContainer.clean()
|
||||
}
|
||||
|
||||
String getTempDirectoryPath(String name) {
|
||||
return tempFileContainer.getTempDirPath(name)
|
||||
}
|
||||
|
||||
private def makeModuleWithDependencies(Module module, boolean includeTests) {
|
||||
def chunk = chunkForModule(module, includeTests)
|
||||
Set<Module> dependencies = new HashSet<Module>()
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.jetbrains.jps
|
||||
|
||||
import org.jetbrains.jps.builders.BuildUtil
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class TempFileContainer {
|
||||
private File baseDirectory
|
||||
private final String tempDirectoryName
|
||||
private final Project project
|
||||
private final Set<String> usedNames = [] as Set
|
||||
|
||||
TempFileContainer(Project project, String tempDirectoryName) {
|
||||
this.project = project
|
||||
this.tempDirectoryName = tempDirectoryName
|
||||
}
|
||||
|
||||
private File getBaseDirectory() {
|
||||
if (baseDirectory == null) {
|
||||
def ant = project.binding.ant
|
||||
baseDirectory = new File(project.targetFolder != null ? project.targetFolder : ".", tempDirectoryName)
|
||||
ant.delete(dir: baseDirectory.absolutePath)
|
||||
ant.mkdir(dir: baseDirectory.absolutePath)
|
||||
}
|
||||
return baseDirectory
|
||||
}
|
||||
|
||||
String getTempDirPath(String name) {
|
||||
String baseName = BuildUtil.suggestFileName(name)
|
||||
String dirName = baseName
|
||||
int i = 2
|
||||
while (usedNames.contains(dirName)) {
|
||||
dirName = baseName + i
|
||||
i++
|
||||
}
|
||||
usedNames << dirName
|
||||
File tempDir = new File(getBaseDirectory(), dirName)
|
||||
return tempDir.absolutePath
|
||||
}
|
||||
|
||||
def clean() {
|
||||
if (baseDirectory != null) {
|
||||
def ant = project.binding.ant
|
||||
ant.delete(dir: baseDirectory.absolutePath)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -106,8 +106,7 @@ class ArtifactBuilder {
|
||||
project.stage("Building '${artifact.name}' artifact")
|
||||
output = getArtifactOutputFolder(artifact)
|
||||
if (output == null) {
|
||||
def dirName = BuildUtil.suggestFileName(artifact.name)
|
||||
output = new File(project.targetFolder != null ? project.targetFolder : ".", "__temp_artifact_$dirName").absolutePath
|
||||
output = project.builder.getTempDirectoryPath(artifact.name)
|
||||
project.info("Output path for artifact '$artifact.name' is not specified so it will be built to $output")
|
||||
}
|
||||
artifactOutputs[artifact] = output
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ArtifactManager">
|
||||
<artifact name="data:">
|
||||
<root id="root">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/data.txt" />
|
||||
</root>
|
||||
</artifact>
|
||||
<artifact name="data;">
|
||||
<root id="root">
|
||||
<element id="file-copy" path="$PROJECT_DIR$/data.txt" output-file-name="data2.txt"/>
|
||||
</root>
|
||||
</artifact>
|
||||
<artifact name="main">
|
||||
<output-path>$OUTPUT_DIR$/artifacts/main</output-path>
|
||||
<root id="root">
|
||||
<element id="artifact" artifact-name="data:" />
|
||||
<element id="artifact" artifact-name="data;" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/artifactWithoutOutput.iml" filepath="$PROJECT_DIR$/artifactWithoutOutput.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jps
|
||||
|
||||
import org.jetbrains.jps.util.FileUtil
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ArtifactWithoutOutputTest extends JpsBuildTestCase {
|
||||
public void test() throws Exception {
|
||||
def outDir = FileUtil.createTempDirectory("output").absolutePath
|
||||
Project project = loadProject("testData/artifactWithoutOutput/artifactWithoutOutput.ipr", ["OUTPUT_DIR":outDir])
|
||||
project.clean()
|
||||
project.buildArtifact("main")
|
||||
project.deleteTempFiles()
|
||||
assertOutput(project, outDir) {
|
||||
dir("artifacts") {
|
||||
dir("main") {
|
||||
file("data.txt")
|
||||
file("data2.txt")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,17 @@ abstract class JpsBuildTestCase extends TestCase {
|
||||
|
||||
def doTest(String projectPath, Map<String, String> pathVariables, Closure initProject, Closure expectedOutput) {
|
||||
Project project = buildAll(projectPath, pathVariables, initProject)
|
||||
assertOutput(project, project.targetFolder, expectedOutput);
|
||||
}
|
||||
|
||||
def protected assertOutput(Project project, String targetFolder, Closure expectedOutput) {
|
||||
def root = new FileSystemItem(name: "<root>")
|
||||
initFileSystemItem(root, expectedOutput)
|
||||
root.assertDirectoryEqual(new File(project.targetFolder), "");
|
||||
root.assertDirectoryEqual(new File(targetFolder), "")
|
||||
}
|
||||
|
||||
def protected buildAll(String projectPath, Map<String, String> pathVariables, Closure initProject) {
|
||||
def binding = new GantBinding()
|
||||
binding.includeTool << Jps
|
||||
def project = new Project(binding)
|
||||
IdeaProjectLoader.loadFromPath(project, projectPath, pathVariables)
|
||||
Project project = loadProject(projectPath, pathVariables)
|
||||
initProject(project)
|
||||
def target = FileUtil.createTempDirectory("targetDir")
|
||||
project.targetFolder = target.absolutePath
|
||||
@@ -37,6 +37,14 @@ abstract class JpsBuildTestCase extends TestCase {
|
||||
return project
|
||||
}
|
||||
|
||||
protected Project loadProject(String projectPath, Map<String, String> pathVariables) {
|
||||
def binding = new GantBinding()
|
||||
binding.includeTool << Jps
|
||||
def project = new Project(binding)
|
||||
IdeaProjectLoader.loadFromPath(project, projectPath, pathVariables)
|
||||
return project
|
||||
}
|
||||
|
||||
def initFileSystemItem(FileSystemItem item, Closure initializer) {
|
||||
def meta = new InitializingExpando()
|
||||
meta.dir = {String name, Closure content ->
|
||||
|
||||
Reference in New Issue
Block a user