Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement a new repository client

Signed-off-by: Alin Dreghiciu <adreghiciu@gmail.com>
  • Loading branch information...
commit b9840639e92aa90fee632244b51a5870c6af7175 1 parent 90b7cd0
@adreghiciu adreghiciu authored
Showing with 2,901 additions and 42 deletions.
  1. +40 −0 nexus/nexus-client-core-testsuite/pom.xml
  2. +35 −0 nexus/nexus-client-core-testsuite/src/test/filtered-resources/logback-test.xml
  3. +47 −0 nexus/nexus-client-core-testsuite/src/test/java/org/sonatype/nexus/client/testsuite/NexusClientITSupport.java
  4. +262 −0 nexus/nexus-client-core-testsuite/src/test/java/org/sonatype/nexus/client/testsuite/RepositoriesIT.java
  5. +2 −1  nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/NexusClientException.java
  6. +2 −1  nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/NexusErrorMessageException.java
  7. +3 −2 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/NexusUnexpectedResponseException.java
  8. +35 −0 ...us-client-core/src/main/java/org/sonatype/nexus/client/core/spi/subsystem/repository/RepositoryFactory.java
  9. +0 −2  nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/config/Segment.java
  10. +1 −0  nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/content/Content.java
  11. +26 −0 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/GroupRepository.java
  12. +36 −0 ...s/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/HostedRepository.java
  13. +38 −0 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ProxyRepository.java
  14. +28 −0 ...us-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ProxyRepositoryStatus.java
  15. +35 −0 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/Repositories.java
  16. +43 −0 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/Repository.java
  17. +25 −0 ...s/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/RepositoryStatus.java
  18. +26 −0 ...s/nexus-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ShadowRepository.java
  19. +26 −0 ...ient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenGroupRepository.java
  20. +30 −0 ...ent-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenHostedRepository.java
  21. +30 −0 ...ient-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenProxyRepository.java
  22. +26 −0 ...ent-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenShadowRepository.java
  23. +2 −2 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/internal/rest/NexusXStreamFactory.java
  24. +2 −4 ...nexus-client-core/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/JerseyContent.java
  25. +108 −0 ...rc/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyGroupRepository.java
  26. +61 −0 .../java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyGroupRepositoryFactory.java
  27. +98 −0 ...c/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyHostedRepository.java
  28. +64 −0 ...java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyHostedRepositoryFactory.java
  29. +139 −0 ...rc/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyProxyRepository.java
  30. +65 −0 .../java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyProxyRepositoryFactory.java
  31. +172 −0 ...e/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyRepositories.java
  32. +254 −0 ...ore/src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyRepository.java
  33. +59 −0 ...c/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyShadowRepository.java
  34. +65 −0 ...java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyShadowRepositoryFactory.java
  35. +50 −0 ...ain/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/ProxyRepositoryStatusImpl.java
  36. +37 −0 ...src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/RepositoryStatusImpl.java
  37. +45 −0 ...a/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenGroupRepository.java
  38. +64 −0 ...onatype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenGroupRepositoryFactory.java
  39. +61 −0 .../org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenHostedRepository.java
  40. +63 −0 ...natype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenHostedRepositoryFactory.java
  41. +66 −0 ...a/org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenProxyRepository.java
  42. +64 −0 ...onatype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenProxyRepositoryFactory.java
  43. +45 −0 .../org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenShadowRepository.java
  44. +64 −0 ...natype/nexus/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenShadowRepositoryFactory.java
  45. +12 −10 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClient.java
  46. +10 −8 nexus/nexus-client-core/src/main/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClientFactory.java
  47. +65 −0 ...us-client-core/src/main/java/org/sonatype/nexus/client/rest/jersey/subsystem/JerseyRepositoriesFactory.java
  48. +0 −2  ...nt-core/src/main/java/org/sonatype/nexus/client/rest/jersey/subsystem/JerseyServerConfigurationFactory.java
  49. +19 −0 nexus/nexus-client-core/src/main/java/org/sonatype/plexus/rest/xstream/LookAheadStreamReader.java
  50. +87 −0 nexus/nexus-client-core/src/main/java/org/sonatype/plexus/rest/xstream/xml/LookAheadXppDriver.java
  51. +259 −0 nexus/nexus-client-core/src/main/java/org/sonatype/plexus/rest/xstream/xml/LookAheadXppReader.java
  52. +4 −10 nexus/nexus-client-core/src/test/java/org/sonatype/nexus/client/rest/jersey/JerseyNexusClientFactoryTest.java
  53. +1 −0  nexus/pom.xml
