001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.weaver; 020 021import java.io.File; 022import java.util.List; 023import java.util.Properties; 024import java.util.ServiceLoader; 025import java.util.logging.Logger; 026 027import org.apache.commons.weaver.lifecycle.WeaveLifecycle; //NOPMD used in javadoc 028import org.apache.commons.weaver.model.WeaveEnvironment; 029import org.apache.commons.weaver.spi.Cleaner; 030 031/** 032 * Implements {@link WeaveLifecycle#CLEAN}. 033 */ 034public class CleanProcessor extends ProcessorBase<Cleaner> { 035 036 /** 037 * Create a new {@link CleanProcessor} instance using the {@link ServiceLoader} mechanism. 038 * 039 * @param classpath not {@code null} 040 * @param target not {@code null} 041 * @param configuration not {@code null} 042 */ 043 public CleanProcessor(final List<String> classpath, final File target, final Properties configuration) { 044 this(classpath, target, configuration, getServiceInstances(Cleaner.class)); 045 } 046 047 /** 048 * Create a new {@link CleanProcessor} instance. 049 * 050 * @param classpath not {@code null} 051 * @param target not {@code null} 052 * @param configuration not {@code null} 053 * @param providers not (@code null} 054 */ 055 public CleanProcessor(final List<String> classpath, final File target, final Properties configuration, 056 final Iterable<Cleaner> providers) { 057 super(classpath, target, configuration, providers); 058 } 059 060 /** 061 * Clean specified targets. 062 */ 063 public void clean() { 064 if (!target.exists()) { 065 log.warning("Target directory " + target + " does not exist; nothing to do!"); 066 } 067 for (final Cleaner cleaner : providers) { 068 final WeaveEnvironment env = new LocalWeaveEnvironment(target, classLoader, configuration, 069 Logger.getLogger(cleaner.getClass().getName())); 070 cleaner.clean(env, finder); 071 } 072 } 073}