build scripts: proprietary tools (signing, scrambling, mac builder properties) extracted to a separate class to simplify code and avoid duplication

This commit is contained in:
nik
2016-08-17 14:01:07 +03:00
parent 7b32ae71e5
commit 3cccdae679
10 changed files with 73 additions and 29 deletions
@@ -38,10 +38,8 @@ abstract class BuildContext {
WindowsDistributionCustomizer windowsDistributionCustomizer
LinuxDistributionCustomizer linuxDistributionCustomizer
MacDistributionCustomizer macDistributionCustomizer
MacHostProperties macHostProperties
ProprietaryBuildTools proprietaryBuildTools
BuildOptions options
SignTool signTool
ScrambleTool scrambleTool
BundledJreManager bundledJreManager
/**
@@ -88,10 +86,10 @@ abstract class BuildContext {
public static BuildContext createContext(AntBuilder ant, JpsGantProjectBuilder projectBuilder, JpsProject project, JpsGlobal global,
String communityHome, String projectHome, String buildOutputRoot, ProductProperties productProperties,
BuildOptions options = new BuildOptions(), MacHostProperties macHostProperties = null, SignTool signTool = null,
ScrambleTool scrambleTool = null) {
ProprietaryBuildTools proprietaryBuildTools = ProprietaryBuildTools.DUMMY,
BuildOptions options = new BuildOptions()) {
return BuildContextImpl.create(ant, projectBuilder, project, global, communityHome, projectHome, buildOutputRoot, productProperties,
options, macHostProperties, signTool, scrambleTool)
proprietaryBuildTools, options)
}
/**
@@ -32,7 +32,8 @@ class IdeaCommunityBuilder {
IdeaCommunityBuilder(String home, String outputRootPath, GantBinding binding, BuildOptions options = new BuildOptions()) {
this.binding = binding
buildContext = BuildContext.createContext(binding.ant, binding.projectBuilder, binding.project, binding.global, home, home,
"$outputRootPath/release", new IdeaCommunityProperties(home), options)
"$outputRootPath/release", new IdeaCommunityProperties(home), ProprietaryBuildTools.DUMMY,
options)
}
IdeaCommunityBuilder(GantBinding binding, BuildContext buildContext) {
@@ -88,7 +88,7 @@ public abstract class ProductProperties {
List<LibraryLicense> allLibraryLicenses = CommunityLibraryLicenses.LICENSES_LIST
/**
* If {@code true} the main product JAR file will be scrambled using {@link BuildContext#scrambleTool}
* If {@code true} the main product JAR file will be scrambled using {@link ProprietaryBuildTools#scrambleTool}
*/
boolean scrambleMainJar = false
@@ -0,0 +1,48 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.intellij.build
import groovy.transform.Canonical
import groovy.transform.CompileStatic
import groovy.transform.Immutable
/**
* Describes proprietary tools which are used to build the product. Pass the instance of this class {@link BuildContext#createContext} method.
*
* @author nik
*/
@CompileStatic
@Canonical
class ProprietaryBuildTools {
public static final ProprietaryBuildTools DUMMY = new ProprietaryBuildTools(null, null, null)
/**
* This tool is required to sign *.exe files in Windows distribution. If it is {@code null} the files won't be signed and Windows may show
* a warning when user tries to run them.
*/
SignTool signTool
/**
* This tool is used to scramble the main product JAR file if {@link ProductProperties#scrambleMainJar} is {@code true}
*/
ScrambleTool scrambleTool
/**
* Describes address and credentials of Mac machine which is used to sign and build *.dmg installer for Mac OS. If {@code null} only *.sit
* archive will be built.
*/
MacHostProperties macHostProperties
}
@@ -18,7 +18,7 @@ package org.jetbrains.intellij.build
import groovy.transform.CompileStatic
/**
* Implement this interfaces and pass the implementation to {@link BuildContext#createContext} method to support scrambling the product
* Implement this interfaces and pass the implementation to {@link ProprietaryBuildTools} constructor to support scrambling the product
* JAR files.
*
* @author nik
@@ -33,7 +33,7 @@ package org.jetbrains.intellij.build
import groovy.transform.CompileStatic
/**
* Implement this interfaces and pass the implementation to {@link BuildContext#createContext} method to sign the product's *.exe files.
* Implement this interfaces and pass the implementation to {@link ProprietaryBuildTools} constructor to sign the product's *.exe files.
*
* @author nik
*/
@@ -38,8 +38,8 @@ class BuildContextImpl extends BuildContext {
//todo[nik] construct buildOutputRoot automatically based on product name
static BuildContextImpl create(AntBuilder ant, JpsGantProjectBuilder projectBuilder, JpsProject project, JpsGlobal global,
String communityHome, String projectHome, String buildOutputRoot, ProductProperties productProperties,
BuildOptions options, MacHostProperties macHostProperties, SignTool signTool, ScrambleTool scrambleTool) {
String communityHome, String projectHome, String buildOutputRoot, ProductProperties productProperties,
ProprietaryBuildTools proprietaryBuildTools, BuildOptions options) {
BuildMessages messages = BuildMessagesImpl.create(projectBuilder, ant.project)
def jdk8Home = JdkUtils.computeJdkHome(messages, "jdk8Home", "$projectHome/build/jdk/1.8", "JDK_18_x64")
@@ -60,15 +60,14 @@ class BuildContextImpl extends BuildContext {
return new BuildContextImpl(ant, messages, paths, project, global, projectBuilder, productProperties,
windowsDistributionCustomizer, linuxDistributionCustomizer, macDistributionCustomizer,
macHostProperties, options, signTool, scrambleTool, outputDirectoriesToKeep)
proprietaryBuildTools, options, outputDirectoriesToKeep)
}
BuildContextImpl(AntBuilder ant, BuildMessages messages, BuildPaths paths, JpsProject project, JpsGlobal global,
JpsGantProjectBuilder projectBuilder, ProductProperties productProperties,
WindowsDistributionCustomizer windowsDistributionCustomizer, LinuxDistributionCustomizer linuxDistributionCustomizer,
MacDistributionCustomizer macDistributionCustomizer,
MacHostProperties macHostProperties, BuildOptions options, SignTool signTool, ScrambleTool scrambleTool,
List<String> outputDirectoriesToKeep) {
ProprietaryBuildTools proprietaryBuildTools, BuildOptions options, List<String> outputDirectoriesToKeep) {
this.ant = ant
this.messages = messages
this.paths = paths
@@ -76,11 +75,9 @@ class BuildContextImpl extends BuildContext {
this.global = global
this.projectBuilder = projectBuilder
this.productProperties = productProperties
this.macHostProperties = macHostProperties
this.proprietaryBuildTools = proprietaryBuildTools
bundledJreManager = new BundledJreManager(this, paths.buildOutputRoot)
this.options = options
this.signTool = signTool
this.scrambleTool = scrambleTool
this.outputDirectoriesToKeep = outputDirectoriesToKeep
bundledJreManager = new BundledJreManager(this, paths.buildOutputRoot)
@@ -212,9 +209,9 @@ class BuildContextImpl extends BuildContext {
@Override
void signExeFile(String path) {
if (signTool != null) {
if (proprietaryBuildTools.signTool != null) {
messages.progress("Signing $path")
signTool.signExeFile(path, this)
proprietaryBuildTools.signTool.signExeFile(path, this)
messages.info("Signing done")
}
else {
@@ -238,7 +235,7 @@ class BuildContextImpl extends BuildContext {
def messages = messages.forkForParallelTask(taskName)
def child = new BuildContextImpl(ant, messages, paths, project, global, projectBuilder, productProperties,
windowsDistributionCustomizer, linuxDistributionCustomizer, macDistributionCustomizer,
macHostProperties, options, signTool, scrambleTool, outputDirectoriesToKeep)
proprietaryBuildTools, options, outputDirectoriesToKeep)
child.bundledJreManager.baseDirectoryForJre = bundledJreManager.baseDirectoryForJre
return child
}
@@ -272,11 +272,11 @@ idea.fatal.error.notification=disabled
new DistributionJARsBuilder(buildContext, includedModules, allPlugins).buildJARs()
}
if (buildContext.productProperties.scrambleMainJar) {
if (buildContext.scrambleTool != null) {
buildContext.scrambleTool.scramble(buildContext.productProperties.productLayout.mainJarName, buildContext)
if (buildContext.proprietaryBuildTools.scrambleTool != null) {
buildContext.proprietaryBuildTools.scrambleTool.scramble(buildContext.productProperties.productLayout.mainJarName, buildContext)
}
else {
buildContext.messages.warning("Scrambling skipped: 'srambleTool' isn't defined")
buildContext.messages.warning("Scrambling skipped: 'scrambleTool' isn't defined")
}
}
buildDistributions()
@@ -347,7 +347,7 @@ idea.fatal.error.notification=disabled
}
else {
List<String> modulesToBuild = ((moduleNames as Set<String>) + DistributionJARsBuilder.ADDITIONAL_MODULES_TO_COMPILE
+ buildContext.scrambleTool?.additionalModulesToCompile ?: []) as List<String>
+ buildContext.proprietaryBuildTools.scrambleTool?.additionalModulesToCompile ?: []) as List<String>
List<String> invalidModules = modulesToBuild.findAll {buildContext.findModule(it) == null}
if (!invalidModules.empty) {
buildContext.messages.warning("The following modules won't be compiled: $invalidModules")
@@ -129,8 +129,8 @@ class DistributionJARsBuilder {
Set<String> usedJars = collectUsedJars(includedModules, []) - productLayout.additionalJarsToUnpackIntoMainJar.collect {FileUtil.toSystemIndependentName(it)}
if (buildContext.scrambleTool != null) {
def forbiddenJarNames = buildContext.scrambleTool.namesOfJarsRequiredToBeScrambled
if (buildContext.proprietaryBuildTools.scrambleTool != null) {
def forbiddenJarNames = buildContext.proprietaryBuildTools.scrambleTool.namesOfJarsRequiredToBeScrambled
def forbiddenJars = usedJars.findAll { forbiddenJarNames.contains(PathUtilRt.getFileName(it)) }
if (!forbiddenJars.empty) {
buildContext.messages.error("The following JARs cannot be included into the product 'lib' directory, they need to be scrambled with the main jar: ${forbiddenJars}")
@@ -61,13 +61,13 @@ class MacDistributionBuilder {
layoutMacApp(ideaPropertiesFile, customIdeaProperties, docTypes)
customizer.copyAdditionalFiles(buildContext, macDistPath)
def macZipPath = buildMacZip()
if (buildContext.macHostProperties == null) {
if (buildContext.proprietaryBuildTools.macHostProperties == null) {
buildContext.messages.info("A Mac OS build agent isn't configured, dmg artifact won't be produced")
buildContext.notifyArtifactBuilt(macZipPath)
}
else {
buildContext.executeStep("Build dmg artifact for Mac OS X", BuildOptions.MAC_DMG_STEP) {
MacDmgBuilder.signAndBuildDmg(buildContext, customizer, buildContext.macHostProperties, macZipPath)
MacDmgBuilder.signAndBuildDmg(buildContext, customizer, buildContext.proprietaryBuildTools.macHostProperties, macZipPath)
buildContext.ant.delete(file: macZipPath)
}
}