com.adobe.aem.analyser.mojos.AnalyseConfigsMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aemanalyser-maven-plugin Show documentation
Show all versions of aemanalyser-maven-plugin Show documentation
Maven plugin to analyse AEM components
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
package com.adobe.aem.analyser.mojos;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.sling.feature.ArtifactId;
import com.adobe.aem.analyser.result.AemAnalyserResult;
import com.adobe.aem.analyser.tasks.ConfigurationsTask;
import com.adobe.aem.analyser.tasks.ConfigurationsTaskConfig;
import com.adobe.aem.analyser.tasks.TaskContext;
import com.adobe.aem.project.model.ConfigurationFile;
@Mojo(name = "analyse-configs",
defaultPhase = LifecyclePhase.COMPILE,
requiresDependencyResolution = ResolutionScope.COMPILE)
public class AnalyseConfigsMojo extends AbstractAnalyseMojo {
/**
* Configuration of the repository root directory
*/
@Parameter(defaultValue = "src/main/content/jcr_root")
private File repositoryRootDirectory;
@Parameter(defaultValue = "false")
private boolean enforceConfigurationBelowConfigFolder;
@Override
protected AemAnalyserResult doExecute(final ArtifactId sdkId, final List addons) throws MojoExecutionException, MojoFailureException {
try {
final TaskContext context = new TaskContext(
this.project.getBasedir(),
new ArtifactId(this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion(), null, this.project.getPackaging()),
sdkId,
addons,
id -> { return this.getOrResolveFeature(id);}
);
final ConfigurationsTaskConfig config = new ConfigurationsTaskConfig();
config.setEnforceRepositoryConfigurationBelowConfigFolder(this.enforceConfigurationBelowConfigFolder);
final ConfigurationsTask task = new ConfigurationsTask(context, config);
final List files = task.scanRepositoryDirectory(this.repositoryRootDirectory);
final AemAnalyserResult result = task.analyseConfigurations(files);
return result;
} catch ( final IOException ioe ) {
throw new MojoExecutionException(ioe.getMessage(), ioe);
}
}
}