View
40 nexus/nexus-client-core-testsuite/pom.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Sonatype Nexus (TM) Open Source Version
+ Copyright (c) 2007-2012 Sonatype, Inc.
+ All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+
+ This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+
+ Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ Eclipse Foundation. All other trademarks are the property of their respective owners.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.sonatype.nexus.client</groupId>
+ <artifactId>nexus-client-core-testsuite</artifactId>
+ <name>Nexus : Client Testsuite</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-testsuite-support</artifactId>
+ <version>2.3-SNAPSHOT</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
View
35 nexus/nexus-client-core-testsuite/src/test/filtered-resources/logback-test.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Sonatype Nexus (TM) Open Source Version
+ Copyright (c) 2007-2012 Sonatype, Inc.
+ All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+
+ This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+
+ Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ Eclipse Foundation. All other trademarks are the property of their respective owners.
+
+-->
+<configuration>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <target>System.out</target>
+ <encoder>
+ <pattern>%level [%thread%X{DC}] %logger - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="Sisu" level="${test.log.level.Sisu:-INFO}"/>
+ <logger name="org.apache.commons.httpclient" level="ERROR"/>
+ <logger name="org.apache.http" level="${test.log.level.org.apache.http:-DEBUG}"/>
+
+ <logger name="org.sonatype.nexus.client" level="TRACE"/>
+
+ <root level="${test.log.level:-INFO}">
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</configuration>
View
47 ...ore-testsuite/src/test/java/org/sonatype/nexus/client/testsuite/NexusClientITSupport.java
@@ -0,0 +1,47 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.testsuite;
+
+import static org.sonatype.nexus.testsuite.support.ParametersLoaders.firstAvailableTestParameters;
+import static org.sonatype.nexus.testsuite.support.ParametersLoaders.systemTestParameters;
+import static org.sonatype.nexus.testsuite.support.ParametersLoaders.testParameters;
+import static org.sonatype.sisu.goodies.common.Varargs.$;
+
+import java.util.Collection;
+
+import org.junit.runners.Parameterized;
+import org.sonatype.nexus.testsuite.support.NexusRunningParametrizedITSupport;
+import org.sonatype.nexus.testsuite.support.NexusStartAndStopStrategy;
+
+@NexusStartAndStopStrategy( NexusStartAndStopStrategy.Strategy.EACH_TEST )
+public abstract class NexusClientITSupport
+ extends NexusRunningParametrizedITSupport
+{
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> data()
+ {
+ return firstAvailableTestParameters(
+ systemTestParameters(),
+ testParameters(
+ $( "${it.nexus.bundle.groupId}:${it.nexus.bundle.artifactId}:zip:bundle" )
+ )
+ ).load();
+ }
+
+ public NexusClientITSupport( final String nexusBundleCoordinates )
+ {
+ super( nexusBundleCoordinates );
+ }
+
+}
View
262 ...ient-core-testsuite/src/test/java/org/sonatype/nexus/client/testsuite/RepositoriesIT.java
@@ -0,0 +1,262 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.testsuite;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.sonatype.nexus.client.core.subsystem.repository.Repositories;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenGroupRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenHostedRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenProxyRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenShadowRepository;
+
+public class RepositoriesIT
+ extends NexusClientITSupport
+{
+
+ public RepositoriesIT( final String nexusBundleCoordinates )
+ {
+ super( nexusBundleCoordinates );
+ }
+
+ @Test
+ public void getHosted()
+ {
+ final Repository repository = repositories().get( "releases" );
+ assertThat( repository, is( instanceOf( MavenHostedRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshHosted()
+ {
+ final Repository repository = repositories().get( "releases" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createHosted()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenHostedRepository.class, id )
+ .save();
+ }
+
+ @Test
+ public void removeHosted()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenHostedRepository.class, id )
+ .save()
+ .remove();
+ }
+
+ @Test
+ public void statusHosted()
+ {
+ final String id = repositoryIdForTest();
+ final MavenHostedRepository repository = repositories().create( MavenHostedRepository.class, id );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void getProxy()
+ {
+ final Repository repository = repositories().get( "central" );
+ assertThat( repository, is( instanceOf( MavenProxyRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshProxy()
+ {
+ final Repository repository = repositories().get( "central" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createProxy()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" )
+ .save();
+ }
+
+ public void removeProxy()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" )
+ .save()
+ .remove();
+ }
+
+ @Test
+ public void statusProxy()
+ {
+ final String id = repositoryIdForTest();
+ final MavenProxyRepository repository = repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void proxyMode()
+ {
+ final String id = repositoryIdForTest();
+ final MavenProxyRepository repository = repositories().create( MavenProxyRepository.class, id )
+ .asProxyOf( "http://localhost:8080" )
+ .doNotAutoBlock();
+ assertThat( repository.status().isBlocked(), is( false ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isBlocked(), is( false ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ repository.block();
+ assertThat( repository.status().isBlocked(), is( true ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ repository.unblock();
+ assertThat( repository.status().isBlocked(), is( false ) );
+ assertThat( repository.status().isAutoBlocked(), is( false ) );
+ }
+
+ @Test
+ public void getGroup()
+ {
+ final Repository repository = repositories().get( "public" );
+ assertThat( repository, is( instanceOf( MavenGroupRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshGroup()
+ {
+ final Repository repository = repositories().get( "public" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createGroup()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenGroupRepository.class, id )
+ .ofRepositories( "central", "releases", "snapshots" )
+ .save();
+ }
+
+ @Test
+ public void removeGroup()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenGroupRepository.class, id )
+ .ofRepositories( "central", "releases", "snapshots" )
+ .save();
+ }
+
+ @Test
+ public void statusGroup()
+ {
+ final String id = repositoryIdForTest();
+ final MavenGroupRepository repository = repositories().create( MavenGroupRepository.class, id )
+ .ofRepositories( "central", "releases", "snapshots" );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void getShadow()
+ {
+ final Repository repository = repositories().get( "central-m1" );
+ assertThat( repository, is( instanceOf( MavenShadowRepository.class ) ) );
+ }
+
+ @Test
+ public void refreshShadow()
+ {
+ final Repository repository = repositories().get( "central-m1" );
+ final String name = repository.name();
+ repository.withName( "foo" );
+ repository.refresh();
+ assertThat( repository.name(), is( name ) );
+ }
+
+ @Test
+ public void createShadow()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenShadowRepository.class, id )
+ .asShadowOf( "apache-snapshots" )
+ .save();
+ }
+
+ @Test
+ public void removeShadow()
+ {
+ final String id = repositoryIdForTest();
+ repositories().create( MavenShadowRepository.class, id )
+ .asShadowOf( "apache-snapshots" )
+ .save()
+ .remove();
+ }
+
+ @Test
+ public void statusShadow()
+ {
+ final String id = repositoryIdForTest();
+ final MavenShadowRepository repository = repositories().create( MavenShadowRepository.class, id )
+ .asShadowOf( "apache-snapshots" );
+ assertThat( repository.status().isInService(), is( false ) );
+ repository.save();
+ assertThat( repository.status().isInService(), is( true ) );
+ assertThat( repository.putOutOfService().status().isInService(), is( false ) );
+ assertThat( repository.putInService().status().isInService(), is( true ) );
+ }
+
+ @Test
+ public void get()
+ {
+ final Collection<Repository> repositories = repositories().get();
+ assertThat( repositories.size(), is( greaterThanOrEqualTo( 7 ) ) );
+ }
+
+ private Repositories repositories()
+ {
+ return client().getSubsystem( Repositories.class );
+ }
+
+}
View
3  .../nexus-client-core/src/main/java/org/sonatype/nexus/client/core/NexusClientException.java
@@ -15,13 +15,14 @@
/**
* Generic runtime exception to be thrown by Subsystems, when some error is reported by Nexus. This exception here is
* solely for purpose of not proliferating possible runtime exceptions of underlying implementation.
- *
+ *
* @author cstamas
*/
@SuppressWarnings( "serial" )
public abstract class NexusClientException
extends RuntimeException
{
+
public NexusClientException( String message )
{
super( message );
View
3  ...-client-core/src/main/java/org/sonatype/nexus/client/core/NexusErrorMessageException.java
@@ -18,13 +18,14 @@
/**
* Thrown when Nexus responds with an Client Error status code and (optionally) with an error message.
- *
+ *
* @author cstamas
*/
@SuppressWarnings( "serial" )
public class NexusErrorMessageException
extends NexusUnexpectedResponseException
{
+
private final Map<String, String> errors;
public NexusErrorMessageException( final int statusCode, final String statusMessage,
View
5 ...t-core/src/main/java/org/sonatype/nexus/client/core/NexusUnexpectedResponseException.java
@@ -17,13 +17,14 @@
* here is solely for purpose of not proliferating possible runtime exceptions of underlying implementation. Best to use
* some subclass of this exception, but this is the last resort (ie. resource does not send proper response, just HTTP
* code and reason phrase).
- *
+ *
* @author cstamas
*/
@SuppressWarnings( "serial" )
public class NexusUnexpectedResponseException
extends NexusClientException
{
+
private final int statusCode;
private final String statusMessage;
@@ -31,7 +32,7 @@
public NexusUnexpectedResponseException( final int statusCode, final String statusMessage )
{
this( statusCode, statusMessage, String.format( "Unexpected response: %s %s", String.valueOf( statusCode ),
- String.valueOf( statusMessage ) ) );
+ String.valueOf( statusMessage ) ) );
}
public NexusUnexpectedResponseException( final int statusCode, final String statusMessage, final String message )
View
35 .../main/java/org/sonatype/nexus/client/core/spi/subsystem/repository/RepositoryFactory.java
@@ -0,0 +1,35 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.spi.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface RepositoryFactory<R extends Repository>
+{
+
+ int canAdapt( RepositoryBaseResource resource );
+
+ R adapt( JerseyNexusClient nexusClient, RepositoryBaseResource resource );
+
+ boolean canCreate( Class<? extends Repository> type );
+
+ R create( JerseyNexusClient nexusClient, String id );
+
+}
View
2  ...us-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/config/Segment.java
@@ -12,8 +12,6 @@
*/
package org.sonatype.nexus.client.core.subsystem.config;
-import org.sonatype.nexus.rest.model.RemoteHttpProxySettings;
-
/**
* A configuration segment.
*
View
1  ...s-client-core/src/main/java/org/sonatype/nexus/client/core/subsystem/content/Content.java
@@ -17,6 +17,7 @@
public interface Content
{
+
void download( Location location, File target )
throws IOException;
View
26 ...re/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/GroupRepository.java
@@ -0,0 +1,26 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface GroupRepository<T extends GroupRepository>
+ extends Repository<T, RepositoryStatus>
+{
+
+ T ofRepositories( String... memberRepositoryIds );
+
+}
View
36 ...e/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/HostedRepository.java
@@ -0,0 +1,36 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface HostedRepository<T extends HostedRepository>
+ extends Repository<T, RepositoryStatus>
+{
+
+ T withRepoPolicy( final String policy );
+
+ T readOnly();
+
+ T allowRedeploy();
+
+ T disableRedeploy();
+
+ T enableBrowsing();
+
+ T disableBrowsing();
+
+}
View
38 ...re/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ProxyRepository.java
@@ -0,0 +1,38 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface ProxyRepository<T extends ProxyRepository>
+ extends Repository<T, ProxyRepositoryStatus>
+{
+
+ T withRepoPolicy( final String policy );
+
+ T asProxyOf( String remoteUrl );
+
+ T autoBlock();
+
+ T doNotAutoBlock();
+
+ T block();
+
+ T unblock();
+
+ T withNotFoundCacheTTL( int minutes );
+
+}
View
28 .../main/java/org/sonatype/nexus/client/core/subsystem/repository/ProxyRepositoryStatus.java
@@ -0,0 +1,28 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface ProxyRepositoryStatus
+ extends RepositoryStatus
+{
+
+ boolean isBlocked();
+
+ boolean isAutoBlocked();
+
+}
View
35 ...-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/Repositories.java
@@ -0,0 +1,35 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+import java.util.Collection;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface Repositories
+{
+
+ <R extends Repository> R get( String id );
+
+ <R extends Repository> R get( Class<R> type, String id );
+
+ Collection<Repository> get();
+
+ <R extends Repository> Collection<R> get( Class<R> type );
+
+ <R extends Repository> R create( Class<R> type, String id );
+
+}
View
43 ...nt-core/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/Repository.java
@@ -0,0 +1,43 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface Repository<T extends Repository, U extends RepositoryStatus>
+{
+
+ String id();
+
+ String name();
+
+ String contentUri();
+
+ U status();
+
+ T withName( String name );
+
+ T putOutOfService();
+
+ T putInService();
+
+ T refresh();
+
+ T save();
+
+ T remove();
+
+}
View
25 ...e/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/RepositoryStatus.java
@@ -0,0 +1,25 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface RepositoryStatus
+{
+
+ boolean isInService();
+
+}
View
26 ...e/src/main/java/org/sonatype/nexus/client/core/subsystem/repository/ShadowRepository.java
@@ -0,0 +1,26 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface ShadowRepository<T extends ShadowRepository>
+ extends Repository<T, RepositoryStatus>
+{
+
+ T asShadowOf( String repositoryId );
+
+}
View
26 .../java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenGroupRepository.java
@@ -0,0 +1,26 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository.maven;
+
+import org.sonatype.nexus.client.core.subsystem.repository.GroupRepository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface MavenGroupRepository
+ extends GroupRepository<MavenGroupRepository>
+{
+
+}
View
30 ...java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenHostedRepository.java
@@ -0,0 +1,30 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository.maven;
+
+import org.sonatype.nexus.client.core.subsystem.repository.HostedRepository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface MavenHostedRepository
+ extends HostedRepository<MavenHostedRepository>
+{
+
+ MavenHostedRepository includeInSearchResults();
+
+ MavenHostedRepository excludeFromSearchResults();
+
+}
View
30 .../java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenProxyRepository.java
@@ -0,0 +1,30 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository.maven;
+
+import org.sonatype.nexus.client.core.subsystem.repository.ProxyRepository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface MavenProxyRepository
+ extends ProxyRepository<MavenProxyRepository>
+{
+
+ MavenProxyRepository withArtifactMaxAge( int minutes );
+
+ MavenProxyRepository withMetadataMaxAge( int minutes );
+
+}
View
26 ...java/org/sonatype/nexus/client/core/subsystem/repository/maven/MavenShadowRepository.java
@@ -0,0 +1,26 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.core.subsystem.repository.maven;
+
+import org.sonatype.nexus.client.core.subsystem.repository.ShadowRepository;
+
+/**
+ * TODO
+ *
+ * @since 2.2
+ */
+public interface MavenShadowRepository
+ extends ShadowRepository<MavenShadowRepository>
+{
+
+}
View
4 ...lient-core/src/main/java/org/sonatype/nexus/client/internal/rest/NexusXStreamFactory.java
@@ -15,8 +15,8 @@
import org.sonatype.nexus.client.internal.msg.ErrorMessage;
import org.sonatype.nexus.client.internal.msg.ErrorResponse;
import org.sonatype.nexus.rest.model.XStreamConfiguratorLightweight;
+import org.sonatype.plexus.rest.xstream.xml.LookAheadXppDriver;
import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.XppDriver;
/**
* Creates XStream instances "preconfigured" for Nexus Core DTOs.
@@ -33,7 +33,7 @@
*/
public XStream createForXml()
{
- final XStream xstream = new XStream( new XppDriver() );
+ final XStream xstream = new XStream( new LookAheadXppDriver() );
xstream.setMode( XStream.NO_REFERENCES );
xstream.autodetectAnnotations( false );
return xstream;
View
6 ...src/main/java/org/sonatype/nexus/client/internal/rest/jersey/subsystem/JerseyContent.java
@@ -13,7 +13,6 @@
package org.sonatype.nexus.client.internal.rest.jersey.subsystem;
import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
import java.io.File;
import java.io.FileNotFoundException;
@@ -25,14 +24,13 @@
import org.sonatype.nexus.client.core.subsystem.content.Content;
import org.sonatype.nexus.client.core.subsystem.content.Location;
import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
-
-import com.google.common.base.Preconditions;
import com.sun.jersey.api.client.ClientResponse;
public class JerseyContent
extends SubsystemSupport<JerseyNexusClient>
implements Content
{
+
private static final String CONTENT_PREFIX = "content/";
public JerseyContent( final JerseyNexusClient nexusClient )
@@ -55,7 +53,7 @@ public void download( final Location location, final File target )
else
{
checkState(
- target.isFile() && target.canWrite(),
+ target.isFile() && target.canWrite(),
"File '%s' is not a file or could not be written", target.getAbsolutePath()
);
}
View
108 ...onatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyGroupRepository.java
@@ -0,0 +1,108 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.GroupRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.RepositoryStatus;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryGroupMemberRepository;
+import org.sonatype.nexus.rest.model.RepositoryGroupResource;
+import org.sonatype.nexus.rest.model.RepositoryGroupResourceResponse;
+
+public class JerseyGroupRepository<T extends GroupRepository>
+ extends JerseyRepository<T, RepositoryGroupResource, RepositoryStatus>
+ implements GroupRepository<T>
+{
+
+ public JerseyGroupRepository( final JerseyNexusClient nexusClient, final String id )
+ {
+ super( nexusClient, id );
+ }
+
+ public JerseyGroupRepository( final JerseyNexusClient nexusClient, final RepositoryGroupResource resource )
+ {
+ super( nexusClient, resource );
+ }
+
+ @Override
+ protected RepositoryGroupResource createSettings()
+ {
+ final RepositoryGroupResource settings = new RepositoryGroupResource();
+
+ settings.setRepoType( "group" );
+ settings.setProviderRole( "org.sonatype.nexus.proxy.repository.GroupRepository" );
+ settings.setExposed( true );
+
+ return settings;
+ }
+
+ private T me()
+ {
+ return (T) this;
+ }
+
+ @Override
+ String uri()
+ {
+ return "repo_groups";
+ }
+
+ @Override
+ RepositoryGroupResource doGet()
+ {
+ final RepositoryGroupResourceResponse response = getNexusClient()
+ .serviceResource( uri() + "/" + id() )
+ .get( RepositoryGroupResourceResponse.class );
+
+ return response.getData();
+ }
+
+ @Override
+ RepositoryGroupResource doCreate()
+ {
+ final RepositoryGroupResourceResponse request = new RepositoryGroupResourceResponse();
+ request.setData( settings() );
+
+ final RepositoryGroupResourceResponse response = getNexusClient()
+ .serviceResource( uri() )
+ .post( RepositoryGroupResourceResponse.class, request );
+
+ return response.getData();
+ }
+
+ @Override
+ RepositoryGroupResource doUpdate()
+ {
+ final RepositoryGroupResourceResponse request = new RepositoryGroupResourceResponse();
+ request.setData( settings() );
+
+ final RepositoryGroupResourceResponse response = getNexusClient()
+ .serviceResource( uri() + "/" + id() )
+ .put( RepositoryGroupResourceResponse.class, request );
+
+ return response.getData();
+ }
+
+ @Override
+ public T ofRepositories( final String... memberRepositoryIds )
+ {
+ for ( final String memberRepositoryId : memberRepositoryIds )
+ {
+ final RepositoryGroupMemberRepository repository = new RepositoryGroupMemberRepository();
+ repository.setId( memberRepositoryId );
+ settings().addRepository( repository );
+ }
+ return me();
+ }
+
+}
View
61 .../nexus/client/internal/rest/jersey/subsystem/repository/JerseyGroupRepositoryFactory.java
@@ -0,0 +1,61 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
+import org.sonatype.nexus.client.core.subsystem.repository.GroupRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryGroupResource;
+
+@Named
+@Singleton
+public class JerseyGroupRepositoryFactory
+ implements RepositoryFactory<GroupRepository>
+{
+
+ @Override
+ public int canAdapt( final RepositoryBaseResource resource )
+ {
+ int score = 0;
+ if ( resource instanceof RepositoryGroupResource )
+ {
+ score++;
+ }
+ return score;
+ }
+
+ @Override
+ public JerseyGroupRepository adapt( final JerseyNexusClient nexusClient,
+ final RepositoryBaseResource resource )
+ {
+ return new JerseyGroupRepository( nexusClient, (RepositoryGroupResource) resource );
+ }
+
+ @Override
+ public boolean canCreate( final Class<? extends Repository> type )
+ {
+ return GroupRepository.class.equals( type );
+ }
+
+ @Override
+ public JerseyGroupRepository create( final JerseyNexusClient nexusClient, final String id )
+ {
+ return new JerseyGroupRepository( nexusClient, id );
+ }
+
+}
View
98 ...natype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyHostedRepository.java
@@ -0,0 +1,98 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.HostedRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.RepositoryStatus;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryResource;
+
+public class JerseyHostedRepository<T extends HostedRepository>
+ extends JerseyRepository<T, RepositoryResource, RepositoryStatus>
+ implements HostedRepository<T>
+{
+
+ public JerseyHostedRepository( final JerseyNexusClient nexusClient, final String id )
+ {
+ super( nexusClient, id );
+ }
+
+ public JerseyHostedRepository( final JerseyNexusClient nexusClient, final RepositoryResource resource )
+ {
+ super( nexusClient, resource );
+ }
+
+ @Override
+ protected RepositoryResource createSettings()
+ {
+ final RepositoryResource settings = new RepositoryResource();
+
+ settings.setRepoType( "hosted" );
+ settings.setProviderRole( "org.sonatype.nexus.proxy.repository.Repository" );
+ settings.setExposed( true );
+ settings.setWritePolicy( "ALLOW_WRITE_ONCE" );
+ settings.setBrowseable( true );
+ settings.setIndexable( false );
+ settings.setRepoPolicy( "MIXED" );
+
+ return settings;
+ }
+
+ private T me()
+ {
+ return (T) this;
+ }
+
+ @Override
+ public T withRepoPolicy( final String policy )
+ {
+ settings().setRepoPolicy( policy );
+ return me();
+ }
+
+ @Override
+ public T readOnly()
+ {
+ settings().setWritePolicy( "READ_ONLY" );
+ return me();
+ }
+
+ @Override
+ public T allowRedeploy()
+ {
+ settings().setWritePolicy( "ALLOW_WRITE_ONCE" );
+ return me();
+ }
+
+ @Override
+ public T disableRedeploy()
+ {
+ settings().setWritePolicy( "ALLOW_WRITE" );
+ return me();
+ }
+
+ @Override
+ public T enableBrowsing()
+ {
+ settings().setBrowseable( true );
+ return me();
+ }
+
+ @Override
+ public T disableBrowsing()
+ {
+ settings().setBrowseable( false );
+ return me();
+ }
+
+}
View
64 ...nexus/client/internal/rest/jersey/subsystem/repository/JerseyHostedRepositoryFactory.java
@@ -0,0 +1,64 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
+import org.sonatype.nexus.client.core.subsystem.repository.HostedRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryResource;
+
+@Named
+@Singleton
+public class JerseyHostedRepositoryFactory
+ implements RepositoryFactory<HostedRepository>
+{
+
+ @Override
+ public int canAdapt( final RepositoryBaseResource resource )
+ {
+ int score = 0;
+ if ( resource instanceof RepositoryResource )
+ {
+ score++;
+ }
+ if ( "hosted".equals( resource.getRepoType() ) )
+ {
+ score++;
+ }
+ return score;
+ }
+
+ @Override
+ public JerseyHostedRepository adapt( final JerseyNexusClient nexusClient,
+ final RepositoryBaseResource resource )
+ {
+ return new JerseyHostedRepository( nexusClient, (RepositoryResource) resource );
+ }
+
+ @Override
+ public boolean canCreate( final Class<? extends Repository> type )
+ {
+ return HostedRepository.class.equals( type );
+ }
+
+ @Override
+ public JerseyHostedRepository create( final JerseyNexusClient nexusClient, final String id )
+ {
+ return new JerseyHostedRepository( nexusClient, id );
+ }
+}
View
139 ...onatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyProxyRepository.java
@@ -0,0 +1,139 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.ProxyRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.ProxyRepositoryStatus;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryProxyResource;
+import org.sonatype.nexus.rest.model.RepositoryResourceRemoteStorage;
+import org.sonatype.nexus.rest.model.RepositoryStatusResource;
+
+public class JerseyProxyRepository<T extends ProxyRepository>
+ extends JerseyRepository<T, RepositoryProxyResource, ProxyRepositoryStatus>
+ implements ProxyRepository<T>
+{
+
+ public JerseyProxyRepository( final JerseyNexusClient nexusClient, final String id )
+ {
+ super( nexusClient, id );
+ }
+
+ public JerseyProxyRepository( final JerseyNexusClient nexusClient, final RepositoryProxyResource settings )
+ {
+ super( nexusClient, settings );
+ }
+
+ @Override
+ protected RepositoryProxyResource createSettings()
+ {
+ final RepositoryProxyResource settings = new RepositoryProxyResource();
+
+ settings.setRepoType( "proxy" );
+ settings.setProviderRole( "org.sonatype.nexus.proxy.repository.Repository" );
+ settings.setExposed( true );
+ settings.setWritePolicy( "READ_ONLY" );
+ settings.setBrowseable( true );
+ settings.setIndexable( false );
+ settings.setNotFoundCacheTTL( 1440 );
+ settings.setRepoPolicy( "MIXED" );
+ settings.setChecksumPolicy( "WARN" );
+ settings.setDownloadRemoteIndexes( true );
+ settings.setFileTypeValidation( true );
+ settings.setArtifactMaxAge( -1 );
+ settings.setMetadataMaxAge( 1440 );
+ settings.setAutoBlockActive( true );
+
+ return settings;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private T me()
+ {
+ return (T) this;
+ }
+
+ @Override
+ ProxyRepositoryStatus convertStatus( final RepositoryStatusResource status )
+ {
+ if ( status == null )
+ {
+ return new ProxyRepositoryStatusImpl( false, false, false );
+ }
+ return new ProxyRepositoryStatusImpl(
+ "IN_SERVICE".equals( status.getLocalStatus() ),
+ !"ALLOW".equals( status.getProxyMode() ),
+ "BLOCKED_AUTO".equals( status.getProxyMode() )
+ );
+ }
+
+ @Override
+ public T withRepoPolicy( final String policy )
+ {
+ settings().setRepoPolicy( policy );
+ return me();
+ }
+
+ @Override
+ public T asProxyOf( final String remoteUrl )
+ {
+ RepositoryResourceRemoteStorage remoteStorage = settings().getRemoteStorage();
+ if ( remoteStorage == null )
+ {
+ remoteStorage = new RepositoryResourceRemoteStorage();
+ settings().setRemoteStorage( remoteStorage );
+ }
+ remoteStorage.setRemoteStorageUrl( remoteUrl );
+ return me();
+ }
+
+ @Override
+ public T withNotFoundCacheTTL( final int minutes )
+ {
+ settings().setNotFoundCacheTTL( minutes );
+ return me();
+ }
+
+ @Override
+ public T autoBlock()
+ {
+ settings().setAutoBlockActive( true );
+ return me();
+ }
+
+ @Override
+ public T doNotAutoBlock()
+ {
+ settings().setAutoBlockActive( false );
+ return me();
+ }
+
+ @Override
+ public T block()
+ {
+ final RepositoryStatusResource newStatus = doGetStatus();
+ newStatus.setProxyMode( "BLOCKED_MANUAL" );
+ doUpdateStatus( newStatus );
+ return me();
+ }
+
+ @Override
+ public T unblock()
+ {
+ final RepositoryStatusResource newStatus = doGetStatus();
+ newStatus.setProxyMode( "ALLOW" );
+ doUpdateStatus( newStatus );
+ return me();
+ }
+
+}
View
65 .../nexus/client/internal/rest/jersey/subsystem/repository/JerseyProxyRepositoryFactory.java
@@ -0,0 +1,65 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
+import org.sonatype.nexus.client.core.subsystem.repository.ProxyRepository;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryProxyResource;
+
+@Named
+@Singleton
+public class JerseyProxyRepositoryFactory
+ implements RepositoryFactory<ProxyRepository>
+{
+
+ @Override
+ public int canAdapt( final RepositoryBaseResource resource )
+ {
+ int score = 0;
+ if ( resource instanceof RepositoryProxyResource )
+ {
+ score++;
+ }
+ if ( "proxy".equals( resource.getRepoType() ) )
+ {
+ score++;
+ }
+ return score;
+ }
+
+ @Override
+ public JerseyProxyRepository adapt( final JerseyNexusClient nexusClient,
+ final RepositoryBaseResource resource )
+ {
+ return new JerseyProxyRepository( nexusClient, (RepositoryProxyResource) resource );
+ }
+
+ @Override
+ public boolean canCreate( final Class<? extends Repository> type )
+ {
+ return ProxyRepository.class.equals( type );
+ }
+
+ @Override
+ public JerseyProxyRepository create( final JerseyNexusClient nexusClient, final String id )
+ {
+ return new JerseyProxyRepository( nexusClient, id );
+ }
+
+}
View
172 ...g/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyRepositories.java
@@ -0,0 +1,172 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.lang.String.format;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.Nullable;
+
+import org.sonatype.nexus.client.core.spi.SubsystemSupport;
+import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
+import org.sonatype.nexus.client.core.subsystem.repository.Repositories;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryGroupResourceResponse;
+import org.sonatype.nexus.rest.model.RepositoryListResource;
+import org.sonatype.nexus.rest.model.RepositoryListResourceResponse;
+import org.sonatype.nexus.rest.model.RepositoryResourceResponse;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+
+/**
+ * @since 2.2
+ */
+public class JerseyRepositories
+ extends SubsystemSupport<JerseyNexusClient>
+ implements Repositories
+{
+
+ private final Set<RepositoryFactory> repositoryFactories;
+
+ public JerseyRepositories( final JerseyNexusClient nexusClient,
+ final Set<RepositoryFactory> repositoryFactories )
+ {
+ super( nexusClient );
+ this.repositoryFactories = repositoryFactories;
+ }
+
+ @Override
+ public <R extends Repository> R get( final String id )
+ {
+ checkNotNull( id );
+
+ // TODO the code is inefficient as it will at worst make two calls. Should be fixed when we have a proper repositories REST resource that will return also groups
+
+ ClientResponse response = getNexusClient()
+ .serviceResource( "repositories/" + id )
+ .get( ClientResponse.class );
+
+ if ( response.getStatus() < 300 )
+ {
+ return convert( id, response.getEntity( RepositoryResourceResponse.class ).getData() );
+ }
+
+ response.close();
+ response = getNexusClient()
+ .serviceResource( "repo_groups/" + id )
+ .get( ClientResponse.class );
+
+ if ( response.getStatus() < 300 )
+ {
+ return convert( id, response.getEntity( RepositoryGroupResourceResponse.class ).getData() );
+ }
+
+ throw new UniformInterfaceException( response );
+ }
+
+ @Override
+ public <R extends Repository> R get( final Class<R> type, final String id )
+ {
+ return type.cast( get( id ) );
+ }
+
+ @Override
+ public Collection<Repository> get()
+ {
+ final RepositoryListResourceResponse response = getNexusClient()
+ .serviceResource( "repositories" )
+ .get( RepositoryListResourceResponse.class );
+
+ if ( response == null || response.getData() == null || response.getData().isEmpty() )
+ {
+ return Collections.emptyList();
+ }
+
+ List<Repository> repositories = Lists.newArrayList();
+
+ for ( final RepositoryListResource resource : response.getData() )
+ {
+ repositories.add( get( resource.getId() ) );
+ }
+
+ return repositories;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Override
+ public <R extends Repository> Collection<R> get( final Class<R> type )
+ {
+ final Collection<Repository> repositories = get();
+ final Collection<Repository> filtered = Collections2.filter( repositories, new Predicate<Repository>()
+ {
+ @Override
+ public boolean apply( @Nullable final Repository repository )
+ {
+ return repository != null && type.isAssignableFrom( repository.getClass() );
+ }
+ }
+ );
+ return (Collection<R>) filtered;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ @Override
+ public <R extends Repository> R create( final Class<R> type, final String id )
+ {
+ for ( RepositoryFactory repositoryFactory : repositoryFactories )
+ {
+ if ( repositoryFactory.canCreate( type ) )
+ {
+ final Repository r = repositoryFactory.create( getNexusClient(), id );
+ return (R) r;
+ }
+ }
+ throw new IllegalStateException(
+ format( "No repository factory found for repository of type %s", type.getName() )
+ );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private <R extends Repository> R convert( final String id, final RepositoryBaseResource rbs )
+ {
+ int currentScore = 0;
+ RepositoryFactory factory = null;
+ for ( RepositoryFactory repositoryFactory : repositoryFactories )
+ {
+ final int score = repositoryFactory.canAdapt( rbs );
+ if ( score > currentScore )
+ {
+ factory = repositoryFactory;
+ }
+ }
+
+ if ( factory == null )
+ {
+ throw new IllegalStateException(
+ format( "No repository factory found for repository with id %s", id )
+ );
+ }
+
+ return (R) factory.adapt( getNexusClient(), rbs );
+ }
+
+}
View
254 ...org/sonatype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyRepository.java
@@ -0,0 +1,254 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.sonatype.nexus.client.core.spi.SubsystemSupport;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.core.subsystem.repository.RepositoryStatus;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryResourceResponse;
+import org.sonatype.nexus.rest.model.RepositoryStatusResource;
+import org.sonatype.nexus.rest.model.RepositoryStatusResourceResponse;
+import com.google.common.base.Throwables;
+
+public abstract class JerseyRepository<T extends Repository, S extends RepositoryBaseResource, U extends RepositoryStatus>
+ extends SubsystemSupport<JerseyNexusClient>
+ implements Repository<T, U>
+{
+
+ private final String id;
+
+ private final S settings;
+
+ private RepositoryStatusResource status;
+
+ private boolean shouldCreate;
+
+ public JerseyRepository( final JerseyNexusClient nexusClient,
+ final String id )
+ {
+ super( nexusClient );
+ this.id = id;
+ this.settings = checkNotNull( createSettings() );
+ this.shouldCreate = true;
+ this.status = null;
+ settings().setId( this.id );
+ }
+
+ public JerseyRepository( final JerseyNexusClient nexusClient,
+ final S settings )
+ {
+ this( nexusClient, checkNotNull( checkNotNull( settings ).getId() ) );
+ this.shouldCreate = false;
+ overwriteSettingsWith( settings );
+ }
+
+ @Override
+ public String id()
+ {
+ return id;
+ }
+
+ @Override
+ public String name()
+ {
+ return settings().getName();
+ }
+
+ @Override
+ public String contentUri()
+ {
+ return settings().getContentResourceURI();
+ }
+
+ @Override
+ public T withName( final String name )
+ {
+ settings().setName( name );
+ return me();
+ }
+
+ protected S settings()
+ {
+ return settings;
+ }
+
+ @Override
+ public synchronized T refresh()
+ {
+ S processed = null;
+
+ if ( !shouldCreate )
+ {
+ processed = doGet();
+ }
+
+ shouldCreate = processed == null;
+ status = null;
+
+ overwriteSettingsWith( processed );
+
+ return me();
+ }
+
+ @Override
+ public synchronized T save()
+ {
+ final S processed;
+ if ( shouldCreate )
+ {
+ processed = doCreate();
+ }
+ else
+ {
+ processed = doUpdate();
+ }
+ overwriteSettingsWith( processed );
+ shouldCreate = false;
+ status = null;
+ return me();
+ }
+
+ @Override
+ public synchronized T remove()
+ {
+ doRemove();
+ shouldCreate = true;
+ status = null;
+ return me();
+ }
+
+ @Override
+ public U status()
+ {
+ if ( status == null && !shouldCreate )
+ {
+ status = doGetStatus();
+ }
+ return convertStatus( status );
+ }
+
+ @Override
+ public T putInService()
+ {
+ final RepositoryStatusResource newStatus = doGetStatus();
+ newStatus.setLocalStatus( "IN_SERVICE" );
+ doUpdateStatus( newStatus );
+ return me();
+ }
+
+ @Override
+ public T putOutOfService()
+ {
+ final RepositoryStatusResource newStatus = doGetStatus();
+ newStatus.setLocalStatus( "OUT_OF_SERVICE" );
+ doUpdateStatus( newStatus );
+ return me();
+ }
+
+ protected abstract S createSettings();
+
+ String uri()
+ {
+ return "repositories";
+ }
+
+ private void overwriteSettingsWith( final S source )
+ {
+ try
+ {
+ BeanUtils.copyProperties( settings(), source == null ? checkNotNull( createSettings() ) : source );
+ settings().setId( id() );
+ }
+ catch ( final Exception e )
+ {
+ throw Throwables.propagate( e );
+ }
+ }
+
+ private T me()
+ {
+ return (T) this;
+ }
+
+ S doGet()
+ {
+ final RepositoryResourceResponse response = getNexusClient()
+ .serviceResource( uri() + "/" + id() )
+ .get( RepositoryResourceResponse.class );
+
+ return (S) response.getData();
+ }
+
+ S doCreate()
+ {
+ final RepositoryResourceResponse request = new RepositoryResourceResponse();
+ request.setData( settings() );
+
+ final RepositoryResourceResponse response = getNexusClient()
+ .serviceResource( uri() )
+ .post( RepositoryResourceResponse.class, request );
+
+ return (S) response.getData();
+ }
+
+ S doUpdate()
+ {
+ final RepositoryResourceResponse request = new RepositoryResourceResponse();
+ request.setData( settings() );
+
+ final RepositoryResourceResponse response = getNexusClient()
+ .serviceResource( uri() + "/" + id() )
+ .put( RepositoryResourceResponse.class, request );
+
+ return (S) response.getData();
+ }
+
+ private void doRemove()
+ {
+ getNexusClient()
+ .serviceResource( uri() + "/" + id() )
+ .delete();
+ }
+
+ U convertStatus( final RepositoryStatusResource status )
+ {
+ if ( status == null )
+ {
+ return (U) new RepositoryStatusImpl( false );
+ }
+ return (U) new RepositoryStatusImpl( "IN_SERVICE".equals( status.getLocalStatus() ) );
+ }
+
+ RepositoryStatusResource doGetStatus()
+ {
+ return getNexusClient()
+ .serviceResource( "repositories/" + id() + "/status" )
+ .get( RepositoryStatusResourceResponse.class ).getData();
+ }
+
+ RepositoryStatusResource doUpdateStatus( final RepositoryStatusResource status )
+ {
+ final RepositoryStatusResourceResponse request = new RepositoryStatusResourceResponse();
+ request.setData( status );
+ final RepositoryStatusResourceResponse response = getNexusClient()
+ .serviceResource( "repositories/" + id() + "/status" )
+ .put( RepositoryStatusResourceResponse.class, request );
+ return this.status = response.getData();
+ }
+
+}
View
59 ...natype/nexus/client/internal/rest/jersey/subsystem/repository/JerseyShadowRepository.java
@@ -0,0 +1,59 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.RepositoryStatus;
+import org.sonatype.nexus.client.core.subsystem.repository.ShadowRepository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryShadowResource;
+
+public class JerseyShadowRepository<T extends ShadowRepository>
+ extends JerseyRepository<T, RepositoryShadowResource, RepositoryStatus>
+ implements ShadowRepository<T>
+{
+
+ public JerseyShadowRepository( final JerseyNexusClient nexusClient, final String id )
+ {
+ super( nexusClient, id );
+ }
+
+ public JerseyShadowRepository( final JerseyNexusClient nexusClient, final RepositoryShadowResource settings )
+ {
+ super( nexusClient, settings );
+ }
+
+ @Override
+ protected RepositoryShadowResource createSettings()
+ {
+ final RepositoryShadowResource settings = new RepositoryShadowResource();
+
+ settings.setRepoType( "virtual" );
+ settings.setProviderRole( "org.sonatype.nexus.proxy.repository.ShadowRepository" );
+ settings.setExposed( true );
+
+ return settings;
+ }
+
+ private T me()
+ {
+ return (T) this;
+ }
+
+ @Override
+ public T asShadowOf( final String repositoryId )
+ {
+ settings().setShadowOf( repositoryId );
+ return me();
+ }
+
+}
View
65 ...nexus/client/internal/rest/jersey/subsystem/repository/JerseyShadowRepositoryFactory.java
@@ -0,0 +1,65 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.sonatype.nexus.client.core.spi.subsystem.repository.RepositoryFactory;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.core.subsystem.repository.ShadowRepository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryShadowResource;
+
+@Named
+@Singleton
+public class JerseyShadowRepositoryFactory
+ implements RepositoryFactory<ShadowRepository>
+{
+
+ @Override
+ public int canAdapt( final RepositoryBaseResource resource )
+ {
+ int score = 0;
+ if ( resource instanceof RepositoryShadowResource )
+ {
+ score++;
+ }
+ if ( "virtual".equals( resource.getRepoType() ) )
+ {
+ score++;
+ }
+ return score;
+ }
+
+ @Override
+ public JerseyShadowRepository adapt( final JerseyNexusClient nexusClient,
+ final RepositoryBaseResource resource )
+ {
+ return new JerseyShadowRepository( nexusClient, (RepositoryShadowResource) resource );
+ }
+
+ @Override
+ public boolean canCreate( final Class<? extends Repository> type )
+ {
+ return ShadowRepository.class.equals( type );
+ }
+
+ @Override
+ public JerseyShadowRepository create( final JerseyNexusClient nexusClient, final String id )
+ {
+ return new JerseyShadowRepository( nexusClient, id );
+ }
+
+}
View
50 ...ype/nexus/client/internal/rest/jersey/subsystem/repository/ProxyRepositoryStatusImpl.java
@@ -0,0 +1,50 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.ProxyRepositoryStatus;
+
+/**
+ * @since 2.2
+ */
+public class ProxyRepositoryStatusImpl
+ extends RepositoryStatusImpl
+ implements ProxyRepositoryStatus
+{
+
+ private final boolean blocked;
+
+ private final boolean autoBlocked;
+
+ public ProxyRepositoryStatusImpl( final boolean inService,
+ final boolean blocked,
+ final boolean autoBlocked )
+ {
+ super( inService );
+ this.blocked = blocked;
+ this.autoBlocked = autoBlocked;
+ }
+
+ @Override
+ public boolean isBlocked()
+ {
+ return blocked;
+ }
+
+ @Override
+ public boolean isAutoBlocked()
+ {
+ return autoBlocked;
+ }
+
+}
View
37 ...sonatype/nexus/client/internal/rest/jersey/subsystem/repository/RepositoryStatusImpl.java
@@ -0,0 +1,37 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository;
+
+import org.sonatype.nexus.client.core.subsystem.repository.RepositoryStatus;
+
+/**
+ * @since 2.2
+ */
+public class RepositoryStatusImpl
+ implements RepositoryStatus
+{
+
+ private final boolean inService;
+
+ public RepositoryStatusImpl( final boolean inService )
+ {
+ this.inService = inService;
+ }
+
+ @Override
+ public boolean isInService()
+ {
+ return inService;
+ }
+
+}
View
45 ...us/client/internal/rest/jersey/subsystem/repository/maven/JerseyMavenGroupRepository.java
@@ -0,0 +1,45 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven;
+
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenGroupRepository;
+import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyGroupRepository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryGroupResource;
+
+public class JerseyMavenGroupRepository
+ extends JerseyGroupRepository<MavenGroupRepository>
+ implements MavenGroupRepository
+{
+
+ public JerseyMavenGroupRepository( final JerseyNexusClient nexusClient, final String id )
+ {
+ super( nexusClient, id );
+ }
+
+ public JerseyMavenGroupRepository( final JerseyNexusClient nexusClient, final RepositoryGroupResource resource )
+ {
+ super( nexusClient, resource );
+ }
+
+ @Override
+ protected RepositoryGroupResource createSettings()
+ {
+ final RepositoryGroupResource settings = super.createSettings();
+
+ settings.setProvider( "maven2" );
+
+ return settings;
+ }
+
+}
View
64 ...nt/internal/rest/jersey/subsystem/repository/maven/JerseyMavenGroupRepositoryFactory.java
@@ -0,0 +1,64 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.maven;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenGroupRepository;
+import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyGroupRepositoryFactory;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryGroupResource;
+
+@Named
+@Singleton
+public class JerseyMavenGroupRepositoryFactory
+ extends JerseyGroupRepositoryFactory
+{
+
+ @Override
+ public int canAdapt( final RepositoryBaseResource resource )
+ {
+ int score = super.canAdapt( resource );
+ if ( score > 0 )
+ {
+ if ( "maven2".equals( resource.getProvider() ) )
+ {
+ score++;
+ }
+ }
+ return score;
+ }
+
+ @Override
+ public JerseyMavenGroupRepository adapt( final JerseyNexusClient nexusClient,
+ final RepositoryBaseResource resource )