use of alien4cloud.model.git.CsarGitCheckoutLocation in project alien4cloud by alien4cloud.
the class CsarGitServiceTest method importManyBranchFromGit.
@Test
public void importManyBranchFromGit() {
CsarGitCheckoutLocation alien12Location = new CsarGitCheckoutLocation();
alien12Location.setBranchId("1.2.0");
CsarGitCheckoutLocation alien14Location = new CsarGitCheckoutLocation();
alien14Location.setBranchId("1.4.0");
List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
importLocations.add(alien12Location);
importLocations.add(alien14Location);
String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, false);
List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(2, result.size());
Assert.assertEquals("tosca-normative-types", result.get(0).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN12", result.get(0).getResult().getVersion());
Assert.assertEquals("tosca-normative-types", result.get(1).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN14", result.get(1).getResult().getVersion());
}
use of alien4cloud.model.git.CsarGitCheckoutLocation in project alien4cloud by alien4cloud.
the class CsarGitServiceTest method importManyBranchFromGitAndStoreLocally.
@Test
public void importManyBranchFromGitAndStoreLocally() {
CsarGitCheckoutLocation alien12Location = new CsarGitCheckoutLocation();
alien12Location.setBranchId("1.2.0");
CsarGitCheckoutLocation alien14Location = new CsarGitCheckoutLocation();
alien14Location.setBranchId("1.4.0");
List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
importLocations.add(alien12Location);
importLocations.add(alien14Location);
String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, true);
List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(2, result.size());
Assert.assertEquals("tosca-normative-types", result.get(0).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN12", result.get(0).getResult().getVersion());
Assert.assertEquals("tosca-normative-types", result.get(1).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN14", result.get(1).getResult().getVersion());
// now we re-import
result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(2, result.size());
Assert.assertEquals(ErrorCode.CSAR_ALREADY_INDEXED, result.get(0).getContext().getParsingErrors().get(0).getErrorCode());
Assert.assertEquals(ErrorCode.CSAR_ALREADY_INDEXED, result.get(1).getContext().getParsingErrors().get(0).getErrorCode());
}
use of alien4cloud.model.git.CsarGitCheckoutLocation in project alien4cloud by alien4cloud.
the class CsarGitRepositoryService method update.
/**
* Update informations for a given CsarGitRepository.
*
* @param id The id of the CsarGitRepository to update.
* @param repositoryUrl The new url of the CsarGitRepository
* @param username The username associated to the CsarGitRepository
* @param password The password associated to the CsarGitRepository
* @param importLocations
* @param isStoredLocally
*/
public void update(String id, String repositoryUrl, String username, String password, List<CsarGitCheckoutLocation> importLocations, boolean isStoredLocally) {
validatesRepositoryUrl(repositoryUrl);
CsarGitRepository repositoryToUpdate = getOrFail(id);
if (!repositoryToUpdate.getRepositoryUrl().equals(repositoryUrl)) {
failIfExists(repositoryUrl);
repositoryToUpdate.setRepositoryUrl(repositoryUrl);
}
if (username != null) {
repositoryToUpdate.setUsername(username);
}
if (password != null) {
repositoryToUpdate.setPassword(password);
}
repositoryToUpdate.setStoredLocally(isStoredLocally);
// just merge the existing location hash into new list so that we don't loose this information
for (CsarGitCheckoutLocation location : importLocations) {
CsarGitCheckoutLocation existingLocation = findLocationIn(location, repositoryToUpdate.getImportLocations());
if (existingLocation != null) {
location.setLastImportedHash(existingLocation.getLastImportedHash());
}
}
repositoryToUpdate.setImportLocations(importLocations);
alienDAO.save(repositoryToUpdate);
}
use of alien4cloud.model.git.CsarGitCheckoutLocation in project alien4cloud by alien4cloud.
the class CsarGitService method importFromGitRepository.
/**
* Import Cloud Service ARchives from a git repository.
*
* @param id The id to access the git repository.
* @return The result of the import (that may contains errors etc.)
*/
public List<ParsingResult<Csar>> importFromGitRepository(String id) {
CsarGitRepository csarGitRepository = csarGitRepositoryService.getOrFail(id);
List<ParsingResult<Csar>> results = Lists.newArrayList();
try {
// Iterate over locations (branches, folders etc.) and process the import
for (CsarGitCheckoutLocation csarGitCheckoutLocation : csarGitRepository.getImportLocations()) {
List<ParsingResult<Csar>> result = doImport(csarGitRepository, csarGitCheckoutLocation);
if (result != null) {
results.addAll(result);
}
}
} finally {
// cleanup
Path archiveZipRoot = tempZipDirPath.resolve(csarGitRepository.getId());
Path archiveGitRoot = tempDirPath.resolve(csarGitRepository.getId());
try {
FileUtil.delete(archiveZipRoot);
if (!csarGitRepository.isStoredLocally()) {
FileUtil.delete(archiveGitRoot);
}
} catch (IOException e) {
log.error("Failed to cleanup files after git import.", e);
}
}
return results;
}
use of alien4cloud.model.git.CsarGitCheckoutLocation in project alien4cloud by alien4cloud.
the class CsarGitServiceTest method importArchiveInProperOrder.
@Test
public void importArchiveInProperOrder() {
CsarGitCheckoutLocation normativeTypesMasterLocation = new CsarGitCheckoutLocation();
normativeTypesMasterLocation.setBranchId("1.2.0");
List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
importLocations.add(normativeTypesMasterLocation);
String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, false);
List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
Assert.assertFalse(result.get(0).hasError(ParsingErrorLevel.ERROR));
CsarGitCheckoutLocation testArchiveLocation = new CsarGitCheckoutLocation();
testArchiveLocation.setBranchId("test-order-import");
importLocations.clear();
importLocations.add(testArchiveLocation);
repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/samples.git", "", "", importLocations, false);
List<ParsingResult<Csar>> sampleResult = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(3, sampleResult.size());
for (ParsingResult<Csar> csarParsingResult : sampleResult) {
boolean hasError = csarParsingResult.hasError(ParsingErrorLevel.ERROR);
if (hasError) {
ParserTestUtil.displayErrors(csarParsingResult);
}
Assert.assertFalse(hasError);
}
Assert.assertEquals("test-archive-1", sampleResult.get(0).getResult().getName());
Assert.assertEquals("test-archive-3", sampleResult.get(1).getResult().getName());
Assert.assertEquals("test-archive-2", sampleResult.get(2).getResult().getName());
}
Aggregations