diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/GerritApi.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/GerritApi.java index 844807b94d..d071e2100e 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/GerritApi.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/GerritApi.java @@ -16,8 +16,25 @@ package com.google.gerrit.extensions.api; import com.google.gerrit.extensions.api.changes.Changes; import com.google.gerrit.extensions.api.projects.Projects; +import com.google.gerrit.extensions.restapi.NotImplementedException; public interface GerritApi { public Changes changes(); public Projects projects(); + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements GerritApi { + @Override + public Changes changes() { + throw new NotImplementedException(); + } + + @Override + public Projects projects() { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ChangeApi.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ChangeApi.java index f0a9e4d7f8..3382b765df 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ChangeApi.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ChangeApi.java @@ -16,6 +16,7 @@ package com.google.gerrit.extensions.api.changes; import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ListChangesOption; +import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.RestApiException; import java.util.EnumSet; @@ -45,4 +46,85 @@ public interface ChangeApi { ChangeInfo get() throws RestApiException; /** {@code get} with {@link ListChangesOption} set to NONE. */ ChangeInfo info() throws RestApiException; + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements ChangeApi { + @Override + public String id() { + throw new NotImplementedException(); + } + + @Override + public RevisionApi current() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public RevisionApi revision(int id) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public RevisionApi revision(String id) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void abandon() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void abandon(AbandonInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void restore() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void restore(RestoreInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeApi revert() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeApi revert(RevertInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void addReviewer(AddReviewerInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void addReviewer(String in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeInfo get(EnumSet options) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeInfo get() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeInfo info() throws RestApiException { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/Changes.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/Changes.java index 48e9fd3f43..9debb6b132 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/Changes.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/Changes.java @@ -14,6 +14,7 @@ package com.google.gerrit.extensions.api.changes; +import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.RestApiException; public interface Changes { @@ -21,4 +22,25 @@ public interface Changes { ChangeApi id(String triplet) throws RestApiException; ChangeApi id(String project, String branch, String id) throws RestApiException; + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements Changes { + @Override + public ChangeApi id(int id) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeApi id(String triplet) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeApi id(String project, String branch, String id) throws RestApiException { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java index dc2a9a7285..a2a96f9359 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java @@ -14,6 +14,7 @@ package com.google.gerrit.extensions.api.changes; +import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.RestApiException; public interface RevisionApi { @@ -27,4 +28,50 @@ public interface RevisionApi { ChangeApi cherryPick(CherryPickInput in) throws RestApiException; ChangeApi rebase() throws RestApiException; boolean canRebase(); + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements RevisionApi { + @Override + public void delete() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void review(ReviewInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void submit() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void submit(SubmitInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public void publish() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeApi cherryPick(CherryPickInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ChangeApi rebase() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public boolean canRebase() { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/BranchApi.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/BranchApi.java index 2f1533f6b0..f88a2cb90f 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/BranchApi.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/BranchApi.java @@ -14,8 +14,20 @@ package com.google.gerrit.extensions.api.projects; +import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.RestApiException; public interface BranchApi { BranchApi create(BranchInput in) throws RestApiException; + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements BranchApi { + @Override + public BranchApi create(BranchInput in) throws RestApiException { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/ProjectApi.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/ProjectApi.java index aee5405020..d013c5d66c 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/ProjectApi.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/ProjectApi.java @@ -15,6 +15,7 @@ package com.google.gerrit.extensions.api.projects; import com.google.gerrit.extensions.common.ProjectInfo; +import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.RestApiException; public interface ProjectApi { @@ -22,4 +23,30 @@ public interface ProjectApi { ProjectApi create(ProjectInput in) throws RestApiException; ProjectInfo get(); BranchApi branch(String ref); + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements ProjectApi { + @Override + public ProjectApi create() throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ProjectApi create(ProjectInput in) throws RestApiException { + throw new NotImplementedException(); + } + + @Override + public ProjectInfo get() { + throw new NotImplementedException(); + } + + @Override + public BranchApi branch(String ref) { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/Projects.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/Projects.java index a3a4137f5a..a0f22b90b8 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/Projects.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/projects/Projects.java @@ -14,8 +14,20 @@ package com.google.gerrit.extensions.api.projects; +import com.google.gerrit.extensions.restapi.NotImplementedException; import com.google.gerrit.extensions.restapi.RestApiException; public interface Projects { ProjectApi name(String name) throws RestApiException; + + /** + * A default implementation which allows source compatibility + * when adding new methods to the interface. + **/ + public class NotImplemented implements Projects { + @Override + public ProjectApi name(String name) throws RestApiException { + throw new NotImplementedException(); + } + } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NotImplementedException.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NotImplementedException.java new file mode 100644 index 0000000000..10d0a147f2 --- /dev/null +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NotImplementedException.java @@ -0,0 +1,24 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// 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.gerrit.extensions.restapi; + +/** Method is not implemented in currently used implementation. */ +public class NotImplementedException extends UnsupportedOperationException { + private static final long serialVersionUID = 1L; + + public NotImplementedException() { + super("Not implemented."); + } +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/GerritApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/GerritApiImpl.java index 33314d3ef0..f7ca136d81 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/GerritApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/GerritApiImpl.java @@ -20,7 +20,7 @@ import com.google.gerrit.extensions.api.projects.Projects; import com.google.inject.Inject; import com.google.inject.Provider; -class GerritApiImpl implements GerritApi { +class GerritApiImpl extends GerritApi.NotImplemented implements GerritApi { private final Provider changes; private final Provider projects; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java index 0bcfd65188..8d4a0c93be 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java @@ -41,7 +41,7 @@ import com.google.inject.assistedinject.Assisted; import java.io.IOException; import java.util.EnumSet; -class ChangeApiImpl implements ChangeApi { +class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi { interface Factory { ChangeApiImpl create(ChangeResource change); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangesImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangesImpl.java index fdd0817f79..27493dd894 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangesImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangesImpl.java @@ -26,7 +26,7 @@ import com.google.gerrit.server.change.ChangesCollection; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; -class ChangesImpl implements Changes { +class ChangesImpl extends Changes.NotImplemented implements Changes { private final ChangesCollection changes; private final ChangeApiImpl.Factory api; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java index fb82b7eef3..b965c187ff 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java @@ -37,7 +37,7 @@ import com.google.inject.assistedinject.Assisted; import java.io.IOException; -class RevisionApiImpl implements RevisionApi { +class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi { interface Factory { RevisionApiImpl create(RevisionResource r); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/BranchApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/BranchApiImpl.java index 39166c3023..f4dc67e6bc 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/BranchApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/BranchApiImpl.java @@ -24,7 +24,7 @@ import com.google.inject.assistedinject.Assisted; import java.io.IOException; -public class BranchApiImpl implements BranchApi { +public class BranchApiImpl extends BranchApi.NotImplemented implements BranchApi { interface Factory { BranchApiImpl create(ProjectResource project, String ref); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java index b06f72aae9..7f73a38702 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectApiImpl.java @@ -36,7 +36,7 @@ import com.google.inject.assistedinject.AssistedInject; import java.io.IOException; -public class ProjectApiImpl implements ProjectApi { +public class ProjectApiImpl extends ProjectApi.NotImplemented implements ProjectApi { interface Factory { ProjectApiImpl create(ProjectResource project); ProjectApiImpl create(String name); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectsImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectsImpl.java index fc0396d8e4..71f2730367 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectsImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/projects/ProjectsImpl.java @@ -23,7 +23,7 @@ import com.google.inject.Inject; import java.io.IOException; -class ProjectsImpl implements Projects { +class ProjectsImpl extends Projects.NotImplemented implements Projects { private final ProjectsCollection projects; private final ProjectApiImpl.Factory api;