Permalink
Browse files

Merge remote-tracking branch 'origin/master' into squash-o-matic-output

  • Loading branch information...
2 parents a53b19e + 49b8efc commit 4ce719876f2de6164e6e45ff08b917f81f8e9c37 @cstamas cstamas committed Nov 28, 2012
Showing with 2,632 additions and 402 deletions.
  1. +1 −1 nexus-maven-plugins/pom.xml
  2. +85 −0 nexus/nexus-api/src/main/java/org/sonatype/nexus/mime/NexusExtensionMimeDetector.java
  3. +202 −0 nexus/nexus-api/src/main/java/org/sonatype/nexus/mime/NexusMimeTypes.java
  4. +13 −0 nexus/nexus-api/src/main/resources/builtin-mimetypes.properties
  5. +73 −0 nexus/nexus-api/src/test/java/org/sonatype/nexus/mime/NexusExtensionMimeDetectorTest.java
  6. +87 −0 nexus/nexus-api/src/test/java/org/sonatype/nexus/mime/NexusMimeTypesTest.java
  7. +18 −2 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/AbstractFormField.java
  8. +8 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/CheckboxFormField.java
  9. +8 −2 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/FormField.java
  10. +8 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/NumberTextFormField.java
  11. +8 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/RepoComboFormField.java
  12. +8 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/RepoOrGroupComboFormField.java
  13. +8 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/StringTextFormField.java
  14. +7 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/formfields/TextAreaFormField.java
  15. +12 −10 nexus/nexus-core/src/main/java/org/sonatype/nexus/mime/DefaultMimeSupport.java
  16. +34 −19 nexus/nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/MavenFileTypeValidator.java
  17. +0 −1 nexus/nexus-core/src/main/java/org/sonatype/nexus/proxy/maven/maven2/M2GroupRepository.java
  18. +13 −0 ...c/main/java/org/sonatype/nexus/proxy/repository/validator/AbstractMimeMagicFileTypeValidator.java
  19. +2 −3 nexus/nexus-core/src/main/resources/mime-types.properties
  20. +67 −1 nexus/nexus-core/src/test/java/org/sonatype/nexus/mime/DefaultMimeSupportTest.java
  21. +59 −0 nexus/nexus-core/src/test/java/org/sonatype/nexus/proxy/maven/MavenFileTypeValidatorTest.java
  22. +1 −1 ...c/test/java/org/sonatype/nexus/proxy/repository/validator/AbstractFileTypeValidationUtilTest.java
  23. +1 −1 nexus/nexus-launcher/pom.xml
  24. +2 −0 nexus/nexus-proxy/src/test/resources/mimetypes.properties
  25. +120 −0 ...elper-plugin/src/main/java/org/sonatype/nexus/plugins/events/api/EventsWaitForPlexusResource.java
  26. +13 −119 ...it-helper-plugin/src/main/java/org/sonatype/nexus/plugins/tasks/api/TaskHelperPlexusResource.java
  27. +216 −0 ...-helper-plugin/src/main/java/org/sonatype/nexus/plugins/tasks/api/TasksWaitForPlexusResource.java
  28. +5 −0 nexus/nexus-test/nexus-testsuite-client/pom.xml
  29. +56 −0 ...s/nexus-test/nexus-testsuite-client/src/main/java/org/sonatype/nexus/testsuite/client/Events.java
  30. +33 −0 ...exus-test/nexus-testsuite-client/src/main/java/org/sonatype/nexus/testsuite/client/Scheduler.java
  31. +34 −0 .../main/java/org/sonatype/nexus/testsuite/client/exception/EventsAreStillBeingHandledException.java
  32. +34 −0 ...nt/src/main/java/org/sonatype/nexus/testsuite/client/exception/TasksAreStillRunningException.java
  33. +111 −0 ...xus-testsuite-client/src/main/java/org/sonatype/nexus/testsuite/client/internal/JerseyEvents.java
  34. +98 −0 ...-testsuite-client/src/main/java/org/sonatype/nexus/testsuite/client/internal/JerseyScheduler.java
  35. +54 −0 ...e-client/src/main/java/org/sonatype/nexus/testsuite/client/rest/JerseyEventsSubsystemFactory.java
  36. +54 −0 ...lient/src/main/java/org/sonatype/nexus/testsuite/client/rest/JerseySchedulerSubsystemFactory.java
  37. +1 −1 ...te/client/rest/{JerseyUIDLocksFactorySubsystemFactory.java → JerseyUIDLocksSubsystemFactory.java}
  38. +6 −2 ...st/nexus-testsuite-support/src/main/java/org/sonatype/nexus/testsuite/support/NexusITSupport.java
  39. +2 −2 ...s-testsuite-support/src/main/java/org/sonatype/nexus/testsuite/support/NexusRunningITSupport.java
  40. +1 −1 nexus/nexus-webapp/src/main/webapp/js/ext/all.js
  41. +28 −0 nexus/nexus-webapp/src/main/webapp/js/ext/element.js
  42. +0 −1 nexus/nexus-webapp/src/main/webapp/js/nexus/panels/GridViewer.js
  43. +24 −0 nexus/nexus-webapp/src/main/webapp/js/nexus/util/FormFieldUtil.js
  44. +0 −7 nexus/nexus-webapp/src/main/webapp/style/Sonatype.css
  45. +124 −107 ...xer/nexus-indexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/DefaultIndexerManager.java
  46. +71 −0 ...exer/nexus-indexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/NexusIndexingContext.java
  47. +385 −0 ...xer/nexus-indexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/NexusScanningListener.java
  48. +216 −0 ...ndexer-lucene-plugin/src/test/java/org/sonatype/nexus/index/Nexus5393IndexEntryDuplicationIT.java
  49. +148 −0 ...lucene-plugin/src/test/java/org/sonatype/nexus/index/Nexus5393IndexEntryDuplicationLocalTest.java
  50. BIN ...ene-plugin/src/test/resources/nexus-5393/remote-repository/.index/nexus-maven-repository-index.gz
  51. +1 −0 ...plugin/src/test/resources/nexus-5393/remote-repository/.index/nexus-maven-repository-index.gz.md5
  52. +1 −0 ...lugin/src/test/resources/nexus-5393/remote-repository/.index/nexus-maven-repository-index.gz.sha1
  53. +6 −0 ...in/src/test/resources/nexus-5393/remote-repository/.index/nexus-maven-repository-index.properties
  54. +1 −0 ...rc/test/resources/nexus-5393/remote-repository/.index/nexus-maven-repository-index.properties.md5
  55. +1 −0 ...c/test/resources/nexus-5393/remote-repository/.index/nexus-maven-repository-index.properties.sha1
  56. BIN ...lucene-plugin/src/test/resources/nexus-5393/remote-repository/log4j/log4j/1.2.13/log4j-1.2.13.jar
  57. +1 −0 ...e-plugin/src/test/resources/nexus-5393/remote-repository/log4j/log4j/1.2.13/log4j-1.2.13.jar.sha1
  58. +13 −0 ...lucene-plugin/src/test/resources/nexus-5393/remote-repository/log4j/log4j/1.2.13/log4j-1.2.13.pom
  59. +1 −0 ...e-plugin/src/test/resources/nexus-5393/remote-repository/log4j/log4j/1.2.13/log4j-1.2.13.pom.sha1
  60. +1 −1 nexus/plugins/nexus-maven-bridge-plugin/pom.xml
  61. +7 −0 nexus/plugins/restlet1x/nexus-restlet1x-model/src/main/mdo/vos.xml
  62. +15 −11 ...t1x/nexus-restlet1x-plugin/src/main/java/org/sonatype/nexus/rest/IndexTemplatePlexusResource.java
  63. +5 −1 ...s-restlet1x-plugin/src/main/java/org/sonatype/nexus/rest/formfield/AbstractFormFieldResource.java
  64. +20 −102 nexus/pom.xml
