configurations{
	mergedViewerDependencies
    compile.extendsFrom(mergedViewerDependencies)
}

dependencies {
	
	mergedViewerDependencies 'org.dpolivaev.mnemonicsetter:mnemonicsetter:0.6'
	lib ':kitfox-svg-salamander-1.1.1-p1'
	lib 'com.github.robtimus:data-url:1.0.1'
	lib 'com.bulenkov:darcula:2018.2'

    lib project(':JOrtho_0.4_freeplane')
    compile project(':freeplane_api')
	
    lib 'commons-lang:commons-lang:2.6',
            'commons-io:commons-io:2.4',
            'commons-codec:commons-codec:1.8',
            'com.jgoodies:jgoodies-forms:1.9.0',
            'com.jgoodies:jgoodies-common:1.8.1'

	lib  ('com.lightdev.app.shtm.simplyhtml:SimplyHTML:0.17.3') {
		exclude module: 'javahelp'
		exclude module: 'mnemonicsetter'
	}
    
 	testRuntime files('src/viewer/resources', 'src/editor/resources', 'src/external/resources')

    // from flatDir "localGitDepsRepository":
    lib ':idw-gpl-1.6.1'
}

sourceSets {
    viewer {}
    editor {}
    external {}
}

// work around for new gradle bug if subproject name equals to root dir name
eclipse {
  project {
    name = 'freeplane'
	}
}

ext.bundleDeps = configurations.lib.files.collect {
    externalizeJar(it)
}
bundleDeps.add(0, "lib/freeplaneosgi-${project.version}.jar")
// this is built from :freeplane_mac on a Mac!
bundleDeps.add(0, "lib/freeplane_mac-${project.version}.jar")
bundleDeps.add(0, "lib/freeplaneeditor-${project.version}.jar")
bundleDeps.add(0, "lib/freeplaneviewer.jar")

ext.bundleExports = """\
                    com.inet.jortho,
                    org.freeplane.api,
                    org.freeplane.core.extension,
                    org.freeplane.core.io,
                    org.freeplane.core.io.xml,
                    org.freeplane.core.resources,
                    org.freeplane.core.resources.components,
                    org.freeplane.core.ui,
                    org.freeplane.core.ui.components,
                    org.freeplane.core.ui.components.calendar,
                    org.freeplane.core.ui.components.html,
                    org.freeplane.core.ui.components.resizer,
                    org.freeplane.core.ui.textchanger,
                    org.freeplane.core.ui.menubuilders,
        			org.freeplane.core.ui.menubuilders.action,
					org.freeplane.core.ui.menubuilders.generic,
					org.freeplane.core.ui.menubuilders.menu,
                    org.freeplane.core.undo,
                    org.freeplane.core.util,
                    org.freeplane.core.util.collection,
                    org.freeplane.core.util.logging,
                    org.freeplane.features.attribute,
                    org.freeplane.features.attribute.mindmapmode,
                    org.freeplane.features.clipboard,
                    org.freeplane.features.clipboard.mindmapmode,
                    org.freeplane.features.cloud,
                    org.freeplane.features.cloud.mindmapmode,
                    org.freeplane.features.edge,
                    org.freeplane.features.edge.mindmapmode,
                    org.freeplane.features.encrypt,
                    org.freeplane.features.encrypt.mindmapmode,
        			org.freeplane.features.explorer,
        			org.freeplane.features.explorer.mindmapmode,
                    org.freeplane.features.export.mindmapmode,
                    org.freeplane.features.filter,
                    org.freeplane.features.filter.condition,
                    org.freeplane.features.format,
                    org.freeplane.features.help,
                    org.freeplane.features.icon,
                    org.freeplane.features.icon.factory,
                    org.freeplane.features.icon.mindmapmode,
                    org.freeplane.features.link,
                    org.freeplane.features.link.mindmapmode,
                    org.freeplane.features.map,
                    org.freeplane.features.map.clipboard,
                    org.freeplane.features.map.filemode,
                    org.freeplane.features.map.mindmapmode,
                    org.freeplane.features.map.mindmapmode.clipboard,
                    org.freeplane.features.mapio,
                    org.freeplane.features.mapio.mindmapmode,
                    org.freeplane.features.mode,
                    org.freeplane.features.mode.browsemode,
                    org.freeplane.features.mode.filemode,
                    org.freeplane.features.mode.mindmapmode,
                    org.freeplane.features.nodelocation,
                    org.freeplane.features.nodelocation.mindmapmode,
                    org.freeplane.features.nodestyle,
                    org.freeplane.features.nodestyle.filemode,
                    org.freeplane.features.nodestyle.mindmapmode,
                    org.freeplane.features.note,
                    org.freeplane.features.note.mindmapmode,
                    org.freeplane.features.print,
                    org.freeplane.features.script,
                    org.freeplane.features.spellchecker.mindmapmode,
                    org.freeplane.features.styles,
                    org.freeplane.features.styles.mindmapmode,
                    org.freeplane.features.text,
                    org.freeplane.features.text.mindmapmode,
                    org.freeplane.features.time,
                    org.freeplane.features.ui,
                    org.freeplane.features.url,
                    org.freeplane.features.url.mindmapmode,
                    org.freeplane.main.addons,
                    org.freeplane.main.applet,
                    org.freeplane.main.application,
                    org.freeplane.main.application.protocols.freeplaneresource,
                    org.freeplane.main.browsemode,
                    org.freeplane.main.filemode,
                    org.freeplane.main.headlessmode,
                    org.freeplane.main.mindmapmode,
                    org.freeplane.main.mindmapmode.stylemode,
                    org.freeplane.main.osgi,
                    org.freeplane.n3.nanoxml,
                    org.freeplane.plugin.macos,
                    org.freeplane.view.swing.features,
                    org.freeplane.view.swing.features.filepreview,
                    org.freeplane.view.swing.features.nodehistory,
                    org.freeplane.view.swing.features.progress.mindmapmode,
                    org.freeplane.view.swing.features.time.mindmapmode,
                    org.freeplane.view.swing.map,
                    org.freeplane.view.swing.map.attribute,
                    org.freeplane.view.swing.map.cloud,
                    org.freeplane.view.swing.map.edge,
                    org.freeplane.view.swing.map.link,
                    org.freeplane.view.swing.map.mindmapmode,
                    org.freeplane.view.swing.ui,
                    org.freeplane.view.swing.ui.mindmapmode,
                    com.jgoodies.forms.builder,
                    com.jgoodies.forms.debug,
                    com.jgoodies.forms.factories,
                    com.jgoodies.forms.layout,
                    com.jgoodies.forms.util,
                    com.lightdev.app.shtm,
                    org.apache.commons.io,
                    org.apache.commons.io.comparator,
                    org.apache.commons.io.filefilter,
                    org.apache.commons.io.input,
                    org.apache.commons.io.monitor,
                    org.apache.commons.io.output,
                    org.apache.commons.lang,
                    org.apache.commons.lang.builder,
                    org.apache.commons.lang.exception,
                    org.apache.commons.lang.math,
                    org.apache.commons.lang.time
                    """
