BUG-2288: DOMNotification API
[controller.git] / opendaylight / config / yang-test-plugin / src / main / java / org / opendaylight / controller / config / yang / test / plugin / DeleteSources.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.yang.test.plugin;
9
10 import org.apache.maven.plugin.AbstractMojo;
11 import org.apache.maven.plugin.MojoExecutionException;
12 import org.apache.maven.plugin.MojoFailureException;
13
14 import java.io.File;
15
16 /**
17  * Delete all Module/ModuleFactory sources
18  *
19  * @goal delete-sources
20  *
21  * @phase initialize
22  */
23 public class DeleteSources extends AbstractMojo{
24     /**
25      * @parameter expression="${project.build.sourceDirectory}"
26      * @readOnly
27      * @required
28      */
29     private File directory;
30
31     @Override
32     public void execute() throws MojoExecutionException, MojoFailureException {
33         if (directory == null || !directory.exists()) {
34             super.getLog().error("Directory does not exists.");
35         }
36         File sourceDirectory = new File(directory.getPath() + Util.replaceDots(".org.opendaylight.controller.config.yang.test.impl"));
37         if (sourceDirectory == null || !sourceDirectory.exists()) {
38             super.getLog().error("Source directory does not exists " + sourceDirectory.getPath());
39         }
40         File[] sourceFiles = sourceDirectory.listFiles();
41         for (File sourceFile: sourceFiles) {
42             if(sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) {
43                 super.getLog().debug("Source file deleted: " + sourceFile.getName());
44                 sourceFile.delete();
45             }
46         }
47     }
48 }