Skip to content

Commit da22e1a

Browse files
authored
Document implementation details of product binary generation in SignProducts.md (#5603)
1 parent 5bebec2 commit da22e1a

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

src/site/markdown/SignProducts.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,150 @@ Now we need to package them as zip files again and place them at the location wh
128128
## Result
129129

130130
You will now end up with a product for windows that only have `eclipse.exe` (or whatever your launcher name was) without the corresponding `eclipsec.exe`, you can find the example [here](https://github.com/eclipse-tycho/tycho/tree/master/demo/custom-signing-product).
131+
132+
## Implementation Details
133+
134+
This section explains where in Tycho and Eclipse P2 the product binary zip files are created and how they flow through the build system. Understanding this implementation can help when troubleshooting or customizing the product signing process.
135+
136+
### Overview of the Product Publishing Flow
137+
138+
The product publishing process in Tycho involves several components working together:
139+
140+
1. **PublishProductMojo** - The entry point Maven mojo
141+
2. **PublishProductToolImpl** - Tycho's implementation of product publishing
142+
3. **Eclipse P2 ProductAction** - P2's publisher action for products
143+
4. **ModuleArtifactRepository** - Tycho's artifact repository implementation
144+
145+
### Detailed Code Flow
146+
147+
#### 1. Entry Point: PublishProductMojo
148+
149+
**Location:** `tycho-p2-publisher-plugin/src/main/java/org/eclipse/tycho/plugins/p2/publisher/PublishProductMojo.java`
150+
151+
This is the `publish-products` mojo that processes all `.product` files in your project. Key responsibilities:
152+
153+
- Reads product definition files from the project directory
154+
- Validates product configuration (id, version, launcher settings)
155+
- Obtains the Equinox executable feature (launcher binaries) from dependencies
156+
- Delegates to `PublishProductToolImpl` for actual publishing
157+
- Calculates SHA-256 checksums for published binary artifacts
158+
159+
The mojo extracts the launcher binaries from `org.eclipse.equinox.executable` feature if the product includes launchers (`includeLaunchers()` returns true). These binaries are passed to the publishing tool.
160+
161+
#### 2. Product Publishing: PublishProductToolImpl
162+
163+
**Location:** `tycho-core/src/main/java/org/eclipse/tycho/p2/tools/publisher/PublishProductToolImpl.java`
164+
165+
This class bridges Tycho and Eclipse P2's publisher infrastructure:
166+
167+
- Creates a P2 `ProductAction` with the expanded product definition
168+
- Configures the artifact repository for writing with `ProductBinariesWriteSession`
169+
- Executes the P2 ProductAction via `PublisherActionRunner`
170+
- Returns dependency seeds for the published product IU
171+
172+
The `ProductBinariesWriteSession` is crucial - it determines the Maven classifier and file extension for binary artifacts (typically `.zip`).
173+
174+
#### 3. P2 ProductAction and ApplicationLauncherAction
175+
176+
**Location (Eclipse P2 repo):** `org.eclipse.equinox.p2.publisher.eclipse/ProductAction.java` and `ApplicationLauncherAction.java`
177+
178+
The P2 `ProductAction` orchestrates several sub-actions:
179+
- `ApplicationLauncherAction` - Publishes executable launcher files
180+
- `ConfigCUsAction` - Creates configuration units
181+
- `RootIUAction` - Creates the root installable unit
182+
- `JREAction` - Handles JRE inclusion if configured
183+
184+
The `ApplicationLauncherAction` creates `EquinoxExecutableAction` instances for each target platform configuration (Windows, Linux, macOS, etc.).
185+
186+
#### 4. Binary Artifact Creation: EquinoxExecutableAction
187+
188+
**Location (Eclipse P2 repo):** `org.eclipse.equinox.p2.publisher.eclipse/EquinoxExecutableAction.java`
189+
190+
This is where the binary executable artifacts are actually created:
191+
192+
1. **Branding**: Applies product branding to executables (icons, names, etc.)
193+
2. **Artifact Key Creation**: Creates a binary artifact key using `PublisherHelper.createBinaryArtifactKey()`
194+
3. **Zip Creation**: The `publishArtifact()` method (from `AbstractPublisherAction`) creates a temporary zip file containing all launcher files using `FileUtils.zip()`
195+
4. **Publishing**: The zip is written to the artifact repository via `destination.getOutputStream(descriptor)`
196+
197+
The classifier for these artifacts follows the pattern: `<product-id>.executable.<ws>.<os>.<arch>` (e.g., `myproduct.executable.win32.win32.x86_64`).
198+
199+
#### 5. Artifact Storage: ModuleArtifactRepository
200+
201+
**Location:** `tycho-core/src/main/java/org/eclipse/tycho/p2/repository/module/ModuleArtifactRepository.java`
202+
203+
This Tycho component manages the module's artifact repository:
204+
205+
- Stores artifacts in the build output directory (`target/`)
206+
- Maintains two metadata files:
207+
- `p2artifacts.xml` - P2 artifact metadata with Maven coordinates
208+
- `local-artifacts.properties` - Maps classifiers to file locations
209+
- Uses `ProductBinariesWriteSession` to determine artifact classifier and extension
210+
- Artifacts are stored as zip files that can be attached to the Maven project
211+
212+
When P2 calls `getOutputStream()` on the repository, the repository:
213+
1. Creates an `IArtifactSink` for the new artifact
214+
2. Determines the file location based on Maven coordinates (GAV + classifier)
215+
3. Returns an output stream that writes to the determined location
216+
4. Commits the artifact metadata to `p2artifacts.xml` when the stream closes
217+
218+
#### 6. Artifact Attachment: AttachPublishedArtifactsMojo
219+
220+
**Location:** `tycho-p2-publisher-plugin/src/main/java/org/eclipse/tycho/plugins/p2/publisher/persistence/AttachPublishedArtifactsMojo.java`
221+
222+
The `attach-artifacts` mojo attaches all published artifacts to the Maven project:
223+
- Retrieves artifact locations from the publishing repository
224+
- Attaches each artifact with its classifier and type
225+
- Main artifact gets no classifier, additional artifacts (like platform-specific executables) get classifiers
226+
227+
These attached artifacts are then available for:
228+
- Installation into the local Maven repository
229+
- Deployment to remote Maven repositories
230+
- Extraction and customization (as shown in the signing steps above)
231+
232+
### Key Classes Reference
233+
234+
#### Tycho Classes
235+
- **PublishProductMojo**: Entry point for product publishing
236+
- **PublishProductToolImpl**: Tycho's product publishing implementation
237+
- **ProductBinariesWriteSession**: Determines classifier/extension for binary artifacts
238+
- **ModuleArtifactRepository**: Stores artifacts in module's build directory
239+
- **PublisherActionRunner**: Executes P2 publisher actions
240+
- **AttachPublishedArtifactsMojo**: Attaches artifacts to Maven project
241+
242+
#### Eclipse P2 Classes (External Dependency)
243+
- **ProductAction**: Orchestrates product publishing
244+
- **ApplicationLauncherAction**: Publishes launcher artifacts
245+
- **EquinoxExecutableAction**: Creates and publishes executable binary artifacts
246+
- **AbstractPublisherAction.publishArtifact()**: Creates zip files from executable files
247+
- **PublisherHelper**: Utility for creating artifact keys and descriptors
248+
249+
### Why Artifacts Are Zip Files
250+
251+
The executable binaries are stored as zip files for several reasons:
252+
253+
1. **Multiple Files**: Each platform's launcher includes multiple files (executables, shared libraries, configuration files)
254+
2. **P2 Artifact Model**: P2's artifact repository model uses a single file per artifact
255+
3. **Maven Repository Compatibility**: Maven repositories work with single files per artifact
256+
4. **Streaming**: Zip format allows efficient streaming during repository operations
257+
258+
This is why Step 2 in the signing process needs to extract the zip file - the actual executables are packaged inside.
259+
260+
### Extension Points for Customization
261+
262+
The signing workflow shown above exploits several extension points:
263+
264+
1. **Phase Reordering**: Moving publish-products to `compile` phase allows interception before `package`
265+
2. **Maven Classifiers**: Each platform's executable has a unique classifier for targeted extraction
266+
3. **File System Access**: Extracted files are in standard build directory for tool access
267+
4. **Repository Plugin**: `tycho-p2-repository-plugin`'s `archive-repository` goal can repackage customized files
268+
269+
### Notes on P2 Integration
270+
271+
Some types in Tycho extend or wrap P2 types:
272+
273+
- **ModuleArtifactRepository** extends P2's `ArtifactRepositoryBaseImpl`
274+
- **ProductConfiguration** wraps P2's `ProductFile`
275+
- **PublisherActionRunner** wraps P2's `Publisher`
276+
277+
This allows Tycho to integrate Maven concepts (GAV coordinates, classifiers) with P2's metadata model while leveraging P2's publisher infrastructure for the actual product generation.

0 commit comments

Comments
 (0)