Merge "Add default empty implementations for extensions-api interfaces"

This commit is contained in:
Shawn Pearce 2014-04-27 18:59:05 +00:00 committed by Gerrit Code Review
commit 844063d312
15 changed files with 250 additions and 7 deletions

View File

@ -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();
}
}
}

View File

@ -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<ListChangesOption> options) throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeInfo get() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeInfo info() throws RestApiException {
throw new NotImplementedException();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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.");
}
}

View File

@ -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> changes;
private final Provider<Projects> projects;

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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;