-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ggj] feat: support file header (apache license) for outer class defi…
…nition (#157) * add file header comment * gapic unit tests pass * fix bazel rules * clean up * format code * file header class * simplify create header * format * new line after file header * file header is optional for class * add composer test * multiple line comment * multiple line comment for header * rename apache license * move file header addition to gapic class * format * convert change in Composer * add edge unit test * move header addition to composer class * format * feedback * feedback * clean up
- Loading branch information
1 parent
922c3b8
commit 286d0dd
Showing
14 changed files
with
182 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/google/api/generator/gapic/utils/ApacheLicense.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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.generator.gapic.utils; | ||
|
||
import com.google.api.generator.engine.ast.BlockComment; | ||
import com.google.api.generator.engine.ast.CommentStatement; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class ApacheLicense { | ||
private static final String fileHeaderString = | ||
"Copyright 2020 Google LLC\n\n" | ||
+ "Licensed under the Apache License, Version 2.0 (the \"License\");\n" | ||
+ "you may not use this file except in compliance with the License.\n" | ||
+ "You may obtain a copy of the License at\n\n" | ||
+ " https://www.apache.org/licenses/LICENSE-2.0\n\n" | ||
+ "Unless required by applicable law or agreed to in writing, software\n" | ||
+ "distributed under the License is distributed on an \"AS IS\" BASIS,\n" | ||
+ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" | ||
+ "See the License for the specific language governing permissions and\n" | ||
+ "limitations under the License."; | ||
|
||
public static final List<CommentStatement> APACHE_LICENSE_COMMENT_STATEMENT = | ||
Arrays.asList(CommentStatement.withComment(BlockComment.withComment(fileHeaderString))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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.generator.gapic.composer; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
import com.google.api.generator.engine.ast.ClassDefinition; | ||
import com.google.api.generator.engine.ast.ScopeNode; | ||
import com.google.api.generator.engine.writer.JavaWriterVisitor; | ||
import com.google.api.generator.gapic.model.GapicClass; | ||
import com.google.api.generator.gapic.model.GapicClass.Kind; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.Test; | ||
|
||
public class ComposerTest { | ||
@Test | ||
public void gapicClass_addApacheLicense() { | ||
ClassDefinition classDef = | ||
ClassDefinition.builder() | ||
.setPackageString("com.google.showcase.v1beta1.stub") | ||
.setName("EchoStubSettings") | ||
.setScope(ScopeNode.PUBLIC) | ||
.build(); | ||
List<GapicClass> gapicClassWithHeaderList = | ||
Composer.addApacheLicense(Arrays.asList(GapicClass.create(Kind.TEST, classDef))); | ||
JavaWriterVisitor visitor = new JavaWriterVisitor(); | ||
gapicClassWithHeaderList.get(0).classDefinition().accept(visitor); | ||
assertEquals(visitor.write(), EXPECTED_CLASS_STRING); | ||
} | ||
|
||
private static final String EXPECTED_CLASS_STRING = | ||
"/*\n" | ||
+ " * Copyright 2020 Google LLC\n" | ||
+ " *\n" | ||
+ " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" | ||
+ " * you may not use this file except in compliance with the License.\n" | ||
+ " * You may obtain a copy of the License at\n" | ||
+ " *\n" | ||
+ " * https://www.apache.org/licenses/LICENSE-2.0\n" | ||
+ " *\n" | ||
+ " * Unless required by applicable law or agreed to in writing, software\n" | ||
+ " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" | ||
+ " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" | ||
+ " * See the License for the specific language governing permissions and\n" | ||
+ " * limitations under the License.\n" | ||
+ " */\n\n" | ||
+ "package com.google.showcase.v1beta1.stub;\n\n" | ||
+ "public class EchoStubSettings {}\n"; | ||
} |