ext.bundleActivator = 'org.freeplane.main.osgi.Activator'

task copyOSGiJars(type: Copy) {
        from ("$buildDir/libs") {
          include("*.jar")
		  exclude('freeplane-*.jar')
        }
     from (configurations.lib) {
          include("*.jar")
		  
     }
     from ('lib') {
          include("*.jar")
          exclude('*-sources.jar')
     }
	 from (project(':freeplane_mac').jar.outputs.files)
     into(globalBin + '/core/' + pluginid + '/lib/')
}
copyOSGiJars.dependsOn project(':freeplane_mac').jar

task copyOSGiManifest(type: Copy) {
     from ("$buildDir/tmp/jar/") {
          include("MANIFEST.MF")
     }
     into(globalBin + '/core/' + pluginid + '/META-INF/')
}

class PartialJar extends Jar {
	String[] includedClasses
}

task editorJar(type: PartialJar) {
    // use '= project.manifest' to avoid that an OSGi manifest is created!
    manifest = project.manifest {
        attributes("Manifest-Version": "1.0",
                   "Main-Class": "org.freeplane.main.application.FreeplaneMain")
    }
    baseName = 'freeplaneeditor'
    dependsOn classes
	includedClasses = [
				"**/application/**",
				"**/mindmapmode/**",
				"**/ortho/**",
				"**/filemode/**",
				"**/core/resources/ui/**",
				"translations/**"
	]
	
    from (sourceSets.main.output) {
				include(includedClasses)
    }
    from (sourceSets.editor.resources)
    includeEmptyDirs = false
}

task osgiJar(type: PartialJar) {
	// use '= project.manifest' to avoid that an OSGi manifest is created!
	manifest = project.manifest {
		attributes("Manifest-Version": "1.0")
	}
	baseName = 'freeplaneosgi'
	dependsOn classes
	includedClasses = [
				"**/osgi/**"
	]
    from (sourceSets.main.output) {
				include(includedClasses)
    }
    includeEmptyDirs = false
}


task viewerJar(type: Jar) {
    // use '= project.manifest' to avoid that an OSGi manifest is created!
    manifest = project.manifest {
        attributes("Manifest-Version": "1.0",
                   "Permissions": "all-permissions",
                   "Codebase": "*",
                   "Application-Library-Allowable-Codebase": "*",
                   "Application-Name": "Freeplane Viewer Applet")
    }

    // this must be unversioned because the applet export code relies on this
    archiveName = 'freeplaneviewer.jar'
    dependsOn classes
    from (sourceSets.main.output) {
        exclude (editorJar.includedClasses)
        exclude (osgiJar.includedClasses )
    }
    from (sourceSets.viewer.resources)
    
    configurations.mergedViewerDependencies.files.each {
    	from(zipTree(it.path))
    }
	
    includeEmptyDirs = false
}

apply from: './signjar.gradle'

eclipseJdt {
    doLast {
        File f = file('.settings/org.eclipse.core.resources.prefs')
        f.append('''encoding//resources/translations=ISO-8859-1
encoding//viewer-resources/translations=ISO-8859-1
''')
    }
}


apply from: './git.gradle'

task copyExternalResources(type: Copy) {
    from(sourceSets.external.resources) {
        include('**')
    }
    into(globalBin + '/resources')

    // (exactly) one of these two groups (copy vs. create) is always disabled!
    dependsOn copyGitTxt
    dependsOn copyGitProperty
    dependsOn createGitProperty
}

task copyDoc(type: Copy) {
    from('doc/') {
        include('**')
    }
    into(globalBin + '/doc')
}

jar.dependsOn viewerJar
jar.dependsOn editorJar
jar.dependsOn osgiJar
build.dependsOn copyOSGiJars
build.dependsOn copyOSGiManifest
build.dependsOn copyExternalResources
build.dependsOn copyDoc

apply from: './format_translation.gradle'
