use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class CopybaraGenerator method generateOriginFilesConfig.
public String generateOriginFilesConfig() {
SortedSet<DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds();
return allDefinitionsChildIds.stream().filter(id -> {
RepositoryFileReference repositoryFileReference = new RepositoryFileReference(id, Constants.LICENSE_FILE_NAME);
if (!repository.exists(repositoryFileReference)) {
return false;
}
try (InputStream inputStream = repository.newInputStream(repositoryFileReference)) {
// we put the whole license file text into a string and check if it starts with "Apache License" after
// trimming it
final String licenceString = "Apache License";
String fileAsString = IOUtils.toString(inputStream);
return fileAsString.trim().startsWith(licenceString);
} catch (IOException e) {
LOGGER.error("Could not create input stream for {}", repositoryFileReference.toString(), e);
return false;
}
}).map(id -> BackendUtils.getPathInsideRepo(id)).collect(Collectors.joining("**\",\n \"", "origin_files = glob([\"README.md\", \"LICENSE\", \"", "**\"]),"));
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class ScriptPluginTest method downloadDeps.
@Test
void downloadDeps() throws Exception {
this.setRevisionTo("origin/plain");
ScriptPlugin scriptPlugin = new ScriptPlugin();
QName originalQName = QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypeimplementations}MySQL-DBMS_5.7-Install-w1");
SelfContainmentPlugin.GeneratedArtifacts generatedArtifacts = scriptPlugin.downloadDependenciesBasedOnArtifact(originalQName, RepositoryFactory.getRepository());
ArtifactTemplateId selfContainedId = new ArtifactTemplateId("http://opentosca.org/add/management/to/instances/nodetypeimplementations", "MySQL-DBMS_5.7-Install-w1-selfContained-w1-wip1", false);
ArtifactTemplateId generatedDAId = new ArtifactTemplateId("http://opentosca.org/add/management/to/instances/nodetypeimplementations", "MySQL-DBMS_5.7-Install-w1-mysql-server-5.7-DA-w1-wip1", false);
assertNotNull(generatedArtifacts);
assertEquals(1, generatedArtifacts.deploymentArtifactsToAdd.size());
assertEquals(generatedDAId.getQName(), generatedArtifacts.deploymentArtifactsToAdd.get(0));
assertEquals(ToscaBaseTypes.archiveArtifactType, repository.getElement(generatedDAId).getType());
assertEquals(originalQName, generatedArtifacts.artifactToReplaceQName);
assertEquals(selfContainedId.getQName(), generatedArtifacts.selfContainedArtifactQName);
assertTrue(repository.exists(selfContainedId));
assertTrue(repository.exists(generatedDAId));
ArtifactTemplateFilesDirectoryId installScriptId = new ArtifactTemplateFilesDirectoryId(selfContainedId);
SortedSet<RepositoryFileReference> containedFiles = repository.getContainedFiles(installScriptId);
assertEquals(1, containedFiles.size());
String targetFileStr = IOUtils.toString(repository.newInputStream(containedFiles.first()), StandardCharsets.UTF_8);
assertEquals("#!/bin/sh\n" + "sudo sh -c \"echo '127.0.0.1' $(hostname) >> /etc/hosts\";\n" + "sudo apt-get update -qq;\n" + "# disables setting the root password with gui, root password etc. will be set in the configure.sh\n" + "export DEBIAN_FRONTEND=noninteractive;\n" + "#//Self-contained CSAR//mysql-server-5.7.tar.gz\n" + "innerCsarRoot=$(find ~ -maxdepth 1 -path \"*.csar\");\n" + "IFS=';' read -ra NAMES <<< \"$DAs\";\n" + "for k in \"${NAMES[@]}\"; do\n" + " IFS=',' read -ra PATH <<< \"$k\"; \n" + " selfContainedDaDirName=$(/usr/bin/sudo /usr/bin/dirname $innerCsarRoot${PATH[1]})\n" + " selfContainedDaName=$(/usr/bin/sudo /usr/bin/basename $innerCsarRoot${PATH[1]})\n" + " selfContainedExtractFolderName=\"${selfContainedDaName%.*}\"\n" + " if [[ \"${PATH[1]}\" == *mysql-server-5.7.tar.gz ]];\n" + " then\n" + " /usr/bin/sudo mkdir -p \"$selfContainedDaDirName/$selfContainedExtractFolderName\"\n" + " /bin/tar -xvzf \"$selfContainedDaDirName/$selfContainedDaName\" -C \"$selfContainedDaDirName/$selfContainedExtractFolderName\"\n" + " break\n" + " fi\n" + "done\n" + "export DEBIAN_FRONTEND=noninteractive\n" + "/usr/bin/sudo -E /usr/bin/dpkg -i -R -E -B \"$selfContainedDaDirName/$selfContainedExtractFolderName\"\n", targetFileStr);
ArtifactTemplateFilesDirectoryId daId = new ArtifactTemplateFilesDirectoryId(generatedDAId);
containedFiles = repository.getContainedFiles(daId);
assertEquals(1, containedFiles.size());
assertEquals("mysql-server-5.7.tar.gz", containedFiles.first().getFileName());
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class OptionResource method onDelete.
@Override
public Response onDelete() {
// delete icon and plan model reference ...
// delete icon
// we use the URL stored in the data instead of the generated URL to be compatible with manually edits
RepositoryFileReference ref = new RepositoryFileReference(this.ssmdId, this.o.getIconUrl());
try {
RepositoryFactory.getRepository().forceDelete(ref);
} catch (IOException e) {
OptionResource.LOGGER.error("Could not remove file", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
// delete plan input
// we use the URL stored in the data instead of the generated URL to be compatible with manually edits
ref = new RepositoryFileReference(this.ssmdId, this.o.getPlanInputMessageUrl());
try {
RepositoryFactory.getRepository().forceDelete(ref);
} catch (IOException e) {
OptionResource.LOGGER.error("Could not remove file", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
// after deleting files, continue with list deletion
return super.onDelete();
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class SelfServicePortalResource method putImage.
@PUT
@Path("image.jpg")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response putImage(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) {
try {
SelfServiceMetaDataUtils.ensureDataXmlExists(RepositoryFactory.getRepository(), this.id);
} catch (IOException e) {
throw new WebApplicationException(e);
}
RepositoryFileReference ref = new RepositoryFileReference(this.id, "image.jpg");
Response response = RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType());
if (StringUtils.isEmpty(this.application.getImageUrl())) {
this.application.setImageUrl("image.jpg");
persist();
}
return response;
}
use of org.eclipse.winery.repository.common.RepositoryFileReference in project winery by eclipse.
the class PlanFileResource method getFileRef.
/**
* Extracts the file reference from plan's planModelReference
*/
@Nullable
private RepositoryFileReference getFileRef() {
if (this.plan.getPlanModelReference() == null) {
return null;
}
String reference = this.plan.getPlanModelReference().getReference();
if (reference == null) {
return null;
}
File f = new File(reference);
return new RepositoryFileReference(this.planId, f.getName());
}
Aggregations