2018-07-08

7: Building the Sample Project of This Site

<The previous article in this series | The table of contents of this series | The next article in this series>

Have gotten a sample project from this site? Here is how to build the project.

Topics


About: UNO (Universal Network Objects)
About: LibreOffice
About: Apache OpenOffice
About: Java programming language
About: C++
About: .NET Framework
About: Python programming language
About: LibreOffice Basic
About: Apache OpenOffice Basic
About: BeanShell
About: JavaScript

The table of contents of this article


Starting Context


  • The reader has built an environment for developing UNO programs in Linux or Windows, according to one of some previous articles (here for Linux and here for Windows).
  • The reader has knowledge on basic operations (to use a text editor; to use a terminal) in his or her operating system.

Target Context


  • The reader will know how to build any sample project cited in this site.
Stage Direction
Here are Hypothesizer 7, Objector 1C, Objector 7A, and Objector 7B in front of a computer.


Orientation


Hypothesizer 7
In this article, we will learn how to build the sample project we have gotten from this site.

Objector 1C
"the sample project we have gotten from this site"? What sample project? I haven't gotten any sample project . . .

Hypothesizer 7
Sir, such sample projects will come in future articles.

Objector 1C
. . . Ah, so I am supposed to have already read a future article.

Hypothesizer 7
Yes, actually.

Objector 1C
Anyway, as I already have an environment according to your instructions, I can build the sample just by executing a command, can't I?

Hypothesizer 7
In a Gradle build script, you may have to adjust a property value, which is the base directory of your LibreOffice or Apache OpenOffice installation, and maybe some other property values.

Objector 1C
Why do I have to do such a thing?

Hypothesizer 7
You need tools, Jar files, C++ header files and libraries, and/or .NET Framework libraries in order to build the sample project, and the property values specify the locations of those files.

Objector 1C
So, your build system is dumb enough not to be able to detect those locations automatically . . .

Hypothesizer 7
They cannot be generally determined automatically because there can be multiple candidates, but yes, the build system is dumb enough not to even search for candidates. In fact, I did not regard implementing the intelligence worth the effort.

Objector 1C
Why didn't you regard so?

Hypothesizer 7
Because the property values are set in a projects-common Gradle build script (they have to be set only once, basically), and they are set by programmers, for whom such setting one or several property values will not be any trouble to fuss over.

Objector 1C
. . .

Objector 7B
As I don't compile any Java, C++, or .NET framework code piece, I don't need any Jar file or something, and I don't need to set anything, right?

Hypothesizer 7
Madam, so, you are going to build . . .

Objector 7B
A UNO extension that includes only Basic code.

Hypothesizer 7
I see. Certainly, such a sample project will come. However, you will have to specify the location of the tool that register the UNO extension into your LibreOffice or Apache OpenOffice.

Objector 7B
I don't particularly want your build system to register my UNO extension; I can register it by a menu item of LibreOffice.

Hypothesizer 7
I see. Then, you do not have to set any property (although still you have to change the name of a file, as is described below), but you may want to specify a Gradle task when you build the project (as you can know how in the main body).

Objector 7B
. . .

Objector 7A
I don't have to use any environment you have specified in your previous articles, do I?

Hypothesizer 7
Well, as the environment I have specified includes only what are used in the sample projects, if you omit an artifact, obviously, you will have to modify the sample project to not use the artifact.

Objector 7A
. . .


Main Body


1: Downloading and Expanding the ZIP File


Hypothesizer 7
When an article provides a sample program, the sample program is provided as a ZIP file, which we can download from the article page.

Objector 1C
To where?

Hypothesizer 7
Anywhere you want to download to: as it is an archive file which you can expand and delete afterwards, the location of the ZIP file does not matter; the location of the expansion matters.

Objector 1C
To where should I expand it?

Hypothesizer 7
As I do not have any habit of using spaces in directory names, . . .

Objector 1C
I'm not interested in your habit at all!

Hypothesizer 7
I wanted to say that the build system was basically tested only against directory paths without any space, and expanding the ZIP file to such a directory would save you trouble.

Objector 1C
Just test it!

Hypothesizer 7
I once did, but I have radically modified the Gradle build scripts since then, and I am not sure now.

