Fix build warnings (#1562)

Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2021-03-01 09:08:01 +01:00
committed by GitHub
parent 0695ca3bac
commit 7852d1034e
46 changed files with 188 additions and 566 deletions

View File

@@ -39,10 +39,10 @@ import static java.util.Collections.unmodifiableCollection;
* .doThrow()
* .violation("name or alias must not be empty if not anonymous", "myParameter", "name")
* .violation("name or alias must not be empty if not anonymous", "myParameter", "alias")
* .when(myParameter.getName() == null && myParameter.getAlias() == null && !myParameter.isAnonymous())
* .when(myParameter.getName() == null &amp;&amp; myParameter.getAlias() == null &amp;&amp; !myParameter.isAnonymous())
* .andThrow()
* .violation("name must be empty if anonymous", "myParameter", "name")
* .when(myParameter.getName() != null && myParameter.isAnonymous());
* .when(myParameter.getName() != null &amp;&amp; myParameter.isAnonymous());
* </pre>
* Mind that using this way you do not have to use if-else constructs.
*/

View File

@@ -32,9 +32,9 @@ package sonia.scm;
public enum ServletContainer
{
SCM_SERVER,
/** Jetty version <= 6 */
/** Jetty version &lt;= 6 */
JETTY,
/** Jetty version >= 7 */
/** Jetty version &gt;= 7 */
ECLIPSE_JETTY,
TOMCAT,
GLASSFISH,

View File

@@ -207,8 +207,7 @@ public class ScmConfiguration implements Configuration {
private String mailDomainName = DEFAULT_MAIL_DOMAIN_NAME;
/**
* Calls the {@link sonia.scm.ConfigChangedListener#configChanged(Object)}
* method of all registered listeners.
* Fires the {@link ScmConfigurationChangedEvent}.
*/
public void fireChangeEvent() {
if (logger.isDebugEnabled()) {
@@ -294,7 +293,7 @@ public class ScmConfiguration implements Configuration {
* <li><b>os</b> = Operation System</li>
* <li><b>arch</b> = Architecture</li>
* </ul>
* For example http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&arch={arch}&snapshot=false
* For example `http://plugins.scm-manager.org/scm-plugin-backend/api/{version}/plugins?os={os}&amp;arch={arch}&amp;snapshot=false`
*
* @return the complete plugin url.
*/
@@ -313,6 +312,7 @@ public class ScmConfiguration implements Configuration {
/**
* Returns the mail domain, that will be used to create e-mail addresses for users without one whenever one is required.
*
* @return default mail domain
* @since 2.8.0
*/

View File

@@ -25,7 +25,7 @@
package sonia.scm.filter;
/**
* Configuration for the {@link GZipFilter}.
* Configuration for the {@link GZipResponseFilter}.
*
* @author Sebastian Sdorra
* @since 1.16

View File

@@ -43,8 +43,7 @@ import java.io.ObjectStreamClass;
* @author Sebastian Sdorra
* @since 1.36
*/
public class ScmObjectInputStream extends ObjectInputStream
{
public class ScmObjectInputStream extends ObjectInputStream {
/**
* the logger for ScmObjectInputStream
@@ -54,11 +53,7 @@ public class ScmObjectInputStream extends ObjectInputStream
//~--- constructors ---------------------------------------------------------
/**
* {@inheritDoc}
*/
public ScmObjectInputStream(InputStream stream) throws IOException
{
public ScmObjectInputStream(InputStream stream) throws IOException {
super(stream);
}
@@ -69,23 +64,18 @@ public class ScmObjectInputStream extends ObjectInputStream
*/
@Override
protected Class<?> resolveClass(ObjectStreamClass desc)
throws IOException, ClassNotFoundException
{
throws IOException, ClassNotFoundException {
Class<?> clazz = null;
ClassLoader classLoader = getClassLoader();
try
{
try {
clazz = classLoader.loadClass(desc.getName());
}
catch (ClassNotFoundException ex)
{
} catch (ClassNotFoundException ex) {
// do not log the exception, because the class
// is mostly found by the parent method.
}
if (clazz == null)
{
if (clazz == null) {
clazz = super.resolveClass(desc);
}
@@ -99,15 +89,12 @@ public class ScmObjectInputStream extends ObjectInputStream
* is not available the method will fall back to the class loader which has
* load this class.
*
*
* @return context class loader or default class loader
*/
private ClassLoader getClassLoader()
{
private ClassLoader getClassLoader() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null)
{
if (classLoader == null) {
logger.debug("could not find context class loader, fall back to default");
classLoader = ScmObjectInputStream.class.getClassLoader();
}

View File

@@ -29,9 +29,8 @@ package sonia.scm.net.ahc;
import java.io.IOException;
/**
* Advanced client for http operations. The {@link AdvancedHttpClient} replaces
* the much more simpler implementation {@link sonia.scm.net.HttpClient}. The
* {@link AdvancedHttpClient} offers a fluid interface for handling most common
* Advanced client for http operations.The {@link AdvancedHttpClient} offers
* a fluid interface for handling most common
* http operations. The {@link AdvancedHttpClient} can be injected by the
* default injection mechanism of SCM-Manager.
* <p>&nbsp;</p>
@@ -62,36 +61,30 @@ import java.io.IOException;
* </code></pre>
*
* @author Sebastian Sdorra
* @since 1.46
*
* @apiviz.landmark
* @since 1.46
*/
public abstract class AdvancedHttpClient
{
public abstract class AdvancedHttpClient {
/**
* Creates a {@link ContentTransformer} for the given Content-Type.
*
* @param type object type
* @param type object type
* @param contentType content-type
* @throws ContentTransformerNotFoundException if no
* {@link ContentTransformer} could be found for the content-type
*
* @return {@link ContentTransformer}
* @throws ContentTransformerNotFoundException if no
* {@link ContentTransformer} could be found for the content-type
*/
protected abstract ContentTransformer createTransformer(Class<?> type,
String contentType);
String contentType);
/**
* Executes the given request and returns the http response. Implementation
* have to check, if the instance if from type
* {@link AdvancedHttpRequestWithBody} in order to handle request contents.
*
*
* @param request request to execute
*
* @return http response
*
* @throws IOException
*/
protected abstract AdvancedHttpResponse request(BaseHttpRequest<?> request)
@@ -100,26 +93,20 @@ public abstract class AdvancedHttpClient
/**
* Returns a builder for a DELETE request.
*
*
* @param url request url
*
* @return request builder
*/
public AdvancedHttpRequestWithBody delete(String url)
{
public AdvancedHttpRequestWithBody delete(String url) {
return new AdvancedHttpRequestWithBody(this, HttpMethod.DELETE, url);
}
/**
* Returns a builder for a HEAD request.
*
*
* @param url request url
*
* @return request builder
*/
public AdvancedHttpRequest head(String url)
{
public AdvancedHttpRequest head(String url) {
return new AdvancedHttpRequest(this, HttpMethod.HEAD, url);
}
@@ -128,53 +115,41 @@ public abstract class AdvancedHttpClient
* every method is supported by the underlying implementation of the http
* client.
*
*
* @param method http method
* @param url request url
*
* @param url request url
* @return request builder
*/
public AdvancedHttpRequestWithBody method(String method, String url)
{
public AdvancedHttpRequestWithBody method(String method, String url) {
return new AdvancedHttpRequestWithBody(this, method, url);
}
/**
* Returns a builder for a OPTIONS request.
*
*
* @param url request url
*
* @return request builder
*/
public AdvancedHttpRequestWithBody options(String url)
{
public AdvancedHttpRequestWithBody options(String url) {
return new AdvancedHttpRequestWithBody(this, HttpMethod.OPTIONS, url);
}
/**
* Returns a builder for a POST request.
*
*
* @param url request url
*
* @return request builder
*/
public AdvancedHttpRequestWithBody post(String url)
{
public AdvancedHttpRequestWithBody post(String url) {
return new AdvancedHttpRequestWithBody(this, HttpMethod.POST, url);
}
/**
* Returns a builder for a PUT request.
*
*
* @param url request url
*
* @return request builder
*/
public AdvancedHttpRequestWithBody put(String url)
{
public AdvancedHttpRequestWithBody put(String url) {
return new AdvancedHttpRequestWithBody(this, HttpMethod.PUT, url);
}
@@ -183,13 +158,10 @@ public abstract class AdvancedHttpClient
/**
* Returns a builder for a GET request.
*
*
* @param url request url
*
* @return request builder
*/
public AdvancedHttpRequest get(String url)
{
public AdvancedHttpRequest get(String url) {
return new AdvancedHttpRequest(this, HttpMethod.GET, url);
}
}

View File

@@ -31,7 +31,7 @@ import sonia.scm.plugin.ExtensionPoint;
* Transforms {@link ByteSource} content to an object and vice versa. This class
* is an extension point, this means that plugins can define their own
* {@link ContentTransformer} implementations by implementing the interface and
* annotate the implementation with the {@link sonia.scm.plugin.ext.Extension}
* annotate the implementation with the {@link sonia.scm.plugin.Extension}
* annotation.
*
* @author Sebastian Sdorra

View File

@@ -37,19 +37,15 @@ import sonia.scm.util.AssertUtil;
*
* @author Sebastian Sdorra
*/
public abstract class AbstractRepositoryManager implements RepositoryManager
{
public abstract class AbstractRepositoryManager implements RepositoryManager {
/**
* Sends a {@link RepositoryHookEvent} to each registered
* {@link RepositoryHook} and sends the {@link RepositoryHookEvent} to
* the {@link ScmEventBus}.
* Sends the {@link RepositoryHookEvent} to the {@link ScmEventBus}.
*
* @param event event to be fired
*/
@Override
public void fireHookEvent(RepositoryHookEvent event)
{
public void fireHookEvent(RepositoryHookEvent event) {
AssertUtil.assertIsNotNull(event);
AssertUtil.assertIsNotNull(event.getRepository());
AssertUtil.assertIsNotNull(event.getType());
@@ -64,13 +60,12 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
/**
* Send a {@link RepositoryEvent} to the {@link ScmEventBus}.
*
* @param event type of change event
* @param repository repository that has changed
* @param event type of change event
* @param repository repository that has changed
* @param oldRepository old repository
*/
protected void fireEvent(HandlerEventType event, Repository repository,
Repository oldRepository)
{
Repository oldRepository) {
ScmEventBus.getInstance().post(new RepositoryModificationEvent(event, repository,
oldRepository));
}
@@ -78,25 +73,21 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
/**
* Send a {@link RepositoryEvent} to the {@link ScmEventBus}.
*
* @param event type of change event
* @param event type of change event
* @param repository repository that has changed
*/
protected void fireEvent(HandlerEventType event, Repository repository)
{
protected void fireEvent(HandlerEventType event, Repository repository) {
ScmEventBus.getInstance().post(new RepositoryEvent(event, repository));
}
/**
* Prepare a hook event before it is fired to the event system of SCM-Manager.
*
*
* @param event hook event
* @since 1.26
*
* @return
* @since 1.26
*/
protected RepositoryHookEvent prepareHookEvent(RepositoryHookEvent event)
{
protected RepositoryHookEvent prepareHookEvent(RepositoryHookEvent event) {
return event;
}
}

View File

@@ -24,6 +24,7 @@
package sonia.scm.repository;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.stream.Stream;
@@ -31,8 +32,9 @@ import java.util.stream.Stream;
import static java.util.stream.Stream.of;
@Value
@EqualsAndHashCode(callSuper=false)
public class Added extends Modification {
private final String path;
String path;
@Override
Stream<String> getEffectedPaths() {

View File

@@ -24,6 +24,7 @@
package sonia.scm.repository;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.stream.Stream;
@@ -31,9 +32,10 @@ import java.util.stream.Stream;
import static java.util.stream.Stream.of;
@Value
@EqualsAndHashCode(callSuper=false)
public class Copied extends Modification {
private final String sourcePath;
private final String targetPath;
String sourcePath;
String targetPath;
@Override
Stream<String> getEffectedPaths() {

View File

@@ -24,6 +24,7 @@
package sonia.scm.repository;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.stream.Stream;
@@ -31,8 +32,9 @@ import java.util.stream.Stream;
import static java.util.stream.Stream.of;
@Value
@EqualsAndHashCode(callSuper=false)
public class Modified extends Modification {
private final String path;
String path;
@Override
Stream<String> getEffectedPaths() {

View File

@@ -24,6 +24,7 @@
package sonia.scm.repository;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.stream.Stream;
@@ -31,8 +32,9 @@ import java.util.stream.Stream;
import static java.util.stream.Stream.of;
@Value
@EqualsAndHashCode(callSuper=false)
public class Removed extends Modification {
private final String path;
String path;
@Override
Stream<String> getEffectedPaths() {

View File

@@ -24,6 +24,7 @@
package sonia.scm.repository;
import lombok.EqualsAndHashCode;
import lombok.Value;
import java.util.stream.Stream;
@@ -31,9 +32,10 @@ import java.util.stream.Stream;
import static java.util.stream.Stream.of;
@Value
@EqualsAndHashCode(callSuper=false)
public class Renamed extends Modification {
private final String oldPath;
private final String newPath;
String oldPath;
String newPath;
@Override
Stream<String> getEffectedPaths() {

View File

@@ -38,7 +38,7 @@ public class RepositoryHookEvent
{
/**
* Constructs a new {@link ExtendedRepositoryHookEvent}.
* Constructs a new {@link RepositoryHookEvent}.
*
* @param context context of current hook
* @param repository

View File

@@ -100,7 +100,7 @@ public interface RepositoryManager
/**
* Creates a new repository and afterwards executes the logic from the {@param afterCreation}.
* Creates a new repository and afterwards executes the logic from the afterCreation.
*
* @param repository the repository to create
* @param afterCreation consumer which is executed after the repository was created

View File

@@ -53,12 +53,12 @@ import java.util.Set;
*
* If the merge is successful, the result will look like this:
* <pre><code>
* O <- Merge result (new head of integration_branch)
* |\
* | \
* old integration_branch -> O O <- feature_branch
* | |
* O O
* O &lt;- Merge result (new head of integration_branch)
* |\
* | \
* old integration_branch -&gt; O O &lt;- feature_branch
* | |
* O O
* </code></pre>
*
* To check whether they can be merged without conflicts beforehand do this:

View File

@@ -41,18 +41,18 @@ import java.io.File;
* implemented:
*
* <dl>
* <dt>{@link #initialize(C, File, String)}</dt>
* <dt>{@link SimpleWorkingCopyFactory#initialize(C, File, String)}</dt>
* <dd>Creates a new clone of the repository for the given context in the given
* directory with the given branch checked out (if branches are supported).</dd>
* <dt>{@link #reclaim(C, File, String)}</dt>
* <dt>{@link SimpleWorkingCopyFactory#reclaim(C, File, String)}</dt>
* <dd>Reclaim the working directory with a already checked out clone of the
* repository given in the context, so that the directory is not modified in
* respect to the repository and the given branch is checked out (if branches
* are supported).</dd>
* <dt>{@link #closeWorkingCopy(W)}</dt>
* <dt>{@link SimpleWorkingCopyFactory#closeWorkingCopy(W)}</dt>
* <dd>Closes resources allocated for the working copy, so that the directory can
* be put to the cache. Will be called at the end of the operation.</dd>
* <dt>{@link #closeRepository(R)}</dt>
* <dt>{@link SimpleWorkingCopyFactory#closeRepository(R)}</dt>
* <dd>Closes resources allocated for the central repository.</dd>
* </dl>
* <br>

View File

@@ -33,33 +33,25 @@ import java.util.function.Predicate;
* @author Sebastian Sdorra
* @since 1.31
*/
public interface SecuritySystem
{
public interface SecuritySystem {
/**
* Store a new permission.
*
*
* @param permission permission to be stored
*
* @return stored permission
*/
void addPermission(AssignedPermission permission);
/**
* Delete stored permission.
*
*
* @param permission permission to be deleted
*/
void deletePermission(AssignedPermission permission);
//~--- get methods ----------------------------------------------------------
/**
* Return all available permissions.
*
*
* @return available permissions
*/
Collection<PermissionDescriptor> getAvailablePermissions();
@@ -68,9 +60,7 @@ public interface SecuritySystem
* Returns all stored permissions which are matched by the given
* {@link Predicate}.
*
*
* @param predicate predicate to filter
*
* @return filtered permissions
*/
Collection<AssignedPermission> getPermissions(Predicate<AssignedPermission> predicate);

View File

@@ -43,7 +43,7 @@ public interface ExportableStore {
StoreEntryMetaData getMetaData();
/**
* Exports the data of this store to the given {@param exporter}.
* Exports the data of this store to the given exporter.
*/
void export(Exporter exporter) throws IOException;
}

View File

@@ -72,7 +72,7 @@ public final class Archives {
* Example:
* <pre>
* Archives.addPathToTar(Paths.get("some/dir"), Files.newOutputStream("my.tar"))
* .filter(path -> !path.toString().endsWith("~"))
* .filter(path -&gt; !path.toString().endsWith("~"))
* .run();
* </pre>
* @param path The path containing the files to be added to the tar.

View File

@@ -28,6 +28,7 @@ import de.otto.edison.hal.Links;
import org.mapstruct.AfterMapping;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.repository.Repository;
@@ -46,6 +47,7 @@ public abstract class GitRepositoryConfigMapper {
@Inject
private ScmPathInfoStore scmPathInfoStore;
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
public abstract GitRepositoryConfigDto map(GitRepositoryConfig config, @Context Repository repository);
public abstract GitRepositoryConfig map(GitRepositoryConfigDto dto);

View File

@@ -496,7 +496,7 @@ public final class GitUtil {
* Returns the name of the tag or {@code null} if the the ref is not a tag.
*
* @param refName ref name
* @return name of tag or {@link null}
* @return name of tag or null
* @since 1.50
*/
public static String getTagName(String refName) {

View File

@@ -51,11 +51,11 @@ class SvnLookupCommandTest {
@Test
void shouldReturnEmptyOptional() {
LookupCommandRequest request = new LookupCommandRequest();
LookupCommandRequest<String> request = new LookupCommandRequest<>();
request.setType(String.class);
request.setArgs(new String[]{"propget"});
Optional<Object> result = command.lookup(request);
Optional<String> result = command.lookup(request);
assertThat(result).isNotPresent();
}
@@ -66,11 +66,11 @@ class SvnLookupCommandTest {
when(context.open()).thenReturn(svnRepository);
when(svnRepository.getRepositoryUUID(true)).thenReturn(uuid);
LookupCommandRequest request = new LookupCommandRequest();
LookupCommandRequest<String> request = new LookupCommandRequest<>();
request.setType(String.class);
request.setArgs(new String[]{"propget", "uuid", "/"});
Optional<Object> result = command.lookup(request);
Optional<String> result = command.lookup(request);
assertThat(result).isPresent();
assertThat(result.get())

View File

@@ -50,8 +50,6 @@ import static org.mockito.Mockito.when;
*/
public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
protected RepositoryDAO repoDao = mock(RepositoryDAO.class);
protected Path repoPath;
protected Repository repository;

View File

@@ -39,141 +39,67 @@ import java.io.IOException;
import java.util.List;
/**
*
* @author Sebastian Sdorra
* @since 1.18
*/
public final class RepositoryClientFactory
{
public final class RepositoryClientFactory {
/**
* Constructs ...
*
*/
public RepositoryClientFactory()
{
private Iterable<RepositoryClientFactoryProvider> providers;
public RepositoryClientFactory() {
this.providers =
ServiceUtil.getServices(RepositoryClientFactoryProvider.class);
}
/**
* Constructs ...
*
*
* @param provider
*
* @param providers
*/
public RepositoryClientFactory(
Iterable<RepositoryClientFactoryProvider> providers)
{
Iterable<RepositoryClientFactoryProvider> providers) {
this.providers = providers;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
*
* @param type
* @param main
* @param workingCopy
*
* @return
*
* @throws IOException
*/
public RepositoryClient create(String type, File main, File workingCopy)
throws IOException
{
throws IOException {
return new RepositoryClient(getProvider(type).create(main, workingCopy));
}
/**
* Method description
*
*
*
* @param type
* @param url
* @param username
* @param password
* @param workingCopy
*
* @return
*
* @throws IOException
*/
public RepositoryClient create(String type, String url, String username,
String password, File workingCopy)
throws IOException
{
String password, File workingCopy)
throws IOException {
return new RepositoryClient(getProvider(type).create(url, username,
password, workingCopy));
}
public RepositoryClient create(String type, String url, File workingCopy)
throws IOException
{
throws IOException {
return new RepositoryClient(getProvider(type).create(url, null, null, workingCopy));
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Iterable<String> getAvailableTypes()
{
public Iterable<String> getAvailableTypes() {
List<String> types = Lists.newArrayList();
for (RepositoryClientFactoryProvider provider : providers)
{
for (RepositoryClientFactoryProvider provider : providers) {
types.add(provider.getType());
}
return types;
}
/**
* Method description
*
*
* @param type
*
* @return
*/
private RepositoryClientFactoryProvider getProvider(String type)
{
private RepositoryClientFactoryProvider getProvider(String type) {
RepositoryClientFactoryProvider provider = null;
for (RepositoryClientFactoryProvider p : providers)
{
if (p.getType().equalsIgnoreCase(type))
{
for (RepositoryClientFactoryProvider p : providers) {
if (p.getType().equalsIgnoreCase(type)) {
provider = p;
break;
}
}
if (provider == null)
{
if (provider == null) {
throw new RuntimeException(
"could not find provider for type ".concat(type));
}
return provider;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Iterable<RepositoryClientFactoryProvider> providers;
}

View File

@@ -29,22 +29,10 @@ package sonia.scm.repository.client.spi;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
* @since 1.18
*/
public interface AddCommand
{
public interface AddCommand {
/**
* Method description
*
*
* @param path
*
* @param file
*
* @throws IOException
*/
public void add(String path) throws IOException;
void add(String path) throws IOException;
}

View File

@@ -29,22 +29,10 @@ package sonia.scm.repository.client.spi;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
* @since 1.18
*/
public interface RemoveCommand
{
public interface RemoveCommand {
/**
* Method description
*
*
* @param file
*
* @param path
*
* @throws IOException
*/
public void remove(String path) throws IOException;
void remove(String path) throws IOException;
}

View File

@@ -26,6 +26,7 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Links;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ObjectFactory;
import sonia.scm.security.ApiKey;
@@ -39,6 +40,7 @@ public abstract class ApiKeyToApiKeyDtoMapper {
@Inject
private ResourceLinks resourceLinks;
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
abstract ApiKeyDto map(ApiKey key, String user);
@ObjectFactory

View File

@@ -27,10 +27,12 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.HalRepresentation;
import de.otto.edison.hal.Links;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = false)
public class BlameDto extends HalRepresentation {
private List<BlameLineDto> lines;

View File

@@ -55,6 +55,7 @@ public abstract class BrowserResultToFileObjectDtoMapper extends BaseFileObjectD
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
@Mapping(target = "children", qualifiedBy = Children.class)
@Mapping(target = "revision", ignore = true)
@Children
protected abstract FileObjectDto fileObjectToDto(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult, @Context Integer offset);

View File

@@ -28,6 +28,7 @@ import de.otto.edison.hal.Embedded;
import de.otto.edison.hal.Links;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ObjectFactory;
import sonia.scm.repository.Branch;
import sonia.scm.repository.Changeset;
@@ -80,6 +81,7 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
abstract ContributorDto map(Contributor contributor);
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
abstract SignatureDto map(Signature signature);
abstract PersonDto map(Person person);

View File

@@ -29,10 +29,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import de.otto.edison.hal.HalRepresentation;
import de.otto.edison.hal.Links;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = false)
public class DiffResultDto extends HalRepresentation {
public DiffResultDto(Links links) {
@@ -42,6 +44,7 @@ public class DiffResultDto extends HalRepresentation {
private List<FileDto> files;
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public static class FileDto extends HalRepresentation {

View File

@@ -33,5 +33,6 @@ import sonia.scm.group.Group;
public abstract class GroupDtoToGroupMapper extends BaseDtoMapper {
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "properties", ignore = true)
public abstract Group map(GroupDto groupDto);
}

View File

@@ -90,12 +90,12 @@ public class IncomingRootResource {
* - ° b2
* -
* <p>
* - /incoming/a/master/changesets -> a1 , e1
* - /incoming/b/master/changesets -> b1 , b2
* - /incoming/b/f/changesets -> b1 , b2, m2
* - /incoming/f/b/changesets -> f1 , e1
* - /incoming/a/b/changesets -> a1 , e1
* - /incoming/a/b/changesets -> a1 , e1
* - /incoming/a/master/changesets -&gt; a1 , e1
* - /incoming/b/master/changesets -&gt; b1 , b2
* - /incoming/b/f/changesets -&gt; b1 , b2, m2
* - /incoming/f/b/changesets -&gt; f1 , e1
* - /incoming/a/b/changesets -&gt; a1 , e1
* - /incoming/a/b/changesets -&gt; a1 , e1
*
* @param namespace
* @param name

View File

@@ -232,7 +232,6 @@ public class NamespacePermissionResource {
*
* @param permission permission to modify
* @param permissionName permission to modify
* @return a web response with the status code 204
*/
@PUT
@Path("{permission-name}")
@@ -264,8 +263,8 @@ public class NamespacePermissionResource {
)
)
public void update(@PathParam("namespace") String namespaceName,
@PathParam("permission-name") String permissionName,
@Valid RepositoryPermissionDto permission) {
@PathParam("permission-name") String permissionName,
@Valid RepositoryPermissionDto permission) {
Namespace namespace = load(namespaceName);
String extractedPermissionName = getPermissionName(permissionName);
if (!isPermissionExist(new RepositoryPermissionDto(extractedPermissionName, isGroupPermission(permissionName)), namespace)) {
@@ -294,7 +293,6 @@ public class NamespacePermissionResource {
* Update a permission to the user or group managed by the repository
*
* @param permissionName permission to delete
* @return a web response with the status code 204
*/
@DELETE
@Path("{permission-name}")
@@ -311,7 +309,7 @@ public class NamespacePermissionResource {
)
)
public void delete(@PathParam("namespace") String namespaceName,
@PathParam("permission-name") String permissionName) {
@PathParam("permission-name") String permissionName) {
log.info("try to delete the permission with name: {}.", permissionName);
Namespace namespace = load(namespaceName);
namespace.getPermissions()

View File

@@ -26,6 +26,7 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Links;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import sonia.scm.lifecycle.Restarter;
import sonia.scm.plugin.AvailablePlugin;
@@ -51,6 +52,13 @@ public abstract class PluginDtoMapper {
@Inject
private Restarter restarter;
@Mapping(target = "newVersion", ignore = true)
@Mapping(target = "pending", ignore = true)
@Mapping(target = "core", ignore = true)
@Mapping(target = "markedForUninstall", ignore = true)
@Mapping(target = "dependencies", ignore = true)
@Mapping(target = "optionalDependencies", ignore = true)
@Mapping(target = "attributes", ignore = true)
public abstract void map(PluginInformation plugin, @MappingTarget PluginDto dto);
public PluginDto mapInstalled(InstalledPlugin plugin, List<AvailablePlugin> availablePlugins) {

View File

@@ -37,6 +37,8 @@ public abstract class RepositoryDtoToRepositoryMapper extends BaseDtoMapper {
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "healthCheckFailures", ignore = true)
@Mapping(target = "properties", ignore = true)
@Mapping(target = "permissions", ignore = true)
public abstract Repository map(RepositoryDto repositoryDto, @Context String id);
@AfterMapping

View File

@@ -28,6 +28,7 @@ import com.google.common.annotations.VisibleForTesting;
import de.otto.edison.hal.Links;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ObjectFactory;
import sonia.scm.importexport.ExportService;
import sonia.scm.importexport.ExportStatus;
@@ -56,6 +57,7 @@ public abstract class RepositoryExportInformationToDtoMapper {
this.exportService = exportService;
}
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
abstract RepositoryExportInformationDto map(RepositoryExportInformation info, @Context Repository repository);
@ObjectFactory

View File

@@ -27,6 +27,7 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Embedded;
import de.otto.edison.hal.Links;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ObjectFactory;
import sonia.scm.repository.RepositoryRole;
import sonia.scm.repository.RepositoryRolePermissions;
@@ -46,6 +47,7 @@ public abstract class RepositoryRoleToRepositoryRoleDtoMapper extends BaseMapper
@Inject
private ResourceLinks resourceLinks;
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
@Override
public abstract RepositoryRoleDto map(RepositoryRole modelObject);

View File

@@ -29,6 +29,7 @@ import de.otto.edison.hal.Link;
import de.otto.edison.hal.Links;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.ObjectFactory;
import sonia.scm.config.ScmConfiguration;
@@ -70,6 +71,8 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
abstract HealthCheckFailureDto toDto(HealthCheckFailure failure);
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
@Mapping(target = "exporting", ignore = true)
@Override
public abstract RepositoryDto map(Repository modelObject);

View File

@@ -43,6 +43,7 @@ public abstract class ResteasyViolationExceptionToErrorDtoMapper {
@Mapping(target = "context", ignore = true)
@Mapping(target = "url", ignore = true)
@Mapping(target = "violations", ignore = true)
@Mapping(target = "additionalMessages", ignore = true)
public abstract ErrorDto map(ConstraintViolationException exception);
@AfterMapping

View File

@@ -38,6 +38,7 @@ public interface ScmViolationExceptionToErrorDtoMapper {
@Mapping(target = "errorCode", ignore = true)
@Mapping(target = "transactionId", ignore = true)
@Mapping(target = "context", ignore = true)
@Mapping(target = "additionalMessages", ignore = true)
ErrorDto map(ScmConstraintViolationException exception);
@AfterMapping

View File

@@ -37,6 +37,7 @@ import sonia.scm.user.User;
public abstract class UserDtoToUserMapper extends BaseDtoMapper {
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "properties", ignore = true)
public abstract User map(UserDto userDto, @Context String usedPassword);

View File

@@ -24,26 +24,18 @@
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.io.Files;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.lifecycle.classloading.ClassLoaderLifeCycle;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Set;
/**
@@ -59,27 +51,8 @@ public final class PluginsInternal
private static final Logger logger =
LoggerFactory.getLogger(PluginsInternal.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private PluginsInternal() {}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param classLoader
* @param directory
*
* @return
*
* @throws IOException
*/
public static Set<InstalledPlugin> collectPlugins(ClassLoaderLifeCycle classLoaderLifeCycle,
Path directory)
throws IOException
@@ -89,15 +62,6 @@ public final class PluginsInternal
return processor.collectPlugins(classLoaderLifeCycle.getBootstrapClassLoader());
}
/**
* Method description
*
*
* @param parent
* @param plugin
*
* @return
*/
public static File createPluginDirectory(File parent, InstalledPluginDescriptor plugin)
{
PluginInformation info = plugin.getInformation();
@@ -105,18 +69,6 @@ public final class PluginsInternal
return new File(parent, info.getName());
}
/**
* Method description
*
*
* @param archive
* @param checksum
* @param directory
* @param checksumFile
* @param core
*
* @throws IOException
*/
public static void extract(SmpArchive archive, String checksum,
File directory, File checksumFile, boolean core)
throws IOException
@@ -144,56 +96,21 @@ public final class PluginsInternal
}
}
/**
* Method description
*
*
* @param wrapped
*
* @return
*/
public static Iterable<InstalledPluginDescriptor> unwrap(Iterable<InstalledPlugin> wrapped)
{
return Iterables.transform(wrapped, new Unwrap());
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param pluginDirectory
*
* @return
*/
public static File getChecksumFile(File pluginDirectory)
{
return new File(pluginDirectory, PluginConstants.FILE_CHECKSUM);
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here..., 14/06/05
* @author Enter your name here...
*/
private static class Unwrap implements Function<InstalledPlugin, InstalledPluginDescriptor>
{
/**
* Method description
*
*
* @param wrapper
*
* @return
*/
@Override
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
@Override
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
{
return wrapper.getDescriptor();
}

View File

@@ -24,7 +24,6 @@
package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import com.github.legman.Subscribe;
import com.google.common.base.Objects;
@@ -62,7 +61,6 @@ import java.util.stream.Collectors;
import static java.util.Objects.isNull;
//~--- JDK imports ------------------------------------------------------------
/**
* TODO add events
@@ -71,13 +69,10 @@ import static java.util.Objects.isNull;
* @since 1.31
*/
@Singleton
public class DefaultSecuritySystem implements SecuritySystem
{
public class DefaultSecuritySystem implements SecuritySystem {
/** Field description */
private static final String NAME = "security";
/** Field description */
private static final String PERMISSION_DESCRIPTOR =
"META-INF/scm/permissions.xml";
@@ -87,18 +82,8 @@ public class DefaultSecuritySystem implements SecuritySystem
private static final Logger logger =
LoggerFactory.getLogger(DefaultSecuritySystem.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param storeFactory
*/
@Inject
@SuppressWarnings("unchecked")
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory, PluginLoader pluginLoader)
{
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory, PluginLoader pluginLoader) {
store = storeFactory
.withType(AssignedPermission.class)
.withName(NAME)
@@ -106,19 +91,8 @@ public class DefaultSecuritySystem implements SecuritySystem
this.availablePermissions = readAvailablePermissions(pluginLoader);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param permission
*
* @return
*/
@Override
public void addPermission(AssignedPermission permission)
{
public void addPermission(AssignedPermission permission) {
assertHasPermission();
validatePermission(permission);
@@ -133,15 +107,8 @@ public class DefaultSecuritySystem implements SecuritySystem
//J+
}
/**
* Method description
*
*
* @param permission
*/
@Override
public void deletePermission(AssignedPermission permission)
{
public void deletePermission(AssignedPermission permission) {
assertHasPermission();
boolean deleted = deletePermissions(sap -> Objects.equal(sap.getName(), permission.getName())
&& Objects.equal(sap.isGroupPermission(), permission.isGroupPermission())
@@ -153,71 +120,35 @@ public class DefaultSecuritySystem implements SecuritySystem
}
}
/**
* Method description
*
*
* @param event
*/
@Subscribe
public void handleEvent(final UserEvent event)
{
if (event.getEventType() == HandlerEventType.DELETE)
{
public void handleEvent(final UserEvent event) {
if (event.getEventType() == HandlerEventType.DELETE) {
deletePermissions(p -> !p.isGroupPermission()
&& event.getItem().getName().equals(p.getName()));
}
}
/**
* Method description
*
*
* @param event
*/
@Subscribe
public void handleEvent(final GroupEvent event)
{
if (event.getEventType() == HandlerEventType.DELETE)
{
public void handleEvent(final GroupEvent event) {
if (event.getEventType() == HandlerEventType.DELETE) {
deletePermissions(p -> p.isGroupPermission()
&& event.getItem().getName().equals(p.getName()));
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Collection<PermissionDescriptor> getAvailablePermissions()
{
public Collection<PermissionDescriptor> getAvailablePermissions() {
assertHasPermission();
return availablePermissions;
}
/**
* Method description
*
*
* @param predicate
*
* @return
*/
@Override
public Collection<AssignedPermission> getPermissions(Predicate<AssignedPermission> predicate)
{
public Collection<AssignedPermission> getPermissions(Predicate<AssignedPermission> predicate) {
Builder<AssignedPermission> permissions = ImmutableSet.builder();
for (Entry<String, AssignedPermission> e : store.getAll().entrySet())
{
if ((predicate == null) || predicate.test(e.getValue()))
{
for (Entry<String, AssignedPermission> e : store.getAll().entrySet()) {
if ((predicate == null) || predicate.test(e.getValue())) {
permissions.add(new StoredAssignedPermission(e.getKey(), e.getValue()));
}
}
@@ -225,25 +156,11 @@ public class DefaultSecuritySystem implements SecuritySystem
return permissions.build();
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
private void assertHasPermission()
{
private void assertHasPermission() {
PermissionPermissions.assign().check();
}
/**
* Method description
*
*
* @param predicate
*/
private boolean deletePermissions(Predicate<AssignedPermission> predicate)
{
private boolean deletePermissions(Predicate<AssignedPermission> predicate) {
List<Entry<String, AssignedPermission>> toRemove =
store.getAll()
.entrySet()
@@ -253,23 +170,12 @@ public class DefaultSecuritySystem implements SecuritySystem
return !toRemove.isEmpty();
}
/**
* Method description
*
*
* @param context
* @param descriptorUrl
*
* @return
*/
@SuppressWarnings("unchecked")
private static List<PermissionDescriptor> parsePermissionDescriptor(
JAXBContext context, URL descriptorUrl)
{
JAXBContext context, URL descriptorUrl) {
List<PermissionDescriptor> descriptors = Collections.EMPTY_LIST;
try
{
try {
PermissionDescriptors descriptorWrapper =
(PermissionDescriptors) context.createUnmarshaller().unmarshal(
descriptorUrl);
@@ -279,26 +185,17 @@ public class DefaultSecuritySystem implements SecuritySystem
logger.debug("found {} permissions at {}", descriptors.size(),
descriptorUrl);
logger.trace("permissions from {}: {}", descriptorUrl, descriptors);
}
catch (JAXBException ex)
{
} catch (JAXBException ex) {
logger.error("could not parse permission descriptor", ex);
}
return descriptors;
}
/**
* Method description
*
* @param pluginLoader
*/
private static ImmutableSet<PermissionDescriptor> readAvailablePermissions(PluginLoader pluginLoader)
{
private static ImmutableSet<PermissionDescriptor> readAvailablePermissions(PluginLoader pluginLoader) {
ImmutableSet.Builder<PermissionDescriptor> builder = ImmutableSet.builder();
try
{
try {
JAXBContext context =
JAXBContext.newInstance(PermissionDescriptors.class);
@@ -306,21 +203,16 @@ public class DefaultSecuritySystem implements SecuritySystem
Enumeration<URL> descirptorEnum =
pluginLoader.getUberClassLoader().getResources(PERMISSION_DESCRIPTOR);
while (descirptorEnum.hasMoreElements())
{
while (descirptorEnum.hasMoreElements()) {
URL descriptorUrl = descirptorEnum.nextElement();
logger.debug("read permission descriptor from {}", descriptorUrl);
builder.addAll(parsePermissionDescriptor(context, descriptorUrl));
}
}
catch (IOException ex)
{
} catch (IOException ex) {
logger.error("could not read permission descriptors", ex);
}
catch (JAXBException ex)
{
} catch (JAXBException ex) {
logger.error(
"could not create jaxb context to read permission descriptors", ex);
}
@@ -328,62 +220,34 @@ public class DefaultSecuritySystem implements SecuritySystem
return builder.build();
}
/**
* Method description
*
*
* @param perm
*/
private void validatePermission(AssignedPermission perm)
{
private void validatePermission(AssignedPermission perm) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(perm.getName()),
"name is required");
Preconditions.checkArgument(!isNull(perm.getPermission()),
"permission is required");
}
//~--- inner classes --------------------------------------------------------
/**
* Descriptor for permissions.
*/
@XmlRootElement(name = "permissions")
@XmlAccessorType(XmlAccessType.FIELD)
private static class PermissionDescriptors
{
private static class PermissionDescriptors {
//~--- get methods --------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@SuppressWarnings("unchecked")
public List<PermissionDescriptor> getPermissions()
{
if (permissions == null)
{
public List<PermissionDescriptor> getPermissions() {
if (permissions == null) {
permissions = Collections.EMPTY_LIST;
}
return permissions;
}
//~--- fields -------------------------------------------------------------
/** Field description */
@XmlElement(name = "permission")
private List<PermissionDescriptor> permissions;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private final ConfigurationEntryStore<AssignedPermission> store;
/** Field description */
private final ImmutableSet<PermissionDescriptor> availablePermissions;
}

View File

@@ -24,26 +24,18 @@
package sonia.scm.template;
//~--- non-JDK imports --------------------------------------------------------
import com.github.mustachejava.Mustache;
import com.google.common.base.Throwables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.Writer;
/**
*
* @author Sebastian Sdorra
*/
public class MustacheTemplate implements Template
{
public class MustacheTemplate implements Template {
/**
* the logger for MustacheTemplae
@@ -51,50 +43,22 @@ public class MustacheTemplate implements Template
private static final Logger logger =
LoggerFactory.getLogger(MustacheTemplate.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
*
* @param templatePath
* @param mustache
*/
public MustacheTemplate(String templatePath, Mustache mustache)
{
public MustacheTemplate(String templatePath, Mustache mustache) {
this.templatePath = templatePath;
this.mustache = mustache;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param writer
* @param environment
* @param model
*
* @throws IOException
*/
@Override
public void execute(Writer writer, Object model) throws IOException
{
if (logger.isDebugEnabled())
{
public void execute(Writer writer, Object model) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("render mustache template at {}", templatePath);
}
try
{
try {
mustache.execute(writer, model);
}
catch (Exception ex)
{
} catch (Exception ex) {
Throwables.propagateIfInstanceOf(ex, IOException.class);
throw new TemplateRenderException(
@@ -102,11 +66,7 @@ public class MustacheTemplate implements Template
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Mustache mustache;
/** Field description */
private String templatePath;
}