Search in sources :

Example 1 with InvalidPathException

use of org.eclipse.jgit.dircache.InvalidPathException in project winery by eclipse.

the class FilebasedRepository method rename.

@Override
public void rename(DefinitionsChildId oldId, DefinitionsChildId newId) throws IOException {
    Objects.requireNonNull(oldId);
    Objects.requireNonNull(newId);
    if (oldId.equals(newId)) {
        // we do not do anything - even not throwing an error
        return;
    }
    Definitions definitions = this.getDefinitions(oldId);
    RepositoryFileReference oldRef = BackendUtils.getRefOfDefinitions(oldId);
    RepositoryFileReference newRef = BackendUtils.getRefOfDefinitions(newId);
    // oldRef points to the definitions file,
    // getParent() returns the directory
    // we need toFile(), because we rely on FileUtils.moveDirectoryToDirectory
    File oldDir = this.id2AbsolutePath(oldRef.getParent()).toFile();
    File newDir = this.id2AbsolutePath(newRef.getParent()).toFile();
    org.apache.commons.io.FileUtils.moveDirectory(oldDir, newDir);
    // Update definitions and store it
    // This also updates the definitions of componentInstanceResource
    BackendUtils.updateWrapperDefinitions(newId, definitions);
    // This works, because the definitions object here is the same as the definitions object treated at copyIdToFields
    // newId has to be passed, because the id is final at AbstractComponentInstanceResource
    BackendUtils.copyIdToFields((HasIdInIdOrNameField) definitions.getElement(), newId);
    try {
        BackendUtils.persist(definitions, newRef, MediaTypes.MEDIATYPE_TOSCA_DEFINITIONS);
    } catch (InvalidPathException e) {
        LOGGER.debug("Invalid path during write", e);
    // QUICK FIX
    // Somewhere, the first letter is deleted --> /odetypes/http%3A%2F%2Fwww.example.org%2F05/
    // We just ignore it for now
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) Definitions(org.eclipse.winery.model.tosca.Definitions) InvalidPathException(org.eclipse.jgit.dircache.InvalidPathException)

Example 2 with InvalidPathException

use of org.eclipse.jgit.dircache.InvalidPathException in project winery by eclipse.

the class AbstractFileBasedRepository method duplicate.

protected void duplicate(DefinitionsChildId oldId, DefinitionsChildId newId, boolean moveOnly) throws IOException {
    Objects.requireNonNull(oldId);
    Objects.requireNonNull(newId);
    if (oldId.equals(newId)) {
        // we do not do anything - even not throwing an error
        return;
    }
    TDefinitions definitions = this.getDefinitions(oldId);
    RepositoryFileReference oldRef = BackendUtils.getRefOfDefinitions(oldId);
    RepositoryFileReference newRef = BackendUtils.getRefOfDefinitions(newId);
    // oldRef points to the definitions file,
    // getParent() returns the directory
    // we need toFile(), because we rely on FileUtils.moveDirectoryToDirectory
    File oldDir = this.id2AbsolutePath(oldRef.getParent()).toFile();
    File newDir = this.id2AbsolutePath(newRef.getParent()).toFile();
    if (moveOnly) {
        org.apache.commons.io.FileUtils.moveDirectory(oldDir, newDir);
    } else {
        org.apache.commons.io.FileUtils.copyDirectory(oldDir, newDir);
    }
    // Update definitions and store it
    // This also updates the definitions of componentInstanceResource
    BackendUtils.updateWrapperDefinitions(newId, definitions, this);
    // This works, because the definitions object here is the same as the definitions object treated at copyIdToFields
    // newId has to be passed, because the id is final at AbstractComponentInstanceResource
    BackendUtils.copyIdToFields((HasIdInIdOrNameField) definitions.getElement(), newId);
    try {
        BackendUtils.persist(this, newId, definitions);
    } catch (InvalidPathException e) {
        LOGGER.debug("Invalid path during write", e);
    // QUICK FIX
    // Somewhere, the first letter is deleted --> /odetypes/http%3A%2F%2Fwww.example.org%2F05/
    // We just ignore it for now
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) File(java.io.File) InvalidPathException(org.eclipse.jgit.dircache.InvalidPathException)

Example 3 with InvalidPathException

use of org.eclipse.jgit.dircache.InvalidPathException in project gerrit by GerritCodeReview.

the class ChangeEditModifier method createNewTree.

private static ObjectId createNewTree(Repository repository, RevCommit baseCommit, List<TreeModification> treeModifications) throws BadRequestException, IOException, InvalidChangeOperationException {
    if (treeModifications.isEmpty()) {
        return baseCommit.getTree();
    }
    ObjectId newTreeId;
    try {
        TreeCreator treeCreator = TreeCreator.basedOn(baseCommit);
        treeCreator.addTreeModifications(treeModifications);
        newTreeId = treeCreator.createNewTreeAndGetId(repository);
    } catch (InvalidPathException e) {
        throw new BadRequestException(e.getMessage());
    }
    if (ObjectId.isEqual(newTreeId, baseCommit.getTree())) {
        throw new InvalidChangeOperationException("no changes were made");
    }
    return newTreeId;
}
Also used : InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) TreeCreator(com.google.gerrit.server.edit.tree.TreeCreator) ObjectId(org.eclipse.jgit.lib.ObjectId) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) InvalidPathException(org.eclipse.jgit.dircache.InvalidPathException)

Aggregations

InvalidPathException (org.eclipse.jgit.dircache.InvalidPathException)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 TreeCreator (com.google.gerrit.server.edit.tree.TreeCreator)1 InvalidChangeOperationException (com.google.gerrit.server.project.InvalidChangeOperationException)1 File (java.io.File)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)1 Definitions (org.eclipse.winery.model.tosca.Definitions)1 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)1 RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)1