import org.gradle.internal.os.OperatingSystem
import org.gradle.plugins.ide.eclipse.model.*
import groovy.transform.ExternalizeMethods
-import org.eclipse.osgi.*
+//import org.eclipse.osgi.*
+import com.diffplug.gradle.GoomphCacheLocations
/*
buildscript {
+
+
+
+
+
+
+
+
+
+
+
+
+
+GoomphCacheLocations.override_workspaces = file(jalviewDirAbsolutePath+"/"+goomph_workspace)
oomphIde {
repoEclipse goomph_eclipse_version
jdt {
-def tempEclipseWorkspace = ""
+def jalviewjsBuildDir
+def jalviewjsSiteDir
+task jalviewjsSitePath {
+ if (jalviewjs_site_dir.startsWith("/")) {
+ jalviewjsSiteDir = jalviewjs_site_dir
+ } else {
+ def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
+ jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs"
+ jalviewjsSiteDir = jalviewjsBuildDir + "/" + jalviewjs_site_dir
+ }
+}
+
+def tempEclipseWorkspace
task jalviewjsSetTempEclipseWorkspace {
tempEclipseWorkspace = file(jalviewjs_eclipse_workspace)
if (!tempEclipseWorkspace.exists()) {
- tempEclipseWorkspace = File.createTempDir()
- tempEclipseWorkspace.deleteOnExit()
+ tempEclipseWorkspace = file("${buildDir}/tmp/eclipse-workspace")
+ //tempEclipseWorkspace.deleteOnExit()
}
println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath())
}
task jalviewjsUnzipFiles {
+ dependsOn jalviewjsSitePath
+
def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip")
zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip
zipFiles.each { file_zip ->
copy {
from zipTree(file_zip)
- into jalviewjs_site_dir
+ into jalviewjsSiteDir
}
}
}
inputs.files zipFiles
- outputs.dir jalviewjs_site_dir
+ outputs.dir jalviewjsSiteDir
}
-def eclipseBinary
def eclipseDropinsDir
-def eclipsePluginsDir
+def eclipseBinary
task jalviewjsEclipsePaths {
def eclipseRoot = jalviewjs_eclipse_root
if (eclipseRoot.startsWith("~")) {
if (OperatingSystem.current().isMacOsX()) {
eclipseRoot += "/Eclipse.app"
eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins"
- eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins"
eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse"
} else if (OperatingSystem.current().isWindows()) { // check these paths!!
eclipseDropinsDir = eclipseRoot+"/dropins"
- eclipsePluginsDir = eclipseRoot+"/plugins"
eclipseBinary = eclipseRoot+"/eclipse"
} else { // linux or unix
eclipseDropinsDir = eclipseRoot+"/dropins"
- eclipsePluginsDir = eclipseRoot+"/plugins"
eclipseBinary = eclipseRoot+"/eclipse"
}
- println("ECLIPSE ROOT: "+eclipseRoot)
}
task jalviewjsEclipseCopyDropins (type: Copy) {
inputs.files inputFiles
}
-task jalviewjsEclipseCopyPlugins (type: Copy) {
- dependsOn jalviewjsEclipsePaths
- def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir)
- def outputDir = eclipsePluginsDir
-
- from inputFiles
- into outputDir
- def outputFiles = []
- rename { filename ->
- outputFiles += outputDir+"/"+filename
- null
- }
- outputs.files outputFiles
- inputs.files inputFiles
-}
-
task jalviewjsEclipseSetup {
dependsOn jalviewjsEclipseCopyDropins
- dependsOn jalviewjsEclipseCopyPlugins
dependsOn jalviewjsSetTempEclipseWorkspace
}
task jalviewjsCreateJ2sSettings(type: WriteProperties) {
+ dependsOn jalviewjsSitePath
outputFile (jalviewDir+"/"+jalviewjs_j2s_settings)
def props = project.properties.sort { it.key }
+ def siteDirProperty = "j2s.site.directory"
+ def setSiteDir = false
props.each { prop, val ->
if (prop.startsWith("j2s.") && val != null) {
+ if (prop == siteDirProperty) {
+ if (!(val.startsWith("/") || val.startsWith("file://") )) {
+ val = jalviewjsSiteDir+"/"+val
+ }
+ setSiteDir = true
+ }
property(prop,val)
}
+ if (!setSiteDir) {
+ property(siteDirProperty,"${jalviewjsSiteDir}")
+ }
}
outputs.file(outputFile)
}
task jalviewjsCopyResources (type: Copy) {
+ dependsOn jalviewjsSitePath
def inputFiles = fileTree(dir: jalviewjs_resource_dir)
- def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir
+ def outputDir = jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir
from inputFiles
into outputDir
}
task jalviewjsCopySiteResources (type: Copy) {
+ dependsOn jalviewjsSitePath
def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir)
- def outputDir = jalviewjs_site_dir
+ def outputDir = jalviewjsSiteDir
from inputFiles
into outputDir
}
task cleanJalviewjs {
+ dependsOn jalviewjsSitePath
/*
- delete jalviewDir+"/"+jalviewjs_site_dir
+ delete jalviewDir+"/"+jalviewjsSiteDir
delete jalviewDir+"/"+eclipse_bin_dir
delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata")
delete jalviewDir+"/"+jalviewjs_j2s_settings
executable(eclipseBinary)
args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
- def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/"
+ def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
inputs.file(jalviewDir+"/.project")
outputs.dir(projdir)
+ outputs.upToDateWhen { file(projdir).exists() }
}
+
+
+
+
+
+
+
task jalviewjsTranspile(type: Exec) {
dependsOn jalviewjsCreateJ2sSettings
dependsOn jalviewjsProjectImport
dependsOn jalviewjsEclipsePaths
executable(eclipseBinary)
args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ])
+
+ def stdout
+ def stderr
+ doFirst {
+ stdout = new ByteArrayOutputStream()
+ stderr = new ByteArrayOutputStream()
+ standardOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"), stdout);
+ errorOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"), stderr);
+ }
+ doLast {
+ if (stdout.toString().contains("Error processing ")) {
+ // j2s did not complete transpile
+ throw new TaskExecutionException("Error during transpilation:\n${stderr}\n")
+ }
+ }
+
inputs.dir(sourceDir)
outputs.dir(eclipse_bin_dir+"/main")
- outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class")
- outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir)
+ outputs.dir(jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir)
+ outputs.file(jalviewjsSiteDir+jalviewjs_server_resource)
+ outputs.upToDateWhen { file(jalviewjsSiteDir+jalviewjs_server_resource).exists() }
+
}
+
+
+
+
+
+
+
task jalviewjsBuildSite {
+ dependsOn jalviewjsSitePath
dependsOn jalviewjsUnzipFiles
dependsOn jalviewjsCopyResources
dependsOn jalviewjsCopySiteResources
compression Compression.GZIP
- from jalviewjs_site_dir
+ from jalviewjsSiteDir
into jalviewjs_site_dir // this is inside the tar file
- inputs.dir(jalviewjs_site_dir)
+ inputs.dir(jalviewjsSiteDir)
}
task jalviewjs {
def jalviewjsServer = null
task jalviewjsServerStart {
+ dependsOn jalviewjsSitePath
doLast {
if (jalviewjsServer != null) {
def running = false
while(port < start+1000 && !running) {
try {
- jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port)
+ def doc_root = new File(jalviewDirAbsolutePath +"/"+ jalviewjsSiteDir)
+ jalviewjsServer = factory.start(doc_root, port)
running = true
- println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
+ println("SERVER STARTED with document root ${doc_root}.\nGo to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.")
//println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000);
} catch (Exception e) {
port++;