All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jolokia.docker.maven.RemoveMojo Maven / Gradle / Ivy

package org.jolokia.docker.maven;/*
 * 
 * Copyright 2014 Roland Huss
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.jolokia.docker.maven.access.DockerAccess;
import org.jolokia.docker.maven.access.DockerAccessException;
import org.jolokia.docker.maven.config.*;
import org.jolokia.docker.maven.service.QueryService;

/**
 * Mojo for removing images. By default only data images are removed. Data images are
 * images without a run configuration.
 *
 * By setting removeAll (property: docker.removeAll) also other
 * images can be removed.
 *
 * In order to explicitely restrict the images to remove, use images to specify a
 * (comma separated) list of images to remove.
 *
 * @author roland
 * @since 23.10.14
 *
 * @goal remove
 * @phase post-integration-test
 */

public class RemoveMojo extends AbstractDockerMojo {

    /**
     * Should all configured images should be removed?
     * 
     * @parameter property = "docker.removeAll" default-value = "false"
     */
    private boolean removeAll;
    
    @Override
    protected void executeInternal(DockerAccess dockerAccess) throws DockerAccessException {
        QueryService queryService = serviceHub.getQueryService();
        
        for (ImageConfiguration image : getImages()) {
            String name = image.getName();
            if (removeAll || image.isDataImage()) {
                if (queryService.hasImage(name)) {
                    if (dockerAccess.removeImage(name,true)) {
                        log.info(image.getDescription() + ": Remove");
                    }
                }
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy