mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no lazy initialization in jps
This commit is contained in:
@@ -112,10 +112,9 @@ binding.setVariable("guessHome", {
|
||||
binding.setVariable("loadProject", {
|
||||
requireProperty("jdkHome", requireProperty("jdk16.home", guessJdk()))
|
||||
def mac = isMac()
|
||||
jdk("IDEA jdk", jdkHome) {
|
||||
if (!mac) {
|
||||
classpath "$jdkHome/lib/tools.jar"
|
||||
}
|
||||
def sdk = jdk("IDEA jdk", jdkHome) { }
|
||||
if (!mac) {
|
||||
sdk.addClaspath "$jdkHome/lib/tools.jar"
|
||||
}
|
||||
IdeaProjectLoader.loadFromPath(project, "${home}")
|
||||
})
|
||||
|
||||
+7
-11
@@ -10,19 +10,15 @@ def gantHome = GANT_HOME
|
||||
|
||||
projectBuilder.targetFolder = "${projectHome}/build"
|
||||
|
||||
library("ANT") {
|
||||
classpath "$libs/ant-1.7.1.jar"
|
||||
library("ANT") {}.addClasspath("$libs/ant-1.7.1.jar")
|
||||
|
||||
library("groovy") {}.addClasspath("$libs/groovy-all-1.7.1.jar")
|
||||
|
||||
def gantLib = library("gant") {}
|
||||
new File("$gantHome/lib").eachFile {
|
||||
gantLib.addClasspath it
|
||||
}
|
||||
|
||||
library("groovy") {
|
||||
classpath "$libs/groovy-all-1.7.1.jar"
|
||||
}
|
||||
|
||||
library("gant") {
|
||||
new File("$gantHome/lib").eachFile {
|
||||
classpath it
|
||||
}
|
||||
}
|
||||
|
||||
module("JPS") {
|
||||
targetLevel ="1.5"
|
||||
|
||||
-2
@@ -130,7 +130,6 @@ public abstract class ArtifactBuilderTestCase extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
final Module module = myProject.createModule(moduleName, Closure.IDENTITY);
|
||||
module.forceInit();
|
||||
module.setSdk(myJdk);
|
||||
module.addDependency(myJdk, PredefinedDependencyScopes.getCOMPILE(), false);
|
||||
if (srcPaths.length > 0) {
|
||||
@@ -145,7 +144,6 @@ public abstract class ArtifactBuilderTestCase extends UsefulTestCase {
|
||||
|
||||
protected Library addProjectLibrary(String name, String jarPath) {
|
||||
final Library library = myProject.createLibrary(name, Closure.IDENTITY);
|
||||
library.forceInit();
|
||||
library.getClasspath().add(jarPath);
|
||||
return library;
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package org.jetbrains.jps
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
class LazyInitializeableObject {
|
||||
private Intializing initializer
|
||||
|
||||
def setInitializer(Closure init) {
|
||||
def meta = ProxyMetaClass.getInstance(getClass())
|
||||
initializer = new Intializing(initializer: init)
|
||||
meta.setInterceptor(initializer)
|
||||
setMetaClass(meta)
|
||||
}
|
||||
|
||||
def forceInit () {
|
||||
if (initializer != null) initializer.init()
|
||||
}
|
||||
}
|
||||
|
||||
private class Intializing implements PropertyAccessInterceptor {
|
||||
private Closure initializer
|
||||
|
||||
Object beforeInvoke(Object object, String methodName, Object[] arguments) {
|
||||
init()
|
||||
}
|
||||
|
||||
Object afterInvoke(Object object, String methodName, Object[] arguments, Object result) {
|
||||
return result
|
||||
}
|
||||
|
||||
Object beforeGet(Object object, String property) {
|
||||
init()
|
||||
}
|
||||
|
||||
void beforeSet(Object object, String property, Object newValue) {
|
||||
init()
|
||||
}
|
||||
|
||||
boolean doInvoke() {
|
||||
true
|
||||
}
|
||||
|
||||
def init() {
|
||||
if (initializer == null) return
|
||||
def i = initializer
|
||||
initializer = null
|
||||
i.call()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
class Library extends LazyInitializeableObject implements ClasspathItem {
|
||||
class Library implements ClasspathItem {
|
||||
Project project;
|
||||
String name;
|
||||
|
||||
@@ -14,42 +14,17 @@ class Library extends LazyInitializeableObject implements ClasspathItem {
|
||||
|
||||
private Map<String, Object> props = [:]
|
||||
|
||||
def Library(project, name, initializer) {
|
||||
this(project, name, false, initializer)
|
||||
}
|
||||
|
||||
def Library(project, name, forceInitialization, initializer) {
|
||||
def Library(project, name) {
|
||||
this.project = project;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Closure lazyInit = {
|
||||
def meta = new InitializingExpando()
|
||||
meta.classpath = {Object[] arg ->
|
||||
arg.each { classpath << FileUtil.toCanonicalPath(it.toString()) }
|
||||
}
|
||||
void addClasspath(Object[] arg) {
|
||||
arg.each { classpath << FileUtil.toCanonicalPath(it.toString()) }
|
||||
}
|
||||
|
||||
meta.src = {Object[] arg ->
|
||||
arg.each { sourceRoots << FileUtil.toCanonicalPath(it.toString()) }
|
||||
}
|
||||
|
||||
initializer.delegate = meta
|
||||
initializer.setResolveStrategy Closure.DELEGATE_FIRST
|
||||
initializer.call()
|
||||
|
||||
def wrongProperties = ["classpath", "src"] as Set
|
||||
meta.getProperties().each {String key, Object value ->
|
||||
if (!wrongProperties.contains(key)) {
|
||||
props[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forceInitialization) {
|
||||
lazyInit.call()
|
||||
}
|
||||
else {
|
||||
setInitializer(lazyInit)
|
||||
}
|
||||
void src(Object[] arg) {
|
||||
arg.each { sourceRoots << FileUtil.toCanonicalPath(it.toString()) }
|
||||
}
|
||||
|
||||
def String toString() {
|
||||
@@ -57,7 +32,6 @@ class Library extends LazyInitializeableObject implements ClasspathItem {
|
||||
}
|
||||
|
||||
def List<String> getClasspathRoots(ClasspathKind kind) {
|
||||
forceInit()
|
||||
classpath
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.TestOnly
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
class Module extends LazyInitializeableObject implements ClasspathItem {//}, Comparable {
|
||||
class Module implements ClasspathItem {//}, Comparable {
|
||||
Project project;
|
||||
String name;
|
||||
Sdk sdk;
|
||||
@@ -109,7 +109,6 @@ class Module extends LazyInitializeableObject implements ClasspathItem {//}, Com
|
||||
}
|
||||
|
||||
def List<ClasspathItem> getClasspath(ClasspathKind kind, boolean exportedOnly) {
|
||||
forceInit()
|
||||
return dependencies.findAll({it.scope.isIncludedIn(kind) && (!exportedOnly || it.exported)})*.item;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class Project {
|
||||
}
|
||||
|
||||
protected def Library createLibrary(String name, Closure initializer, Map<String, Library> libraries, String accessor) {
|
||||
Library lib = new Library(this, name, initializer)
|
||||
Library lib = new Library(this, name)
|
||||
libraries.put(name, lib)
|
||||
lib
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ package org.jetbrains.jps
|
||||
*/
|
||||
class Sdk extends Library {
|
||||
Sdk(project, name, initializer) {
|
||||
super(project, name, true, initializer);
|
||||
super(project, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,8 +329,8 @@ public class IdeaProjectLoader {
|
||||
}
|
||||
|
||||
private NodeList loadProjectLibraries(Node librariesComponent) {
|
||||
return librariesComponent?.library?.each {Node libTag ->
|
||||
project.createLibrary(libTag."@name", libraryInitializer(libTag, projectMacroExpander))
|
||||
return (NodeList)librariesComponent?.library?.each {Node libTag ->
|
||||
initLibrary(libTag, projectMacroExpander, project.createLibrary(libTag."@name", Closure.IDENTITY))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,11 +378,10 @@ public class IdeaProjectLoader {
|
||||
}
|
||||
|
||||
private Library loadLibrary(Project project, String name, Node libraryTag, MacroExpander macroExpander) {
|
||||
return new Library(project, name, true, libraryInitializer(libraryTag, macroExpander))
|
||||
return initLibrary(new Library(project, name))
|
||||
}
|
||||
|
||||
private Closure libraryInitializer(Node libraryTag, MacroExpander macroExpander) {
|
||||
return {
|
||||
private Library initLibrary(Node libraryTag, MacroExpander macroExpander, Library library) {
|
||||
Map<String, Boolean> jarDirs = [:]
|
||||
libraryTag.jarDirectory.each {Node dirNode ->
|
||||
jarDirs[dirNode.@url] = Boolean.parseBoolean(dirNode.@recursive)
|
||||
@@ -395,18 +394,18 @@ public class IdeaProjectLoader {
|
||||
def paths = []
|
||||
collectChildJars(path, jarDirs[url], paths)
|
||||
paths.each {
|
||||
classpath it
|
||||
library.addClasspath it
|
||||
}
|
||||
}
|
||||
else {
|
||||
classpath path
|
||||
library.addClasspath path
|
||||
}
|
||||
}
|
||||
|
||||
libraryTag.SOURCES.root.each {Node rootTag ->
|
||||
src macroExpander.expandMacros(rootTag.@url)
|
||||
library.src macroExpander.expandMacros(rootTag.@url)
|
||||
}
|
||||
}
|
||||
return library
|
||||
}
|
||||
|
||||
private def collectChildJars(String path, boolean recursively, List<String> paths) {
|
||||
|
||||
@@ -20,10 +20,6 @@ final class Jps {
|
||||
return project.createLibrary(name, initializer)
|
||||
})
|
||||
|
||||
binding.setVariable("globalLibrary", {String name, Closure initializer ->
|
||||
return project.createGlobalLibrary(name, initializer)
|
||||
})
|
||||
|
||||
binding.setVariable("jdk", {Object[] args ->
|
||||
if (!(args.length in [2,3])) {
|
||||
projectBuilder.error("expected 2 to 3 parameters for jdk() but ${args.length} found")
|
||||
|
||||
@@ -15,9 +15,7 @@ class BuildFromIdeaProjectTest extends JpsBuildTestCase {
|
||||
|
||||
private Closure getGlobalLib() {
|
||||
return {Project project, ProjectBuilder projectBuilder ->
|
||||
project.createGlobalLibrary("jdom") {
|
||||
classpath "testData/iprProject/lib/jdom.jar"
|
||||
}
|
||||
project.createGlobalLibrary("jdom") { }.addClasspath("testData/iprProject/lib/jdom.jar")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,8 @@ public class ModuleClasspathTest extends JpsBuildTestCase {
|
||||
protected void setUp() {
|
||||
super.setUp()
|
||||
project = loadProject(getProjectPath(), [:], {Project project ->
|
||||
project.createJavaSdk("1.6", "jdk16") {
|
||||
classpath "/jdk.jar"
|
||||
}
|
||||
project.createJavaSdk("1.5", "jdk15") {
|
||||
classpath "/jdk15.jar"
|
||||
}
|
||||
project.createJavaSdk("1.6", "jdk16") { }.addClasspath("/jdk.jar")
|
||||
project.createJavaSdk("1.5", "jdk15") { }.addClasspath("/jdk15.jar")
|
||||
})
|
||||
builder = createBuilder(project)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user