use of alien4cloud.tosca.parser.ParsingResult in project alien4cloud by alien4cloud.
the class ArchiveParserUtil method cleanup.
public static <T> ParsingResult<T> cleanup(ParsingResult<?> result) {
ParsingContext context = new ParsingContext(result.getContext().getFileName());
context.getParsingErrors().addAll(result.getContext().getParsingErrors());
return new ParsingResult<T>(null, context);
}
use of alien4cloud.tosca.parser.ParsingResult in project alien4cloud by alien4cloud.
the class ArchiveUploadService method preParsing.
@ToscaContextual
public Map<CSARDependency, CsarDependenciesBean> preParsing(Set<Path> paths, List<ParsingResult<Csar>> parsingResults) {
Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = Maps.newHashMap();
for (Path path : paths) {
try {
// FIXME cleanup git import archives
ParsingResult<CsarDependenciesBean> parsingResult = parser.parseImports(path);
parsingResult.getResult().setPath(path);
csarDependenciesBeans.put(parsingResult.getResult().getSelf(), parsingResult.getResult());
} catch (ParsingException e) {
ParsingResult<Csar> failedResult = new ParsingResult<>();
failedResult.setContext(new ParsingContext(path.getFileName().toString()));
failedResult.getContext().setParsingErrors(e.getParsingErrors());
parsingResults.add(failedResult);
log.debug("Not able to parse archive, ignoring it", e);
}
}
return csarDependenciesBeans;
}
use of alien4cloud.tosca.parser.ParsingResult 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.tosca.parser.ParsingResult 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());
}
use of alien4cloud.tosca.parser.ParsingResult in project alien4cloud by alien4cloud.
the class CsarGitServiceTest method importOneBranchFromGit.
@Test
public void importOneBranchFromGit() {
CsarGitCheckoutLocation alien12Location = new CsarGitCheckoutLocation();
alien12Location.setBranchId("1.2.0");
List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
importLocations.add(alien12Location);
String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, false);
List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(1, result.size());
Assert.assertEquals("tosca-normative-types", result.get(0).getResult().getName());
}
Aggregations