2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang2sources.plugin;
11 import java.io.IOException;
12 import java.util.Collection;
13 import org.apache.maven.model.Resource;
14 import org.apache.maven.plugin.MojoFailureException;
15 import org.apache.maven.project.MavenProject;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 private static final Logger LOG = LoggerFactory.getLogger(YangProvider.class);
22 void addYangsToMetaInf(final MavenProject project, final File yangFilesRootDir,
23 final Collection<File> excludedFiles) throws MojoFailureException {
25 // copy project's src/main/yang/*.yang to target/generated-sources/yang/META-INF/yang/*.yang
26 File generatedYangDir = new GeneratedDirectories(project).getYangDir();
27 addYangsToMetaInf(project, yangFilesRootDir, excludedFiles, generatedYangDir);
30 private static void addYangsToMetaInf(final MavenProject project, final File yangFilesRootDir,
31 final Collection<File> excludedFiles, final File generatedYangDir) throws MojoFailureException {
33 File withMetaInf = new File(generatedYangDir, YangToSourcesProcessor.META_INF_YANG_STRING);
37 Collection<File> files = Util.listFiles(yangFilesRootDir, excludedFiles);
38 for (File file : files) {
39 org.apache.commons.io.FileUtils.copyFile(file, new File(withMetaInf, file.getName()));
41 } catch (IOException e) {
42 LOG.warn("Failed to generate files into root {}", yangFilesRootDir, e);
43 throw new MojoFailureException("Unable to list yang files into resource folder", e);
46 setResource(generatedYangDir, project);
48 LOG.debug("{} Yang files from: {} marked as resources: {}", YangToSourcesProcessor.LOG_PREFIX, yangFilesRootDir,
49 YangToSourcesProcessor.META_INF_YANG_STRING_JAR);
52 static void setResource(final File targetYangDir, final MavenProject project) {
53 Resource res = new Resource();
54 res.setDirectory(targetYangDir.getPath());
55 project.addResource(res);