or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

artifact-management.mdindex.mdlegacy-repository-system.mdmetadata-processing.mdprofile-management.mdproject-building.mdrepository-operations.mdruntime-information.md

profile-management.mddocs/

0

# Profile Management

1

2

Maven profile activation and management system for backward compatibility with Maven2 profile handling patterns.

3

4

## Capabilities

5

6

### ProfileManager

7

8

Main interface for managing Maven profiles and their activation.

9

10

```java { .api }

11

/**

12

* Interface for managing Maven profiles and their activation

13

* @deprecated Use newer Maven 3.x profile management APIs

14

*/

15

@Deprecated

16

public interface ProfileManager {

17

/**

18

* Adds a profile to the manager

19

* @param profile profile to add

20

*/

21

void addProfile(Profile profile);

22

23

/**

24

* Adds multiple profiles to the manager

25

* @param profiles list of profiles to add

26

*/

27

void addProfiles(List<Profile> profiles);

28

29

/**

30

* Explicitly activates a profile by ID

31

* @param profileId ID of profile to activate

32

*/

33

void explicitlyActivate(String profileId);

34

35

/**

36

* Explicitly activates multiple profiles by IDs

37

* @param profileIds list of profile IDs to activate

38

*/

39

void explicitlyActivate(List<String> profileIds);

40

41

/**

42

* Explicitly deactivates a profile by ID

43

* @param profileId ID of profile to deactivate

44

*/

45

void explicitlyDeactivate(String profileId);

46

47

/**

48

* Explicitly deactivates multiple profiles by IDs

49

* @param profileIds list of profile IDs to deactivate

50

*/

51

void explicitlyDeactivate(List<String> profileIds);

52

53

/**

54

* Gets list of currently active profiles

55

* @return List of active Profile objects

56

* @throws ProfileActivationException if activation fails

57

*/

58

List getActiveProfiles() throws ProfileActivationException;

59

60

/**

61

* Gets all profiles by their IDs

62

* @return Map of profile ID to Profile object

63

*/

64

Map getProfilesById();

65

66

/**

67

* Gets list of explicitly activated profile IDs

68

* @return List of activated profile ID strings

69

*/

70

List<String> getExplicitlyActivatedIds();

71

72

/**

73

* Gets list of explicitly deactivated profile IDs

74

* @return List of deactivated profile ID strings

75

*/

76

List<String> getExplicitlyDeactivatedIds();

77

78

/**

79

* Gets list of profile IDs activated by default

80

* @return List of default active profile IDs

81

*/

82

List getIdsActivatedByDefault();

83

84

/**

85

* Gets the request properties used for profile activation

86

* @return Properties object with activation properties

87

*/

88

Properties getRequestProperties();

89

}

90

```

91

92

### DefaultProfileManager

93

94

Default implementation of ProfileManager.

95

96

```java { .api }

97

/**

98

* Default implementation of ProfileManager

99

*/

100

public class DefaultProfileManager implements ProfileManager {

101

/**

102

* Creates a new DefaultProfileManager

103

*/

104

public DefaultProfileManager();

105

106

/**

107

* Adds a profile to the manager

108

*/

109

public void addProfile(Profile profile);

110

111

/**

112

* Explicitly activates a profile by ID

113

*/

114

public void explicitlyActivate(String profileId);

115

116

/**

117

* Explicitly deactivates a profile by ID

118

*/

119

public void explicitlyDeactivate(String profileId);

120

121

/**

122

* Gets list of currently active profiles

123

*/

124

public List getActiveProfiles() throws ProfileActivationException;

125

126

/**

127

* Gets the request properties used for profile activation

128

*/

129

public Properties getRequestProperties();

130

}

131

```

132

133

### MavenProfilesBuilder

134

135

Interface for building profile configurations from files.

136

137

```java { .api }

138

/**

139

* Interface for building profile configurations from files

140

* @deprecated Use newer Maven 3.x profile building APIs

141

*/

142

@Deprecated

143

public interface MavenProfilesBuilder {

144

/**

145

* Role constant for Plexus component lookup

146

*/

147

String ROLE = MavenProfilesBuilder.class.getName();

148

149

/**

150

* Builds profiles from the given base directory

151

* @param basedir base directory to search for profiles

152

* @return ProfilesRoot containing parsed profiles

153

* @throws ProfilesBuilderException if profile building fails

154

*/

155

ProfilesRoot buildProfiles(File basedir) throws ProfilesBuilderException;

156

}

157

```

158

159

### DefaultMavenProfilesBuilder

160

161

