Package org.apache.sling.feature.maven
Class ProjectHelper
java.lang.Object
org.apache.sling.feature.maven.ProjectHelper
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckFeatureId(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature) static StringcheckPreprocessorRun(org.apache.maven.project.MavenProject project) Check that the preprocessor has been runstatic FilecreateTmpFeatureFile(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature) Create a temporary file for the featurestatic FilecreateTmpFeatureFile(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature, boolean overwrite) Create a temporary file for the featurestatic StringgenerateAggregateFeatureKey(String classifier, boolean attach) getAssembledFeatures(org.apache.maven.project.MavenProject project) Get the assembled features from the project.getAssembledTestFeatures(org.apache.maven.project.MavenProject project) Get the assembled test feature from the projectstatic org.codehaus.plexus.util.xml.Xpp3DomGets 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 StringgetConfigValue(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.getDefaultMetadata(org.apache.maven.project.MavenProject project) getFeatures(org.apache.maven.project.MavenProject project) Get the raw feature from the project.static org.apache.maven.artifact.ArtifactgetOrResolveArtifact(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.apache.maven.artifact.resolver.ArtifactResolver resolver, org.apache.sling.feature.ArtifactId id) Get a resolved Artifact from the coordinates providedstatic org.apache.sling.feature.FeaturegetOrResolveFeature(org.apache.maven.project.MavenProject project, org.apache.maven.execution.MavenSession session, org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.apache.maven.artifact.resolver.ArtifactResolver resolver, org.apache.sling.feature.ArtifactId id) getTestFeatures(org.apache.maven.project.MavenProject project) Get the raw test feature from the projectstatic FilegetTmpDir(org.apache.maven.project.MavenProject project) static booleanisAggregate(String featureKey) static booleanisAttachAggregate(String featureKey) static booleanisLocalProjectArtifact(org.apache.maven.project.MavenProject project, org.apache.sling.feature.ArtifactId id) Check if the artifact is produced by the current projectpropertiesToMap(Properties value) static StringreadFeatureFile(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 variablesstatic voidstatic voidsetDefaultMetadata(org.apache.maven.project.MavenProject project, Map<String, Map<String, String>> data) static voidsetFeatureInfo(org.apache.maven.project.MavenProject project, org.apache.sling.feature.Feature feature) static voidStore all relevant information about the project for plugins to be retrievedstatic org.apache.sling.feature.ArtifactIdtoArtifactId(org.apache.maven.model.Dependency dep) static org.apache.maven.model.DependencytoDependency(org.apache.sling.feature.ArtifactId id, String scope) static StringtoString(org.apache.maven.model.Dependency d) static voidvalidateFeatureClassifiers(org.apache.maven.project.MavenProject project) Validate the classifiers in a projectstatic voidvalidateFeatureClassifiers(org.apache.maven.project.MavenProject project, String additionalClassifier, boolean attachFeature) Validate the classifiers in a project
-
Constructor Details
-
ProjectHelper
public ProjectHelper()
-
-
Method Details
-
storeProjectInfo
Store all relevant information about the project for plugins to be retrieved- Parameters:
info- The project info
-
checkPreprocessorRun
Check that the preprocessor has been run- Parameters:
project- The maven project- Returns:
nullif 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- Pluginname- 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- Pluginname- Configuration parameter.- Returns:
nullif nothing is configured, the value otherwise.- Throws:
RuntimeException- If more than one value is configured
-
getTmpDir
-
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 projectfeature- 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 projectfeature- The featureoverwrite- If set totruethe 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.apache.maven.artifact.resolver.ArtifactResolver resolver, org.apache.sling.feature.ArtifactId id) Get a resolved Artifact from the coordinates provided- Parameters:
project- The maven projectsession- The maven sessionartifactHandlerManager- The artifact handler managerresolver- The artifact resolverid- 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.apache.maven.artifact.resolver.ArtifactResolver resolver, org.apache.sling.feature.ArtifactId id) -
toString
-
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
-
isAttachAggregate
-
generateAggregateFeatureKey
-
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 projectadditionalClassifier- Optional additional classifierattachFeature- 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 projectid- The artifact id- Returns:
trueif the artifact belongs to the project
-
propertiesToMap
-
scan
-
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 usefile- The json filesuggestedClassifier- The suggested classifierlegacyReplace- if the old replace is enabledenableProjectVars- is the project variables are enabledadditionalVars- 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
-
getDefaultMetadata
-