1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.repository.aether.internal

File AetherUtils.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
7
3
1
70
36
5
0.71
2.33
3
1.67

Classes

Class Line # Actions
AetherUtils 38 7 0% 5 3
0.7857142778.6%
 

Contributing tests

This file is covered by 21 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.repository.aether.internal;
21   
22    import java.util.regex.Matcher;
23    import java.util.regex.Pattern;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.eclipse.aether.artifact.Artifact;
27    import org.eclipse.aether.artifact.DefaultArtifact;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.ResolveException;
30    import org.xwiki.extension.internal.ExtensionFactory;
31    import org.xwiki.extension.internal.maven.MavenUtils;
32    import org.xwiki.extension.version.internal.DefaultVersion;
33   
34    /**
35    * @version $Id: ed4cab624f2025e1ba9a8ff25db7665873f5d3b5 $
36    * @since 4.0M1
37    */
 
38    public final class AetherUtils
39    {
40    private static final Pattern PARSER_ID = Pattern.compile("([^: ]+):([^: ]+)(:([^: ]+))?");
41   
 
42  103 toggle public static DefaultArtifact createArtifact(String id, String version) throws ResolveException
43    {
44  103 Matcher matcher = PARSER_ID.matcher(id);
45  103 if (!matcher.matches()) {
46  3 throw new InvalidExtensionIdException(
47    "Bad id " + id + ", expected format is <groupId>:<artifactId>[:<classifier>]");
48    }
49   
50  100 return new DefaultArtifact(matcher.group(1), matcher.group(2), StringUtils.defaultString(matcher.group(4), ""),
51    "jar", version);
52    }
53   
 
54  0 toggle public static ExtensionId createExtensionId(Artifact artifact)
55    {
56  0 return createExtensionId(artifact, null);
57    }
58   
59    /**
60    * @since 8.4
61    */
 
62  51 toggle public static ExtensionId createExtensionId(Artifact artifact, ExtensionFactory factory)
63    {
64  51 String extensionId =
65    MavenUtils.toExtensionId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier());
66   
67  51 return new ExtensionId(extensionId, factory != null ? factory.getVersion(artifact.getBaseVersion())
68    : new DefaultVersion(artifact.getBaseVersion()));
69    }
70    }