Package org.apache.sling.feature.maven

# Class ProjectHelper

java.lang.Object
org.apache.sling.feature.maven.ProjectHelper

public abstract class ProjectHelper extends Object
The project helper contains utility functions and provides access to the already read and processed features and test features. Mojos must not read features by themselves but use this helper to get them.

## Constructor Summary

Constructors
Constructor
Description
`ProjectHelper()`

## Method Summary

Modifier and Type
Method
Description
`static void`
`checkFeatureId(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature)`
`static String`
`checkPreprocessorRun(org.apache.maven.project.MavenProject project)`
Check that the preprocessor has been run
`static File`
`createTmpFeatureFile(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature)`
Create a temporary file for the feature
`static File`
`createTmpFeatureFile(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature, boolean overwrite)`
Create a temporary file for the feature
`static String`
`generateAggregateFeatureKey(String classifier, boolean attach)`
`static Map<String,org.apache.sling.feature.Feature>`
`getAssembledFeatures(org.apache.maven.project.MavenProject project)`
Get the assembled features from the project.
`static Map<String,org.apache.sling.feature.Feature>`
`getAssembledTestFeatures(org.apache.maven.project.MavenProject project)`
Get the assembled test feature from the project
`static org.codehaus.plexus.util.xml.Xpp3Dom`
`getConfig(org.apache.maven.model.Plugin plugin, String name)`
Gets a configuration value for a plugin if it is set in the configuration for the plugin or any configuration for an execution of the plugin.
`static String`
`getConfigValue(org.apache.maven.model.Plugin plugin, String name, String defaultValue)`
Gets a configuration value for a plugin if it is set in the configuration for the plugin or any configuration for an execution of the plugin.
`static final Map<String,Map<String,String>>`
`getDefaultMetadata(org.apache.maven.project.MavenProject project)`
`static Map<String,org.apache.sling.feature.Feature>`
`getFeatures(org.apache.maven.project.MavenProject project)`
Get the raw feature from the project.
`static org.apache.maven.artifact.Artifact`
`getOrResolveArtifact(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.eclipse.aether.RepositorySystem repoSystem, org.apache.sling.feature.ArtifactId id)`
Get a resolved Artifact from the coordinates provided
`static org.apache.sling.feature.Feature`
`getOrResolveFeature(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.eclipse.aether.RepositorySystem repoSystem, org.apache.sling.feature.ArtifactId id)`
`static Map<String,org.apache.sling.feature.Feature>`
`getTestFeatures(org.apache.maven.project.MavenProject project)`
Get the raw test feature from the project
`static File`
`getTmpDir(org.apache.maven.project.MavenProject project)`
`static boolean`
`isAggregate(String featureKey)`
`static boolean`
`isAttachAggregate(String featureKey)`
`static boolean`
`isLocalProjectArtifact(org.apache.maven.project.MavenProject project, org.apache.sling.feature.ArtifactId id)`
Check if the artifact is produced by the current project
`static Map<String,String>`
`propertiesToMap(Properties value)`
`static String`
`readFeatureFile(org.apache.maven.project.MavenProject project, File file, String suggestedClassifier, boolean legacyReplace, boolean enableProjectVars, String[] additionalVars)`
Read the json file, minify it, add id if missing and replace variables
`static void`
`scan(List<File> files, File dir, String includes, String excludes)`
`static void`
`setDefaultMetadata(org.apache.maven.project.MavenProject project, Map<String,Map<String,String>> data)`
`static void`
`setFeatureInfo(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature)`
`static void`
`storeProjectInfo(FeatureProjectInfo info)`
Store all relevant information about the project for plugins to be retrieved
`static org.apache.sling.feature.ArtifactId`
`toArtifactId(org.apache.maven.model.Dependency dep)`
`static org.apache.maven.model.Dependency`
`toDependency(org.apache.sling.feature.ArtifactId id, String scope)`
`static String`
`toString(org.apache.maven.model.Dependency d)`
`static void`
`validateFeatureClassifiers(org.apache.maven.project.MavenProject project)`
Validate the classifiers in a project
`static void`
`validateFeatureClassifiers(org.apache.maven.project.MavenProject project, String additionalClassifier, boolean attachFeature)`
Validate the classifiers in a project

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ProjectHelper

public ProjectHelper()

## Method Details

### storeProjectInfo

public static void storeProjectInfo(FeatureProjectInfo info)
Store all relevant information about the project for plugins to be retrieved

Parameters:
  `info` - The project info

### checkPreprocessorRun

public static String checkPreprocessorRun(org.apache.maven.project.MavenProject project)
Check that the preprocessor has been run

Parameters:
  `project` - The maven project
Returns:
  `null` if the preprocessor ran, an error string if not

### getAssembledFeatures

public static Map<String,org.apache.sling.feature.Feature> getAssembledFeatures(org.apache.maven.project.MavenProject project)
Get the assembled features from the project. An assembled feature is already processed with respect to its include. The returned map uses the full path in the file system as the key and the assembled feature as a value.

Parameters:
  `project` - The maven projet
Returns:
  The assembled features. The map might be empty.

### getFeatures

public static Map<String,org.apache.sling.feature.Feature> getFeatures(org.apache.maven.project.MavenProject project)
Get the raw feature from the project. The returned map uses the full path in the file system as the key and the read feature as a value.

Parameters:
  `project` - The maven projet
