marklogic / java-client-api

Java client for the MarkLogic enterprise NoSQL database
https://docs.marklogic.com/guide/java
Apache License 2.0
59 stars 72 forks source link

Function declaration without endpoint main module does not throw errors #974

Closed georgeajit closed 6 years ago

georgeajit commented 6 years ago

Version of MarkLogic Java Client API

4.1

Version of MarkLogic Server

10.0 nightly build

Java version

1.8

OS and version

Windows / Cygwin

Input: Some code to illustrate the problem, preferably in a state that can be independently reproduced on our end

Installed the latest development-tools jar using

./gradlew marklogic-development-tools:Jar
./gradlew marklogic-development-tools:publishToMavenLocal

Created a dummy gradle project with build.gradle

buildscript{
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url 'http://developer.marklogic.com/maven2' }
        dependencies{
            classpath group: 'com.marklogic', name: 'marklogic-development-tools', version: '4.1'           
        }
    }
}

plugins {
    id 'java'
}

apply plugin: 'java'
apply plugin: com.marklogic.client.tools.gradle.ToolsPlugin

group 'com.marklogic'
version '4.1'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

dependencies {
    compile ('marklogic-development-tools:4.1') 
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
    maven { url 'http://developer.marklogic.com/maven2' }
}

task generateTestProxyWithBothParams(type: com.marklogic.client.tools.gradle.EndpointProxiesGenTask) {
    serviceDeclarationFile = 'src/main/ml-modules/root/simple/service.json'
    javaBaseDirectory='src/main/ml-modules/root/simple/output/'
}

API declaration file:

{
  "functionName" : "incrementer",
  "params" : [ {
    "name" : "input",
    "datatype" : "decimal"
  } ],
  "return" : {
    "datatype" : "string"
  }
}

Service declaration file:

{
  "endpointDirectory" : "/simple/",
  "$javaClass" : "com.marklogic.client.test.Simple"
}

Ran the following task without having a main module:

gradle generateTestProxyWithBothParams

Actual output: What did you observe? What errors did you see? Can you attach the logs? (Java logs, MarkLogic logs)

:generateTestProxyWithBothParamsfunction declaration without endpoint main module: C:\space\b9_0\markLogicDevelopmentToolsFunctionalTest\marklogic-development-tools-functionattests\src\main\ml-modules\root\simple\incrementer.api

It is also seen that the utility function generates an interface without any method declarations inside such as this:

package com.marklogic.client.test;

// IMPORTANT: Do not edit. This file is generated.

import com.marklogic.client.DatabaseClient;

import com.marklogic.client.impl.BaseProxy;

/**
 * Provides a set of operations on the database server
 */
public interface Simple {
    /**
     * Creates a Simple object for executing operations on the database server.
     *
     * The DatabaseClientFactory class can create the DatabaseClient parameter. A single
     * client object can be used for any number of requests and in multiple threads.
     *
     * @param db    provides a client for communicating with the database server
     * @return  an object for session state
     */
    static Simple on(DatabaseClient db) {
        final class SimpleImpl implements Simple {
            private BaseProxy baseProxy;

            private SimpleImpl(DatabaseClient dbClient) {
                baseProxy = new BaseProxy(dbClient, "/simple/");
            }

        }

        return new SimpleImpl(db);
    }

}

Expected output: What specifically did you expect to happen?

Throw an error and may be do not generate the interface.

Alternatives: What else have you tried, actual/expected?

ehennum commented 6 years ago

With this commit, a service directory with service.json but no *.api / endpoint module pairs should throw an error instead of generating an empty proxy class.

georgeajit commented 6 years ago

The task will throw an error now. Here is an output:

:generateTestProxyWithBothParamsfunction declaration without endpoint main module: C:\space\b9_0\markLogicDevelopmentToolsFunctionalTest\marklogic-development-tools-functionattests\src\main\ml-modules\root\simple\incrementer.api
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateTestProxyWithBothParams'.
> no proxy declaration with endpoint module found in /simple/

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
1 actionable task: 1 executed

The issue is fixed.