View Javadoc
1   package com.soebes.maven.extensions.incremental;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.assertj.core.api.Assertions.assertThat;
23  
24  import java.io.File;
25  import java.util.List;
26  
27  import org.apache.maven.scm.ScmException;
28  import org.apache.maven.scm.ScmFile;
29  import org.apache.maven.scm.ScmFileSet;
30  import org.apache.maven.scm.command.status.StatusScmResult;
31  import org.apache.maven.scm.manager.NoSuchScmProviderException;
32  import org.apache.maven.scm.manager.ScmManager;
33  import org.apache.maven.scm.repository.ScmRepository;
34  import org.apache.maven.scm.repository.ScmRepositoryException;
35  import org.codehaus.plexus.PlexusTestCase;
36  import org.slf4j.Logger;
37  import org.slf4j.LoggerFactory;
38  
39  public class SecondTest extends PlexusTestCase {
40      private final Logger LOGGER = LoggerFactory.getLogger(getClass());
41  
42      protected void setUp() throws Exception {
43  	super.setUp();
44  	super.setupContainer();
45      }
46  
47      protected void tearDown() throws Exception {
48  	super.tearDown();
49      }
50  
51      private List<ScmFile> getChangedFiles() throws Exception {
52  	ScmManager scmManager = (ScmManager) lookup(ScmManager.ROLE);
53  
54  	assertThat(scmManager).isNotNull();
55  
56  	ScmRepository repository = null;
57  	try {
58  	    // TODO: This can be extracted from the pom file (scm connection).
59  	    repository = scmManager.makeScmRepository("scm:git:ssh://git@github.com:khmarbaise/supose.git");
60  	} catch (ScmRepositoryException | NoSuchScmProviderException e) {
61  	    e.printStackTrace();
62  	}
63  
64  	StatusScmResult result = null;
65  	try {
66  	    result = scmManager.status(repository, new ScmFileSet(new File("/Users/kama/ws-git/supose")));
67  	} catch (ScmException e) {
68  	    e.printStackTrace();
69  	}
70  
71  	List<ScmFile> changedFiles = result.getChangedFiles();
72  	for (ScmFile scmFile : changedFiles) {
73  	    LOGGER.info(" file:" + scmFile.getPath() + " " + scmFile.getStatus());
74  	}
75  	return changedFiles;
76  
77      }
78  
79      public void testShouldGetChangesFiles() throws Exception {
80  	getChangedFiles();
81      }
82  
83  }