diff --git a/README.md b/README.md index eb4450c7..7d00b6c6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Configure your languages ```groovy xtext { - version = '2.7.2' // the current default, can be omitted + version = '2.8.0' // the current default, can be omitted encoding = 'UTF-8' //the default, can be omitted /* Java sourceDirs are added automatically, diff --git a/build.gradle b/build.gradle index ae4028bf..d231cd6c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,47 +1,54 @@ buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'org.xtend:xtend-gradle-plugin:0.4.3' - classpath 'com.github.oehme.sobula:sobula:0.4.1' - } + repositories { + jcenter() + } + dependencies { + classpath 'org.xtend:xtend-gradle-plugin:0.4.5' + classpath 'com.github.oehme.sobula:sobula:0.4.2' + } +} + +/* + * TODO this weird order is a workaround for a bug in the nebula publishing plugin + * If they don't fix it soon, sobula should be rewritten to work without it. + */ +configure(subprojects.findAll{p-> p.name.contains('plugin')}){ + apply plugin: 'org.xtend.xtend' + apply plugin: 'com.github.oehme.sobula.plugin-release' + apply plugin: 'java-gradle-plugin' + + dependencies { + compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.8.0' + } } subprojects { - apply plugin: 'java' - apply plugin: 'eclipse' - apply plugin: 'com.github.oehme.sobula.bintray-release' - apply plugin: 'com.github.oehme.sobula.stefan' + apply plugin: 'eclipse' + apply plugin: 'java' + + sourceCompatibility = 1.6 +} - group = "org.xtext" - bintray.pkg.name = "$project.group:$project.name" - - contacts { - "xtext@itemis.com" { - moniker "The Xtext team" - roles "owner" - github "xtext" - } - } +allprojects { + apply plugin: 'com.github.oehme.sobula.bintray-release' + + group = "org.xtext" + bintray.pkg.name = "$rootProject.group:$rootProject.name" + + contacts { + "xtext@itemis.com" { + moniker "The Xtext team" + roles "owner" + github "xtext" + } + } - //TODO create bintray and central users - bintray.user = "oehme" - bintray.pkg.version.mavenCentralSync.user = "oehme" - - repositories { + //TODO create bintray and central users + bintray.user = "oehme" + bintray.pkg.version.mavenCentralSync.user = "oehme" + repositories { jcenter() } - - sourceCompatibility = 1.5 } -configure(subprojects.findAll{p-> p.name.contains('plugin')}){ - apply plugin: 'com.github.oehme.sobula.plugin-release' - apply plugin: 'java-gradle-plugin' - apply plugin: 'org.xtend.xtend' - - dependencies { - compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.7.3' - } -} +bintray.publications = [] // don't publish a POM for the root project \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b80df596..6bd4a158 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-bin.zip +distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip diff --git a/settings.gradle b/settings.gradle index fbc16e73..1a162601 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'xtext-gradle-lib', 'xtext-gradle-plugin' \ No newline at end of file +include 'xtext-gradle-lib', 'xtext-gradle-plugin', 'xtext-idea-gradle-plugin' \ No newline at end of file diff --git a/xtext-gradle-lib/build.gradle b/xtext-gradle-lib/build.gradle index bf8925ad..31e0f9f1 100644 --- a/xtext-gradle-lib/build.gradle +++ b/xtext-gradle-lib/build.gradle @@ -1,7 +1,7 @@ description 'A small wrapper for Xtext to make it easier to use from Gradle' dependencies { - compile ("org.eclipse.xtext:org.eclipse.xtext.builder.standalone:[2.5.4,)") { + compile ("org.eclipse.xtext:org.eclipse.xtext.builder.standalone:[2.8.0,)") { exclude group:'asm', module:'asm' } } diff --git a/xtext-gradle-lib/src/main/java/org/xtext/builder/standalone/Main.java b/xtext-gradle-lib/src/main/java/org/xtext/builder/standalone/Main.java index 995b8a6a..5cb5b732 100644 --- a/xtext-gradle-lib/src/main/java/org/xtext/builder/standalone/Main.java +++ b/xtext-gradle-lib/src/main/java/org/xtext/builder/standalone/Main.java @@ -1,7 +1,6 @@ package org.xtext.builder.standalone; import java.io.File; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -12,7 +11,6 @@ import org.eclipse.xtext.builder.standalone.LanguageAccessFactory; import org.eclipse.xtext.builder.standalone.StandaloneBuilder; import org.eclipse.xtext.builder.standalone.StandaloneBuilderModule; -import org.eclipse.xtext.parser.IEncodingProvider; import com.google.common.base.Splitter; import com.google.common.collect.Lists; @@ -28,7 +26,6 @@ public static boolean generate(String[] args) throws Exception { builder.setEncoding("UTF-8"); List sourcePath = Lists.newArrayList(); - File workingDirectory = new File(""); LanguageConfigurationParser languageParser = new LanguageConfigurationParser(); Iterator arguments = Arrays.asList(args).iterator(); @@ -41,7 +38,7 @@ public static boolean generate(String[] args) throws Exception { } else if ("-encoding".equals(argument.trim())) { builder.setEncoding(arguments.next().trim()); } else if ("-cwd".equals(argument.trim())) { - workingDirectory = new File(arguments.next().trim()); + builder.setBaseDir(arguments.next().trim()); } else if (argument.trim().startsWith("-L")) { languageParser.addArgument(argument); } else { @@ -49,23 +46,10 @@ public static boolean generate(String[] args) throws Exception { } } Map languages = new LanguageAccessFactory().createLanguageAccess( - languageParser.getLanguages(), Main.class.getClassLoader(), workingDirectory); - fixEncoding(languages, builder); + languageParser.getLanguages(), Main.class.getClassLoader()); builder.setLanguages(languages); builder.setSourceDirs(sourcePath); - try { - Method javaSourceDirsSetter = StandaloneBuilder.class.getMethod("setJavaSourceDirs", Iterable.class); - javaSourceDirsSetter.invoke(builder, sourcePath); - } catch (Exception ignored) {} + builder.setJavaSourceDirs(sourcePath); return builder.launch(); } - - private static void fixEncoding(Map languages, StandaloneBuilder builder) { - for (LanguageAccess language : languages.values()) { - IEncodingProvider encodingProvider = language.getEncodingProvider(); - if (encodingProvider instanceof IEncodingProvider.Runtime) { - ((IEncodingProvider.Runtime) encodingProvider).setDefaultEncoding(builder.getEncoding()); - } - } - } } diff --git a/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextExtension.xtend b/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextExtension.xtend index 5db1bb91..e9ebfa7a 100644 --- a/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextExtension.xtend +++ b/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextExtension.xtend @@ -11,7 +11,7 @@ import org.gradle.api.tasks.SourceSet import org.gradle.util.ConfigureUtil class XtextExtension { - @Accessors String version = "2.7.2" + @Accessors String version = "2.8.0" @Accessors String encoding = "UTF-8" @Accessors SourceDirectorySet sources @Accessors NamedDomainObjectContainer languages; diff --git a/xtext-idea-gradle-plugin/.gitignore b/xtext-idea-gradle-plugin/.gitignore new file mode 100644 index 00000000..6b73abbb --- /dev/null +++ b/xtext-idea-gradle-plugin/.gitignore @@ -0,0 +1,3 @@ +.settings/ +.project +.classpath \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/build.gradle b/xtext-idea-gradle-plugin/build.gradle new file mode 100644 index 00000000..62571361 --- /dev/null +++ b/xtext-idea-gradle-plugin/build.gradle @@ -0,0 +1,5 @@ +description 'A plugin for for building IntelliJ IDEA Xtext plugins' + +dependencies { + compile 'org.apache.httpcomponents:httpclient:4.4' +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaComponentPlugin.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaComponentPlugin.xtend new file mode 100644 index 00000000..379a5039 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaComponentPlugin.xtend @@ -0,0 +1,55 @@ +package org.xtext.gradle.idea + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.plugins.ide.eclipse.model.Classpath +import org.gradle.plugins.ide.eclipse.model.EclipseModel +import org.gradle.plugins.ide.eclipse.model.Library +import org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory +import org.xtext.gradle.idea.tasks.DownloadIdea + +import static extension org.xtext.gradle.idea.tasks.GradleExtensions.* +import org.gradle.plugins.ide.eclipse.EclipsePlugin + +class IdeaComponentPlugin implements Plugin { + + override apply(Project project) { + project.plugins.apply(IdeaDevelopmentPlugin) + project.plugins.apply(JavaPlugin) + + val compile = project.configurations.getAt("compile") + compile.exclude(#{"module" -> "guava"}) + compile.exclude(#{"module" -> "log4j"}) + + val ideaProvided = project.configurations.create("ideaProvided") + + project.afterEvaluate [ + val downloadTask = project.tasks.getByName("downloadIdea") as DownloadIdea + val ideaHomeDir = downloadTask.ideaHomeDir + + val ideaLibs = project.fileTree(ideaHomeDir + "/lib").builtBy(downloadTask).include("*.jar") + project.dependencies.add(ideaProvided.name, ideaLibs) + project.convention.getPlugin(JavaPluginConvention).sourceSets.forEach [ + compileClasspath = compileClasspath.plus(ideaProvided) + ] + + project.plugins.withType(EclipsePlugin) [ + project.tasks.getByName("eclipseClasspath").dependsOn(downloadTask) + project.extensions.getByType(EclipseModel).classpath => [ + plusConfigurations.add(ideaProvided) + + val fileReferenceFactory = new FileReferenceFactory + file.whenMerged.add [ Classpath it | + val sourceZip = ideaHomeDir / "sources.zip" + entries.filter(Library).filter[library.file.parentFile == ideaHomeDir / 'lib'].forEach [ + sourcePath = fileReferenceFactory.fromFile(sourceZip) + ] + ] + ] + ] + ] + } + +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaDevelopmentPlugin.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaDevelopmentPlugin.xtend new file mode 100644 index 00000000..327939a9 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaDevelopmentPlugin.xtend @@ -0,0 +1,24 @@ +package org.xtext.gradle.idea + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.xtext.gradle.idea.tasks.DownloadIdea +import org.xtext.gradle.idea.tasks.IdeaExtension + +import static extension org.xtext.gradle.idea.tasks.GradleExtensions.* + +class IdeaDevelopmentPlugin implements Plugin { + + override apply(Project project) { + val idea = project.extensions.create("ideaDevelopment", IdeaExtension) => [ + ideaHome = project.rootDir / "ideaHome" + ideaVersion = "140.2683.2" + sandboxDir = project.rootProject.buildDir / "ideaSandbox" + ] + val downloadTask = project.tasks.create("downloadIdea", DownloadIdea) + project.afterEvaluate [ + downloadTask.ideaHome = idea.ideaHome + downloadTask.ideaVersion = idea.ideaVersion + ] + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaPluginPlugin.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaPluginPlugin.xtend new file mode 100644 index 00000000..541d869a --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaPluginPlugin.xtend @@ -0,0 +1,36 @@ +package org.xtext.gradle.idea + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginConvention +import org.xtext.gradle.idea.tasks.AssembleSandbox +import org.xtext.gradle.idea.tasks.IdeaExtension +import org.xtext.gradle.idea.tasks.IdeaZip + +import static extension org.xtext.gradle.idea.tasks.GradleExtensions.* +import org.gradle.api.Action +import org.xtext.gradle.idea.tasks.IdeaPluginSpec + +class IdeaPluginPlugin implements Plugin { + override apply(Project project) { + project.plugins.apply(IdeaComponentPlugin) + val idea = project.extensions.getByType(IdeaExtension) + val mainSourceSet = project.convention.getPlugin(JavaPluginConvention).sourceSets.getByName("main") + val providedDependencies = project.configurations.getAt("ideaProvided") + val runtimeDependencies = project.configurations.getAt("runtime") + + val Action archiveConfig = [ + classes.from(mainSourceSet.output) + libraries.from(runtimeDependencies.minus(providedDependencies)) + metaInf.from("META-INF") + ] + + project.tasks.create("ideaZip", IdeaZip, archiveConfig) + + val assembleSandboxTask = project.tasks.create("assembleSandbox", AssembleSandbox, archiveConfig) + + project.afterEvaluate [ + assembleSandboxTask.destinationDir = project.file(idea.sandboxDir) / project.name + ] + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaRepositoryPlugin.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaRepositoryPlugin.xtend new file mode 100644 index 00000000..fefc2c38 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/IdeaRepositoryPlugin.xtend @@ -0,0 +1,39 @@ +package org.xtext.gradle.idea + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.xtext.gradle.idea.tasks.AssembleSandbox +import org.xtext.gradle.idea.tasks.DownloadIdea +import org.xtext.gradle.idea.tasks.IdeaExtension +import org.xtext.gradle.idea.tasks.IdeaRepository +import org.xtext.gradle.idea.tasks.IdeaZip +import org.xtext.gradle.idea.tasks.RunIdea + +import static extension org.xtext.gradle.idea.tasks.GradleExtensions.* + +class IdeaRepositoryPlugin implements Plugin { + + override apply(Project project) { + project.plugins.apply(IdeaDevelopmentPlugin) + val idea = project.extensions.getByType(IdeaExtension) + val repositoryTask = project.tasks.create("ideaRepository", IdeaRepository) [ + into(project.buildDir / 'ideaRepository') + ] + project.allprojects [ + tasks.withType(IdeaZip) [ zip | + repositoryTask.from(zip) + ] + ] + val runIdea = project.tasks.create("runIdea", RunIdea) + val downloadTask = project.tasks.getAt("downloadIdea") as DownloadIdea + project.afterEvaluate [ + val ideaLibs = project.fileTree(downloadTask.ideaHomeDir + "/lib") + ideaLibs.builtBy(downloadTask).include("*.jar") + subprojects.map[tasks.withType(AssembleSandbox)].flatten.forEach[runIdea.dependsOn(it)] + runIdea.sandboxDir = project.file(idea.sandboxDir) + runIdea.ideaHome = project.file(idea.ideaHome) + val tools = project.files('''«System.getenv("JAVA_HOME")»/lib/tools.jar''') + runIdea.classpath = ideaLibs.plus(tools) + ] + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/AssembleSandbox.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/AssembleSandbox.xtend new file mode 100644 index 00000000..5e687582 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/AssembleSandbox.xtend @@ -0,0 +1,18 @@ +package org.xtext.gradle.idea.tasks + +import org.eclipse.xtend.lib.annotations.Accessors +import org.gradle.api.file.CopySpec +import org.gradle.api.tasks.Sync + +@Accessors +class AssembleSandbox extends Sync implements IdeaPluginSpec { + CopySpec classes + CopySpec libraries + CopySpec metaInf + + new() { + classes = rootSpec.addChild.into("classes") + libraries = rootSpec.addChild.into("lib") + metaInf = rootSpec.addChild.into("META-INF") + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/DownloadIdea.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/DownloadIdea.xtend new file mode 100644 index 00000000..c840da7f --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/DownloadIdea.xtend @@ -0,0 +1,137 @@ +package org.xtext.gradle.idea.tasks + +import java.io.File +import java.net.URL +import java.nio.file.Files +import java.util.regex.Pattern +import org.apache.http.client.methods.HttpGet +import org.apache.http.impl.client.DefaultHttpClient +import org.apache.http.util.EntityUtils +import org.eclipse.xtend.lib.annotations.Accessors +import org.eclipse.xtend.lib.annotations.Data +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import org.gradle.internal.os.OperatingSystem + +import static extension org.xtext.gradle.idea.tasks.GradleExtensions.* +import org.gradle.api.file.FileCopyDetails +import com.google.common.base.Splitter + +@Accessors +class DownloadIdea extends DefaultTask { + static val os = OperatingSystem.current + + Object ideaHome + @Input String ideaVersion + + new() { + onlyIf[(ideaHomeDir.list?.toList ?: #[]).size < 3] + } + + @TaskAction + def download() { + val buildInfo = queryBuildInfo + val archiveFile = new File(ideaHomeDir, buildInfo.archiveName) + if (!archiveFile.exists) { + Files.copy(new URL(buildInfo.archiveUrl).openStream, archiveFile.toPath) + } + val sourceArchiveFile = new File(ideaHomeDir, buildInfo.sourceArchiveName) + if (!sourceArchiveFile.exists) { + Files.copy(new URL(buildInfo.sourceArchiveUrl).openStream, sourceArchiveFile.toPath) + } + project.copy [ + into(ideaHomeDir) + if (os.isLinux) { + from(project.tarTree(archiveFile)) + eachFile[cutDirs(1)] + } else { + from(project.zipTree(archiveFile)) + if (os.isMacOsX) { + eachFile[cutDirs(2)] + } + } + ] + } + + @OutputDirectory + def getIdeaHomeDir() { + project.file(ideaHome) + } + + def queryBuildInfo() { + val buildApiUrl = "https://teamcity.jetbrains.com/guestAuth/app/rest/builds" + + val buildLocator = '''buildType:bt410,status:SUCCESS,branch:idea/«ideaVersion»''' + val buildIdRequestUrl = '''«buildApiUrl»/?locator=«buildLocator»''' + val buildId = httpGet(buildIdRequestUrl) [ response | + val pattern = Pattern.compile('^(.*)\\sid="(\\d+)"(.*)$') + val matcher = pattern.matcher(response) + matcher.find + matcher.group(2) + ] + + val buildUrl = '''«buildApiUrl»/id:«buildId»''' + + val buildNumberRequestUrl = '''«buildUrl»/artifacts/children''' + val buildNumber = httpGet(buildNumberRequestUrl) [ response | + val pattern = Pattern.compile('^(.*)ideaIC-([\\w\\.]+)\\.win\\.zip(.*)$') + val matcher = pattern.matcher(response) + matcher.find + matcher.group(2) + ] + val archiveName = '''ideaIC-«buildNumber».«os.archiveExtension»''' + + val contentBaseUrl = '''«buildUrl»/artifacts/content''' + new IdeaBuildInfo(ideaVersion, buildId, buildUrl, buildNumber, contentBaseUrl, archiveName) + } + + def httpGet(String url, (String)=>String responseHandler) { + val client = new DefaultHttpClient() + val request = new HttpGet(url) + val result = try { + val response = EntityUtils.toString(client.execute(request).entity) + responseHandler.apply(response) + } finally { + request.releaseConnection + } + result + } + + def archiveExtension(OperatingSystem os) { + if (os.isWindows) { + "win.zip" + } else if (os.isMacOsX) { + "mac.zip" + } else { + "tar.gz" + } + } + + def cutDirs(FileCopyDetails file, int levels) { + val segments = Splitter.on('/').omitEmptyStrings.split(file.path) + file.path = segments.drop(levels).join('/') + } +} + +@Data class IdeaBuildInfo { + String version + String buildId + String buildUrl + String buildNumber + String contentBaseUrl + String archiveName + + def String getArchiveUrl() { + '''«contentBaseUrl»/«archiveName»''' + } + + def String getSourceArchiveName() { + "sources.zip" + } + + def String getSourceArchiveUrl() { + '''«contentBaseUrl»/«sourceArchiveName»''' + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/GradleExtensions.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/GradleExtensions.xtend new file mode 100644 index 00000000..15dbeb3b --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/GradleExtensions.xtend @@ -0,0 +1,25 @@ +package org.xtext.gradle.idea.tasks + +import groovy.lang.Closure +import org.gradle.api.Project +import org.gradle.api.file.CopySpec +import java.io.File + +class GradleExtensions { + static def copy(Project project, (CopySpec)=>void copyspec) { + project.copy(new Closure(null) { + override getMaximumNumberOfParameters() { + 1 + } + + override call(Object argument) { + copyspec.apply(argument as CopySpec) + null + } + }) + } + + static def /(File parent, String child) { + new File(parent, child) + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaExtension.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaExtension.xtend new file mode 100644 index 00000000..438209b0 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaExtension.xtend @@ -0,0 +1,10 @@ +package org.xtext.gradle.idea.tasks + +import org.eclipse.xtend.lib.annotations.Accessors + +@Accessors +class IdeaExtension { + Object ideaHome + String ideaVersion + Object sandboxDir +} diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaPluginSpec.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaPluginSpec.xtend new file mode 100644 index 00000000..a42639f3 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaPluginSpec.xtend @@ -0,0 +1,9 @@ +package org.xtext.gradle.idea.tasks + +import org.gradle.api.file.CopySpec + +interface IdeaPluginSpec { + def CopySpec getClasses() + def CopySpec getLibraries() + def CopySpec getMetaInf() +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaRepository.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaRepository.xtend new file mode 100644 index 00000000..f9880954 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaRepository.xtend @@ -0,0 +1,34 @@ +package org.xtext.gradle.idea.tasks + +import com.google.common.base.Charsets +import com.google.common.io.Files +import java.io.File +import org.gradle.api.tasks.Sync +import org.gradle.api.tasks.Input +import org.eclipse.xtend.lib.annotations.Accessors + +class IdeaRepository extends Sync { + @Input @Accessors String rootUrl + + val files = newArrayList + + new() { + rootSpec.eachFile[files.add(file)] + } + + override protected copy() { + super.copy() + val pluginDescriptor = new File(destinationDir, "updatePlugins.xml") + Files.write(''' + + «FOR it : files» + + «ENDFOR» + + ''', pluginDescriptor, Charsets.UTF_8) + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaZip.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaZip.xtend new file mode 100644 index 00000000..fda4e1bf --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/IdeaZip.xtend @@ -0,0 +1,19 @@ +package org.xtext.gradle.idea.tasks + +import org.eclipse.xtend.lib.annotations.Accessors +import org.gradle.api.file.CopySpec +import org.gradle.api.tasks.bundling.Zip + +@Accessors(PUBLIC_GETTER) +class IdeaZip extends Zip implements IdeaPluginSpec { + CopySpec classes + CopySpec libraries + CopySpec metaInf + + new() { + rootSpec.into(project.name) + classes = rootSpec.addChild.into("classes") + libraries = rootSpec.addChild.into("lib") + metaInf = rootSpec.addChild.into("META-INF") + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/RunIdea.xtend b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/RunIdea.xtend new file mode 100644 index 00000000..48308f33 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/java/org/xtext/gradle/idea/tasks/RunIdea.xtend @@ -0,0 +1,39 @@ +package org.xtext.gradle.idea.tasks + +import com.google.common.base.Splitter +import com.google.common.collect.Lists +import java.io.File +import java.util.List +import org.eclipse.xtend.lib.annotations.Accessors +import org.gradle.api.internal.tasks.options.Option +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.JavaExec + +@Accessors +class RunIdea extends JavaExec { + @Input File sandboxDir + @Input File ideaHome + @Input List pluginsToRun = Lists.newArrayList + + new() { + main = "com.intellij.idea.Main" + maxHeapSize = "2G" + jvmArgs("-XX:MaxPermSize=512m") + } + + override getJvmArgs() { + val args = Lists.newArrayList(super.jvmArgs) + args += '''-Didea.home.path=«ideaHome»''' + if (pluginsToRun.isEmpty) { + args += '''-Didea.plugins.path=«sandboxDir»''' + } else { + args += '''-Dplugin.path=«pluginsToRun.join(',')[new File(sandboxDir, it).path]»''' + } + args + } + + @Option(option="ideaPlugins", description="A comma-separated list of the IDs of the plugins to activate. By default, all plugins in the sandbox are activated") + def setPluginsToRun(String pluginsToRun) { + this.pluginsToRun = Splitter.on(',').trimResults.omitEmptyStrings.split(pluginsToRun).toList + } +} \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-component.properties b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-component.properties new file mode 100644 index 00000000..e93f5500 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-component.properties @@ -0,0 +1 @@ +implementation-class=org.xtext.gradle.idea.IdeaComponentPlugin \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-dev.properties b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-dev.properties new file mode 100644 index 00000000..32bb8969 --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-dev.properties @@ -0,0 +1 @@ +implementation-class=org.xtext.gradle.idea.IdeaDevelopmentPlugin \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-plugin.properties b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-plugin.properties new file mode 100644 index 00000000..f9b7da4d --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-plugin.properties @@ -0,0 +1 @@ +implementation-class=org.xtext.gradle.idea.IdeaPluginPlugin \ No newline at end of file diff --git a/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-repository.properties b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-repository.properties new file mode 100644 index 00000000..d5af8d2c --- /dev/null +++ b/xtext-idea-gradle-plugin/src/main/resources/META-INF/gradle-plugins/org.xtext.idea-repository.properties @@ -0,0 +1 @@ +implementation-class=org.xtext.gradle.idea.IdeaRepositoryPlugin \ No newline at end of file