Skip to content

Commit

Permalink
Merge pull request #39901 from xlight05/revert-apidocs-err-stage
Browse files Browse the repository at this point in the history
[2201.4.1-stage] Revert 'Check compilation errors when generating module doc'
  • Loading branch information
rdulmina authored Mar 19, 2023
2 parents b34f6a6 + 8e6fc78 commit 7a97d7b
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.ballerinalang.docgen.docs.BallerinaDocGenerator;
import picocli.CommandLine;

import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void execute() {
BalaProject balaProject = BalaProject.loadProject(defaultBuilder, balaPath);
try {
BallerinaDocGenerator.generateAPIDocs(balaProject, this.projectPath.toString(), false);
} catch (Exception e) {
} catch (IOException e) {
CommandUtil.printError(this.errStream, e.getMessage(), null, false);
CommandUtil.exitError(this.exitWhenFinish);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void execute(Project project) {
BallerinaDocGenerator.generateAPIDocs(project, outputPath.toString(), false);
this.out.println("Saved to: " + sourceRootPath.relativize(outputPath).toString());

} catch (Exception e) {
} catch (IOException e) {
throw createLauncherException("Unable to generate API Documentation.", e.getCause());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static List<Connector> getProjectConnectors(Project project, boolean deta
* @return
* @throws IOException
*/
public static List<Connector> generateConnectorModel(Project project) throws Exception {
public static List<Connector> generateConnectorModel(Project project) throws IOException {
List<Connector> connectors = new ArrayList<>();
Map<String, ModuleDoc> moduleDocMap = BallerinaDocGenerator.generateModuleDocMap(project);
for (Map.Entry<String, ModuleDoc> moduleDoc : moduleDocMap.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void getProjectConnectorWithFunctionMetadata() throws IOException {
}

@Test(description = "Test connector metadata generation")
public void getConnectorMetadata() throws Exception {
public void getConnectorMetadata() throws IOException {
List<Connector> connectors = ConnectorGenerator.generateConnectorModel(balaProject);
Assert.assertEquals(connectors.size(), 1);
Connector connector = connectors.get(0);
Expand Down Expand Up @@ -152,7 +152,7 @@ public void getConnectorMetadata() throws Exception {
}

@Test(description = "Test connector metadata generation")
public void getFunctionMetadata() throws Exception {
public void getFunctionMetadata() throws IOException {
Map<String, ModuleDoc> moduleDocMap = BallerinaDocGenerator.generateModuleDocMap(balaProject);
ModuleDoc testConnector = moduleDocMap.get(moduleName);
SyntaxTree st = testConnector.syntaxTreeMap.get("main.bal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.gson.GsonBuilder;
import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.compiler.syntax.tree.SyntaxTree;
import io.ballerina.projects.DiagnosticResult;
import io.ballerina.projects.Document;
import io.ballerina.projects.Project;
import io.ballerina.projects.util.ProjectConstants;
Expand Down Expand Up @@ -190,7 +189,7 @@ public static void mergeApiDocs(Path apiDocsRoot) {
* @param excludeUI Exclude UI elements being copied/generated
*/
public static void generateAPIDocs(Project project, String output, boolean excludeUI)
throws Exception {
throws IOException {
Map<String, ModuleDoc> moduleDocMap = generateModuleDocMap(project);
ModuleLibrary moduleLib = new ModuleLibrary();
moduleLib.modules = getDocsGenModel(moduleDocMap, project.currentPackage().packageOrg().toString(),
Expand Down Expand Up @@ -393,7 +392,7 @@ private static SearchJson genSearchJson(ModuleLibrary moduleLib) {
* @return a map of module names and their ModuleDoc.
*/
public static Map<String, ModuleDoc> generateModuleDocMap(io.ballerina.projects.Project project)
throws Exception {
throws IOException {
Map<String, ModuleDoc> moduleDocMap = new HashMap<>();
for (io.ballerina.projects.Module module : project.currentPackage().modules()) {
String moduleName;
Expand All @@ -420,11 +419,6 @@ public static Map<String, ModuleDoc> generateModuleDocMap(io.ballerina.projects.
});
// we cannot remove the module.getCompilation() here since the semantic model is accessed
// after the code gen phase here. package.getCompilation() throws an IllegalStateException
DiagnosticResult diagnostics = module.getCompilation().diagnostics();
if (diagnostics.hasErrors()) {
throw new Exception("API documentation generation failed due to compilation errors: " +
diagnostics.errors().toString());
}
ModuleDoc moduleDoc = new ModuleDoc(moduleMdText, resources,
syntaxTreeMap, module.getCompilation().getSemanticModel(), module.isDefaultModule());
moduleDocMap.put(moduleName, moduleDoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setup() throws IOException {
}

@Test
public void generatingDocsForBalaTest() throws Exception {
public void generatingDocsForBalaTest() throws IOException {
Path balaPath = this.resourceDir.resolve("balas").resolve("foo-fb-any-1.3.5.bala");

ProjectEnvironmentBuilder defaultBuilder = ProjectEnvironmentBuilder.getDefaultBuilder();
Expand All @@ -75,22 +75,6 @@ public void generatingDocsForBalaTest() throws Exception {
Assert.assertTrue(sfWorldModuleApiDocsJsonAsString.contains("PersonZ"), "PersonZ class is missing");
}

@Test
public void generatingDocsForBalaWithCompileErrors() {
Path balaPath = this.resourceDir.resolve("balas").resolve("foo-fb-any-1.3.6.bala");
ProjectEnvironmentBuilder defaultBuilder = ProjectEnvironmentBuilder.getDefaultBuilder();
defaultBuilder.addCompilationCacheFactory(TempDirCompilationCache::from);
BalaProject balaProject = BalaProject.loadProject(defaultBuilder, balaPath);

try {
BallerinaDocGenerator.generateAPIDocs(balaProject, this.docsPath.toString(), true);
} catch (Exception e) {
Assert.assertEquals(e.getMessage(), "API documentation generation failed due to compilation " +
"errors: [ERROR [foo/fb.errors/1.3.6::world.bal:(24:16,24:24)] incompatible types: expected " +
"'string', found 'int']");
}
}

@Test
public void testDocutilsGetSummary() {
String description = "Connects the fb communication services!@#$%^&*()-=+_';/?><|\"";
Expand All @@ -107,7 +91,7 @@ public void testDocutilsGetSummary() {
}

@Test
public void generatingDocsForBalaWithAnnotationTest() throws Exception {
public void generatingDocsForBalaWithAnnotationTest() throws IOException {
Path balaPath = this.resourceDir.resolve("balas").resolve("bar-testannotation-any-1.0.0.bala");
ProjectEnvironmentBuilder defaultBuilder = ProjectEnvironmentBuilder.getDefaultBuilder();
defaultBuilder.addCompilationCacheFactory(TempDirCompilationCache::from);
Expand All @@ -122,7 +106,7 @@ public void generatingDocsForBalaWithAnnotationTest() throws Exception {
}

@Test
public void generatingDocsForBalaWithAnnotationTest2() throws Exception {
public void generatingDocsForBalaWithAnnotationTest2() throws IOException {
Path balaPath = this.resourceDir.resolve("balas").resolve("ballerina-http-java11-2.4.0.bala");
ProjectEnvironmentBuilder defaultBuilder = ProjectEnvironmentBuilder.getDefaultBuilder();
defaultBuilder.addCompilationCacheFactory(TempDirCompilationCache::from);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class BuildLangLib {
static boolean skipBootstrap = false;


public static void main(String[] args) throws Exception {
public static void main(String[] args) throws IOException {
PrintStream out = System.out;
try {
projectDir = Paths.get(args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand All @@ -48,7 +49,7 @@ public class DeprecatedAnnotationTest {
private Module testModule;

@BeforeClass
public void setup() throws Exception {
public void setup() throws IOException {
String sourceRoot =
"test-src" + File.separator + "documentation" + File.separator + "deprecated_annotation_project";
io.ballerina.projects.Project project = BCompileUtil.loadProject(sourceRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -44,7 +45,7 @@ public class DocModelTest {
private Module testModule;

@BeforeClass
public void setup() throws Exception {
public void setup() throws IOException {
String sourceRoot = "test-src" + File.separator + "documentation" + File.separator + "docerina_project";
io.ballerina.projects.Project project = BCompileUtil.loadProject(sourceRoot);
Map<String, ModuleDoc> moduleDocMap = BallerinaDocGenerator.generateModuleDocMap(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand All @@ -39,7 +40,7 @@ public class ErrorsTest {
private Module testModule;

@BeforeClass
public void setup() throws Exception {
public void setup() throws IOException {
String sourceRoot =
"test-src" + File.separator + "documentation" + File.separator + "errors_project";
io.ballerina.projects.Project project = BCompileUtil.loadProject(sourceRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand All @@ -52,7 +53,7 @@ public class FieldLevelDocsTest {
private BClass employeeCls;

@BeforeClass
public void setup() throws Exception {
public void setup() throws IOException {
String sourceRoot =
"test-src" + File.separator + "documentation" + File.separator + "record_object_fields_project";
io.ballerina.projects.Project project = BCompileUtil.loadProject(sourceRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -63,7 +64,7 @@ public class MultilineDocsTest {
"```" + System.lineSeparator() + "\n";

@BeforeClass
public void setup() throws Exception {
public void setup() throws IOException {
String sourceRoot =
"test-src" + File.separator + "documentation" + File.separator + "multi_line_docs_project";
io.ballerina.projects.Project project = BCompileUtil.loadProject(sourceRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand All @@ -40,7 +41,7 @@ public class ObjectFieldDefaultValueTest {
private List<BClass> bClasses;

@BeforeClass
public void setup() throws Exception {
public void setup() throws IOException {
String sourceRoot =
"test-src" + File.separator + "documentation" + File.separator + "default_value_initialization";
io.ballerina.projects.Project project = BCompileUtil.loadProject(sourceRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ public isolated function inlineRecordReturn(CommonResponse prvtRecord, Subscript
decimal longitude;
json...;
|} {
return {
latitude: "",
longitude: 0
};
}

# Anydata type apram
public type AnydataType anydata;
@typeParam
type AnydataType anydata;

# A type param
public type TypeParam any|error;
@typeParam
type TypeParam any|error;

# Built-in subtype of string containing strings of length 1.
public type Char string;
@builtinSubtype
type Char string;

public isolated function cancelFuture(future<any|error> f) returns () {
public isolated function cancelFuture(future<any|error> f) returns {
}

# Docs for tuple module variable.
Expand Down

0 comments on commit 7a97d7b

Please sign in to comment.