@@ -159,7 +159,7 @@
<dependency>
<groupId>org.sonatype.sisu.litmus</groupId>
<artifactId>litmus-testsupport</artifactId>
- <version>1.4</version>
+ <version>1.5.1</version>
<scope>test</scope>
</dependency>
@@ -0,0 +1,85 @@
+/**
+ * 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.mime;
+
+import java.util.Collection;
+import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
+import eu.medsea.mimeutil.MimeException;
+import eu.medsea.mimeutil.MimeUtil2;
+import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
+
+/**
+ * File extension detector using {@link NexusMimeTypes}. Falls back to the default MimeUtil behavior if not mime type is
+ * set.
+ *
+ * @since 2.3
+ */
+public class NexusExtensionMimeDetector
+ extends ExtensionMimeDetector
+{
+
+ private NexusMimeTypes mimeTypes;
+
+ public NexusExtensionMimeDetector()
+ {
+ this( new NexusMimeTypes() );
+ }
+
+ public NexusExtensionMimeDetector( final NexusMimeTypes mimeTypes )
+ {
+ this.mimeTypes = mimeTypes;
+ }
+
+ @VisibleForTesting
+ void setNexusMimeTypes( NexusMimeTypes mimeTypes )
+ {
+ this.mimeTypes = mimeTypes;
+ }
+
+ @Override
+ public Collection getMimeTypesFileName( final String fileName )
+ throws MimeException
+ {
+
+ final List<String> detected = Lists.newArrayList();
+
+ final String extension = MimeUtil2.getExtension( fileName );
+ final NexusMimeTypes.NexusMimeType mimeType = mimeTypes.getMimeTypes( extension );
+ if ( mimeType != null )
+ {
+ if ( mimeType.isOverride() )
+ {
+ detected.addAll( mimeType.getMimetypes() );
+ return detected;
+ }
+ else
+ {
+ final Collection defaultTypes = super.getMimeTypesFileName( fileName );
+
+ // HACK we have to list additional mimetypes first, because MimeUtil2#getMostSpecificMimeType
+ // is broken and will usually choose the last mimetype in the list.
+ detected.addAll( mimeType.getMimetypes() );
+ detected.addAll( defaultTypes );
+ return detected;
+ }
+ }
+
+ return super.getMimeTypesFileName( fileName );
+ }
+}
@@ -0,0 +1,202 @@
+/**
+ * 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.mime;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import eu.medsea.mimeutil.MimeUtil2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parse mime type extensions and overrides from classpath.
+ *
+ * This class will look up '/builtin-mimetypes.properties' and '/nexus.mimetypes' from classpath.
+ * These property files must have the following format:
+ * <ul>
+ * <li><em>additional mimetypes:</em>
+ * A mapping from file name extension to a comma separated list of mime types (e.g. "bz2: application/x-bzip2,application/x-bzip").
+ * No whitespace is allowed in the list of mime types.</li>
+ *
+ * <li><em>overriding mimetypes:</em>
+ * The format is the same as adding mime types, but prefixed with 'override.' (e.g. "override.html: text/xhtml,application/xml").
+ * These mime type definitions will override the builtin mime types.
+ * The first listed mimetype is the 'primary' mime type and will be used by Nexus as the downstream content type.
+ * </li>
+ * </ul>
+ *
+ * @since 2.3
+ */
+public class NexusMimeTypes
+{
+
+ private static Logger log = LoggerFactory.getLogger( NexusMimeTypes.class );
+
+ public static final String BUILTIN_MIMETYPES_FILENAME = "builtin-mimetypes.properties";
+ public static final String MIMETYPES_FILENAME = "nexus.mimetypes";
+
+ private Map<String, NexusMimeType> extensions = Maps.newHashMap();
+
+
+ public NexusMimeTypes()
+ {
+ load( BUILTIN_MIMETYPES_FILENAME );
+ load( MIMETYPES_FILENAME );
+ }
+
+ private void load( final String filename )
+ {
+ final InputStream stream = this.getClass().getResourceAsStream( "/" + filename );
+ if ( stream != null )
+ {
+ final Properties properties = new Properties();
+ try
+ {
+ properties.load( stream );
+ initMimeTypes( properties );
+ }
+ catch ( IOException e )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.warn( "Could not load " + MIMETYPES_FILENAME, e );
+ }
+ else
+ {
+ log.warn( "Could not load " + MIMETYPES_FILENAME + ": {}", e.getMessage() );
+ }
+ }
+ }
+ }
+
+ @VisibleForTesting
+ void initMimeTypes( final Properties properties )
+ {
+ final Set<String> keys = properties.stringPropertyNames();
+ final Map<String, List<String>> overrides = Maps.newHashMap();
+ final Map<String, List<String>> additional = Maps.newHashMap();
+
+ for ( String key : keys )
+ {
+ if ( key.startsWith( "override." ) )
+ {
+ overrides.put( key.substring( "override.".length() ), types( properties.getProperty( key, null ) ) );
+ }
+ else
+ {
+ additional.put( key, types( properties.getProperty( key, null ) ) );
+ }
+ }
+
+ for ( String extension : overrides.keySet() )
+ {
+ final List<String> mimetypes = overrides.get( extension );
+
+ if ( additional.containsKey( extension ))
+ {
+ mimetypes.addAll( additional.get( extension ) );
+ additional.remove( extension );
+ }
+ // HACK
+ // MimeUtils2 is broken so that the last listed MimeType will *usually* be chosen as the "most specific"
+ // one (depends on the impl/order of HashSet<String>.iterator() and a bug in MimeUtils2#getMostSpecificMimeType).
+ //
+ // For Nexus mimetypes, the first listed should be the "primary" mimetype, so we have to reverse the lists.
+ Collections.reverse( mimetypes );
+
+ this.extensions.put( extension, new NexusMimeType( true, extension, mimetypes ));
+ }
+
+ for ( String extension : additional.keySet() )
+ {
+ final List<String> mimetypes = additional.get( extension );
+
+ // HACK
+ // MimeUtils2 is broken so that the last listed MimeType will *usually* be chosen as the "most specific"
+ // one (depends on the impl/order of HashSet<String>.iterator() and a bug in MimeUtils2#getMostSpecificMimeType).
+ //
+ // For Nexus mimetypes, the first listed should be the "primary" mimetype, so we have to reverse the lists.
+ Collections.reverse( mimetypes );
+
+ this.extensions.put( extension, new NexusMimeType( false, extension, mimetypes ) );
+ }
+
+
+ }
+
+ private List<String> types( final String value )
+ {
+ if ( value == null )
+ {
+ return Collections.emptyList();
+ }
+ else
+ {
+ return Lists.newArrayList( Splitter.on( "," ).split( value ) );
+ }
+ }
+
+ public NexusMimeType getMimeTypes( String extension )
+ {
+ while ( !extension.isEmpty() )
+ {
+ if ( extensions.containsKey( extension ) )
+ {
+ return extensions.get( extension );
+ }
+ extension = MimeUtil2.getExtension( extension );
+ }
+
+ return null;
+ }
+
+ public class NexusMimeType
+ {
+
+ private boolean override;
+ private String extension;
+ private List<String> mimetypes;
+
+ private NexusMimeType( final boolean override, final String extension, final List<String> mimetypes )
+ {
+ this.override = override;
+ this.extension = extension;
+ this.mimetypes = mimetypes;
+ }
+
+ public String getExtension()
+ {
+ return extension;
+ }
+
+ public List<String> getMimetypes()
+ {
+ return mimetypes;
+ }
+
+ public boolean isOverride()
+ {
+ return override;
+ }
+ }
+}
@@ -0,0 +1,13 @@
+jar = application/zip
+zip = application/zip
+war = application/zip
+ear = application/zip
+pom = application/xml,application/x-maven-pom,text/xml
+xml = application/xml,text/xml
+tar = application/x-tar
+swc = application/zip
+swf = application/x-shockwave-flash
+gz = application/x-gzip,application/x-tgz
+tgz = application/x-tgz,application/x-gzip
+bz2 = application/x-bzip2
+tbz = application/x-bzip2
@@ -0,0 +1,73 @@
+/**
+ * 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.mime;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasItems;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.sonatype.sisu.litmus.testsupport.TestSupport;
+
+/**
+ * Tests for {@link NexusExtensionMimeDetector}.
+ */
+public class NexusExtensionMimeDetectorTest
+ extends TestSupport
+{
+
+ public NexusExtensionMimeDetector underTest;
+
+ @Mock
+ private NexusMimeTypes mimeTypes;
+
+ @Mock
+ private NexusMimeTypes.NexusMimeType mimeType;
+
+ @Before
+ public void setup()
+ {
+ underTest = new NexusExtensionMimeDetector( mimeTypes );
+ }
+
+ @Test
+ public void fallbackToDefaults()
+ {
+ assertThat( underTest.getMimeTypesFileName( "foo.zip" ), hasItem( "application/zip" ) );
+ }
+
+ @Test
+ public void extendedMimeType()
+ {
+ when( mimeTypes.getMimeTypes( "zip" ) ).thenReturn( mimeType );
+ when( mimeType.getMimetypes() ).thenReturn( Lists.newArrayList( "fake/mimetype" ) );
+
+ assertThat( underTest.getMimeTypesFileName( "foo.zip" ), hasItems( "application/zip", "fake/mimetype" ) );
+ }
+
+ @Test
+ public void overriddenMimeType()
+ {
+ when( mimeTypes.getMimeTypes( "zip" ) ).thenReturn( mimeType );
+ when( mimeType.isOverride() ).thenReturn( true );
+ when( mimeType.getMimetypes() ).thenReturn( Lists.newArrayList( "fake/mimetype" ) );
+
+ // Matchers.contains is an exact match!
+ assertThat( underTest.getMimeTypesFileName( "foo.zip" ), contains( "fake/mimetype" ) );
+ }
+}
Oops, something went wrong.

0 comments on commit 4ce7198

Please sign in to comment.