jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1868687 - in /jackrabbit/commons/filevault-package-maven-plugin/trunk/src: main/java/org/apache/jackrabbit/filevault/maven/packaging/ main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ test/java/org/apache/ja...
Date Mon, 21 Oct 2019 10:03:58 GMT
Author: kwin
Date: Mon Oct 21 10:03:57 2019
New Revision: 1868687

URL: http://svn.apache.org/viewvc?rev=1868687&view=rev
Log:
JCRVLT-371 store and evaluate dependencies locations as Maven
coordinates in/from properties.xml

Added:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependencyTest.java
Modified:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/AbstractValidateMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ArchiveValidationContextImpl.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DependencyResolver.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/SubPackageValidationContext.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/AbstractValidateMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/AbstractValidateMojo.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/AbstractValidateMojo.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/AbstractValidateMojo.java Mon Oct 21 10:03:57 2019
@@ -120,7 +120,7 @@ public abstract class AbstractValidateMo
      * minimal version accepted. Otherwise, the version range defines a lower and upper bound of accepted versions, where the bounds are
      * either included using parentheses {@code ()} or excluded using brackets {@code []} */
     @Parameter(property = "vault.dependencies")
-    protected MavenBasedPackageDependency[] dependencies = new MavenBasedPackageDependency[0];
+    protected Collection<MavenBasedPackageDependency> dependencies = new LinkedList<>();
 
     /** Defines the packages that define the repository structure. For the format description look at {@link #dependencies}.
      * <p>
@@ -131,7 +131,7 @@ public abstract class AbstractValidateMo
      * So therefore this repository-structure packages serve as indicator packages that helps satisfy the structural dependencies, but are
      * not added as real dependencies to the package. */
     @Parameter(property = "vault.repository.structure.packages")
-    protected MavenBasedPackageDependency[] repositoryStructurePackages = new MavenBasedPackageDependency[0];
+    protected Collection<MavenBasedPackageDependency> repositoryStructurePackages = new LinkedList<>();
 
     /**
      * Mapping of package dependencies given via group and name to Maven identifiers for enhanced validation.
@@ -170,9 +170,6 @@ public abstract class AbstractValidateMo
     }
     @Override 
     public void execute() throws MojoExecutionException, MojoFailureException {
-        // resolve mapping map
-        resolver = new DependencyResolver(DefaultRepositoryRequest.getRepositoryRequest(session, project), repositorySystem,
-                resolutionErrorHandler, resolveMap(mapPackageDependencyToMavenGa));
         translateLegacyParametersToValidatorParameters();
         final Collection<PackageInfo> resolvedDependencies = new LinkedList<>();
         if (project != null) {
@@ -214,10 +211,13 @@ public abstract class AbstractValidateMo
                     "Could not get meta information for dependencies '" + StringUtils.join(dependencies, ",") + "': " + e.getMessage(),
                     e);
         }
-        doExecute(resolvedDependencies);
+        // resolve mapping map
+        resolver = new DependencyResolver(DefaultRepositoryRequest.getRepositoryRequest(session, project), repositorySystem,
+                resolutionErrorHandler, resolveMap(mapPackageDependencyToMavenGa), resolvedDependencies);
+        doExecute();
     }
 
-    private Collection<PackageInfo> getPackageInfoFromMavenBasedDependencies(MavenBasedPackageDependency... dependencies) throws IOException {
+    private Collection<PackageInfo> getPackageInfoFromMavenBasedDependencies(Collection<MavenBasedPackageDependency> dependencies) throws IOException {
         Collection<PackageInfo> packageInfos = new LinkedList<>();
         // try to resolve from project artifacts (in case a project is given)
         MavenBasedPackageDependency.resolve(project, getLog(), dependencies);
@@ -249,5 +249,5 @@ public abstract class AbstractValidateMo
         }
     }
 
-    public abstract void doExecute(Collection<PackageInfo> resolvedDependencies) throws MojoExecutionException, MojoFailureException;
+    public abstract void doExecute() throws MojoExecutionException, MojoFailureException;
 }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java Mon Oct 21 10:03:57 2019
@@ -22,6 +22,8 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -30,6 +32,7 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -37,6 +40,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.jar.Manifest;
+import java.util.stream.Collectors;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
@@ -215,7 +219,7 @@ public class GenerateMetadataMojo extend
      * {@code ()} or excluded using brackets {@code []}
      */
     @Parameter(property = "vault.dependencies")
