diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository')
10 files changed, 1564 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java new file mode 100644 index 00000000..ac18b3ad --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java @@ -0,0 +1,55 @@ +package org.apache.maven.artifact.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.UnknownRepositoryLayoutException; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; + +/** @author jdcasey */ +public interface ArtifactRepositoryFactory +{ + String ROLE = ArtifactRepositoryFactory.class.getName(); + + String DEFAULT_LAYOUT_ID = "default"; + + String LOCAL_REPOSITORY_ID = "local"; + + @Deprecated + ArtifactRepositoryLayout getLayout( String layoutId ) + throws UnknownRepositoryLayoutException; + + @Deprecated + ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId, boolean uniqueVersion ) + throws UnknownRepositoryLayoutException; + + ArtifactRepository createDeploymentArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, + boolean uniqueVersion ); + + ArtifactRepository createArtifactRepository( String id, String url, String layoutId, + ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) + throws UnknownRepositoryLayoutException; + + ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, + ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ); + + void setGlobalUpdatePolicy( String snapshotPolicy ); + + void setGlobalChecksumPolicy( String checksumPolicy ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java new file mode 100644 index 00000000..e0a55879 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -0,0 +1,267 @@ +package org.apache.maven.artifact.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.Proxy; +import org.apache.maven.wagon.repository.Repository; + +/** + * This class is an abstraction of the location from/to resources can be + * transfered. + * + * @author <a href="michal.maczka@dimatics.com">Michal Maczka </a> + */ +@Deprecated +public class DefaultArtifactRepository + extends Repository + implements ArtifactRepository +{ + private ArtifactRepositoryLayout layout; + + private ArtifactRepositoryPolicy snapshots; + + private ArtifactRepositoryPolicy releases; + + private boolean blacklisted; + + private Authentication authentication; + + private Proxy proxy; + + private List<ArtifactRepository> mirroredRepositories = Collections.emptyList(); + + /** + * Create a local repository or a test repository. + * + * @param id the unique identifier of the repository + * @param url the URL of the repository + * @param layout the layout of the repository + */ + public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout ) + { + this( id, url, layout, null, null ); + } + + /** + * Create a remote deployment repository. + * + * @param id the unique identifier of the repository + * @param url the URL of the repository + * @param layout the layout of the repository + * @param uniqueVersion whether to assign each snapshot a unique version + */ + public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, boolean uniqueVersion ) + { + super( id, url ); + this.layout = layout; + } + + /** + * Create a remote download repository. + * + * @param id the unique identifier of the repository + * @param url the URL of the repository + * @param layout the layout of the repository + * @param snapshots the policies to use for snapshots + * @param releases the policies to use for releases + */ + public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, + ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) + { + super( id, url ); + + this.layout = layout; + + if ( snapshots == null ) + { + snapshots = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + + this.snapshots = snapshots; + + if ( releases == null ) + { + releases = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + + this.releases = releases; + } + + public String pathOf( Artifact artifact ) + { + return layout.pathOf( artifact ); + } + + public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata ) + { + return layout.pathOfRemoteRepositoryMetadata( artifactMetadata ); + } + + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) + { + return layout.pathOfLocalRepositoryMetadata( metadata, repository ); + } + + public void setLayout( ArtifactRepositoryLayout layout ) + { + this.layout = layout; + } + + public ArtifactRepositoryLayout getLayout() + { + return layout; + } + + public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy snapshots ) + { + this.snapshots = snapshots; + } + + public ArtifactRepositoryPolicy getSnapshots() + { + return snapshots; + } + + public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy releases ) + { + this.releases = releases; + } + + public ArtifactRepositoryPolicy getReleases() + { + return releases; + } + + public String getKey() + { + return getId(); + } + + public boolean isBlacklisted() + { + return blacklisted; + } + + public void setBlacklisted( boolean blacklisted ) + { + this.blacklisted = blacklisted; + } + + public String toString() + { + StringBuilder sb = new StringBuilder(); + + sb.append( " id: " ).append( getId() ).append( "\n" ); + sb.append( " url: " ).append( getUrl() ).append( "\n" ); + sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( "\n" ); + + if ( snapshots != null ) + { + sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() ); + sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" ); + } + + if ( releases != null ) + { + sb.append( " releases: [enabled => " ).append( releases.isEnabled() ); + sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" ); + } + + return sb.toString(); + } + + public Artifact find( Artifact artifact ) + { + File artifactFile = new File( getBasedir(), pathOf( artifact ) ); + + // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal + // with multiple local repository implementations yet. + artifact.setFile( artifactFile ); + + if ( artifactFile.exists() ) + { + artifact.setResolved( true ); + } + + return artifact; + } + + public List<String> findVersions( Artifact artifact ) + { + return Collections.emptyList(); + } + + public boolean isProjectAware() + { + return false; + } + + public Authentication getAuthentication() + { + return authentication; + } + + public void setAuthentication( Authentication authentication ) + { + this.authentication = authentication; + } + + public Proxy getProxy() + { + return proxy; + } + + public void setProxy( Proxy proxy ) + { + this.proxy = proxy; + } + + public boolean isUniqueVersion() + { + return true; + } + + public List<ArtifactRepository> getMirroredRepositories() + { + return mirroredRepositories; + } + + public void setMirroredRepositories( List<ArtifactRepository> mirroredRepositories ) + { + if ( mirroredRepositories != null ) + { + this.mirroredRepositories = mirroredRepositories; + } + else + { + this.mirroredRepositories = Collections.emptyList(); + } + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java new file mode 100644 index 00000000..658dbdac --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java @@ -0,0 +1,124 @@ +package org.apache.maven.artifact.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Arrays; +import java.util.List; + +import org.apache.maven.artifact.UnknownRepositoryLayoutException; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.repository.RepositorySystem; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.eclipse.aether.RepositorySystemSession; + +/** + * @author jdcasey + */ +@Component( role = ArtifactRepositoryFactory.class ) +public class DefaultArtifactRepositoryFactory + implements ArtifactRepositoryFactory +{ + + @Requirement + private org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory factory; + + @Requirement + private LegacySupport legacySupport; + + @Requirement + private RepositorySystem repositorySystem; + + public ArtifactRepositoryLayout getLayout( String layoutId ) + throws UnknownRepositoryLayoutException + { + return factory.getLayout( layoutId ); + } + + public ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId, + boolean uniqueVersion ) + throws UnknownRepositoryLayoutException + { + return injectSession( factory.createDeploymentArtifactRepository( id, url, layoutId, uniqueVersion ), false ); + } + + public ArtifactRepository createDeploymentArtifactRepository( String id, String url, + ArtifactRepositoryLayout repositoryLayout, + boolean uniqueVersion ) + { + return injectSession( factory.createDeploymentArtifactRepository( id, url, repositoryLayout, uniqueVersion ), + false ); + } + + public ArtifactRepository createArtifactRepository( String id, String url, String layoutId, + ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ) + throws UnknownRepositoryLayoutException + { + return injectSession( factory.createArtifactRepository( id, url, layoutId, snapshots, releases ), true ); + } + + public ArtifactRepository createArtifactRepository( String id, String url, + ArtifactRepositoryLayout repositoryLayout, + ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ) + { + return injectSession( factory.createArtifactRepository( id, url, repositoryLayout, snapshots, releases ), true ); + } + + public void setGlobalUpdatePolicy( String updatePolicy ) + { + factory.setGlobalUpdatePolicy( updatePolicy ); + } + + public void setGlobalChecksumPolicy( String checksumPolicy ) + { + factory.setGlobalChecksumPolicy( checksumPolicy ); + } + + private ArtifactRepository injectSession( ArtifactRepository repository, boolean mirrors ) + { + RepositorySystemSession session = legacySupport.getRepositorySession(); + + if ( session != null && repository != null && !isLocalRepository( repository ) ) + { + List<ArtifactRepository> repositories = Arrays.asList( repository ); + + if ( mirrors ) + { + repositorySystem.injectMirror( session, repositories ); + } + + repositorySystem.injectProxy( session, repositories ); + + repositorySystem.injectAuthentication( session, repositories ); + } + + return repository; + } + + private boolean isLocalRepository( ArtifactRepository repository ) + { + // unfortunately, the API doesn't allow to tell a remote repo and the local repo apart... + return "local".equals( repository.getId() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java new file mode 100644 index 00000000..8553a312 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/layout/FlatRepositoryLayout.java @@ -0,0 +1,92 @@ +package org.apache.maven.artifact.repository.layout; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.codehaus.plexus.component.annotations.Component; + +/** + * The code in this class is taken from DefaultRepositorylayout, located at: + * http://svn.apache.org/viewvc/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java + * + */ +@Component( role = ArtifactRepositoryLayout.class, hint = "flat" ) +public class FlatRepositoryLayout + implements ArtifactRepositoryLayout +{ + private static final char ARTIFACT_SEPARATOR = '-'; + + private static final char GROUP_SEPARATOR = '.'; + + public String getId() + { + return "flat"; + } + + public String pathOf( Artifact artifact ) + { + ArtifactHandler artifactHandler = artifact.getArtifactHandler(); + + StringBuilder path = new StringBuilder( 128 ); + + path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() ); + + if ( artifact.hasClassifier() ) + { + path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() ); + } + + if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) + { + path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() ); + } + + return path.toString(); + } + + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) + { + return pathOfRepositoryMetadata( metadata.getLocalFilename( repository ) ); + } + + private String pathOfRepositoryMetadata( String filename ) + { + StringBuilder path = new StringBuilder( 128 ); + + path.append( filename ); + + return path.toString(); + } + + public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) + { + return pathOfRepositoryMetadata( metadata.getRemoteFilename() ); + } + + @Override + public String toString() + { + return getId(); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java new file mode 100644 index 00000000..e7937134 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java @@ -0,0 +1,558 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.DefaultRepositoryRequest; +import org.apache.maven.artifact.repository.RepositoryRequest; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.repository.legacy.UpdateCheckManager; +import org.apache.maven.repository.legacy.WagonManager; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * @author Jason van Zyl + */ +@Component( role = RepositoryMetadataManager.class ) +public class DefaultRepositoryMetadataManager + extends AbstractLogEnabled + implements RepositoryMetadataManager +{ + @Requirement + private WagonManager wagonManager; + + @Requirement + private UpdateCheckManager updateCheckManager; + + public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, + ArtifactRepository localRepository ) + throws RepositoryMetadataResolutionException + { + RepositoryRequest request = new DefaultRepositoryRequest(); + request.setLocalRepository( localRepository ); + request.setRemoteRepositories( remoteRepositories ); + resolve( metadata, request ); + } + + public void resolve( RepositoryMetadata metadata, RepositoryRequest request ) + throws RepositoryMetadataResolutionException + { + ArtifactRepository localRepo = request.getLocalRepository(); + List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories(); + + if ( !request.isOffline() ) + { + Date localCopyLastModified = null; + if ( metadata.getBaseVersion() != null ) + { + localCopyLastModified = getLocalCopyLastModified( localRepo, metadata ); + } + + for ( ArtifactRepository repository : remoteRepositories ) + { + ArtifactRepositoryPolicy policy = metadata.getPolicy( repository ); + + File file = + new File( localRepo.getBasedir(), localRepo.pathOfLocalRepositoryMetadata( metadata, repository ) ); + boolean update; + + if ( !policy.isEnabled() ) + { + update = false; + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( + "Skipping update check for " + metadata.getKey() + " (" + file + + ") from disabled repository " + repository.getId() + " (" + + repository.getUrl() + ")" ); + } + } + else if ( request.isForceUpdate() ) + { + update = true; + } + else if ( localCopyLastModified != null && !policy.checkOutOfDate( localCopyLastModified ) ) + { + update = false; + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( + "Skipping update check for " + metadata.getKey() + " (" + file + + ") from repository " + repository.getId() + " (" + repository.getUrl() + + ") in favor of local copy" ); + } + } + else + { + update = updateCheckManager.isUpdateRequired( metadata, repository, file ); + } + + if ( update ) + { + getLogger().info( metadata.getKey() + ": checking for updates from " + repository.getId() ); + try + { + wagonManager.getArtifactMetadata( metadata, repository, file, policy.getChecksumPolicy() ); + } + catch ( ResourceDoesNotExistException e ) + { + getLogger().debug( metadata + " could not be found on repository: " + repository.getId() ); + + // delete the local copy so the old details aren't used. + if ( file.exists() ) + { + if ( !file.delete() ) + { + // sleep for 10ms just in case this is windows holding a file lock + try + { + Thread.sleep( 10 ); + } + catch ( InterruptedException ie ) + { + // ignore + } + file.delete(); // if this fails, forget about it + } + } + } + catch ( TransferFailedException e ) + { + getLogger().warn( metadata + " could not be retrieved from repository: " + repository.getId() + + " due to an error: " + e.getMessage() ); + getLogger().debug( "Exception", e ); + } + finally + { + updateCheckManager.touch( metadata, repository, file ); + } + } + + // TODO: should this be inside the above check? + // touch file so that this is not checked again until interval has passed + if ( file.exists() ) + { + file.setLastModified( System.currentTimeMillis() ); + } + } + } + + try + { + mergeMetadata( metadata, remoteRepositories, localRepo ); + } + catch ( RepositoryMetadataStoreException e ) + { + throw new RepositoryMetadataResolutionException( "Unable to store local copy of metadata: " + + e.getMessage(), e ); + } + } + + private Date getLocalCopyLastModified( ArtifactRepository localRepository, RepositoryMetadata metadata ) + { + String metadataPath = localRepository.pathOfLocalRepositoryMetadata( metadata, localRepository ); + File metadataFile = new File( localRepository.getBasedir(), metadataPath ); + return metadataFile.isFile() ? new Date( metadataFile.lastModified() ) : null; + } + + private void mergeMetadata( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, + ArtifactRepository localRepository ) + throws RepositoryMetadataStoreException + { + // TODO: currently this is first wins, but really we should take the latest by comparing either the + // snapshot timestamp, or some other timestamp later encoded into the metadata. + // TODO: this needs to be repeated here so the merging doesn't interfere with the written metadata + // - we'd be much better having a pristine input, and an ongoing metadata for merging instead + + Map<ArtifactRepository, Metadata> previousMetadata = new HashMap<ArtifactRepository, Metadata>(); + ArtifactRepository selected = null; + for ( ArtifactRepository repository : remoteRepositories ) + { + ArtifactRepositoryPolicy policy = metadata.getPolicy( repository ); + + if ( policy.isEnabled() && loadMetadata( metadata, repository, localRepository, previousMetadata ) ) + { + metadata.setRepository( repository ); + selected = repository; + } + } + if ( loadMetadata( metadata, localRepository, localRepository, previousMetadata ) ) + { + metadata.setRepository( null ); + selected = localRepository; + } + + updateSnapshotMetadata( metadata, previousMetadata, selected, localRepository ); + } + + private void updateSnapshotMetadata( RepositoryMetadata metadata, + Map<ArtifactRepository, Metadata> previousMetadata, + ArtifactRepository selected, ArtifactRepository localRepository ) + throws RepositoryMetadataStoreException + { + // TODO: this could be a lot nicer... should really be in the snapshot transformation? + if ( metadata.isSnapshot() ) + { + Metadata prevMetadata = metadata.getMetadata(); + + for ( ArtifactRepository repository : previousMetadata.keySet() ) + { + Metadata m = previousMetadata.get( repository ); + if ( repository.equals( selected ) ) + { + if ( m.getVersioning() == null ) + { + m.setVersioning( new Versioning() ); + } + + if ( m.getVersioning().getSnapshot() == null ) + { + m.getVersioning().setSnapshot( new Snapshot() ); + } + } + else + { + if ( ( m.getVersioning() != null ) && ( m.getVersioning().getSnapshot() != null ) + && m.getVersioning().getSnapshot().isLocalCopy() ) + { + m.getVersioning().getSnapshot().setLocalCopy( false ); + metadata.setMetadata( m ); + metadata.storeInLocalRepository( localRepository, repository ); + } + } + } + + metadata.setMetadata( prevMetadata ); + } + } + + private boolean loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository, + ArtifactRepository localRepository, Map<ArtifactRepository, + Metadata> previousMetadata ) + { + boolean setRepository = false; + + File metadataFile = + new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( repoMetadata, + remoteRepository ) ); + + if ( metadataFile.exists() ) + { + Metadata metadata; + + try + { + metadata = readMetadata( metadataFile ); + } + catch ( RepositoryMetadataReadException e ) + { + if ( getLogger().isDebugEnabled() ) + { + getLogger().warn( e.getMessage(), e ); + } + else + { + getLogger().warn( e.getMessage() ); + } + return setRepository; + } + + if ( repoMetadata.isSnapshot() && ( previousMetadata != null ) ) + { + previousMetadata.put( remoteRepository, metadata ); + } + + if ( repoMetadata.getMetadata() != null ) + { + setRepository = repoMetadata.getMetadata().merge( metadata ); + } + else + { + repoMetadata.setMetadata( metadata ); + setRepository = true; + } + } + return setRepository; + } + + /** @todo share with DefaultPluginMappingManager. */ + protected Metadata readMetadata( File mappingFile ) + throws RepositoryMetadataReadException + { + Metadata result; + + Reader reader = null; + try + { + reader = ReaderFactory.newXmlReader( mappingFile ); + + MetadataXpp3Reader mappingReader = new MetadataXpp3Reader(); + + result = mappingReader.read( reader, false ); + } + catch ( FileNotFoundException e ) + { + throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "'", e ); + } + catch ( IOException e ) + { + throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': " + + e.getMessage(), e ); + } + catch ( XmlPullParserException e ) + { + throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': " + + e.getMessage(), e ); + } + finally + { + IOUtil.close( reader ); + } + + return result; + } + + /** + * Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local + * metadata if necessary to allow proper merging/updating of metadata during deployment. + */ + private void fixTimestamp( File metadataFile, Metadata metadata, Metadata reference ) + { + boolean changed = false; + + if ( metadata != null && reference != null ) + { + Versioning versioning = metadata.getVersioning(); + Versioning versioningRef = reference.getVersioning(); + if ( versioning != null && versioningRef != null ) + { + String lastUpdated = versioning.getLastUpdated(); + String now = versioningRef.getLastUpdated(); + if ( lastUpdated != null && now != null && now.compareTo( lastUpdated ) < 0 ) + { + getLogger().warn( + "The last updated timestamp in " + metadataFile + " refers to the future (now = " + + now + ", lastUpdated = " + lastUpdated + + "). Please verify that the clocks of all" + + " deploying machines are reasonably synchronized." ); + versioning.setLastUpdated( now ); + changed = true; + } + } + } + + if ( changed ) + { + getLogger().debug( "Repairing metadata in " + metadataFile ); + + Writer writer = null; + try + { + writer = WriterFactory.newXmlWriter( metadataFile ); + new MetadataXpp3Writer().write( writer, metadata ); + } + catch ( IOException e ) + { + String msg = "Could not write fixed metadata to " + metadataFile + ": " + e.getMessage(); + if ( getLogger().isDebugEnabled() ) + { + getLogger().warn( msg, e ); + } + else + { + getLogger().warn( msg ); + } + } + finally + { + IOUtil.close( writer ); + } + } + } + + public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository, + ArtifactRepository remoteRepository ) + throws RepositoryMetadataResolutionException + { + File file; + try + { + file = getArtifactMetadataFromDeploymentRepository( metadata, localRepository, remoteRepository ); + } + catch ( TransferFailedException e ) + { + throw new RepositoryMetadataResolutionException( metadata + " could not be retrieved from repository: " + + remoteRepository.getId() + " due to an error: " + e.getMessage(), e ); + } + + try + { + if ( file.exists() ) + { + Metadata prevMetadata = readMetadata( file ); + metadata.setMetadata( prevMetadata ); + } + } + catch ( RepositoryMetadataReadException e ) + { + throw new RepositoryMetadataResolutionException( e.getMessage(), e ); + } + } + + private File getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata, + ArtifactRepository localRepo, + ArtifactRepository remoteRepository ) + throws TransferFailedException + { + File file = + new File( localRepo.getBasedir(), localRepo.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) ); + + try + { + wagonManager.getArtifactMetadataFromDeploymentRepository( metadata, remoteRepository, file, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); + } + catch ( ResourceDoesNotExistException e ) + { + getLogger().info( metadata + " could not be found on repository: " + remoteRepository.getId() + + ", so will be created" ); + + // delete the local copy so the old details aren't used. + if ( file.exists() ) + { + if ( !file.delete() ) + { + // sleep for 10ms just in case this is windows holding a file lock + try + { + Thread.sleep( 10 ); + } + catch ( InterruptedException ie ) + { + // ignore + } + file.delete(); // if this fails, forget about it + } + } + } + finally + { + if ( metadata instanceof RepositoryMetadata ) + { + updateCheckManager.touch( (RepositoryMetadata) metadata, remoteRepository, file ); + } + } + return file; + } + + public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository, + ArtifactRepository deploymentRepository ) + throws RepositoryMetadataDeploymentException + { + File file; + if ( metadata instanceof RepositoryMetadata ) + { + getLogger().info( "Retrieving previous metadata from " + deploymentRepository.getId() ); + try + { + file = getArtifactMetadataFromDeploymentRepository( metadata, localRepository, deploymentRepository ); + } + catch ( TransferFailedException e ) + { + throw new RepositoryMetadataDeploymentException( metadata + " could not be retrieved from repository: " + + deploymentRepository.getId() + " due to an error: " + e.getMessage(), e ); + } + + if ( file.isFile() ) + { + try + { + fixTimestamp( file, readMetadata( file ), ( (RepositoryMetadata) metadata ).getMetadata() ); + } + catch ( RepositoryMetadataReadException e ) + { + // will be reported via storeInlocalRepository + } + } + } + else + { + // It's a POM - we don't need to retrieve it first + file = + new File( localRepository.getBasedir(), + localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) ); + } + + try + { + metadata.storeInLocalRepository( localRepository, deploymentRepository ); + } + catch ( RepositoryMetadataStoreException e ) + { + throw new RepositoryMetadataDeploymentException( "Error installing metadata: " + e.getMessage(), e ); + } + + try + { + wagonManager.putArtifactMetadata( file, metadata, deploymentRepository ); + } + catch ( TransferFailedException e ) + { + throw new RepositoryMetadataDeploymentException( "Error while deploying metadata: " + e.getMessage(), e ); + } + } + + public void install( ArtifactMetadata metadata, ArtifactRepository localRepository ) + throws RepositoryMetadataInstallationException + { + try + { + metadata.storeInLocalRepository( localRepository, localRepository ); + } + catch ( RepositoryMetadataStoreException e ) + { + throw new RepositoryMetadataInstallationException( "Error installing metadata: " + e.getMessage(), e ); + } + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java new file mode 100644 index 00000000..490b47f3 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java @@ -0,0 +1,119 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; + +import java.util.Iterator; +import java.util.List; + +/** + * Metadata for the group directory of the repository. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class GroupRepositoryMetadata + extends AbstractRepositoryMetadata +{ + private final String groupId; + + public GroupRepositoryMetadata( String groupId ) + { + super( new Metadata() ); + this.groupId = groupId; + } + + public boolean storedInGroupDirectory() + { + return true; + } + + public boolean storedInArtifactVersionDirectory() + { + return false; + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return null; + } + + public String getBaseVersion() + { + return null; + } + + public void addPluginMapping( String goalPrefix, + String artifactId ) + { + addPluginMapping( goalPrefix, artifactId, artifactId ); + } + + public void addPluginMapping( String goalPrefix, + String artifactId, + String name ) + { + List plugins = getMetadata().getPlugins(); + boolean found = false; + for ( Iterator i = plugins.iterator(); i.hasNext() && !found; ) + { + Plugin plugin = (Plugin) i.next(); + if ( plugin.getPrefix().equals( goalPrefix ) ) + { + found = true; + } + } + if ( !found ) + { + Plugin plugin = new Plugin(); + plugin.setPrefix( goalPrefix ); + plugin.setArtifactId( artifactId ); + plugin.setName( name ); + + + getMetadata().addPlugin( plugin ); + } + } + + public Object getKey() + { + return groupId; + } + + public boolean isSnapshot() + { + return false; + } + + public ArtifactRepository getRepository() + { + return null; + } + + public void setRepository( ArtifactRepository remoteRepository ) + { + // intentionally blank + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java new file mode 100644 index 00000000..bf199218 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java @@ -0,0 +1,172 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.util.Collections; +import java.util.Map; + +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.RepositoryException; +import org.eclipse.aether.metadata.AbstractMetadata; +import org.eclipse.aether.metadata.MergeableMetadata; +import org.eclipse.aether.metadata.Metadata; + +/** + * <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part + * of the public API. In particular, this class can be changed or deleted without prior notice. + * + * @author Benjamin Bentmann + */ +public final class MetadataBridge + extends AbstractMetadata + implements MergeableMetadata +{ + + private ArtifactMetadata metadata; + + private boolean merged; + + public MetadataBridge( ArtifactMetadata metadata ) + { + this.metadata = metadata; + } + + public void merge( File current, File result ) + throws RepositoryException + { + try + { + if ( current.exists() ) + { + FileUtils.copyFile( current, result ); + } + ArtifactRepository localRepo = new MetadataRepository( result ); + metadata.storeInLocalRepository( localRepo, localRepo ); + merged = true; + } + catch ( Exception e ) + { + throw new RepositoryException( e.getMessage(), e ); + } + } + + public boolean isMerged() + { + return merged; + } + + public String getGroupId() + { + return emptify( metadata.getGroupId() ); + } + + public String getArtifactId() + { + return metadata.storedInGroupDirectory() ? "" : emptify( metadata.getArtifactId() ); + } + + public String getVersion() + { + return metadata.storedInArtifactVersionDirectory() ? emptify( metadata.getBaseVersion() ) : ""; + } + + public String getType() + { + return metadata.getRemoteFilename(); + } + + private String emptify( String string ) + { + return ( string != null ) ? string : ""; + } + + public File getFile() + { + return null; + } + + public MetadataBridge setFile( File file ) + { + return this; + } + + public Nature getNature() + { + if ( metadata instanceof RepositoryMetadata ) + { + switch ( ( (RepositoryMetadata) metadata ).getNature() ) + { + case RepositoryMetadata.RELEASE_OR_SNAPSHOT: + return Nature.RELEASE_OR_SNAPSHOT; + case RepositoryMetadata.SNAPSHOT: + return Nature.SNAPSHOT; + default: + return Nature.RELEASE; + } + } + else + { + return Nature.RELEASE; + } + } + + public Map<String, String> getProperties() + { + return Collections.emptyMap(); + } + + @Override + public Metadata setProperties( Map<String, String> properties ) + { + return this; + } + + @SuppressWarnings( "deprecation" ) + static class MetadataRepository + extends DefaultArtifactRepository + { + + private File metadataFile; + + public MetadataRepository( File metadataFile ) + { + super( "local", "", null ); + this.metadataFile = metadataFile; + } + + @Override + public String getBasedir() + { + return metadataFile.getParent(); + } + + @Override + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) + { + return metadataFile.getName(); + } + + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataUtils.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataUtils.java new file mode 100644 index 00000000..bdc4a795 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataUtils.java @@ -0,0 +1,39 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Assists in handling repository metadata. + * + * @author Benjamin Bentmann + */ +class MetadataUtils +{ + + public static Metadata cloneMetadata( Metadata src ) + { + if ( src == null ) + { + return null; + } + return src.clone(); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataReadException.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataReadException.java new file mode 100644 index 00000000..23e59841 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataReadException.java @@ -0,0 +1,40 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Problem storing the repository metadata in the local repository. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class RepositoryMetadataReadException + extends Exception +{ + public RepositoryMetadataReadException( String message ) + { + super( message ); + } + + public RepositoryMetadataReadException( String message, + Exception e ) + { + super( message, e ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java new file mode 100644 index 00000000..359ab2ce --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java @@ -0,0 +1,98 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * Metadata for the artifact version directory of the repository. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + * @todo split instantiation (versioning, plugin mappings) from definition + */ +public class SnapshotArtifactRepositoryMetadata + extends AbstractRepositoryMetadata +{ + private Artifact artifact; + + public SnapshotArtifactRepositoryMetadata( Artifact artifact ) + { + super( createMetadata( artifact, null ) ); + this.artifact = artifact; + } + + public SnapshotArtifactRepositoryMetadata( Artifact artifact, + Snapshot snapshot ) + { + super( createMetadata( artifact, createVersioning( snapshot ) ) ); + this.artifact = artifact; + } + + public boolean storedInGroupDirectory() + { + return false; + } + + public boolean storedInArtifactVersionDirectory() + { + return true; + } + + public String getGroupId() + { + return artifact.getGroupId(); + } + + public String getArtifactId() + { + return artifact.getArtifactId(); + } + + public String getBaseVersion() + { + return artifact.getBaseVersion(); + } + + public Object getKey() + { + return "snapshot " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion(); + } + + public boolean isSnapshot() + { + return artifact.isSnapshot(); + } + + public int getNature() + { + return isSnapshot() ? SNAPSHOT : RELEASE; + } + + public ArtifactRepository getRepository() + { + return artifact.getRepository(); + } + + public void setRepository( ArtifactRepository remoteRepository ) + { + artifact.setRepository( remoteRepository ); + } +} |