View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  		// String fetchUrl = getScmProviderUrl(trimToNull(scm.getConnection()));
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  }