-    private MavenBasedPackageDependency[] dependencies = new MavenBasedPackageDependency[0];
+    private Collection<MavenBasedPackageDependency> dependencies = new LinkedList<>();
 
 
     /**
@@ -457,9 +461,10 @@ public class GenerateMetadataMojo extend
             setEmbeddedFilesMap(embeddedFiles);
 
             String dependenciesString = computeDependencies();
-
+            String dependenciesLocations = computeDependenciesLocations();
+            
             // generate properties.xml
-            final Properties vaultProperties = computeProperties(dependenciesString);
+            final Properties vaultProperties = computeProperties(dependenciesString, dependenciesLocations);
             try (FileOutputStream fos = new FileOutputStream(new File(vaultDir, Constants.PROPERTIES_XML))) {
                 vaultProperties.storeToXML(fos, project.getName());
             }
@@ -479,7 +484,7 @@ public class GenerateMetadataMojo extend
 
             // generate manifest file
             MavenArchiver mavenArchiver = new MavenArchiver();
-            Manifest manifest = mavenArchiver.getManifest(session, project, getMavenArchiveConfiguration(vaultProperties, dependenciesString));
+            Manifest manifest = mavenArchiver.getManifest(session, project, getMavenArchiveConfiguration(vaultProperties, dependenciesString, dependenciesLocations));
             try (OutputStream out = new FileOutputStream(getGeneratedManifestFile())) {
                 manifest.write(out);
             }
@@ -705,15 +710,28 @@ public class GenerateMetadataMojo extend
     /**
      * Computes the dependency string.
      * @return the dependency string
+     * @throws URISyntaxException 
      */
     private String computeDependencies() throws IOException {
         String dependenciesString = null;
-        if (dependencies.length > 0) {
-            dependenciesString = org.apache.jackrabbit.vault.packaging.Dependency.toString(MavenBasedPackageDependency.resolve(project, getLog(), dependencies).toArray(new Dependency[0]));
+        if (!dependencies.isEmpty()) {
+            MavenBasedPackageDependency.resolve(project, getLog(), dependencies);
+            Dependency[] vaultDependencies = dependencies.stream().map(MavenBasedPackageDependency::getPackageDependency).toArray(Dependency[]::new);
+            dependenciesString = Dependency.toString(vaultDependencies);
         }
         return dependenciesString;
     }
 
+    private String computeDependenciesLocations() throws IOException {
+        String dependenciesLocations = null;
+        if (!dependencies.isEmpty()) {
+            MavenBasedPackageDependency.resolve(project, getLog(), dependencies);
+            // pid = uri
+            dependenciesLocations = dependencies.stream().map(a -> a.getInfo().getId().toString() + "=" + a.getLocation()).collect(Collectors.joining(","));
+        }
+        return dependenciesLocations;
+    }
+
     /**
      * Escapes multiline manifest values to work around bug <a href="https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8222547">JDK-8222547</a>
      * Java itself only adds leading SPACE in case a line is longer than 72 chars.
@@ -728,7 +746,7 @@ public class GenerateMetadataMojo extend
                .replaceAll("\r(?!\n)", "\r ");  // only CR (not followed by LF)
     }
 
-    private MavenArchiveConfiguration getMavenArchiveConfiguration(Properties vaultProperties, String dependenciesString) throws IOException {
+    private MavenArchiveConfiguration getMavenArchiveConfiguration(Properties vaultProperties, String dependenciesString, String dependenciesLocations) throws IOException {
         if (archive == null) {
             archive = new MavenArchiveConfiguration();
             archive.setManifest(new ManifestConfiguration());
@@ -747,7 +765,11 @@ public class GenerateMetadataMojo extend
             archive.addManifestEntry(PackageProperties.MF_KEY_PACKAGE_DESC, escapeManifestValue(vaultProperties.getProperty("description", "")));
             if (dependenciesString != null && dependenciesString.length() > 0) {
                 archive.addManifestEntry(PackageProperties.MF_KEY_PACKAGE_DEPENDENCIES, escapeManifestValue(dependenciesString));
+                if (dependenciesLocations != null && dependenciesLocations.length() > 0) {
+                    archive.addManifestEntry(PackageProperties.MF_KEY_PACKAGE_DEPENDENCIES_LOCATIONS, escapeManifestValue(dependenciesLocations));
+                }
             }
+            
             // be sure to avoid duplicates
             Set<String> rts = new TreeSet<>();
             for (PathFilterSet p: filters.getFilterSets()) {
@@ -766,7 +788,7 @@ public class GenerateMetadataMojo extend
         return archive;
     }
 
-    private Properties computeProperties(String dependenciesString) {
+    private Properties computeProperties(String dependenciesString, String dependenciesLocations) {
         final Properties props = new Properties();
 
         // find the description of the content package (bug #30546)
@@ -806,6 +828,9 @@ public class GenerateMetadataMojo extend
         // dependencies
         if (dependenciesString != null && dependenciesString.length() > 0) {
             props.put(PackageProperties.NAME_DEPENDENCIES, dependenciesString);
+            if (dependenciesLocations != null && dependenciesLocations.length() > 0) {
+                props.put(PackageProperties.NAME_DEPENDENCIES_LOCATIONS, dependenciesLocations);
+            }
         }
 
         // creation stamp

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependency.java Mon Oct 21 10:03:57 2019
@@ -18,25 +18,27 @@ package org.apache.jackrabbit.filevault.
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Collection;
-import java.util.LinkedList;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.inject.Inject;
 
-import org.apache.jackrabbit.vault.packaging.Dependency;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.PackageInfo;
 import org.apache.jackrabbit.vault.packaging.VersionRange;
 import org.apache.jackrabbit.vault.packaging.impl.DefaultPackageInfo;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
- * The {@code Dependency} class represents a dependency to another content package.
+ * This class represents a dependency to another content package.
  * A dependency consists of a group name, a package name and a version range.
  * <p>
  * A dependency is declared as a {@code <dependency>} element of a list
@@ -66,41 +68,59 @@ import org.codehaus.plexus.util.StringUt
  */
 public class MavenBasedPackageDependency {
 
+    
     /**
      * The group name, required for package-id references
      */
+    @Inject
     private String group;
 
     /**
      * The group id, required for maven coordinate references
      */
+    @Inject
     private String groupId;
 
     /**
      * The package name, required for package-id references.
      */
+    @Inject
     private String name;
 
     /**
      * The artifact id, required for maven coordinate references
      */
+    @Inject
     private String artifactId;
 
     /**
+     * The classifier, optional for maven coordinate references
+     */
+    @Inject
+    private String classifier;
+
+    /**
      * The version range (optional)
      */
+    @Inject
     private String version;
 
     /**
-     * Package information of this dependency. only available for maven referenced dependencies after {@link #resolve(MavenProject, Log)}
+     * Package information of this dependency. Only available for maven referenced dependencies after {@link #resolve(MavenProject, Log)}
      */
     private PackageInfo info;
 
     /**
-     * Resolved package dependency. only available after {@link #resolve(MavenProject, Log)}
+     * Resolved package dependency. Only available after {@link #resolve(MavenProject, Log)}
      */
     private org.apache.jackrabbit.vault.packaging.Dependency dependency;
     
+    private boolean isResolved;
+    
+    private String mavenVersion;
+    
+    private final static String MAVEN_REPOSITORY_SCHEME = "maven";
+    
     // default constructor for passing Maven Mojo parameters of that type
     public MavenBasedPackageDependency() {
         
@@ -111,20 +131,16 @@ public class MavenBasedPackageDependency
      *
      * @param project the Maven project
      * @param log the Logger
-     * @param dependencyList The list of {@link MavenBasedPackageDependency} instances to convert.
+     * @param dependencies The list of {@link MavenBasedPackageDependency} instances to convert.
      * @return The Vault Packaging Dependency representing the resolved dependencies. Not all given items from the {@code dependencyList} can necessarily be resolved, therefore the the size of the collection might be less than the size of the collection given in {@code dependencyList} 
      * @throws IOException in case meta information could not be read from the project dependency or the 
      * dependency is not a content package.
+     * @throws URISyntaxException 
      */
-    public static @Nonnull Collection<Dependency> resolve(final MavenProject project, final Log log, final MavenBasedPackageDependency... dependencyList) throws IOException {
-        Collection<Dependency> dependencies = new LinkedList<>();
-        for (int i = 0; i < dependencyList.length; i++) {
-            Dependency dependency = dependencyList[i].resolve(project, log);
-            if (dependency != null) {
-                dependencies.add(dependency);
-            }
+    public static void resolve(final MavenProject project, final Log log, final Collection<MavenBasedPackageDependency> dependencies) throws IOException {
+        for (MavenBasedPackageDependency dependency : dependencies) {
+            dependency.resolve(project, log);
         }
-        return dependencies;
     }
 
     /**
@@ -132,9 +148,15 @@ public class MavenBasedPackageDependency
      * class to a Vault Packaging Dependency for easy string conversion.
      * @throws IOException in case meta information could not be read from the project dependency or the 
      * dependency is not a content package.
+     * @throws URISyntaxException 
      */
     @SuppressWarnings("deprecation")
-    private @CheckForNull org.apache.jackrabbit.vault.packaging.Dependency resolve(final MavenProject project, final Log log) throws IOException {
+    private void resolve(final MavenProject project, final Log log) throws IOException {
+        if (isResolved) {
+            return;
+        } else {
+            isResolved = true;
+        }
         if (!StringUtils.isEmpty(group) || !StringUtils.isEmpty(name)) {
             log.warn("Using package id in dependencies is deprecated. Use Maven coordinates (given via 'groupId' and 'artifactId') instead of '" + group + ":" + name +"'!");
         }
@@ -142,15 +164,17 @@ public class MavenBasedPackageDependency
             boolean foundMavenDependency = false;
             if (project != null) {
                 for (Artifact a : project.getDependencyArtifacts()) {
-                    if (a.getArtifactId().equals(artifactId) && a.getGroupId().equals(groupId)) {
+                    
+                    if (a.getArtifactId().equals(artifactId) && a.getGroupId().equals(groupId) && StringUtils.equals(a.getClassifier(), classifier)) {
                         // check if file exists and if it points to a real file (might also point to a classes dir)
                         try {
                             readMetaData(a.getFile(), log);
+                            mavenVersion = a.getVersion();
                             foundMavenDependency = true;
                         } catch (IOException e) {
                             // can not resolve name and group
                             log.warn("Could not resolve dependency '" + this + "'", e);
-                            return null;
+                            return;
                         }
                         break;
                     }
@@ -160,14 +184,14 @@ public class MavenBasedPackageDependency
                 }
             } else {
                 log.warn("Dependency '" + this + "' was given via Maven coordinates but there is no Maven project connected which allows to resolve those.");
-                return null;
+                return;
             }
         }
         if (StringUtils.isEmpty(group) || StringUtils.isEmpty(name)) {
             throw new IOException("Specified dependency " + this + " is not qualified (group and name or groupId and artifactId is missing)!");
         }
         VersionRange range = StringUtils.isEmpty(version) ? VersionRange.INFINITE : VersionRange.fromString(version);
-        return dependency = new org.apache.jackrabbit.vault.packaging.Dependency(group, name, range);
+        dependency = new org.apache.jackrabbit.vault.packaging.Dependency(group, name, range);
     }
 
     public void readMetaData(File file, Log log) throws IOException {
@@ -189,7 +213,7 @@ public class MavenBasedPackageDependency
             group = id.getGroup();
             name = id.getName();
             if (StringUtils.isEmpty(version)) {
-                log.info("No explicit version range given for dependency '" + this+ "'. Using default version range derived from the Maven dependency");
+                log.debug("No explicit version range given for dependency '" + this+ "'. Using default version range derived from the Maven dependency");
                 version = new VersionRange(id.getVersion(), true, null, false).toString();
             }
             this.info = info;
@@ -218,6 +242,15 @@ public class MavenBasedPackageDependency
         return dependency;
     }
 
+    @CheckForNull
+    public URI getLocation() {
+        if (groupId != null && artifactId != null && mavenVersion != null) {
+            // which version?
+            return mavenCoordinatesToUri(groupId, artifactId, mavenVersion, classifier);
+        }
+        return null;
+    }
+
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder("Dependency{");
@@ -229,4 +262,48 @@ public class MavenBasedPackageDependency
         sb.append('}');
         return sb.toString();
     }
+
+    public static URI mavenCoordinatesToUri(@Nonnull String groupId, @Nonnull String artifactId, @Nonnull String version, String classifier) {
+        StringBuilder ssp = new StringBuilder();
+        ssp.append(groupId).append(":").append(artifactId).append(":").append(version).append(":zip");
+        if (StringUtils.isNotEmpty(classifier)) {
+            ssp.append(":").append(classifier);
+        }
+        try {
+            return new URI(MAVEN_REPOSITORY_SCHEME, ssp.toString(), null);
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Could not create uri from string " + ssp.toString(), e);
+        }
+    }
+
+    public static Artifact uriToMavenCoordinates(URI uri) {
+        if (!MAVEN_REPOSITORY_SCHEME.equals(uri.getScheme())) {
+            return null;
+        }
+        if (!uri.isOpaque()) {
+            throw new IllegalArgumentException("Only opaque Maven URIs are supported");
+        }
+        // support groupId, artifactId, packaging and classifier (format like https://maven.apache.org/plugins/maven-dependency-plugin/get-mojo.html#artifact)
+        // extract group id and artifact id
+        String[] parts = uri.getSchemeSpecificPart().split(":");
+        if (parts.length < 2) {
+            throw new IllegalArgumentException("At least group id and artifact id need to be given separatedby ':'");
+        }
+        String groupId = parts[0];
+        String artifactId = parts[1];
+        String version = "default";
+        if (parts.length > 2) {
+            version = parts[2];
+        }
+        String type = "zip";
+        if (parts.length > 3) {
+            type = parts[3];
+        }
+        String classifier = "";
+        if (parts.length > 4) {
+            type = parts[4];
+        }
+        // TODO: version must not be null!
+        return new DefaultArtifact(groupId, artifactId, version, null, type, classifier, null);
+    }
 }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidateFilesMojo.java Mon Oct 21 10:03:57 2019
@@ -29,7 +29,6 @@ import java.util.List;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.filevault.maven.packaging.validator.impl.context.DirectoryValidationContext;
 import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
-import org.apache.jackrabbit.vault.packaging.PackageInfo;
 import org.apache.jackrabbit.vault.util.Constants;
 import org.apache.jackrabbit.vault.validation.ValidationExecutor;
 import org.apache.jackrabbit.vault.validation.ValidationViolation;
@@ -54,6 +53,8 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.codehaus.plexus.util.AbstractScanner;
+import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.Scanner;
 
 /** Validates individual files with all registered validators. This is only active for incremental builds (i.e. inside m2e)
@@ -139,7 +140,7 @@ public class ValidateFilesMojo extends A
     }
 
     @Override
-    public void doExecute(Collection<PackageInfo> resolvedDependencies) throws MojoExecutionException, MojoFailureException {
+    public void doExecute() throws MojoExecutionException, MojoFailureException {
         final List<String> allGoals;
         if (session != null) {
             allGoals = session.getGoals();
@@ -160,6 +161,7 @@ public class ValidateFilesMojo extends A
             getLog().warn("Could not determine plugin executions", e1);
         }
         try {
+            // TODO: consider also embedded bundles and packages (never appear in the jcr source dir)
             File metaInfoVaultSourceDirectory = AbstractMetadataPackageMojo.getMetaInfVaultSourceDirectory(metaInfVaultDirectory, getLog());
             File metaInfRootDirectory = null;
             if (metaInfoVaultSourceDirectory != null) {
@@ -167,7 +169,7 @@ public class ValidateFilesMojo extends A
             }
             File generatedMetaInfRootDirectory = new File(workDirectory, Constants.META_INF);
             getLog().info("Using generatedMetaInfRootDirectory: " + generatedMetaInfRootDirectory + " and metaInfRootDir: " + metaInfRootDirectory);
-            ValidationContext context = new DirectoryValidationContext(generatedMetaInfRootDirectory, metaInfRootDirectory, resolver, resolvedDependencies, getLog());
+            ValidationContext context = new DirectoryValidationContext(generatedMetaInfRootDirectory, metaInfRootDirectory, resolver, getLog());
             ValidationExecutor executor = validationExecutorFactory.createValidationExecutor(context, false, false, validatorsSettings);
             if (executor == null) {
                 throw new MojoExecutionException("No registered validators found!");
@@ -198,7 +200,7 @@ public class ValidateFilesMojo extends A
         for (String relativeFile : scanner.getIncludedFiles()) {
             File absoluteFile = new File(baseDir, relativeFile);
             validationHelper.clearPreviousValidationMessages(buildContext, absoluteFile);
-            getLog().info("Validating file '" + absoluteFile + "'...");
+            getLog().debug("Validating file '" + absoluteFile + "'...");
             try (InputStream input = new FileInputStream(absoluteFile)) {
                 final Collection<ValidationViolation> messages;
                 if (isMetaInf) {

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java Mon Oct 21 10:03:57 2019
@@ -31,7 +31,6 @@ import org.apache.jackrabbit.filevault.m
 import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.ZipArchive;
 import org.apache.jackrabbit.vault.fs.io.ZipStreamArchive;
-import org.apache.jackrabbit.vault.packaging.PackageInfo;
 import org.apache.jackrabbit.vault.util.Constants;
 import org.apache.jackrabbit.vault.validation.ValidationExecutor;
 import org.apache.jackrabbit.vault.validation.ValidationViolation;
@@ -62,16 +61,16 @@ public class ValidatePackageMojo extends
     }
 
     @Override
-    public void doExecute(Collection<PackageInfo> resolvedDependencies) throws MojoExecutionException, MojoFailureException {
+    public void doExecute() throws MojoExecutionException, MojoFailureException {
         try {
-            validatePackage(packageFile, resolvedDependencies);
+            validatePackage(packageFile);
             validationHelper.failBuildInCaseOfViolations(failOnValidationWarnings);
         } catch (IOException | ParserConfigurationException | SAXException e) {
             throw new MojoExecutionException("Could not validate package '" + packageFile + "': " + e.getMessage(), e);
         }
     }
 
-    private void validatePackage(File file, Collection<PackageInfo> resolvedDependencies) throws IOException, ParserConfigurationException, SAXException, MojoExecutionException {
+    private void validatePackage(File file) throws IOException, ParserConfigurationException, SAXException, MojoExecutionException {
         getLog().info("Start validating package '" + file + "'...");
 
         // open file to extract the meta data for the validation context
@@ -79,7 +78,7 @@ public class ValidatePackageMojo extends
         ValidationExecutor executor;
         try (Archive archive = new ZipArchive(file)) {
             archive.open(true);
-            context = new ArchiveValidationContextImpl(archive, file.toPath(), resolver, resolvedDependencies, getLog());
+            context = new ArchiveValidationContextImpl(archive, file.toPath(), resolver, getLog());
             executor = validationExecutorFactory.createValidationExecutor(context, false, enforceRecursiveSubpackageValidation, validatorsSettings);
             if (executor != null) {
                 validationHelper.printUsedValidators(getLog(), executor, context, true);
@@ -116,6 +115,10 @@ public class ValidatePackageMojo extends
         if (entryPath.startsWith(Constants.META_INF)) {
             messages.addAll(executor.validateMetaInf(inputStream, Paths.get(Constants.META_INF).relativize(entryPath), packagePath.resolve(Constants.META_INF)));
         } else if (entryPath.startsWith(Constants.ROOT_DIR)) {
+            // strip off jcr_root
+            Path relativeJcrPath = Paths.get(Constants.ROOT_DIR).relativize(entryPath);
+            messages.addAll(executor.validateJcrRoot(inputStream, relativeJcrPath, packagePath.resolve(Constants.ROOT_DIR)));
+            
             // in case this is a subpackage
             if (entryPath.getFileName().toString().endsWith(VaultMojo.PACKAGE_EXT)) {
                 Path subPackagePath = context.getPackageRootPath().resolve(entryPath);
@@ -133,10 +136,6 @@ public class ValidatePackageMojo extends
                     getLog().debug("Skip validating sub package as no validator is interested in it.");
                 }
                 getLog().info("End validating sub package.");
-            } else {
-                // strip off jcr_root
-                Path relativeJcrPath = Paths.get(Constants.ROOT_DIR).relativize(entryPath);
-                messages.addAll(executor.validateJcrRoot(inputStream, relativeJcrPath, packagePath.resolve(Constants.ROOT_DIR)));
             }
         } else {
             messages.add(new ValidationViolation(ValidationMessageSeverity.WARN, "Found unexpected file outside of " + Constants.ROOT_DIR + " and " + Constants.META_INF, entryPath, packagePath, null, 0,0, null));

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ArchiveValidationContextImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ArchiveValidationContextImpl.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ArchiveValidationContextImpl.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/ArchiveValidationContextImpl.java Mon Oct 21 10:03:57 2019
@@ -47,7 +47,7 @@ public class ArchiveValidationContextImp
      * @param configuration
      * @throws IOException 
      */
-    public ArchiveValidationContextImpl(Archive archive, Path archivePath, DependencyResolver resolver, Collection<PackageInfo> resolvedDependencies, Log log) throws IOException {
+    public ArchiveValidationContextImpl(Archive archive, Path archivePath, DependencyResolver resolver, Log log) throws IOException {
         this.archivePath = archivePath;
         properties = archive.getMetaInf().getProperties();
         if (properties == null) {
@@ -57,7 +57,7 @@ public class ArchiveValidationContextImp
         if (filter == null) {
             throw new IllegalStateException("Archive '" + archivePath + "' does not contain a filter.xml.");
         }
-        this.resolvedDependencies = resolver.resolve(getProperties().getDependencies(), resolvedDependencies, log);
+        this.resolvedDependencies = resolver.resolve(getProperties().getDependencies(), getProperties().getDependenciesLocations(), log);
     }
 
 

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DependencyResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DependencyResolver.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DependencyResolver.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DependencyResolver.java Mon Oct 21 10:03:57 2019
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.filevault.
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
@@ -25,7 +26,9 @@ import java.util.Map;
 
 import javax.annotation.CheckForNull;
 
+import org.apache.jackrabbit.filevault.maven.packaging.MavenBasedPackageDependency;
 import org.apache.jackrabbit.vault.packaging.Dependency;
+import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.PackageInfo;
 import org.apache.jackrabbit.vault.packaging.VersionRange;
 import org.apache.jackrabbit.vault.packaging.impl.DefaultPackageInfo;
@@ -38,55 +41,63 @@ import org.apache.maven.artifact.resolve
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.repository.RepositorySystem;
 
-/**
- * Allows to resolve a {@link Dependency} from the underlying Maven repository (first local, then remote).
- */
+/** Allows to resolve a {@link Dependency} from the underlying Maven repository (first local, then remote). */
 public class DependencyResolver {
 
     private final RepositoryRequest repositoryRequest;
     private final RepositorySystem repositorySystem;
     private final ResolutionErrorHandler resolutionErrorHandler;
     private final Map<Dependency, Artifact> mapPackageDependencyToMavenArtifact;
+    private final Collection<PackageInfo> knownPackageInfos;
 
-    public DependencyResolver(RepositoryRequest repositoryRequest, RepositorySystem repositorySystem, ResolutionErrorHandler resolutionErrorHandler, Map<Dependency, Artifact> mapPackageDependencyToMavenArtifact) {
+    public DependencyResolver(RepositoryRequest repositoryRequest, RepositorySystem repositorySystem,
+            ResolutionErrorHandler resolutionErrorHandler, Map<Dependency, Artifact> mapPackageDependencyToMavenArtifact,
+            Collection<PackageInfo> knownPackageInfos) {
         super();
         this.repositoryRequest = repositoryRequest;
         this.repositorySystem = repositorySystem;
         this.resolutionErrorHandler = resolutionErrorHandler;
         this.mapPackageDependencyToMavenArtifact = mapPackageDependencyToMavenArtifact;
+        this.knownPackageInfos = knownPackageInfos;
     }
 
-    public List<PackageInfo> resolve(Dependency[] dependencies, Collection<PackageInfo> potentiallyResolvedDependencies, Log log) throws IOException {
-        List<PackageInfo> resolvedDependencies = new LinkedList<>(potentiallyResolvedDependencies);
-        
+    public List<PackageInfo> resolve(Dependency[] packageDependencies, Map<PackageId, URI> packageLocations, Log log) throws IOException {
+        List<PackageInfo> packageInfos = new LinkedList<>();
+
         // resolve dependencies
-        for (Dependency dependency : dependencies) {
-            boolean dependencyAlreadyResolved = false;
+        for (Dependency packageDependency : packageDependencies) {
+            PackageInfo packageInfo = null;
             // is it already resolved?
-            for (PackageInfo resolvedDependency : resolvedDependencies) {
-                if (dependency.matches(resolvedDependency.getId())) {
-                    log.debug("Dependency is already resolved from project dependencies: " + dependency);
-                    dependencyAlreadyResolved = true;
-                    break;
+            for (PackageInfo knownPackageInfo : knownPackageInfos) {
+                if (packageDependency.matches(knownPackageInfo.getId())) {
+                    log.debug("Dependency is already resolved from project dependencies: " + packageDependency);
+                    packageInfo = knownPackageInfo;
                 }
             }
-            if (!dependencyAlreadyResolved) {
-                log.info("Trying to resolve dependency '" + dependency + "' from Maven repository");
-                PackageInfo resolvedDependency = resolve(dependency, log);
-                if (resolvedDependency != null) {
-                    resolvedDependencies.add(resolvedDependency);
+            if (packageInfo == null) {
+                for (Map.Entry<PackageId, URI> packageLocation : packageLocations.entrySet()) {
+                    if (packageDependency.matches(packageLocation.getKey())) {
+                        Artifact artifact = MavenBasedPackageDependency.uriToMavenCoordinates(packageLocation.getValue());
+                        packageInfo = resolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), log);
+                    }
                 }
             }
+            if (packageInfo == null) {
+                log.info("Trying to resolve dependency '" + packageDependency + "' from Maven repository");
+                packageInfo = resolve(packageDependency, log);
+            }
+            if (packageInfo != null) {
+                packageInfos.add(packageInfo);
+            }
         }
-        return resolvedDependencies;
+        return packageInfos;
     }
 
     public @CheckForNull PackageInfo resolve(Dependency dependency, Log log) throws IOException {
         // resolving a version range is not supported with Maven API, but only with lower level Aether API (requires Maven 3.5 or newer)
         // https://github.com/eclipse/aether-demo/blob/master/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java
         // therefore do an best effort resolve instead
-        
-        File file = null;
+
         final String groupId;
         final String artifactId;
         Artifact artifact = mapPackageDependencyToMavenArtifact.get(dependency);
@@ -98,25 +109,31 @@ public class DependencyResolver {
             groupId = dependency.getGroup();
             artifactId = dependency.getName();
         }
+        PackageInfo info = null;
         if (dependency.getRange().isLowInclusive()) {
-            file = resolve(groupId, artifactId, dependency.getRange().getLow().toString(), log);
+            info = resolve(groupId, artifactId, dependency.getRange().getLow().toString(), log);
         }
-        if (file == null && dependency.getRange().isHighInclusive()) {
-            file = resolve(groupId, artifactId, dependency.getRange().getHigh().toString(), log);
+        if (info == null && dependency.getRange().isHighInclusive()) {
+            info = resolve(groupId, artifactId, dependency.getRange().getHigh().toString(), log);
         }
-        if (file == null && VersionRange.INFINITE.equals(dependency.getRange())) {
-            file = resolve(groupId, artifactId, Artifact.LATEST_VERSION, log);
+        if (info == null && VersionRange.INFINITE.equals(dependency.getRange())) {
+            info = resolve(groupId, artifactId, Artifact.LATEST_VERSION, log);
         }
-        if (file == null) {
+        if (info == null) {
             log.warn("Could not resolve dependency from any Maven Repository for dependency " + dependency);
             return null;
         }
-        return DefaultPackageInfo.read(file);
+        return info;
     }
 
-    private @CheckForNull File resolve(String groupId, String artifactId, String version, Log log) {
+    private @CheckForNull PackageInfo resolve(String groupId, String artifactId, String version, Log log) throws IOException {
         Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, version, "zip");
-        return resolve(artifact, log);
+        File file = resolve(artifact, log);
+        if (file != null) {
+            return DefaultPackageInfo.read(file);
+        } else {
+            return null;
+        }
     }
 
     private @CheckForNull File resolve(Artifact artifact, Log log) {
@@ -131,11 +148,11 @@ public class DependencyResolver {
             try {
                 resolutionErrorHandler.throwErrors(resolutionRequest, result);
             } catch (ArtifactResolutionException e) {
-                log.warn("Could not resolve artifact '" + artifact +"': " + e.getMessage());
+                // log.warn("Could not resolve artifact '" + artifact +"': " + e.getMessage());
                 log.debug(e);
             }
             return null;
         }
-        
+
     }
 }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/DirectoryValidationContext.java Mon Oct 21 10:03:57 2019
@@ -54,7 +54,7 @@ public class DirectoryValidationContext
     
     private static final Path RELATIVE_PROPERTIES_XML_PATH = Paths.get(Constants.VAULT_DIR, Constants.PROPERTIES_XML);
 
-    public DirectoryValidationContext(@Nonnull final File generatedMetaInfRootDirectory, final File metaInfRootDirectory, DependencyResolver resolver, Collection<PackageInfo> resolvedDependencies, @Nonnull final Log log) throws IOException, ConfigurationException {
+    public DirectoryValidationContext(@Nonnull final File generatedMetaInfRootDirectory, final File metaInfRootDirectory, DependencyResolver resolver, @Nonnull final Log log) throws IOException, ConfigurationException {
         Path propertiesPath = null;
         if (!Constants.META_INF.equals(generatedMetaInfRootDirectory.getName())) {
             throw new IllegalArgumentException("The workDir must end with 'META-INF' but is '" + generatedMetaInfRootDirectory+"'");
@@ -84,7 +84,7 @@ public class DirectoryValidationContext
         }
         filter.load(filterFile);
         
-        this.resolvedDependencies = resolver.resolve(getProperties().getDependencies(), resolvedDependencies, log);
+        this.resolvedDependencies = resolver.resolve(getProperties().getDependencies(), getProperties().getDependenciesLocations(), log);
     }
 
     @Override

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/SubPackageValidationContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/SubPackageValidationContext.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/SubPackageValidationContext.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/validator/impl/context/SubPackageValidationContext.java Mon Oct 21 10:03:57 2019
@@ -28,7 +28,7 @@ public class SubPackageValidationContext
     private final ValidationContext containerPackageContext;
 
     public SubPackageValidationContext(ArchiveValidationContextImpl containerPackageContext, Archive archive, Path archivePath, DependencyResolver resolver, Log log) throws IOException {
-        super(archive, archivePath, resolver, containerPackageContext.getDependenciesMetaInfo(), log);
+        super(archive, archivePath, resolver, log);
         this.containerPackageContext = containerPackageContext;
     }
 

Added: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependencyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependencyTest.java?rev=1868687&view=auto
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependencyTest.java (added)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/MavenBasedPackageDependencyTest.java Mon Oct 21 10:03:57 2019
@@ -0,0 +1,52 @@
+/*
+ * 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.jackrabbit.filevault.maven.packaging;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.jackrabbit.filevault.maven.packaging.SimpleEmbeddedTest.SimpleArtifact;
+import org.apache.maven.artifact.Artifact;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MavenBasedPackageDependencyTest {
+
+    @Test
+    public void testUriToMavenCoordinates() throws URISyntaxException {
+        Assert.assertEquals(new SimpleArtifact("group1", "name1", null, "zip"), MavenBasedPackageDependency.uriToMavenCoordinates(new URI("maven", "group1:name1", null)));
+    }
+
+    @Test
+    public void testMavenCoordinatesToUri() throws URISyntaxException {
+        Assert.assertEquals(new URI("maven", "group1:name1:1.0:zip:classifier1", null), MavenBasedPackageDependency.mavenCoordinatesToUri("group1", "name1", "1.0", "classifier1"));
+        Assert.assertEquals(new URI("maven", "group1:name1:1.0:zip", null), MavenBasedPackageDependency.mavenCoordinatesToUri("group1", "name1", "1.0", null));
+    }
+
+    @Test 
+    public void testMavenCoordinatesToUriRoundtrip() throws URISyntaxException {
+        Artifact artifact = new SimpleArtifact("groupname", "artifactName", null, "zip");
+        Assert.assertEquals(artifact, MavenBasedPackageDependency.uriToMavenCoordinates(MavenBasedPackageDependency.mavenCoordinatesToUri(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier())));
+    }
+    
+    @Test 
+    public void testUriToMavenCoordinatesRoundtrip() throws URISyntaxException {
+        URI uri = new URI("maven", "test-group:some name:1.0:zip", null);
+        Artifact artifact = MavenBasedPackageDependency.uriToMavenCoordinates(uri);
+        Assert.assertEquals(uri, MavenBasedPackageDependency.mavenCoordinatesToUri(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier()));
+    }
+}

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java?rev=1868687&r1=1868686&r2=1868687&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java Mon Oct 21 10:03:57 2019
@@ -95,21 +95,21 @@ public class SimpleEmbeddedTest {
         Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.containsInAnyOrder(artifacts.get(4)));
     }
 
-    private final static class SimpleArtifact extends DefaultArtifact {
-        private SimpleArtifact(String groupId, String artifactId) {
+    public final static class SimpleArtifact extends DefaultArtifact {
+        SimpleArtifact(String groupId, String artifactId) {
             this(groupId, artifactId, null);
         }
 
-        private SimpleArtifact(String groupId, String artifactId, String scope) {
+        SimpleArtifact(String groupId, String artifactId, String scope) {
             this(groupId, artifactId, scope, null);
         }
 
-        private SimpleArtifact(String groupId, String artifactId, String scope, String type) {
+        SimpleArtifact(String groupId, String artifactId, String scope, String type) {
             this(groupId, artifactId, scope, type, null);
         }
         
-        private SimpleArtifact(String groupId, String artifactId, String scope, String type, String classifier) {
-            super(groupId, artifactId, "1.0", scope, type == null ? "jar" : type, classifier == null ? "" : classifier, null);
+        SimpleArtifact(String groupId, String artifactId, String scope, String type, String classifier) {
+            super(groupId, artifactId, "default", scope, type == null ? "jar" : type, classifier == null ? "" : classifier, null);
         }
     }
 }



Mime
View raw message