Remove sal-rest-docgen-maven 30/96630/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 23 Jun 2021 13:44:30 +0000 (15:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 23 Jun 2021 13:45:12 +0000 (15:45 +0200)
Static generator for swagger documentation is not used anywhere and it
is an utter mess. Remove it.

JIRA: MDSAL-232
Change-Id: I8a131f22f7f5d01aa0d66116413ded822fda1341
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
artifacts/pom.xml
restconf/pom.xml
restconf/sal-rest-docgen-maven/pom.xml [deleted file]
restconf/sal-rest-docgen-maven/src/main/java/org/opendaylight/netconf/sal/rest/doc/maven/StaticDocGenerator.java [deleted file]

index 3a1adc3df6fc0802e421907dccdcb892be4db162..397155894290ffcbb99230895463616fec8941a8 100644 (file)
                 <artifactId>sal-rest-docgen</artifactId>
                 <version>${project.version}</version>
             </dependency>
-            <dependency>
-                <groupId>${project.groupId}</groupId>
-                <artifactId>sal-rest-docgen-maven</artifactId>
-                <version>${project.version}</version>
-            </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>sal-restconf-broker</artifactId>
index d35762429acb501fc892a31261f5f28e5c8818a4..ef55c0ec921bebbfd4b1e543561a7fa37c47b494 100644 (file)
@@ -35,7 +35,6 @@
         <module>restconf-nb-rfc8040</module>
         <module>sal-rest-connector-config</module>
         <module>sal-rest-docgen</module>
-        <module>sal-rest-docgen-maven</module>
         <module>wadl-generator</module>
         <module>websocket-client</module>
         <!--
diff --git a/restconf/sal-rest-docgen-maven/pom.xml b/restconf/sal-rest-docgen-maven/pom.xml
deleted file mode 100644 (file)
index 9bd2d55..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
- Copyright (c) 2013 Cisco Systems, 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
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>org.opendaylight.netconf</groupId>
-        <artifactId>netconf-parent</artifactId>
-        <version>2.0.0-SNAPSHOT</version>
-        <relativePath>../../parent</relativePath>
-    </parent>
-
-    <artifactId>sal-rest-docgen-maven</artifactId>
-    <packaging>jar</packaging>
-
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.apache.maven</groupId>
-                <artifactId>maven-core</artifactId>
-                <version>3.2.5</version>
-                <scope>provided</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-databind</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.maven</groupId>
-            <artifactId>maven-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-maven-plugin-spi</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>sal-rest-docgen</artifactId>
-        </dependency>
-    </dependencies>
-</project>
diff --git a/restconf/sal-rest-docgen-maven/src/main/java/org/opendaylight/netconf/sal/rest/doc/maven/StaticDocGenerator.java b/restconf/sal-rest-docgen-maven/src/main/java/org/opendaylight/netconf/sal/rest/doc/maven/StaticDocGenerator.java
deleted file mode 100644 (file)
index beb3db6..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, 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.netconf.sal.rest.doc.maven;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import javax.ws.rs.core.UriInfo;
-import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl;
-import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.URIType;
-import org.opendaylight.netconf.sal.rest.doc.impl.BaseYangSwaggerGeneratorDraft02;
-import org.opendaylight.netconf.sal.rest.doc.swagger.Resource;
-import org.opendaylight.netconf.sal.rest.doc.swagger.ResourceList;
-import org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
-import org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class gathers all yang defined {@link Module}s and generates Swagger compliant documentation.
- */
-public class StaticDocGenerator extends BaseYangSwaggerGeneratorDraft02
-        implements BasicCodeGenerator {
-    private static final Logger LOG = LoggerFactory.getLogger(StaticDocGenerator.class);
-
-    private static final String DEFAULT_OUTPUT_BASE_DIR_PATH = "target" + File.separator + "generated-resources"
-        + File.separator + "swagger-api-documentation";
-
-    public StaticDocGenerator() {
-        super(Optional.empty());
-    }
-
-    @Override
-    @SuppressFBWarnings("DM_DEFAULT_ENCODING")
-    public Collection<File> generateSources(final EffectiveModelContext context, final File outputBaseDir,
-            final Set<Module> currentModules, final ModuleResourceResolver moduleResourcePathResolver)
-                    throws IOException {
-        final List<File> result = new ArrayList<>();
-
-        // Create Base Directory
-        final File outputDir;
-        if (outputBaseDir == null) {
-            outputDir = new File(DEFAULT_OUTPUT_BASE_DIR_PATH);
-        } else {
-            outputDir = outputBaseDir;
-        }
-
-        if (!outputDir.mkdirs()) {
-            throw new IOException("Could not create directory " + outputDir);
-        }
-
-        // Create Resources directory
-        final File resourcesDir = new File(outputDir, "resources");
-        if (!resourcesDir.mkdirs()) {
-            throw new IOException("Could not create directory " + resourcesDir);
-        }
-
-        // Create JS file
-        final File resourcesJsFile = new File(outputDir, "resources.js");
-        if (!resourcesJsFile.createNewFile()) {
-            LOG.info("File {} already exists.", resourcesJsFile);
-        }
-
-        try (BufferedWriter bufferedWriter =
-                new BufferedWriter(new FileWriter(resourcesJsFile, StandardCharsets.UTF_8))) {
-            final ObjectMapper mapper = new ObjectMapper();
-            mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
-
-            // Write resource listing to JS file
-            final ResourceList resourceList = super.getResourceListing(null, context, "", URIType.DRAFT02,
-                    ApiDocServiceImpl.OAversion.V2_0);
-            String resourceListJson = mapper.writeValueAsString(resourceList);
-            resourceListJson = resourceListJson.replace("\'", "\\\'").replace("\\n", "\\\\n");
-            bufferedWriter.write("function getSpec() {\n\treturn \'" + resourceListJson + "\';\n}\n\n");
-
-            // Write resources/APIs to JS file and to disk
-            bufferedWriter.write("function jsonFor(resource) {\n\tswitch(resource) {\n");
-            for (final Resource resource : resourceList.getApis()) {
-                final int revisionIndex = resource.getPath().indexOf('(');
-                final String name = resource.getPath().substring(0, revisionIndex);
-                final String revision =
-                        resource.getPath().substring(revisionIndex + 1, resource.getPath().length() - 1);
-                final SwaggerObject swaggerObject = super.getApiDeclaration(name, revision, null, context, "",
-                    URIType.DRAFT02, ApiDocServiceImpl.OAversion.V2_0);
-                String json = mapper.writeValueAsString(swaggerObject);
-                // Manually insert models because org.json.JSONObject cannot be serialized by ObjectMapper
-                json = json.replace(
-                        "\"models\":{}", "\"models\":"
-                                + swaggerObject.getDefinitions().toString().replace("\\\"", "\""));
-                // Escape single quotes and new lines
-                json = json.replace("\'", "\\\'").replace("\\n", "\\\\n");
-                bufferedWriter.write("\t\tcase \"" + name + "(" + revision + ")\": return \'" + json + "\';\n");
-
-                final File resourceFile = new File(resourcesDir, name + "(" + revision + ").json");
-
-                try (BufferedWriter resourceFileWriter =
-                        new BufferedWriter(new FileWriter(resourceFile, StandardCharsets.UTF_8))) {
-                    resourceFileWriter.write(json);
-                }
-
-                result.add(resourceFile);
-            }
-            bufferedWriter.write("\t}\n\treturn \"\";\n}");
-        }
-
-        result.add(resourcesJsFile);
-        return result;
-    }
-
-    @Override
-    public String generatePath(final UriInfo uriInfo, final String name, final String revision) {
-        if (uriInfo == null) {
-            return name + "(" + revision + ")";
-        }
-        return super.generatePath(uriInfo, name, revision);
-    }
-
-    @Override
-    public void setAdditionalConfig(final Map<String, String> additionalConfig) {
-        // No-op, although it should not be
-    }
-
-    @Override
-    public void setResourceBaseDir(final File resourceBaseDir) {
-        // No-op, although it should not be
-    }
-}