From 9e383dd864e533007d4a9269cca109e758654b9e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 7 Mar 2023 23:28:31 +0100 Subject: [PATCH] Remove GeneratedDirectories GeneratedDirectories is useless as a separate object because its instance methods have a single caller site. Inline the users, so we remove one level of indirection. This exposes the duplication of "generated-sources" name, which needs to be further centralized, depending on how things pan out looking. JIRA: YANGTOOLS-745 Change-Id: Ie7706cda2a661c6c1c7983e0edc67826dc21ee06 Signed-off-by: Robert Varga --- .../plugin/GeneratedDirectories.java | 36 ------------------- .../yang2sources/plugin/YangProvider.java | 5 ++- .../plugin/YangToSourcesProcessor.java | 2 +- 3 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/GeneratedDirectories.java diff --git a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/GeneratedDirectories.java b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/GeneratedDirectories.java deleted file mode 100644 index 49371248d6..0000000000 --- a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/GeneratedDirectories.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang2sources.plugin; - -import java.io.File; -import org.apache.maven.project.MavenProject; - -/** - * Utility to obtain the correct path to generated directories. - * It's important that this does not hard-code "target/" anywhere, but uses - * ${project.build.directory}/, to make target-ide/ possible. - * - * @author Michael Vorburger.ch - */ -class GeneratedDirectories { - - private final File targetGeneratedSources; - - GeneratedDirectories(MavenProject project) { - this.targetGeneratedSources = new File(project.getBuild().getDirectory(), "generated-sources"); - } - - public File getYangServicesDir() { - return new File(targetGeneratedSources, "spi"); - } - - public File getYangDir() { - return new File(targetGeneratedSources, "yang"); - } - -} diff --git a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java index 26fa900b05..87da24b78a 100644 --- a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java +++ b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java @@ -26,7 +26,10 @@ abstract class YangProvider { Collection addYangsToMetaInf(final MavenProject project, final Collection modelsInProject) throws IOException { - final File generatedYangDir = new GeneratedDirectories(project).getYangDir(); + final File generatedYangDir = + // FIXME: why are we generating these in "generated-sources"? At the end of the day YANG files are more + // resources (except we do not them to be subject to filtering) + new File(new File(project.getBuild().getDirectory(), "generated-sources"), "yang"); LOG.debug("Generated dir {}", generatedYangDir); // copy project's src/main/yang/*.yang to ${project.builddir}/generated-sources/yang/META-INF/yang/ diff --git a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java index 58f9a24089..7fc0df6c85 100644 --- a/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java +++ b/plugin/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java @@ -269,7 +269,7 @@ class YangToSourcesProcessor { } // add META_INF/services - File generatedServicesDir = new GeneratedDirectories(project).getYangServicesDir(); + File generatedServicesDir = new File(new File(project.getBuild().getDirectory(), "generated-sources"), "spi"); YangProvider.setResource(generatedServicesDir, project); LOG.debug("{} Yang services files from: {} marked as resources: {}", LOG_PREFIX, generatedServicesDir, META_INF_YANG_SERVICES_STRING_JAR); -- 2.36.6