Returns:
  The raw features. The map might be empty.

### getAssembledTestFeatures

public static Map<String,org.apache.sling.feature.Feature> getAssembledTestFeatures(org.apache.maven.project.MavenProject project)
Get the assembled test feature from the project

Parameters:
  `project` - The maven projet
Returns:
  The assembled features or `null`

### getTestFeatures

public static Map<String,org.apache.sling.feature.Feature> getTestFeatures(org.apache.maven.project.MavenProject project)
Get the raw test feature from the project

Parameters:
  `project` - The maven projet
Returns:
  The raw features or `null`

### getConfigValue

public static String getConfigValue(org.apache.maven.model.Plugin plugin, String name, String defaultValue)
Gets a configuration value for a plugin if it is set in the configuration for the plugin or any configuration for an execution of the plugin.

Parameters:
  `plugin` - Plugin
  `name` - Configuration parameter.
  `defaultValue` - The default value if no configuration is found.
Returns:
  The default value if nothing is configured, the value otherwise.
Throws:
  `RuntimeException` - If more than one value is configured

### getConfig

public static org.codehaus.plexus.util.xml.Xpp3Dom getConfig(org.apache.maven.model.Plugin plugin, String name)
Gets a configuration value for a plugin if it is set in the configuration for the plugin or any configuration for an execution of the plugin.

Parameters:
  `plugin` - Plugin
  `name` - Configuration parameter.
Returns:
  `null` if nothing is configured, the value otherwise.
Throws:
  `RuntimeException` - If more than one value is configured

### getTmpDir

public static File getTmpDir(org.apache.maven.project.MavenProject project)

### createTmpFeatureFile

public static File createTmpFeatureFile(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature)
Create a temporary file for the feature

Parameters:
  `project` - The Maven project
  `feature` - The feature
Returns:
  Return a temporary file

### createTmpFeatureFile

public static File createTmpFeatureFile(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature, boolean overwrite)
Create a temporary file for the feature

Parameters:
  `project` - The Maven project
  `feature` - The feature
  `overwrite` - If set to `true` the feature is always written even if the file already exists
Returns:
  Return a temporary file

### getOrResolveArtifact

public static org.apache.maven.artifact.Artifact getOrResolveArtifact(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.eclipse.aether.RepositorySystem repoSystem, org.apache.sling.feature.ArtifactId id)
Get a resolved Artifact from the coordinates provided

Parameters:
  `project` - The maven project
  `session` - The maven session
  `artifactHandlerManager` - The artifact handler manager
  `repoSystem` - The repository system
  `id` - The ID of the artifact to get/resolve.
Returns:
  the artifact, which has been resolved.

### getOrResolveFeature

public static org.apache.sling.feature.Feature getOrResolveFeature(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.eclipse.aether.RepositorySystem repoSystem, org.apache.sling.feature.ArtifactId id)

### toString

public static String toString(org.apache.maven.model.Dependency d)

### toDependency

public static org.apache.maven.model.Dependency toDependency(org.apache.sling.feature.ArtifactId id, String scope)

### toArtifactId

public static org.apache.sling.feature.ArtifactId toArtifactId(org.apache.maven.model.Dependency dep)

### setFeatureInfo

public static void setFeatureInfo(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature)

### isAggregate

public static boolean isAggregate(String featureKey)

### isAttachAggregate

public static boolean isAttachAggregate(String featureKey)

### generateAggregateFeatureKey

public static String generateAggregateFeatureKey(String classifier, boolean attach)

### validateFeatureClassifiers

public static void validateFeatureClassifiers(org.apache.maven.project.MavenProject project)
Validate the classifiers in a project

Parameters:
  `project` - The maven project

### validateFeatureClassifiers

public static void validateFeatureClassifiers(org.apache.maven.project.MavenProject project, String additionalClassifier, boolean attachFeature)
Validate the classifiers in a project

Parameters:
  `project` - The maven project
  `additionalClassifier` - Optional additional classifier
  `attachFeature` - Set to true to attach the feature

### isLocalProjectArtifact

public static boolean isLocalProjectArtifact(org.apache.maven.project.MavenProject project, org.apache.sling.feature.ArtifactId id)
Check if the artifact is produced by the current project

Parameters:
  `project` - The current project
  `id` - The artifact id
Returns:
  `true` if the artifact belongs to the project

### propertiesToMap

public static Map<String,String> propertiesToMap(Properties value)

### scan

public static void scan(List<File> files, File dir, String includes, String excludes)

### readFeatureFile

public static String readFeatureFile(org.apache.maven.project.MavenProject project, File file, String suggestedClassifier, boolean legacyReplace, boolean enableProjectVars, String[] additionalVars)
Read the json file, minify it, add id if missing and replace variables

Parameters:
  `project` - The Maven project to use
  `file` - The json file
  `suggestedClassifier` - The suggested classifier
  `legacyReplace` - if the old replace is enabled
  `enableProjectVars` - is the project variables are enabled
  `additionalVars` - any additional variables
Returns:
  The read and minified JSON

### checkFeatureId

public static void checkFeatureId(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature)

### setDefaultMetadata

public static void setDefaultMetadata(org.apache.maven.project.MavenProject project, Map<String,Map<String,String>> data)

### getDefaultMetadata

public static final Map<String,Map<String,String>> getDefaultMetadata(org.apache.maven.project.MavenProject project)