Default implementation of MavenProfilesBuilder.

162

163

```java { .api }

164

/**

165

* Default implementation of MavenProfilesBuilder

166

*/

167

public class DefaultMavenProfilesBuilder implements MavenProfilesBuilder {

168

/**

169

* Builds profiles from the given base directory

170

*/

171

public ProfilesRoot buildProfiles(File basedir) throws ProfilesBuilderException;

172

}

173

```

174

175

## Profile Activation

176

177

### ProfileActivator

178

179

Base interface for profile activation strategies.

180

181

```java { .api }

182

/**

183

* Base interface for profile activation strategies

184

*/

185

public interface ProfileActivator {

186

/**

187

* Determines if a profile can be detected/activated

188

* @param profile profile to check

189

* @param context activation context

190

* @return true if profile can be activated

191

* @throws ProfileActivationException if activation check fails

192

*/

193

boolean canDetermineActivation(Profile profile, ProfileActivationContext context)

194

throws ProfileActivationException;

195

196

/**

197

* Determines if a profile should be activated

198

* @param profile profile to check

199

* @param context activation context

200

* @return true if profile should be activated

201

* @throws ProfileActivationException if activation determination fails

202

*/

203

boolean isActive(Profile profile, ProfileActivationContext context)

204

throws ProfileActivationException;

205

}

206

```

207

208

### FileProfileActivator

209

210

Activates profiles based on file existence.

211

212

```java { .api }

213

/**

214

* Activates profiles based on file existence

215

*/

216

public class FileProfileActivator extends DetectedProfileActivator {

217

/**

218

* Checks if profile should be activated based on file presence/absence

219

*/

220

public boolean isActive(Profile profile, ProfileActivationContext context)

221

throws ProfileActivationException;

222

}

223

```

224

225

### JdkPrefixProfileActivator

226

227

Activates profiles based on JDK version matching.

228

229

```java { .api }

230

/**

231

* Activates profiles based on JDK version matching

232

*/

233

public class JdkPrefixProfileActivator extends DetectedProfileActivator {

234

/**

235

* Checks if profile should be activated based on JDK version

236

*/

237

public boolean isActive(Profile profile, ProfileActivationContext context)

238

throws ProfileActivationException;

239

}

240

```

241

242

### SystemPropertyProfileActivator

243

244

Activates profiles based on system property values.

245

246

```java { .api }

247

/**

248

* Activates profiles based on system property values

249

*/

250

public class SystemPropertyProfileActivator extends DetectedProfileActivator {

251

/**

252

* Checks if profile should be activated based on system properties

253

*/

254

public boolean isActive(Profile profile, ProfileActivationContext context)

255

throws ProfileActivationException;

256

}

257

```

258

259

### OperatingSystemProfileActivator

260

261

Activates profiles based on operating system characteristics.

262

263

```java { .api }

264

/**

265

* Activates profiles based on operating system characteristics

266

*/

267

public class OperatingSystemProfileActivator extends DetectedProfileActivator {

268

/**

269

* Checks if profile should be activated based on OS details

270

*/

271

public boolean isActive(Profile profile, ProfileActivationContext context)

272

throws ProfileActivationException;

273

}

274

```

275

276

## Usage Examples

277

278

### Basic Profile Management

279

280

```java

281

import org.apache.maven.profiles.ProfileManager;

282

import org.apache.maven.profiles.DefaultProfileManager;

283

import org.apache.maven.model.Profile;

284

import org.apache.maven.profiles.activation.ProfileActivationException;

285

286

// Create profile manager

287

ProfileManager profileManager = new DefaultProfileManager();

288

289

// Create and add profiles

290

Profile devProfile = new Profile();

291

devProfile.setId("development");

292

Profile prodProfile = new Profile();

293

prodProfile.setId("production");

294

295

profileManager.addProfile(devProfile);

296

profileManager.addProfile(prodProfile);

297

298

// Explicitly activate profiles

299

profileManager.explicitlyActivate("development");

300

profileManager.explicitlyDeactivate("production");

301

302

try {

303

// Get active profiles

304

List activeProfiles = profileManager.getActiveProfiles();

305

System.out.println("Active profiles: " + activeProfiles.size());

306

307

// Access request properties

308

Properties props = profileManager.getRequestProperties();

309

System.out.println("Request properties: " + props);

310

} catch (ProfileActivationException e) {

311

System.err.println("Profile activation failed: " + e.getMessage());

312

}

313

```

314

315

### Building Profiles from Directory

316

317