Objector 1C
Then test it again!

Hypothesizer 7
I wanted to say that as I would modify the Gradle build scripts also from now on, it would be tough to test it each time against possible space-included directory paths, especially because I do not feel any necessity of using spaces in directory names: such names are only cumbersome . . .

Objector 1C
. . . As Windows has some standard directories that have spaces in their names, . . .

Hypothesizer 7
I know that, but I avoid those directories as far as possible because I do not want to fill up the C drive.

Objector 1C
I'm not interested in your such taste . . .

Hypothesizer 7
I understand, but I must humbly admit at this point that our build system is not tested against space-included directory paths, although I would test when the build system has become more stable.

Objector 1C
. . .

Hypothesizer 7
All the sample ZIP files of this site are meant to be expanded to the same directory, which we will call 'development directory': there are common-to-projects Gradle build scripts, and we can get done with the only-once configuration, in that way. However, . . .

Objector 1C
"However"?

Hypothesizer 7
As those common Gradle build scripts will be frequently updated (sometimes incompatibly with prior versions), overwriting those files might break old projects.

Objector 1C
That will be a problem, won't it?

Hypothesizer 7
In that case, you can download the new versions of the broken projects from this site, or you can opt to create each development directory per sample program, which, of course, necessitates the configuration per development directory.

Objector 1C
Do you mean that you are going to renew ZIP files in that case?

Hypothesizer 7
That is my intention.

Objector 1C
Why won't you make the updates compatible?

Hypothesizer 7
Because I sometimes feel the desirability of radically modifying the build system.

Objector 1C
. . .

Hypothesizer 7
That is the same with common projects.

Objector 1C
What are "common projects"?

Hypothesizer 7
I will introduce such projects that are commonly used by some sample projects.

Objector 1C
Do you mean, as multiple samples share some code pieces, such common code pieces will be put into those common projects?

Hypothesizer 7
Yes, I do.

Objector 1C
And do you mean, those common projects may be updated incompatibly?

Hypothesizer 7
Yes, I do.

Objector 1C
Hmm . . .

Hypothesizer 7
I intend to update all the sample projects accordingly, but you will have to re-download them.


2: Understanding the Structure of the Development Directory


Hypothesizer 7
The development directory has some common-to-projects Gradle build scripts.

There is also 'commonVolatileProperties.gradle_Template', which is the template of the configuration file that contains prone-to-be-changed-per-environment settings.

Objector 7A
"Volatile"?

Hypothesizer 7
What one regards as being volatile is really a matter of taste, but I have separated some settings into this file according to my taste, lest those volatile settings will not be overwritten when a ZIP file is expanded into the existing development directory.

Objector 7A
Ah-ha.

Hypothesizer 7
You have to change the file name, 'commonVolatileProperties.gradle_Template', to 'commonVolatileProperties.gradle', and write the settings into the file.

In fact, these are the properties supposed to be set.

Parameter NameValue
c_javaCompilerThe Java compiler ('c_jdkCompiler') or null (if you do not use it, null has to be set, or the build can fail when a project contains any Java source file)
c_cplusplusCompilerThe C++ compiler ('c_gccCompiler' or 'c_visualStudioCplusplusCompiler') or null (if you do not use it, null has to be set, or the build can fail when a project contains any C++ source file)
c_csharpCompilerThe C# compiler ('c_dotnetCsharpCompiler') or null (if you do not use it, null has to be set, or the build can fail when a project contains any C# source file)
c_pythonCompilerThe Python compiler ('c_theBiasPlanetPythonCompiler') or null (if you do not use it, null has to be set, or the build can fail when a project contains any Python source file)
c_additionalLibrariesDirectoryPathThe directory of additional libraries, when some projects require such libraries
c_javaFxDirectoryPathThe directory of OpenJFX or null (if you do not use it, null has to be set, or the build can fail when a project contains any Java source file)
c_officeDirectoryPathThe base directory of LibreOffice or Apache OpenOffice
c_officeAdditionalHeaderFilesBaseDirectoryPathThe base directory of LibreOffice or Apache OpenOffice additional header files, if you develop C++ code pieces
c_visualStudioDirectoryPathThe base directory of Visual Studio IDE
c_visualStudioVersionThe Visual Studio version (a sub directory name under the base directory of Visual Studio IDE)
c_windowsSdkDirectoryPathThe base directory of Windows SDK
c_windowsSdkVersionThe Windows SDK version (a sub directory name under the base directory of Windows SDK)
c_wxWidgetsDirectoryPathThe base directory of wxWidgets
c_wxWidgetsLibrariesSubDirectoryNameThe name of the libraries sub directory under the base directory of wxWidgets
c_openSslDirectoryPathThe base directory of OpenSSL

