Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: Java MVVM #1

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8c579b2
Refactoring PHP generation to use the MVVM pattern
garrettjonesgoogle Jul 19, 2016
4f0cba2
Java MVVM
garrettjonesgoogle Jul 19, 2016
046b5c3
InitCodeGenerator: using Name for suggestedName
garrettjonesgoogle Jul 22, 2016
a0fc1d8
breaking apart long method
garrettjonesgoogle Jul 22, 2016
18d8163
Merge branch 'master' into garrettjones-mvvm-java
garrettjonesgoogle Jul 25, 2016
1f22381
Restoring method deleted in merge
garrettjonesgoogle Jul 25, 2016
0c8ce0f
Java surface: adding api call settings members/functions
garrettjonesgoogle Jul 25, 2016
97c4dc9
Java settings surface: adding constructor
garrettjonesgoogle Jul 25, 2016
2c9b303
Java surface: adding page streaming descriptor classes
garrettjonesgoogle Jul 25, 2016
5642c05
Java settings surface: adding bundling descriptors
garrettjonesgoogle Jul 25, 2016
01e30eb
PR feedback
garrettjonesgoogle Jul 26, 2016
5312e23
Merge branch 'master' into garrettjones-mvvm-java
garrettjonesgoogle Jul 26, 2016
c98316a
Fixes after merge
garrettjonesgoogle Jul 26, 2016
6196a6d
Renaming ViewNamer to NameFormatterMixin
garrettjonesgoogle Jul 26, 2016
0bc4f9d
Decomposing type naming functionality further
garrettjonesgoogle Jul 26, 2016
fd76cf9
Partial impl
garrettjonesgoogle Jul 26, 2016
043cda2
Merge branch 'master' into garrettjones-mvvm-java
garrettjonesgoogle Jul 26, 2016
8a06ab9
fixing java code after merge
garrettjonesgoogle Jul 27, 2016
62ac865
Java surface: generating settings builder
garrettjonesgoogle Jul 27, 2016
62b0c92
Java surface: adding license
garrettjonesgoogle Jul 27, 2016
5a15f5a
Java surface: generating service doc
garrettjonesgoogle Jul 27, 2016
376ae35
Addressing PR comments
garrettjonesgoogle Jul 28, 2016
f42e48c
Java surface: generating package-info
garrettjonesgoogle Jul 28, 2016
bd3798d
Merge branch 'master' into garrettjones-mvvm-java
garrettjonesgoogle Jul 28, 2016
60005b2
blank line fixes
garrettjonesgoogle Jul 28, 2016
68c5b2e
Renaming to NameFormatterDelegator
garrettjonesgoogle Jul 28, 2016
c9c9608
Replacing primary Java generation with MVVM, fixing differences
garrettjonesgoogle Jul 29, 2016
177239e
Merge branch 'master' into garrettjones-mvvm-java
garrettjonesgoogle Jul 29, 2016
4cfd08d
generalizing Grpc type names
garrettjonesgoogle Jul 29, 2016
12b02ce
Generalizing container type name
garrettjonesgoogle Jul 29, 2016
f7bb388
Deleting dead code
garrettjonesgoogle Jul 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions src/main/java/com/google/api/codegen/InterfaceListView.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/com/google/api/codegen/ServiceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.google.api.tools.framework.model.Interface;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
* Utility class that provides service configuration data from an Interface.
Expand Down Expand Up @@ -50,7 +50,7 @@ public String getTitle(Interface service) {
* Return a list of scopes for authentication.
*/
public Iterable<String> getAuthScopes(Interface service) {
Set<String> result = new HashSet<>();
Set<String> result = new TreeSet<>();
Service config = service.getModel().getServiceConfig();
Authentication auth = config.getAuthentication();
for (AuthenticationRule rule : auth.getRulesList()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/google/api/codegen/ServiceMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class ServiceMessages {
* Returns true if the message is the empty message.
*/
public boolean isEmptyType(TypeRef type) {
return s_isEmptyType(type);
}

public static boolean s_isEmptyType(TypeRef type) {
return type.isMessage()
&& type.getMessageType().getFullName().equals(Empty.getDescriptor().getFullName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public String addImport(String namespace) {
*/
public Iterable<String> getXmlDocLines(String text, String element) {
// TODO(jonskeet): Convert markdown to XML documentation format.
// https://github.com/googleapis/toolkit/issues/331
List<String> result = new ArrayList<>();
result.add("/// <" + element + ">");
for (String line : Splitter.on(String.format("%n")).split(text)) {
Expand All @@ -65,6 +66,7 @@ public Iterable<String> getXmlDocLines(String text, String element) {
*/
public Iterable<String> getXmlParameterLines(String text, String parameterName) {
// TODO(jonskeet): Convert markdown to XML documentation format.
// https://github.com/googleapis/toolkit/issues/331
List<String> result = new ArrayList<>();
result.add("/// <paramref name=\"" + parameterName + "\">");
for (String line : Splitter.on(String.format("%n")).split(text)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,38 @@
package com.google.api.codegen.gapic;

import com.google.api.codegen.ApiConfig;
import com.google.api.codegen.clientconfig.ClientConfigGapicContext;
import com.google.api.codegen.InterfaceListView;
import com.google.api.codegen.InterfaceView;
import com.google.api.codegen.ProtoFileView;
import com.google.api.codegen.SnippetSetRunner;
import com.google.api.codegen.clientconfig.ClientConfigGapicContext;
import com.google.api.codegen.clientconfig.ClientConfigSnippetSetRunner;
import com.google.api.codegen.csharp.CSharpCodePathMapper;
import com.google.api.codegen.csharp.CSharpGapicContext;
import com.google.api.codegen.csharp.CSharpSnippetSetRunner;
import com.google.api.codegen.go.GoGapicContext;
import com.google.api.codegen.go.GoSnippetSetRunner;
import com.google.api.codegen.java.JavaGapicContext;
import com.google.api.codegen.java.JavaIterableSnippetSetRunner;
import com.google.api.codegen.java.JavaSnippetSetRunner;
import com.google.api.codegen.nodejs.NodeJSGapicContext;
import com.google.api.codegen.nodejs.NodeJSSnippetSetRunner;
import com.google.api.codegen.php.PhpGapicContext;
import com.google.api.codegen.php.PhpSnippetSetRunner;
import com.google.api.codegen.py.PythonGapicContext;
import com.google.api.codegen.py.PythonInterfaceInitializer;
import com.google.api.codegen.py.PythonProtoFileInitializer;
import com.google.api.codegen.py.PythonSnippetSetRunner;
import com.google.api.codegen.rendering.CommonSnippetSetRunner;
import com.google.api.codegen.ruby.RubyGapicContext;
import com.google.api.codegen.ruby.RubySnippetSetRunner;
import com.google.api.codegen.transformer.java.JavaGapicSurfaceTransformer;
import com.google.api.codegen.transformer.php.PhpGapicSurfaceTransformer;
import com.google.api.codegen.util.CommonRenderingUtil;
import com.google.api.codegen.util.java.JavaRenderingUtil;
import com.google.api.tools.framework.model.Interface;
import com.google.api.tools.framework.model.Model;
import com.google.api.tools.framework.model.ProtoFile;

import org.apache.commons.lang3.NotImplementedException;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.NotImplementedException;

/**
* MainGapicProviderFactory creates GapicProvider instances based on an id.
*/
Expand Down Expand Up @@ -119,28 +118,14 @@ public static List<GapicProvider<? extends Object>> defaultCreate(
.setShouldAppendPackage(true)
.build();
GapicProvider<? extends Object> mainProvider =
CommonGapicProvider.<Interface>newBuilder()
.setModel(model)
.setView(new InterfaceView())
.setContext(new JavaGapicContext(model, apiConfig))
.setSnippetSetRunner(
new JavaSnippetSetRunner<Interface>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT))
.setSnippetFileNames(Arrays.asList("java/main.snip", "java/settings.snip"))
.setCodePathMapper(javaPathMapper)
.build();
GapicProvider<? extends Object> packageInfoProvider =
CommonGapicProvider.<Iterable<Interface>>newBuilder()
ViewModelGapicProvider.newBuilder()
.setModel(model)
.setView(new InterfaceListView())
.setContext(new JavaGapicContext(model, apiConfig))
.setSnippetSetRunner(
new JavaIterableSnippetSetRunner<Interface>(
SnippetSetRunner.SNIPPET_RESOURCE_ROOT))
.setSnippetFileNames(Arrays.asList("java/package-info.snip"))
.setCodePathMapper(javaPathMapper)
.setApiConfig(apiConfig)
.setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil()))
.setModelToViewTransformer(new JavaGapicSurfaceTransformer(javaPathMapper))
.build();

return Arrays.<GapicProvider<? extends Object>>asList(mainProvider, packageInfoProvider);
return Arrays.<GapicProvider<? extends Object>>asList(mainProvider);

} else if (id.equals(NODEJS)) {
GapicCodePathMapper nodeJSPathMapper =
Expand Down Expand Up @@ -173,14 +158,11 @@ public static List<GapicProvider<? extends Object>> defaultCreate(
GapicCodePathMapper phpPathMapper =
CommonGapicCodePathMapper.newBuilder().setPrefix("src").build();
GapicProvider<? extends Object> provider =
CommonGapicProvider.<Interface>newBuilder()
ViewModelGapicProvider.newBuilder()
.setModel(model)
.setView(new InterfaceView())
.setContext(new PhpGapicContext(model, apiConfig))
.setSnippetSetRunner(
new PhpSnippetSetRunner<Interface>(SnippetSetRunner.SNIPPET_RESOURCE_ROOT))
.setSnippetFileNames(Arrays.asList("php/main.snip"))
.setCodePathMapper(phpPathMapper)
.setApiConfig(apiConfig)
.setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil()))
.setModelToViewTransformer(new PhpGapicSurfaceTransformer(apiConfig, phpPathMapper))
.build();

GapicCodePathMapper phpClientConfigPathMapper =
Expand Down
122 changes: 122 additions & 0 deletions src/main/java/com/google/api/codegen/gapic/ViewModelGapicProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* Copyright 2016 Google Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.api.codegen.gapic;

import com.google.api.codegen.ApiConfig;
import com.google.api.codegen.rendering.CommonSnippetSetRunner;
import com.google.api.codegen.transformer.ModelToViewTransformer;
import com.google.api.codegen.viewmodel.ViewModel;
import com.google.api.tools.framework.model.Interface;
import com.google.api.tools.framework.model.Model;
import com.google.api.tools.framework.model.stages.Merged;
import com.google.api.tools.framework.snippet.Doc;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class ViewModelGapicProvider implements GapicProvider<Interface> {
private final Model model;
private final ApiConfig apiConfig;
private final CommonSnippetSetRunner snippetSetRunner;
private final ModelToViewTransformer modelToViewTransformer;

private ViewModelGapicProvider(
Model model,
ApiConfig apiConfig,
CommonSnippetSetRunner snippetSetRunner,
ModelToViewTransformer modelToViewTransformer) {
this.model = model;
this.apiConfig = apiConfig;
this.snippetSetRunner = snippetSetRunner;
this.modelToViewTransformer = modelToViewTransformer;
}

@Override
public List<String> getSnippetFileNames() {
return modelToViewTransformer.getTemplateFileNames();
}

@Override
public Map<String, Doc> generate() {
return generate(null);
}

@Override
public Map<String, Doc> generate(String snippetFileName) {
// Establish required stage for generation.
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}

List<ViewModel> surfaceDocs = modelToViewTransformer.transform(model, apiConfig);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}

Map<String, Doc> docs = new TreeMap<>();
for (ViewModel surfaceDoc : surfaceDocs) {
if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) {
continue;
}
Doc doc = snippetSetRunner.generate(surfaceDoc);
if (doc == null) {
// generation failed; failures are captured in the model.
continue;
}
docs.put(surfaceDoc.outputPath(), doc);
}

return docs;
}

public static Builder newBuilder() {
return new Builder();
}

public static class Builder {
private Model model;
private ApiConfig apiConfig;
private CommonSnippetSetRunner snippetSetRunner;
private ModelToViewTransformer modelToViewTransformer;

private Builder() {}

public Builder setModel(Model model) {
this.model = model;
return this;
}

public Builder setApiConfig(ApiConfig apiConfig) {
this.apiConfig = apiConfig;
return this;
}

public Builder setSnippetSetRunner(CommonSnippetSetRunner snippetSetRunner) {
this.snippetSetRunner = snippetSetRunner;
return this;
}

public Builder setModelToViewTransformer(ModelToViewTransformer modelToViewTransformer) {
this.modelToViewTransformer = modelToViewTransformer;
return this;
}

public ViewModelGapicProvider build() {
return new ViewModelGapicProvider(model, apiConfig, snippetSetRunner, modelToViewTransformer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public Iterable<String> getJavaDocLines(String text) {
* firstLinePrefix. Markdown will be translated to javadoc.
*/
public Iterable<String> getJavaDocLinesWithPrefix(String text, String firstLinePrefix) {
// TODO(wgg): convert markdown to javadoc
// TODO: convert markdown to javadoc
// https://github.com/googleapis/toolkit/issues/331
List<String> result = new ArrayList<>();
String linePrefix = firstLinePrefix;
text = JAVADOC_ESCAPER.escape(text);
Expand Down
Loading