```java

318

import org.apache.maven.profiles.MavenProfilesBuilder;

319

import org.apache.maven.profiles.DefaultMavenProfilesBuilder;

320

import org.apache.maven.profiles.ProfilesBuilderException;

321

322

// Build profiles from directory

323

MavenProfilesBuilder builder = new DefaultMavenProfilesBuilder();

324

File projectDir = new File(".");

325

326

try {

327

ProfilesRoot profilesRoot = builder.buildProfiles(projectDir);

328

List<Profile> profiles = profilesRoot.getProfiles();

329

System.out.println("Found " + profiles.size() + " profiles");

330

331

for (Profile profile : profiles) {

332

System.out.println("Profile: " + profile.getId());

333

}

334

} catch (ProfilesBuilderException e) {

335

System.err.println("Failed to build profiles: " + e.getMessage());

336

}

337

```

338

339

### Custom Profile Activation

340

341

```java

342

import org.apache.maven.profiles.activation.ProfileActivator;

343

import org.apache.maven.profiles.activation.FileProfileActivator;

344

import org.apache.maven.profiles.activation.JdkPrefixProfileActivator;

345

import org.apache.maven.profiles.activation.SystemPropertyProfileActivator;

346

347

// File-based activation

348

ProfileActivator fileActivator = new FileProfileActivator();

349

boolean fileBasedActive = fileActivator.isActive(profile, context);

350

351

// JDK version-based activation

352

ProfileActivator jdkActivator = new JdkPrefixProfileActivator();

353

boolean jdkBasedActive = jdkActivator.isActive(profile, context);

354

355

// System property-based activation

356

ProfileActivator propActivator = new SystemPropertyProfileActivator();

357

boolean propBasedActive = propActivator.isActive(profile, context);

358

359

System.out.println("Activation results:");

360

System.out.println(" File-based: " + fileBasedActive);

361

System.out.println(" JDK-based: " + jdkBasedActive);

362

System.out.println(" Property-based: " + propBasedActive);

363

```

364

365

### Profile Configuration Workflow

366

367

```java

368

// Complete profile management workflow

369

public void configureProfiles(File projectDir, List<String> activeProfileIds) {

370

try {

371

// Build profiles from directory

372

MavenProfilesBuilder builder = new DefaultMavenProfilesBuilder();

373

ProfilesRoot profilesRoot = builder.buildProfiles(projectDir);

374

375

// Create profile manager

376

ProfileManager profileManager = new DefaultProfileManager();

377

378

// Add all discovered profiles

379

for (Profile profile : profilesRoot.getProfiles()) {

380

profileManager.addProfile(profile);

381

}

382

383

// Activate requested profiles

384

for (String profileId : activeProfileIds) {

385

profileManager.explicitlyActivate(profileId);

386

}

387

388

// Get final active profiles

389

List activeProfiles = profileManager.getActiveProfiles();

390

System.out.println("Configured " + activeProfiles.size() + " active profiles");

391

392

} catch (ProfilesBuilderException | ProfileActivationException e) {

393

System.err.println("Profile configuration failed: " + e.getMessage());

394

}

395

}

396

```

397

398

## Exception Handling

399

400

### ProfileActivationException

401

402

```java { .api }

403

/**

404

* Exception thrown when profile activation fails

405

*/

406

public class ProfileActivationException extends Exception {

407

/**

408

* Creates exception with message

409

* @param message error message

410

*/

411

public ProfileActivationException(String message);

412

413

/**

414

* Creates exception with message and cause

415

* @param message error message

416

* @param cause underlying cause

417

*/

418

public ProfileActivationException(String message, Throwable cause);

419

}

420

```

421

422

### ProfilesBuilderException

423

424

```java { .api }

425

/**

426

* Exception thrown when profile building fails

427

*/

428

public class ProfilesBuilderException extends Exception {

429

/**

430

* Creates exception with message

431

* @param message error message

432

*/

433

public ProfilesBuilderException(String message);

434

435

/**

436

* Creates exception with message and cause

437

* @param message error message

438

* @param cause underlying cause

439

*/

440

public ProfilesBuilderException(String message, Throwable cause);

441

}

442

```

443

444

## Migration Notes

445

446

The profile management system in maven-compat is deprecated and maintained for backward compatibility. Modern Maven 3.x applications should use:

447

448

- `org.apache.maven.model.Profile` for profile representation

449

- `org.apache.maven.model.building.ModelBuilder` for profile resolution

450

- `org.apache.maven.execution.MavenExecutionRequest` for profile activation

451

452

The legacy system follows Plexus component patterns, while modern Maven uses standard dependency injection.