The properties used in the file contain these values.

Property NameValue
c_operatingSystemNamePropertyNameThe name of the operating system name Java property
c_operatingSystemNameLinux"Linux"
c_projectDirectoryPathThe project directory path
c_operatingSystemDirectoriesSeparatorThe directories separator ('/' or '\') of the operating system
c_parentDirectoryNameThe parent directory special name ('..')

Of course, you can use rather literals.

Objector 7A
You said, the judgment of being volatile is according to your taste.

Hypothesizer 7
Yes. If you have opted to install LibreOffice SDK or Apache OpenOffice SDK to a directory that is not the LibreOffice base directory or the Apache OpenOffice base directory, you will have to change 'c_officeSdkDirectoryPath' in 'commonProperties.gradle'.

Objector 7A
Is that all?

Hypothesizer 7
Probably, for building sample projects. If you want to change other things for your own projects, there are some parameters you can change in 'commonProperties.gradle', for example the locations of source files, intermediate files, and target files, but we will talk about them in a future article.

Objector 7A
All right.

Hypothesizer 7
The 'build.gradle' file in the development directory is the Gradle build script that builds all the projects under the development directory.

Directories right under the development directory (except directories whose names start with '.') are project directories, each of which has the 'build.gradle' file, which is the Gradle project file.

Source files are under the directory, 'source', divided into programming-language-specific directories ('unoIdl', 'java', 'cplusplus', etc.) and the 'resource' directory.

Objector 7A
"'resource' directory"?

Hypothesizer 7
It contains the Jar manifest file, the UNO extension manifest file and related configuration files, etc.

Objector 7A
Ah-ha.

Hypothesizer 7
Although there do not exist at first, the 'intermediate' directory and the 'target' directory will be created by the build process. The 'target' directory will contain the target file (for example a UNO extension file if the project is a UNO extension project); the 'intermediate' directory will contain the intermediate files (for example class files if the project includes Java code pieces).


3: Building the Project or All the Projects


Hypothesizer 7
When we want to build a project, we open a terminal, change the current directory to the project directory, and execute this command, unless we face the Gradle-relentlessly-resolves-symbolic-links problem.

@bash Source Code
gradle

Objector 7A
What if I face that lengthy-named problem?

Hypothesizer 7
You can use 'Gradle.sh' in the development directory.

Objector 7A
Ah.

Hypothesizer 7
If the project is a UNO extension project, the build process will try to shutdown all the LibreOffice and Apache OpenOffice processes, register the UNO extension, and start a LibreOffice or Apache OpenOffice process.

Objector 7B
As I said in 'Orientation', that is meddlesomeness.

Hypothesizer 7
I understand. In that case, you can execute this command.

@bash Source Code
gradle i_makeUnoExtensionTask

Objector 7B
It is cumbersome to type such a long command each time . . .

Hypothesizer 7
Or you can change the default task to 'c_makeUnoExtensionTaskName' (the single quotations should not be written) in the 'build.gradle' file of the project, and execute the pure 'gradle' command thereafter.

Objector 7B
Hmm . . .

Hypothesizer 7
When the project is built, the projects referenced by the project will be automatically built.

We can also build all the projects in the development directory by changing the current directory to the development directory and executing the 'gradle' command.


4: The Conclusion and Beyond


Hypothesizer 7
Now, we can build any sample project of this site.

Although we did not delve into the code of the Gradle build scripts, we will do so in future articles.

We will see various sample programs that can be built by this build system, in future articles.


References


<The previous article in this series | The table of contents of this series | The next article in this series>