plugins {
	id 'com.diffplug.eclipse.mavencentral'
	id 'com.diffplug.eclipse.excludebuildfolder'
}

apply plugin: 'com.diffplug.spotless-changelog'
spotlessChangelog {
	changelogFile 'CHANGES.md'
}

apply plugin: 'com.diffplug.blowdryer'

configurations.all {
	exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt.${osgi.platform}'
	exclude group: 'com.sun.jna', module: 'com.sun.jna'
	exclude group: 'com.sun.jna', module: 'com.sun.jna.platform'
}
apply from: 干.file('base/java.gradle')
apply from: 干.file('base/changelog.gradle')
apply from: 干.file('base/gradle-plugin.gradle')
apply from: 干.file('spotless/freshmark.gradle')
apply from: 干.file('spotless/java.gradle')
apply from: 干.file('base/maven.gradle')
apply from: 干.file('base/sonatype.gradle')
spotless {
	java {
		targetExclude 'src/main/java/com/diffplug/gradle/eclipse/apt/**'
	}
}

String VER_DURIAN = '1.2.0'
String VER_DURIAN_SWT = '4.3.0'
String VER_BNDLIB = '6.3.1'
String OLDEST_SUPPORTED_GRADLE = '5.1'
String VER_P2_BOOTSTRAP = '4.13.0'

dependencies {
	// Compile misc
	implementation "com.diffplug.durian:durian-core:${VER_DURIAN}"
	implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}"
	implementation "com.diffplug.durian:durian-io:${VER_DURIAN}"
	implementation "com.diffplug.durian:durian-swt.os:${VER_DURIAN_SWT}"
	implementation "commons-io:commons-io:2.16.1"
	implementation "com.diffplug.spotless:spotless-lib:2.34.0"
	implementation "com.squareup.okhttp3:okhttp:4.12.0"
	implementation "com.squareup.okio:okio:3.9.0"
	// OSGi
	implementation "biz.aQute.bnd:biz.aQute.bndlib:${VER_BNDLIB}"
	// testing
	testImplementation "junit:junit:4.13.2"
	testImplementation "org.assertj:assertj-core:3.26.0"
}

configurations.compileClasspath {
	transitive = false
}
eclipseMavenCentral {
	silenceEquoIDE()
	release VER_P2_BOOTSTRAP, {
		api 'org.eclipse.osgi'
		api 'org.eclipse.osgi.compatibility.state'
		compileOnly 'org.eclipse.core.jobs'
		compileOnly 'org.eclipse.core.runtime'
		compileOnly 'org.eclipse.core.resources'
		compileOnly 'org.eclipse.e4.core.di'
		compileOnly 'org.eclipse.equinox.common'
		compileOnly 'org.eclipse.ui.workbench'
		compileOnly 'org.eclipse.pde.core'
		compileOnly 'org.eclipse.jdt.launching'
		compileOnly 'org.eclipse.emf.ecore'
	}
}

test {
	if(JavaVersion.current() != JavaVersion.VERSION_1_8) {
		jvmArgs '--add-modules=ALL-SYSTEM', '--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED'
	}
	testLogging.exceptionFormat = 'full'
}

///////////////////
// OSGi metadata //
///////////////////
jar.manifest.attributes(
		'Manifest-Version': '1.0',
		'Bundle-SymbolicName': 'com.diffplug.gradle.goomph',
		'Bundle-Name': 'com.diffplug.gradle.goomph',
		'Bundle-Version': '0.0.0.SNAPSHOT',
		'Export-Package': 'com.diffplug.gradle.osgi',
		'Bundle-ClassPath': '.',
		'Bundle-ManifestVersion': '2',
		'DynamicImport-Package': '*'
		)

// we'll want the findbugs annotations (they don't have a 3.0.1 version)
dependencies {
	compileOnly 'com.google.code.findbugs:annotations:3.0.1'
	compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
}

///////////
// MAVEN //
///////////
javadoc {
	options.source("${ver_java}")
	// setup links
	options.linksOffline('https://docs.oracle.com/javase/8/docs/api/', 'gradle/javadoc/java8')
	options.linksOffline("https://docs.gradle.org/${OLDEST_SUPPORTED_GRADLE}/javadoc/", 'gradle/javadoc/gradle')
	options.linksOffline("https://www.javadoc.io/doc/biz.aQute.bnd/biz.aQute.bndlib/${VER_BNDLIB}/", 'gradle/javadoc/bndlib')
}

/////////////////////////////
// LEGACY REDIRECT PLUGINS //
/////////////////////////////
// plugin ids that we are migrating
def old_plugins = 'eclipseBuildProperties eclipseExcludeBuildFolder eclipseMavenCentral eclipseProjectDeps eclipseResourceFilters equinoxLaunch oomphIde p2AsMaven osgiBndManifest swtNativeDeps'.split()
gradlePlugin {
	plugins {
		for (plugin in old_plugins) {
			register "${plugin}Legacy", {
				String newId   = 干.proj("plugin_${plugin}_id", "for ${plugin}: apply plugin: 'id'")
				String newImpl = 干.proj("plugin_${plugin}_impl", "for ${plugin}: implementationClass")
				String oldId;
				if (newId.equals("com.diffplug.osgi.equinoxlaunch")) {
					oldId = "com.diffplug.gradle.equinoxlaunch";
				} else {
					oldId = newId.replace("com.diffplug.", "com.diffplug.gradle.");
				}
				id                  = oldId
				implementationClass = "${newImpl}\$Legacy"
				displayName         = "Back-compat alias to $newId"
				description         = "Back-compat alias to $newId"
				tags.set(Arrays.asList("eclipse"))
			}
		}
	}
}
