diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java index 0e6bc39622..1ebf1d6d76 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -180,7 +180,7 @@ public class DefaultArtifactRepository sb.append( " id: " ).append( getId() ).append( "\n" ); sb.append( " url: " ).append( getUrl() ).append( "\n" ); - sb.append( " layout: " ).append( layout != null ? layout.getId() : "none" ).append( "\n" ); + sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( "\n" ); if ( snapshots != null ) { diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java index e8d0e63de0..d86930b912 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java @@ -83,4 +83,11 @@ public class FlatRepositoryLayout { return pathOfRepositoryMetadata( metadata.getRemoteFilename() ); } + + @Override + public String toString() + { + return getId(); + } + } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java index 67cae5fd65..37fe3ab572 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorSelector.java @@ -23,6 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.List; +import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.settings.Mirror; import org.codehaus.plexus.component.annotations.Component; @@ -143,7 +144,7 @@ public class DefaultMirrorSelector static boolean matchesLayout( ArtifactRepository repository, Mirror mirror ) { - return matchesLayout( repository.getLayout().getId(), mirror.getMirrorOfLayouts() ); + return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() ); } /** diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java index ae4757898b..93b16017b4 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java @@ -883,6 +883,12 @@ public class LegacyRepositorySystem return fallback.pathOfRemoteRepositoryMetadata( metadata ); } + @Override + public String toString() + { + return getId(); + } + } } diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java index c3a51d12ec..f5e36c0f22 100644 --- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java +++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java @@ -197,7 +197,7 @@ public class RepositoryUtils RemoteRepository result = null; if ( repo != null ) { - result = new RemoteRepository( repo.getId(), repo.getLayout().getId(), repo.getUrl() ); + result = new RemoteRepository( repo.getId(), getLayout( repo ), repo.getUrl() ); result.setPolicy( true, toPolicy( repo.getSnapshots() ) ); result.setPolicy( false, toPolicy( repo.getReleases() ) ); result.setAuthentication( toAuthentication( repo.getAuthentication() ) ); @@ -207,6 +207,31 @@ public class RepositoryUtils return result; } + public static String getLayout( ArtifactRepository repo ) + { + try + { + return repo.getLayout().getId(); + } + catch ( LinkageError e ) + { + /* + * NOTE: getId() was added in 3.x and is as such not implemented by plugins compiled against 2.x APIs. + */ + String className = repo.getLayout().getClass().getSimpleName(); + if ( className.endsWith( "RepositoryLayout" ) ) + { + String layout = className.substring( 0, className.length() - "RepositoryLayout".length() ); + if ( layout.length() > 0 ) + { + layout = Character.toLowerCase( layout.charAt( 0 ) ) + layout.substring( 1 ); + return layout; + } + } + return ""; + } + } + private static RepositoryPolicy toPolicy( ArtifactRepositoryPolicy policy ) { RepositoryPolicy result = null; diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java index 2cf10697c6..36c20e556c 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java @@ -136,7 +136,7 @@ public class MavenArtifactRepository sb.append( " id: " ).append( getId() ).append( "\n" ); sb.append( " url: " ).append( getUrl() ).append( "\n" ); - sb.append( " layout: " ).append( layout != null ? layout.getId() : "none" ).append( "\n" ); + sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( "\n" ); if ( snapshots != null ) { diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java index 4bb5d794d3..70c0b14c35 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java @@ -103,4 +103,10 @@ public class DefaultRepositoryLayout return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); } + @Override + public String toString() + { + return getId(); + } + }