1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.maven.spring.function;
17
18 import static org.apache.commons.lang3.StringUtils.trimToNull;
19 import static org.kuali.common.core.scm.maven.MavenScmUrlUtils.getScmProviderUrl;
20 import static org.kuali.common.core.scm.maven.MavenScmUtils.getScmLabelFromMavenScmTag;
21 import static org.kuali.common.maven.spring.MavenAwareUtils.getScmType;
22 import static org.kuali.common.util.base.Precondition.checkNotNull;
23
24 import org.apache.maven.model.Scm;
25 import org.apache.maven.project.MavenProject;
26 import org.kuali.common.core.scm.api.ScmLabel;
27 import org.kuali.common.core.scm.api.ScmProvider;
28 import org.kuali.common.core.scm.maven.ScmInfo;
29
30 import com.google.common.base.Function;
31 import com.google.common.base.Optional;
32
33 public enum MavenProjectToScmInfoFunction implements Function<MavenProject, ScmInfo> {
34 INSTANCE;
35
36 @Override
37 public ScmInfo apply(MavenProject project) {
38 checkNotNull(project, "project");
39 Scm scm = checkNotNull(project.getScm(), "scm");
40 ScmProvider type = getScmType(scm);
41 String pushUrl = getScmProviderUrl(trimToNull(scm.getDeveloperConnection()));
42
43 String browseUrl = trimToNull(scm.getUrl());
44 Optional<ScmLabel> label = getScmLabelFromMavenScmTag(scm.getTag());
45 return ScmInfo.builder().withProvider(type).withUrl(pushUrl).withBrowseUrl(browseUrl).withLabel(label).build();
46 }
47
48 }