You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/11/07 10:24:00 UTC
[sling-slingfeature-maven-plugin] branch master updated: SLING-8058
: Make configuration of slingfeature-maven-plugin consistent. Adjust
analysis mojo
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 870f428 SLING-8058 : Make configuration of slingfeature-maven-plugin consistent. Adjust analysis mojo
870f428 is described below
commit 870f42866030b35192bca81779cb764792c7eb85
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Nov 7 11:23:52 2018 +0100
SLING-8058 : Make configuration of slingfeature-maven-plugin consistent. Adjust analysis mojo
---
.../sling/feature/maven/mojos/Aggregate.java | 8 ++
.../feature/maven/mojos/AnalyseFeaturesMojo.java | 130 ++++++++++-----------
.../sling/feature/maven/mojos/Repository.java | 7 ++
.../org/apache/sling/feature/maven/mojos/Scan.java | 50 ++++++++
4 files changed, 128 insertions(+), 67 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java b/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java
index c62f310..77459a1 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java
@@ -44,4 +44,12 @@ public class Aggregate extends FeatureSelectionConfig {
public Map<String, String> variables;
public Map<String, String> frameworkProperties;
+
+ @Override
+ public String toString() {
+ return "Aggregate [filesIncludes=" + getIncludes() + ", filesExcludes=" + getExcludes() + ", includeArtifact="
+ + getArtifacts() + ", includeClassifier=" + getClassifiers() + ", classifier=" + classifier
+ + ", markAsFinal=" + markAsFinal + ", title=" + title + ", description=" + description + ", variables="
+ + variables + ", frameworkProperties=" + frameworkProperties + "]";
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
index fdbb34c..3085c09 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
@@ -19,13 +19,10 @@ package org.apache.sling.feature.maven.mojos;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
-import java.util.Set;
+import java.util.List;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -39,6 +36,8 @@ import org.apache.sling.feature.builder.ArtifactProvider;
import org.apache.sling.feature.maven.ProjectHelper;
import org.apache.sling.feature.scanner.Scanner;
+import edu.emory.mathcs.backport.java.util.Collections;
+
/**
* Analyse the feature.
*/
@@ -47,28 +46,21 @@ import org.apache.sling.feature.scanner.Scanner;
requiresDependencyResolution = ResolutionScope.TEST,
threadSafe = true
)
-public class AnalyseFeaturesMojo extends AbstractFeatureMojo {
-
- @Component
- private ArtifactHandlerManager artifactHandlerManager;
-
- @Component
- ArtifactResolver artifactResolver;
-
- @Parameter
- Set<String> includeTasks;
+public class AnalyseFeaturesMojo extends AbstractIncludingFeatureMojo {
@Parameter
- Set<String> excludeTasks;
-
- @Parameter
- Set<String> includeFeatures;
-
- @Parameter
- Set<String> excludeFeatures;
+ private List<Scan> scans;
+ @SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ List<Scan> list = scans;
+ if (list == null || list.isEmpty()) {
+ // use default configuration
+ final Scan a = new Scan();
+ a.setFilesInclude("**/*.*");
+ list = Collections.singletonList(a);
+ }
final ArtifactProvider am = new ArtifactProvider() {
@Override
@@ -77,64 +69,68 @@ public class AnalyseFeaturesMojo extends AbstractFeatureMojo {
}
};
- boolean hasErrors = false;
+ getLog().debug(MessageUtils.buffer().a("Setting up the ").strong("Scanner").a("...").toString());
+ Scanner scanner;
try {
- getLog().debug(MessageUtils.buffer().a("Setting up the ").strong("Scanner").a("...").toString());
- final Scanner scanner = new Scanner(am);
- getLog().debug(MessageUtils.buffer().strong("Scanner").a(" successfully set up").toString());
-
- getLog().debug(MessageUtils.buffer().a("Setting up the ").strong("Analyser").a("...").toString());
- final Analyser analyser = new Analyser(scanner, includeTasks, excludeTasks);
- getLog().debug(MessageUtils.buffer().strong("Analyser").a(" successfully set up").toString());
+ scanner = new Scanner(am);
+ } catch (final IOException e) {
+ throw new MojoExecutionException("A fatal error occurred while setting up the Scanner, see error cause:",
+ e);
+ }
+ getLog().debug(MessageUtils.buffer().strong("Scanner").a(" successfully set up").toString());
- getLog().debug("Retrieving Feature files...");
- final Collection<Feature> features = ProjectHelper.getAssembledFeatures(this.project).values();
+ boolean hasErrors = false;
+ for (final Scan an : list) {
+ try {
- if (features.isEmpty()) {
- getLog().debug("There are no assciated Feature files to current ptoject, plugin execution will be interrupted");
- return;
- } else {
- getLog().debug("Starting Features analysis...");
- }
+ getLog().debug(MessageUtils.buffer().a("Setting up the ").strong("Analyser").a("...").toString());
+ final Analyser analyser = new Analyser(scanner, an.getIncludeTasks(), an.getExcludeTasks());
+ getLog().debug(MessageUtils.buffer().strong("Analyser").a(" successfully set up").toString());
- for (final Feature f : features) {
- String featureId = f.getId().toMvnId();
- boolean included = includeFeatures != null ? includeFeatures.contains(featureId) : true;
- boolean excluded = excludeFeatures != null ? excludeFeatures.contains(featureId) : false;
+ getLog().debug("Retrieving Feature files...");
+ final Collection<Feature> features = this.getSelectedFeatures(an).values();
- if (!included || excluded) {
- getLog().debug(MessageUtils.buffer().a("Feature '").strong(featureId).a("' will not be included in the Analysis").toString());
+ if (features.isEmpty()) {
+ getLog().debug(
+ "There are no assciated Feature files to current project, plugin execution will be interrupted");
continue;
+ } else {
+ getLog().debug("Starting Features analysis...");
}
- try {
- getLog().debug(MessageUtils.buffer().a("Analyzing Feature ").strong(featureId).a(" ...").toString());
- final AnalyserResult result = analyser.analyse(f);
- for (final String msg : result.getWarnings()) {
- getLog().warn(msg);
+ for (final Feature f : features) {
+ try {
+ getLog().debug(MessageUtils.buffer().a("Analyzing Feature ").strong(f.getId().toMvnId())
+ .a(" ...").toString());
+ final AnalyserResult result = analyser.analyse(f);
+ for (final String msg : result.getWarnings()) {
+ getLog().warn(msg);
+ }
+ for (final String msg : result.getErrors()) {
+ getLog().error(msg);
+ }
+
+ if (!result.getErrors().isEmpty()) {
+ getLog().error("Analyser detected errors on Feature '" + f.getId().toMvnId()
+ + "'. See log output for error messages.");
+ hasErrors = true;
+ } else {
+ getLog().debug(MessageUtils.buffer().a("Feature ").debug(f.getId().toMvnId())
+ .a(" succesfully passed all analysis").toString());
+ }
+ } catch (Exception t) {
+ throw new MojoFailureException(
+ "Exception during analysing feature " + f.getId().toMvnId() + " : " + t.getMessage(),
+ t);
}
- for (final String msg : result.getErrors()) {
- getLog().error(msg);
- }
-
- if (!result.getErrors().isEmpty()) {
- getLog().error("Analyser detected errors on Feature '" + f.getId()
- + "'. See log output for error messages.");
- hasErrors = true;
- } else {
- getLog().debug(MessageUtils.buffer().a("Feature ").debug(featureId).a(" succesfully passed all analysis").toString());
- }
- } catch (Exception t) {
- throw new MojoFailureException(
- "Exception during analysing feature " + f.getId().toMvnId() + " : " + t.getMessage(), t);
}
+ } catch (IOException e) {
+ throw new MojoExecutionException(
+ "A fatal error occurred while setting up the Analyzer, see error cause:", e);
+ } finally {
+ getLog().debug("Features analysis complete");
}
- } catch (IOException e) {
- throw new MojoExecutionException("A fatal error occurred while setting up the Scanner and related Analyzer, see error cause:", e);
- } finally {
- getLog().debug("Features analysis complete");
}
-
if (hasErrors) {
throw new MojoFailureException("One or more features Analyzer detected Feature error(s), please read the plugin log for more datils");
}
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/Repository.java b/src/main/java/org/apache/sling/feature/maven/mojos/Repository.java
index 339af71..5b3ee26 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/Repository.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/Repository.java
@@ -38,4 +38,11 @@ public class Repository extends FeatureSelectionConfig {
public List<Dependency> getEmbeds() {
return this.embeds;
}
+
+ @Override
+ public String toString() {
+ return "Repository [filesIncludes=" + getIncludes() + ", filesExcludes=" + getExcludes() + ", includeArtifact="
+ + getArtifacts() + ", includeClassifier=" + getClassifiers() + ", embeds=" + embeds + ", repositoryDir="
+ + repositoryDir + "]";
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/Scan.java b/src/main/java/org/apache/sling/feature/maven/mojos/Scan.java
new file mode 100644
index 0000000..d7a95af
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/Scan.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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 CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.feature.maven.mojos;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Scan extends FeatureSelectionConfig {
+
+ private Set<String> includeTasks = new HashSet<>();
+
+ private Set<String> excludeTasks = new HashSet<>();
+
+ public void setIncludeTask(final String name) {
+ this.includeTasks.add(name);
+ }
+
+ public void setExcludeTask(final String name) {
+ this.excludeTasks.add(name);
+ }
+
+ public Set<String> getIncludeTasks() {
+ return this.includeTasks.isEmpty() ? null : this.includeTasks;
+ }
+
+ public Set<String> getExcludeTasks() {
+ return this.excludeTasks.isEmpty() ? null : this.excludeTasks;
+ }
+
+ @Override
+ public String toString() {
+ return "Scan [filesIncludes=" + getIncludes() + ", filesExcludes=" + getExcludes() + ", includeArtifact="
+ + getArtifacts() + ", includeClassifier=" + getClassifiers() + "includeTasks=" + includeTasks
+ + ", excludeTasks=" + excludeTasks + "]";
+ }
+}
\ No newline at end of file